1 /* Copyright 1986-1992 Emmet P. Gray.
2 * Copyright 1996-1998,2001,2002,2009 Alain Knaff.
3 * This file is part of mtools.
5 * Mtools is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Mtools is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
19 #include "sysincludes.h"
22 #include "mtoolsDirentry.h"
25 * Remove a string of FAT entries (delete the file). The argument is
26 * the beginning of the string. Does not consider the file length, so
27 * if FAT is corrupted, watch out!
30 int fat_free(Stream_t *Dir, unsigned int fat)
32 Stream_t *Stream = GetFs(Dir);
34 unsigned int next_no_step;
35 /* a zero length file? */
39 while (!This->fat_error) {
40 /* get next cluster number */
41 next_no_step = fatDecode(This,fat);
42 /* mark current cluster as empty */
43 fatDeallocate(This,fat);
44 if (next_no_step >= This->last_fat)
51 int fatFreeWithDir(Stream_t *Dir, struct directory *dir)
55 if((!strncmp(dir->name,". ",8) ||
56 !strncmp(dir->name,".. ",8)) &&
57 !strncmp(dir->ext," ",3)) {
58 fprintf(stderr,"Trying to remove . or .. entry\n");
63 if(fat32RootCluster(Dir))
64 first |= STARTHI(dir) << 16;
65 return fat_free(Dir, first);
68 int fatFreeWithDirentry(direntry_t *entry)
70 return fatFreeWithDir(entry->Dir, &entry->dir);