diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2024-06-06 15:05:45 +0200 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2024-06-06 15:08:36 +0200 |
commit | ddb15c409290ac5473ee36d5dc621a92f161cdfb (patch) | |
tree | c618b4aefd2f552a98521b645b986622d688022b /src/fs | |
parent | d6d6d34e944e7a2a6d345e71750cfa35f94445f5 (diff) |
basic gpt support
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/gpt.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/fs/gpt.c b/src/fs/gpt.c new file mode 100644 index 0000000..f9ff055 --- /dev/null +++ b/src/fs/gpt.c @@ -0,0 +1,71 @@ +#include <fs/gpt.h> +#include <ahci.h> +#include <mem.h> +#include <memory.h> +#include <vga.h> + +struct gpt_header *read_gpt_disk(struct disk *disk) { + uint16_t *gpt = kmalloc(512); + if (!read(disk->port, 1, 1, gpt)) + return NULL; + struct gpt_header *part = (void*) gpt; + if (memcmp(part->sig, "EFI PART", 8) != 0) { + vga_puts("not gpt"); + return NULL; + } + vga_puts("found gpt table on disk 0\n"); + + vga_puts("number of partitions: "); + vga_putn(part->number_partitions); + vga_putc('\n'); + + vga_puts("starting lba: "); + vga_putn(part->first_lba); + vga_putc('\n'); + + vga_puts("size per entry: "); + vga_putn(part->size_partitions); + vga_putc('\n'); + + return part; +} + +struct gpt_entry *get_gpt_entry(struct disk *disk, struct gpt_header *header, size_t num) { + if (num >= header->number_partitions) + return NULL; + uint16_t *data = kmalloc(512); + if (!read(disk->port, header->first_lba + num, 1, data)) + return NULL; + struct gpt_entry *entry = (void *) data; + + /* + vga_puts("unique guid for first partition: "); + vga_putx(entry->guid); + vga_putc('\n'); + */ + + vga_puts("starting partition lba: "); + vga_putn(entry->lba.start); + vga_putc('\n'); + + vga_puts("ending partition lba: "); + vga_putn(entry->lba.end); + vga_putc('\n'); + + return entry; +} + +char *read_gpt_entry(struct disk *disk, struct gpt_entry *entry) { + uint16_t *data = kmalloc(512 * (entry->lba.end - entry->lba.start)); + uint16_t *ptr = data; + for (size_t lba = entry->lba.start; lba < entry->lba.end; lba += 1024) { + if (!read(disk->port, lba, entry->lba.end - lba < 1024 ? entry->lba.end - lba : 1024, ptr)) { + vga_puts("failed to read disk"); + kfree(data); + return NULL; + } + ptr += 1024 * 256; + } + + return (char *)data; +} |