block: read GPT header from block devices on init

This commit is contained in:
Michael Shaw 2023-05-13 23:04:15 -04:00
commit 05c528f64c
6 changed files with 138 additions and 8 deletions

View file

@ -3,6 +3,7 @@
#define _BLOCK_H_
#include <kernel/common.h>
#include <kernel/gpt.h>
struct block_device;
@ -16,9 +17,16 @@ struct block_device {
struct block_device_ops ops;
void *data;
size_t size;
size_t block_count;
size_t block_size;
struct gpt_header *gpt_header;
struct gpt_entry *gpt_entries;
size_t gpt_entries_count;
};
struct block_device *block_register(char *name, struct block_device_ops *ops, void *data);
struct block_device *block_register(char *name, struct block_device_ops *ops, void *data, size_t block_count, size_t block_size);
int block_read(struct block_device *bdev, void *buf, size_t offset, size_t size);
int block_write(struct block_device *bdev, void *buf, size_t offset, size_t size);

52
include/kernel/gpt.h Normal file
View file

@ -0,0 +1,52 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _GPT_H_
#define _GPT_H_
#include <kernel/common.h>
struct block_device;
/* GPT LBA 0 */
struct gpt_mbr_prot {
uint8_t boot[1];
uint8_t chs_start[3];
uint8_t type[1];
uint8_t chs_end[3];
uint8_t lba_start[4];
uint8_t lba_size[4];
} PACKED;
/* GPT LBA 1
* checksums use CRC32
*/
struct gpt_header {
uint64_t signature;
uint8_t revision[4];
uint8_t header_size[4];
uint8_t checksum[4];
uint8_t reserved[4];
uint64_t lba_this;
uint64_t lba_alt;
uint64_t lba_first;
uint64_t lba_last;
uint8_t guid[16];
uint64_t lba_table;
uint32_t entry_count;
uint32_t entry_size;
uint32_t checksum_table;
} PACKED;
/* GPT LBA 2 */
struct gpt_entry {
uint8_t guid[16];
uint8_t guid_parent[16];
uint64_t lba_first;
uint64_t lba_last;
uint8_t attr[8];
char name[72];
} PACKED;
void block_gpt_init(struct block_device *dev);
#endif /* _GPT_H_ */