Nucleus
Barry Files namespace f0dcd54 (3 years, 3 months ago)
diff --git a/include/nucleus/task.h b/include/nucleus/task.h
index 397fae7..cfc0c99 100644
--- a/include/nucleus/task.h
+++ b/include/nucleus/task.h
@@ -30,7 +30,9 @@ enum State {
/* Structure for a Task */
struct Task {
Object obj;
- pid_t tid;
+ pid_t tid, tgid;
+ uid_t uid, euid, suid;
+ gid_t gid, egid, sgid;
enum Priority priority;
enum State state;
@@ -39,6 +41,7 @@ struct Task {
/* Namespaces */
FileSystem *fs;
+ Files *files;
};
extern ObjectType taskType;
@@ -46,6 +49,13 @@ extern ObjectType taskType;
extern Task *currentTask[];
#define current currentTask[CPUID]
+/* Check if super-user */
+static inline int
+super_user(void)
+{
+ return (current->euid == 0);
+}
+
void init_tasking(void);
void schedule(void);
pid_t clone(int flags);
diff --git a/include/nucleus/vfs.h b/include/nucleus/vfs.h
index ebd5396..59162c0 100644
--- a/include/nucleus/vfs.h
+++ b/include/nucleus/vfs.h
@@ -6,10 +6,13 @@
#include <nucleus/object.h>
#include <nucleus/memory.h>
+#define NFILES 32
#define NAME_MAX 255
+#define PATH_MAX 1024
typedef struct FSType FSType;
typedef struct FileSystem FileSystem;
+typedef struct Files Files;
typedef struct SuperBlock SuperBlock;
typedef struct SuperOps SuperOps;
typedef struct Inode Inode;
@@ -48,12 +51,16 @@ struct Inode {
InodeOps *ops;
FileOps *fileOps;
SuperBlock *super;
- union {
- ObjectList *dirEntries;
- ObjectList *pages;
- };
+ ObjectList *dirEntries;
+ ObjectList *pages;
};
struct InodeOps {
+ int (*create)(Inode *, DirEntry *, mode_t);
+ Inode *(*lookup)(Inode *, const char *);
+ int (*mkdir)(Inode *, DirEntry *, mode_t);
+ int (*rmdir)(Inode *, DirEntry *);
+ int (*mknod)(Inode *, DirEntry *, mode_t, dev_t);
+ int (*rename)(Inode *, DirEntry *, Inode *, DirEntry *);
};
/* Structure for a Directory Entry */
@@ -75,10 +82,15 @@ struct File {
ObjectList *path;
};
struct FileOps {
+ size_t (*read)(File *, char *, size_t, off_t);
+ size_t (*write)(File *, char *, size_t, off_t);
+ int (*open)(File *);
};
extern ObjectType fstypeType;
extern ObjectType fsType;
+extern ObjectType filesType;
+extern ObjectType superBlockType;
extern ObjectType inodeType;
extern ObjectType dirEntryType;
extern ObjectType fileType;
@@ -87,6 +99,23 @@ void init_vfs(void);
void register_fstype(const char *name, mount_callback_t mount);
int mount(const char *src, const char *target, const char *type,
unsigned long flags, void *data);
+
+/* Super Block functions */
+Inode *super_alloc_inode(SuperBlock *sb);
+Inode *super_find_inode(SuperBlock *sb, ino_t ino);
+/* Inode functions */
+int permission(Inode *inode, int mask);
+int inode_create(Inode *inode, DirEntry *entry, mode_t mode);
+DirEntry *inode_lookup(Inode *inode, const char *name);
+/* Directory Entry functions */
DirEntry *find_direntry(ObjectList *list, const char *name);
+/* File functions */
+int file_open(File *file);
+size_t file_read(File *file, char *buf, size_t count);
+size_t file_write(File *file, char *buf, size_t count);
+/* Files namespace functions */
+File *get_file_by_fd(int fd);
+int allocate_fd(void);
+void install_fd(int fd, File *file);
#endif