[9] | 1 | #include "sysincludes.h"
|
---|
| 2 | #include "msdos.h"
|
---|
| 3 | #include "fsP.h"
|
---|
| 4 | #include "mtoolsDirent.h"
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Remove a string of FAT entries (delete the file). The argument is
|
---|
| 8 | * the beginning of the string. Does not consider the file length, so
|
---|
| 9 | * if FAT is corrupted, watch out!
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | int fat_free(Stream_t *Dir, unsigned int fat)
|
---|
| 13 | {
|
---|
| 14 | Stream_t *Stream = GetFs(Dir);
|
---|
| 15 | DeclareThis(Fs_t);
|
---|
| 16 | unsigned int next_no_step;
|
---|
| 17 | /* a zero length file? */
|
---|
| 18 | if (fat == 0)
|
---|
| 19 | return(0);
|
---|
| 20 |
|
---|
| 21 | /* CONSTCOND */
|
---|
| 22 | while (!This->fat_error) {
|
---|
| 23 | /* get next cluster number */
|
---|
| 24 | next_no_step = fatDecode(This,fat);
|
---|
| 25 | /* mark current cluster as empty */
|
---|
| 26 | fatDeallocate(This,fat);
|
---|
| 27 | if (next_no_step >= This->last_fat)
|
---|
| 28 | break;
|
---|
| 29 | fat = next_no_step;
|
---|
| 30 | }
|
---|
| 31 | return(0);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | int fatFreeWithDir(Stream_t *Dir, struct directory *dir)
|
---|
| 35 | {
|
---|
| 36 | unsigned int first;
|
---|
| 37 |
|
---|
| 38 | if((!strncmp(dir->name,". ",8) ||
|
---|
| 39 | !strncmp(dir->name,".. ",8)) &&
|
---|
| 40 | !strncmp(dir->ext," ",3)) {
|
---|
| 41 | fprintf(stderr,"Trying to remove . or .. entry\n");
|
---|
| 42 | return -1;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | first = START(dir);
|
---|
| 46 | if(fat32RootCluster(Dir))
|
---|
| 47 | first |= STARTHI(dir) << 16;
|
---|
| 48 | return fat_free(Dir, first);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | int fatFreeWithDirentry(direntry_t *entry)
|
---|
| 52 | {
|
---|
| 53 | return fatFreeWithDir(entry->Dir, &entry->dir);
|
---|
| 54 | }
|
---|
| 55 |
|
---|