diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-30 11:41:20 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-30 11:41:20 -0400 |
commit | 9da9cd84dd084f521d9cbdae292deea96e36f86c (patch) | |
tree | 40fda2070a2ba8db6900c1a6bbc9a194c26f6c65 /kernel | |
parent | lossy RLE for apple (diff) | |
download | comus-9da9cd84dd084f521d9cbdae292deea96e36f86c.tar.gz comus-9da9cd84dd084f521d9cbdae292deea96e36f86c.tar.bz2 comus-9da9cd84dd084f521d9cbdae292deea96e36f86c.zip |
update fs headers 3.0
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/fs/fs.c | 17 | ||||
-rw-r--r-- | kernel/include/comus/fs.h | 23 |
2 files changed, 29 insertions, 11 deletions
diff --git a/kernel/fs/fs.c b/kernel/fs/fs.c index 4c7ea29..f9b3959 100644 --- a/kernel/fs/fs.c +++ b/kernel/fs/fs.c @@ -1,4 +1,3 @@ -#include "comus/memory.h" #include <lib.h> #include <comus/fs.h> #include <comus/mboot.h> @@ -15,7 +14,7 @@ static void load_disks(void) size_t rd_len; void *rd = mboot_get_initrd(&rd_len); if (rd != NULL) { - assert(idx < N_DISKS, "Too many disks, limit is: %d\n", N_DISKS); + assert(idx < N_DISKS, "Too many disks, limit is: %d", N_DISKS); fs_disks[idx] = (struct disk){ .d_present = 1, .d_id = idx, @@ -29,7 +28,7 @@ static void load_disks(void) // check for ide/ata devices struct ide_devicelist ide_list = ide_devices_enumerate(); for (size_t i = 0; i < ide_list.num_devices; i++) { - assert(idx < N_DISKS, "Too many disks, limit is: %d\n", N_DISKS); + assert(idx < N_DISKS, "Too many disks, limit is: %d", N_DISKS); fs_disks[idx] = (struct disk){ .d_present = 1, .d_id = idx, @@ -45,19 +44,23 @@ static void load_disks(void) static void load_fs(struct disk *disk) { - struct file_system *fs = &fs_loaded_file_systems[disk->d_id]; + struct file_system *fs; + + fs = &fs_loaded_file_systems[disk->d_id]; fs->fs_disk = disk; fs->fs_id = disk->d_id; + fs->fs_present = 1; - (void)fs; - // TODO: load fs on disk + // // try examplefs + // if (example_mount(fs) == SUCCESS) + // return; + fs->fs_present = 0; WARN("failed to load fs on disk %u", disk->d_id); } void fs_init(void) { - // zero structures memsetv(fs_disks, 0, sizeof(fs_disks)); memsetv(fs_loaded_file_systems, 0, sizeof(fs_loaded_file_systems)); diff --git a/kernel/include/comus/fs.h b/kernel/include/comus/fs.h index 77d065e..5989afc 100644 --- a/kernel/include/comus/fs.h +++ b/kernel/include/comus/fs.h @@ -83,6 +83,16 @@ struct stat { unsigned long s_length; }; +/// seek whence +enum { + /// seek from start of file + SEEK_SET = 0, + /// seek from current position + SEEK_CUR = 1, + /// seek from end of file + SEEK_END = 2, +}; + /// generic file pointer type. file system open function /// must extend this struct, allocate it on the heap, /// and return it as a generic file pointer. @@ -103,13 +113,16 @@ struct stat { /// size_t sector; // data /// }; /// -/// int example_open(const char *fullpath, struct file **out) +/// int example_open(struct file_system *fs, const char *fullpath, +/// struct file **out) /// { /// struct example_file *file; /// /// // do some checks here to get file info at full path +/// // header = example_locate(fs, fullpath); ?? /// /// file = kalloc(sizeof(struct example_file)); +/// file->f_type = F_REG; /// file->read = example_read; /// file->write = example_write; /// file->seek = example_seek; @@ -121,10 +134,12 @@ struct stat { /// ``` /// struct file { + /// file type + enum file_type f_type; /// read from the file int (*read)(struct file *file, char *buffer, size_t nbytes); /// write into the file - int (*write)(struct file *file, char *buffer, size_t nbytes); + int (*write)(struct file *file, const char *buffer, size_t nbytes); /// seeks the file int (*seek)(struct file *file, long int offset, int whence); /// get directory entry at index @@ -185,9 +200,9 @@ struct file_system { /// filesystem name const char *fs_name; /// opens a file - int (*open)(const char *fullpath, struct file **out); + int (*open)(struct file_system *fs, const char *fullpath, struct file **out); /// stats a file - int (*stat)(const char *fullpath, struct stat *file); + int (*stat)(struct file_system *fs, const char *fullpath, struct stat *file); }; // list of all disks on the system |