ReactOS 0.4.16-dev-297-gc569aee
file.c File Reference
#include "vfatlib.h"
#include <debug.h>
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static void put_char (char **p, unsigned char c)
 
charfile_name (unsigned char *fixed)
 
int file_cvt (unsigned char *name, unsigned char *fixed)
 
void file_add (char *path, FD_TYPE type)
 
FDSC ** file_cd (FDSC **curr, char *fixed)
 
static FDSC ** file_find (FDSC **dir, char *fixed)
 
FD_TYPE file_type (FDSC **curr, char *fixed)
 
void file_modify (FDSC **curr, char *fixed)
 
static void report_unused (FDSC *this)
 
void file_unused (void)
 

Variables

FDSCfp_root = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file file.c.

Function Documentation

◆ file_add()

void file_add ( char path,
FD_TYPE  type 
)

Definition at line 142 of file file.c.

143{
144 FDSC **current, *walk;
145 char name[MSDOS_NAME];
146 char *here;
147
148 current = &fp_root;
149 if (*path != '/')
150 die("%s: Absolute path required.", path);
151 path++;
152 while (1) {
153 if ((here = strchr(path, '/')))
154 *here = 0;
155 if (!file_cvt((unsigned char *)path, (unsigned char *)name))
156 exit(2);
157 for (walk = *current; walk; walk = walk->next)
158 if (!here && (!strncmp(name, walk->name, MSDOS_NAME) || (type ==
160 &&
161 !strncmp
162 (name + 1,
163 walk->name
164 + 1,
166 - 1))))
167 die("Ambiguous name: \"%s\"", path);
168 else if (here && !strncmp(name, walk->name, MSDOS_NAME))
169 break;
170 if (!walk) {
171 walk = alloc(sizeof(FDSC));
172 strncpy(walk->name, name, MSDOS_NAME);
173 walk->type = here ? fdt_none : type;
174 walk->first = NULL;
175 walk->next = *current;
176 *current = walk;
177 }
178 current = &walk->first;
179 if (!here)
180 break;
181 *here = '/';
182 path = here + 1;
183 }
184}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define NULL
Definition: types.h:112
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
@ fdt_none
Definition: file.h:28
@ fdt_undelete
Definition: file.h:28
#define die(str)
Definition: mkdosfs.c:347
struct task_struct * current
Definition: linux.c:32
#define MSDOS_NAME
Definition: msdos_fs.h:46
#define alloc
Definition: rosglue.h:13
#define exit(n)
Definition: config.h:202
FDSC * fp_root
Definition: file.c:32
int file_cvt(unsigned char *name, unsigned char *fixed)
Definition: file.c:84
Definition: file.h:30
FD_TYPE type
Definition: file.h:32
struct _fptr * first
Definition: file.h:33
struct _fptr * next
Definition: file.h:34
char name[MSDOS_NAME]
Definition: file.h:31
Definition: name.c:39

◆ file_cd()

FDSC ** file_cd ( FDSC **  curr,
char fixed 
)

Definition at line 186 of file file.c.

187{
188 FDSC **walk;
189
190 if (!curr || !*curr)
191 return NULL;
192 for (walk = curr; *walk; walk = &(*walk)->next)
193 if (!strncmp((*walk)->name, fixed, MSDOS_NAME) && (*walk)->first)
194 return &(*walk)->first;
195 return NULL;
196}
ios_base &_STLP_CALL fixed(ios_base &__s)
Definition: _ios_base.h:332

Referenced by subdirs().

◆ file_cvt()

int file_cvt ( unsigned char name,
unsigned char fixed 
)

Definition at line 84 of file file.c.

85{
86 unsigned char c;
87 int size, ext, cnt;
88
89 size = 8;
90 ext = 0;
91 while (*name) {
92 c = *name;
93 if (c < ' ' || c > 0x7e || strchr("*?<>|\"/", c)) {
94 printf("Invalid character in name. Use \\ooo for special "
95 "characters.\n");
96 return 0;
97 }
98 if (c == '.') {
99 if (ext) {
100 printf("Duplicate dots in name.\n");
101 return 0;
102 }
103 while (size--)
104 *fixed++ = ' ';
105 size = 3;
106 ext = 1;
107 name++;
108 continue;
109 }
110 if (c == '\\') {
111 c = 0;
112 name++;
113 for (cnt = 3; cnt; cnt--) {
114 if (*name < '0' || *name > '7') {
115 printf("Expected three octal digits.\n");
116 return 0;
117 }
118 c = c * 8 + *name++ - '0';
119 }
120 name--;
121 }
122 if (islower(c))
123 c = toupper(c);
124 if (size) {
125 *fixed++ = c;
126 size--;
127 }
128 name++;
129 }
130 if (*name || size == 8)
131 return 0;
132 if (!ext) {
133 while (size--)
134 *fixed++ = ' ';
135 size = 3;
136 }
137 while (size--)
138 *fixed++ = ' ';
139 return 1;
140}
#define islower(c)
Definition: acclib.h:72
int toupper(int c)
Definition: utclib.c:881
static const WCHAR *const ext[]
Definition: module.c:53
#define printf
Definition: freeldr.h:97
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

Referenced by file_add(), and rename_file().

◆ file_find()

