📄 bit-vect.c
字号:
#include "fs.h"// member functions for BitVect#define BVSIZE BLKSIZEvoid BitVect_init(struct BitVect *v){//make all bits free initially int i; for(i=0;i<BVSIZE;i++) v->vect[i]=0;}static int find_free_loc(char vect){// ret loc of the first 0 in vect int i; char mask; for(i=0;i<8;i++){ mask = (1 << i); if ( (vect & mask) == 0) return i; } panic("no free loc");}static void set_bit(char vect, int fbit){// mark fbit position in vect vect = vect | (1 << fbit);}int BitVect_get_free_bit(struct BitVect *v){// find free bit int i,fbit; for(i=0;i<BVSIZE;i++) // if (v->vect[i]!= 0xff) { // found a byte with free bit fbit=find_free_loc(v->vect[i]); // find its loc set_bit(v->vect[i], fbit); // mark it return fbit; } panic("no more free bit");}void BitVect_set_bit(struct BitVect *v,int x){ // first compute vect and offset int vector, offset; vector = x / 8; // vect is a byte offset = x % 8; set_bit(v->vect[vector], offset);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -