format.c
来自「操作系统简单的登入程序」· C语言 代码 · 共 67 行
C
67 行
#include <stdio.h>#include <string.h>#include "filesys.h" format(){ char* buff; super= (struct filesys* )malloc(sizeof(struct filesys)); fd=fopen("filesystem","w+"); buff= (char* )malloc(BLOCKNUM*BLOCKSIZE*sizeof(char)); if(buff ==NULL) { printf("\n file system file creat failed!!!\n"); } else { fseek(fd,0,SEEK_SET); fwrite(buff,BLOCKNUM*BLOCKSIZE*sizeof(char),1,fd); super->s_isize=BLOCKNUM; super->s_fsize=BLOCKNUM-DATABLOCKSTART; super->s_nfree=super->s_fsize; super->s_pfree=DATABLOCKSTART; super->s_ninode=INODENUMBER; super->s_pinode=0; fseek(fd,0,SEEK_SET); fwrite(super,sizeof(struct filesys),1,fd); fseek(fd,BLOCKSIZE,SEEK_SET); memset(block_buf,'0',BLOCKNUM); memset(block_buf,'1',DATABLOCKSTART); fwrite(block_buf,sizeof(char),BLOCKNUM,fd); fseek(fd,2*BLOCKSIZE,SEEK_SET); memset(inode_buf,'0',BLOCKNUM); fwrite(inode_buf,sizeof(char),BLOCKNUM,fd); super->s_free=block_buf; super->s_inode=inode_buf; newdir1("root","admin","root"); newdir2("root","admin"); } //fclose(fd);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?