partition table parsing

This commit is contained in:
notsomeidiot123 2025-10-15 13:37:20 -04:00
parent 6e9f89379d
commit 92b0eb9fcf
4 changed files with 38 additions and 11 deletions

View File

@ -19,7 +19,7 @@ all: bootloader tools kernel
# sudo mkdir mount/sys # for system files
# ./diskwrite -v -o image.bin
# ./diskwrite -v -l kernel.elf idm.elf -o image.bin
qemu-system-i386 -hda image.bin -hdc test.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
qemu-system-i386 -hda image.bin -hdb test.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
sudo umount mount
tools:

View File

@ -10,6 +10,26 @@ struct mount_handler{
uint32_t key;
}mount_handlers[32];
int vfs_link_exists(vfile_t *file){
if(get_paddr(file) == 0 || file->type >= VFILE_MOUNT){
return 0;
}
return 1;
}
void vfs_write_part(vfile_t *file, void *data, uint32_t offset, uint32_t count){
if(!vfs_link_exists(file->parent) || count > file->size){
return;
}
fread(file->parent, data, offset + file->id, count);
}
void vfs_read_part(vfile_t *file, void *data, uint32_t offset, uint32_t count){
if(!vfs_link_exists(file->parent) || count > file->size){
return;
}
fwrite(file->parent, data, offset + file->id, count);
}
void vfs_detect_partitions(vfile_t *file){
char *buffer = kmalloc(1);
fread(file, buffer, 0, 512);
@ -19,26 +39,31 @@ void vfs_detect_partitions(vfile_t *file){
mlog(MODULE_NAME, "Magic: %x\n", mbr->magic, MLOG_PRINT);
return;
}
char cat[2] = {'a', 0};
char nfname[512] = {0};
strcpy(file->name, nfname);
strcat(cat, nfname);
char finalfname[512] = {0};
strcpy("/dev/", finalfname);
strcat(nfname, finalfname);
for(int i = 0; i < 4; i++){
partition_t part = mbr->partitions[i];
if(part.type == 0xee){
mlog(MODULE_NAME, "Found gpt\n", MLOG_PRINT);
return;
}
char cat = {'a', 0};
char nfname[512] = {0};
if(part.attributes != 0 || part.attributes != 0x80){
if((part.attributes != 0 && part.attributes != 0x80) ){
//check disk for filesystem
mlog(MODULE_NAME, "No partitions in %s!\n", MLOG_PRINT, file->name);
strcpy(file->name, nfname);
strcat(nfname, cat);
char finalfname[512] = {0};
strcpy("/dev", finalfname);
strcat(nfname, finalfname);
mlog(MODULE_NAME, "No partitions in %s\n", MLOG_PRINT, file->name);
// fcreate() new file representing partition
vfile_t *nfile = fcreate(finalfname, VFILE_DEVICE, vfs_write_part, vfs_read_part);
nfile->id = 0;
nfile->size = file->size;
nfile->parent = file;
return;
}
//now, re-check for filesystems
finalfname[strlen(finalfname)-1]++;
}
mlog(MODULE_NAME, "Magic: %x\n", MLOG_PRINT, mbr->magic);
return;

View File

@ -2,6 +2,7 @@
#include <stdint.h>
typedef enum vfile_type{
VFILE_NULL,
VFILE_POINTER,//virtual files
VFILE_DEVICE,
VFILE_MOUNT,//in the pointer passed to the function, must specify a read, write, open, create, and delete function.

View File

@ -49,6 +49,7 @@ typedef enum mount_ops{
}MOUNT_OPERATION;
typedef enum vfile_type{
VFILE_NULL,
VFILE_POINTER,
VFILE_DEVICE,
VFILE_MOUNT,