summaryrefslogtreecommitdiff
path: root/kernel/fs
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-13 19:20:36 +0100
committerAnton Kling <anton@kling.gg>2023-11-13 19:23:58 +0100
commit1de1e8d02f392ed8bb061705d7717351bf3023bd (patch)
tree2f44b4e79d62225b27a8823bdfd9634ba5cb6a4e /kernel/fs
parent1966047921e2958469f9faac1bd1f56d1fc5587a (diff)
Kernel: Add support for AHCI and make use of it with the current filesystem.
It will now also create a corresponding /dev/sd* device for each detected SATA drive. The filesystem still writes using the ATA driver. This should be fixed soon.
Diffstat (limited to 'kernel/fs')
-rw-r--r--kernel/fs/ext2.c13
-rw-r--r--kernel/fs/vfs.h1
2 files changed, 12 insertions, 2 deletions
diff --git a/kernel/fs/ext2.c b/kernel/fs/ext2.c
index 8092b23..17d9e11 100644
--- a/kernel/fs/ext2.c
+++ b/kernel/fs/ext2.c
@@ -14,6 +14,8 @@ u32 block_byte_size;
u32 inode_size;
u32 inodes_per_block;
+vfs_fd_t *mount_fd = NULL;
+
#define BLOCK_SIZE (block_byte_size)
void ext2_close(vfs_fd_t *fd) {
@@ -55,7 +57,7 @@ void cached_read_block(u32 block, void *address, size_t size, size_t offset) {
struct BLOCK_CACHE *c = &cache[free_found];
c->block_num = block;
- read_lba(block * block_byte_size / 512, c->block, 1024, 0);
+ raw_vfs_pread(mount_fd, c->block, 1024, block * block_byte_size);
cached_read_block(block, address, size, offset);
}
@@ -740,6 +742,11 @@ int ext2_create_file(const char *path, int mode) {
}
vfs_inode_t *ext2_mount(void) {
+ int fd = vfs_open("/dev/sda", O_RDWR, 0);
+ // TODO: Can this be done better? Maybe create a seperate function in
+ // the VFS?
+ mount_fd = get_current_task()->file_descriptors[fd];
+ get_current_task()->file_descriptors[fd] = NULL;
parse_superblock();
return vfs_create_inode(0 /*inode_num*/, 0 /*type*/, 0 /*has_data*/,
0 /*can_write*/, 0 /*is_open*/,
@@ -751,7 +758,9 @@ vfs_inode_t *ext2_mount(void) {
void parse_superblock(void) {
superblock = ksbrk(2 * SECTOR_SIZE);
- read_lba(EXT2_SUPERBLOCK_SECTOR, (void *)superblock, 2 * SECTOR_SIZE, 0);
+ raw_vfs_pread(mount_fd, superblock, 2 * SECTOR_SIZE,
+ EXT2_SUPERBLOCK_SECTOR * 512);
+
block_byte_size = 1024 << superblock->block_size;
if (0xEF53 != superblock->ext2_signature) {
diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h
index 0ce5cd1..949d175 100644
--- a/kernel/fs/vfs.h
+++ b/kernel/fs/vfs.h
@@ -78,6 +78,7 @@ void vfs_mount(char *path, vfs_inode_t *local_root);
int vfs_pwrite(int fd, void *buf, u64 count, u64 offset);
int raw_vfs_pwrite(vfs_fd_t *vfs_fd, void *buf, u64 count,
u64 offset);
+int raw_vfs_pread(vfs_fd_t *vfs_fd, void *buf, u64 count, u64 offset);
int vfs_pread(int fd, void *buf, u64 count, u64 offset);
vfs_vm_object_t *vfs_get_vm_object(int fd, u64 length, u64 offset);
int vfs_dup2(int org_fd, int new_fd);