finish new filesystem

This commit is contained in:
sfja 2026-11-24 03:33:57 +01:00
parent e5ffb4ff3d
commit a33dd11f03
3 changed files with 756 additions and 151 deletions

View File

@ -27,18 +27,29 @@ block()
set(fs_file ${CMAKE_CURRENT_BINARY_DIR}/fs.bin) set(fs_file ${CMAKE_CURRENT_BINARY_DIR}/fs.bin)
set(disk_file ${CMAKE_CURRENT_BINARY_DIR}/disk.bin) set(disk_file ${CMAKE_CURRENT_BINARY_DIR}/disk.bin)
# add_custom_command(
# OUTPUT ${fs_file}
# COMMAND fstool ${fs_file} mkfile /kernel.bin
# COMMAND fstool ${fs_file} import ${kernel_file} /kernel.bin
# COMMAND fstool ${fs_file} mkdir /docs
# COMMAND fstool ${fs_file} mkfile /docs/readme.txt
# COMMAND fstool ${fs_file} importb ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt /docs/readme.txt
# DEPENDS fstool ${kernel_file}
# VERBATIM
# USES_TERMINAL
# )
add_custom_command( add_custom_command(
OUTPUT ${fs_file} OUTPUT ${fs_file}
COMMAND fstool ${fs_file} mkfile /kernel.bin COMMAND fs2 -d ${fs_file} -c importw2w ${kernel_file} /kernel.bin
COMMAND fstool ${fs_file} import ${kernel_file} /kernel.bin COMMAND fs2 -d ${fs_file} -c mkdir /docs
COMMAND fstool ${fs_file} mkdir /docs COMMAND fs2 -d ${fs_file} -c importb2w ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt /docs/readme.txt
COMMAND fstool ${fs_file} mkfile /docs/readme.txt DEPENDS fs2 ${kernel_file}
COMMAND fstool ${fs_file} importb ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt /docs/readme.txt
DEPENDS fstool ${kernel_file}
VERBATIM VERBATIM
USES_TERMINAL USES_TERMINAL
) )
add_custom_command( add_custom_command(
OUTPUT ${disk_file} OUTPUT ${disk_file}
COMMAND mkdisk ${disk_file} ${boot_file} ${fs_file}:0800 COMMAND mkdisk ${disk_file} ${boot_file} ${fs_file}:0800

855
src/fs2.c

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ constexpr size_t fs_inode_ind_block_idx = fs_inode_ndir_blocks_count;
constexpr uint16_t fs_superblock_magic = 0x5a5a; constexpr uint16_t fs_superblock_magic = 0x5a5a;
typedef uint16_t word; typedef uint16_t word;
typedef int16_t iword;
enum : word { enum : word {
INode_File, INode_File,
@ -65,6 +66,21 @@ typedef struct {
word current_offset; word current_offset;
} DirCursor; } DirCursor;
typedef enum : word {
File_Read = 1 << 0,
File_Write = 1 << 1,
File_Trunc = 1 << 2,
File_ReadWrite = File_Read | File_Write,
} FileMode;
typedef struct {
INode *inode;
word mode;
word current_block_idx;
word current_offset;
} FileCursor;
typedef struct Disk Disk; typedef struct Disk Disk;
struct Disk { struct Disk {
@ -80,10 +96,12 @@ typedef struct {
word *ind_block; word *ind_block;
word *direntry_block; word *direntry_block;
word *inode_block; word *inode_block;
word *data_block;
Superblock *sb; Superblock *sb;
word current_ind_block_id; word current_ind_block_id;
word current_direntry_block_id; word current_direntry_block_id;
word current_inode_block_id; word current_inode_block_id;
word current_data_block_id;
bool out_of_sync; bool out_of_sync;
} Fs; } Fs;
@ -93,12 +111,21 @@ void fs_sync(Fs *fs);
void fs_root(Fs *fs, INode *out_inode); void fs_root(Fs *fs, INode *out_inode);
void fs_inode(Fs *fs, INode *out_inode, word inode_id); void fs_inode(Fs *fs, INode *out_inode, word inode_id);
void fs_opendir(Fs *fs, DirCursor *out_cursor, INode *inode); word fs_opendir(Fs *fs, DirCursor *out_cursor, INode *inode);
void fs_closedir(Fs *fs, DirCursor *cursor); void fs_closedir(Fs *fs, DirCursor *cursor);
DirEntry *fs_readdir(Fs *fs, DirCursor *cursor); DirEntry *fs_readdir(Fs *fs, DirCursor *cursor);
word fs_mkdir(Fs *fs, INode *out_inode, INode *parent, const word *name); word fs_mkdir(Fs *fs, INode *out_inode, INode *parent, const word *name);
word fs_rmdir(Fs *fs, INode *inode); word fs_rmdir(Fs *fs, INode *inode);
word fs_mkfile(Fs *fs, INode *out_inode, INode *parent, const word *name);
word fs_unlink(Fs *fs, INode *inode, INode *dirinode);
word fs_open(Fs *fs, FileCursor *out_cursor, INode *inode, FileMode mode);
void fs_close(Fs *fs, FileCursor *cursor);
iword fs_read(Fs *fs, FileCursor *cursor, word *buffer, word count);
iword fs_write(Fs *fs, FileCursor *cursor, const word *buffer, word count);
int fs_tell(Fs *fs, FileCursor *cursor);
void fs_seek(Fs *fs, FileCursor *cursor, int pos);
void fs_mkfs(Fs *fs, Disk *disk, word block_offset); void fs_mkfs(Fs *fs, Disk *disk, word block_offset);
#endif #endif