partition table parsing
This commit is contained in:
parent
6e9f89379d
commit
92b0eb9fcf
2
makefile
2
makefile
|
|
@ -19,7 +19,7 @@ all: bootloader tools kernel
|
||||||
# sudo mkdir mount/sys # for system files
|
# sudo mkdir mount/sys # for system files
|
||||||
# ./diskwrite -v -o image.bin
|
# ./diskwrite -v -o image.bin
|
||||||
# ./diskwrite -v -l kernel.elf idm.elf -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
|
sudo umount mount
|
||||||
|
|
||||||
tools:
|
tools:
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,26 @@ struct mount_handler{
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
}mount_handlers[32];
|
}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){
|
void vfs_detect_partitions(vfile_t *file){
|
||||||
char *buffer = kmalloc(1);
|
char *buffer = kmalloc(1);
|
||||||
fread(file, buffer, 0, 512);
|
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);
|
mlog(MODULE_NAME, "Magic: %x\n", mbr->magic, MLOG_PRINT);
|
||||||
return;
|
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++){
|
for(int i = 0; i < 4; i++){
|
||||||
partition_t part = mbr->partitions[i];
|
partition_t part = mbr->partitions[i];
|
||||||
if(part.type == 0xee){
|
if(part.type == 0xee){
|
||||||
mlog(MODULE_NAME, "Found gpt\n", MLOG_PRINT);
|
mlog(MODULE_NAME, "Found gpt\n", MLOG_PRINT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char cat = {'a', 0};
|
if((part.attributes != 0 && part.attributes != 0x80) ){
|
||||||
char nfname[512] = {0};
|
|
||||||
if(part.attributes != 0 || part.attributes != 0x80){
|
|
||||||
//check disk for filesystem
|
//check disk for filesystem
|
||||||
mlog(MODULE_NAME, "No partitions in %s!\n", MLOG_PRINT, file->name);
|
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
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
//now, re-check for filesystems
|
|
||||||
|
finalfname[strlen(finalfname)-1]++;
|
||||||
}
|
}
|
||||||
mlog(MODULE_NAME, "Magic: %x\n", MLOG_PRINT, mbr->magic);
|
mlog(MODULE_NAME, "Magic: %x\n", MLOG_PRINT, mbr->magic);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef enum vfile_type{
|
typedef enum vfile_type{
|
||||||
|
VFILE_NULL,
|
||||||
VFILE_POINTER,//virtual files
|
VFILE_POINTER,//virtual files
|
||||||
VFILE_DEVICE,
|
VFILE_DEVICE,
|
||||||
VFILE_MOUNT,//in the pointer passed to the function, must specify a read, write, open, create, and delete function.
|
VFILE_MOUNT,//in the pointer passed to the function, must specify a read, write, open, create, and delete function.
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ typedef enum mount_ops{
|
||||||
}MOUNT_OPERATION;
|
}MOUNT_OPERATION;
|
||||||
|
|
||||||
typedef enum vfile_type{
|
typedef enum vfile_type{
|
||||||
|
VFILE_NULL,
|
||||||
VFILE_POINTER,
|
VFILE_POINTER,
|
||||||
VFILE_DEVICE,
|
VFILE_DEVICE,
|
||||||
VFILE_MOUNT,
|
VFILE_MOUNT,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue