summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorrtm <rtm>2006-07-21 22:10:40 +0000
committerrtm <rtm>2006-07-21 22:10:40 +0000
commit9d3fb6714181f44300a0a5431279841427e4ef06 (patch)
treeb201602d7ff5e1a9ce51554bdf8c417f7caaa192 /mkfs.c
parent11a9947f1a68e23001690955d8d0975ad4d6cf0c (diff)
downloadxv6-labs-9d3fb6714181f44300a0a5431279841427e4ef06.tar.gz
xv6-labs-9d3fb6714181f44300a0a5431279841427e4ef06.tar.bz2
xv6-labs-9d3fb6714181f44300a0a5431279841427e4ef06.zip
namei
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/mkfs.c b/mkfs.c
index 033e064..9dcb29c 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -24,7 +24,7 @@ ushort
xshort(ushort x)
{
ushort y;
- uchar *a = &y;
+ uchar *a = (uchar *) &y;
a[0] = x;
a[1] = x >> 8;
return y;
@@ -34,7 +34,7 @@ uint
xint(uint x)
{
uint y;
- uchar *a = &y;
+ uchar *a = (uchar *) &y;
a[0] = x;
a[1] = x >> 8;
a[2] = x >> 16;
@@ -47,16 +47,21 @@ main(int argc, char *argv[])
int i;
struct dinode din;
char dbuf[512];
+ uint bn;
if(argc != 2){
fprintf(stderr, "Usage: mkfs fs.img\n");
exit(1);
}
- if(sizeof(struct dinode) * IPB != 512){
+ if((512 % sizeof(struct dinode)) != 0){
fprintf(stderr, "sizeof(dinode) must divide 512\n");
exit(1);
}
+ if((512 % sizeof(struct dirent)) != 0){
+ fprintf(stderr, "sizeof(dirent) must divide 512\n");
+ exit(1);
+ }
fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666);
if(fd < 0){
@@ -78,7 +83,8 @@ main(int argc, char *argv[])
din.type = xshort(T_DIR);
din.nlink = xshort(2);
din.size = xint(512);
- din.addrs[0] = xint(freeblock++);
+ bn = freeblock++;
+ din.addrs[0] = xint(bn);
winode(1, &din);
bzero(dbuf, sizeof(dbuf));
@@ -86,7 +92,7 @@ main(int argc, char *argv[])
strcpy(((struct dirent *) dbuf)[0].name, ".");
((struct dirent *) dbuf)[1].inum = xshort(1);
strcpy(((struct dirent *) dbuf)[1].name, "..");
- wsect(din.addrs[0], dbuf);
+ wsect(bn, dbuf);
exit(0);
}