move partiton detection

This commit is contained in:
notsomeidiot123 2025-10-14 13:24:29 -04:00
parent 0deac50c2a
commit 6e9f89379d
5 changed files with 69 additions and 58 deletions

View File

@ -29,7 +29,15 @@ void sysinit(){
}
modules_init();
initrc_read(initrc);
vfile_t *disk_dir = fopen("/dev/disk");
if(disk_dir == 0){
mlog("KERNEL", "Error: /dev/disk does not exist\n", MLOG_PRINT);
}
vfile_t **dir_data = disk_dir->access.data.ptr;
for(uint32_t i = 0; dir_data[i]; i++){
mlog("KERNEL", "Filename: %s\n", MLOG_PRINT, dir_data[i]->name);
vfs_detect_partitions(dir_data[i]);
}
printf("Bleh\n");
for(;;);
}

View File

@ -10,7 +10,39 @@ struct mount_handler{
uint32_t key;
}mount_handlers[32];
void vfs_detect_partitions(vfile_t *file){
char *buffer = kmalloc(1);
fread(file, buffer, 0, 512);
mbr_t *mbr = buffer;
if(mbr->magic != MBR_MAGIC){
mlog(MODULE_NAME, "No MBR!\n", MLOG_PRINT);
mlog(MODULE_NAME, "Magic: %x\n", mbr->magic, MLOG_PRINT);
return;
}
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){
//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);
// fcreate() new file representing partition
return;
}
//now, re-check for filesystems
}
mlog(MODULE_NAME, "Magic: %x\n", MLOG_PRINT, mbr->magic);
return;
}
void vfs_add_mount_handler(int (*mount_handler)(vfile_t *device, MOUNT_OPERATION op, ...), uint32_t key){
if(mount_handler == 0){

View File

@ -55,6 +55,25 @@ typedef struct mount_funcs{
void (*create)(char *filename, FS_FILE_FLAGS flags);
}mount_t;
typedef struct partition{
uint8_t attributes;
uint8_t chs_start[3];
uint8_t type;
uint8_t chs_end[3];
uint32_t lba_start;
uint32_t lba_size;
}__attribute__((packed))partition_t;
#define MBR_MAGIC 0xaa55
typedef struct mbr{
char code[440];
char id[4];
char res[2];
partition_t partitions[4];
uint16_t magic;
}__attribute__((packed)) mbr_t;
void vfs_init();
vfile_t *fcreate(char *name, VFILE_TYPE type, ...);
void fdelete();
@ -63,4 +82,5 @@ int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count
vfile_t *search_dir(char *name, vfile_t dir);
vfile_t *fopen(char *name);
void vfs_del_mount_handler(uint32_t key);
void vfs_add_mount_handler(int (*mount_handler)(vfile_t *device, MOUNT_OPERATION op, ...), uint32_t key);
void vfs_add_mount_handler(int (*mount_handler)(vfile_t *device, MOUNT_OPERATION op, ...), uint32_t key);
void vfs_detect_partitions(vfile_t *file);

View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include "modlib.h"
#include "fs_driver.h"
#include "stdarg.h"
#define MODULE_NAME "KIFSM"
KOS_MAPI_FP api;
@ -9,32 +10,12 @@ KOS_MAPI_FP api;
// }
void detect_partitions(vfile_t *file){
char *buffer = malloc(api, 1);
fread(api, file, buffer, 0, 512);
mbr_t *mbr = buffer;
if(mbr->magic != MBR_MAGIC){
puts(api, MODULE_NAME, "No MBR!\n");
api(MODULE_API_PRINT, MODULE_NAME, "Magic: %x\n", mbr->magic);
return;
int callback(vfile_t *device, MOUNT_OPERATION op, ...){
if(op == MOUNT_NEW){
//call mount functions to try and
}
for(int i = 0; i < 4; i++){
partition_t part = mbr->partitions[i];
if(part.type == 0xee){
puts(api, MODULE_NAME, "Found gpt\n");
return;
}
if(part.attributes != 0 || part.attributes != 0x80){
//check disk for filesystem
api(MODULE_API_PRINT, MODULE_NAME, "No partitions!\n");
return;
}
//now, re-check for filesystems
}
api(MODULE_API_PRINT, MODULE_NAME, "Magic: %x\n", mbr->magic);
return;
}
//buffer is a pointer to a string that contains the filename, followed by a comma, followed by the mount destination. If there is no destination [i.e. no comma], command will be treated as unmount
int mount(vfile_t *file, char *buffer, uint32_t offset, uint32_t count){
char filename_buffer[256];
@ -72,16 +53,5 @@ void init(KOS_MAPI_FP module_api, uint32_t api_version){
api = module_api;
api(MODULE_API_PRINT, MODULE_NAME, "KIFSM Filesystem Driver Module v0.1.0\nSupported Filesystems:\n");
vfile_t *disk_dir = fopen(api, "/dev/disk");
if(disk_dir == 0){
puts(api, MODULE_NAME, "Could not find /dev/disk\n");
}
vfile_t **dir_data = disk_dir->access.data.ptr;
for(uint32_t i = 0; dir_data[i]; i++){
api(MODULE_API_PRINT, MODULE_NAME, "Filename: %s\n", dir_data[i]->name);
detect_partitions(dir_data[i]);
}
fcreate(api, "/dev/fat32mnt", VFILE_DEVICE, mount, phony_read);
// mount(0, "bleh,test", 0, 15);
return;
}

View File

@ -1,21 +1,2 @@
#pragma once
#include <stdint.h>
typedef struct partition{
uint8_t attributes;
uint8_t chs_start[3];
uint8_t type;
uint8_t chs_end[3];
uint32_t lba_start;
uint32_t lba_size;
}__attribute__((packed))partition_t;
#define MBR_MAGIC 0xaa55
typedef struct mbr{
char code[440];
char id[4];
char res[2];
partition_t partitions[4];
uint16_t magic;
}__attribute__((packed)) mbr_t;
#include <stdint.h>