diff --git a/NuFX/DirectoryEntry.cpp b/NuFX/DirectoryEntry.cpp new file mode 100644 index 0000000..cc99cef --- /dev/null +++ b/NuFX/DirectoryEntry.cpp @@ -0,0 +1,63 @@ +#include "DirectoryEntry.h" + +#include + +using namespace NuFX; + +EntryPointer DirectoryEntry::lookup(const std::string& name) const +{ + EntryIterator iter; + + for (iter = _children.begin(); iter != _children.end(); ++iter) + { + + EntryPointer e = *iter; + + if (e->name() == name) return e; + } + + return EntryPointer(); // empty. +} + +DirectoryEntryPointer DirectoryEntry::dir_lookup(const std::string &name) +{ + EntryIterator iter; + + for (iter = _children.begin(); iter != _children.end(); ++iter) + { + + EntryPointer e = *iter; + + if (e->name() == name) + { + // dynamic cast, will return as empty pointer if + // not a directory. + + return DYNAMIC_POINTER_CAST(DirectoryEntryPointer, e); + } + } + + // not found, insert it.. + + DirectoryEntryPointer e(new DirectoryEntryPointer(name)); + VolumeEntryPointer v = volume().lock(); + + _children.add(e); + + if (v) + { + v->addEntry(e); + } + + return e; +} + +#pragma mark - +#pragma mark fuse-support + +EntryPointer DirectoryEntry::childAtIndex(unsigned index) const +{ + if (index >= _children.size()) return EntryPointer(); + + return _children[index]; +} diff --git a/NuFX/DirectoryEntry.h b/NuFX/DirectoryEntry.h new file mode 100644 index 0000000..abcffb5 --- /dev/null +++ b/NuFX/DirectoryEntry.h @@ -0,0 +1,38 @@ +#ifndef __NUFX_DIRECTORYENTRY_H__ +#define __NUFX_DIRECTORYENTRY_H__ + +#include "Entry.h" + +#include +#include + +namespace NuFX { + + + class DirectoryEntry : public Entry + { + public: + + + EntryPointer lookup(const std::string & name) const; + + EntryPointer childAtIndex(unsigned index) const; + + + protected: + + // creates directory if it does not exist. + DirectoryEntryPointer dir_lookup(const std::string &name); + + private: + + + std::vector _children; + + typedef std::vector::iterator EntryIterator; + + }; +} + + +#endif \ No newline at end of file diff --git a/NuFX/Entry.cpp b/NuFX/Entry.cpp new file mode 100644 index 0000000..3f8408e --- /dev/null +++ b/NuFX/Entry.cpp @@ -0,0 +1,66 @@ +#include "Entry.h" +#include "Exception.h" + +using namespace NuFX; + + +Entry::Entry() : + _inode(0) +{ +} + +Entry::Entry(const std::string& name) : + _name(name), _inode(0) +{ +} + + +Entry::~Entry() +{ +} + + +unsigned Entry::inode() const +{ + return _inode; +} + +const std::string& Entry::name() const +{ + return _name; +} + +void Entry::setName(const std::string& name) +{ + _name = name; +} + +VolumeEntryWeakPointer Entry::volume() const +{ + return _volume; +} + +void Entry::setVolume(VolumeEntryWeakPointer volume) +{ + _volume = volume; +} + +int Entry::stat(struct stat *st) const +{ + return -1; +} + +ssize_t Entry::read(size_t size, off_t offset) const +{ + return -1; +} + +ssize_t Entry::listxattr(char *namebuf, size_t size, int options) const +{ + return -1; +} + +ssize_t Entry::getxattr(const std::string &name, void *value, size_t size, u_int32_t position, int options) const +{ + return -1; +} diff --git a/NuFX/Entry.h b/NuFX/Entry.h new file mode 100644 index 0000000..20c8320 --- /dev/null +++ b/NuFX/Entry.h @@ -0,0 +1,69 @@ +#ifndef __NUFX_ENTRY_H__ +#define __NUFX_ENTRY_H__ + + +#include + +#include +#include + + +#include +#include +#include +#include + +namespace NuFX { + + class DirectoryEntry; + class Entry; + class FileEntry; + class VolumeEntry; + + typedef SHARED_PTR(DirectoryEntry) DirectoryEntryPointer; + typedef SHARED_PTR(Entry) EntryPointer; + typedef SHARED_PTR(FileEntry) FileEntryPointer; + typedef SHARED_PTR(VolumeEntry) VolumeEntryPointer; + + typedef WEAK_PTR(Entry) EntryWeakPointer; + typedef WEAK_PTR(VolumeEntry) VolumeEntryWeakPointer; + + class Entry : public ENABLE_SHARED_FROM_THIS(Entry) { + + public: + + virtual ~Entry(); + + virtual unsigned inode() const; + virtual const std::string& name() const; + + + // operations... + virtual int stat(VolumeEntryPointer, struct stat *) const; + virtual ssize_t read(VolumeEntryPointer, size_t size, off_t offset) const; + virtual ssize_t listxattr(VolumeEntryPointer, char *namebuf, size_t size, int options) const; + virtual ssize_t getxattr(VolumeEntryPointer, const std::string &name, void *value, size_t size, u_int32_t position, int options) const; + + virtual int open(VolumeEntryPointer, int flags); + virtual int close(VolumeEntryPointer); + + + + protected: + Entry(); + Entry(const std::string& name); + + void setName(const std::string&); + + private: + Entry(const Entry&); + Entry& operator=(const Entry&); + + friend VolumeEntry; + + std::string _name; + unsigned _inode; + }; +} + +#endif \ No newline at end of file diff --git a/NuFX/FileEntry.h b/NuFX/FileEntry.h new file mode 100644 index 0000000..0963319 --- /dev/null +++ b/NuFX/FileEntry.h @@ -0,0 +1,23 @@ +#ifndef __NUFX_FILEENTRY_H__ +#define __NUFX_FILEENTRY_H__ + +#include "Entry.h" +#include + +namespace NuFX { + + + class FileEntry : public Entry + { + public: + + private: + + NuRecordIdx _recordID; + unsigned _flags; // threads + size_t _size; // data size + }; +} + + +#endif \ No newline at end of file diff --git a/NuFX/VolumeEntry.cpp b/NuFX/VolumeEntry.cpp new file mode 100644 index 0000000..116e2bb --- /dev/null +++ b/NuFX/VolumeEntry.cpp @@ -0,0 +1,14 @@ +#include "VolumeEntry.h" + +using namespace NuFX; + +void VolumeEntry::addEntry(EntryPointer e) +{ + if (!e) return; + + e->setVolume(pointer()); + + _inodeIndex->push_back(e); + + e->_inode = _inodeIndex->length() + 100 - 1; +} \ No newline at end of file diff --git a/NuFX/VolumeEntry.h b/NuFX/VolumeEntry.h new file mode 100644 index 0000000..540dbaa --- /dev/null +++ b/NuFX/VolumeEntry.h @@ -0,0 +1,35 @@ +#ifndef __NUFX_VOLUMEENTRY_H__ +#define __NUFX_VOLUMEENTRY_H__ + +#include "DirectoryEntry.h" + +#include + +namespace NuFX { + + + class VolumeEntry : public DirectoryEntry + { + public: + + void addEntry(EntryPointer); + + private: + + VolumeEntryPointer pointer() const + { + return STATIC_POINTER_CAST(VolumeEntryPointer, shared_from_this()); + } + + void parse(); + + NuArchive *_archive; + + //unsigned _inodeGenerator; + + std::vector _inodeIndex; + }; +} + + +#endif \ No newline at end of file