home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / mtools_3.6.src.lzh / MTOOLS_3.6 / fat_free.c < prev    next >
C/C++ Source or Header  |  1997-11-12  |  1KB  |  54 lines

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