-//-------------------------------------------------------------------------------
-// Routine: DeleteFile
-//
-// Function: De-allocates all disk space allocated to a specified file
-// including the space used by the catalog (ie the catalog record).
-// The space occupied by both forks is also deallocated.
-//
-//-------------------------------------------------------------------------------
-
-OSErr DeleteFile( ExtendedVCB *vcb, HFSCatalogNodeID parDirID, ConstUTF8Param catalogName, UInt32 catalogHint )
-{
- OSErr err;
- OSErr errDF, errRF;
- CatalogNodeData catalogData;
- Boolean recordDeleted;
-
- recordDeleted = false;
-
- INIT_CATALOGDATA(&catalogData, kCatNameNoCopyName);
-
- // Find catalog data in catalog
- err = GetCatalogNode( vcb, parDirID, catalogName, kUndefinedStrLen, catalogHint, &catalogData, &catalogHint);
- if( err != noErr )
- goto Exit;
-
-
- // Check to make sure record is for a file
- if ( catalogData.cnd_type != kCatalogFileNode )
- {
- err = notAFileErr;
- goto Exit;
- }
-
- //
- // Always delete the Catalog record first (to minimize disk corruption)
- //
- err = DeleteCatalogNode(vcb, parDirID, catalogName, catalogHint);
- if( err != noErr )
- goto Exit;
-
- //
- // Note: we don't report errors from DeallocateFork since the
- // file no longer exists (since DeleteCatalogNode succeeded).
- // Any errors mean that there are possibly some orphaned disk
- // blocks but from the clients perspective the file was deleted.
- //
-
- // Deallocate data fork extents
- errDF = DeallocateFork( vcb, catalogData.cnd_nodeID, kDataForkType,
- catalogData.cnd_datafork.extents, &recordDeleted );
-
- // Deallocate resource fork extents
- errRF = DeallocateFork( vcb, catalogData.cnd_nodeID, kResourceForkType,
- catalogData.cnd_rsrcfork.extents, &recordDeleted );
-
- if (recordDeleted)
- err = FlushExtentFile( vcb );
-
- CLEAN_CATALOGDATA(&catalogData);
- return (errDF ? errDF : (errRF ? errRF : err));
-Exit:
-
- CLEAN_CATALOGDATA(&catalogData);
- return( err );
-}