diff options
author | Ian McFarlane <i.mcfarlane2002@gmail.com> | 2025-04-22 14:51:47 -0400 |
---|---|---|
committer | Ian McFarlane <i.mcfarlane2002@gmail.com> | 2025-04-22 14:51:47 -0400 |
commit | 325e2ea9aef0723645b86bdc773f02293747c495 (patch) | |
tree | 2d844c3e30a27eaf463fed851620221f3ad7d540 /kernel/fs/fs.c | |
parent | try to find mcfg (diff) | |
parent | force rebuild on header change (diff) | |
download | comus-pcie.tar.gz comus-pcie.tar.bz2 comus-pcie.zip |
Merge branch 'main' into pciepcie
Diffstat (limited to 'kernel/fs/fs.c')
-rw-r--r-- | kernel/fs/fs.c | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/kernel/fs/fs.c b/kernel/fs/fs.c index 4b6bc5d..c8399a3 100644 --- a/kernel/fs/fs.c +++ b/kernel/fs/fs.c @@ -18,7 +18,7 @@ void fs_init(void) void *rd = mboot_get_initrd(&rd_len); if (rd != NULL) { assert(idx < N_DISKS, "Too many disks, limit is: %d\n", N_DISKS); - fs_disks[idx] = (struct disk) { + fs_disks[idx] = (struct disk){ .present = 1, .id = idx, .type = DISK_TYPE_RAMDISK, @@ -32,7 +32,7 @@ void fs_init(void) 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); - fs_disks[idx] = (struct disk) { + fs_disks[idx] = (struct disk){ .present = 1, .id = idx, .type = DISK_TYPE_ATA, @@ -92,7 +92,8 @@ int fs_find_file_rel(struct file *rel, char *rel_path, struct file *res) panic("fs_find_file_rel NOT YET IMPLEMENTED"); } -static int disk_read_rd(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) +static int disk_read_rd(struct disk *disk, size_t offset, size_t len, + uint8_t *buffer) { if (offset + len >= disk->rd.len) { WARN("attempted to read past length of ramdisk"); @@ -103,7 +104,8 @@ static int disk_read_rd(struct disk *disk, size_t offset, size_t len, uint8_t *b return 0; } -static int disk_read_ata(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) +static int disk_read_ata(struct disk *disk, size_t offset, size_t len, + uint8_t *buffer) { static size_t atabuf_len = 0; static uint16_t *atabuf = NULL; @@ -112,28 +114,28 @@ static int disk_read_ata(struct disk *disk, size_t offset, size_t len, uint8_t * uint32_t err = offset % ATA_SECT_SIZE; int ret = 0; - if (atabuf == NULL || atabuf_len < numsects*ATA_SECT_SIZE) { - if ((atabuf = krealloc(atabuf, numsects*ATA_SECT_SIZE)) == NULL) + if (atabuf == NULL || atabuf_len < numsects * ATA_SECT_SIZE) { + if ((atabuf = krealloc(atabuf, numsects * ATA_SECT_SIZE)) == NULL) return 1; - atabuf_len = numsects*ATA_SECT_SIZE; + atabuf_len = numsects * ATA_SECT_SIZE; } // read sectors - if ((ret = ide_device_read_sectors(disk->ide, numsects, offset / ATA_SECT_SIZE, atabuf))) + if ((ret = ide_device_read_sectors(disk->ide, numsects, + offset / ATA_SECT_SIZE, atabuf))) return 1; // copy over to buffer - memcpy(buffer, atabuf + err, len); + memcpy(buffer, (char *)atabuf + err, len); return ret; } - -int disk_read(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) +int disk_read(struct disk *disk, size_t offset, size_t len, void *buffer) { int ret = 0; - switch(disk->type) { + switch (disk->type) { case DISK_TYPE_RAMDISK: ret = disk_read_rd(disk, offset, len, buffer); break; @@ -141,14 +143,16 @@ int disk_read(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) ret = disk_read_ata(disk, offset, len, buffer); break; default: - ERROR("attempted to read from disk with invalid type: %d\n", disk->type); + ERROR("attempted to read from disk with invalid type: %d\n", + disk->type); ret = 1; } return ret; } -static int disk_write_rd(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) +static int disk_write_rd(struct disk *disk, size_t offset, size_t len, + uint8_t *buffer) { if (offset + len >= disk->rd.len) { WARN("attempted to write past length of ramdisk"); @@ -159,7 +163,8 @@ static int disk_write_rd(struct disk *disk, size_t offset, size_t len, uint8_t * return 0; } -static int disk_write_ata(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) +static int disk_write_ata(struct disk *disk, size_t offset, size_t len, + uint8_t *buffer) { static size_t atabuf_len = 0; static uint16_t *atabuf = NULL; @@ -168,31 +173,33 @@ static int disk_write_ata(struct disk *disk, size_t offset, size_t len, uint8_t uint32_t err = offset % ATA_SECT_SIZE; int ret = 0; - if (atabuf == NULL || atabuf_len < numsects*ATA_SECT_SIZE) { - if ((atabuf = krealloc(atabuf, numsects*ATA_SECT_SIZE)) == NULL) + if (atabuf == NULL || atabuf_len < numsects * ATA_SECT_SIZE) { + if ((atabuf = krealloc(atabuf, numsects * ATA_SECT_SIZE)) == NULL) return 1; - atabuf_len = numsects*ATA_SECT_SIZE; + atabuf_len = numsects * ATA_SECT_SIZE; } // read sectors what will be overwritten - if ((ret = ide_device_read_sectors(disk->ide, numsects, offset / ATA_SECT_SIZE, atabuf))) + if ((ret = ide_device_read_sectors(disk->ide, numsects, + offset / ATA_SECT_SIZE, atabuf))) return 1; // copy custom data over - memcpy(atabuf + err, buffer, len); + memcpy((char *)atabuf + err, buffer, len); // write back sectors - if ((ret = ide_device_write_sectors(disk->ide, numsects, offset / ATA_SECT_SIZE, atabuf))) + if ((ret = ide_device_write_sectors(disk->ide, numsects, + offset / ATA_SECT_SIZE, atabuf))) return 1; return ret; } -int disk_write(struct disk *disk, size_t offset, size_t len, uint8_t *buffer) +int disk_write(struct disk *disk, size_t offset, size_t len, void *buffer) { int ret = 0; - switch(disk->type) { + switch (disk->type) { case DISK_TYPE_RAMDISK: ret = disk_write_rd(disk, offset, len, buffer); break; |