diff --git a/tasks/fs0/include/memfs/file.h b/tasks/fs0/include/memfs/file.h new file mode 100644 index 0000000..9679bee --- /dev/null +++ b/tasks/fs0/include/memfs/file.h @@ -0,0 +1,7 @@ +#ifndef __MEMFS_FILE_H__ +#define __MEMFS_FILE_H__ + +extern struct file_ops memfs_file_operations; +extern struct dentry_ops memfs_dentry_operations; + +#endif /* __MEMFS_FILE_H__ */ diff --git a/tasks/fs0/include/stat.h b/tasks/fs0/include/stat.h new file mode 100644 index 0000000..c77f0b3 --- /dev/null +++ b/tasks/fs0/include/stat.h @@ -0,0 +1,46 @@ +#ifndef __FS0_STAT_H__ +#define __FS0_STAT_H__ + +/* Posix definitions for file mode flags (covers type and access permissions) */ +#define S_IFMT 00170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 + +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 + +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 + +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 + +#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO) +#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO) +#define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH) +#define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH) +#define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH) + +#endif /* __FS0_STAT_H__ */ diff --git a/tasks/fs0/include/vfs.h b/tasks/fs0/include/vfs.h new file mode 100644 index 0000000..d1874da --- /dev/null +++ b/tasks/fs0/include/vfs.h @@ -0,0 +1,88 @@ +#ifndef __VFS_H__ +#define __VFS_H__ + +#include +#include +#include +#include + +/* + * FIXME: + * These ought to be strings and split/comparison functions should + * always use strings because formats like UTF-8 wouldn't work. + */ +#define VFS_STR_SEP '/' +#define VFS_STR_PARDIR ".." +#define VFS_STR_CURDIR "." +#define VFS_STR_XATDIR "...." + +/* + * This is a temporary replacement for page cache support provided by mm0. + * Normally mm0 tracks all vnode pages, but this is used to track pages in + * directory vnodes, which are normally never mapped by tasks. + */ +extern struct memfs_superblock *memfs_superblock; +static inline void *vfs_alloc_dirpage(void) +{ + /* + * Urgh, we allocate from the block cache of memfs to store generic vfs directory + * pages. This is currently the quickest we can allocate page-aligned memory. + */ + return memfs_alloc_block(memfs_superblock); +} + +static inline void vfs_free_dirpage(void *block) +{ + memfs_free_block(memfs_superblock, block); +} + +static inline struct dentry *vfs_alloc_dentry(void) +{ + struct dentry *d = kzalloc(sizeof(struct dentry)); + + INIT_LIST_HEAD(&d->child); + INIT_LIST_HEAD(&d->children); + INIT_LIST_HEAD(&d->vref); + + return d; +} + +static inline void vfs_free_dentry(struct dentry *d) +{ + return kfree(d); +} + +static inline struct vnode *vfs_alloc_vnode(void) +{ + struct vnode *v = kzalloc(sizeof(struct vnode)); + + INIT_LIST_HEAD(&v->dentries); + INIT_LIST_HEAD(&v->state_list); + + return v; +} + +static inline void vfs_free_vnode(struct vnode *v) +{ + kfree(v); +} + +static inline struct superblock *vfs_alloc_superblock(void) +{ + struct superblock *sb = kmalloc(sizeof(struct superblock)); + INIT_LIST_HEAD(&sb->list); + return sb; +} + +struct vfs_mountpoint { + struct superblock *sb; /* The superblock of mounted filesystem */ + struct vnode *pivot; /* The dentry upon which we mount */ +}; + +extern struct vfs_mountpoint vfs_root; + +int vfs_mount_root(struct superblock *sb); +struct vnode *generic_vnode_lookup(struct vnode *thisnode, char *path); +struct vnode *vfs_lookup(struct superblock *sb, char *path); + +#endif /* __VFS_H__ */