diff --git a/format/main.c b/format/main.c index 0876009..5f7fb21 100644 --- a/format/main.c +++ b/format/main.c @@ -35,7 +35,7 @@ #include "ubixfs.h" #include "superblock.h" #include "inode.h" -#include "btree.h" +#include "btreeheader.h" static void usage() { fprintf(stderr, "usage: format [-q] disk [slice]\n"); @@ -75,7 +75,7 @@ printf("Ubix Disk Format Utility Version 1.0\n"); printf("(c) 2004 Ubix Corp \n\n"); - fd = fopen(argv[0],"rb+"); + fd = fopen(argv[0],"wb+"); if (fd == NULL) { fprintf(stderr,"Error: unable to open disk: %s\n",argv[0]); @@ -107,7 +107,7 @@ exit(0x1); } - for (x = 1;x <= d->partitions[i].p_size;x++) { + for (x = 1;x < d->partitions[i].p_size;x++) { if (fwrite(sector,512,1,fd) != 1) { printf("Error: %i\n",x); exit(0x1); @@ -115,6 +115,7 @@ } } + blocks = (d->partitions[i].p_size - 1) / 8; batSize = (d->partitions[i].p_size - 1) % 8; @@ -124,8 +125,10 @@ } batSect = (d->partitions[i].p_offset + (blocks * 8)); + /* write super block here */ - if (fseek(fd,d->partitions[i].p_offset + (d->partitions[i].p_size - 1),SEEK_SET) != 0x0) { + rewind(fd); + if (fseek(fd,((d->partitions[i].p_offset + d->partitions[i].p_size - 1) * 512),SEEK_SET) != 0x0) { fprintf(stderr, "Error: fseek failed for super block\n"); exit(0x1); } @@ -161,7 +164,10 @@ sb->rootDir.start = 0; sb->rootDir.len = 1; - fwrite(sb, 512, 1, fd); + if (fwrite(sb, 512, 1, fd) != 0x1) { + fprintf(stderr, "Error: Could not write out super block\n"); + exit(0x1); + } // write out the root dir @@ -181,8 +187,20 @@ exit(0x1); } - memset(sector, 0 ,512); - fwrite(sector, 512, batSize, fd); + memset(sector, 0x0 ,512); + sector[0] = 0x80; + if (fwrite(sector,512,1,fd) != 1) { + fprintf(stderr, "Error: %i\n",x); + exit(0x1); + } + + sector[0] = 0x0; + for (x = 1;x < batSize;x++) { + if (fwrite(sector,512,1,fd) != 1) { + fprintf(stderr, "Error: %i\n",x); + exit(0x1); + } + } /* Print debug info */ printf("blocks: [%i]\n",blocks); @@ -203,6 +221,9 @@ /*** $Log$ + Revision 1.10 2004/09/06 17:52:49 flameshadow + add: UBIX_MAGIC numbers for the superblock + Revision 1.9 2004/09/06 16:44:21 flameshadow chg: changed the pointers in include/inode.h to be void * add: wrote out root dir in the format utility