Boot loader: Add get_stat(), directory_from()

* Add Node::Stat() and simplify Descriptor::Stat().
* Add get_stat() and directory_from().
This commit is contained in:
Ingo Weinhold
2014-04-18 23:31:39 +02:00
parent 2f019bd6ca
commit 59ae1c816d
2 changed files with 44 additions and 9 deletions
+9 -1
View File
@@ -17,6 +17,7 @@
#ifdef __cplusplus #ifdef __cplusplus
struct file_map_run; struct file_map_run;
struct stat;
/** This is the base class for all VFS nodes */ /** This is the base class for all VFS nodes */
@@ -41,6 +42,8 @@ class Node : public DoublyLinkedListLinkImpl<Node> {
virtual off_t Size() const; virtual off_t Size() const;
virtual ino_t Inode() const; virtual ino_t Inode() const;
void Stat(struct stat& stat);
status_t Acquire(); status_t Acquire();
status_t Release(); status_t Release();
@@ -149,8 +152,13 @@ extern int open_node(Node *node, int mode);
extern int open_from(Directory *directory, const char *path, int mode, extern int open_from(Directory *directory, const char *path, int mode,
mode_t permissions = 0); mode_t permissions = 0);
extern DIR* open_directory(Directory* baseDirectory, const char* path); extern DIR* open_directory(Directory* baseDirectory, const char* path);
extern status_t get_stat(Directory* directory, const char* path,
struct stat& st);
extern Node *get_node_from(int fd); extern Node* get_node_from(int fd);
// returns a reference
extern Directory* directory_from(DIR* dir);
// does not return a reference
extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false); extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false);
extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false); extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false);
+35 -8
View File
@@ -55,7 +55,7 @@ class Descriptor {
ssize_t WriteAt(off_t pos, const void *buffer, size_t bufferSize); ssize_t WriteAt(off_t pos, const void *buffer, size_t bufferSize);
ssize_t Write(const void *buffer, size_t bufferSize); ssize_t Write(const void *buffer, size_t bufferSize);
status_t Stat(struct stat &stat); void Stat(struct stat &stat);
off_t Offset() const { return fOffset; } off_t Offset() const { return fOffset; }
int32 RefCount() const { return fRefCount; } int32 RefCount() const { return fRefCount; }
@@ -151,6 +151,15 @@ Node::Inode() const
} }
void
Node::Stat(struct stat& stat)
{
stat.st_mode = Type();
stat.st_size = Size();
stat.st_ino = Inode();
}
status_t status_t
Node::Acquire() Node::Acquire()
{ {
@@ -374,14 +383,10 @@ Descriptor::WriteAt(off_t pos, const void *buffer, size_t bufferSize)
} }
status_t void
Descriptor::Stat(struct stat &stat) Descriptor::Stat(struct stat &stat)
{ {
stat.st_mode = fNode->Type(); fNode->Stat(stat);
stat.st_size = fNode->Size();
stat.st_ino = fNode->Inode();
return B_OK;
} }
@@ -999,6 +1004,27 @@ get_node_from(int fd)
} }
status_t
get_stat(Directory* directory, const char* path, struct stat& st)
{
Node* node;
status_t error = get_node_for_path(directory, path, &node);
if (error != B_OK)
return error;
node->Stat(st);
node->Release();
return B_OK;
}
Directory*
directory_from(DIR* dir)
{
return dir != NULL ? dir->directory : NULL;
}
int int
close(int fd) close(int fd)
{ {
@@ -1029,7 +1055,8 @@ fstat(int fd, struct stat *stat)
if (descriptor == NULL) if (descriptor == NULL)
RETURN_AND_SET_ERRNO(B_FILE_ERROR); RETURN_AND_SET_ERRNO(B_FILE_ERROR);
RETURN_AND_SET_ERRNO(descriptor->Stat(*stat)); descriptor->Stat(*stat);
return 0;
} }