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

📄 ext2-inode.c

📁 用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码
💻 C
字号:
#include "fs.h"//member functions for Ext2Inode /* ATTENTION:ext2 inode table stores inode n in inode_table[n-1]!!! */void Ext2Inode_init(struct Ext2Inode *in){   in->i_blocks=0; // 0 blocks assigned yet}void Ext2Inode_alloc_block(struct Ext2Inode *in, int blk_no){// assign a block (whose block number is blk_no) to this inode   int nblk = in->i_blocks;   if (nblk <= 12) { // we can still use direct block      in->i_block[nblk] = blk_no;	  in->i_blocks++;   }   else panic("we can't handle more than 13 blocks yet\n");}struct Ext2Inode * Ext2Inode_make_inode(int ino, int blkno){// make ext2 inode with inode num=ino and 1 block whose block num is blkno   int q, r,blk_loc;   struct Ext2Inode * iblock; int adj_ino;   adj_ino = ino-1; // inode table starts with ino 1, not ino 0   q = adj_ino / EXT2_INODES_PER_BLOCK; //block num in which this ino belongs to   r = adj_ino % EXT2_INODES_PER_BLOCK; // offset   blk_loc = EXT2_INODE_TABLE_LOCATION + q; // block location   iblock = (struct Ext2Inode *)FBTable_get_block(blk_loc);   Ext2Inode_alloc_block(&iblock[r], blkno);   return &iblock[r];}struct Ext2Inode * Ext2Inode_get_inode(int ino){// get ext2 inode with inode num=ino   int q, r,blk_loc;   struct Ext2Inode * iblock;   int adj_ino;   printk("ext2 inode %d is goint to be retrieved\n",ino);   printk("EXT2_INODES_PER_BLOCK is %d\n",EXT2_INODES_PER_BLOCK);   adj_ino = ino-1; // inode table starts with ino 1 not ino 0   q = adj_ino / EXT2_INODES_PER_BLOCK; //block num in which this ino belongs to   r = adj_ino % EXT2_INODES_PER_BLOCK; // offset   blk_loc = EXT2_INODE_TABLE_LOCATION + q; // block location   iblock = (struct Ext2Inode *)FBTable_get_block(blk_loc);   printk("now it is: bnum:%d off:%d i_blocks:%d, i_block[0]:%d\n", q,r,iblock[r].i_blocks, iblock[r].i_block[0]);   return &iblock[r];}

⌨️ 快捷键说明

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