⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file-syscall.c

📁 用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码
💻 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[EXT2_NAME_LEN]; // 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 *in;   char *blk;   int pos;      pos = current->fd[x]->pos; // current file pointer   in = current->fd[x]->iptr;   // get it   if ((pos+n) >= BLKSIZE) panic("can't read past block, yet\n");   blk = FBTable_get_block(in->inode->i_block[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 *in;   char *blk;   int pos;      pos = current->fd[x]->pos; // current file pointer   in = current->fd[x]->iptr;   // assume all files are 1 block for now. get it   blk = FBTable_get_block(in->inode->i_block[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 + -