1: #include <stdio.h> 2: #include "msdos.h" 3: 4: extern int fat_error; 5: extern unsigned int last_fat; 6: 7: /* 8: * Remove a string of FAT entries (delete the file). The argument is 9: * the beginning of the string. Does not consider the file length, so 10: * if FAT is corrupted, watch out! 11: */ 12: 13: int 14: fat_free(fat) 15: unsigned int fat; 16: { 17: unsigned int next, fat_decode(); 18: /* a zero length file? */ 19: if (fat == 0) 20: return(0); 21: 22: /* CONSTCOND */ 23: while (1) { 24: /* get next cluster number */ 25: next = fat_decode(fat); 26: /* mark current cluster as empty */ 27: if (fat_encode(fat, 0) || next == 1) { 28: fprintf(stderr, "fat_free: FAT problem\n"); 29: fat_error++; 30: return(-1); 31: } 32: if (next >= last_fat) 33: break; 34: fat = next; 35: } 36: return(0); 37: }