资源简介
对Linux文件系统用C语言进行模拟,在Windows 下建立自己的小型二级文件系统,并在自已建立的文件系统之上进行一系列的操作,包括文件系统的建立,对索引结点和目录文件的操作,目录的安全性设置,目录的检索以及文件的共享等。
代码片段和文件信息
#include
#include“head.h“
#include
#include
struct hinode hinode[NHINO];
struct dir dir;
struct pwd pwd[PWDNUM];
struct user user[USERNUM];
struct inode *cur_path_inode;
int user_id;
int user_gid;
int login1;
int infile;//判断是否是查询。
FILE *fd;
struct filsys filsys;
struct listid listid;
struct inode *iget(unsigned int dinodeid)
{
int exited=0;
unsigned int inodeid;
long addr;
struct inode *temp*newinode;
inodeid=dinodeid%NHINO;
if(hinode[inodeid].i_forw ==NULL)exited=0;
else
{
temp=hinode[inodeid].i_forw ;
while(temp)
{
if(temp->i_ino ==inodeid)
{
exited=1;
temp->i_count++;
return temp;
}
else
temp=temp->i_forw ;
};
}
addr=DINODESTART+dinodeid*DINODESIZ;
newinode=(struct inode*)malloc(sizeof(struct inode));
fseek(fdaddr0);
fread(&(newinode->di_number)DINODESIZ1fd);
newinode->i_count =1;
newinode->i_flag =0;
newinode->i_ino =dinodeid;
return newinode;
}
void iput(struct inode *pinode)
{
long addr;
if(pinode->i_count>1)
{
pinode->i_count--;
return;
}
else
if(pinode->di_number!=0)
{
addr=DINODESTART+pinode->i_ino*DINODESIZ;
fseek(fdaddr0);
fwrite(&pinode->di_numberDINODESIZ1fd);
}
}
void format()
{
struct inode *inode;
struct direct dir_buf[BLOCKSIZ/(DIRSIZ+2)];
struct pwd pwd[BLOCKSIZ/(PWDSIZ+4)];
char *buf;
int i;
fd=fopen(“filesystem““wb+“);
buf=(char*)malloc((DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char));
if(buf==NULL)
{printf(“\nfile system creat failed!!!\n“);
exit(0);
}
fseek(fd00);
fwrite(buf1(DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char)fd);
pwd[0].p_uid =111;pwd[0].p_gid=01;
strcpy(pwd[0].password“aaa“);
pwd[1].p_uid =222;pwd[1].p_gid=01;
strcpy(pwd[1].password“bbb“);
pwd[2].p_uid =333;pwd[2].p_gid=02;
strcpy(pwd[2].password“ccc“);
pwd[3].p_uid =444;pwd[3].p_gid=03;
strcpy(pwd[3].password“ddd“);
pwd[4].p_uid =555;pwd[4].p_gid=04;
strcpy(pwd[4].password“eee“);
inode=iget(0);
inode->di_mode=DIEMPTY;
iput(inode);
inode=iget(1);
inode->di_number=1;
inode->di_mode=DIDIR|DEFAULTMODE;
inode->di_size=3*(DIRSIZ+2);
inode->di_addr[0]=0;
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(fdDATASTART0);
fwrite(dir_buf13*(DIRSIZ+2)fd);
iput(inode);
inode=iget(2);
inode->di_number=1;
inode->di_mode=DIDIR|DEFAULTMODE;
inode->di_size=3*(DIRSIZ+2);
inode->di_addr[0]=1;
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“pwd“);
dir_buf[2].d_ino=3;
fseek(fdDATASTART+BLOCKSIZ*10);
fwrite(dir_buf13*(DIRSIZ+2)fd);
iput(inode);
inode=iget(3);
inode->di_number=1;
inode->di_mode=DIFILE;
inode->di_size=3*(DIRSIZ+2);
inode->di_addr[0]=2;
for(i=5;i {
pwd[i].p_gid=0;
pwd[i].p_uid=0;
strcpy(pwd[i].password“aaaaaaaaaaa
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2429 2004-05-09 16:41 Linux\head.h
文件 4330 2004-03-23 21:33 Linux\linux.dsp
文件 535 2004-03-23 20:42 Linux\linux.dsw
文件 21967 2004-05-27 21:33 Linux\main.cpp
...D..R 0 2007-08-12 22:16 Linux
----------- --------- ---------- ----- ----
29261 5
评论
共有 条评论