?? format.c
字號(hào):
#include <stdio.h>
#include <stdlib.h>
#include "filesys.h"
format()
{
struct inode *inode; //i節(jié)點(diǎn)
struct direct dir_buf[BLOCKSIZ/(DIRSIZ+2)];//目錄項(xiàng)結(jié)構(gòu)
unsigned int block_buf[BLOCKSIZ/sizeof(int)];
char *buf;
int i,j;
/* creat the file system file*/
if(!(fd=fopen("filesystem","wb+")))
{printf("err!\n");exit(0);}
buf=(char *)malloc((DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char));
if(buf==NULL)
{ printf("\nfile system file creat failed!!!\n"); exit(0); }
fseek(fd,0,SEEK_SET);
fwrite(buf,1,(DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char),fd);
//1. creat the main directory and its sub dir etc and the file password
inode=iget(0); /* 0 empty dinode id */
inode->di_mode=DIEMPTY;//di_mode存取權(quán)限
iput(inode);
inode=iget(1); /* l main dir id */
inode->di_number=1;
inode->di_mode=DEFAULTMODE | DIDIR;
inode->di_size=3*(DIRSIZ+2);
inode->di_addr[0]=0; /* block 0# is used by the main directory */
strcpy(dir_buf[0].d_name,"..");
dir_buf[0].d_ino=1;
strcpy(dir_buf[1].d_name,".");
dir_buf[1].d_ino=1;
strcpy(dir_buf[2].d_name,"etc");
dir_buf[2].d_ino=2;
fseek(fd,DATASTART,SEEK_SET);
fwrite(dir_buf,1,3*(DIRSIZ+2),fd);
iput(inode);
/* inode=iget(2); // 2 etc dir id
inode->di_number=1;
inode->di_mode=DEFAULTMODE | DIDIR;
inode->di_size=3*(DIRSIZ+2);
inode->di_addr[0]=1; // block 1# is used by the etc directory
strcpy(dir_buf[0].d_name,"..");
dir_buf[0].d_ino=1;
strcpy(dir_buf[1].d_name,".");
dir_buf[1].d_ino=2;
strcpy(dir_buf[2].d_name,"password");
dir_buf[2].d_ino=3;
fseek(fd,DATASTART+BLOCKSIZ*1,SEEK_SET);
fwrite(dir_buf,1,3*(DIRSIZ+2),fd);
iput(inode);
inode=iget(3); // 3 password id
inode->di_number=1;
inode->di_mode=DEFAULTMODE | DIFILE;
inode->di_size=BLOCKSIZ;
inode->di_addr[0]=2; //block 2# is used by the password file
for(i=5;i<PWDNUM;i++)
{
pwd[i].p_uid=0;
pwd[i].p_gid=0;
strcpy(pwd[i].password,"123456789ABC");
}
fseek(fd,DATASTART+2*BLOCKSIZ,SEEK_SET);
fwrite(pwd,1,BLOCKSIZ,fd);
iput(inode);
*/
// 2.initialize the superblock
filsys.s_isize=DINODEBLK;
filsys.s_fsize=FILEBLK;
filsys.s_ninode=DINODEBLK*BLOCKSIZ/DINODESIZ-4;
filsys.s_nfree=FILEBLK-3;
for(i=0;i<NICINOD;i++)
{
/* begin with 4,0,1,2,3,is used by main,etc,password*/
filsys.s_inode[i]=4+i;//????????????????????????????????????
}
filsys.s_pinode=0;
filsys.s_rinode=NICINOD+4;
block_buf[NICFREE-1]=FILEBLK+1; /* FILEBLK+1 is a flag of end */
for(i=0;i<NICFREE-1; i++)
block_buf[NICFREE-2-i]=FILEBLK-i;
fseek(fd,DATASTART+BLOCKSIZ*(FILEBLK-NICFREE-1),SEEK_SET);
fwrite(block_buf,1,BLOCKSIZ,fd);
for(i=FILEBLK-NICFREE-1;i>2;i-=NICFREE)
{
for(j=0;j<NICFREE;j++)
{
block_buf[j]=i-j;
}
block_buf[j]=50;
fseek(fd,DATASTART+BLOCKSIZ*(i-1),SEEK_SET);
fwrite(block_buf,1,BLOCKSIZ,fd);
}
j=i+NICFREE;
for(i=j ;i>2;i--)
{
filsys.s_free[NICFREE-1+i-j]=i;
}
filsys.s_pfree=NICFREE-1-j+3;
filsys.s_pinode=0;
fseek(fd,BLOCKSIZ,SEEK_SET);
fwrite(&filsys.s_isize,1,sizeof(struct filsys),fd);
fseek(fd,BLOCKSIZ,SEEK_SET);
fread(&filsys.s_isize,1,sizeof(struct filsys),fd);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -