diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-17 13:30:09 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-17 13:30:09 +0200 |
commit | 7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef (patch) | |
tree | df44a926f105c913c77525d35441d20a632f1440 /src/kernel/vfs/vdir.cpp | |
parent | c6d35a5f4fdda6ae2e98498f19a4adaee6d95692 (diff) | |
download | TCE-7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef.tar.gz TCE-7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef.zip |
Beginning of a VFS implemented. C++ is great.
Diffstat (limited to 'src/kernel/vfs/vdir.cpp')
-rw-r--r-- | src/kernel/vfs/vdir.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/kernel/vfs/vdir.cpp b/src/kernel/vfs/vdir.cpp new file mode 100644 index 0000000..299c0e7 --- /dev/null +++ b/src/kernel/vfs/vdir.cpp @@ -0,0 +1,55 @@ +#include "vdir.h" + +vdir::vdir(node* parent) : node(parent, FT_DIR), children(8, 64) { + children.add(new vdir_child(".", this)); + child_count = 1; + + if (parent != 0) { + children.add(new vdir_child("..", parent)); + child_count++; + } +} + +node* vdir::get_child(char* name) { + for (unsigned i = 0; i < child_count; i++) { + vdir_child *c = children.at(i); + ASSERT(c != 0); + if (strcmp(c->name, name) == 0) return c->el; + } + return 0; +} + +int vdir::read(size_t offset, size_t len, char* buffer) { + if (offset >= child_count) return 0; + vdir_child *c = children.at(offset); + ASSERT(c != 0); + size_t nlen = strlen(c->name); + if (len <= nlen) { + return E_TOO_SHORT; + } + strcpy(buffer, c->name); + return nlen; +} + +int vdir::write(size_t offset, size_t len, char* buffer) { + // rename file + if (offset >= child_count) return E_INVALID_RANGE; + vdir_child *c = children.at(offset); + ASSERT(c != 0); + if (len == 0) return E_INVALID; + kfree(c->name); + c->name = (char*)kmalloc(len + 1); + for (unsigned i = 0; i < len; i++) c->name[i] = buffer[i]; + c->name[len] = 0; + return len; +} + +size_t vdir::get_size() { + return child_count; +} + +int vdir::add_child(char* name, node *child) { + ASSERT((int)child_count == children.add(new vdir_child(name, child))); + child_count++; + return 0; +} |