// Rename the specified File. VFS_BOOL VFS_File_Rename( const VFS_String& strFrom, const VFS_String& strTo ) // pszTo has to be a single File Name without a Path. { // 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( strFrom, 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 ); // Make the Target Name absolute. VFS_String strAbsoluteTo; VFS_Util_GetPath( strAbsoluteFileName, strAbsoluteTo ); strAbsoluteTo = WithoutTrailingSeparator( strAbsoluteTo, VFS_TRUE ) + VFS_PATH_SEPARATOR + strTo; // Try to rename the File. if( !VFS_RENAME( strAbsoluteFileName, strAbsoluteTo ) ) { SetLastError( VFS_ERROR_PERMISSION_DENIED ); return VFS_FALSE; } return VFS_TRUE; }
STATIC int base0fs_rename(inode_t *old_dir, struct dentry *old_dentry, inode_t *new_dir, struct dentry *new_dentry) { int err; struct dentry *lower_old_dentry; struct dentry *lower_new_dentry; struct dentry *lower_old_dir_dentry; struct dentry *lower_new_dir_dentry; print_entry_location(); lower_old_dentry = base0fs_lower_dentry(old_dentry);/* CPW: Moved below print_entry_location */ lower_new_dentry = base0fs_lower_dentry(new_dentry); fist_checkinode(old_dir, "base0fs_rename-old_dir"); fist_checkinode(new_dir, "base0fs_rename-new_dir"); dget(lower_old_dentry); dget(lower_new_dentry); lower_old_dir_dentry = dget_parent(lower_old_dentry); lower_new_dir_dentry = dget_parent(lower_new_dentry); lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); err = VFS_RENAME(lower_old_dir_dentry->d_inode, lower_old_dentry, lower_new_dir_dentry->d_inode, lower_new_dentry); if (err) goto out_lock; fist_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); if (new_dir != old_dir) fist_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); out_lock: // unlock_rename will dput the new/old parent dentries whose refcnts // were incremented via dget_parent above. dput(lower_new_dentry); dput(lower_old_dentry); unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); fist_checkinode(new_dir, "post base0fs_rename-new_dir"); print_exit_status(err); return err; }