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"
21 #include "mtoolsDirentry.h"
24 * Remove a string of FAT entries (delete the file). The argument is
25 * the beginning of the string. Does not consider the file length, so
26 * if FAT is corrupted, watch out!
29 int fat_free(Stream_t *Dir, unsigned int fat)
31 Stream_t *Stream = GetFs(Dir);
33 unsigned int next_no_step;
34 /* a zero length file? */
38 while (!This->fat_error) {
39 /* get next cluster number */
40 next_no_step = fatDecode(This,fat);
41 /* mark current cluster as empty */
42 fatDeallocate(This,fat);
43 if (next_no_step >= This->last_fat)
50 int fatFreeWithDir(Stream_t *Dir, struct directory *dir)
54 if((!strncmp(dir->name,". ",8) ||
55 !strncmp(dir->name,".. ",8)) &&
56 !strncmp(dir->ext," ",3)) {
57 fprintf(stderr,"Trying to remove . or .. entry\n");
62 if(fat32RootCluster(Dir))
63 first |= (uint32_t) STARTHI(dir) << 16;
64 return fat_free(Dir, first);
67 int fatFreeWithDirentry(direntry_t *entry)
69 return fatFreeWithDir(entry->Dir, &entry->dir);