ReactOS 0.4.16-dev-297-gc569aee
check.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

off_t alloc_rootdir_entry (DOS_FS *fs, DIR_ENT *de, const char *pattern, int gen_name)
 
int scan_root (DOS_FS *fs)
 

Function Documentation

◆ alloc_rootdir_entry()

off_t alloc_rootdir_entry ( DOS_FS fs,
DIR_ENT *  de,
const char pattern,
int  gen_name 
)

Definition at line 74 of file check.c.

75{
76 static int curr_num = 0;
78
79 if (fs->root_cluster) {
80 DIR_ENT d2;
81 int i = 0, got = 0;
82 uint32_t clu_num, prev = 0;
83 off_t offset2;
84
85 clu_num = fs->root_cluster;
86 offset = cluster_start(fs, clu_num);
87 while (clu_num > 0 && clu_num != -1) {
88 fs_read(offset, sizeof(DIR_ENT), &d2);
89 if (IS_FREE(d2.name) && d2.attr != VFAT_LN_ATTR) {
90 got = 1;
91 break;
92 }
93 i += sizeof(DIR_ENT);
94 offset += sizeof(DIR_ENT);
95 if ((i % fs->cluster_size) == 0) {
96 prev = clu_num;
97 if ((clu_num = next_cluster(fs, clu_num)) == 0 || clu_num == -1)
98 break;
99 offset = cluster_start(fs, clu_num);
100 }
101 }
102 if (!got) {
103 /* no free slot, need to extend root dir: alloc next free cluster
104 * after previous one */
105 if (!prev)
106 die("Root directory has no cluster allocated!");
107 for (clu_num = prev + 1; clu_num != prev; clu_num++) {
109
110 if (clu_num >= fs->data_clusters + 2)
111 clu_num = 2;
112 get_fat(&entry, fs->fat, clu_num, fs);
113 if (!entry.value)
114 break;
115 }
116 if (clu_num == prev)
117 die("Root directory full and no free cluster");
118 set_fat(fs, prev, clu_num);
119 set_fat(fs, clu_num, -1);
120 set_owner(fs, clu_num, get_owner(fs, fs->root_cluster));
121 /* clear new cluster */
122 memset(&d2, 0, sizeof(d2));
123 offset = cluster_start(fs, clu_num);
124 for (i = 0; i < fs->cluster_size; i += sizeof(DIR_ENT))
125 fs_write(offset + i, sizeof(d2), &d2);
126 }
127 memset(de, 0, sizeof(DIR_ENT));
128 if (gen_name) {
129 while (1) {
130 char expanded[12];
131 sprintf(expanded, pattern, curr_num);
132 memcpy(de->name, expanded, MSDOS_NAME);
133 clu_num = fs->root_cluster;
134 i = 0;
135 offset2 = cluster_start(fs, clu_num);
136 while (clu_num > 0 && clu_num != -1) {
137 fs_read(offset2, sizeof(DIR_ENT), &d2);
138 if (offset2 != offset &&
139 !strncmp((const char *)d2.name, (const char *)de->name,
140 MSDOS_NAME))
141 break;
142 i += sizeof(DIR_ENT);
143 offset2 += sizeof(DIR_ENT);
144 if ((i % fs->cluster_size) == 0) {
145 if ((clu_num = next_cluster(fs, clu_num)) == 0 ||
146 clu_num == -1)
147 break;
148 offset2 = cluster_start(fs, clu_num);
149 }
150 }
151 if (clu_num == 0 || clu_num == -1)
152 break;
153 if (++curr_num >= 10000)
154 die("Unable to create unique name");
155 }
156 } else {
157 memcpy(de->name, pattern, MSDOS_NAME);
158 }
159 } else {
160 DIR_ENT *root;
161 int next_free = 0, scan;
162
163 root = alloc(fs->root_entries * sizeof(DIR_ENT));
164 fs_read(fs->root_start, fs->root_entries * sizeof(DIR_ENT), root);
165
166 while (next_free < fs->root_entries)
167 if (IS_FREE(root[next_free].name) &&
168 root[next_free].attr != VFAT_LN_ATTR)
169 break;
170 else
171 next_free++;
172 if (next_free == fs->root_entries)
173 die("Root directory is full.");
174 offset = fs->root_start + next_free * sizeof(DIR_ENT);
175 memset(de, 0, sizeof(DIR_ENT));
176 if (gen_name) {
177 while (1) {
178 char expanded[12];
179 sprintf(expanded, pattern, curr_num);
180 memcpy(de->name, expanded, MSDOS_NAME);
181 for (scan = 0; scan < fs->root_entries; scan++)
182 if (scan != next_free &&
183 !strncmp((const char *)root[scan].name,
184 (const char *)de->name, MSDOS_NAME))
185 break;
186 if (scan == fs->root_entries)
187 break;
188 if (++curr_num >= 10000)
189 die("Unable to create unique name");
190 }
191 } else {
192 memcpy(de->name, pattern, MSDOS_NAME);
193 }
194 free(root);
195 }
196 ++n_files;
197 return offset;
198}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define free
Definition: debug_ros.c:5
UINT32 uint32_t
Definition: types.h:75
static HRESULT get_owner(VARIANT *user, VARIANT *domain, VARIANT *retval)
Definition: process.c:34
__kernel_off_t off_t
Definition: linux.h:201
#define VFAT_LN_ATTR
Definition: fsck.fat.h:78
static DOS_FILE * root
Definition: check.c:37
GLubyte * pattern
Definition: glext.h:7787
GLintptr offset
Definition: glext.h:5920
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
uint32_t entry
Definition: isohybrid.c:63
#define die(str)
Definition: mkdosfs.c:347
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define IS_FREE(n)
Definition: msdos_fs.h:44
#define MSDOS_NAME
Definition: msdos_fs.h:46
const char * root_entries[]
Definition: netreg.cpp:25
#define alloc
Definition: rosglue.h:13
#define n_files
Definition: rosglue.h:43
uint32_t next_cluster(DOS_FS *fs, uint32_t cluster)
Definition: fat.c:276
void set_owner(DOS_FS *fs, uint32_t cluster, DOS_FILE *owner)
Definition: fat.c:303
off_t cluster_start(DOS_FS *fs, uint32_t cluster)
Definition: fat.c:289
void get_fat(FAT_ENTRY *entry, void *fat, uint32_t cluster, DOS_FS *fs)
Definition: fat.c:41
void set_fat(DOS_FS *fs, uint32_t cluster, int32_t new)
Definition: fat.c:189
void fs_read(off_t pos, int size, void *data)
Definition: io.c:282
void fs_write(off_t pos, int size, void *data)
Definition: io.c:344
#define memset(x, y, z)
Definition: compat.h:39
Definition: fsck.fat.h:192
Definition: cookie.c:202
Definition: ffs.h:70
Definition: name.c:39
WCHAR * name
Definition: name.c:42

Referenced by reclaim_file(), and write_volume_label().

◆ scan_root()

int scan_root ( DOS_FS fs)

Scan all directory and file information for errors.

Parameters
[in,out]fsInformation about the filesystem
Returns
0 Success
1 Error

Definition at line 1232 of file check.c.

1233{
1234 DOS_FILE **chain;
1235 int i;
1236
1237 root = NULL;
1238 chain = &root;
1239 new_dir();
1240 if (fs->root_cluster) {
1241 add_file(fs, &chain, NULL, 0, &fp_root);
1242 } else {
1243 for (i = 0; i < fs->root_entries; i++)
1244 add_file(fs, &chain, NULL, fs->root_start + i * sizeof(DIR_ENT),
1245 &fp_root);
1246 }
1248 (void)check_dir(fs, &root, 0);
1249 if (check_files(fs, root))
1250 return 1;
1251 return subdirs(fs, NULL, &fp_root);
1252}
#define NULL
Definition: types.h:112
static void add_file(DOS_FS *fs, DOS_FILE ***chain, DOS_FILE *parent, off_t offset, FDSC **cp)
Definition: check.c:1117
static int check_dir(DOS_FS *fs, DOS_FILE **root, int dots)
Definition: check.c:826
static void new_dir(void)
Definition: check.c:1099
static int subdirs(DOS_FS *fs, DOS_FILE *parent, FDSC **cp)
Definition: check.c:1210
static int check_files(DOS_FS *fs, DOS_FILE *start)
Definition: check.c:816
void lfn_check_orphaned(void)
Definition: lfn.c:517
FDSC * fp_root
Definition: file.c:32
struct sock * chain
Definition: tcpcore.h:1

Referenced by VfatChkdsk().