📄 blockmanage.c
字号:
#include <stdio.h>#include "filesys.h"unsigned int balloc();int bfree(unsigned int pos);void updateblockmap(unsigned short order,char flag);/*balloc function write the ainode to the filesys.o(ainode's address is already allocated).change the super->s_nfree */unsigned int balloc(){ unsigned short number; unsigned short i; if(super->s_nfree==0) { printf("\nDisk Full!!!\n"); return DISKFULL; } number=super->s_pfree; *(super->s_free+number)='1'; updateblockmap(number,super->s_free[number]); if(--super->s_nfree!=0) { for(i=0;i<BLOCKNUM;i++) { if(*(super->s_free+(i+super->s_pfree)%BLOCKNUM)!='1') { super->s_pfree=(i+super->s_pfree)%BLOCKNUM; updatesys(); break; } } } return number; } int bfree(pos)unsigned int pos;{ if(super->s_nfree+1>BLOCKNUM) { printf("\nDisk Error!!!\n"); return DISKFULL; } super->s_nfree++; *(super->s_free+pos)='0'; super->s_pfree=pos; updatesys(); updateblockmap(pos,'0'); return DISKSUCCESS;}void updateblockmap(unsigned short order,char flag){ fd=fopen("filesystem","r+"); fseek(fd,(BLOCKSIZE+order),SEEK_SET); fwrite(&flag,sizeof(char),1,fd); fseek(fd,0,SEEK_SET); fwrite(super,sizeof(struct filesys),1,fd); fclose(fd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -