v2 initial commit
This commit is contained in:
parent
2c97dba9f7
commit
d2ef885e8d
118 changed files with 2420 additions and 9320 deletions
|
|
@ -1,17 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _DEVFS_H_
|
||||
#define _DEVFS_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct vnode;
|
||||
struct devfs_dev_info {
|
||||
void *dev;
|
||||
ssize_t (*read)(void *dev, void *buf, size_t offset, size_t size);
|
||||
ssize_t (*write)(void *dev, void *buf, size_t offset, size_t size);
|
||||
};
|
||||
|
||||
struct fs *devfs_init();
|
||||
int devfs_insert(struct vnode *dir, const char *name, uint32_t flags, struct devfs_dev_info *ops);
|
||||
|
||||
#endif /* _DEVFS_H_ */
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _EXT2_H_
|
||||
#define _EXT2_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/block.h>
|
||||
#include <kernel/gpt.h>
|
||||
|
||||
#include <fs/vfs.h>
|
||||
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
#define EXT2_ROOT_INO 2
|
||||
#define EXT2_SUPERBLOCK_BLOCKNO 1
|
||||
|
||||
#define EXT2_DE_UNKNOWN 0
|
||||
#define EXT2_DE_FILE 1
|
||||
#define EXT2_DE_DIR 2
|
||||
#define EXT2_DE_CHRDEV 3
|
||||
#define EXT2_DE_BLKDEV 4
|
||||
#define EXT2_DE_FIFO 5
|
||||
#define EXT2_DE_SOCK 6
|
||||
#define EXT2_DE_SYMLINK 7
|
||||
|
||||
#define EXT2_INO_FIFO 0x1000
|
||||
#define EXT2_INO_CHARDEV 0x2000
|
||||
#define EXT2_INO_DIR 0x4000
|
||||
#define EXT2_INO_BLKDEV 0x6000
|
||||
#define EXT2_INO_REG 0x8000
|
||||
#define EXT2_INO_SYMLINK 0xA000
|
||||
#define EXT2_INO_SOCK 0xC000
|
||||
|
||||
#define EXT2_FLAG_LONG_FILESIZE 0x0002
|
||||
|
||||
struct ext2_superblock {
|
||||
uint32_t inodes_count;
|
||||
uint32_t blocks_count;
|
||||
uint32_t u_blocks_count;
|
||||
uint32_t free_blocks_count;
|
||||
uint32_t free_inodes_count;
|
||||
uint32_t first_data_block;
|
||||
|
||||
uint32_t log_block_size;
|
||||
uint32_t log_frag_size;
|
||||
|
||||
uint32_t blocks_per_group;
|
||||
uint32_t frags_per_group;
|
||||
uint32_t inodes_per_group;
|
||||
|
||||
uint32_t mtime;
|
||||
uint32_t wtime;
|
||||
|
||||
uint16_t mnt_count;
|
||||
uint16_t max_mnt_count;
|
||||
uint16_t magic;
|
||||
uint16_t state;
|
||||
uint16_t errors;
|
||||
uint16_t minor_rev_level;
|
||||
|
||||
uint32_t lastcheck;
|
||||
uint32_t checkinterval;
|
||||
uint32_t creator_os;
|
||||
uint32_t rev_level;
|
||||
|
||||
uint16_t def_resuid;
|
||||
uint16_t def_resgid;
|
||||
|
||||
/* extended superblock fields
|
||||
* if rev_level >= 1
|
||||
*/
|
||||
uint32_t first_ino;
|
||||
uint16_t inode_size;
|
||||
uint16_t block_group_nr;
|
||||
uint32_t feature_compat;
|
||||
uint32_t feature_incompat;
|
||||
uint32_t feature_ro_compat;
|
||||
uint8_t uuid[16];
|
||||
char volume_name[16];
|
||||
char last_mounted[64];
|
||||
uint32_t algo_bitmap;
|
||||
|
||||
/* performance hints */
|
||||
uint8_t prealloc_blocks;
|
||||
uint8_t prealloc_dir_blocks;
|
||||
uint16_t padding1;
|
||||
|
||||
/* journaling support */
|
||||
uint8_t journal_uuid[16];
|
||||
uint32_t journal_inum;
|
||||
uint32_t journal_dev;
|
||||
uint32_t last_orphan;
|
||||
} PACKED;
|
||||
|
||||
struct ext2_inode {
|
||||
uint16_t mode;
|
||||
uint16_t uid;
|
||||
uint32_t size;
|
||||
|
||||
uint32_t atime;
|
||||
uint32_t ctime;
|
||||
uint32_t mtime;
|
||||
uint32_t dtime;
|
||||
|
||||
uint16_t gid;
|
||||
uint16_t links_count;
|
||||
uint32_t blocks;
|
||||
uint32_t flags;
|
||||
uint32_t osd1;
|
||||
uint32_t block[15];
|
||||
|
||||
uint32_t generation;
|
||||
uint32_t file_acl;
|
||||
uint32_t dir_acl;
|
||||
uint32_t faddr;
|
||||
|
||||
uint8_t frag_number;
|
||||
uint8_t frag_size;
|
||||
uint16_t padding1;
|
||||
uint16_t user_high;
|
||||
uint16_t group_high;
|
||||
uint32_t padding2;
|
||||
} PACKED;
|
||||
|
||||
struct ext2_group_desc {
|
||||
uint32_t block_bitmap;
|
||||
uint32_t inode_bitmap;
|
||||
uint32_t inode_table;
|
||||
uint16_t free_blocks_count;
|
||||
uint16_t free_inodes_count;
|
||||
uint16_t used_dirs_count;
|
||||
uint16_t padding[7];
|
||||
} PACKED;
|
||||
|
||||
struct ext2_dir_entry {
|
||||
uint32_t inode;
|
||||
uint16_t rec_len;
|
||||
uint8_t name_len;
|
||||
ftype_t file_type;
|
||||
char name[];
|
||||
} PACKED;
|
||||
|
||||
struct ext2fs {
|
||||
struct ext2_superblock sb;
|
||||
struct block_device *bdev;
|
||||
|
||||
uint32_t bgdt_blockno;
|
||||
uint32_t bgdt_num_blocks;
|
||||
struct ext2_group_desc *bgdt;
|
||||
|
||||
spinlock_t lock;
|
||||
|
||||
uint32_t indir_block_size;
|
||||
|
||||
uint32_t block_size;
|
||||
};
|
||||
|
||||
struct fs *ext2_init_fs(struct block_device *bdev);
|
||||
|
||||
#endif /* _EXT2_H_ */
|
||||
162
include/fs/vfs.h
162
include/fs/vfs.h
|
|
@ -1,162 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _VFS_H_
|
||||
#define _VFS_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
#define VFSE_IS_BDEV 0xFFFA
|
||||
|
||||
#define VFS_TYPE_EXT2 0x0001
|
||||
|
||||
/* same as EXT2_INO_* */
|
||||
#define VFS_VNO_FIFO 0x1000
|
||||
#define VFS_VNO_CHARDEV 0x2000
|
||||
#define VFS_VNO_DIR 0x4000
|
||||
#define VFS_VNO_BLKDEV 0x6000
|
||||
#define VFS_VNO_REG 0x8000
|
||||
#define VFS_VNO_SYMLINK 0xA000
|
||||
#define VFS_VNO_SOCK 0xC000
|
||||
#define VFS_VTYPE_MASK 0xF000
|
||||
|
||||
#define FTYPE_CHARDEV VFS_VNO_CHARDEV
|
||||
#define FTYPE_DIR VFS_VNO_DIR
|
||||
#define FTYPE_BLKDEV VFS_VNO_BLKDEV
|
||||
#define FTYPE_REG VFS_VNO_REG
|
||||
#define FTYPE_SYMLINK VFS_VNO_SYMLINK
|
||||
#define FTYPE_SOCK VFS_VNO_SOCK
|
||||
#define FTYPE_FIFO VFS_VNO_FIFO
|
||||
|
||||
#define VFS_DE_UNKNOWN 0
|
||||
#define VFS_DE_FILE 1
|
||||
#define VFS_DE_DIR 2
|
||||
#define VFS_DE_CHRDEV 3
|
||||
#define VFS_DE_BLKDEV 4
|
||||
#define VFS_DE_FIFO 5
|
||||
#define VFS_DE_SOCK 6
|
||||
#define VFS_DE_SYMLINK 7
|
||||
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define O_RDONLY 0x0001
|
||||
#define O_WRONLY 0x0002
|
||||
#define O_RDWR 0x0004
|
||||
#define O_CREAT 0x0008
|
||||
#define O_TRUNC 0x0010
|
||||
#define O_APPEND 0x0020
|
||||
|
||||
#define S_IFIFO 0x1000
|
||||
|
||||
#define FS_TYPE_EXT2 0x0001
|
||||
#define FS_TYPE_PFS 0x0002 /* pseudo fs */
|
||||
|
||||
typedef uint32_t ino_t;
|
||||
typedef uint8_t ftype_t;
|
||||
typedef size_t off_t;
|
||||
|
||||
struct vnode {
|
||||
char name[256];
|
||||
uint32_t flags;
|
||||
uint32_t gid;
|
||||
uint32_t uid;
|
||||
uint32_t size;
|
||||
uint32_t ino_num;
|
||||
|
||||
struct fs *fs;
|
||||
struct vnode *ptr;
|
||||
struct vnode *next;
|
||||
|
||||
struct vnode *parent;
|
||||
|
||||
struct dirent *dirents; /* for directories */
|
||||
size_t num_dirents;
|
||||
|
||||
bool mount_ptr; /* does this node point to a root of a mounted fs? */
|
||||
bool no_free; /* permanently cached vnodes */
|
||||
|
||||
void *priv_data;
|
||||
|
||||
size_t refcount;
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
struct dirent {
|
||||
uint64_t inode; /* fs-specific inode number */
|
||||
uint16_t reclen; /* length of this record */
|
||||
ftype_t type; /* type: file, dir, chrdev, blkdev, etc. */
|
||||
char name[256];
|
||||
|
||||
struct vnode *vnode; /* we don't want duplicate vnodes */
|
||||
};
|
||||
|
||||
struct file {
|
||||
struct vnode *vnode;
|
||||
|
||||
spinlock_t ref_lock;
|
||||
uint64_t refcount;
|
||||
|
||||
ino_t ino_num; /* inode number */
|
||||
uint32_t type; /* type of the file */
|
||||
uint64_t size; /* size of the file */
|
||||
};
|
||||
|
||||
struct file_descriptor {
|
||||
struct file *file;
|
||||
|
||||
int fd;
|
||||
uint64_t pos;
|
||||
uint32_t flags;
|
||||
|
||||
char *buf;
|
||||
size_t buf_len;
|
||||
|
||||
struct fs *fs;
|
||||
};
|
||||
|
||||
struct fs_ops {
|
||||
int (*read)(struct vnode *vnode, void *buf, size_t offset, size_t size);
|
||||
int (*write)(struct vnode *vnode, void *buf, size_t offset, size_t size);
|
||||
int (*unlink)(struct vnode *parent, const char *name);
|
||||
int (*creat)(struct vnode *parent, const char *path, mode_t mode);
|
||||
int (*open_vno)(struct fs *vfs, struct vnode *out, ino_t ino_num);
|
||||
};
|
||||
|
||||
struct fs {
|
||||
struct vnode *root;
|
||||
void *fs;
|
||||
uint32_t type;
|
||||
struct fs_ops *ops;
|
||||
|
||||
char *mount_point;
|
||||
};
|
||||
|
||||
struct statbuf {
|
||||
size_t size;
|
||||
};
|
||||
|
||||
void vfs_init(const char *rootfs);
|
||||
ssize_t vfs_write(struct file *file, void *buf, off_t off, size_t count);
|
||||
ssize_t vfs_read(struct file *file, void *buf, off_t off, size_t count);
|
||||
int vfs_statf(struct file *file, struct statbuf *statbuf);
|
||||
struct file *vfs_open(const char *pathname, int *err);
|
||||
struct vnode *vfs_create_file(struct vnode *parent, const char *path, mode_t mode);
|
||||
struct vnode *vfs_mknod(const char *pathname, mode_t mode);
|
||||
int vfs_close(struct file *file);
|
||||
int unlink(const char *pathname);
|
||||
int statfd(struct file_descriptor *fdesc, struct statbuf *statbuf);
|
||||
|
||||
char *basename(char *path);
|
||||
char *dirname(char *path);
|
||||
|
||||
struct fs *vfs_create();
|
||||
struct vnode *vfs_create_vno();
|
||||
void vfs_dealloc(struct fs *fs);
|
||||
int vfs_mount(struct fs *fs, const char *mount_point);
|
||||
|
||||
uint64_t vfs_file_type(struct file *file);
|
||||
void *vfs_file_dev(struct file *file);
|
||||
|
||||
int stdout_write(struct file_descriptor *fdesc, void *buf, size_t len);
|
||||
|
||||
#endif /* _VFS_H_ */
|
||||
Loading…
Reference in a new issue