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:
		
							parent
							
								
									a9953236cc
								
							
						
					
					
						commit
						2501560cd6
					
				
					 5 changed files with 21 additions and 18 deletions
				
			
		|  | @ -35,12 +35,12 @@ int             filestat(struct file*, uint64 addr); | ||||||
| int             filewrite(struct file*, uint64, int n); | int             filewrite(struct file*, uint64, int n); | ||||||
| 
 | 
 | ||||||
| // fs.c
 | // fs.c
 | ||||||
| void            readsb(int dev, struct superblock *sb); | void            fsinit(int); | ||||||
| int             dirlink(struct inode*, char*, uint); | int             dirlink(struct inode*, char*, uint); | ||||||
| struct inode*   dirlookup(struct inode*, char*, uint*); | struct inode*   dirlookup(struct inode*, char*, uint*); | ||||||
| struct inode*   ialloc(uint, short); | struct inode*   ialloc(uint, short); | ||||||
| struct inode*   idup(struct inode*); | struct inode*   idup(struct inode*); | ||||||
| void            iinit(int dev); | void            iinit(); | ||||||
| void            ilock(struct inode*); | void            ilock(struct inode*); | ||||||
| void            iput(struct inode*); | void            iput(struct inode*); | ||||||
| void            iunlock(struct inode*); | void            iunlock(struct inode*); | ||||||
|  | @ -64,7 +64,7 @@ void            kfree(void *); | ||||||
| void            kinit(); | void            kinit(); | ||||||
| 
 | 
 | ||||||
| // log.c
 | // log.c
 | ||||||
| void            initlog(int dev); | void            initlog(int, struct superblock*); | ||||||
| void            log_write(struct buf*); | void            log_write(struct buf*); | ||||||
| void            begin_op(); | void            begin_op(); | ||||||
| void            end_op(); | void            end_op(); | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								kernel/fs.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								kernel/fs.c
									
										
									
									
									
								
							|  | @ -28,7 +28,7 @@ static void itrunc(struct inode*); | ||||||
| struct superblock sb;  | struct superblock sb;  | ||||||
| 
 | 
 | ||||||
| // Read the super block.
 | // Read the super block.
 | ||||||
| void | static void | ||||||
| readsb(int dev, struct superblock *sb) | readsb(int dev, struct superblock *sb) | ||||||
| { | { | ||||||
|   struct buf *bp; |   struct buf *bp; | ||||||
|  | @ -38,6 +38,15 @@ readsb(int dev, struct superblock *sb) | ||||||
|   brelse(bp); |   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.
 | // Zero a block.
 | ||||||
| static void | static void | ||||||
| bzero(int dev, int bno) | bzero(int dev, int bno) | ||||||
|  | @ -170,7 +179,7 @@ struct { | ||||||
| } icache; | } icache; | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| iinit(int dev) | iinit() | ||||||
| { | { | ||||||
|   int i = 0; |   int i = 0; | ||||||
|    |    | ||||||
|  | @ -178,10 +187,6 @@ iinit(int dev) | ||||||
|   for(i = 0; i < NINODE; i++) { |   for(i = 0; i < NINODE; i++) { | ||||||
|     initsleeplock(&icache.inode[i].lock, "inode"); |     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); | static struct inode* iget(uint dev, uint inum); | ||||||
|  |  | ||||||
|  | @ -52,16 +52,14 @@ static void recover_from_log(void); | ||||||
| static void commit(); | static void commit(); | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| initlog(int dev) | initlog(int dev, struct superblock *sb) | ||||||
| { | { | ||||||
|   if (sizeof(struct logheader) >= BSIZE) |   if (sizeof(struct logheader) >= BSIZE) | ||||||
|     panic("initlog: too big logheader"); |     panic("initlog: too big logheader"); | ||||||
| 
 | 
 | ||||||
|   struct superblock sb; |  | ||||||
|   initlock(&log.lock, "log"); |   initlock(&log.lock, "log"); | ||||||
|   readsb(dev, &sb); |   log.start = sb->logstart; | ||||||
|   log.start = sb.logstart; |   log.size = sb->nlog; | ||||||
|   log.size = sb.nlog; |  | ||||||
|   log.dev = dev; |   log.dev = dev; | ||||||
|   recover_from_log(); |   recover_from_log(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -23,6 +23,7 @@ main() | ||||||
|     plicinit();      // set up interrupt controller
 |     plicinit();      // set up interrupt controller
 | ||||||
|     plicinithart();  // ask PLIC for device interrupts
 |     plicinithart();  // ask PLIC for device interrupts
 | ||||||
|     binit();         // buffer cache
 |     binit();         // buffer cache
 | ||||||
|  |     iinit();         // inode cache
 | ||||||
|     fileinit();      // file table
 |     fileinit();      // file table
 | ||||||
|     virtio_disk_init(); // emulated hard disk
 |     virtio_disk_init(); // emulated hard disk
 | ||||||
|     userinit();      // first user process
 |     userinit();      // first user process
 | ||||||
|  |  | ||||||
|  | @ -493,12 +493,11 @@ forkret(void) | ||||||
|   release(&myproc()->lock); |   release(&myproc()->lock); | ||||||
| 
 | 
 | ||||||
|   if (first) { |   if (first) { | ||||||
|     // Some initialization functions must be run in the context
 |     // File system initialization must be run in the context of a
 | ||||||
|     // of a regular process (e.g., they call sleep), and thus cannot
 |     // regular process (e.g., because it calls sleep), and thus cannot
 | ||||||
|     // be run from main().
 |     // be run from main().
 | ||||||
|     first = 0; |     first = 0; | ||||||
|     iinit(ROOTDEV); |     fsinit(ROOTDEV); | ||||||
|     initlog(ROOTDEV); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   usertrapret(); |   usertrapret(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue