nfs4: Fix several problems with emulated attributes

This commit is contained in:
Pawel Dziepak
2012-08-17 01:14:30 +02:00
parent e8c12d9410
commit da950cb2ef
5 changed files with 39 additions and 11 deletions
@@ -12,6 +12,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <AutoDeleter.h>
#include <fs_cache.h> #include <fs_cache.h>
#include <NodeMonitor.h> #include <NodeMonitor.h>
@@ -267,10 +268,16 @@ Inode::Link(Inode* dir, const char* name)
status_t status_t
Inode::Remove(const char* name, FileType type) Inode::Remove(const char* name, FileType type)
{ {
MemoryDeleter nameDeleter;
if (type == NF4NAMEDATTR) { if (type == NF4NAMEDATTR) {
status_t result = LoadAttrDirHandle(); status_t result = LoadAttrDirHandle();
if (result != B_OK) if (result != B_OK)
return result; return result;
name = AttrToFileName(name);
if (name == NULL)
return B_NO_MEMORY;
nameDeleter.SetTo(const_cast<char*>(name));
} }
ChangeInfo changeInfo; ChangeInfo changeInfo;
@@ -311,6 +318,8 @@ Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName,
if (from->fFileSystem != to->fFileSystem) if (from->fFileSystem != to->fFileSystem)
return B_DONT_DO_THAT; return B_DONT_DO_THAT;
MemoryDeleter fromNameDeleter;
MemoryDeleter toNameDeleter;
if (attribute) { if (attribute) {
status_t result = from->LoadAttrDirHandle(); status_t result = from->LoadAttrDirHandle();
if (result != B_OK) if (result != B_OK)
@@ -319,6 +328,14 @@ Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName,
result = to->LoadAttrDirHandle(); result = to->LoadAttrDirHandle();
if (result != B_OK) if (result != B_OK)
return result; return result;
fromName = from->AttrToFileName(fromName);
toName = to->AttrToFileName(toName);
fromNameDeleter.SetTo(const_cast<char*>(fromName));
toNameDeleter.SetTo(const_cast<char*>(toName));
if (fromName == NULL || toName == NULL)
return B_NO_MEMORY;
} }
ChangeInfo fromChange, toChange; ChangeInfo fromChange, toChange;
@@ -132,6 +132,8 @@ protected:
status_t GetStat(struct stat* st, status_t GetStat(struct stat* st,
OpenAttrCookie* attr = NULL); OpenAttrCookie* attr = NULL);
char* AttrToFileName(const char* path);
static inline status_t CheckLockType(short ltype, uint32 mode); static inline status_t CheckLockType(short ltype, uint32 mode);
private: private:
@@ -85,11 +85,11 @@ Inode::LoadAttrDirHandle()
return B_UNSUPPORTED; return B_UNSUPPORTED;
char* attrDir char* attrDir
= reinterpret_cast<char*>(malloc(strlen(fInfo.fName) + 32)); = reinterpret_cast<char*>(malloc(strlen(Name()) + 32));
if (attrDir == NULL) if (attrDir == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
strcpy(attrDir, "."); strcpy(attrDir, ".");
strcat(attrDir, fInfo.fName); strcat(attrDir, Name());
strcat(attrDir, "-haiku-attrs"); strcat(attrDir, "-haiku-attrs");
result = NFS4Inode::LookUp(attrDir, NULL, NULL, &handle, true); result = NFS4Inode::LookUp(attrDir, NULL, NULL, &handle, true);
@@ -40,12 +40,15 @@ Inode::CreateState(const char* name, int mode, int perms, OpenState* state,
fi.fParent = fInfo.fHandle; fi.fParent = fInfo.fHandle;
fi.fName = strdup(name); fi.fName = strdup(name);
char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2 + if (fInfo.fPath != NULL) {
strlen(fInfo.fPath))); char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2 +
strcpy(path, fInfo.fPath); strlen(fInfo.fPath)));
strcat(path, "/"); strcpy(path, fInfo.fPath);
strcat(path, name); strcat(path, "/");
fi.fPath = path; strcat(path, name);
fi.fPath = path;
} else
fi.fPath = strdup(name);
fFileSystem->InoIdMap()->AddEntry(fi, FileIdToInoT(fileID)); fFileSystem->InoIdMap()->AddEntry(fi, FileIdToInoT(fileID));
@@ -193,8 +196,8 @@ Inode::Close(OpenFileCookie* cookie)
} }
static char* char*
AttrToFileName(const char* path) Inode::AttrToFileName(const char* path)
{ {
char* name = strdup(path); char* name = strdup(path);
if (name == NULL) if (name == NULL)
@@ -126,7 +126,13 @@ RootInode::_UpdateInfo(bool force)
break; break;
} while (true); } while (true);
fInfoCache.flags = 0; fInfoCache.flags = B_FS_IS_PERSISTENT | B_FS_IS_SHARED
| B_FS_SUPPORTS_NODE_MONITORING;
if (fFileSystem->NamedAttrs()
|| fFileSystem->GetConfiguration().fEmulateNamedAttrs)
fInfoCache.flags |= B_FS_HAS_MIME | B_FS_HAS_ATTR;
strncpy(fInfoCache.volume_name, fName, B_FILE_NAME_LENGTH); strncpy(fInfoCache.volume_name, fName, B_FILE_NAME_LENGTH);
fInfoCacheExpire = time(NULL) + MetadataCache::kExpirationTime; fInfoCacheExpire = time(NULL) + MetadataCache::kExpirationTime;