1 Star 0 Fork 0

杨谨徽 / 代码托管

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
FS1.1.c 3.02 KB
一键复制 编辑 原始数据 按行查看 历史
杨谨徽 提交于 2023-10-15 02:37 . add FS1.1.c.
#include "type.h"
#include "util.c"
// global variables
MINODE minode[NMINODES], *root;
MTABLE mtable[NMTABLE];
PROC proc[NPROC], *running;
int ninode, nblocks, bmap, imap, ibiock;
int dev;
char gline[25], *name[16]; // tokenized component string strings
int nname; // number of component strings
char *rootdev = "mydisk"; // default root_device
int fs_init()
{
int i, j;
for(i=0; i<NMINODES; i++) // initialize all minodes as FREE
minode[i].refCount = 0;
for(i=0; i<NMOUNT; i++) // initialize mtable entries as FREE
mtable[i].dev = 0;
for (i=0; i<NPROC; i++){ // initialize PROCs
proc[i].status = READY; //reday to run
proc[i].pid = i; //pid = 0 to NPROC-1
proc[i].uid = i; //P0 is a superuser process
for(j=0; j<NFD; j++)
proc[i].fd[j] = 0; //all file descriptors are NULL
proc[i].next = &proc[i+1];
}
proc[NPROC-1].next = &proc[0]; //circular list
running = &proc[0]; //P0 runs first
}
int mount_root (char *rootdev) // mount root file system
{
int i;
MTABLE *mp;
SUPER *sp;
GD *gp;
char buf[BLKSIZE];
dev = open(rootdev, O_RDWR);
if(dev < 0){
printf("panic:can't open root device\n");
exit(1);
}
/* get super block of rootdev */
get_block(dev, 1, buf);
sp = (SUPER *)buf;
/* check magic number */
if(sp->s_magic != SUPER_MAGIC){
printf ("super magic=%x:%s is not an EXT2 filesysln",
sp->s_magic, rootdev) ;
exit (0);
}
// fill mount table mtable[0] with rootdev information
mp = &mtable[0]; // use mtable[0]
mp->dev = dev;
// copy super block info into mtable[0]
ninodes = mp->ninodes = sp->s_inodes_count;
nblocks = mp->nblocks = sp->s_blocks_count;
strcpy(mp->devName, rootdev);
strcpy(mp->mntName, "/");
get_block(dev, 2, buf);
gp = (GD *)buf;
bmap = mp->bmap = gp->bg_blocks_bitmap;
imap = mp->imap = gp->bg_inodes_bitmap;
iblock = mp->iblock = gp->bg_inode_table;
printf("bmap=%d imap=%d iblock=%d\n", bmap, imap, iblock);
// call iget( ) , which inc minode's refCount
root = iget(dev, 2); // get root inode
mp->mntDirPtr = root; // double link
root->mntPtr = mp;
// set proc CwDs
for(i=0; i<NPROC; i++) // set proc's CWD
proc[i].cwd = iget(dev, 2); // each inc refcount by 1
printf("mount : %smounted on / in", rootdev);
return 0;
}
int main(int argc, char *argv[])
{
char line[128], cmd[16], pathname[64];
if(argc > 1)
rootdev = argv[1];
fs_init( );
mount_root(rootdev);
while(1){
printf("P%d running: ", running->pid);
printf("input command : ");
fgets(line, 128, stdin);
line[strlen(line)-1] = 0;
if(line[0]==0)
continue;
sscanf(line, "%s %s", cmd, pathname);
if(!strcmp(cmd, "ls"))
ls(pathname);
if(!strcmp(cmd, "cd"))
chdir(pathname);
if(!strcmp(cmd, "pwd"))
pwd(running->cwd);
if(!strcmp(cmd, "quit"))
quit( );
}
}
int quit() // write a11 modified minodes to disk
{
int i;
for(i=0; i<NMINODES; i++){
MINODE *mip = &minode[i];
if(mip->refCount && mip->dirty){
mip->refCount = 1;
iput(mip);
}
}
exit(0);
}
1
https://gitee.com/SHIBATORI/code-hosting.git
git@gitee.com:SHIBATORI/code-hosting.git
SHIBATORI
code-hosting
代码托管
master

搜索帮助