aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/fs')
-rw-r--r--src/kernel/fs/ata_pio.c122
-rw-r--r--src/kernel/fs/ata_pio.h30
-rw-r--r--src/kernel/fs/atapi_pio.c12
-rw-r--r--src/kernel/fs/atapi_pio.h6
-rw-r--r--src/kernel/fs/install.c21
-rw-r--r--src/kernel/fs/iso9660/iso9660.c20
-rw-r--r--src/kernel/fs/iso9660/iso9660.h8
-rw-r--r--src/kernel/fs/marfs/directory.c44
-rw-r--r--src/kernel/fs/marfs/disklevel.c9
-rw-r--r--src/kernel/fs/marfs/marfs.h42
-rw-r--r--src/kernel/fs/marfs/new_file.c94
-rw-r--r--src/kernel/fs/marfs/read_whole_file.c40
-rw-r--r--src/kernel/fs/marfs/sectorlevel.c71
-rw-r--r--src/kernel/fs/vfs.c18
14 files changed, 288 insertions, 249 deletions
diff --git a/src/kernel/fs/ata_pio.c b/src/kernel/fs/ata_pio.c
index d3544ba..78cf7ac 100644
--- a/src/kernel/fs/ata_pio.c
+++ b/src/kernel/fs/ata_pio.c
@@ -3,123 +3,127 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/interrupts/interrupts.h>
-struct ATA_INTERFACE *new_ATA(uint8_t master, uint16_t portBase) {
- struct ATA_INTERFACE *ret = kmalloc(sizeof(struct ATA_INTERFACE));
+struct ata_interface *new_ata(uint8_t master, uint16_t port_base)
+{
+ struct ata_interface *ret = kmalloc(sizeof(struct ata_interface));
ret->master = master;
- ret->dataPort = portBase;
- ret->errorPort = portBase + 0x1;
- ret->sectorCountPort = portBase + 0x2;
- ret->lbaLowPort = portBase + 0x3;
- ret->lbaMidPort = portBase + 0x4;
- ret->lbaHiPort = portBase + 0x5;
- ret->devicePort = portBase + 0x6;
- ret->commandPort = portBase + 0x7;
- ret->controlPort = portBase + 0x206;
-
- // isr_ignore(0x06);
+ ret->data_port = port_base;
+ ret->error_port = port_base + 0x1;
+ ret->sector_count_port = port_base + 0x2;
+ ret->lba_low_port = port_base + 0x3;
+ ret->lba_mid_port = port_base + 0x4;
+ ret->lba_high_port = port_base + 0x5;
+ ret->device_port = port_base + 0x6;
+ ret->command_port = port_base + 0x7;
+ ret->control_port = port_base + 0x206;
+
// isr_ignore(0x2E);
// isr_ignore(0x2F);
return ret;
}
-uint8_t ATA_identify(struct ATA_INTERFACE *iface, uint16_t *retdata) {
- send_b(iface->devicePort, iface->master ? 0xA0 : 0xB0);
- send_b(iface->controlPort, 0);
+uint8_t ata_identify(struct ata_interface *interface, uint16_t *ret_data)
+{
+ outb(interface->device_port, interface->master ? 0xA0 : 0xB0);
+ outb(interface->control_port, 0);
- send_b(iface->devicePort, 0xA0);
- uint8_t status = receive_b(iface->commandPort);
+ outb(interface->device_port, 0xA0);
+ uint8_t status = inb(interface->command_port);
if (status == 0xFF) return 1;
- send_b(iface->devicePort, iface->master ? 0xA0 : 0xB0);
- send_b(iface->sectorCountPort, 0);
- send_b(iface->lbaLowPort, 0);
- send_b(iface->lbaMidPort, 0);
- send_b(iface->lbaHiPort, 0);
- send_b(iface->commandPort, 0xEC); // Identify command
+ outb(interface->device_port, interface->master ? 0xA0 : 0xB0);
+ outb(interface->sector_count_port, 0);
+ outb(interface->lba_low_port, 0);
+ outb(interface->lba_mid_port, 0);
+ outb(interface->lba_high_port, 0);
+ outb(interface->command_port, 0xEC); // Identify command
- status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
if (!status) return 1;
while (((status & 0x80) == 0x80) && ((status & 0x01) != 0x01)) {
- status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
}
if (status & 0x01) return 1;
- for (int i = 0; i < 256; i++) retdata[i] = receive_w(iface->dataPort);
+ for (int i = 0; i < 256; i++) ret_data[i] = inw(interface->data_port);
return 0;
}
-uint8_t *ATA_read28(struct ATA_INTERFACE *iface, uint32_t sector) {
+uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector)
+{
if (sector > 0x0FFFFFFF) return 0;
- send_b(iface->devicePort, (iface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
+ outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
- uint8_t status;
- for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort);
+ uint8_t status = 0;
+ for (int i = 0; i < 5; i++) status = inb(interface->command_port);
if (status == 0xFF) return 0;
- send_b(iface->errorPort, 0);
- send_b(iface->sectorCountPort, 1);
- send_b(iface->lbaLowPort, sector & 0x000000FF);
- send_b(iface->lbaMidPort, (sector & 0x0000FF00) >> 8);
- send_b(iface->lbaHiPort, (sector & 0x00FF0000) >> 16);
- send_b(iface->commandPort, 0x20); // Read command
+ outb(interface->error_port, 0);
+ outb(interface->sector_count_port, 1);
+ outb(interface->lba_low_port, sector & 0x000000FF);
+ outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8);
+ outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16);
+ outb(interface->command_port, 0x20); // Read command
- status = receive_b(iface->commandPort);
- while ((status & 0x80) && !(status & 0x01)) status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
+ while ((status & 0x80) && !(status & 0x01)) status = inb(interface->command_port);
uint8_t *ret = kmalloc(BYTES_PER_SECTOR);
for (int i = 0; i < BYTES_PER_SECTOR; i += 2) {
- uint16_t data = receive_w(iface->dataPort);
+ uint16_t data = inw(interface->data_port);
ret[i] = data & 0xFF;
ret[i + 1] = (data >> 8) & 0xFF;
}
return ret;
}
-uint8_t ATA_write28(struct ATA_INTERFACE *iface, uint32_t sector, uint8_t *contents) {
+uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint8_t *contents)
+{
if (sector > 0x0FFFFFFF) return 1;
- asm volatile ("cli");
+ asm ("cli");
- send_b(iface->devicePort, (iface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
+ outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
- uint8_t status;
- for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort);
+ uint8_t status = 0;
+ for (int i = 0; i < 5; i++) status = inb(interface->command_port);
if (status == 0xFF) return 1;
- send_b(iface->errorPort, 0);
- send_b(iface->sectorCountPort, 1);
- send_b(iface->lbaLowPort, sector & 0x000000FF);
- send_b(iface->lbaMidPort, (sector & 0x0000FF00) >> 8);
- send_b(iface->lbaHiPort, (sector & 0x00FF0000) >> 16);
- send_b(iface->commandPort, 0x30); // Write command
+ outb(interface->error_port, 0);
+ outb(interface->sector_count_port, 1);
+ outb(interface->lba_low_port, sector & 0x000000FF);
+ outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8);
+ outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16);
+ outb(interface->command_port, 0x30); // Write command
- while ((status & 0x80) || !(status & 0x08)) status = receive_b(iface->commandPort);
+ while ((status & 0x80) || !(status & 0x08)) status = inb(interface->command_port);
if (status & (0x01 || 0x20)) return 2;
for (int i = 0; i < BYTES_PER_SECTOR; i += 2) {
uint16_t data = contents[i];
data |= ((uint16_t) contents[i + 1]) << 8;
- send_w(iface->dataPort, data);
+ outw(interface->data_port, data);
}
- send_b(iface->commandPort, 0xE7); // Flush command
+ outb(interface->command_port, 0xE7); // Flush command
- for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort);
+ for (int i = 0; i < 5; i++) status = inb(interface->command_port);
if (!status) return 3;
while ((status & 0x80) && !(status & 0x01)) {
- status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
}
return 0;
}
-uint8_t ATA_clear28(struct ATA_INTERFACE *iface, uint32_t sector) {
- uint8_t emptysector[512] = {0};
- return ATA_write28(iface, sector, emptysector);
+uint8_t ata_clear28(struct ata_interface *interface, uint32_t sector)
+{
+ uint8_t empty_sector[512] = {0};
+ return ata_write28(interface, sector, empty_sector);
} \ No newline at end of file
diff --git a/src/kernel/fs/ata_pio.h b/src/kernel/fs/ata_pio.h
index 3f1439d..fa08a0c 100644
--- a/src/kernel/fs/ata_pio.h
+++ b/src/kernel/fs/ata_pio.h
@@ -5,27 +5,27 @@
#define BYTES_PER_SECTOR 512
-struct ATA_INTERFACE {
+struct ata_interface {
uint8_t master;
- uint16_t dataPort;
- uint16_t errorPort;
- uint16_t sectorCountPort;
- uint16_t lbaLowPort;
- uint16_t lbaMidPort;
- uint16_t lbaHiPort;
- uint16_t devicePort;
- uint16_t commandPort;
- uint16_t controlPort;
+ uint16_t data_port;
+ uint16_t error_port;
+ uint16_t sector_count_port;
+ uint16_t lba_low_port;
+ uint16_t lba_mid_port;
+ uint16_t lba_high_port;
+ uint16_t device_port;
+ uint16_t command_port;
+ uint16_t control_port;
};
-struct ATA_INTERFACE *new_ATA(uint8_t master, uint16_t portBase);
+struct ata_interface *new_ata(uint8_t master, uint16_t port_base);
-uint8_t ATA_identify(struct ATA_INTERFACE *iface, uint16_t *retdata);
+uint8_t ata_identify(struct ata_interface *interface, uint16_t *ret_data);
-uint8_t *ATA_read28(struct ATA_INTERFACE *iface, uint32_t sector);
+uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector);
-uint8_t ATA_write28(struct ATA_INTERFACE *iface, uint32_t sector, uint8_t *contents);
+uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint8_t *contents);
-uint8_t ATA_clear28(struct ATA_INTERFACE *iface, uint32_t sector);
+uint8_t ata_clear28(struct ata_interface *interface, uint32_t sector);
#endif
diff --git a/src/kernel/fs/atapi_pio.c b/src/kernel/fs/atapi_pio.c
index e64cd75..34cd1e6 100644
--- a/src/kernel/fs/atapi_pio.c
+++ b/src/kernel/fs/atapi_pio.c
@@ -3,13 +3,14 @@
#include <kernel/system.h>
#include <kernel/paging/paging.h>
-void ATAPI_read(uint16_t nblocks, uint32_t lba) {
+void ATAPI_read(uint16_t nblocks, uint32_t lba)
+{
struct dapack *d = (struct dapack *) ATAPI_PIO_DAPACK;
d->size = 0x10;
d->null = 0x00;
- d->blkcount = nblocks;
- d->boffset = ATAPI_PIO_BUFFER;
- d->bsegment = 0x0000;
+ d->blk_count = nblocks;
+ d->b_offset = ATAPI_PIO_BUFFER;
+ d->b_segment = 0x0000;
d->start = lba;
d->upper_lba_bits = 0x00000000;
@@ -22,7 +23,8 @@ void ATAPI_read(uint16_t nblocks, uint32_t lba) {
v86(LBA_READ_INT, &regs);
}
-void ATAPI_granular_read(uint32_t nblocks, uint32_t lba, uint8_t *output) {
+void ATAPI_granular_read(uint32_t nblocks, uint32_t lba, uint8_t *output)
+{
for (uint32_t i = 0; i < nblocks; i++) {
ATAPI_read(1, lba + i);
for (uint16_t j = 0; j < ATAPI_SECTOR_SIZE; j++) output[j + (2048 * i)] = ((uint8_t *) ATAPI_PIO_BUFFER)[j];
diff --git a/src/kernel/fs/atapi_pio.h b/src/kernel/fs/atapi_pio.h
index 5e89e85..be48f2f 100644
--- a/src/kernel/fs/atapi_pio.h
+++ b/src/kernel/fs/atapi_pio.h
@@ -12,9 +12,9 @@
struct dapack {
uint8_t size;
uint8_t null;
- uint16_t blkcount;
- uint16_t boffset;
- uint16_t bsegment;
+ uint16_t blk_count;
+ uint16_t b_offset;
+ uint16_t b_segment;
uint32_t start;
uint32_t upper_lba_bits;
} __attribute__((packed));
diff --git a/src/kernel/fs/install.c b/src/kernel/fs/install.c
index c098266..d5f62b2 100644
--- a/src/kernel/fs/install.c
+++ b/src/kernel/fs/install.c
@@ -6,16 +6,18 @@
#include <mlibc/stdlib.h>
#include <kernel/acpi/acpi.h>
#include <kernel/io/io.h>
+#include <kernel/timer/timer.h>
-void install_melvix() {
- info("You're booting from a CD, Melvix will only run after an install");
- asm volatile ("cli");
- struct ATA_INTERFACE *primary_master = new_ATA(1, 0x1F0);
+void install_melvix()
+{
+ info("You're booting from a CD, Melvix will only run after an installation");
+ asm ("cli");
+ struct ata_interface *primary_master = new_ata(1, 0x1F0);
if (marfs_init(primary_master) != 0) {
panic("No HDD found!");
}
- struct marfs_SUPERBLOCK *currentSB = marfs_read_superblock();
+ struct marfs_superblock *currentSB = marfs_read_superblock();
if (currentSB->signature == 0x1083B99F34B59645) { // WEEEOOOWEEEOOO
panic("Melvix seems to be already installed!");
}
@@ -26,7 +28,7 @@ void install_melvix() {
// Copy MBR
info("Copying MBR... ");
char *stage1_p[] = {"BOOT", "HDD1.BIN"};
- struct ISO9660_entity *stage1_e = ISO9660_get(stage1_p, 2);
+ struct iso9660_entity *stage1_e = ISO9660_get(stage1_p, 2);
if (!stage1_e)
panic("Couldn't find the first HDD bootloader!");
uint8_t *stage1 = ISO9660_read(stage1_e);
@@ -40,7 +42,7 @@ void install_melvix() {
// Copy second stage
info("Copying second stage...");
char *stage2_p[] = {"BOOT", "HDD2.BIN"};
- struct ISO9660_entity *stage2_e = ISO9660_get(stage2_p, 2);
+ struct iso9660_entity *stage2_e = ISO9660_get(stage2_p, 2);
if (!stage2_e)
panic("Couldn't find the second HDD bootloader!");
uint8_t *stage2 = ISO9660_read(stage2_e);
@@ -50,16 +52,17 @@ void install_melvix() {
// Copy the kernel
info("Copying the kernel... ");
char *kernel_p[] = {"BOOT", "KERNEL.BIN"};
- struct ISO9660_entity *kernel_e = ISO9660_get(kernel_p, 2);
+ struct iso9660_entity *kernel_e = ISO9660_get(kernel_p, 2);
if (!kernel_e)
panic("WTH Kernel not found!?");
uint8_t *kernel = kmalloc(kernel_e->length + 2048);
- ATAPI_granular_read(1 + (kernel_e->length / 2048), kernel_e->LBA, kernel);
+ ATAPI_granular_read(1 + (kernel_e->length / 2048), kernel_e->lba, kernel);
marfs_new_file(kernel_e->length, kernel, 0, 0, 0);
kfree(kernel);
kfree(kernel_e);
info("Installation successful!");
serial_write("Installation successful!\nRebooting...\n");
+ timer_wait(200);
acpi_poweroff();
} \ No newline at end of file
diff --git a/src/kernel/fs/iso9660/iso9660.c b/src/kernel/fs/iso9660/iso9660.c
index f8eddd4..81b1ba6 100644
--- a/src/kernel/fs/iso9660/iso9660.c
+++ b/src/kernel/fs/iso9660/iso9660.c
@@ -4,21 +4,22 @@
#include <kernel/fs/iso9660/iso9660.h>
#include <mlibc/stdlib.h>
-struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) {
+struct iso9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz)
+{
ATAPI_read(1, 0x10);
uint32_t last_len = *(uint32_t *) (
ATAPI_PIO_BUFFER +
ISO9660_ROOT_RECORD_OFFSET +
ISO9660_DIR_EAR_LENGTH
);
- uint32_t last_LBA = *(uint32_t *) (
+ uint32_t last_lba = *(uint32_t *) (
ATAPI_PIO_BUFFER +
ISO9660_ROOT_RECORD_OFFSET +
ISO9660_DIR_EAR_LBA
);
for (uint8_t dirs_i = 0; dirs_i < dirs_sz; dirs_i++) {
- ATAPI_read((last_len % 2048 != 0) + (last_len / 2048), last_LBA);
+ ATAPI_read((last_len % 2048 != 0) + (last_len / 2048), last_lba);
uint8_t found = 0;
for (uint32_t i = 0; i < last_len && !found;) {
@@ -36,7 +37,7 @@ struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) {
if (strcmp(dirs[dirs_i], filename) == 0) {
found = 1;
- last_LBA = *(uint32_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_EAR_LBA);
+ last_lba = *(uint32_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_EAR_LBA);
last_len = *(uint32_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_EAR_LENGTH);
} else {
i += *(uint8_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_RECORD_LENGTH);
@@ -44,17 +45,18 @@ struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) {
}
if (!found) {
- return (struct ISO9660_entity *) 0;
+ return (struct iso9660_entity *) 0;
}
}
- struct ISO9660_entity *ret = (struct ISO9660_entity *) kmalloc(sizeof(struct ISO9660_entity));
- ret->LBA = last_LBA;
+ struct iso9660_entity *ret = (struct iso9660_entity *) kmalloc(sizeof(struct iso9660_entity));
+ ret->lba = last_lba;
ret->length = last_len;
return ret;
}
-uint8_t *ISO9660_read(struct ISO9660_entity *entity) {
- ATAPI_read((entity->length % 2048 != 0) + (entity->length / 2048), entity->LBA);
+uint8_t *ISO9660_read(struct iso9660_entity *entity)
+{
+ ATAPI_read((entity->length % 2048 != 0) + (entity->length / 2048), entity->lba);
return (uint8_t *) ATAPI_PIO_BUFFER;
} \ No newline at end of file
diff --git a/src/kernel/fs/iso9660/iso9660.h b/src/kernel/fs/iso9660/iso9660.h
index 3de5d1a..86629e4 100644
--- a/src/kernel/fs/iso9660/iso9660.h
+++ b/src/kernel/fs/iso9660/iso9660.h
@@ -10,13 +10,13 @@
#include <stdint.h>
-struct ISO9660_entity {
- uint32_t LBA;
+struct iso9660_entity {
+ uint32_t lba;
uint32_t length;
};
-struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz);
+struct iso9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz);
-uint8_t *ISO9660_read(struct ISO9660_entity *entity);
+uint8_t *ISO9660_read(struct iso9660_entity *entity);
#endif
diff --git a/src/kernel/fs/marfs/directory.c b/src/kernel/fs/marfs/directory.c
index bf19fc7..210d908 100644
--- a/src/kernel/fs/marfs/directory.c
+++ b/src/kernel/fs/marfs/directory.c
@@ -3,52 +3,56 @@
#include <mlibc/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
-uint32_t marfs_new_dir(uint32_t uid) { return marfs_new_file(0, 0, uid, 0, 1); }
+uint32_t marfs_new_dir(uint32_t uid)
+{
+ return marfs_new_file(0, 0, uid, 0, 1);
+}
-void marfs_add_to_dir(uint32_t LBAinode, char *filename, uint32_t lba) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, LBAinode);
+void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_inode);
// Read the content
- uint8_t *old = marfs_allocate_and_read_whole_file(LBAinode);
+ uint8_t *old = marfs_allocate_and_read_whole_file(lba_inode);
// Allocate memory
uint8_t *contents = kmalloc(inode->size + strlen(filename) + 1 + 4);
// Copy the content
- uint8_t lastWasNull = 0;
- uint64_t newsize = 0;
+ uint8_t last_was_null = 0;
+ uint64_t new_size = 0;
for (uint64_t i = 0; i < inode->size; i++) {
- if (old[i] == 0 && lastWasNull) continue;
+ if (old[i] == 0 && last_was_null) continue;
- contents[newsize++] = old[i];
- lastWasNull = (old[i] == 0);
+ contents[new_size++] = old[i];
+ last_was_null = (old[i] == 0);
}
kfree(old);
// Append new file
- for (uint16_t i = 0; i <= strlen(filename); i++) contents[newsize++] = filename[i];
- for (signed char j = 24; j > 0; j -= 8) contents[newsize++] = (lba >> j) & 0xFF;
+ for (size_t i = 0; i <= strlen(filename); i++) contents[new_size++] = filename[i];
+ for (signed char j = 24; j > 0; j -= 8) contents[new_size++] = (lba >> j) & 0xFF;
// Free the blocks
- uint32_t newsize_in_blocks = newsize / 512;
- if (newsize % 512) newsize_in_blocks++;
- for (uint32_t i = 0; i < newsize_in_blocks; i++)
+ uint32_t new_size_in_blocks = new_size / 512;
+ if (new_size % 512) new_size_in_blocks++;
+ for (uint32_t i = 0; i < new_size_in_blocks; i++)
marfs_mark_block_as_free(marfs_get_block(inode, i));
// Overwrite
- uint32_t aux_inode = marfs_new_file(newsize, contents, 0xDEADBEEF, 0, 0);
- struct marfs_INODE *real_aux_inode = (struct marfs_INODE *) ATA_read28(iface, aux_inode);
+ uint32_t aux_inode = marfs_new_file(new_size, contents, 0xDEADBEEF, 0, 0);
+ struct marfs_inode *real_aux_inode = (struct marfs_inode *) ata_read28(interface, aux_inode);
for (uint8_t i = 0; i < 10; i++) inode->DBPs[i] = real_aux_inode->DBPs[i];
inode->ext_1 = real_aux_inode->ext_1;
inode->ext_2 = real_aux_inode->ext_2;
inode->ext_3 = real_aux_inode->ext_3;
inode->ext_4 = real_aux_inode->ext_4;
- real_aux_inode->isUsed = 0;
- ATA_write28(iface, aux_inode, (uint8_t *) real_aux_inode);
+ real_aux_inode->is_used = 0;
+ ata_write28(interface, aux_inode, (uint8_t *) real_aux_inode);
kfree(real_aux_inode);
- inode->size = newsize;
- ATA_write28(iface, LBAinode, (uint8_t *) inode);
+ inode->size = new_size;
+ ata_write28(interface, lba_inode, (uint8_t *) inode);
kfree(inode);
}
diff --git a/src/kernel/fs/marfs/disklevel.c b/src/kernel/fs/marfs/disklevel.c
index f54dea1..a902362 100644
--- a/src/kernel/fs/marfs/disklevel.c
+++ b/src/kernel/fs/marfs/disklevel.c
@@ -2,9 +2,10 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/fs/marfs/marfs.h>
-void marfs_format(void) {
+void marfs_format(void)
+{
// Create superblock
- struct marfs_SUPERBLOCK sb;
+ struct marfs_superblock sb;
sb.signature = 0x1083B99F34B59645; // Huh, magic?!
sb.n_inodes = (marfs_get_max_lba() - 2) >> 5;
sb.n_chunks = (marfs_get_max_lba() - (2 + sb.n_inodes)) >> 9;
@@ -16,8 +17,8 @@ void marfs_format(void) {
marfs_writeSB(&sb);
// Initialize the inodes
- for (uint32_t i = 0; i < sb.n_inodes; i++) ATA_clear28(iface, 2 + i);
+ for (uint32_t i = 0; i < sb.n_inodes; i++) ata_clear28(interface, 2 + i);
// Initialize the chunks
- for (uint32_t i = 0; i < sb.n_chunks; i++) ATA_clear28(iface, sb.s_first_chunk + i * 512);
+ for (uint32_t i = 0; i < sb.n_chunks; i++) ata_clear28(interface, sb.s_first_chunk + i * 512);
}
diff --git a/src/kernel/fs/marfs/marfs.h b/src/kernel/fs/marfs/marfs.h
index ba6f0b3..f197e5b 100644
--- a/src/kernel/fs/marfs/marfs.h
+++ b/src/kernel/fs/marfs/marfs.h
@@ -3,7 +3,7 @@
#include <stdint.h>
-struct marfs_SUPERBLOCK {
+struct marfs_superblock {
uint64_t signature;
uint32_t n_inodes;
uint32_t n_chunks;
@@ -12,7 +12,7 @@ struct marfs_SUPERBLOCK {
uint32_t s_first_chunk;
} __attribute__((packed));
-struct marfs_INODE {
+struct marfs_inode {
uint64_t size;
uint32_t creation_time;
uint32_t last_mod_time;
@@ -24,41 +24,35 @@ struct marfs_INODE {
uint32_t ext_3;
uint32_t ext_4;
uint32_t uid;
- uint8_t isApp;
- uint8_t isDir;
- uint8_t isUsed;
+ uint8_t is_app;
+ uint8_t is_dir;
+ uint8_t is_used;
} __attribute__((packed));
-enum marfs_RESERVED_INODES {
- marfs_INODE_JBOOT2,
- marfs_INODE_KERNEL,
- marfs_INODE_ROOT
-};
-
-struct ATA_INTERFACE *iface;
-struct marfs_SUPERBLOCK sb_cache;
-uint32_t maxLBA;
+struct ata_interface *interface;
+struct marfs_superblock sb_cache;
+uint32_t max_lba;
// marfs_sectorlevel.c
-uint8_t marfs_init(struct ATA_INTERFACE *iface);
+uint8_t marfs_init(struct ata_interface *interface);
uint32_t marfs_get_max_lba(void);
uint8_t marfs_write_mbr(uint8_t *mbr);
-struct marfs_SUPERBLOCK *marfs_read_superblock();
+struct marfs_superblock *marfs_read_superblock();
-uint8_t marfs_writeSB(struct marfs_SUPERBLOCK *sb);
+uint8_t marfs_writeSB(struct marfs_superblock *sb);
uint32_t marfs_get_free_lba_block(void);
-uint8_t marfs_mark_block_as_used(uint32_t LBAsector);
+uint8_t marfs_mark_block_as_used(uint32_t lba_sector);
-uint8_t marfs_mark_block_as_free(uint32_t LBAsector);
+uint8_t marfs_mark_block_as_free(uint32_t lba_sector);
uint32_t marfs_get_free_lba_inode(void);
-void marfs_mark_inode_as_free(uint32_t LBAsector);
+void marfs_mark_inode_as_free(uint32_t lba_sector);
// marfs_disklevel.c
void marfs_format(void);
@@ -69,13 +63,13 @@ uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec
// marfs_dir.c
uint32_t marfs_new_dir(uint32_t uid);
-void marfs_add_to_dir(uint32_t LBAinode, char *filename, uint32_t lba);
+void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba);
// marfs_read_whole_file.c
-uint32_t marfs_get_block(struct marfs_INODE *inode, uint32_t i);
+uint32_t marfs_get_block(struct marfs_inode *inode, uint32_t i);
-void marfs_read_whole_file(uint32_t LBAinode, uint8_t *buffer);
+void marfs_read_whole_file(uint32_t lba_inode, uint8_t *buffer);
-uint8_t *marfs_allocate_and_read_whole_file(uint32_t LBAinode);
+uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode);
#endif
diff --git a/src/kernel/fs/marfs/new_file.c b/src/kernel/fs/marfs/new_file.c
index ebc8152..4503ed1 100644
--- a/src/kernel/fs/marfs/new_file.c
+++ b/src/kernel/fs/marfs/new_file.c
@@ -3,16 +3,17 @@
#include <mlibc/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
-static uint8_t last_maxlevel = 0;
+static uint8_t last_max_level = 0;
-void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t recLBA, uint32_t realLBA) {
- if (level > last_maxlevel) last_maxlevel = level;
- uint32_t *contents = (uint32_t *) ATA_read28(iface, recLBA);
+void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t rec_lba, uint32_t real_lba)
+{
+ if (level > last_max_level) last_max_level = level;
+ uint32_t *contents = (uint32_t *) ata_read28(interface, rec_lba);
uint32_t idx = i - 10;
- if (last_maxlevel > 1) idx -= 1 << 7;
- if (last_maxlevel > 2) idx -= 1 << (7 * 2);
- if (last_maxlevel > 3) idx -= 1 << (7 * 3);
+ if (last_max_level > 1) idx -= 1 << 7;
+ if (last_max_level > 2) idx -= 1 << (7 * 2);
+ if (last_max_level > 3) idx -= 1 << (7 * 3);
idx >>= 7 * (level - 1);
if (level > 1) {
@@ -21,82 +22,83 @@ void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t recLBA, uint32_t
marfs_mark_block_as_used(contents[idx]);
}
} else {
- contents[idx] = realLBA;
+ contents[idx] = real_lba;
}
- ATA_write28(iface, recLBA, (uint8_t *) contents);
+ ata_write28(interface, rec_lba, (uint8_t *) contents);
uint32_t contents_idx = contents[idx];
kfree(contents);
if (level != 1) {
- marfs_update_recursive(level - 1, i, contents_idx, realLBA);
+ marfs_update_recursive(level - 1, i, contents_idx, real_lba);
}
- last_maxlevel = 0;
+ last_max_level = 0;
}
-uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec, uint8_t dir) {
- struct marfs_INODE *inode = (struct marfs_INODE *) kcalloc(1, 512);
+uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec, uint8_t dir)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) kcalloc(1, 512);
inode->size = size;
inode->creation_time = inode->last_mod_time = inode->last_access_time = 0; // TODO: POSIX time
inode->n_blocks = size / 512;
if (size % 512) inode->n_blocks++;
inode->uid = uid;
- inode->isApp = exec;
- inode->isDir = dir;
- inode->isUsed = 1;
+ inode->is_app = exec;
+ inode->is_dir = dir;
+ inode->is_used = 1;
uint32_t size_in_blocks = inode->n_blocks;
- uint32_t LBA_singly, LBA_doubly, LBA_triply, LBA_quadruply;
- LBA_singly = LBA_doubly = LBA_triply = LBA_quadruply = 0;
+ uint32_t lba_singly, lba_doubly, lba_triply, lba_quadruply;
+ lba_singly = lba_doubly = lba_triply = lba_quadruply = 0;
for (uint32_t i = 0; i < size_in_blocks; i++) {
- uint32_t thisblock = marfs_get_free_lba_block();
+ uint32_t this_block = marfs_get_free_lba_block();
if (i != size_in_blocks - 1) {
- ATA_write28(iface, thisblock, data);
+ ata_write28(interface, this_block, data);
} else if (size % 512) {
uint8_t contents[512] = {0};
for (uint16_t i = 0; i < size % 512; i++) contents[i] = data[i];
- ATA_write28(iface, thisblock, contents);
+ ata_write28(interface, this_block, contents);
}
data += 512;
- marfs_mark_block_as_used(thisblock);
+ marfs_mark_block_as_used(this_block);
if (i > 9 + (128 * 128 * 128)) {
- if (!LBA_quadruply) {
- LBA_quadruply = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_quadruply);
- inode->ext_4 = LBA_quadruply;
+ if (!lba_quadruply) {
+ lba_quadruply = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_quadruply);
+ inode->ext_4 = lba_quadruply;
}
- marfs_update_recursive(4, i, LBA_quadruply, thisblock);
+ marfs_update_recursive(4, i, lba_quadruply, this_block);
} else if (i > 9 + (128 * 128)) {
- if (!LBA_triply) {
- LBA_triply = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_triply);
- inode->ext_3 = LBA_triply;
+ if (!lba_triply) {
+ lba_triply = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_triply);
+ inode->ext_3 = lba_triply;
}
- marfs_update_recursive(3, i, LBA_triply, thisblock);
+ marfs_update_recursive(3, i, lba_triply, this_block);
} else if (i > 9 + 128) {
- if (!LBA_doubly) {
- LBA_doubly = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_doubly);
- inode->ext_2 = LBA_doubly;
+ if (!lba_doubly) {
+ lba_doubly = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_doubly);
+ inode->ext_2 = lba_doubly;
}
- marfs_update_recursive(2, i, LBA_doubly, thisblock);
+ marfs_update_recursive(2, i, lba_doubly, this_block);
} else if (i > 9) {
- if (!LBA_singly) {
- LBA_singly = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_singly);
- inode->ext_1 = LBA_singly;
+ if (!lba_singly) {
+ lba_singly = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_singly);
+ inode->ext_1 = lba_singly;
}
- marfs_update_recursive(1, i, LBA_singly, thisblock);
+ marfs_update_recursive(1, i, lba_singly, this_block);
} else {
- inode->DBPs[i] = thisblock;
+ inode->DBPs[i] = this_block;
}
}
// Write the inode
- uint32_t inode_LBA = marfs_get_free_lba_inode();
- ATA_write28(iface, inode_LBA, (uint8_t *) inode);
+ uint32_t inode_lba = marfs_get_free_lba_inode();
+ ata_write28(interface, inode_lba, (uint8_t *) inode);
- return inode_LBA;
+ return inode_lba;
} \ No newline at end of file
diff --git a/src/kernel/fs/marfs/read_whole_file.c b/src/kernel/fs/marfs/read_whole_file.c
index 0d3af26..324cd9b 100644
--- a/src/kernel/fs/marfs/read_whole_file.c
+++ b/src/kernel/fs/marfs/read_whole_file.c
@@ -3,28 +3,30 @@
#include <mlibc/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
-static uint8_t last_maxlevel = 0;
+static uint8_t last_max_level = 0;
-uint32_t marfs_get_recursive(uint8_t level, uint32_t i, uint32_t recLBA) {
- if (level > last_maxlevel) last_maxlevel = level;
- uint32_t *contents = (uint32_t *) ATA_read28(iface, recLBA);
+uint32_t marfs_get_recursive(uint8_t level, uint32_t i, uint32_t rec_lba)
+{
+ if (level > last_max_level) last_max_level = level;
+ uint32_t *contents = (uint32_t *) ata_read28(interface, rec_lba);
uint32_t idx = i - 10;
- if (last_maxlevel > 1) idx -= 1 << 7;
- if (last_maxlevel > 2) idx -= 1 << (7 * 2);
- if (last_maxlevel > 3) idx -= 1 << (7 * 3);
+ if (last_max_level > 1) idx -= 1 << 7;
+ if (last_max_level > 2) idx -= 1 << (7 * 2);
+ if (last_max_level > 3) idx -= 1 << (7 * 3);
idx >>= 7 * (level - 1);
- uint32_t next_recLBA = contents[idx];
+ uint32_t next_rec_lba = contents[idx];
kfree(contents);
uint32_t toRet;
- if (level > 1) toRet = marfs_get_recursive(level - 1, i, next_recLBA);
- else toRet = next_recLBA;
- last_maxlevel = 0;
+ if (level > 1) toRet = marfs_get_recursive(level - 1, i, next_rec_lba);
+ else toRet = next_rec_lba;
+ last_max_level = 0;
return toRet;
}
-uint32_t marfs_get_block(struct marfs_INODE *inode, uint32_t i) {
+uint32_t marfs_get_block(struct marfs_inode *inode, uint32_t i)
+{
if (i > 9 + (128 * 128 * 128)) {
return marfs_get_recursive(4, i, inode->ext_4);
} else if (i > 9 + (128 * 128)) {
@@ -38,13 +40,14 @@ uint32_t marfs_get_block(struct marfs_INODE *inode, uint32_t i) {
}
}
-void marfs_read_whole_file(uint32_t LBAinode, uint8_t *buffer) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, LBAinode);
+void marfs_read_whole_file(uint32_t lba_inode, uint8_t *buffer)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_inode);
uint32_t size_in_blocks = inode->n_blocks;
for (uint32_t i = 0; i < size_in_blocks; i++) {
uint32_t this_block = marfs_get_block(inode, i);
- uint8_t *this_block_contents = ATA_read28(iface, this_block);
+ uint8_t *this_block_contents = ata_read28(interface, this_block);
uint16_t upper_bound = (i != size_in_blocks - 1) ? 512 : (inode->size % 512);
for (uint16_t j = 0; j < upper_bound; j++) buffer[(i * 512) + j] = this_block_contents[j];
kfree(this_block_contents);
@@ -54,12 +57,13 @@ void marfs_read_whole_file(uint32_t LBAinode, uint8_t *buffer) {
}
// TODO: Beautify
-uint8_t *marfs_allocate_and_read_whole_file(uint32_t LBAinode) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, LBAinode);
+uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_inode);
uint64_t size = inode->size;
kfree(inode);
uint8_t *buffer = kmalloc(size);
- marfs_read_whole_file(LBAinode, buffer);
+ marfs_read_whole_file(lba_inode, buffer);
return buffer;
}
diff --git a/src/kernel/fs/marfs/sectorlevel.c b/src/kernel/fs/marfs/sectorlevel.c
index d8795fa..d9fa2c4 100644
--- a/src/kernel/fs/marfs/sectorlevel.c
+++ b/src/kernel/fs/marfs/sectorlevel.c
@@ -3,36 +3,44 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/fs/marfs/marfs.h>
-uint8_t marfs_init(struct ATA_INTERFACE *_iface) {
- iface = _iface;
- uint16_t identifydata[256 * 2];
- uint8_t ret = ATA_identify(iface, identifydata);
- maxLBA = (identifydata[61] << 16) + identifydata[60];
+uint8_t marfs_init(struct ata_interface *_interface)
+{
+ interface = _interface;
+ uint16_t identify_data[256 * 2];
+ uint8_t ret = ata_identify(interface, identify_data);
+ max_lba = (identify_data[61] << 16) + identify_data[60];
return ret;
}
-uint32_t marfs_get_max_lba(void) { return maxLBA; }
+uint32_t marfs_get_max_lba(void)
+{
+ return max_lba;
+}
-uint8_t marfs_write_mbr(uint8_t *mbr) {
- return ATA_write28(iface, 0, mbr);
+uint8_t marfs_write_mbr(uint8_t *mbr)
+{
+ return ata_write28(interface, 0, mbr);
}
-struct marfs_SUPERBLOCK *marfs_read_superblock() {
- struct marfs_SUPERBLOCK *p = (struct marfs_SUPERBLOCK *) ATA_read28(iface, 1);
+struct marfs_superblock *marfs_read_superblock()
+{
+ struct marfs_superblock *p = (struct marfs_superblock *) ata_read28(interface, 1);
sb_cache = *p;
return p;
}
-uint8_t marfs_writeSB(struct marfs_SUPERBLOCK *sb) {
+uint8_t marfs_writeSB(struct marfs_superblock *sb)
+{
sb_cache = *sb;
- return ATA_write28(iface, 1, (uint8_t *) sb);
+ return ata_write28(interface, 1, (uint8_t *) sb);
}
-uint32_t marfs_get_free_lba_block(void) {
+uint32_t marfs_get_free_lba_block(void)
+{
uint32_t offset = 2 + sb_cache.s_first_chunk;
uint8_t *p = 0;
for (uint32_t i = 0; i < sb_cache.n_chunks; i++) {
- p = ATA_read28(iface, offset);
+ p = ata_read28(interface, offset);
if (!(*p & 0x80)) break;
kfree(p);
offset += 512;
@@ -45,19 +53,20 @@ uint32_t marfs_get_free_lba_block(void) {
}
kfree(p);
- ATA_clear28(iface, offset);
+ ata_clear28(interface, offset);
return offset;
}
-static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode) {
+static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode)
+{
lba_sector -= 2;
lba_sector -= sb_cache.s_first_chunk;
uint16_t block_in_chunk = lba_sector % 512;
lba_sector /= 512;
lba_sector = 2 + sb_cache.s_first_chunk + (512 * lba_sector);
- uint8_t *p = ATA_read28(iface, lba_sector);
+ uint8_t *p = ata_read28(interface, lba_sector);
p[block_in_chunk] = mode;
if (mode == 0) {
@@ -73,29 +82,37 @@ static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode) {
p[0] = full_chunk;
}
- uint8_t ret = ATA_write28(iface, lba_sector, p);
+ uint8_t ret = ata_write28(interface, lba_sector, p);
kfree(p);
return ret;
}
-uint8_t marfs_mark_block_as_free(uint32_t lba_sector) { return marfs_mark_block(lba_sector, 0); }
+uint8_t marfs_mark_block_as_free(uint32_t lba_sector)
+{
+ return marfs_mark_block(lba_sector, 0);
+}
-uint8_t marfs_mark_block_as_used(uint32_t lba_sector) { return marfs_mark_block(lba_sector, 1); }
+uint8_t marfs_mark_block_as_used(uint32_t lba_sector)
+{
+ return marfs_mark_block(lba_sector, 1);
+}
-uint32_t marfs_get_free_lba_inode(void) {
+uint32_t marfs_get_free_lba_inode(void)
+{
uint32_t offset;
for (offset = 2; offset < 2 + sb_cache.n_inodes; offset++) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, offset);
- uint8_t used = inode->isUsed;
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, offset);
+ uint8_t used = inode->is_used;
kfree(inode);
if (!used) break;
}
return offset;
}
-void marfs_mark_inode_as_free(uint32_t lba_sector) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, lba_sector);
- inode->isUsed = 0;
- ATA_write28(iface, lba_sector, (uint8_t *) inode);
+void marfs_mark_inode_as_free(uint32_t lba_sector)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_sector);
+ inode->is_used = 0;
+ ata_write28(interface, lba_sector, (uint8_t *) inode);
kfree(inode);
} \ No newline at end of file
diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c
index 5591a60..702851e 100644
--- a/src/kernel/fs/vfs.c
+++ b/src/kernel/fs/vfs.c
@@ -2,31 +2,36 @@
fs_node_t *fs_root = 0;
-uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
+uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer)
+{
if (node->read != 0)
return node->read(node, offset, size, buffer);
else
return 0;
}
-uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
+uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer)
+{
if (node->write != 0)
return node->write(node, offset, size, buffer);
else
return 0;
}
-void open_fs(fs_node_t *node, uint8_t read, uint8_t write) {
+void open_fs(fs_node_t *node, uint8_t read, uint8_t write)
+{
if (node->open != 0)
return node->open(node);
}
-void close_fs(fs_node_t *node) {
+void close_fs(fs_node_t *node)
+{
if (node->close != 0)
return node->close(node);
}
-struct dirent *readdir_fs(fs_node_t *node, uint32_t index) {
+struct dirent *readdir_fs(fs_node_t *node, uint32_t index)
+{
if ((node->flags & 0x7) == FS_DIRECTORY &&
node->readdir != 0)
return node->readdir(node, index);
@@ -34,7 +39,8 @@ struct dirent *readdir_fs(fs_node_t *node, uint32_t index) {
return 0;
}
-fs_node_t *finddir_fs(fs_node_t *node, char *name) {
+fs_node_t *finddir_fs(fs_node_t *node, char *name)
+{
if ((node->flags & 0x7) == FS_DIRECTORY &&
node->finddir != 0)
return node->finddir(node, name);