BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 015db5ab00d4752727512ef7b91a3809f6853469

// Related

Nucleus

Barry File object 015db5a (3 years, 3 months ago)
diff --git a/include/nucleus/vfs.h b/include/nucleus/vfs.h
index fd78c10..ebd5396 100644
--- a/include/nucleus/vfs.h
+++ b/include/nucleus/vfs.h
@@ -15,6 +15,8 @@ typedef struct SuperOps SuperOps;
 typedef struct Inode Inode;
 typedef struct InodeOps InodeOps;
 typedef struct DirEntry DirEntry;
+typedef struct File File;
+typedef struct FileOps FileOps;
 
 typedef Inode *(*mount_callback_t)(FSType *, int, const char *, void *);
 
@@ -44,6 +46,7 @@ struct Inode {
 	size_t size;
 	dev_t dev;
 	InodeOps *ops;
+	FileOps *fileOps;
 	SuperBlock *super;
 	union {
 		ObjectList *dirEntries;
@@ -62,10 +65,23 @@ struct DirEntry {
 	SuperBlock *super;
 };
 
+/* Structure for an open File */
+struct File {
+	Object obj;
+	Inode *inode;
+	int flags;
+	off_t pos;
+	FileOps *ops;
+	ObjectList *path;
+};
+struct FileOps {
+};
+
 extern ObjectType fstypeType;
 extern ObjectType fsType;
 extern ObjectType inodeType;
 extern ObjectType dirEntryType;
+extern ObjectType fileType;
 
 void init_vfs(void);
 void register_fstype(const char *name,	mount_callback_t mount);
diff --git a/vfs/direntry.c b/vfs/direntry.c
index f0953d1..a8a0110 100644
--- a/vfs/direntry.c
+++ b/vfs/direntry.c
@@ -14,6 +14,7 @@ struct FindData {
 
 static void direntry_delete(Object *);
 
+/* Directory Entry object type */
 ObjectType dirEntryType = {
 	.size = sizeof(DirEntry),
 	.delete = direntry_delete,
diff --git a/vfs/file.c b/vfs/file.c
new file mode 100644
index 0000000..8aef18f
--- /dev/null
+++ b/vfs/file.c
@@ -0,0 +1,30 @@
+/*
+ * This file implements the File object and associated functions.  A file
+ * represents an opened file, and holds a reference the the underlying inode.
+ * Most of the functions here are just wrappers around the file operations.
+ * They perform the necessary validation to ensure the operation can be called
+ * on the particular file.  If no operation is found, they may implement a
+ * generic version.
+ */
+
+#include <nucleus/object.h>
+#include <nucleus/vfs.h>
+
+static void file_delete(Object *);
+
+/* File object type */
+ObjectType fileType = {
+	.size = sizeof(File),
+	.delete = file_delete,
+};
+
+/* Destroy a file */
+static void
+file_delete(Object *obj)
+{
+	File *file = (void *) obj;
+	if (file->inode)
+		put(file->inode);
+	if (file->path)
+		destroy_list(file->path);
+}
diff --git a/vfs/superblock.c b/vfs/superblock.c
index 237f723..657ddc7 100644
--- a/vfs/superblock.c
+++ b/vfs/superblock.c
@@ -15,6 +15,7 @@ struct FindData {
 	Inode *result;
 };
 
+/* Super Block object type */
 ObjectType superBlockType = {
 	.size = sizeof(SuperBlock),
 };