From 16885aac6f2a31ea6ddefd53f14c6c8ab5ccc1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 9 Sep 2003 02:21:58 +0000 Subject: [PATCH] Made the Node base class better to use with files and directories, added Acquire()/Release() support as well. New Directory base class. Added basic support for file systems and the root file system, not yet fully working (no path parsing yet), and not yet tested. Implemented fstat(). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4591 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/boot/loader/vfs.cpp | 116 ++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/src/kernel/boot/loader/vfs.cpp b/src/kernel/boot/loader/vfs.cpp index 71e3e7d3ee..7e3e4a6941 100644 --- a/src/kernel/boot/loader/vfs.cpp +++ b/src/kernel/boot/loader/vfs.cpp @@ -4,12 +4,16 @@ */ +#include "Partition.h" +#include "RootFileSystem.h" + #include #include #include #include #include +#include #include @@ -23,6 +27,8 @@ class Descriptor { ssize_t WriteAt(off_t pos, const void *buffer, size_t bufferSize); ssize_t Write(const void *buffer, size_t bufferSize); + status_t Stat(struct stat &stat); + off_t Offset() const { return fOffset; } int32 RefCount() const { return fRefCount; } @@ -41,6 +47,7 @@ class Descriptor { list gBootDevices; list gPartitions; Descriptor *gDescriptors[MAX_VFS_DESCRIPTORS]; +Directory *gRoot; Node::Node() @@ -59,13 +66,51 @@ Node::~Node() status_t Node::Open(void **_cookie, int mode) { - return B_OK; + return Acquire(); } status_t Node::Close(void *cookie) { + return Release(); +} + + +status_t +Node::GetName(char *nameBuffer, size_t bufferSize) const +{ + return B_ERROR; +} + + +int32 +Node::Type() const +{ + return 0; +} + + +off_t +Node::Size() const +{ + return 0LL; +} + + +status_t +Node::Acquire() +{ + fRefCount++; + return B_OK; +} + +status_t +Node::Release() +{ + if (--fRefCount == 0) + delete this; + return B_OK; } @@ -96,6 +141,44 @@ ConsoleNode::Write(const void *buffer, size_t bufferSize) // #pragma mark - +Directory::Directory() + : Node() +{ +} + + +ssize_t +Directory::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) +{ + return B_ERROR; +} + + +ssize_t +Directory::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) +{ + return B_ERROR; +} + + +int32 +Directory::Type() const +{ + return S_IFDIR; +} + + +status_t +Directory::AddNode(Node */*node*/) +{ + // just don't do anything + return B_ERROR; +} + + +// #pragma mark - + + Descriptor::Descriptor(Node *node, void *cookie) : fNode(node), @@ -147,6 +230,16 @@ Descriptor::WriteAt(off_t pos, const void *buffer, size_t bufferSize) } +status_t +Descriptor::Stat(struct stat &stat) +{ + stat.st_mode = fNode->Type(); + stat.st_size = fNode->Size(); + + return B_OK; +} + + status_t Descriptor::Acquire() { @@ -158,7 +251,7 @@ Descriptor::Acquire() status_t Descriptor::Release() { - if (--fRefCount == 1) { + if (--fRefCount == 0) { status_t status = fNode->Close(fCookie); if (status != B_OK) return status; @@ -250,6 +343,12 @@ vfs_init(stage2_args *args) status_t mount_boot_file_systems() { + list_init_etc(&gPartitions, Partition::NextOffset()); + + gRoot = new RootFileSystem(); + if (gRoot == NULL) + return B_NO_MEMORY; + Node *device = NULL; while ((device = (Node *)list_get_next_item(&gBootDevices, (void *)device)) != NULL) { int fd = open_node(device, O_RDONLY); @@ -360,3 +459,16 @@ close(int fd) return status; } + +int +fstat(int fd, struct stat *stat) +{ + if (stat == NULL) + return B_BAD_VALUE; + + Descriptor *descriptor = get_descriptor(fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + return descriptor->Stat(*stat); +}