From 611e4e1ac21cf585707518576b10b8467d3e759d Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 24 Jul 2020 07:14:52 -0500 Subject: [PATCH] Remove unnecessary files --- stuff/drivers/i386/pci.c | 104 ----------- stuff/drivers/i386/pci.h | 13 -- stuff/drivers/i386/serial.c | 159 ---------------- stuff/drivers/i386/vga.c | 84 --------- stuff/drivers/parallel.h | 6 - stuff/drivers/pci.h | 49 ----- stuff/drivers/ps2.h | 6 - stuff/drivers/serial.h | 8 - stuff/drivers/timer.h | 7 - stuff/drivers/vga.h | 29 --- stuff/drivers/x86_64/vga.c | 85 --------- stuff/fs/devfs.c | 71 ------- stuff/fs/devfs.h | 9 - stuff/fs/initrd.c | 85 --------- stuff/fs/initrd.h | 6 - stuff/vfs.c | 358 ------------------------------------ stuff/vfs.h | 22 --- 17 files changed, 1101 deletions(-) delete mode 100644 stuff/drivers/i386/pci.c delete mode 100644 stuff/drivers/i386/pci.h delete mode 100644 stuff/drivers/i386/serial.c delete mode 100644 stuff/drivers/i386/vga.c delete mode 100644 stuff/drivers/parallel.h delete mode 100644 stuff/drivers/pci.h delete mode 100644 stuff/drivers/ps2.h delete mode 100644 stuff/drivers/serial.h delete mode 100644 stuff/drivers/timer.h delete mode 100644 stuff/drivers/vga.h delete mode 100644 stuff/drivers/x86_64/vga.c delete mode 100644 stuff/fs/devfs.c delete mode 100644 stuff/fs/devfs.h delete mode 100644 stuff/fs/initrd.c delete mode 100644 stuff/fs/initrd.h delete mode 100644 stuff/vfs.c delete mode 100644 stuff/vfs.h diff --git a/stuff/drivers/i386/pci.c b/stuff/drivers/i386/pci.c deleted file mode 100644 index 76484d5..0000000 --- a/stuff/drivers/i386/pci.c +++ /dev/null @@ -1,104 +0,0 @@ -#include "../../cpu/i386/ports.h" -#include "../vga.h" -#include "pci.h" -#include -#include -#include - -pci_dev_common_info** pci_devs; -static uint32_t max_devs; -uint32_t pci_num_devs; - -static uint32_t read_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset) { - uint32_t address; - uint32_t lbus=(uint32_t)bus; - uint32_t ldev=(uint32_t)device; - uint32_t lfunc=(uint32_t)func; - address=(uint32_t)((lbus << 16)|(ldev << 11)|(lfunc<<8)|(offset&0xfc)|((uint32_t)0x80000000)); - port_long_out(PCI_CONFIG_ADDRESS,address); - uint32_t data=port_long_in(PCI_CONFIG_DATA); - return data; -} - -static void write_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset,uint32_t data) { - uint32_t address; - uint32_t lbus=(uint32_t)bus; - uint32_t ldev=(uint32_t)device; - uint32_t lfunc=(uint32_t)func; - address=(uint32_t)((lbus << 16)|(ldev << 11)|(lfunc<<8)|(offset&0xfc)|((uint32_t)0x80000000)); - port_long_out(PCI_CONFIG_ADDRESS,address); - port_long_out(PCI_CONFIG_DATA,data); -} - -pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func) { - uint32_t* info=malloc(sizeof(uint32_t)*5); - info[0]=read_config(bus,device,func,0); - info[1]=read_config(bus,device,func,4); - info[2]=read_config(bus,device,func,8); - info[3]=read_config(bus,device,func,0xC); - pci_dev_common_info* pci_info=(pci_dev_common_info*)info; - pci_info->bus=bus; - pci_info->device=device; - pci_info->func=func; - return pci_info; -} - -void pci_set_dev_info(pci_dev_common_info* inf) { - uint32_t* info=(uint32_t*)inf; - write_config(inf->bus,inf->device,inf->func,0,info[0]); - write_config(inf->bus,inf->device,inf->func,4,info[1]); - write_config(inf->bus,inf->device,inf->func,8,info[2]); - write_config(inf->bus,inf->device,inf->func,0xC,info[3]); -} - -static void checkFunction(pci_dev_common_info* info); - -static void checkDevice(uint8_t bus, uint8_t device) { - pci_dev_common_info* info=pci_get_dev_info(bus,device,0); - if(info->vend_id==0xFFFF||info->class_code==0xFF) { - return; - } - checkFunction(info); - if((info->header_type&0x80)!=0) { - for(uint8_t function=1;function<8;function++) { - pci_dev_common_info* info=pci_get_dev_info(bus,device,function); - if(info->vend_id!=0xFFFF&&info->class_code!=0xFF) { - checkFunction(info); - } - } - } -} - -static void checkFunction(pci_dev_common_info* info) { - if (pci_num_devs==max_devs) { - max_devs+=32; - pci_devs=malloc(sizeof(pci_dev_common_info)*max_devs); - } - pci_devs[pci_num_devs]=info; - pci_num_devs++; - klog("INFO","Found PCI device. Class code:%x, Subclass:%x Prog IF:%x",info->class_code,info->subclass,info->prog_if); - klog("INFO","Vendor ID:%x, Device ID:%x",info->vend_id,info->dev_id); - if ((info->header_type&0x7f)==0) { - for (uint8_t offset=0x10;offset<0x10+4*6;offset+=4) { - uint32_t bar=read_config(info->bus,info->device,info->func,offset); - if (bar!=0) { - if (bar&0x1) { - klog("INFO","IO BAR%d:%x",(offset-0x10)/4,bar&0xFFFFFFFC); - } else { - klog("INFO","MEM BAR%d:%x",(offset-0x10)/4,bar&0xFFFFFFF0); - } - } - } - } -} - -void pci_init() { - pci_devs=malloc(sizeof(pci_dev_common_info)*32); - max_devs=32; - pci_num_devs=0; - for(uint16_t bus=0;bus<1; bus++) { - for(uint8_t device=0;device<32; device++) { - checkDevice(bus, device); - } - } -} diff --git a/stuff/drivers/i386/pci.h b/stuff/drivers/i386/pci.h deleted file mode 100644 index 71d66c0..0000000 --- a/stuff/drivers/i386/pci.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PCI_INTERN_H -#define PCI_INTERN_H - -#include "../pci.h" -#include - -#define PCI_CONFIG_ADDRESS 0xCF8 -#define PCI_CONFIG_DATA 0xCFC - -pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func); -void pci_set_dev_info(pci_dev_common_info* inf); - -#endif diff --git a/stuff/drivers/i386/serial.c b/stuff/drivers/i386/serial.c deleted file mode 100644 index 20eda82..0000000 --- a/stuff/drivers/i386/serial.c +++ /dev/null @@ -1,159 +0,0 @@ -#include "../../cpu/i386/isr.h" -#include "../../cpu/i386/ports.h" -#include "../../fs/devfs.h" -#include "../serial.h" -#include "../vga.h" -#include -#include -#include -#include -#include - -#define SERIAL_LINE_ENABLE_DLAB 0x80 - -static devbuf* bufs[4]; - -static int data_port(int com) { - switch (com) { - case 0: return 0x3f8; - case 1: return 0x2f8; - case 2: return 0x3e8; - case 3: return 0x2e8; - } - return 0; -} - -static int int_port(int com) { - switch (com) { - case 0: return 0x3f9; - case 1: return 0x2f9; - case 2: return 0x3e9; - case 3: return 0x2e9; - } - return 0; -} - - -static int fifo_port(int com) { - switch (com) { - case 0: return 0x3fa; - case 1: return 0x2fa; - case 2: return 0x3ea; - case 3: return 0x2ea; - } - return 0; -} -static int line_cmd_port(int com) { - switch (com) { - case 0: return 0x3fb; - case 1: return 0x2fb; - case 2: return 0x3eb; - case 3: return 0x2eb; - } - return 0; -} -static int modem_port(int com) { - switch (com) { - case 0: return 0x3fc; - case 1: return 0x2fc; - case 2: return 0x3ec; - case 3: return 0x2ec; - } - return 0; -} -static int line_stat_port(int com) { - switch (com) { - case 0: return 0x3fd; - case 1: return 0x2fd; - case 2: return 0x3ed; - case 3: return 0x2ed; - } - return 0; -} -static int scratch_port(int com) { - switch (com) { - case 0: return 0x3ff; - case 1: return 0x2ff; - case 2: return 0x3ef; - case 3: return 0x2ef; - } - return 0; -} - -static void configure_baud_rate(uint32_t divisor,int com) { - port_byte_out(line_cmd_port(com),SERIAL_LINE_ENABLE_DLAB); - port_byte_out(data_port(com),(divisor>>8)&0xFF); - port_byte_out(data_port(com),divisor&0xFF); -} - -static int is_transmit_fifo_empty(int com) { - return port_byte_in(line_stat_port(com))&0x20; -} - -static void configure(uint32_t com, uint32_t rate) { - configure_baud_rate(115200/rate,com); - port_byte_out(line_cmd_port(com),0x03); - port_byte_out(fifo_port(com),0xC7); - port_byte_out(modem_port(com),0x03); - port_byte_out(int_port(com),0x01); -} - -static int drv(char* filename,int c,long pos,char wr) { - int com; - switch (filename[4]) { - case '0': - com=0; - break; - case '1': - com=1; - break; - case '2': - com=2; - break; - case '3': - com=3; - break; - } - if (wr) { - while (!is_transmit_fifo_empty(com)) continue; - port_byte_out(data_port(com),c); - return 0; - } else { - return devbuf_get(bufs[com]); - } -} - -void serial_int_handler_1(registers_t regs) { - char data=port_byte_in(data_port(0)); - if (data=='\r') { - data='\n'; - } - devbuf_add(data,bufs[0]); -} - -void serial_int_handler_2(registers_t regs) { - devbuf_add(port_byte_in(data_port(1)),bufs[1]); -} - - -void serial_init() { - klog("INFO","Scanning for serial ports"); - for (int i=0;i<2;i++) { - port_byte_out(scratch_port(i),0xaa); - if (port_byte_in(scratch_port(i))==0xaa) { - klog("INFO","Found COM%d",i+1); - bufs[i]=devbuf_init(); - switch (i) { - case 0: - isr_register_handler(IRQ4,serial_int_handler_1); - configure(0,9600); - devfs_add(drv,"ttyS0"); - break; - case 1: - isr_register_handler(IRQ3,serial_int_handler_2); - configure(1,9600); - devfs_add(drv,"ttyS1"); - } - } - } -} diff --git a/stuff/drivers/i386/vga.c b/stuff/drivers/i386/vga.c deleted file mode 100644 index f059ce4..0000000 --- a/stuff/drivers/i386/vga.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "../../cpu/i386/ports.h" -#include "../vga.h" -#include -#include -#include -#define xy_to_indx(x,y) ((x+(y*width))*2) -static char* screen; -static int width; -static int height; -static int x; -static int y; -static vga_colors fg_color; -static vga_colors bg_color; - -static void set_char(int x,int y,char c) { - screen[xy_to_indx(x,y)]=c; - screen[xy_to_indx(x,y)+1]=(bg_color<<4)|fg_color; -} - -void vga_clear() { - for (int y=0;y>8); -} - -void vga_init(text_fb_info framebuffer_info) { - x=0; - y=0; - fg_color=VGA_WHITE; - bg_color=VGA_BLACK; - screen=framebuffer_info.address; - width=framebuffer_info.width; - height=framebuffer_info.height; - port_byte_out(0x3D4,0xA); - port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xC0)|14); - port_byte_out(0x3D4,0xB); - port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xE0)|15); - set_cursor(0,0); - vga_clear(); -} - -void vga_write_string(const char* string) { - for (size_t i=0;i - -typedef struct { - uint16_t vend_id; - uint16_t dev_id; - uint16_t command; - uint16_t status; - uint8_t rev_id; - uint8_t prog_if; - uint8_t subclass; - uint8_t class_code; - uint8_t cache_line_size; - uint8_t lat_timer; - uint8_t header_type; - uint8_t bist; - uint16_t bus; - uint8_t device; - uint8_t func; -} __attribute__((packed)) pci_dev_common_info; - -typedef enum { - PCI_CLASS_UNCLASSIFIED=0x0, - PCI_CLASS_STORAGE=0x1, - PCI_CLASS_NETWORK=0x2, - PCI_CLASS_DISPLAY=0x3, - PCI_CLASS_MULTIMEDIA=0x4, - PCI_CLASS_MEMORY=0x5, - PCI_CLASS_BRIDGE=0x6, - PCI_CLASS_SIMPCOM=0x7, - PCI_CLASS_BASEPERIPH=0x8, - PCI_CLASS_INPDEV=0x9, - PCI_CLASS_DOCK=0xa, - PCI_CLASS_CPU=0xb, - PCI_CLASS_SERBUS=0xc, - PCI_CLASS_WIRELESS=0xd, - PCI_CLASS_INTELLIGENT=0xe, - PCI_CLASS_SATELLITE=0xf, - PCI_CLASS_ENCRYPTION=0x10, - PCI_CLASS_SIGPROCESS=0x11, -} pci_class; - -extern pci_dev_common_info** pci_devs; -extern uint32_t pci_num_devs; -void pci_init(); - -#endif diff --git a/stuff/drivers/ps2.h b/stuff/drivers/ps2.h deleted file mode 100644 index e98c5c2..0000000 --- a/stuff/drivers/ps2.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PS2_EXT_H -#define PS2_EXT_H - -void ps2_init(); - -#endif diff --git a/stuff/drivers/serial.h b/stuff/drivers/serial.h deleted file mode 100644 index 717df8a..0000000 --- a/stuff/drivers/serial.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef SERIAL_H -#define SERIAL_H - -#include - -void serial_init(); - -#endif diff --git a/stuff/drivers/timer.h b/stuff/drivers/timer.h deleted file mode 100644 index 6967145..0000000 --- a/stuff/drivers/timer.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -void wait(int milli); -void timer_init(); - -#endif diff --git a/stuff/drivers/vga.h b/stuff/drivers/vga.h deleted file mode 100644 index f51462b..0000000 --- a/stuff/drivers/vga.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef vga_H -#define vga_H - -typedef enum { - VGA_BLACK=0, - VGA_BLUE=1, - VGA_GREEN=2, - VGA_CYAN=3, - VGA_RED=4, - VGA_PURPLE=5, - VGA_BROWN=6, - VGA_GRAY=7, - VGA_DARK_GRAY=8, - VGA_LIGHT_BLUE=9, - VGA_LIGHT_GREEN=10, - VGA_LIGHT_CYAN=11, - VGA_LIGHT_RED=12, - VGA_LIGHT_PURPLE=13, - VGA_YELLOW=14, - VGA_WHITE=15 -} vga_colors; - - -void vga_init(); -void vga_write_string(const char *string); -void vga_clear(); -void vga_backspace(); - -#endif diff --git a/stuff/drivers/x86_64/vga.c b/stuff/drivers/x86_64/vga.c deleted file mode 100644 index 3745777..0000000 --- a/stuff/drivers/x86_64/vga.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "../../cpu/x86_64/ports.h" -#include "../vga.h" -#include -#include -#include - -#define xy_to_indx(x,y) ((x+(y*width))*2) -static char* screen; -static int width; -static int height; -static int x; -static int y; -static vga_colors fg_color; -static vga_colors bg_color; - -static void set_char(int x,int y,char c) { - screen[xy_to_indx(x,y)]=c; - screen[xy_to_indx(x,y)+1]=(bg_color<<4)|fg_color; -} - -void vga_clear() { - for (int y=0;y>8); -} - -void vga_init(text_fb_info framebuffer_info) { - x=0; - y=0; - fg_color=VGA_WHITE; - bg_color=VGA_BLACK; - screen=framebuffer_info.address; - width=framebuffer_info.width; - height=framebuffer_info.height; - port_byte_out(0x3D4,0xA); - port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xC0)|14); - port_byte_out(0x3D4,0xB); - port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xE0)|15); - set_cursor(0,0); - vga_clear(); -} - -void vga_write_string(const char* string) { - for (size_t i=0;i -#include -#include - -static char** devices; -static dev_drv* dev_drivers; -static size_t num_devices; -static size_t max_devices; - -char devfs_drv(fs_op op,FILE* stream,void* data1,void* data2) { - if (op==FSOP_MOUNT) { - return 1; - } - if (op==FSOP_OPEN) { - for (size_t i=0;ipath)==0) { - return 1; - } - } - return 0; - } - if (op==FSOP_GETC) { - size_t i; - for (i=0;ipath)==0) { - break; - } - } - *((int*)data1)=dev_drivers[i]((char*)stream->path,0,stream->pos,0); - stream->pos+=1; - return 1; - } - if (op==FSOP_PUTC) { - size_t i; - for (i=0;ipath)==0) { - break; - } - } - dev_drivers[i]((char*)stream->path,*((int*)data1),stream->pos,1); - stream->pos+=1; - return 1; - } - if (op==FSOP_CLOSE) { - return 1; - } - return 0; -} - -void init_devfs() { - devices=malloc(sizeof(char*)*32); - dev_drivers=malloc(sizeof(dev_drv)*32); - num_devices=0; - max_devices=32; - register_fs(devfs_drv,"devfs"); - mount("/dev/","","devfs"); -} - -void devfs_add(dev_drv drv,char* name) { - if (num_devices==max_devices) { - devices=realloc(devices,sizeof(char*)*(max_devices+32)); - dev_drivers=realloc(dev_drivers,sizeof(dev_drv)*(max_devices+32)); - max_devices+=32; - } - dev_drivers[num_devices]=drv; - devices[num_devices]=malloc(sizeof(char)*(strlen(name)+1)); - strcpy(devices[num_devices],name); - num_devices++; -} diff --git a/stuff/fs/devfs.h b/stuff/fs/devfs.h deleted file mode 100644 index 9027a8e..0000000 --- a/stuff/fs/devfs.h +++ /dev/null @@ -1,9 +0,0 @@ -#define DEVFS_H -#ifndef DEVFS_H - -typedef int (*dev_drv)(char* filename,int c,long pos,char wr); - -void init_devfs(); -void devfs_add(dev_drv drv,char* name); - -#endif diff --git a/stuff/fs/initrd.c b/stuff/fs/initrd.c deleted file mode 100644 index 6132e22..0000000 --- a/stuff/fs/initrd.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "../..//vfs.h" -#include -#include -#include -#include - -static char** names; -static long* offsets; -static unsigned long* sizes; -static size_t num_files; -static FILE* initrd_fd; - -static char drv(fs_op op,FILE* stream,void* data1,void* data2) { - if (op==FSOP_MOUNT) { - return 1; - } - if (op==FSOP_OPEN) { - char file_exists=0; - for (size_t i=0;ipath)==0) { - file_exists=1; - } - } - return file_exists; - } - if (op==FSOP_GETC) { - size_t i; - for (i=0;ipath)==0) { - break; - } - } - if (stream->pos>=sizes[i]) { - *((int*)data1)=EOF; - stream->eof=1; - return 1; - } - fseek(initrd_fd,offsets[i]+stream->pos,SEEK_SET); - *((int*)data1)=fgetc(initrd_fd); - stream->pos+=1; - return 1; - } - if (op==FSOP_CLOSE) { - return 1; - } - return 0; -} - -void initrd_init() { - initrd_fd=fopen("/dev/initrd","r"); - if (!initrd_fd) { - klog("PANIC","Cannot open initrd!"); - for(;;) {} - } - size_t max_files=32; - num_files=0; - names=malloc(sizeof(char*)*32); - offsets=malloc(sizeof(long)*32); - sizes=malloc(sizeof(long)*32); - for (size_t i=0;i<1;i++) { - if (i==max_files) { - names=realloc(names,sizeof(char*)*(max_files+32)); - offsets=realloc(offsets,sizeof(long)*(max_files+32)); - sizes=realloc(sizes,sizeof(long)*(max_files+32)); - max_files+=32; - } - uint32_t name_size; - fread(&name_size,4,1,initrd_fd); - if (name_size==0) { - break; - } - char* name=malloc(sizeof(char)*(name_size+1)); - fread(name,1,name_size+1,initrd_fd); - long contents_size; - fread(&contents_size,4,1,initrd_fd); - long datapos=ftell(initrd_fd); - fseek(initrd_fd,contents_size,SEEK_CUR); - names[i]=name; - offsets[i]=datapos; - sizes[i]=contents_size; - num_files++; - } - fseek(initrd_fd,0,SEEK_SET); - register_fs(drv,"initrd"); -} diff --git a/stuff/fs/initrd.h b/stuff/fs/initrd.h deleted file mode 100644 index 6637845..0000000 --- a/stuff/fs/initrd.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef INITRD_H -#define INITRD_H - -uint32_t initrd_init(); - -#endif diff --git a/stuff/vfs.c b/stuff/vfs.c deleted file mode 100644 index dd83c8f..0000000 --- a/stuff/vfs.c +++ /dev/null @@ -1,358 +0,0 @@ -#include "vfs.h" -#include -#include -#include -#include -#include -#include - -typedef struct _vfs_mapping_struct { - char* mntpnt; - size_t type; - struct _vfs_mapping_struct* next; -} vfs_mapping; - -static const char** drv_names; -static fs_drv* drvs; -static size_t max_drvs; -static size_t next_drv_indx; -static vfs_mapping* head_mapping; -static vfs_mapping* tail_mapping; - -FILE* stdin=NULL; -FILE* stdout=NULL; -FILE* stderr=NULL; - - -static int vfsstrcmp(const char* s1,const char* s2) { - int i; - for (i = 0; s1[i] == s2[i]; i++) { - if (s1[i] == '\0') return 0; - } - if (s1[i] == '\0') return 0; - return s1[i] - s2[i]; -} - -void init_vfs() { - drvs=malloc(sizeof(fs_drv)*32); - drv_names=malloc(sizeof(const char**)*32); - max_drvs=32; - next_drv_indx=0; - head_mapping=NULL; - tail_mapping=NULL; -} - -size_t register_fs(fs_drv drv,const char* type) { - if (next_drv_indx==max_drvs) { - drvs=realloc(drvs,sizeof(fs_drv)*(max_drvs+32)); - drv_names=realloc(drv_names,sizeof(char*)*(max_drvs+32)); - max_drvs+=32; - } - drvs[next_drv_indx]=drv; - drv_names[next_drv_indx]=type; - next_drv_indx++; - return next_drv_indx-1; -} - -char mount(char* mntpnt,char* dev,char* type) { - size_t i; - for (i=0;imntpnt=malloc(sizeof(char)*(strlen(mntpnt)+1)); - strcpy(mapping->mntpnt,mntpnt); - mapping->type=i; - mapping->next=NULL; - head_mapping=mapping; - tail_mapping=mapping; - } else { - vfs_mapping* mapping=malloc(sizeof(vfs_mapping)); - mapping->mntpnt=malloc(sizeof(char)*(strlen(mntpnt)+1)); - strcpy(mapping->mntpnt,mntpnt); - mapping->type=i; - mapping->next=NULL; - tail_mapping->next=mapping; - } - return 1; - } else { - return 0; - } -} - -FILE* fopen(const char* filename,const char* mode) { - vfs_mapping* mnt=head_mapping; - vfs_mapping* mntpnt=NULL; - const char* path; - size_t mntpnt_len=0; - for (;mnt!=NULL;mnt=mnt->next) { - char* root=mnt->mntpnt; - if (strlen(root)>mntpnt_len) { - if (vfsstrcmp(root,filename)==0) { - mntpnt=mnt; - mntpnt_len=strlen(root); - } - } - } - if (mntpnt) { - path=filename+mntpnt_len; - FILE* stream=malloc(sizeof(FILE)); - stream->mntpnt=mntpnt->mntpnt; - stream->path=path; - if (strcmp(mode,"w")==0) { - stream->wr=1; - stream->rd=0; - } else if (strcmp(mode,"r+")==0) { - stream->wr=1; - stream->rd=1; - } else { - stream->wr=0; - stream->rd=1; - } - stream->type=mntpnt->type; - stream->pos=0; - stream->eof=0; - stream->error=0; - char ok=drvs[mntpnt->type](FSOP_OPEN,stream,NULL,NULL); - if (ok) { - return stream; - } else { - free(stream); - return NULL; - } - } - return NULL; -} - -int fgetc(FILE* stream) { - if (!stream->rd) { - errno=EBADF; - stream->error=1; - return EOF; - } - int c; - drvs[stream->type](FSOP_GETC,stream,&c,NULL); - return c; -} - -int getc() { - return fgetc(stdin); -} - -char* fgets(char* str,int count,FILE* stream) { - if (!stream->rd) { - errno=EBADF; - stream->error=1; - return NULL; - } - int i; - for (i=0;ird) { - errno=EBADF; - stream->error=1; - return 0; - } - char* buffer=(char*)buffer_ptr; - size_t bytes=size*count; - for (size_t i=0;iwr) { - errno=EBADF; - stream->error=1; - return EOF; - } - char ok=drvs[stream->type](FSOP_PUTC,stream,&c,NULL); - if (ok) { - return c; - } else { - return EOF; - } -} - -int putc(int c) { - return fputc(c,stdout); -} - -int fputs(const char* s,FILE* stream) { - if (!stream->wr) { - errno=EBADF; - stream->error=1; - return EOF; - } - size_t len=strlen(s); - for (size_t i=0;iwr) { - errno=EBADF; - stream->error=1; - return 0; - } - char* buffer=(char*)buffer_ptr; - size_t bytes=size*count; - for (size_t i=0;ipos=offset; - } - if (origin==SEEK_CUR) { - stream->pos+=offset; - } - return 0; -} - -long ftell(FILE* stream) { - return stream->pos; -} - -int fclose(FILE* stream) { - drvs[stream->type](FSOP_CLOSE,stream,NULL,NULL); - free(stream); - return 0; -} - -int feof(FILE *stream) { - return stream->eof; -} - -int ferror(FILE *stream) { - return stream->error; -} diff --git a/stuff/vfs.h b/stuff/vfs.h deleted file mode 100644 index 1375e15..0000000 --- a/stuff/vfs.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef VFS_H -#define VFS_H - -#include -#include - -typedef enum { - FSOP_MOUNT, - FSOP_OPEN, - FSOP_GETC, - FSOP_PUTC, - FSOP_CLOSE, - FSOP_UMOUNT -} fs_op; - -typedef char (*fs_drv)(fs_op op,FILE* stream,void* data1,void* data2); - -void init_vfs(); -uint32_t register_fs(fs_drv drv,const char* type); -char mount(char* mntpnt,char* dev,char* type); - -#endif