home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / ramfs102.zip / src / delete.c < prev    next >
C/C++ Source or Header  |  2002-03-21  |  2KB  |  91 lines

  1. #include "includes.h"
  2.  
  3.  
  4.  
  5. APIRET EXPENTRY FS_DELETE (
  6.     struct cdfsi *pcdfsi,
  7.     struct cdfsd *pcdfsd,
  8.     PSZ         pFile,
  9.     USHORT     iCurDirEnd )
  10. {
  11.   int       rc;
  12.   PVOLUME   pVolume;
  13.   DIRENTRY  Entry;
  14.   FLAT      flatEntry;
  15.   FLAT      flatBlkDir;
  16.   struct vpfsi *pvpfsi;
  17.   struct vpfsd *pvpfsd;
  18. #ifdef DEBUG
  19.   POPENFILE pCurOpenfile;
  20. #endif
  21.  
  22.   UtilEnterRamfs();
  23.   DEBUG_PRINTF1 ("FS_DELETE  pFile='%s'", pFile);
  24.  
  25.   FSH_GETVOLPARM (pcdfsi->cdi_hVPB, &pvpfsi, &pvpfsd);
  26.   pVolume = pvpfsd->pVolume;
  27.   flatBlkDir = pVolume->flatBlkRootDir;
  28.   pFile += 3;
  29.   if (iCurDirEnd != 0xFFFF)
  30.   {
  31.     flatBlkDir = pcdfsd->pCurdir->flatBlkDir;
  32.     pFile += iCurDirEnd-3;
  33.   }
  34.  
  35.   switch (UtilLocate (&flatBlkDir, &flatEntry, &Entry, pFile))
  36.   {
  37.     case LOC_NOPATH:       /* bad path */
  38.        rc = ERROR_PATH_NOT_FOUND;
  39.        break;
  40.  
  41.     case LOC_DIRENTRY:       /* attempted to delete a directory */
  42.        rc = ERROR_ACCESS_DENIED;
  43.        break;
  44.  
  45.     case LOC_NOENTRY:       /* file not found */
  46.        rc = ERROR_FILE_NOT_FOUND;
  47.        break;
  48.  
  49.     case LOC_FILEENTRY:       /* file exists */
  50. #ifdef DEBUG
  51.        /* check for any open instances of this file.
  52.           This isn't necessary because OS/2 only calls FS_DELETE if there
  53.           is no open instances. */
  54.        pCurOpenfile = pVolume->pFirstOpenfile;
  55.        while (pCurOpenfile != 0)
  56.        {
  57.          if (pCurOpenfile->flatEntry == flatEntry)
  58.          {
  59.            /* found an open instance of the file */
  60.            debugging = TRUE;
  61.            DEBUG_PRINTF1 ("\r\n!!! FS_DELETE Attempt to delete open file %s\r\n",
  62.                   pCurOpenfile->szName);
  63.            INT3;
  64.            rc = ERROR_SHARING_VIOLATION;
  65.            goto end;
  66.          }
  67.          pCurOpenfile = pCurOpenfile->pNextOpenfile;
  68.        }
  69. #endif
  70.  
  71.        if (Entry.fDOSattr & DOSATTR_READONLY)
  72.        {
  73.          /* attempted to delete a read-only file */
  74.          rc = ERROR_ACCESS_DENIED;
  75.          break;
  76.        }
  77.  
  78.        UtilDeleteEntry (pVolume, flatBlkDir, &Entry, flatEntry);
  79.        fblock_shutdown (&Entry.fblkFile);
  80.        BlockFree (&Entry.blkEA);
  81.        rc = NO_ERROR;
  82.        break;
  83.   }
  84.  
  85. end:
  86.  
  87.   DEBUG_PRINTF1 (" => %d\r\n", rc);
  88.   UtilExitRamfs();
  89.   return rc;
  90. }
  91.