fs: add ramfs
This commit is contained in:
parent
a7c526d2a6
commit
750ffa2e16
13 changed files with 355 additions and 55 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#define _VFS_H_
|
||||
|
||||
#include <kernel/spinlock.h>
|
||||
#include <drivers/block.h>
|
||||
#include <lib/rwlock.h>
|
||||
#include <lib/list.h>
|
||||
|
||||
|
|
@ -19,19 +20,30 @@
|
|||
|
||||
#define DIRENT_TYPE(dirent) ((dirent)->flags & 0x7)
|
||||
|
||||
#define INODE_UNKNOWN 0x0
|
||||
#define INODE_REGULAR 0x1
|
||||
#define INODE_DIRECTORY 0x2
|
||||
#define INODE_CHRDEV 0x3
|
||||
#define INODE_BLKDEV 0x4
|
||||
#define INODE_FIFO 0x5
|
||||
#define INODE_SOCKET 0x6
|
||||
#define INODE_SYMLINK 0x7
|
||||
|
||||
typedef struct _inode inode_t;
|
||||
typedef struct _dirent dirent_t;
|
||||
typedef struct _fs fs_t;
|
||||
|
||||
struct fs_ops {
|
||||
int (*alloc_inode)(fs_t *fs, inode_t *out);
|
||||
int (*free_inode)(fs_t *fs, inode_t *inode);
|
||||
struct fs_type {
|
||||
char name[256];
|
||||
dirent_t *(*fs_mount)(int flags, struct block_device *bdev);
|
||||
void (*fs_umount)(fs_t *fs);
|
||||
bool (*fs_detect)(struct block_device *bdev);
|
||||
};
|
||||
|
||||
struct fs_superblock {
|
||||
u64 type;
|
||||
size_t block_size;
|
||||
size_t n_blocks;
|
||||
struct fs_ops {
|
||||
int (*alloc_inode)(fs_t *fs, inode_t **out);
|
||||
int (*free_inode)(fs_t *fs, inode_t *inode);
|
||||
int (*open_inode)(fs_t *fs, u64 id, inode_t **out);
|
||||
};
|
||||
|
||||
struct inode_ops {
|
||||
|
|
@ -39,36 +51,50 @@ struct inode_ops {
|
|||
ssize_t (*read)(inode_t *inode, char *buf, size_t size, size_t offset);
|
||||
ssize_t (*write)(inode_t *inode, char *buf, size_t size, size_t offset);
|
||||
/* for directory files */
|
||||
int (*mkdir)(inode_t *inode, const char *name, dirent_t *out);
|
||||
int (*creat)(inode_t *inode, const char *name, dirent_t *out);
|
||||
int (*link)(inode_t *inode, const char *name, dirent_t *out);
|
||||
int (*mkdir)(inode_t *inode, const char *name, dirent_t **out);
|
||||
int (*creat)(inode_t *inode, const char *name, dirent_t **out);
|
||||
int (*link)(inode_t *inode, const char *name, dirent_t **out);
|
||||
int (*unlink)(inode_t *inode, const char *name);
|
||||
int (*lookup)(inode_t *parent, const char *name, dirent_t *out);
|
||||
int (*readdir)(inode_t *parent);
|
||||
};
|
||||
|
||||
struct _fs {
|
||||
struct fs_superblock superblock;
|
||||
struct _inode *root_inode;
|
||||
u64 fs_type;
|
||||
u64 type;
|
||||
size_t block_size;
|
||||
size_t n_blocks;
|
||||
|
||||
inode_t *root_inode;
|
||||
|
||||
spinlock_t lock;
|
||||
struct fs_ops fs_ops;
|
||||
};
|
||||
|
||||
struct _dirent {
|
||||
inode_t *inode;
|
||||
u64 ino_num;
|
||||
|
||||
size_t rec_len;
|
||||
size_t name_len;
|
||||
size_t flags;
|
||||
|
||||
u64 flags;
|
||||
u64 type;
|
||||
|
||||
char *name;
|
||||
};
|
||||
|
||||
struct _inode {
|
||||
fs_t *fs;
|
||||
u64 mode;
|
||||
u64 ino_num;
|
||||
u64 file_size;
|
||||
|
||||
list_t dentries;
|
||||
|
||||
void *data;
|
||||
|
||||
u64 refcount;
|
||||
rwlock_t rwlock;
|
||||
struct fs *fs;
|
||||
rwlock_t rwlock;
|
||||
|
||||
struct _inode *parent_inode;
|
||||
struct inode_ops i_ops;
|
||||
};
|
||||
|
|
@ -76,5 +102,8 @@ struct _inode {
|
|||
void vfs_init();
|
||||
inode_t *inode_create();
|
||||
void inode_free(inode_t *inode);
|
||||
dirent_t *inode_find_dirent(inode_t *inode, const char *name);
|
||||
dirent_t *dirent_create(const char *name);
|
||||
void dirent_free(dirent_t *dirent);
|
||||
|
||||
#endif /* _VFS_H_ */
|
||||
|
|
|
|||
Loading…
Reference in a new issue