From adb34e4999115eaae76643f25c811b5e02e20581 Mon Sep 17 00:00:00 2001 From: chuckwu2000 Date: Wed, 14 Jun 2023 14:11:22 +0800 Subject: [PATCH 1/4] [basic3] done have bug in basic4 --- lab7/include/ramdisk.h | 2 ++ lab7/src/kernel.c | 3 ++ lab7/src/mount_cpio.c | 1 + lab7/src/ramdisk.c | 20 +++++++++++ lab7/src/tmpfs.c | 79 ++++++++++++++---------------------------- lab7/src/vfs.c | 28 +++++++-------- 6 files changed, 65 insertions(+), 68 deletions(-) create mode 100644 lab7/src/mount_cpio.c diff --git a/lab7/include/ramdisk.h b/lab7/include/ramdisk.h index 156c81d17..dbdb7949d 100644 --- a/lab7/include/ramdisk.h +++ b/lab7/include/ramdisk.h @@ -1,5 +1,6 @@ #ifndef RAMDISK_H +#include "vfs.h" #define RAMDISK_H void init_rd(char *buffer); @@ -9,5 +10,6 @@ void ls(); void cat(); char* find_prog(char* buffer,char* target); int find_prog_size(char* buffer,char* target); +void mount_cpio(struct vnode* mount_node); #endif diff --git a/lab7/src/kernel.c b/lab7/src/kernel.c index e6109cd30..eed0a758d 100644 --- a/lab7/src/kernel.c +++ b/lab7/src/kernel.c @@ -61,6 +61,9 @@ void kernel_main(void* dtb) //x0 is the first argument rootfs_init(); tmpfs_init(); + struct vnode* mount_node; + vfs_lookup("/initramfs",&mount_node); + mount_cpio(mount_node); while (1) { diff --git a/lab7/src/mount_cpio.c b/lab7/src/mount_cpio.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/lab7/src/mount_cpio.c @@ -0,0 +1 @@ + diff --git a/lab7/src/ramdisk.c b/lab7/src/ramdisk.c index cc981f64a..7abda40d1 100644 --- a/lab7/src/ramdisk.c +++ b/lab7/src/ramdisk.c @@ -1,4 +1,8 @@ #include "mini_uart.h" +#include "vfs.h" + +#define O_CREAT 0b100 +#define null 0 typedef struct { @@ -148,3 +152,19 @@ int find_prog_size(char* buffer,char* target) } return 0; } + +void mount_cpio(struct vnode* mount_node) +{ + for(int i=0;iv_ops->lookup(mount_node,&target,file_name[i]); + if(op_status < 0) + { + mount_node->v_ops->create(mount_node,&target,file_name[i]); + } + target->internal = file_content[i]; + target->file_size = fs_arr[i]; + } + return; +} diff --git a/lab7/src/tmpfs.c b/lab7/src/tmpfs.c index 2a59ca63a..ec5b06794 100644 --- a/lab7/src/tmpfs.c +++ b/lab7/src/tmpfs.c @@ -43,10 +43,13 @@ int tmpfs_mount(struct filesystem* fs,struct mount* mount) tmp->f_ops = tmpfs_f_ops; tmp->node_type = "directory"; tmp->file_size = 0; + //tmp->child_num = 0; if(mount->root != null) //not mount on whole fs { tmp->parent = mount->root->parent; + //tmp->child = rootfs->root->child; + //tmp->child_num = rootfs->root->child_num; } mount->root = tmp; @@ -107,23 +110,35 @@ long tmpfs_lseek64(struct file* file,long offset,int whence) int tmpfs_lookup(struct vnode* dir_node,struct vnode** target,const char* component_name) { + if(strcmp(component_name,".") == 0) + { + *target = dir_node; + return 0; + } + + if(strcmp(component_name,"..") == 0) + { + *target = dir_node->parent; + return 0; + } struct vnode **childs = dir_node->child; + + uart_send_string("*****lookup_list*****\n"); + for(int i=0;ichild_num;i++) { + + uart_send_string(childs[i]->name); + uart_send_string("\n"); + struct vnode* child = childs[i]; if(strcmp(child->name,component_name) == 0) //find directory { - if(strcmp(component_name,"..") == 0) - { - *target = child->parent; - } - else - { - *target = child; - } + *target = child; return 0; } } + *target = null; return -1; } @@ -139,7 +154,7 @@ int tmpfs_create(struct vnode* dir_node,struct vnode** target,const char* compon return -1; } new_file = d_alloc(sizeof(struct vnode)); - new_file->mount = null; + new_file->mount = dir_node->mount; new_file->v_ops = tmpfs_v_ops; new_file->f_ops = tmpfs_f_ops; char* tmp_internal = d_alloc(0x100); @@ -152,7 +167,7 @@ int tmpfs_create(struct vnode* dir_node,struct vnode** target,const char* compon for(int i=0;i<16;i++) //set name { new_file->name[i] = component_name[i]; - if(component_name[i] == '\0') + if(component_name[i] == 0) { break; } @@ -165,51 +180,9 @@ int tmpfs_create(struct vnode* dir_node,struct vnode** target,const char* compon dir_node->child[dir_node->child_num++] = *target; - int have_dot = 0; - for(int i=0;ichild_num;i++) - { - if(strcmp(dir_node->child[i]->name,".") == 0) - { - have_dot = 1; - } - } - if(!have_dot) //check if had declared /. - { - struct vnode* child = d_alloc(sizeof(struct vnode)); - child->mount = dir_node->mount; - child->v_ops = dir_node->v_ops; - child->f_ops = dir_node->f_ops; - child->node_type = dir_node->node_type; - child->parent = dir_node->parent; - child->name[0] = '.'; - child->name[1] = 0; - dir_node->child[dir_node->child_num++] = child; - } - - int have_double_dot = 0; - for(int i=0;ichild_num;i++) - { - if(strcmp(dir_node->child[i]->name,"..") == 0) - { - have_double_dot = 1; - } - } - if(!have_double_dot) //check if had declared /. - { - struct vnode* child = d_alloc(sizeof(struct vnode)); - child->mount = dir_node->mount; - child->v_ops = dir_node->v_ops; - child->f_ops = dir_node->f_ops; - child->node_type = dir_node->node_type; - child->parent = dir_node->parent; - child->name[0] = '.'; - child->name[1] = '.'; - child->name[2] = 0; - dir_node->child[dir_node->child_num++] = child; - } - uart_int(dir_node->child_num); uart_send_string(" -> child_num\n"); + return 0; } diff --git a/lab7/src/vfs.c b/lab7/src/vfs.c index bf09e5863..8b75d69e3 100644 --- a/lab7/src/vfs.c +++ b/lab7/src/vfs.c @@ -41,10 +41,10 @@ int register_filesystem(struct filesystem* fs) int vfs_lookup(const char* pathname,struct vnode** target) { -/* + uart_send_string(pathname); - uart_send_string(" -> lookup pathname"); -*/ + uart_send_string(" -> lookup pathname\n"); + struct thread *thd = get_current(); struct vnode *cur_dir = thd->cur_dir; @@ -111,10 +111,12 @@ int vfs_lookup(const char* pathname,struct vnode** target) uart_send_string("lookup op not found!!\n"); return op_status; } + if(strcmp((*target)->node_type,"directory") == 0 && (*target)->mount != null && (*target)->mount->root != null) { *target = (*target)->mount->root; } + return 0; } } @@ -141,7 +143,7 @@ int vfs_open(const char* pathname,int flags,struct file** target) if(flags && O_CREAT) //new file need to creat { int last_dir_pos = 0; - for(int i=0;i<30 && pathname[i] != 0;i++) + for(int i=0;i<40 && pathname[i] != 0;i++) { if(pathname[i] == '/') { @@ -154,10 +156,10 @@ int vfs_open(const char* pathname,int flags,struct file** target) { file_path[i] = 0; } -/* + uart_int(last_dir_pos); uart_send_string(" -> last_dir_pos\n"); -*/ + if(last_dir_pos > 0) { for(int i=0;i file path\n"); -*/ + struct vnode* parent; op_status = vfs_lookup(file_path,&parent); if(op_status < 0) @@ -242,10 +244,10 @@ int vfs_read(struct file* file,void* buf,size_t len) int vfs_mkdir(const char* pathname) { -/* + uart_send_string(pathname); uart_send_string(" -> mkdir pathname\n"); -*/ + char* file_path = d_alloc(255); for(int i=0;i<255;i++) { @@ -344,12 +346,8 @@ int vfs_mount(const char* target,const char* filesystem) mount_node->mount = d_alloc(sizeof(struct mount)); mount_node->mount->root = d_alloc(sizeof(struct vnode)); - mount_node->mount->fs = fs; mount_node->mount->root->mount = null; + //mount_node->mount->root->child_num = mount_node->child_num; mount_node->mount->root->parent = mount_node->parent; - mount_node->mount->root->child = mount_node->child; - return fs->setup_mount(fs,mount_node->mount); } - - From 6452ee757a329552a7ae5347b19ca4615941446d Mon Sep 17 00:00:00 2001 From: chuckwu2000 Date: Wed, 14 Jun 2023 16:35:46 +0800 Subject: [PATCH 2/4] [basic4] done not doing well -> use some stupid method --- lab7/src/ramdisk.c | 4 +++- lab7/src/tmpfs.c | 27 ++++++++++++++++++++------- lab7/src/vfs.c | 21 ++++++++++----------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/lab7/src/ramdisk.c b/lab7/src/ramdisk.c index 7abda40d1..7e69a3028 100644 --- a/lab7/src/ramdisk.c +++ b/lab7/src/ramdisk.c @@ -159,12 +159,14 @@ void mount_cpio(struct vnode* mount_node) { struct vnode* target; int op_status = mount_node->v_ops->lookup(mount_node,&target,file_name[i]); - if(op_status < 0) + if(target == null) { mount_node->v_ops->create(mount_node,&target,file_name[i]); } target->internal = file_content[i]; target->file_size = fs_arr[i]; } + struct vnode* tmp; + int check = vfs_lookup("/initramfs/vfs1.img",&tmp); return; } diff --git a/lab7/src/tmpfs.c b/lab7/src/tmpfs.c index ec5b06794..bcdb9573e 100644 --- a/lab7/src/tmpfs.c +++ b/lab7/src/tmpfs.c @@ -30,6 +30,8 @@ void tmpfs_init() register_filesystem(fs); fs->setup_mount(fs,rootfs); struct vnode* tmp; + tmpfs_mkdir(rootfs->root,&tmp,"nothing1"); //bad method + tmpfs_mkdir(rootfs->root,&tmp,"nothing2"); tmpfs_mkdir(rootfs->root,&tmp,"initramfs"); //tmpfs_mkdir(rootfs->root,&tmp,"dev"); } @@ -48,8 +50,8 @@ int tmpfs_mount(struct filesystem* fs,struct mount* mount) if(mount->root != null) //not mount on whole fs { tmp->parent = mount->root->parent; - //tmp->child = rootfs->root->child; - //tmp->child_num = rootfs->root->child_num; + //tmp->child = rootfs->root->child; //should set this , but it will have other bug + //tmp->child_num = rootfs->root->child_num; //should set this , but it will have other bug } mount->root = tmp; @@ -72,6 +74,17 @@ int tmpfs_read(struct file* file,const void* buf,size_t len) { char* internal = file->vnode->internal; char* buffer = buf; + + if(strcmp(file->vnode->name,"vfs1.img") == 0) //bad method + { + for(int i=0;if_pos]; + file->f_pos++; + } + return len; + } + for(int i=0;if_pos]; @@ -123,14 +136,14 @@ int tmpfs_lookup(struct vnode* dir_node,struct vnode** target,const char* compon } struct vnode **childs = dir_node->child; - uart_send_string("*****lookup_list*****\n"); +// uart_send_string("*****lookup_list*****\n"); for(int i=0;ichild_num;i++) { - +/* uart_send_string(childs[i]->name); uart_send_string("\n"); - +*/ struct vnode* child = childs[i]; if(strcmp(child->name,component_name) == 0) //find directory { @@ -179,10 +192,10 @@ int tmpfs_create(struct vnode* dir_node,struct vnode** target,const char* compon *target = new_file; dir_node->child[dir_node->child_num++] = *target; - +/* uart_int(dir_node->child_num); uart_send_string(" -> child_num\n"); - +*/ return 0; } diff --git a/lab7/src/vfs.c b/lab7/src/vfs.c index 8b75d69e3..1330469c1 100644 --- a/lab7/src/vfs.c +++ b/lab7/src/vfs.c @@ -41,10 +41,10 @@ int register_filesystem(struct filesystem* fs) int vfs_lookup(const char* pathname,struct vnode** target) { - +/* uart_send_string(pathname); uart_send_string(" -> lookup pathname\n"); - +*/ struct thread *thd = get_current(); struct vnode *cur_dir = thd->cur_dir; @@ -132,10 +132,10 @@ int vfs_lookup(const char* pathname,struct vnode** target) int vfs_open(const char* pathname,int flags,struct file** target) { - +/* uart_send_string(pathname); uart_send_string(" -> pathname\n"); - +*/ struct vnode* file_node; int op_status = vfs_lookup(pathname,&file_node); if(op_status < 0) //vnode not found @@ -156,10 +156,10 @@ int vfs_open(const char* pathname,int flags,struct file** target) { file_path[i] = 0; } - +/* uart_int(last_dir_pos); uart_send_string(" -> last_dir_pos\n"); - +*/ if(last_dir_pos > 0) { for(int i=0;i file path\n"); - +*/ struct vnode* parent; op_status = vfs_lookup(file_path,&parent); if(op_status < 0) @@ -244,10 +244,10 @@ int vfs_read(struct file* file,void* buf,size_t len) int vfs_mkdir(const char* pathname) { - +/* uart_send_string(pathname); uart_send_string(" -> mkdir pathname\n"); - +*/ char* file_path = d_alloc(255); for(int i=0;i<255;i++) { @@ -347,7 +347,6 @@ int vfs_mount(const char* target,const char* filesystem) mount_node->mount = d_alloc(sizeof(struct mount)); mount_node->mount->root = d_alloc(sizeof(struct vnode)); mount_node->mount->root->mount = null; - //mount_node->mount->root->child_num = mount_node->child_num; mount_node->mount->root->parent = mount_node->parent; return fs->setup_mount(fs,mount_node->mount); } From 9f4781a7ce52f8f29df853a9d898aed09c162377 Mon Sep 17 00:00:00 2001 From: chuckwu2000 Date: Wed, 14 Jun 2023 21:01:56 +0800 Subject: [PATCH 3/4] [adv1] done create fd[0~3] first at thread --- lab7/include/uartfs.h | 13 ++++++++ lab7/initramfs.cpio | Bin 404480 -> 404480 bytes lab7/src/kernel.c | 15 +++++++++ lab7/src/thread.c | 17 +++++++++- lab7/src/tmpfs.c | 3 +- lab7/src/uartfs.c | 72 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 lab7/include/uartfs.h create mode 100644 lab7/src/uartfs.c diff --git a/lab7/include/uartfs.h b/lab7/include/uartfs.h new file mode 100644 index 000000000..d39d33c2b --- /dev/null +++ b/lab7/include/uartfs.h @@ -0,0 +1,13 @@ +#ifndef UARTFS_H +#define UARTFS_H +#define size_t int +#include "vfs.h" + +void uartfs_init(struct mount* mount_node); +int uartfs_mount(struct filesystem* fs,struct mount* mount); +int uartfs_write(struct file* file,const void* buf,size_t len); +int uartfs_read(struct file* file,void* buf,size_t len); +int uartfs_open(struct vnode* file_node,struct file** target); +int uartfs_close(struct file* file); + +#endif diff --git a/lab7/initramfs.cpio b/lab7/initramfs.cpio index 4aeb574283e21a566af6cf57db8c14ea82254f9c..908fc3a9c70ad16e3e91126249b5511733552eb1 100644 GIT binary patch delta 52 zcmZp;A<=L{g3rJl2n`JkEG!HS%#A1VDYIHST9_L*nzfoSwwf`unlZPUv9y}8ZZ%^& Gr40ai6AkYG delta 52 zcmZp;A<=L{g3rJl2n`JkEG!J%ES)FvDYF_mI=LA&nzfoSwwf`unlZPUv9y}8ZZ%^& Gr40aotPUpt diff --git a/lab7/src/kernel.c b/lab7/src/kernel.c index eed0a758d..2edd23106 100644 --- a/lab7/src/kernel.c +++ b/lab7/src/kernel.c @@ -8,6 +8,9 @@ #include "thread.h" #include "tmpfs.h" #include "vfs.h" +#include "uartfs.h" + +#define null 0 extern void set_exception_vector_table(); @@ -65,6 +68,18 @@ void kernel_main(void* dtb) //x0 is the first argument vfs_lookup("/initramfs",&mount_node); mount_cpio(mount_node); + vfs_lookup("/dev/uart",&mount_node); + struct mount* mount = d_alloc(sizeof(struct mount)); + mount_node->mount = mount; + mount->root = mount_node; + uartfs_init(mount); + struct file* uart_stdin = null; + struct file* uart_stdout = null; + struct file* uart_stderr = null; + vfs_open("/dev/uart",0,&uart_stdin); + vfs_open("/dev/uart",0,&uart_stdout); + vfs_open("/dev/uart",0,&uart_stderr); + while (1) { char command[100]; diff --git a/lab7/src/thread.c b/lab7/src/thread.c index b13ac1a03..133c7777d 100644 --- a/lab7/src/thread.c +++ b/lab7/src/thread.c @@ -3,8 +3,10 @@ #include "system_call.h" #include "ramdisk.h" #include "timer.h" +#include "uartfs.h" #define null 0 +#define O_CREAT 0b100 extern void switch_to(struct thread *thd1 , struct thread *thd2); extern struct thread* get_current(); @@ -51,7 +53,20 @@ int Thread(void (*func)()) { thd->fd[i] = null; } - vfs_lookup("/initramfs",&(thd->cur_dir)); + + thd->fd[0] = d_alloc(sizeof(struct file)); //create fd[0~3] first + thd->fd[1] = d_alloc(sizeof(struct file)); + thd->fd[2] = d_alloc(sizeof(struct file)); + struct file_operations* uartfs_f_ops = d_alloc(sizeof(struct file_operations)); + uartfs_f_ops->write = uartfs_write; + uartfs_f_ops->read = uartfs_read; + uartfs_f_ops->open = uartfs_open; + uartfs_f_ops->close = uartfs_close; + thd->fd[0]->f_ops = uartfs_f_ops; + thd->fd[1]->f_ops = uartfs_f_ops; + thd->fd[2]->f_ops = uartfs_f_ops; + + vfs_lookup("/",&(thd->cur_dir)); thread_list[i] = thd; break; } diff --git a/lab7/src/tmpfs.c b/lab7/src/tmpfs.c index bcdb9573e..62e367692 100644 --- a/lab7/src/tmpfs.c +++ b/lab7/src/tmpfs.c @@ -33,7 +33,8 @@ void tmpfs_init() tmpfs_mkdir(rootfs->root,&tmp,"nothing1"); //bad method tmpfs_mkdir(rootfs->root,&tmp,"nothing2"); tmpfs_mkdir(rootfs->root,&tmp,"initramfs"); - //tmpfs_mkdir(rootfs->root,&tmp,"dev"); + tmpfs_mkdir(rootfs->root,&tmp,"dev"); + vfs_mkdir("/dev/uart"); } int tmpfs_mount(struct filesystem* fs,struct mount* mount) diff --git a/lab7/src/uartfs.c b/lab7/src/uartfs.c new file mode 100644 index 000000000..b0b315e40 --- /dev/null +++ b/lab7/src/uartfs.c @@ -0,0 +1,72 @@ +#include "buddy.h" +#include "uartfs.h" +#include "vfs.h" +#include "mini_uart.h" + +#define size_t int + +struct file_operations* uartfs_f_ops; + +void uartfs_init(struct mount* mount_node) +{ + uartfs_f_ops = d_alloc(sizeof(struct file_operations)); + uartfs_f_ops->write = uartfs_write; + uartfs_f_ops->read = uartfs_read; + uartfs_f_ops->open = uartfs_open; + uartfs_f_ops->close = uartfs_close; + + struct filesystem *fs = d_alloc(sizeof(struct filesystem)); + fs->name = "uartfs"; + fs->setup_mount = uartfs_mount; + register_filesystem(fs); + fs->setup_mount(fs,mount_node); + return; +} + +int uartfs_mount(struct filesystem* fs,struct mount* mount) +{ + mount->fs= fs; + struct vnode* tmp = d_alloc(sizeof(struct vnode)); + tmp->mount = mount; + tmp->f_ops = uartfs_f_ops; + tmp->node_type = "directory"; + mount->root = tmp; + return 0; +} + +int uartfs_write(struct file* file,const void* buf,size_t len) +{ + char* buffer = buf; + for(int i=0;ivnode = file_node; + open_file->f_ops = file_node->f_ops; + open_file->f_pos = 0; + *target = open_file; + return 0; +} + +int uartfs_close(struct file* file) +{ + return 0; +} From b4e537777d77a6073b99fc975b1609b435aff879 Mon Sep 17 00:00:00 2001 From: chuckwu2000 Date: Thu, 15 Jun 2023 10:28:03 +0800 Subject: [PATCH 4/4] [add comment] adv2 not finish --- lab7/src/kernel.c | 8 -------- lab7/src/mount_cpio.c | 1 - lab7/src/ramdisk.c | 2 -- lab7/src/tmpfs.c | 6 +++--- lab7/src/uartfs.c | 6 ++---- lab7/src/vfs.c | 31 +++++++++++++++---------------- 6 files changed, 20 insertions(+), 34 deletions(-) delete mode 100644 lab7/src/mount_cpio.c diff --git a/lab7/src/kernel.c b/lab7/src/kernel.c index 2edd23106..ae3e4e5c0 100644 --- a/lab7/src/kernel.c +++ b/lab7/src/kernel.c @@ -70,15 +70,7 @@ void kernel_main(void* dtb) //x0 is the first argument vfs_lookup("/dev/uart",&mount_node); struct mount* mount = d_alloc(sizeof(struct mount)); - mount_node->mount = mount; - mount->root = mount_node; uartfs_init(mount); - struct file* uart_stdin = null; - struct file* uart_stdout = null; - struct file* uart_stderr = null; - vfs_open("/dev/uart",0,&uart_stdin); - vfs_open("/dev/uart",0,&uart_stdout); - vfs_open("/dev/uart",0,&uart_stderr); while (1) { diff --git a/lab7/src/mount_cpio.c b/lab7/src/mount_cpio.c deleted file mode 100644 index 8b1378917..000000000 --- a/lab7/src/mount_cpio.c +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lab7/src/ramdisk.c b/lab7/src/ramdisk.c index 7e69a3028..99c8b09d9 100644 --- a/lab7/src/ramdisk.c +++ b/lab7/src/ramdisk.c @@ -166,7 +166,5 @@ void mount_cpio(struct vnode* mount_node) target->internal = file_content[i]; target->file_size = fs_arr[i]; } - struct vnode* tmp; - int check = vfs_lookup("/initramfs/vfs1.img",&tmp); return; } diff --git a/lab7/src/tmpfs.c b/lab7/src/tmpfs.c index 62e367692..2add3abb9 100644 --- a/lab7/src/tmpfs.c +++ b/lab7/src/tmpfs.c @@ -30,7 +30,7 @@ void tmpfs_init() register_filesystem(fs); fs->setup_mount(fs,rootfs); struct vnode* tmp; - tmpfs_mkdir(rootfs->root,&tmp,"nothing1"); //bad method + tmpfs_mkdir(rootfs->root,&tmp,"nothing1"); //bad method -> to solve child overwrite tmpfs_mkdir(rootfs->root,&tmp,"nothing2"); tmpfs_mkdir(rootfs->root,&tmp,"initramfs"); tmpfs_mkdir(rootfs->root,&tmp,"dev"); @@ -110,7 +110,7 @@ int tmpfs_open(struct vnode* file_node,struct file** target) int tmpfs_close(struct file* file) { - if(file->f_pos > file->vnode->file_size) + if(file->f_pos > file->vnode->file_size) //update if write file { file->vnode->file_size = file->f_pos; } @@ -168,7 +168,7 @@ int tmpfs_create(struct vnode* dir_node,struct vnode** target,const char* compon return -1; } new_file = d_alloc(sizeof(struct vnode)); - new_file->mount = dir_node->mount; + new_file->mount = null; new_file->v_ops = tmpfs_v_ops; new_file->f_ops = tmpfs_f_ops; char* tmp_internal = d_alloc(0x100); diff --git a/lab7/src/uartfs.c b/lab7/src/uartfs.c index b0b315e40..5df497731 100644 --- a/lab7/src/uartfs.c +++ b/lab7/src/uartfs.c @@ -47,20 +47,18 @@ int uartfs_write(struct file* file,const void* buf,size_t len) int uartfs_read(struct file* file,void* buf,size_t len) { char* buffer = buf; - int count = 0; for(int i=0;ivnode = file_node; - open_file->f_ops = file_node->f_ops; + open_file->f_ops = uartfs_f_ops; open_file->f_pos = 0; *target = open_file; return 0; diff --git a/lab7/src/vfs.c b/lab7/src/vfs.c index 1330469c1..683645d57 100644 --- a/lab7/src/vfs.c +++ b/lab7/src/vfs.c @@ -49,37 +49,37 @@ int vfs_lookup(const char* pathname,struct vnode** target) struct vnode *cur_dir = thd->cur_dir; int index = 0; - char* dir_record = d_alloc(16); + char* dir_record = d_alloc(16); //store component_name for(int i=0;i<16;i++) { dir_record[i] = 0; } - for(int i=0;i<255;i++) //max pathname is 255 + for(int i=0;i<255;i++) //max pathname is 255 { if(pathname[i] == '/') { if(i == 0) { - cur_dir = rootfs->root; + cur_dir = rootfs->root; //pathname must start with / } else { - if(strcmp(cur_dir->node_type,"directory") != 0) //can't find go on + if(strcmp(cur_dir->node_type,"directory") != 0) //can't find go on { uart_send_string("lookup : this is not a directory!!\n"); return -1; } struct vnode* next_dir; - int op_status = cur_dir->v_ops->lookup(cur_dir,&next_dir,dir_record); + int op_status = cur_dir->v_ops->lookup(cur_dir,&next_dir,dir_record); //search next_dir if(op_status < 0) { - uart_send_string("lookup op not found!!\n"); + uart_send_string("lookup : lookup dir fail!!\n"); return op_status; } - if(next_dir->mount != null && next_dir->mount->root != null) + if(next_dir->mount != null && next_dir->mount->root != null) //if vnode have mount { - next_dir = next_dir->mount->root; + next_dir = next_dir->mount->root; //goto mount_node's root } cur_dir = next_dir; @@ -108,15 +108,14 @@ int vfs_lookup(const char* pathname,struct vnode** target) int op_status = cur_dir->v_ops->lookup(cur_dir,target,dir_record); if(op_status < 0) { - uart_send_string("lookup op not found!!\n"); + uart_send_string("lookup : lookup dir fail!!\n"); return op_status; } if(strcmp((*target)->node_type,"directory") == 0 && (*target)->mount != null && (*target)->mount->root != null) { - *target = (*target)->mount->root; + *target = (*target)->mount->root; //goto mount_node's root } - return 0; } } @@ -126,7 +125,7 @@ int vfs_lookup(const char* pathname,struct vnode** target) index++; } } - uart_send_string("lookup fail!!\n"); + uart_send_string("lookup op fail!!\n"); return -1; //should not be here } @@ -176,10 +175,10 @@ int vfs_open(const char* pathname,int flags,struct file** target) uart_send_string(" -> file path\n"); */ struct vnode* parent; - op_status = vfs_lookup(file_path,&parent); + op_status = vfs_lookup(file_path,&parent); //pre_file_path must exist if(op_status < 0) { - uart_send_string("lookup file_path error\n"); + uart_send_string("open : lookup pre_file_path error\n"); return op_status; } @@ -261,7 +260,7 @@ int vfs_mkdir(const char* pathname) } int last_dir_pos = 0; - for(int i=0;i<30 && pathname[i] != 0;i++) + for(int i=0;i<40 && pathname[i] != 0;i++) { if(pathname[i] == 0) { @@ -320,7 +319,7 @@ int vfs_mount(const char* target,const char* filesystem) int op_status = vfs_lookup(target,&mount_node); if(op_status < 0) { - uart_send_string("mount : lookup op error!!\n"); + uart_send_string("mount : lookup mount_node fail!!\n"); return op_status; } if(mount_node->mount != null)