diff --git a/fdisk/main.c b/fdisk/main.c index 2b61f6d..0312fe9 100644 --- a/fdisk/main.c +++ b/fdisk/main.c @@ -47,57 +47,73 @@ u_int32_t dp_size; /* partition size in sectors */ }; +static void usage() { + fprintf(stderr, "usage: fdisk [-B] drive [slice]\n"); + exit(0x1); + } + int main(int argc,char **argv) { FILE *fd; - FILE *mbr; struct dos_partition *d = 0x0; char *data = (char *)malloc(512); int i = 0x0; + int ch = 0x0; char buf[256]; d = (struct dos_partition *)(data + 0x1BE); + + while ((ch = getopt(argc, argv, "B")) != -1) { + switch (ch) { + case 'B': + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc < 1) + usage(); + printf("Ubix Disk Editor 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); + } - if (argc >= 2) { - printf("Drive Info (%s):\n",argv[1]); - fd = fopen(argv[1],"rb"); - } - else { - printf("Drive Info (ad0):\n"); - fd = fopen("devfs:ad0","rb"); - } - fseek(fd,0,0); + fread(data,512,1,fd); - if (argc >= 3) { - i = atoi(argv[2]); - if (i == 0) { - mbr = fopen("sys:mrb","rb"); - fseek(mbr,0,0); - fread(data,512,1,mbr); - printf("Installing Ubix MBR\n"); + if (argc >= 2) { + i = atoi(argv[1]) - 1; + if (i < 0) { + fprintf(stderr, "Error: invalid partition\n"); + exit(0x1); } - else { - i--; - printf("d[%i].dp_type = %i, ",i,d[i].dp_type); - printf("New Value: "); - gets((char *)&buf); - d[i].dp_type = atoi(buf); - printf("d[%i].dp_start: %i, ",i,d[i].dp_start); - printf("New Value: "); - gets((char *)&buf); - d[i].dp_start = atoi(buf); - printf("d[%i].dp_size: %i, ",i,d[i].dp_size); - printf("New Value: "); - gets((char *)&buf); - d[i].dp_size = atoi(buf); - printf("d[%i].dp_type: 0x%X\n",i,d[i].dp_type); - printf("d[%i].dp_start: %i\n",i,d[i].dp_start); - printf("d[%i].dp_size: %i\n",i,d[i].dp_size); - } + + printf("d[%i].dp_type = %i, ",i,d[i].dp_type); + printf("New Value: "); + fgets((char *)&buf,256,stdin); + d[i].dp_type = atoi(buf); + printf("d[%i].dp_start: %i, ",i,d[i].dp_start); + printf("New Value: "); + fgets((char *)&buf,256,stdin); + d[i].dp_start = atoi(buf); + printf("d[%i].dp_size: %i, ",i,d[i].dp_size); + printf("New Value: "); + fgets((char *)&buf,256,stdin); + d[i].dp_size = atoi(buf); + printf("d[%i].dp_type: 0x%X\n",i,d[i].dp_type); + printf("d[%i].dp_start: %i\n",i,d[i].dp_start); + printf("d[%i].dp_size: %i\n",i,d[i].dp_size); + fseek(fd,0,0); fwrite(data,512,1,fd); } @@ -118,6 +134,9 @@ /*** $Log$ + Revision 1.1.1.1 2004/09/01 06:44:38 reddawg + UbixOS Tool + Revision 1.9 2004/08/15 00:33:02 reddawg Wow the ide driver works again