Lines Matching defs:fat

29 __RCSID("$NetBSD: fat.c,v 1.18 2006/06/05 16:51:18 christos Exp $");
31 "$FreeBSD: releng/11.0/sbin/fsck_msdosfs/fat.c 268632 2014-07-14 20:58:02Z pfg $";
133 checkclnum(struct bootblock *boot, u_int fat, cl_t cl, cl_t *next)
148 cl, fat,
202 struct fatEntry *fat;
213 fat = malloc(len = boot->NumClusters * sizeof(struct fatEntry));
214 if (fat == NULL) {
219 (void)memset(fat, 0, len);
284 fat[cl].next = p[0] + (p[1] << 8)
286 fat[cl].next &= boot->ClustMask;
287 ret |= checkclnum(boot, no, cl, &fat[cl].next);
292 fat[cl].next = p[0] + (p[1] << 8);
293 ret |= checkclnum(boot, no, cl, &fat[cl].next);
298 fat[cl].next = (p[0] + (p[1] << 8)) & 0x0fff;
299 ret |= checkclnum(boot, no, cl, &fat[cl].next);
303 fat[cl].next = ((p[1] >> 4) + (p[2] << 4)) & 0x0fff;
304 ret |= checkclnum(boot, no, cl, &fat[cl].next);
313 free(fat);
316 *fp = fat;
419 clearchain(struct bootblock *boot, struct fatEntry *fat, cl_t head)
424 if (fat[p].head != head)
426 q = fat[p].next;
427 fat[p].next = fat[p].head = CLUST_FREE;
428 fat[p].length = 0;
433 tryclear(struct bootblock *boot, struct fatEntry *fat, cl_t head, cl_t *truncp)
436 clearchain(boot, fat, head);
444 p = fat[p].next, len++)
447 fat[head].length = len;
457 checkfat(struct bootblock *boot, struct fatEntry *fat)
469 if (fat[head].head != 0 /* cluster already belongs to some chain */
470 || fat[head].next == CLUST_FREE
471 || fat[head].next == CLUST_BAD)
477 fat[p].head != head;
478 p = fat[p].next) {
479 fat[p].head = head;
484 fat[head].length = fat[head].next == CLUST_FREE ? 0 : len;
494 if (fat[head].head != head)
498 for (len = fat[head].length, p = head;
499 (n = fat[p].next) >= CLUST_FIRST && n < boot->NumClusters;
501 if (fat[n].head != head || len-- < 2)
510 ret |= tryclear(boot, fat, head, &fat[p].next);
518 if (head == fat[n].head) {
525 head, fat[n].head, n);
526 conf = tryclear(boot, fat, head, &fat[p].next);
527 if (ask(0, "Clear chain starting at %u", h = fat[n].head)) {
534 p = fat[p].next) {
535 if (h != fat[p].head) {
542 fat[p].head = head;
545 clearchain(boot, fat, h);
558 writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
622 if (fat[cl].next == CLUST_FREE)
624 *p++ = (u_char)fat[cl].next;
625 *p++ = (u_char)(fat[cl].next >> 8);
626 *p++ = (u_char)(fat[cl].next >> 16);
628 *p++ |= (fat[cl].next >> 24)&0x0f;
631 if (fat[cl].next == CLUST_FREE)
633 *p++ = (u_char)fat[cl].next;
634 *p++ = (u_char)(fat[cl].next >> 8);
637 if (fat[cl].next == CLUST_FREE)
639 *p++ = (u_char)fat[cl].next;
640 *p = (u_char)((fat[cl].next >> 8) & 0xf);
644 if (fat[cl].next == CLUST_FREE)
646 *p++ |= (u_char)(fat[cl + 1].next << 4);
647 *p++ = (u_char)(fat[cl + 1].next >> 4);
668 checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat)
676 if (fat[head].head != head
677 || fat[head].next == CLUST_FREE
678 || (fat[head].next >= CLUST_RSRVD
679 && fat[head].next < CLUST_EOFS)
680 || (fat[head].flags & FAT_USED))
684 head, fat[head].length);
685 mod |= ret = reconnect(dosfs, boot, fat, head);
689 clearchain(boot, fat, head);