slab: replace struct slab with slab_t
This type should never be modified by the user, and only passed into the functions in slab.c. Using a typedef to notifies the user semantically of this fact
This commit is contained in:
parent
0395b65ad8
commit
29a0435cf6
13 changed files with 196 additions and 46 deletions
10
fs/block.c
10
fs/block.c
|
|
@ -40,7 +40,17 @@ inline int block_read(struct block_device *bdev, void *buf, size_t offset, size_
|
|||
return bdev->ops.read(bdev, buf, offset, size);
|
||||
}
|
||||
|
||||
inline int block_readp(struct block_part *part, void *buf, size_t offset, size_t size)
|
||||
{
|
||||
return part->bdev->ops.read(part->bdev, buf, part->lba_start + offset, size);
|
||||
}
|
||||
|
||||
inline int block_write(struct block_device *bdev, void *buf, size_t offset, size_t size)
|
||||
{
|
||||
return bdev->ops.write(bdev, buf, offset, size);
|
||||
}
|
||||
|
||||
inline int block_writep(struct block_part *part, void *buf, size_t offset, size_t size)
|
||||
{
|
||||
return part->bdev->ops.write(part->bdev, buf, part->lba_start + offset, size);
|
||||
}
|
||||
|
|
|
|||
54
fs/fat32.c
54
fs/fat32.c
|
|
@ -1,3 +1,57 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/block.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <fs/fat32.h>
|
||||
|
||||
struct fat32_fs *fat_init_part(struct block_part *part)
|
||||
{
|
||||
struct fat32_fs *ret = kmalloc(sizeof(struct fat32_fs), ALLOC_KERN);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->part = part;
|
||||
ret->dev = part->bdev;
|
||||
|
||||
char *buf = kmalloc(2048, ALLOC_KERN);
|
||||
if (!buf)
|
||||
goto free_ret;
|
||||
|
||||
if (block_readp(part, &ret->bpb, 0, 1)) {
|
||||
kprintf(LOG_ERROR "Failed to read block\n");
|
||||
goto free_buf;
|
||||
}
|
||||
|
||||
if (ret->bpb.signature != FAT32_SIGNATURE) {
|
||||
kprintf(LOG_ERROR "Invalid FAT32 signature: %x\n", ret->bpb.signature);
|
||||
goto free_buf;
|
||||
}
|
||||
|
||||
if (ret->bpb.bytes_per_sector != 512) {
|
||||
kprintf(LOG_ERROR "Invalid FAT32 bytes per sector: %d\n", ret->bpb.bytes_per_sector);
|
||||
goto free_buf;
|
||||
}
|
||||
|
||||
if (block_readp(part, buf, ret->bpb.fsinfo_sector, 1)) {
|
||||
kprintf(LOG_ERROR "Failed to read fsinfo block\n");
|
||||
goto free_buf;
|
||||
}
|
||||
|
||||
struct fat32_fsinfo *fsinfo = (struct fat32_fsinfo *)(buf);
|
||||
ret->fsinfo = *fsinfo;
|
||||
|
||||
if (block_readp(part, buf + 512, ret->bpb.root_cluster, 1)) {
|
||||
goto free_buf;
|
||||
}
|
||||
|
||||
memcpy(&ret->root, buf + 512, sizeof(struct fat32_dirent));
|
||||
|
||||
kfree(buf);
|
||||
return ret;
|
||||
|
||||
/* error conditions */
|
||||
free_buf:
|
||||
kfree(buf);
|
||||
free_ret:
|
||||
kfree(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
30
fs/gpt.c
30
fs/gpt.c
|
|
@ -3,6 +3,8 @@
|
|||
#include <kernel/gpt.h>
|
||||
#include <kernel/slab.h>
|
||||
|
||||
#include <fs/fat32.h>
|
||||
|
||||
#define GPT_HEADER_SIGNATURE 0x5452415020494645ull /* "EFI PART" */
|
||||
|
||||
void block_gpt_init(struct block_device *dev)
|
||||
|
|
@ -32,26 +34,36 @@ void block_gpt_init(struct block_device *dev)
|
|||
goto free_entries;
|
||||
}
|
||||
|
||||
if (block_read(dev, entries, header->lba_first, 1)) {
|
||||
if (block_read(dev, entries, header->lba_table, 1)) {
|
||||
kprintf(LOG_ERROR "Failed to read GPT entries for device %s\n", dev->name);
|
||||
goto free_entries;
|
||||
}
|
||||
|
||||
dev->gpt_header = header;
|
||||
dev->gpt_entries = entries;
|
||||
dev->gpt_entries_count = header->entry_count;
|
||||
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)
|
||||
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;
|
||||
|
||||
fat_init_part(part);
|
||||
}
|
||||
dev->partition_count = used_count;
|
||||
|
||||
|
||||
#ifdef KDEBUG
|
||||
kprintf(LOG_DEBUG "GPT header for device %s loaded\n", dev->name);
|
||||
#endif
|
||||
return; /* Success */
|
||||
|
||||
free_entries:
|
||||
kfree(entries);
|
||||
free_header:
|
||||
kfree(header);
|
||||
|
||||
dev->gpt_entries = NULL;
|
||||
dev->gpt_header = NULL;
|
||||
dev->gpt_entries_count = 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue