Cosmetic cleanup: fsinit reads sb and calls loginit. initialize icache

in main.c and don't make it disk specific; the icache is shared.  This
doesn't matter since we have only one disk, but conceptually cleaner
and maybe helpful to students for mount lab.
This commit is contained in:
Frans Kaashoek 2019-08-18 14:35:11 -04:00
parent a9953236cc
commit 2501560cd6
5 changed files with 21 additions and 18 deletions

View file

@ -35,12 +35,12 @@ int filestat(struct file*, uint64 addr);
int filewrite(struct file*, uint64, int n);
// fs.c
void readsb(int dev, struct superblock *sb);
void fsinit(int);
int dirlink(struct inode*, char*, uint);
struct inode* dirlookup(struct inode*, char*, uint*);
struct inode* ialloc(uint, short);
struct inode* idup(struct inode*);
void iinit(int dev);
void iinit();
void ilock(struct inode*);
void iput(struct inode*);
void iunlock(struct inode*);
@ -64,7 +64,7 @@ void kfree(void *);
void kinit();
// log.c
void initlog(int dev);
void initlog(int, struct superblock*);
void log_write(struct buf*);
void begin_op();
void end_op();

View file

@ -28,7 +28,7 @@ static void itrunc(struct inode*);
struct superblock sb;
// Read the super block.
void
static void
readsb(int dev, struct superblock *sb)
{
struct buf *bp;
@ -38,6 +38,15 @@ readsb(int dev, struct superblock *sb)
brelse(bp);
}
// Init fs
void
fsinit(int dev) {
readsb(dev, &sb);
if(sb.magic != FSMAGIC)
panic("invalid file system");
initlog(dev, &sb);
}
// Zero a block.
static void
bzero(int dev, int bno)
@ -170,7 +179,7 @@ struct {
} icache;
void
iinit(int dev)
iinit()
{
int i = 0;
@ -178,10 +187,6 @@ iinit(int dev)
for(i = 0; i < NINODE; i++) {
initsleeplock(&icache.inode[i].lock, "inode");
}
readsb(dev, &sb);
if(sb.magic != FSMAGIC)
panic("invalid file system");
}
static struct inode* iget(uint dev, uint inum);

View file

@ -52,16 +52,14 @@ static void recover_from_log(void);
static void commit();
void
initlog(int dev)
initlog(int dev, struct superblock *sb)
{
if (sizeof(struct logheader) >= BSIZE)
panic("initlog: too big logheader");
struct superblock sb;
initlock(&log.lock, "log");
readsb(dev, &sb);
log.start = sb.logstart;
log.size = sb.nlog;
log.start = sb->logstart;
log.size = sb->nlog;
log.dev = dev;
recover_from_log();
}

View file

@ -23,6 +23,7 @@ main()
plicinit(); // set up interrupt controller
plicinithart(); // ask PLIC for device interrupts
binit(); // buffer cache
iinit(); // inode cache
fileinit(); // file table
virtio_disk_init(); // emulated hard disk
userinit(); // first user process

View file

@ -493,12 +493,11 @@ forkret(void)
release(&myproc()->lock);
if (first) {
// Some initialization functions must be run in the context
// of a regular process (e.g., they call sleep), and thus cannot
// File system initialization must be run in the context of a
// regular process (e.g., because it calls sleep), and thus cannot
// be run from main().
first = 0;
iinit(ROOTDEV);
initlog(ROOTDEV);
fsinit(ROOTDEV);
}
usertrapret();