Support for filesystem callbacks
This commit is contained in:
parent
c19b4ffc6f
commit
0deac50c2a
|
|
@ -124,6 +124,15 @@ uint32_t module_api(uint32_t func, ...){
|
|||
uint32_t size = va_arg(vars, uint32_t);
|
||||
return_value = (uint32_t)kmalloc_page_paddr((uint32_t)paddr, size);
|
||||
break;
|
||||
case MODULE_ADD_FS_HANDLER:
|
||||
void *handler = va_arg(vars, void (*)(void *, uint32_t, ...));
|
||||
key = va_arg(vars, uint32_t);
|
||||
vfs_add_mount_handler(handler, key);
|
||||
break;
|
||||
case MODULE_DEL_FS_HANDLER:
|
||||
key = va_arg(vars, uint32_t);
|
||||
vfs_del_mount_handler(key);
|
||||
break;
|
||||
|
||||
}
|
||||
va_end(vars);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ enum MODULE_API_FUNCS{
|
|||
MODULE_API_FREE, //free memory allocated by malloc
|
||||
MODULE_API_PMALLOC64K,
|
||||
MODULE_API_KMALLOC_PADDR,
|
||||
MODULE_ADD_FS_HANDLER,
|
||||
MODULE_DEL_FS_HANDLER,
|
||||
};
|
||||
|
||||
typedef struct module{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,33 @@
|
|||
#define MODULE_NAME "KVFS"
|
||||
vfile_t root_dir = {"/", VFILE_DIRECTORY};
|
||||
|
||||
struct mount_handler{
|
||||
int (*callback)(vfile_t *device, MOUNT_OPERATION op, ...);
|
||||
uint32_t key;
|
||||
}mount_handlers[32];
|
||||
|
||||
|
||||
|
||||
void vfs_add_mount_handler(int (*mount_handler)(vfile_t *device, MOUNT_OPERATION op, ...), uint32_t key){
|
||||
if(mount_handler == 0){
|
||||
return;
|
||||
}
|
||||
for(uint32_t i = 0; i < 32; i++){
|
||||
if(mount_handlers[i].callback == 0){
|
||||
mount_handlers[i].callback = mount_handler;
|
||||
mount_handlers[i].key = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
void vfs_del_mount_handler(uint32_t key){
|
||||
for(uint32_t i = 0; i < 32; i++){
|
||||
if(mount_handlers[i].key == key){
|
||||
mount_handlers[i].callback = 0;
|
||||
mount_handlers[i].key = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vfs_init(){
|
||||
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
|
||||
root_dir.access.data.ptr = kmalloc(1);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ typedef enum vfile_type{
|
|||
VFILE_PIPE //yay we have pipes
|
||||
}VFILE_TYPE;
|
||||
|
||||
typedef enum mount_ops{
|
||||
MOUNT_NEW,
|
||||
MOUNT_UNMOUNT,
|
||||
}MOUNT_OPERATION;
|
||||
|
||||
|
||||
//this code is gonna be ***really*** unsafe
|
||||
typedef struct virtual_file{
|
||||
char name[20];
|
||||
|
|
@ -55,4 +61,6 @@ void fdelete();
|
|||
int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
|
||||
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);
|
||||
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);
|
||||
|
|
@ -192,8 +192,8 @@ int ata_write(vfile_t *file, void *ptr, uint32_t offset, uint32_t count){
|
|||
if (count == 0) return -1;
|
||||
|
||||
drive_t drive = drives[file->mount_id];
|
||||
uint16_t io_base = drive.BARs[0] >> 2;
|
||||
uint16_t ctrl_base = drive.BARs[1] >> 2;
|
||||
uint16_t io_base = drive.BARs[0] &0xfffe;
|
||||
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
||||
uint16_t bm_base = drive.BARs[4] & ~3;
|
||||
|
||||
|
||||
|
|
@ -279,8 +279,8 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
|||
if (count == 0) return -1;
|
||||
|
||||
drive_t drive = drives[file->mount_id];
|
||||
uint16_t io_base = drive.BARs[0] >> 2;
|
||||
uint16_t ctrl_base = drive.BARs[1] >> 2;
|
||||
uint16_t io_base = drive.BARs[0] &0xfffe;
|
||||
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
||||
uint16_t bm_base = drive.BARs[4] & ~3;
|
||||
|
||||
|
||||
|
|
@ -388,8 +388,8 @@ cpu_registers_t *int_handler(cpu_registers_t * regs){
|
|||
//dma set 0x80 for udma
|
||||
//
|
||||
void ata_set_dma(uint32_t index, uint8_t dma_mode){
|
||||
uint16_t bar0 = drives[index].BARs[0] >> 2;
|
||||
uint16_t bar1 = drives[index].BARs[1] >> 2;
|
||||
uint16_t bar0 = drives[index].BARs[0] &0xfffe;
|
||||
uint16_t bar1 = drives[index].BARs[1] &0xfffe;
|
||||
|
||||
while(!ata_ready(bar0, bar1, drives[index].flags.slave << 4));
|
||||
|
||||
|
|
@ -414,8 +414,8 @@ void ata_set_dma(uint32_t index, uint8_t dma_mode){
|
|||
//return 2 if is SATA
|
||||
//return 3 if is SATAPI
|
||||
uint8_t ata_identify(uint32_t index, uint16_t disk){
|
||||
uint16_t bar0 = drives[index].BARs[0] >> 2;
|
||||
uint16_t bar1 = drives[index].BARs[1] >> 2;
|
||||
uint16_t bar0 = drives[index].BARs[0] &0xfffe;
|
||||
uint16_t bar1 = drives[index].BARs[1] &0xfffe;
|
||||
if(!ata_ready(bar0, bar1, disk & 0x10)){
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -556,12 +556,12 @@ void init(KOS_MAPI_FP module_api, uint32_t api_version){
|
|||
fread(api, current_file, BARs, 0x10, 5);
|
||||
if(PCI_IDE_NATIVE(~progif)){
|
||||
native_ide_present = 1;
|
||||
BARs[0] = (ATA_PRIMARY_BUS) << 2 | 1;
|
||||
BARs[1] = (ATA_PRIMARY_BUS + 0x206) << 2 | 1;
|
||||
BARs[0] = (ATA_PRIMARY_BUS) | 1;
|
||||
BARs[1] = (ATA_PRIMARY_BUS + 0x206) | 1;
|
||||
}
|
||||
if(PCI_IDE_SECONDARY_NATIVE(~progif)){
|
||||
BARs[2] = (ATA_SECONDARY_BUS << 2) | 1;
|
||||
BARs[3] = (ATA_SECONDARY_BUS + 0x206) << 2 | 1;
|
||||
BARs[2] = (ATA_SECONDARY_BUS) | 1;
|
||||
BARs[3] = (ATA_SECONDARY_BUS + 0x206) | 1;
|
||||
}
|
||||
ide_init(BARs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
KOS_MAPI_FP api;
|
||||
|
||||
void mount_fat32(vfile_t *dev_file, char *destination){
|
||||
// void mount_fat32(vfile_t *dev_file, char *destination){
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
void detect_partitions(vfile_t *file){
|
||||
char *buffer = malloc(api, 1);
|
||||
|
|
@ -18,8 +18,6 @@ void detect_partitions(vfile_t *file){
|
|||
api(MODULE_API_PRINT, MODULE_NAME, "Magic: %x\n", mbr->magic);
|
||||
return;
|
||||
}
|
||||
//first: check for filesystem headers (if they exist, register entire drive as fs and return)
|
||||
//then, check partitions.
|
||||
for(int i = 0; i < 4; i++){
|
||||
partition_t part = mbr->partitions[i];
|
||||
if(part.type == 0xee){
|
||||
|
|
@ -29,6 +27,7 @@ void detect_partitions(vfile_t *file){
|
|||
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
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ enum MODULE_API_FUNCS{
|
|||
MODULE_API_FREE, //free memory allocated by malloc
|
||||
MODULE_API_PMALLOC64K,
|
||||
MODULE_API_KMALLOC_PADDR,
|
||||
MODULE_ADD_FS_HANDLER,
|
||||
MODULE_DEL_FS_HANDLER,
|
||||
};
|
||||
|
||||
typedef uint32_t (*KOS_MAPI_FP)(unsigned int function, ...);
|
||||
|
|
@ -41,6 +43,11 @@ typedef struct cpu_registers{
|
|||
uint32_t eip, cs, eflags, useresp, ss;
|
||||
}__attribute__((packed))cpu_registers_t;
|
||||
|
||||
typedef enum mount_ops{
|
||||
MOUNT_NEW,
|
||||
MOUNT_UNMOUNT,
|
||||
}MOUNT_OPERATION;
|
||||
|
||||
typedef enum vfile_type{
|
||||
VFILE_POINTER,
|
||||
VFILE_DEVICE,
|
||||
|
|
|
|||
Loading…
Reference in New Issue