Home | History | Annotate | Download | only in fsck_msdos

Lines Matching full:boot

74 checkdirty(int fs, struct bootblock *boot)
80 if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK)
83 off = boot->ResSectors;
84 off *= boot->BytesPerSec;
86 buffer = malloc(boot->BytesPerSec);
97 if (read(fs, buffer, boot->BytesPerSec) != boot->BytesPerSec) {
106 if (buffer[0] != boot->Media || buffer[1] != 0xff)
108 if (boot->ClustMask == CLUST16_MASK) {
121 if (boot->ClustMask == CLUST16_MASK) {
138 checkclnum(struct bootblock *boot, int fat, cl_t cl, cl_t *next)
140 if (*next >= (CLUST_RSRVD&boot->ClustMask))
141 *next |= ~boot->ClustMask;
143 boot->NumFree++;
147 boot->NumBad++;
151 || (*next >= boot->NumClusters && *next < CLUST_EOFS)) {
155 *next&boot->ClustMask);
169 _readfat(int fs, struct bootblock *boot, int no, u_char **buffer)
174 (boot->FATsecs * boot->BytesPerSec) / 1024);
176 *buffer = malloc(boot->FATsecs * boot->BytesPerSec);
182 off = boot->ResSectors + no * boot->FATsecs;
183 off *= boot->BytesPerSec;
190 if (read(fs, *buffer, boot->FATsecs * boot->BytesPerSec)
191 != boot->FATsecs * boot->BytesPerSec) {
207 readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp)
214 boot->NumFree = boot->NumBad = 0;
216 if (!_readfat(fs, boot, no, &buffer))
219 fat = calloc(boot->NumClusters, sizeof(struct fatEntry));
226 if (buffer[0] != boot->Media
228 || (boot->ClustMask == CLUST16_MASK && buffer[3] != 0xff)
229 || (boot->ClustMask == CLUST32_MASK
236 * 0xXXffff0fffffff07 for FAT32 upon boot, to know that the
240 if (buffer[0] == boot->Media && buffer[1] == 0xff
242 && ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f)
243 || (boot->ClustMask == CLUST32_MASK
251 switch (boot->ClustMask) {
275 switch (boot->ClustMask) {
286 for (cl = CLUST_FIRST; cl < boot->NumClusters;) {
287 switch (boot->ClustMask) {
291 fat[cl].next &= boot->ClustMask;
292 ret |= checkclnum(boot, no, cl, &fat[cl].next);
298 ret |= checkclnum(boot, no, cl, &fat[cl].next);
304 ret |= checkclnum(boot, no, cl, &fat[cl].next);
306 if (cl >= boot->NumClusters)
309 ret |= checkclnum(boot, no, cl, &fat[cl].next);
407 comparefat(struct bootblock *boot, struct fatEntry *first,
413 for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++)
420 clearchain(struct bootblock *boot, struct fatEntry *fat, cl_t head)
424 for (p = head; p >= CLUST_FIRST && p < boot->NumClusters; p = q) {
434 tryclear(struct bootblock *boot, struct fatEntry *fat, cl_t head, cl_t *trunc)
437 clearchain(boot, fat, head);
450 checkfat(struct bootblock *boot, struct fatEntry *fat)
460 for (head = CLUST_FIRST; head < boot->NumClusters; head++) {
469 p >= CLUST_FIRST && p < boot->NumClusters;
472 if (len > boot->NumClusters) {
490 for (head = CLUST_FIRST; head < boot->NumClusters; head++) {
497 for (p = head,wdk=boot->NumClusters;
498 (n = fat[p].next) >= CLUST_FIRST && n < boot->NumClusters && wdk;
510 ret |= tryclear(boot, fat, head, &fat[p].next);
513 if (n < CLUST_FIRST || n >= boot->NumClusters) {
516 ret |= tryclear(boot, fat, head, &fat[p].next);
521 conf = tryclear(boot, fat, head, &fat[p].next);
528 p >= CLUST_FIRST && p < boot->NumClusters;
540 clearchain(boot, fat, h);
553 writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
562 buffer = malloc(fatsz = boot->FATsecs * boot->BytesPerSec);
568 boot->NumFree = 0;
571 *p++ = (u_char)boot->Media;
574 switch (boot->ClustMask) {
591 switch (boot->ClustMask) {
603 if (!_readfat(fs, boot, boot->ValidFat >= 0 ? boot->ValidFat :0,
614 for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++) {
615 switch (boot->ClustMask) {
618 boot->NumFree++;
627 boot->NumFree++;
633 boot->NumFree++;
634 if (cl + 1 < boot->NumClusters
636 boot->NumFree++;
644 for (i = 0; i < boot->FATs; i++) {
645 off = boot->ResSectors + i * boot->FATsecs;
646 off *= boot->BytesPerSec;
661 checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat)
667 for (head = CLUST_FIRST; head < boot->NumClusters; head++) {
678 mod |= ret = reconnect(dosfs, boot, fat, head);
683 clearchain(boot, fat, head);
688 clearchain(boot, fat, head);
694 if (boot->FSInfo) {
696 if (boot->FSFree != boot->NumFree) {
698 boot->FSFree, boot->NumFree);
700 boot->FSFree = boot->NumFree;
705 if (boot->NumFree) {
706 if ((boot->FSNext >= boot->NumClusters) || (fat[boot->FSNext].next != CLUST_FREE)) {
708 boot->FSNext);
710 for (head = CLUST_FIRST; head < boot->NumClusters; head++)
712 boot->FSNext = head;
719 if (boot->FSNext > boot->NumClusters ) {
721 boot->FSNext, boot->NumClusters);
722 boot->FSNext=CLUST_FIRST; // boot->FSNext can have -1 value.
725 if (boot->NumFree && fat[boot->FSNext].next != CLUST_FREE) {
727 boot->FSNext);
729 for (head = CLUST_FIRST; head < boot->NumClusters; head++)
731 boot->FSNext = head;
738 mod |= writefsinfo(dosfs, boot);