Add Node::Init() flags parameter
* Add Node::Init() flags:
- NODE_FLAG_KEEP_NAME: Take over ownership of the name.
- NODE_FLAG_CONST_NAME: Don't copy the name -- it's a constant that
lives at least as long as the object.
* Remove Init() implementations in derived classes that just call the
base class version.
This commit is contained in:
@@ -31,13 +31,13 @@ Directory::~Directory()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Directory::Init(Directory* parent, const char* name)
|
Directory::Init(Directory* parent, const char* name, uint32 flags)
|
||||||
{
|
{
|
||||||
status_t error = fChildTable.Init();
|
status_t error = Node::Init(parent, name, flags);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
return Node::Init(parent, name);
|
return fChildTable.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ public:
|
|||||||
Directory(ino_t id);
|
Directory(ino_t id);
|
||||||
virtual ~Directory();
|
virtual ~Directory();
|
||||||
|
|
||||||
virtual status_t Init(Directory* parent, const char* name);
|
virtual status_t Init(Directory* parent, const char* name,
|
||||||
|
uint32 flags);
|
||||||
|
|
||||||
virtual status_t Read(off_t offset, void* buffer,
|
virtual status_t Read(off_t offset, void* buffer,
|
||||||
size_t* bufferSize);
|
size_t* bufferSize);
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ Node::Node(ino_t id)
|
|||||||
:
|
:
|
||||||
fID(id),
|
fID(id),
|
||||||
fParent(NULL),
|
fParent(NULL),
|
||||||
fName(NULL)
|
fName(NULL),
|
||||||
|
fFlags(0)
|
||||||
{
|
{
|
||||||
rw_lock_init(&fLock, "packagefs node");
|
rw_lock_init(&fLock, "packagefs node");
|
||||||
}
|
}
|
||||||
@@ -24,19 +25,28 @@ Node::Node(ino_t id)
|
|||||||
|
|
||||||
Node::~Node()
|
Node::~Node()
|
||||||
{
|
{
|
||||||
PRINT("%p->Node::~Node()\n", this);
|
if ((fFlags & NODE_FLAG_OWNS_NAME) != 0)
|
||||||
free(fName);
|
free(fName);
|
||||||
|
|
||||||
rw_lock_destroy(&fLock);
|
rw_lock_destroy(&fLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Node::Init(Directory* parent, const char* name)
|
Node::Init(Directory* parent, const char* name, uint32 flags)
|
||||||
{
|
{
|
||||||
fParent = parent;
|
fParent = parent;
|
||||||
fName = strdup(name);
|
fFlags = flags;
|
||||||
if (fName == NULL)
|
|
||||||
RETURN_ERROR(B_NO_MEMORY);
|
if ((flags & NODE_FLAG_CONST_NAME) != 0
|
||||||
|
|| (flags & NODE_FLAG_KEEP_NAME) != 0) {
|
||||||
|
fName = const_cast<char*>(name);
|
||||||
|
} else {
|
||||||
|
fName = strdup(name);
|
||||||
|
if (fName == NULL)
|
||||||
|
RETURN_ERROR(B_NO_MEMORY);
|
||||||
|
fFlags |= NODE_FLAG_OWNS_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,18 @@ class Directory;
|
|||||||
class PackageNode;
|
class PackageNode;
|
||||||
|
|
||||||
|
|
||||||
|
// node flags
|
||||||
|
enum {
|
||||||
|
NODE_FLAG_KEEP_NAME = 0x01,
|
||||||
|
// Init(): Take over ownership of the given name (i.e. free in
|
||||||
|
// destructor).
|
||||||
|
NODE_FLAG_CONST_NAME = 0x02,
|
||||||
|
// Init(): The given name is a constant that won't go away during the
|
||||||
|
// lifetime of the object. No need to copy.
|
||||||
|
NODE_FLAG_OWNS_NAME = NODE_FLAG_CONST_NAME
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Node : public BReferenceable, public DoublyLinkedListLinkImpl<Node> {
|
class Node : public BReferenceable, public DoublyLinkedListLinkImpl<Node> {
|
||||||
public:
|
public:
|
||||||
Node(ino_t id);
|
Node(ino_t id);
|
||||||
@@ -42,7 +54,10 @@ public:
|
|||||||
Node*& IDHashTableNext()
|
Node*& IDHashTableNext()
|
||||||
{ return fIDHashTableNext; }
|
{ return fIDHashTableNext; }
|
||||||
|
|
||||||
virtual status_t Init(Directory* parent, const char* name);
|
virtual status_t Init(Directory* parent, const char* name,
|
||||||
|
uint32 flags);
|
||||||
|
// If specified to keep the name, it does
|
||||||
|
// so also on error.
|
||||||
|
|
||||||
virtual status_t VFSInit(dev_t deviceID);
|
virtual status_t VFSInit(dev_t deviceID);
|
||||||
virtual void VFSUninit();
|
virtual void VFSUninit();
|
||||||
@@ -75,6 +90,7 @@ protected:
|
|||||||
char* fName;
|
char* fName;
|
||||||
Node* fNameHashTableNext;
|
Node* fNameHashTableNext;
|
||||||
Node* fIDHashTableNext;
|
Node* fIDHashTableNext;
|
||||||
|
uint32 fFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ PackageFSRoot::Init()
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t error = fPackageLinksDirectory->Init(NULL,
|
status_t error = fPackageLinksDirectory->Init(NULL,
|
||||||
kPackageLinksDirectoryName);
|
kPackageLinksDirectoryName, 0);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
RETURN_ERROR(error);
|
RETURN_ERROR(error);
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,6 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t Init(Directory* parent, const char* name)
|
|
||||||
{
|
|
||||||
return Node::Init(parent, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual mode_t Mode() const
|
virtual mode_t Mode() const
|
||||||
{
|
{
|
||||||
return S_IFLNK | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
|
return S_IFLNK | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
|
||||||
@@ -162,7 +157,7 @@ PackageLinkDirectory::Init(Directory* parent, Package* package)
|
|||||||
if (fSelfLink == NULL)
|
if (fSelfLink == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t error = fSelfLink->Init(this, kSelfLinkName);
|
status_t error = fSelfLink->Init(this, kSelfLinkName, NODE_FLAG_CONST_NAME);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
RETURN_ERROR(error);
|
RETURN_ERROR(error);
|
||||||
|
|
||||||
@@ -182,7 +177,6 @@ PackageLinkDirectory::Init(Directory* parent, Package* package)
|
|||||||
char* name = (char*)malloc(size);
|
char* name = (char*)malloc(size);
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
MemoryDeleter nameDeleter(name);
|
|
||||||
|
|
||||||
memcpy(name, package->Name(), nameLength + 1);
|
memcpy(name, package->Name(), nameLength + 1);
|
||||||
if (version != NULL) {
|
if (version != NULL) {
|
||||||
@@ -191,8 +185,7 @@ PackageLinkDirectory::Init(Directory* parent, Package* package)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init the directory/node
|
// init the directory/node
|
||||||
error = Init(parent, name);
|
error = Init(parent, name, NODE_FLAG_KEEP_NAME);
|
||||||
// TODO: This copies the name unnecessarily!
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
RETURN_ERROR(error);
|
RETURN_ERROR(error);
|
||||||
|
|
||||||
@@ -204,9 +197,9 @@ PackageLinkDirectory::Init(Directory* parent, Package* package)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PackageLinkDirectory::Init(Directory* parent, const char* name)
|
PackageLinkDirectory::Init(Directory* parent, const char* name, uint32 flags)
|
||||||
{
|
{
|
||||||
return Directory::Init(parent, name);
|
return Directory::Init(parent, name, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ public:
|
|||||||
virtual ~PackageLinkDirectory();
|
virtual ~PackageLinkDirectory();
|
||||||
|
|
||||||
status_t Init(Directory* parent, Package* package);
|
status_t Init(Directory* parent, Package* package);
|
||||||
virtual status_t Init(Directory* parent, const char* name);
|
virtual status_t Init(Directory* parent, const char* name,
|
||||||
|
uint32 flags);
|
||||||
|
|
||||||
virtual mode_t Mode() const;
|
virtual mode_t Mode() const;
|
||||||
virtual uid_t UserID() const;
|
virtual uid_t UserID() const;
|
||||||
|
|||||||
@@ -30,13 +30,6 @@ PackageLinksDirectory::~PackageLinksDirectory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
PackageLinksDirectory::Init(Directory* parent, const char* name)
|
|
||||||
{
|
|
||||||
return Directory::Init(parent, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
mode_t
|
mode_t
|
||||||
PackageLinksDirectory::Mode() const
|
PackageLinksDirectory::Mode() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ public:
|
|||||||
PackageLinksDirectory();
|
PackageLinksDirectory();
|
||||||
virtual ~PackageLinksDirectory();
|
virtual ~PackageLinksDirectory();
|
||||||
|
|
||||||
virtual status_t Init(Directory* parent, const char* name);
|
|
||||||
|
|
||||||
virtual mode_t Mode() const;
|
virtual mode_t Mode() const;
|
||||||
virtual uid_t UserID() const;
|
virtual uid_t UserID() const;
|
||||||
virtual gid_t GroupID() const;
|
virtual gid_t GroupID() const;
|
||||||
|
|||||||
@@ -27,13 +27,6 @@ UnpackingDirectory::~UnpackingDirectory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
UnpackingDirectory::Init(Directory* parent, const char* name)
|
|
||||||
{
|
|
||||||
return Directory::Init(parent, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
mode_t
|
mode_t
|
||||||
UnpackingDirectory::Mode() const
|
UnpackingDirectory::Mode() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ public:
|
|||||||
UnpackingDirectory(ino_t id);
|
UnpackingDirectory(ino_t id);
|
||||||
virtual ~UnpackingDirectory();
|
virtual ~UnpackingDirectory();
|
||||||
|
|
||||||
virtual status_t Init(Directory* parent, const char* name);
|
|
||||||
|
|
||||||
virtual mode_t Mode() const;
|
virtual mode_t Mode() const;
|
||||||
virtual uid_t UserID() const;
|
virtual uid_t UserID() const;
|
||||||
virtual gid_t GroupID() const;
|
virtual gid_t GroupID() const;
|
||||||
|
|||||||
@@ -27,13 +27,6 @@ UnpackingLeafNode::~UnpackingLeafNode()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
UnpackingLeafNode::Init(Directory* parent, const char* name)
|
|
||||||
{
|
|
||||||
return Node::Init(parent, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
UnpackingLeafNode::VFSInit(dev_t deviceID)
|
UnpackingLeafNode::VFSInit(dev_t deviceID)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ public:
|
|||||||
UnpackingLeafNode(ino_t id);
|
UnpackingLeafNode(ino_t id);
|
||||||
virtual ~UnpackingLeafNode();
|
virtual ~UnpackingLeafNode();
|
||||||
|
|
||||||
virtual status_t Init(Directory* parent, const char* name);
|
|
||||||
|
|
||||||
virtual status_t VFSInit(dev_t deviceID);
|
virtual status_t VFSInit(dev_t deviceID);
|
||||||
virtual void VFSUninit();
|
virtual void VFSUninit();
|
||||||
|
|
||||||
|
|||||||
@@ -511,7 +511,8 @@ Volume::Mount(const char* parameterString)
|
|||||||
= new(std::nothrow) ::RootDirectory(kRootDirectoryID, st.st_mtim);
|
= new(std::nothrow) ::RootDirectory(kRootDirectoryID, st.st_mtim);
|
||||||
if (fRootDirectory == NULL)
|
if (fRootDirectory == NULL)
|
||||||
RETURN_ERROR(B_NO_MEMORY);
|
RETURN_ERROR(B_NO_MEMORY);
|
||||||
fRootDirectory->Init(NULL, volumeName != NULL ? volumeName : "Package FS");
|
fRootDirectory->Init(NULL, volumeName != NULL ? volumeName : "Package FS",
|
||||||
|
0);
|
||||||
fNodes.Insert(fRootDirectory);
|
fNodes.Insert(fRootDirectory);
|
||||||
|
|
||||||
// get our mount point
|
// get our mount point
|
||||||
@@ -1101,7 +1102,7 @@ Volume::_CreateUnpackingNode(mode_t mode, Directory* parent, const char* name,
|
|||||||
Node* node = unpackingNode->GetNode();
|
Node* node = unpackingNode->GetNode();
|
||||||
BReference<Node> nodeReference(node, true);
|
BReference<Node> nodeReference(node, true);
|
||||||
|
|
||||||
status_t error = node->Init(parent, name);
|
status_t error = node->Init(parent, name, 0);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
RETURN_ERROR(error);
|
RETURN_ERROR(error);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user