diff --git a/format/Makefile b/format/Makefile new file mode 100644 index 0000000..bd2b65b --- /dev/null +++ b/format/Makefile @@ -0,0 +1,50 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +#Linker +LD = ld + +#Binary File Name +BINARY = format + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = #../../lib/ubix/startup.o + +#CFLAGS +CFLAGS = -O + +#Includes +INCLUDES = -I../include + +LIBRARIES = #../../lib/libc_old/libc_old.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) +# strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) *.core diff --git a/format/main.c b/format/main.c new file mode 100644 index 0000000..c226f0f --- /dev/null +++ b/format/main.c @@ -0,0 +1,156 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +#include "ubixfs.h" + +static void usage() { + fprintf(stderr, "usage: format [-q] disk [slice]\n"); + exit (1); + } + +int main(int argc,char **argv) { + FILE *fd; + struct ubixDiskLabel *d = (struct ubixDiskLabel *)malloc(512); + int ch = 0x0; + int i = 0x0; + int x = 0x0; + short bat = 0x0; + u_int32_t blocks = 0x0; + u_int32_t batSect = 0x0; + char sector[512]; + char q = 0x0; + + while ((ch = getopt(argc, argv, "q")) != -1) { + switch (ch) { + case 'q': + q = 0x1; + break; + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) + usage(); + + printf("Ubix Disk Format Utility Version 1.0\n"); + printf("(c) 2004 Ubix Corp \n\n"); + + fd = fopen(argv[0],"rb+"); + + if (fd == NULL) { + fprintf(stderr,"Error: unable to open disk: %s\n",argv[0]); + exit(1); + } + + fseek(fd,512,0); + fread(d,512,1,fd); + if (d->magicNum != UBIX_LABEL_MAGIC || d->magicNum2 != UBIX_LABEL_MAGIC) { + fprintf(stderr, "Error: invalid disk label\n"); + exit(1); + } + + i = atoi(argv[1]) - 1; + if (i < 0) { + fprintf(stderr, "Error: invalid partition: %s\n",argv[1]); + exit(1); + } + + if (d->partitions[i].p_fstype != UBIX_UBIXFS_MAGIC) { + fprintf(stderr, "Error: not an ubix parition\n"); + exit(1); + } + + if (q == 0x0) { + memset(sector,0x0,512); + + if (fseek(fd,d->partitions[i].p_offset * 512,0x0) != 0x0) { + fprintf(stderr, "Error: fseek failed\n"); + exit(0x1); + } + + for (x = 1;x <= d->partitions[i].p_size;x++) { + if (fwrite(sector,512,1,fd) != 1) { + printf("Error: %i\n",x); + exit(0x1); + } + } + } + + blocks = (d->partitions[i].p_size - 1) / 8; + bat = (d->partitions[i].p_size - 1) % 8; + + while ((bat * 4096) < blocks) { + bat += 0x4; + blocks--; + } + + batSect = (d->partitions[i].p_offset + 1) + (blocks * 8); + + if (fseek(fd,d->partitions[i].p_offset * 512,0x0) != 0x0) { + fprintf(stderr, "Error: fseek failed\n"); + exit(0x1); + } + + /* write super block here */ + + /* Write BAT */ + if (fseek(fd,batSect * 512,0x0) != 0x0) { + fprintf(stderr, "Error: fseek failed\n"); + exit(0x1); + } + memset(sector,0x69,512); + fwrite(sector,512,1,fd); + + /* Print debug info */ + printf("batSect: [%i]\n",batSect); + printf("bat: [%i]\n",bat); + printf("d->partitions[%i].p_offset = %i\n",i,d->partitions[i].p_offset); + printf("d->partitions[%i].p_size = %i\n",i,d->partitions[i].p_size); + printf("d->partitions[%i].p_bsize = 0x%X\n",i,d->partitions[i].p_bsize); + + fclose(fd); + printf("Format Complete\n"); + + return(0); + } + +/*** + $Log$ + END + ***/ + diff --git a/include/ubixfs.h b/include/ubixfs.h index 5392c69..e2903c2 100644 --- a/include/ubixfs.h +++ b/include/ubixfs.h @@ -33,7 +33,9 @@ #define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */ #define MAXUBIXPARTITIONS 16 #define UBIXFSMAGIC ((uInt32)0x69) /* The File System Magic Number */ -#define UBIX_LABEL_MAGIC ((u_int32_t)0x69696969) /* Disk Label Magic Number */ +#define UBIX_LABEL_MAGIC ((u_int32_t)0x69696969) /* Disk Label Magic Number */ +#define UBIX_UBIXFS_MAGIC ((u_int8_t)0xAD) /* Ubix UBIXFS Magic Number */ +#define UBIX_SWAP_MAGIC ((u_int8_t)0xBC) /* Ubix Swap Magic Number */ struct ubixDiskLabel { u_int32_t magicNum; @@ -73,6 +75,9 @@ /*** $Log$ + Revision 1.2 2004/09/01 07:56:52 reddawg + disklabel: works enough to test with + Revision 1.1.1.1 2004/09/01 06:44:38 reddawg UbixOS Tool