📄 file-syscall.c
字号:
#include "../hos.h"// file system callsint do_creat(char *fname){ struct Inode *ldir_inode; struct DirBlock *ldir; int x, new_ino,new_bno; char leaf_name[MAXFNAME]; // for leaf file name // compute the inode for last directory, and leaf file name ldir_inode = ITable_compute_inode_for_last_directory(fname, leaf_name); printk("last dir ino %d : ",ldir_inode->ino); // get the directory block for this dir ldir = Inode_get_block(ldir_inode); printk("its blk is "); FB_dump((char *)ldir); // alloc new inode new_ino = BitVect_get_free_bit(&d_ibm); printk("new ino %d : ",new_ino); // alloc a block new_bno = BitVect_get_free_bit(&d_dbm); printk("new blk %d : ", new_bno); // make inode ITable_make_inode(new_ino, new_bno); // report this in the last directory DirBlk_report_new_entry(ldir, new_ino, leaf_name); // flush file system flush_to_disk(); // now perform open for this file x = do_open(fname); return x;}int do_open(char *fname){ struct Inode *inode; struct FilePtr *fptr; int x; inode = ITable_compute_inode(fname); // report it in file table fptr = FPTable_report_new_file(inode); // report it in current->fd x = FDTable_report_new_fd(current->fd, fptr); return x;}void do_read(int x, char *buf, int n){// read n bytes from file x. put it in buf struct Inode *inode; char *blk; int pos; pos = current->fd[x]->pos; // current file pointer inode = current->fd[x]->iptr; // assume all files are 1 block for now. get it blk = FBTable_get_block(inode->blk[0]); substr(blk, buf, pos, pos+n-1); current->fd[x]->pos += n; // move the file pointer}void do_write(int x, char *buf, int n){// write n bytes in buf to file x struct Inode *inode; struct FBlock *blk; int pos; pos = current->fd[x]->pos; // current file pointer inode = current->fd[x]->iptr; // assume all files are 1 block for now. get it blk = FBTable_get_block(inode->blk[0]); write_substr(buf, blk, pos, pos+n-1); current->fd[x]->pos += n; // move the file pointer flush_to_disk();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -