summaryrefslogtreecommitdiff
path: root/Source/Kernel/VFS
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-09-13 15:14:13 +0200
committerAlexis211 <alexis211@gmail.com>2009-09-13 15:14:13 +0200
commit0b760a50b5aee05f1f34c1599b547c8b78d1d737 (patch)
tree8271581cdf49d2eef265d31bd9e1fc30c0ecaf4f /Source/Kernel/VFS
parentb808b613a5c7e0b6c6c45b28f7f0169dc13afaa2 (diff)
downloadMelon-0b760a50b5aee05f1f34c1599b547c8b78d1d737.tar.gz
Melon-0b760a50b5aee05f1f34c1599b547c8b78d1d737.zip
Ram file system seems to work \o/
Diffstat (limited to 'Source/Kernel/VFS')
-rw-r--r--Source/Kernel/VFS/DirectoryNode.class.h60
-rw-r--r--Source/Kernel/VFS/DirectoryNode.proto.h46
-rw-r--r--Source/Kernel/VFS/FSNode.proto.h37
-rw-r--r--Source/Kernel/VFS/FileNode.class.h28
-rw-r--r--Source/Kernel/VFS/FileNode.proto.h24
-rw-r--r--Source/Kernel/VFS/FileSystem.proto.h31
-rw-r--r--Source/Kernel/VFS/VFS.ns.h7
7 files changed, 135 insertions, 98 deletions
diff --git a/Source/Kernel/VFS/DirectoryNode.class.h b/Source/Kernel/VFS/DirectoryNode.class.h
new file mode 100644
index 0000000..cb1574c
--- /dev/null
+++ b/Source/Kernel/VFS/DirectoryNode.class.h
@@ -0,0 +1,60 @@
+#ifndef DEF_DIRECTORYNODE_CLASS_H
+#define DEF_DIRECTORYNODE_CLASS_H
+
+#include <VFS/FileNode.class.h>
+#include <Library/Vector.class.h>
+
+class DirectoryNode : public FSNode {
+ protected:
+ Vector<FSNode*> m_children;
+ bool m_contentLoaded;
+
+ public:
+ DirectoryNode(String name, FileSystem* fs, FSNode* parent, u32int permissions = 0777,
+ u32int uid = 0, u32int gid = 0) :
+ FSNode(name, fs, parent, 0, permissions, uid, gid), m_children(), m_contentLoaded(false) {}
+
+ Vector<FSNode*> &getChildren() { return m_children; } //MUST BE USED ONLY BY FILESYSTEMS
+
+ u8int type() { return NT_DIRECTORY; }
+
+ bool loadContent() {
+ if (m_contentLoaded) return true;
+ bool b = m_fs->loadContents(this);
+ if (!b) return false;
+ m_length = m_children.size();
+ m_contentLoaded = true;
+ return b;
+ }
+
+ FSNode* getChild(u32int index) {
+ if (!m_contentLoaded)
+ if (!loadContent())
+ return NULL;
+ if (index >= m_children.size()) return NULL;
+ return m_children[index];
+ }
+
+ FSNode* getChild(String name) {
+ if (!m_contentLoaded)
+ if (!loadContent())
+ return NULL;
+ for (u32int i = 0; i < m_children.size(); i++) {
+ if (name == m_children[i]->getName())
+ return m_children[i];
+ }
+ return NULL;
+ }
+ FileNode* createFile(String name) {
+ FileNode* n = m_fs->createFile(this, name);
+ m_length = m_children.size();
+ return n;
+ }
+ DirectoryNode* createDirectory(String name) {
+ DirectoryNode* n = m_fs->createDirectory(this, name);
+ m_length = m_children.size();
+ return n;
+ }
+};
+
+#endif
diff --git a/Source/Kernel/VFS/DirectoryNode.proto.h b/Source/Kernel/VFS/DirectoryNode.proto.h
deleted file mode 100644
index f9c1c9f..0000000
--- a/Source/Kernel/VFS/DirectoryNode.proto.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef DEF_DIRECTORYNODE_PROTO_H
-#define DEF_DIRECTORYNODE_PROTO_H
-
-#include <VFS/FSNode.proto.h>
-#include <Library/Vector.class.h>
-
-class DirectoryNode : public virtual FSNode {
- protected:
- Vector<FSNode*> m_children;
- bool m_contentLoaded;
-
- protected:
- DirectoryNode() : m_children(), m_contentLoaded(false) {}
-
- virtual bool FSLoadContent() = 0;
-
- public:
- bool loadContent() {
- if (m_contentLoaded) return true;
- bool b = FSLoadContent();
- m_length = m_children.size();
- if (b) m_contentLoaded = true;
- return b;
- }
-
- FSNode* getChild(u32int index) {
- if (!m_contentLoaded)
- if (!loadContent)
- return NULL;
- if (index >= m_children.size()) return NULL;
- return m_children[index];
- }
-
- FSNode* getChild(String name) {
- if (!m_contentLoaded)
- if (!loadContent)
- return NULL;
- for (u32int i = 0; i < m_children.size(); i++) {
- if (m_children[i]->getName() == name)
- return m_children[i];
- }
- return NULL;
- }
-};
-
-#endif
diff --git a/Source/Kernel/VFS/FSNode.proto.h b/Source/Kernel/VFS/FSNode.proto.h
index 62d28be..fb24a82 100644
--- a/Source/Kernel/VFS/FSNode.proto.h
+++ b/Source/Kernel/VFS/FSNode.proto.h
@@ -3,8 +3,8 @@
#include <Core/common.wtf.h>
#include <Library/String.class.h>
-
-class FileSystem;
+class FSNode;
+#include <VFS/FileSystem.proto.h>
enum {
NT_FILE = 1,
@@ -20,12 +20,11 @@ class FSNode {
u32int m_permissions, m_uid, m_gid;
FileSystem *m_fs;
FSNode *m_parent;
- u32int m_inode;
- FSNode(String name, FileSystem* fs, FSNode* parent, u32int inode, u32int length = 0, u32int permissions = 0777,
+ FSNode(String name, FileSystem* fs, FSNode* parent, u32int length = 0, u32int permissions = 0777,
u32int uid = 0, u32int gid = 0) :
- m_name(name), m_fs(fs), m_parent(parent), m_inode(inode), m_length(length), m_premissions(permissions),
- m_uid(uid), m_gid(gid) {}
+ m_name(name), m_length(length), m_permissions(permissions),
+ m_uid(uid), m_gid(gid), m_fs(fs), m_parent(parent) {}
public:
@@ -38,49 +37,33 @@ class FSNode {
u32int getGid() { return m_gid; }
FileSystem *getFS() { return m_fs; }
FSNode* getParent() { return m_parent; }
- u32int getInode() { return m_inode; }
-
- protected:
- //Must be implemented by *FSNode
- virtual bool FSSetName(String name) = 0;
- virtual bool FSTruncate() = 0;
- virtual bool FSSetPermissions(u32int permissions) = 0;
- virtual bool FSSetUid(u32int uid) = 0;
- virtual bool FSSetGid(u32int gid) = 0;
- virtual bool FSSetParent(FSNode* parent) = 0;
public:
bool setName(String name) {
- bool b = FSSetName(name);
+ bool b = m_fs->setName(this, name);
if (b) m_name = name;
return b;
}
- bool truncate() {
- bool b = FSTruncate();
- if (b) m_length = 0;
- return b;
- }
bool setPermissions(u32int permissions) {
- bool b = FSSetPermissions(permissions);
+ bool b = m_fs->setPermissions(this, permissions);
if (b) m_permissions = permissions;
return b;
}
bool setUid(u32int uid) {
- bool b = FSSetUid(uid);
+ bool b = m_fs->setUid(this, uid);
if (b) m_uid = uid;
return b;
}
bool setGid(u32int gid) {
- bool b = FSSetGid(gid);
+ bool b = m_fs->setGid(this, gid);
if (b) m_gid = gid;
return b;
}
bool setParent(FSNode* parent) {
- bool b = FSSetParent(parent); //FSSetParent is only expected to move files/directories in the same filesystem
+ bool b = m_fs->setParent(this, parent); //FSSetParent is only expected to move files/directories in the same filesystem
if (b) m_parent = parent;
return b;
}
- void setInode(u32int inode) { m_inode = inode; }
};
#endif
diff --git a/Source/Kernel/VFS/FileNode.class.h b/Source/Kernel/VFS/FileNode.class.h
new file mode 100644
index 0000000..29fab45
--- /dev/null
+++ b/Source/Kernel/VFS/FileNode.class.h
@@ -0,0 +1,28 @@
+#ifndef DEF_FILENODE_CLASS_H
+#define DEF_FILENODE_CLASS_H
+
+#include <VFS/FSNode.proto.h>
+
+class FileNode : public FSNode {
+ protected:
+ FileNode(String name, FileSystem* fs, FSNode* parent, u32int length = 0, u32int permissions = 0777,
+ u32int uid = 0, u32int gid = 0): FSNode(name, fs, parent, length, permissions, uid, gid) {}
+
+ public:
+ u8int type() { return NT_FILE; }
+
+ u32int read(u64int position, u32int max_length, u8int *data) {
+ return m_fs->read(this, position, max_length, data);
+ }
+
+ bool write(u64int position, u32int length, u8int *data) {
+ return m_fs->write(this, position, length, data);
+ }
+
+ bool truncate() {
+ return m_fs->truncate(this);
+ }
+
+};
+
+#endif
diff --git a/Source/Kernel/VFS/FileNode.proto.h b/Source/Kernel/VFS/FileNode.proto.h
deleted file mode 100644
index b02c277..0000000
--- a/Source/Kernel/VFS/FileNode.proto.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef DEF_FILENODE_PROTO_H
-#define DEF_FILENODE_PROTO_H
-
-#include <VFS/FSNode.proto.h>
-
-class FileNode : public virtual FSNode {
- protected:
- DirectoryNode() {}
-
- virtual bool FSRead(u64int position, u32int max_length, u8int *data) = 0;
- virtual bool FSWrite(u64int position, u32int length, u8int *data) = 0;
-
- public:
- bool read(u64int position, u32int max_length, u8int *data) {
- return FSRead(position, max_length, data);
- }
-
- bool write(u64int position, u32int length, u8int *data) {
- return FSWrite(position, length, data);
- }
-
-};
-
-#endif
diff --git a/Source/Kernel/VFS/FileSystem.proto.h b/Source/Kernel/VFS/FileSystem.proto.h
index 523caf7..79bb84c 100644
--- a/Source/Kernel/VFS/FileSystem.proto.h
+++ b/Source/Kernel/VFS/FileSystem.proto.h
@@ -1,4 +1,35 @@
#ifndef DEF_FILESYSTEM_PROTO_H
#define DEF_FILESYSTEM_PROTO_H
+#include <VFS/Partition.class.h>
+class FSNode;
+class FileNode;
+class DirectoryNode;
+
+//This abstract class describes a filesystem
+class FileSystem {
+ protected:
+ bool m_isWritable; //false = read only
+ DirectoryNode* m_rootNode;
+
+ public:
+ bool isWritable() { return m_isWritable; }
+ DirectoryNode* getRootNode() { return m_rootNode; }
+
+ //Must be implemented by the filesystem
+ virtual bool setName(FSNode* node, String name) = 0;
+ virtual bool setPermissions(FSNode* node, u32int permissions) = 0;
+ virtual bool setUid(FSNode* node, u32int uid) = 0;
+ virtual bool setGid(FSNode* node, u32int gid) = 0;
+ virtual bool setParent(FSNode* node, FSNode* parent) = 0;
+
+ virtual u32int read(FileNode* file, u64int position, u32int max_length, u8int *data) = 0;
+ virtual bool write(FileNode* file, u64int position, u32int length, u8int *data) = 0;
+ virtual bool truncate(FileNode* file) = 0;
+
+ virtual bool loadContents(DirectoryNode* dir) = 0;
+ virtual FileNode* createFile(DirectoryNode* parent, String name) = 0;
+ virtual DirectoryNode* createDirectory(DirectoryNode* parent, String name) = 0;
+};
+
#endif
diff --git a/Source/Kernel/VFS/VFS.ns.h b/Source/Kernel/VFS/VFS.ns.h
index cdd6e23..622d120 100644
--- a/Source/Kernel/VFS/VFS.ns.h
+++ b/Source/Kernel/VFS/VFS.ns.h
@@ -2,9 +2,14 @@
#define DEF_VFS_NS_H
#include <VFS/FSNode.proto.h>
+#include <VFS/FileSystem.proto.h>
-namespace VFS {
+typedef FileSystem* (* mountcallback)(Partition* partition);
+namespace VFS {
+ void registerMountCallback(mountcallback mcb);
+ bool mount(Partition* partition);
+ bool setRootNode(FSNode* root);
}
#endif