Finished system/vfs.c:fcreate(), wrote documentations
This commit is contained in:
parent
21137ee62b
commit
ff9425c321
|
|
@ -0,0 +1,17 @@
|
|||
# How to build this project
|
||||
|
||||
## To build and run in qemu:
|
||||
|
||||
simply run `make` That's it. It'll ask for your password to run `sudo mount image.bin`, to create a few directories (and eventually move in files that will be needed for installation/running). If you don't feel comfortable doing this through make, cause you don't trust the build script or something, you can run
|
||||
|
||||
`make tools && make bootloader && make kernel`
|
||||
|
||||
followed by `cp bin/bootloader.bin image.bin`, `qemu-img resize -f raw image.bin 64M`, and `diskwrite idm.elf ifsm.elf kernel.elf -o image.bin`, which will then allow you to mount image.bin. Then, run `mk {mount}/mod {mount}/bin {mount}/sys` and copy and files that need to be copied into their respective folders (currently there are none other than `idm.elf`, `ifsm.elf`, and `kernel.elf`)
|
||||
|
||||
You MUST run the `diskwrite` tool BEFORE mounting, as it sets up the filesystem for the bootloader, and copies `idm.elf`, `ifsm.elf` and `kernel.elf` in a way that can be read by the bootloader.
|
||||
|
||||
To run, just use the command `qemu-system-i386 -hda image.bin {settings}`, with whatever settings you choose. I recommend using at least 32 megabytes of memory, and if you would like to see the kernel logs as they are writen to serial, with the option `-serial mon:stdio`
|
||||
|
||||
## To build, but NOT run in qemu
|
||||
|
||||
You could always just run `make` and close qemu immediately, or you could run `make mount`. It'll ask for your password again for the above reason, but you can just follow the above steps, minus running qemu if you don't feel comfortable letting the build script handle it. Again, it is imperitive that you run `diskwrite` as specified, or else the bootloader won't be able to find the files (as linux defaults to long file names, and my bootloader does not support them, and the short filenames are in a different style than expected (eg `kernel.elf` becomes `KERNEL ELF`))
|
||||
|
|
@ -31,9 +31,10 @@ extern void kmain(kernel_info_t *kernel_info){
|
|||
pic_disable();
|
||||
pic_setmask(0xfe, PIC1_DATA);
|
||||
vfs_init();
|
||||
|
||||
fcreate("/dev", VFILE_DIRECTORY, kmalloc(1), 1);
|
||||
fcreate("/dev/test", VFILE_POINTER, kmalloc(1), 1);
|
||||
fcreate("/dev/test", VFILE_POINTER, kmalloc(1), 1);
|
||||
fcreate("/tmp", VFILE_DIRECTORY, kmalloc(1), 1);
|
||||
|
||||
mlog("KERNEL", "Initializing Scheduler & starting PID 1\n", MLOG_PRINT);
|
||||
boot_info = kernel_info;
|
||||
scheduler_init();
|
||||
|
|
|
|||
|
|
@ -11,12 +11,43 @@ void vfs_init(){
|
|||
root_dir.access.data.size_pgs = 1;
|
||||
}
|
||||
|
||||
vfile_t **find_free_dirent(vfile_t *current_dir){
|
||||
|
||||
void add_file(vfile_t *vfile, vfile_t *current_dir){
|
||||
vfile_t **dir_data = current_dir->access.data.ptr;
|
||||
int i = 0;
|
||||
while(dir_data[i] && (i * sizeof(vfile_t *))/4096 < current_dir->access.data.size_pgs){
|
||||
i++;
|
||||
}
|
||||
dir_data[i] = vfile;
|
||||
}
|
||||
|
||||
/*
|
||||
Long comment cause this one's a complicated one.
|
||||
Create a file of the specified path in name
|
||||
if the path leads to a mounted filesystem then
|
||||
use the mounted filesystem's specified create() function to create the file.
|
||||
else, create a pointer in the virtual path that points to a file entry for the new file.
|
||||
If this new file is a Directory or Pointer, specify a pointer to be used as a buffer to store data for this file, as well as the size of the buffer, in pages.
|
||||
If this new file is a Mounted filesystem, this pointer must be an array of functions as defined below:
|
||||
int fwrite(vfile_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
//must write count bytes from data to file offset by offset bytes.
|
||||
int fread(vfile_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
//must read count bytes from data to file offset by offset bytes.
|
||||
int fopen(char *filename, vfile_t *file);
|
||||
//must return a vfile_t struct written to the address specified in file, to represent a file named name (from the mount's filename)
|
||||
(eg. /mount/root/test is passed as /root/test)
|
||||
fcreate(char *filename, FS_FILE_FLAGS flags);
|
||||
FS_FILE_FLAGS is in the same format as FAT's file attribute byte of dirents.
|
||||
filenames are truncated, as with the previous example.
|
||||
fdelete(vfile_t *file);
|
||||
//the file specified in the file pointer must be deleted.
|
||||
else, if the file is a virtual representation of a device, of of a file (any miscellaneous file object that does not fit the other types) then
|
||||
specify a pointer to be used as the read function, as defined below:
|
||||
void read(struct virtual_file *file, void *data, uint32_t offset, uint32_t count);
|
||||
specify a pointer to be used as the write function, with the same function prototype as the function above
|
||||
void write(struct virtual_file *file, void *data, uint32_t offset, uint32_t count);
|
||||
*/
|
||||
void fcreate(char *name, VFILE_TYPE type, ...){
|
||||
char *last = strtok(name + (name[0] == '/'), '/');
|
||||
name += name[0]== '/';
|
||||
char *last = strtok(name, '/');
|
||||
char *tmp = last;
|
||||
uint32_t filename_offset = 0;
|
||||
vfile_t *current_dir = &root_dir;
|
||||
|
|
@ -27,26 +58,34 @@ void fcreate(char *name, VFILE_TYPE type, ...){
|
|||
while(tmp != 0){
|
||||
// dir = tmp;
|
||||
tmpfile = search_dir(tmp, *current_dir);
|
||||
// printf("%s\n", name + filename_offset);
|
||||
if(!tmpfile){
|
||||
//create file in folder;
|
||||
vfile_t *vfile = kmalloc(1);
|
||||
vfile->type = type;
|
||||
uint32_t tmpnsize = strlen(tmp);
|
||||
if(tmp[tmpnsize - 1] == '/'){
|
||||
tmp[tmpnsize - 1] = 0;
|
||||
}
|
||||
strcpy(tmp, vfile->name);
|
||||
|
||||
switch(type){
|
||||
case VFILE_POINTER:
|
||||
case VFILE_DIRECTORY:
|
||||
case VFILE_MOUNT:
|
||||
void *ptr = va_arg(args, void*);
|
||||
vfile->access.data.ptr = ptr;
|
||||
vfile->access.data.size_pgs = va_arg(args, uint32_t);
|
||||
strcpy(tmp, vfile->name);
|
||||
vfile_t **dir_data = current_dir->access.data.ptr;
|
||||
int i = 0;
|
||||
while(dir_data[i] && (i * sizeof(vfile_t *))/4096 < current_dir->access.data.size_pgs){
|
||||
i++;
|
||||
}
|
||||
dir_data[i] = vfile;
|
||||
add_file(vfile, current_dir);
|
||||
// printf("Created File: %s\n", vfile->name);
|
||||
return;
|
||||
case VFILE_FILE:
|
||||
case VFILE_DEVICE:
|
||||
void *write = va_arg(args, void *);
|
||||
void *read = va_arg(args, void *);
|
||||
vfile->access.funcs.write = write;
|
||||
vfile->access.funcs.read = read;
|
||||
// strcpy
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -77,8 +116,14 @@ uint32_t fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t
|
|||
|
||||
// search through root directory
|
||||
switch(file_entry->type){
|
||||
case VFILE_POINTER:
|
||||
memcpy(byte_array, file_entry->access.data.ptr + offset, count);
|
||||
break;
|
||||
case VFILE_PDIR:
|
||||
case VFILE_FILE:
|
||||
case VFILE_DEVICE:
|
||||
file_entry->access.funcs.write(file_entry, byte_array, offset, count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
typedef enum vfile_type{
|
||||
VFILE_POINTER,
|
||||
VFILE_DEVICE,
|
||||
VFILE_MOUNT,
|
||||
VFILE_MOUNT,//in the pointer passed to the function, must specify a read, write, open, create, and delete function.
|
||||
VFILE_DIRECTORY,
|
||||
VFILE_PDIR,//used for directories in physical filesystems.
|
||||
VFILE_FILE
|
||||
|
|
@ -29,14 +29,16 @@ typedef struct virtual_file{
|
|||
}vfile_t;
|
||||
|
||||
typedef enum fs_flags{
|
||||
FS_FILE_IS_DIR = 1,
|
||||
FS_FILE_IS_SYSTEM = 2,
|
||||
FS_FILE_IS_HIDDEN = 4,
|
||||
FS_FILE_READ_ONLY = 1,
|
||||
FS_FILE_HIDDEN = 2,
|
||||
FS_FILE_SYSTEM = 4,
|
||||
FS_FILE_IS_DIR = 0x10,
|
||||
FS_FILE_ARCHIVE = 0x20
|
||||
}FS_FILE_FLAGS;
|
||||
|
||||
typedef struct mount_funcs{
|
||||
void (*write)(vfile_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
void (*read)(vfile_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
int (*write)(vfile_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
int (*read)(vfile_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
int (*open)(char *filename, vfile_t *file);
|
||||
void (*delete)(vfile_t *file);
|
||||
void (*create)(char *filename, FS_FILE_FLAGS flags);
|
||||
|
|
|
|||
Loading…
Reference in New Issue