Return parent directory to new file in RAMFS
This commit is contained in:
parent
02b5c8890a
commit
3b42ce5386
|
|
@ -21,13 +21,16 @@ bits 16
|
||||||
;Load part2 |x|
|
;Load part2 |x|
|
||||||
;Get video mode information |0|
|
;Get video mode information |0|
|
||||||
;Set video mode |0|
|
;Set video mode |0|
|
||||||
;get memory map |0|
|
;get memory map |x|
|
||||||
;enable paging |0|
|
;enable paging |x|
|
||||||
;read filesystem |0|
|
;read filesystem |x|
|
||||||
;load kernel |0|
|
;load kernel |x|
|
||||||
;parse ELF format |0|
|
;parse ELF format |x|
|
||||||
;pass memory and video information to kernel|0|
|
;pass memory and video information to kernel|x|
|
||||||
;relocate and jump to kernel |0|
|
;relocate and jump to kernel |x|
|
||||||
|
|
||||||
|
;TODO 7/4/26
|
||||||
|
;Remember to ZERO THE BSS
|
||||||
|
|
||||||
jump:
|
jump:
|
||||||
jmp short start
|
jmp short start
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@
|
||||||
#include "../drivers/serial.h"
|
#include "../drivers/serial.h"
|
||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
|
|
||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
|
||||||
|
#define null 0
|
||||||
|
|
||||||
|
|
||||||
#define MLOG_DEBUG 1
|
#define MLOG_DEBUG 1
|
||||||
#define MLOG_PRINT 2
|
#define MLOG_PRINT 2
|
||||||
#define MLOG_WARN 3
|
#define MLOG_WARN 3
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "../shared/kstdlib.h"
|
#include "../shared/kstdlib.h"
|
||||||
#include "../shared/memory.h"
|
#include "../shared/memory.h"
|
||||||
#include "../shared/string.h"
|
#include "../shared/string.h"
|
||||||
#define MODULE_NAME "KVFS"
|
#define MODULE_NAME "RAMFS"
|
||||||
|
|
||||||
fileops_t ramfs_ops =
|
fileops_t ramfs_ops =
|
||||||
{
|
{
|
||||||
|
|
@ -21,16 +21,22 @@ vfile_t root_dir = {"/", FS_FILE_IS_DIR | FS_FILE_SYSTEM, &ramfs_ops};
|
||||||
void ramfs_init(){
|
void ramfs_init(){
|
||||||
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
|
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
|
||||||
root_dir.private = kmalloc(1);
|
root_dir.private = kmalloc(1);
|
||||||
root_dir.size = PAGE_SIZE_BYTES;//one page is 4096 bytes
|
root_dir.size = PAGE_SIZE_BYTES;
|
||||||
// printf("Sizeof VFILE_T: %d", sizeof(vfile_t));
|
// printf("Sizeof VFILE_T: %d", sizeof(vfile_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
vfile_t *search_dir(char *subname, vfile_t *directory){
|
vfile_t *search_dir(char *subname, vfile_t *directory){
|
||||||
|
vfile_t **children = (vfile_t **)directory->private;
|
||||||
|
for(int i = 0; i < directory->size / sizeof(vfile_t *); i++){
|
||||||
|
if(!strcmp(children[i], subname)){
|
||||||
|
return children[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//resolves the path relative to start
|
//resolves the path relative to start
|
||||||
vfile_t *resolve_path(char *pathname, vfile_t *start){
|
vfile_t *resolve_path(char *pathname, vfile_t *start, uint32_t get_last_child){
|
||||||
const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4;
|
const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4;
|
||||||
|
|
||||||
if(!start){
|
if(!start){
|
||||||
|
|
@ -58,18 +64,36 @@ vfile_t *resolve_path(char *pathname, vfile_t *start){
|
||||||
}
|
}
|
||||||
|
|
||||||
vfile_t **buffer = (vfile_t **)start->private;
|
vfile_t **buffer = (vfile_t **)start->private;
|
||||||
printf("START\n");
|
|
||||||
vfile_t *entry = start;
|
vfile_t *entry = start;
|
||||||
for(int i = 0; i < pathname_entries - 1; i++){
|
for(int i = 0; i < pathname_entries - !get_last_child; i++){
|
||||||
printf("%s", path_tokens[i]);
|
printf("%s", path_tokens[i]);
|
||||||
|
entry = search_dir(path_tokens[i], entry);
|
||||||
|
if(!entry){
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf("END\n");
|
kfree(path);
|
||||||
|
kfree(path_tokens);
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *get_filename(char *path){
|
||||||
|
char *filename = path + strlen(path) - 1;//get last character in pathname
|
||||||
|
while(*filename != '/' || filename == path) filename--;
|
||||||
|
filename += filename != path;//if the new filename is at the beginning of the path, don't adjust for '/' character
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){
|
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){
|
||||||
resolve_path("test/test1/test2", &root_dir);
|
if(!path){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
vfile_t *parent = resolve_path(path, &root_dir, false);
|
||||||
|
if(!parent){
|
||||||
|
mlog(MODULE_NAME, "Could not locate parent directory for %s\n", MLOG_PRINT, path);
|
||||||
|
}
|
||||||
|
get_filename(path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue