From b093987a7bc63250dc7c9bc92552579190beaa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 14 Oct 2005 09:23:00 +0000 Subject: [PATCH] tarfs is now maintaining a node ID and got all methods that its entries are statable. Renamed TarFS::Node to TarFS::File to correctly name the class hierarchy. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14376 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../boot/loader/file_systems/tarfs/tarfs.cpp | 74 +++++++++++++++---- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/system/boot/loader/file_systems/tarfs/tarfs.cpp b/src/system/boot/loader/file_systems/tarfs/tarfs.cpp index 9dc9493c9f..ebe452a449 100644 --- a/src/system/boot/loader/file_systems/tarfs/tarfs.cpp +++ b/src/system/boot/loader/file_systems/tarfs/tarfs.cpp @@ -55,7 +55,7 @@ class Directory; class Entry : public DoublyLinkedListLinkImpl { public: - Entry(const char *name) : fName(name) {} + Entry(const char *name); virtual ~Entry() {} const char *Name() const { return fName; } @@ -64,6 +64,7 @@ class Entry : public DoublyLinkedListLinkImpl { protected: const char *fName; + int32 fID; }; @@ -71,16 +72,20 @@ typedef DoublyLinkedList EntryList; typedef EntryList::Iterator EntryIterator; -class Node : public ::Node, public Entry { +class File : public ::Node, public Entry { public: - Node(tar_header *header, const char *name); - virtual ~Node(); + File(tar_header *header, const char *name); + virtual ~File(); virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); virtual status_t GetName(char *nameBuffer, size_t bufferSize) const; + virtual int32 Type() const; + virtual off_t Size() const; + virtual ino_t Inode() const; + virtual ::Node *ToNode() { return this; } private: @@ -100,13 +105,15 @@ class Directory : public ::Directory, public Entry { virtual status_t GetName(char *nameBuffer, size_t bufferSize) const; virtual TarFS::Entry *LookupEntry(const char *name); - virtual Node *Lookup(const char *name, bool traverseLinks); + virtual ::Node *Lookup(const char *name, bool traverseLinks); virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize); virtual status_t GetNextNode(void *cookie, Node **_node); virtual status_t Rewind(void *cookie); virtual bool IsEmpty(); + virtual ino_t Inode() const; + virtual ::Node *ToNode() { return this; }; virtual TarFS::Directory *ToTarDirectory() { return this; } @@ -131,7 +138,8 @@ class Volume : public TarFS::Directory { } // namespace TarFS -//using namespace TarFS; + +static int32 sNextID = 1; // #pragma mark - @@ -186,22 +194,32 @@ skip_gzip_header(z_stream *stream) // #pragma mark - -TarFS::Node::Node(tar_header *header, const char *name) +TarFS::Entry::Entry(const char *name) : - TarFS::Entry(name), + fName(name), + fID(sNextID++) +{ +} + + +// #pragma mark - + + +TarFS::File::File(tar_header *header, const char *name) + : TarFS::Entry(name), fHeader(header) { fSize = strtol(header->size, NULL, 8); } -TarFS::Node::~Node() +TarFS::File::~File() { } ssize_t -TarFS::Node::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) +TarFS::File::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) { TRACE(("tarfs: read at %Ld, %lu bytes, fSize = %Ld\n", pos, bufferSize, fSize)); @@ -222,19 +240,40 @@ TarFS::Node::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) ssize_t -TarFS::Node::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) +TarFS::File::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) { return B_NOT_ALLOWED; } status_t -TarFS::Node::GetName(char *nameBuffer, size_t bufferSize) const +TarFS::File::GetName(char *nameBuffer, size_t bufferSize) const { return strlcpy(nameBuffer, Name(), bufferSize) >= bufferSize ? B_BUFFER_OVERFLOW : B_OK; } +int32 +TarFS::File::Type() const +{ + return S_IFREG; +} + + +off_t +TarFS::File::Size() const +{ + return fSize; +} + + +ino_t +TarFS::File::Inode() const +{ + return fID; +} + + // #pragma mark - TarFS::Directory::Directory(const char *name) @@ -416,8 +455,8 @@ TarFS::Directory::AddFile(tar_header *header) return error; } - // create the node - TarFS::Node *file = new TarFS::Node(header, leaf); + // create the file + TarFS::File *file = new TarFS::File(header, leaf); if (!file) return B_NO_MEMORY; @@ -434,6 +473,13 @@ TarFS::Directory::IsEmpty() } +ino_t +TarFS::Directory::Inode() const +{ + return fID; +} + + // #pragma mark -