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

📄 inode.c

📁 用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码
💻 C
字号:
#include "fs.h"//member functions for Inode, Itable classvoid Inode_init(struct Inode *in){   in->ino=-1;   //in->num_blk=0; // 0 blocks assigned yet}void ITable_make_inode(int ino, int blkno){// make new inode in disk and copy it in itable   struct Ext2Inode * inode;   struct Inode *in;   inode=Ext2Inode_make_inode(ino, blkno);   in = ITable_get_free_inode();   in->ino=ino;   in->inode=inode;}   void Inode_alloc_block(struct Inode *in, int blk_no){// assign a block (whose block number is blk_no) to this inode   Ext2Inode_alloc_block(in->inode, blk_no);}struct DirBlock *Inode_get_block(struct Inode *in, int b){// return b-th block of file with inode "in"   // block num   int  bno = in->inode->i_block[b];   return (struct DirBlock *)FBTable_get_block(bno);}void ITable_init(){   int i;   for(i=0;i<MAX_INODE_ITABLE;i++)      Inode_init(&(itable.arr[i]));}struct Inode * ITable_get_free_inode(){   int i;   for(i=0;i<MAX_INODE_ITABLE;i++)      if (itable.arr[i].ino==-1)	     return &(itable.arr[i]);}struct Inode * ITable_get_inode(int ino){// this inode is not in the system ITable. get it   struct Ext2Inode * inode;   struct Inode *in;   inode = Ext2Inode_get_inode(ino);   in = ITable_get_free_inode();   in->ino = ino;   in->inode = inode;   return in;}struct Inode *ITable_find_loc(int ino){// the location of inode in inode table that has inode num = ino   int i;   for(i=0;i<MAX_INODE_ITABLE;i++)      if (itable.arr[i].ino==ino)	     return &(itable.arr[i]);   // if we couldn't find, get it   return ITable_get_inode(ino);}struct Inode *find_inode_for_file(struct Inode *currdir, char *f){// return the inode for file f which belongs to currdir.   int ino = find_ino_for_file_in_dir(f, currdir); // get ino   struct Inode *in = ITable_find_loc(ino);   printk("inode for %s is %d\n", f, ino);   return in;}struct Inode *ITable_compute_inode(char *path){// bring in the inode of file "path" and return the pointer// suppose path was /aa/bb   char dir[EXT2_NAME_LEN+1], *temp;   struct Inode *curr_inode;   int leaf; // we don't use this here   leaf = get_next_fname(path,dir);   // following should changed later so that we use current->root, current->pwd   if (dir[0]=='/' && strlen(dir)==1){      curr_inode = root; // root dir indoe   }    else panic("only absolute path supported for now\n");   temp = path; // temp is /aa/bb   for(;;){      temp=move_to_remaining_path(temp); // temp is aa/bb, bb, NULL 	  if (temp==0) return curr_inode; // return inode of /aa/bb	  leaf=get_next_fname(temp, dir); // dir is aa, bb	  curr_inode = find_inode_for_file(curr_inode, dir); 	                           // curr_inode is /aa, /aa/bb   }}struct Inode *ITable_compute_inode_for_last_directory(char *path, char *leaf_name){// bring in the inode of last dir in "path" and return the pointer, and at the// same time return the leaf file name in leaf_name// suppose path was /aa/bb/cc, then we return inode of /aa/bb, and cc in// leaf_name   char dir[EXT2_NAME_LEN+1], *temp;   struct Inode *curr_inode;   int leaf;   printk("comp inode for last dir. path is %s :", path);   leaf = get_next_fname(path, dir);   printk("next fname is %s : ", dir);   // following should changed later so that we use current->root, current->pwd   if (dir[0]=='/' && strlen(dir)==1){      curr_inode = &(itable.arr[2]); // root dir indoe   }    else panic("only absolute path supported for now\n");   temp = path; // temp is /aa/bb/cc   for(;;){      printk("curr inode no is %d : ",curr_inode->ino);      temp=move_to_remaining_path(temp); // temp is aa/bb/cc, bb/cc, cc	  if (temp==0) panic("we reached end of path\n"); //this shouldn't happen	  leaf = get_next_fname(temp, dir); // dir is aa, bb, cc	  if (leaf==1){ // we reached the end of the path. leaf is 0,0,1	     // leaf file name		 strcpy(leaf_name, dir);		 printk("returning. leaf_name %s last dir ino %d\n",leaf_name,curr_inode->ino);	     return curr_inode; // return the last directory	  }	  curr_inode = find_inode_for_file(curr_inode, dir); 	                           // curr_inode is /aa, /aa/bb   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -