home *** CD-ROM | disk | FTP | other *** search
- /* Program to "reformat" partitions on a fixed disk.
- * Written by Scott E. Garfinkle, Sep 1986. All rights reserved.
- *
- * This program will perform a "soft" reformat of a hard disk partition.
- * Note that this will only block out any sectors that cannot be read. It
- * does not attempt to fix them.
- *
- * Requires the following external .obj files: rdioctl, rdpart, part1, misc, init
- *
- * usage: pformat <d:>
- */
- #include "part.h"
- #include <dos.h>
- #include <errno.h>
- #include <ctype.h>
-
- static char *buf;
- word partno;
- extern byte fixed_disk; /* BIOS "address" of currently selected fixed disk */
- word sector_size; /* aka bytes per sector */
- word lineno; /* current screen line */
-
- extern int read_ioctl(char *buffer, word drive);
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- word i, csize, fat_size, temp;
- BPB *bptr, *pbptr;
- extern BOOT part_boot_rec[4]; /* boot record of each (active) logical partition */
-
- if(argc != 2) {
- fprintf(stderr,"Usage: pformat <drive:>\n");
- exit(1);
- /* NOTREACHED */
- }
- if((i = tolower(argv[1][0]) - 'a' + 1) < 4) {
- fprintf(stderr,"pformat: must use DOS format to format dos drives.\n");
- exit(2);
- /* NOTREACHED */
- }
- erase_eos(14);
- scr_pos(22,0);
- printf("Partition Reformatter, Copyright(C) 1986, 1988 S. E. Garfinkle.");
- scr_pos(23,0);
- printf("All rights reserved.");
- do {
- sector_size = get_scr_val(14,"Enter sector size (256,512,1024,etc.):",512,256,16*1024);
- } while (sector_size != 256 && (sector_size & 0x1ff));
- erase_eos(14);
- buf = malloc(sector_size);
- if((i=read_ioctl(buf, i)) < 0) {
- fprintf(stderr,"Illegal %s\n", i == -1 ? "ioctl function" :
- "Drive code");
- exit(2);
- }
- erase_eos(20);
- printf("If you proceed, you will completely erase drive %c.\n",argv[1][0]);
- i = get_scr_char(21,"Are you SURE you want to continue? (y/n)",'N','y');
- if(tolower(i) != 'y') {
- exit(3);
- /* NOTREACHED */
- }
- puts("\nReformatting...standby.");
- partno = *(word *)(buf+sizeof(BPB)+4);
- fixed_disk = partno >> 4 ? DISK1 : DISK0;
- init();
- partno &= 0xf;
- i = make_rdir(partno); /* returns number of sectors in root dir */
- if(!i || !make_fat(partno, ((BPB *)buf)->secs_in_fat, i)) {
- if(errno == ENOMEM) {
- puts("Not enough memory.");
- }
- else {
- puts("Error in creating FAT or root directory for partition.");
- }
- sleep(1000L);
- }
- erase_eos(0);
- scr_pos(10,0);
- printf("Drive %c is reformatted. You should now reboot.\n",argv[1][0]);
- }
-