block: replace block_part with independent block devices

this also removes the fat32 support for now, as the virtual filesystem
needs more work
This commit is contained in:
Michael Shaw 2023-05-27 17:32:39 -04:00
commit 21e2540243
6 changed files with 25 additions and 190 deletions

View file

@ -1,9 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/block.h>
#include <kernel/gpt.h>
#include <kernel/slab.h>
#include <fs/fat32.h>
#include <kernel/block.h>
#define GPT_HEADER_SIGNATURE 0x5452415020494645ull /* "EFI PART" */
@ -11,11 +8,11 @@ void block_gpt_init(struct block_device *dev)
{
size_t block_size = dev->block_size;
struct gpt_header *header = kmalloc(block_size, ALLOC_KERN);
struct gpt_header *header = kmalloc(block_size, ALLOC_DMA);
if (!header)
return;
struct gpt_entry *entries = kmalloc(block_size, ALLOC_KERN);
struct gpt_entry *entries = kmalloc(block_size, ALLOC_DMA);
if (!entries)
goto free_header;
@ -39,26 +36,33 @@ void block_gpt_init(struct block_device *dev)
goto free_entries;
}
dev->partitions = kmalloc(sizeof(struct block_part) * header->entry_count, ALLOC_KERN);
size_t used_count = 0;
for(size_t i = 0; i < header->entry_count; i++) {
if (entries[i].type_guid[1] == 0)
for (size_t i = 0; i < header->entry_count; i++) {
if (entries[i].type_guid[1] == 0)
continue;
used_count++;
struct block_part *part = &dev->partitions[i];
part->bdev = dev;
part->lba_start = entries[i].lba_first;
part->num_blocks = entries[i].lba_last - entries[i].lba_first + 1;
struct block_device *bdev = kmalloc(sizeof(struct block_device), ALLOC_KERN);
memcpy(bdev, dev, sizeof(struct block_device));
struct fat32_fs *fs = fat_init_part(part);
fat_print_root(fs);
if (!bdev)
continue;
bdev->name = kmalloc(64, ALLOC_KERN);
if (!bdev->name) {
kfree(bdev);
continue;
}
snprintf(bdev->name, "%sp%d", 63, dev->name, used_count - 1);
bdev->name[63] = '\0';
bdev->lba_start = entries[i].lba_first;
bdev->block_count = entries[i].lba_last - entries[i].lba_first + 1;
}
dev->partition_count = used_count;
#ifdef KDEBUG
kprintf(LOG_DEBUG "GPT header for device %s loaded\n", dev->name);
#endif