Remove kernel_interface.cpp LeafNode dependency
Introduce abstract virtual Node::ReadSymlink() method that is now used in packagefs_read_symlink() instead of casting to LeafNode.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2009-2011, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -164,6 +164,13 @@ Directory::Read(io_request* request)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Directory::ReadSymlink(void* buffer, size_t* bufferSize)
|
||||
{
|
||||
return B_IS_A_DIRECTORY;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Directory::AddChild(Node* node)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2009-2011, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef DIRECTORY_H
|
||||
@@ -48,6 +48,9 @@ public:
|
||||
size_t* bufferSize);
|
||||
virtual status_t Read(io_request* request);
|
||||
|
||||
virtual status_t ReadSymlink(void* buffer,
|
||||
size_t* bufferSize);
|
||||
|
||||
void AddChild(Node* node);
|
||||
void RemoveChild(Node* node);
|
||||
Node* FindChild(const char* name);
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2009-2011, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "LeafNode.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
@@ -168,6 +172,27 @@ LeafNode::Read(io_request* request)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LeafNode::ReadSymlink(void* buffer, size_t* bufferSize)
|
||||
{
|
||||
PackageLeafNode* packageNode = fPackageNodes.Head();
|
||||
if (packageNode == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
const char* linkPath = packageNode->SymlinkPath();
|
||||
if (linkPath == NULL) {
|
||||
*bufferSize = 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
size_t toCopy = std::min(strlen(linkPath), *bufferSize);
|
||||
memcpy(buffer, linkPath, toCopy);
|
||||
*bufferSize = toCopy;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
LeafNode::SymlinkPath() const
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2009-2011, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef LEAF_NODE_H
|
||||
@@ -35,6 +35,9 @@ public:
|
||||
size_t* bufferSize);
|
||||
virtual status_t Read(io_request* request);
|
||||
|
||||
virtual status_t ReadSymlink(void* buffer,
|
||||
size_t* bufferSize);
|
||||
|
||||
const char* SymlinkPath() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2009-2011, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef NODE_H
|
||||
@@ -60,6 +60,9 @@ public:
|
||||
size_t* bufferSize) = 0;
|
||||
virtual status_t Read(io_request* request) = 0;
|
||||
|
||||
virtual status_t ReadSymlink(void* buffer,
|
||||
size_t* bufferSize) = 0;
|
||||
|
||||
protected:
|
||||
rw_lock fLock;
|
||||
ino_t fID;
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "DebugSupport.h"
|
||||
#include "Directory.h"
|
||||
#include "GlobalFactory.h"
|
||||
#include "LeafNode.h"
|
||||
#include "PackageFSRoot.h"
|
||||
#include "Volume.h"
|
||||
|
||||
@@ -315,17 +314,7 @@ packagefs_read_symlink(fs_volume* fsVolume, fs_vnode* fsNode, char* buffer,
|
||||
if (!S_ISLNK(node->Mode()))
|
||||
return B_BAD_VALUE;
|
||||
|
||||
const char* linkPath = dynamic_cast<LeafNode*>(node)->SymlinkPath();
|
||||
if (linkPath == NULL) {
|
||||
*_bufferSize = 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
size_t toCopy = std::min(strlen(linkPath), *_bufferSize);
|
||||
memcpy(buffer, linkPath, toCopy);
|
||||
*_bufferSize = toCopy;
|
||||
|
||||
return B_OK;
|
||||
return node->ReadSymlink(buffer, _bufferSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user