STATIC int base0fs_unlink(inode_t *dir, struct dentry *dentry) { int err = 0; inode_t *lower_dir; struct dentry *lower_dentry; struct dentry *lower_dir_dentry; print_entry_location(); lower_dir = INODE_TO_LOWER(dir); /* CPW: Moved below print_entry_location */ lower_dentry = base0fs_lower_dentry(dentry); BUG_ON(!lower_dentry); fist_checkinode(dir, "base0fs_unlink-dir"); dget(dentry); lower_dir_dentry = base0fs_lock_parent(lower_dentry); /* avoid destroying the lower inode if the file is in use */ dget(lower_dentry); err = VFS_UNLINK(lower_dir, lower_dentry); dput(lower_dentry); if (!err) /* vfs_unlink does that */ d_delete(lower_dentry); out_lock: fist_copy_attr_times(dir, lower_dir); /* propagate number of hard-links */ dentry->d_inode->i_nlink = INODE_TO_LOWER(dentry->d_inode)->i_nlink; fist_copy_attr_ctime(dentry->d_inode, dir); unlock_dir(lower_dir_dentry); /* * call d_drop so the system "forgets" about us */ if (!err) { d_drop(dentry); } dput(dentry); fist_checkinode(dir, "post base0fs_unlink-dir"); print_exit_status(err); return err; }
// Delete the File with the specified File Name. VFS_BOOL VFS_File_Delete( const VFS_String& strFileName ) { // Not initialized yet? if( !IsInit() ) { SetLastError( VFS_ERROR_NOT_INITIALIZED_YET ); return VFS_FALSE; } // Try to open the file to get the absolute file name and to see if the file is still open // and if it's not in an Archive (VFS_WRITE would fail otherwise). VFS_Handle hFile = VFS_File_Open( strFileName, VFS_READ | VFS_WRITE ); if( hFile == VFS_INVALID_HANDLE_VALUE ) return VFS_FALSE; // Get the File Pointer. IFile* pFile = ( IFile* )( VFS_DWORD )hFile; // Check if there are still references to the File (but count ourself). if( pFile->GetRefCount() > 1 ) { // Close the File. VFS_File_Close( hFile ); SetLastError( VFS_ERROR_IN_USE ); return VFS_FALSE; } // Get the absolute File Name. VFS_String strAbsoluteFileName = pFile->GetFileName(); // Close the File. VFS_File_Close( hFile ); // Try to delete the File. if( !VFS_UNLINK( strAbsoluteFileName ) ) { SetLastError( VFS_ERROR_PERMISSION_DENIED ); return VFS_FALSE; } return VFS_TRUE; }