static FDSC ** file_find ( FDSC **  dir,
char fixed 
)
static

Definition at line 198 of file file.c.

199{
200 if (!dir || !*dir)
201 return NULL;
202 if (*(unsigned char *)fixed == DELETED_FLAG) {
203 while (*dir) {
204 if (!strncmp((*dir)->name + 1, fixed + 1, MSDOS_NAME - 1)
205 && !(*dir)->first)
206 return dir;
207 dir = &(*dir)->next;
208 }
209 return NULL;
210 }
211 while (*dir) {
212 if (!strncmp((*dir)->name, fixed, MSDOS_NAME) && !(*dir)->first)
213 return dir;
214 dir = &(*dir)->next;
215 }
216 return NULL;
217}
unsigned int dir
Definition: maze.c:112
#define DELETED_FLAG
Definition: msdos_fs.h:43

Referenced by file_modify(), and file_type().

◆ file_modify()

void file_modify ( FDSC **  curr,
char fixed 
)

Definition at line 230 of file file.c.

231{
232 FDSC **this, *next;
233
234 if (!(this = file_find(curr, fixed)))
235 die("Internal error: file_find failed");
236 switch ((*this)->type) {
237 case fdt_drop:
238 printf("Dropping %s\n", file_name((unsigned char *)fixed));
239 *(unsigned char *)fixed = DELETED_FLAG;
240 break;
241 case fdt_undelete:
242 *fixed = *(*this)->name;
243 printf("Undeleting %s\n", file_name((unsigned char *)fixed));
244 break;
245 default:
246 die("Internal error: file_modify");
247 }
248 next = (*this)->next;
249 free(*this);
250 *this = next;
251}
#define free
Definition: debug_ros.c:5
@ fdt_drop
Definition: file.h:28
static LPCWSTR file_name
Definition: protocol.c:147
static unsigned __int64 next
Definition: rand_nt.c:6
static FDSC ** file_find(FDSC **dir, char *fixed)
Definition: file.c:198

Referenced by add_file().

◆ file_name()

char * file_name ( unsigned char fixed)

Construct the "pretty-printed" representation of the name in a short directory entry.

Parameters
[in]fixedPointer to name[0] of a DIR_ENT
Returns
Pointer to static string containing pretty "8.3" equivalent of the name in the directory entry.

Definition at line 58 of file file.c.

59{
60 static char path[MSDOS_NAME * 4 + 2];
61 char *p;
62 int i, j;
63
64 p = path;
65 for (i = j = 0; i < 8; i++)
66 if (fixed[i] != ' ') {
67 while (j++ < i)
68 *p++ = ' ';
69 put_char(&p, fixed[i]);
70 }
71 if (strncmp((const char *)(fixed + 8), " ", 3)) {
72 *p++ = '.';
73 for (i = j = 0; i < 3; i++)
74 if (fixed[i + 8] != ' ') {
75 while (j++ < i)
76 *p++ = ' ';
77 put_char(&p, fixed[i + 8]);
78 }
79 }
80 *p = 0;
81 return path;
82}
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static void put_char(char **p, unsigned char c)
Definition: file.c:34

◆ file_type()

FD_TYPE file_type ( FDSC **  curr,
char fixed 
)

Definition at line 221 of file file.c.

222{
223 FDSC **this;
224
225 if ((this = file_find(curr, fixed)))
226 return (*this)->type;
227 return fdt_none;
228}

Referenced by add_file(), CVfdShExt::DoVfdDrop(), file_write_http_header(), map_acemask(), map_dacl_2_nfs4acl(), OnImage(), OnTarget(), Open(), PrintImageInfo(), Save(), UpdateImageInfo(), VfdImageTip(), and VfdOpenImage().

◆ file_unused()

void file_unused ( void  )

Definition at line 269 of file file.c.

270{
272}
static void report_unused(FDSC *this)
Definition: file.c:253

Referenced by VfatChkdsk().

◆ put_char()

static void put_char ( char **  p,
unsigned char  c 
)
static

Definition at line 34 of file file.c.

35{
36#ifndef __REACTOS__
37 if (dos_char_to_printable(p, c))
38 return;
39#endif
40 if ((c >= ' ' && c < 0x7f) || c >= 0xa0)
41 *(*p)++ = c;
42 else {
43 *(*p)++ = '\\';
44 *(*p)++ = '0' + (c >> 6);
45 *(*p)++ = '0' + ((c >> 3) & 7);
46 *(*p)++ = '0' + (c & 7);
47 }
48}

Referenced by file_name().

◆ report_unused()

static void report_unused ( FDSC this)
static

Definition at line 253 of file file.c.

254{
255 FDSC *next;
256
257 while (this) {
258 next = this->next;
259 if (this->first)
260 report_unused(this->first);
261 else if (this->type != fdt_none)
262 printf("Warning: did not %s file %s\n", this->type == fdt_drop ?
263 "drop" : "undelete", file_name((unsigned char *)this->name));
264 free(this);
265 this = next;
266 }
267}
const GLint * first
Definition: glext.h:5794

Referenced by file_unused(), and report_unused().

Variable Documentation

◆ fp_root

FDSC* fp_root = NULL

Definition at line 32 of file file.c.

Referenced by file_add(), file_unused(), and scan_root().