diff --git a/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp b/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp index 370a3378a5..979838655c 100644 --- a/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp @@ -267,27 +267,11 @@ DirectoryCache::NotifyChanges(DirectoryCacheSnapshot* oldSnapshot, FileInfo fi; fi.fFileId = newCurrent->fNode; fi.fParent = fInode->fInfo.fHandle; - fi.fName = strdup(newCurrent->fName); - if (fi.fName == NULL) + status_t result = fi.CreateName(fInode->fInfo.fPath, + newCurrent->fName); + if (result != B_OK) break; - if (fInode->fInfo.fPath != NULL) { - size_t pathLength = strlen(newCurrent->fName) + 2 + - strlen(fInode->fInfo.fPath); - char* path = reinterpret_cast(pathLength); - if (path == NULL) - break; - - strcpy(path, fInode->fInfo.fPath); - strcat(path, "/"); - strcat(path, newCurrent->fName); - fi.fPath = path; - } else { - fi.fPath = strdup(newCurrent->fName); - if (fi.fPath == NULL) - break; - } - fInode->GetFileSystem()->InoIdMap()->AddEntry(fi, Inode::FileIdToInoT(newCurrent->fNode), true); } while (false); diff --git a/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp b/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp index 9ff0e49211..b33eaa42c4 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp @@ -46,6 +46,38 @@ FileInfo::ParsePath(RequestBuilder& req, uint32& count, const char* _path) } +status_t +FileInfo::CreateName(const char* dirPath, const char* name) +{ + free(const_cast(fName)); + fName = strdup(name); + if (fName == NULL) + return B_NO_MEMORY; + + if (dirPath != NULL) { + char* path = reinterpret_cast(malloc(strlen(name) + 2 + + strlen(dirPath))); + if (path == NULL) + return B_NO_MEMORY; + + strcpy(path, dirPath); + strcat(path, "/"); + strcat(path, name); + + free(const_cast(fPath)); + fPath = path; + } else { + free(const_cast(fPath)); + fPath = strdup(name); + } + + if (fPath == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + status_t FileInfo::UpdateFileHandles(FileSystem* fs) { @@ -56,7 +88,7 @@ FileInfo::UpdateFileHandles(FileSystem* fs) uint32 lookupCount = 0; status_t result; -dprintf("%s %s\n", fs->Path(), fPath); + result = ParsePath(req, lookupCount, fs->Path()); if (result != B_OK) return result; diff --git a/src/add-ons/kernel/file_systems/nfs4/FileInfo.h b/src/add-ons/kernel/file_systems/nfs4/FileInfo.h index ecacc0cace..4182dcc331 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileInfo.h +++ b/src/add-ons/kernel/file_systems/nfs4/FileInfo.h @@ -55,8 +55,10 @@ struct FileInfo { status_t UpdateFileHandles(FileSystem* fs); - static status_t ParsePath(RequestBuilder& req, uint32& count, + static status_t ParsePath(RequestBuilder& req, uint32& count, const char* _path); + + status_t CreateName(const char* dirPath, const char* name); }; struct FileSystemId { diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp index 2ff488e8de..d52409deb3 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp @@ -226,26 +226,9 @@ Inode::Link(Inode* dir, const char* name) FileInfo fi = fInfo; fi.fParent = dir->fInfo.fHandle; - free(const_cast(fi.fName)); - fi.fName = strdup(name); - if (fi.fName == NULL) - return B_NO_MEMORY; - - if (fInfo.fPath != NULL) { - char* path = reinterpret_cast(malloc(strlen(name) + 2 + - strlen(fInfo.fPath))); - if (path == NULL) - return B_NO_MEMORY; - - strcpy(path, fInfo.fPath); - strcat(path, "/"); - strcat(path, name); - fi.fPath = path; - } else { - fi.fPath = strdup(name); - if (fi.fPath == NULL) - return B_NO_MEMORY; - } + result = fi.CreateName(fInfo.fPath, name); + if (result != B_OK) + return result; fFileSystem->InoIdMap()->AddEntry(fi, fInfo.fFileId); @@ -315,7 +298,7 @@ Inode::Remove(const char* name, FileType type, ino_t* id) status_t Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName, - bool attribute) + bool attribute, ino_t* id) { if (from->fFileSystem != to->fFileSystem) return B_DONT_DO_THAT; @@ -342,8 +325,8 @@ Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName, ChangeInfo fromChange, toChange; uint64 fileID; - status_t result = NFS4Inode::Rename(from, to, fromName, toName, &fromChange, - &toChange, &fileID, attribute); + status_t result = NFS4Inode::RenameNode(from, to, fromName, toName, + &fromChange, &toChange, &fileID, attribute); if (result != B_OK) return result; @@ -360,6 +343,9 @@ Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName, cache->Unlock(); } + if (id != NULL) + *id = FileIdToInoT(fileID); + cache = attribute ? to->fAttrCache : to->fCache; if (cache->Lock() == B_OK) { if (toChange.fAtomic @@ -828,25 +814,9 @@ Inode::ChildAdded(const char* name, uint64 fileID, fi.fFileId = fileID; fi.fHandle = fileHandle; fi.fParent = fInfo.fHandle; - fi.fName = strdup(name); - if (fi.fName == NULL) - return B_NO_MEMORY; - - if (fInfo.fPath != NULL) { - char* path = reinterpret_cast(malloc(strlen(name) + 2 + - strlen(fInfo.fPath))); - if (path == NULL) - return B_NO_MEMORY; - - strcpy(path, fInfo.fPath); - strcat(path, "/"); - strcat(path, name); - fi.fPath = path; - } else { - fi.fPath = strdup(name); - if (fi.fPath == NULL) - return B_NO_MEMORY; - } + status_t result = fi.CreateName(fInfo.fPath, name); + if (result != B_OK) + return result; return fFileSystem->InoIdMap()->AddEntry(fi, FileIdToInoT(fileID)); } diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.h b/src/add-ons/kernel/file_systems/nfs4/Inode.h index 6c9e1fc9de..6a89c949e7 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Inode.h +++ b/src/add-ons/kernel/file_systems/nfs4/Inode.h @@ -58,10 +58,10 @@ public: status_t Link(Inode* dir, const char* name); status_t Remove(const char* name, FileType type, - ino_t* id); + ino_t* id = NULL); static status_t Rename(Inode* from, Inode* to, const char* fromName, const char* toName, - bool attribute = false); + bool attribute = false, ino_t* id = NULL); status_t Stat(struct stat* st, OpenAttrCookie* attr = NULL); diff --git a/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp b/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp index b677477963..756d49e44d 100644 --- a/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp @@ -38,17 +38,7 @@ Inode::CreateState(const char* name, int mode, int perms, OpenState* state, fi.fFileId = fileID; fi.fHandle = handle; fi.fParent = fInfo.fHandle; - fi.fName = strdup(name); - - if (fInfo.fPath != NULL) { - char* path = reinterpret_cast(malloc(strlen(name) + 2 + - strlen(fInfo.fPath))); - strcpy(path, fInfo.fPath); - strcat(path, "/"); - strcat(path, name); - fi.fPath = path; - } else - fi.fPath = strdup(name); + fi.CreateName(fInfo.fPath, name); fFileSystem->InoIdMap()->AddEntry(fi, FileIdToInoT(fileID)); diff --git a/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp b/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp index 3ae8de5beb..fa50569be9 100644 --- a/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp @@ -329,7 +329,7 @@ NFS4Inode::WriteStat(OpenState* state, AttrValue* attrs, uint32 attrCount) status_t -NFS4Inode::Rename(Inode* from, Inode* to, const char* fromName, +NFS4Inode::RenameNode(Inode* from, Inode* to, const char* fromName, const char* toName, ChangeInfo* fromChange, ChangeInfo* toChange, uint64* fileID, bool attribute) { diff --git a/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.h b/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.h index cd3c461c77..4aff6886c9 100644 --- a/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.h +++ b/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.h @@ -36,7 +36,7 @@ protected: status_t Link(Inode* dir, const char* name, ChangeInfo* changeInfo); - static status_t Rename(Inode* from, Inode* to, const char* fromName, + static status_t RenameNode(Inode* from, Inode* to, const char* fromName, const char* toName, ChangeInfo* fromChange, ChangeInfo* toChange, uint64* fileID, bool attribute = false); diff --git a/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp b/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp index c2e4b6ae17..9958fa02e6 100644 --- a/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp @@ -429,7 +429,21 @@ nfs4_rename(fs_volume* volume, fs_vnode* fromDir, const char* fromName, { Inode* fromInode = reinterpret_cast(fromDir->private_node); Inode* toInode = reinterpret_cast(toDir->private_node); - return Inode::Rename(fromInode, toInode, fromName, toName); + + ino_t id; + status_t result = Inode::Rename(fromInode, toInode, fromName, toName, false, + &id); + if (result != B_OK) + return result; + + Inode* child; + result = get_vnode(volume, id, reinterpret_cast(&child)); + if (result == B_OK) { + child->fInfo.fParent = toInode->fInfo.fHandle; + child->fInfo.CreateName(toInode->fInfo.fPath, toName); + } + + return B_OK; }