diff options
Diffstat (limited to 'mkfs.c')
-rw-r--r-- | mkfs.c | 47 |
1 files changed, 27 insertions, 20 deletions
@@ -4,11 +4,15 @@ #include <string.h> #include <fcntl.h> #include <assert.h> + +#define stat xv6_stat // avoid clash with host struct stat #include "types.h" #include "fs.h" #include "stat.h" +#include "param.h" -int nblocks = 995; +int nblocks = 985; +int nlog = LOGSIZE; int ninodes = 200; int size = 1024; @@ -33,7 +37,7 @@ ushort xshort(ushort x) { ushort y; - uchar *a = (uchar*) &y; + uchar *a = (uchar*)&y; a[0] = x; a[1] = x >> 8; return y; @@ -43,7 +47,7 @@ uint xint(uint x) { uint y; - uchar *a = (uchar*) &y; + uchar *a = (uchar*)&y; a[0] = x; a[1] = x >> 8; a[2] = x >> 16; @@ -77,20 +81,23 @@ main(int argc, char *argv[]) sb.size = xint(size); sb.nblocks = xint(nblocks); // so whole disk is size sectors sb.ninodes = xint(ninodes); + sb.nlog = xint(nlog); bitblocks = size/(512*8) + 1; usedblocks = ninodes / IPB + 3 + bitblocks; freeblock = usedblocks; - printf("used %d (bit %d ninode %lu) free %u total %d\n", usedblocks, - bitblocks, ninodes/IPB + 1, freeblock, nblocks+usedblocks); + printf("used %d (bit %d ninode %zu) free %u log %u total %d\n", usedblocks, + bitblocks, ninodes/IPB + 1, freeblock, nlog, nblocks+usedblocks+nlog); - assert(nblocks + usedblocks == size); + assert(nblocks + usedblocks + nlog == size); - for(i = 0; i < nblocks + usedblocks; i++) + for(i = 0; i < nblocks + usedblocks + nlog; i++) wsect(i, zeroes); - wsect(1, &sb); + memset(buf, 0, sizeof(buf)); + memmove(buf, &sb, sizeof(sb)); + wsect(1, buf); rootino = ialloc(T_DIR); assert(rootino == ROOTINO); @@ -173,7 +180,7 @@ winode(uint inum, struct dinode *ip) bn = i2b(inum); rsect(bn, buf); - dip = ((struct dinode*) buf) + (inum % IPB); + dip = ((struct dinode*)buf) + (inum % IPB); *dip = *ip; wsect(bn, buf); } @@ -187,7 +194,7 @@ rinode(uint inum, struct dinode *ip) bn = i2b(inum); rsect(bn, buf); - dip = ((struct dinode*) buf) + (inum % IPB); + dip = ((struct dinode*)buf) + (inum % IPB); *ip = *dip; } @@ -225,12 +232,12 @@ balloc(int used) int i; printf("balloc: first %d blocks have been allocated\n", used); - assert(used < 512); + assert(used < 512*8); bzero(buf, 512); - for(i = 0; i < used; i++) { + for(i = 0; i < used; i++){ buf[i/8] = buf[i/8] | (0x1 << (i%8)); } - printf("balloc: write bitmap block at sector %lu\n", ninodes/IPB + 3); + printf("balloc: write bitmap block at sector %zu\n", ninodes/IPB + 3); wsect(ninodes / IPB + 3, buf); } @@ -239,7 +246,7 @@ balloc(int used) void iappend(uint inum, void *xp, int n) { - char *p = (char*) xp; + char *p = (char*)xp; uint fbn, off, n1; struct dinode din; char buf[512]; @@ -252,24 +259,24 @@ iappend(uint inum, void *xp, int n) while(n > 0){ fbn = off / 512; assert(fbn < MAXFILE); - if(fbn < NDIRECT) { - if(xint(din.addrs[fbn]) == 0) { + if(fbn < NDIRECT){ + if(xint(din.addrs[fbn]) == 0){ din.addrs[fbn] = xint(freeblock++); usedblocks++; } x = xint(din.addrs[fbn]); } else { - if(xint(din.addrs[NDIRECT]) == 0) { + if(xint(din.addrs[NDIRECT]) == 0){ // printf("allocate indirect block\n"); din.addrs[NDIRECT] = xint(freeblock++); usedblocks++; } // printf("read indirect block\n"); - rsect(xint(din.addrs[NDIRECT]), (char*) indirect); - if(indirect[fbn - NDIRECT] == 0) { + rsect(xint(din.addrs[NDIRECT]), (char*)indirect); + if(indirect[fbn - NDIRECT] == 0){ indirect[fbn - NDIRECT] = xint(freeblock++); usedblocks++; - wsect(xint(din.addrs[NDIRECT]), (char*) indirect); + wsect(xint(din.addrs[NDIRECT]), (char*)indirect); } x = xint(indirect[fbn-NDIRECT]); } |