diff options
-rw-r--r-- | sbin/fdisk/cmd.c | 84 | ||||
-rw-r--r-- | sbin/fdisk/disk.c | 45 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 117 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 34 | ||||
-rw-r--r-- | sbin/fdisk/misc.c | 15 | ||||
-rw-r--r-- | sbin/fdisk/part.c | 18 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 47 |
7 files changed, 180 insertions, 180 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 0cc388cfe7f..88fec138619 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.9 1997/10/19 23:13:48 deraadt Exp $ */ +/* $OpenBSD: cmd.c,v 1.10 1997/10/19 23:29:35 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -83,7 +83,7 @@ Xreinit(cmd, disk, mbr, tt, offset) printf("In memory copy is initialized.\n"); printf("Use 'write' to update disk.\n"); - return(CMD_DIRTY); + return (CMD_DIRTY); } int @@ -99,7 +99,7 @@ Xdisk(cmd, disk, mbr, tt, offset) DISK_printmetrics(disk); /* Ask for new info */ - if(ask_yn("Change disk geometry?")){ + if (ask_yn("Change disk geometry?")) { disk->real->cylinders = ask_num("BIOS Cylinders", ASK_DEC, disk->real->cylinders, 1, 1024, NULL); disk->real->heads = ask_num("BIOS Heads", ASK_DEC, @@ -111,7 +111,7 @@ Xdisk(cmd, disk, mbr, tt, offset) * disk->real->sectors; } - return(CMD_CONT); + return (CMD_CONT); } int @@ -127,13 +127,13 @@ Xedit(cmd, disk, mbr, tt, offset) ret = CMD_CONT; - if(!isdigit(cmd->args[0])){ + if (!isdigit(cmd->args[0])) { printf("Invalid argument: %s <partition number>\n", cmd->cmd); return (ret); } pn = atoi(cmd->args); - if(pn < 0 || pn > 3){ + if (pn < 0 || pn > 3) { printf("Invalid partition number.\n"); return (ret); } @@ -152,14 +152,14 @@ Xedit(cmd, disk, mbr, tt, offset) EDIT("Partition id", ASK_HEX, pp->id, 0, 0xFF, PRT_printall); /* Unused, so just zero out */ - if(pp->id == DOSPTYP_UNUSED){ + if (pp->id == DOSPTYP_UNUSED) { memset(pp, 0, sizeof(*pp)); printf("Partiton %d cleared.\n", pn); - return(ret); + return (ret); } /* Change table entry */ - if(ask_yn("Do you wish to edit in CHS mode?")){ + if (ask_yn("Do you wish to edit in CHS mode?")) { int maxcyl, maxhead, maxsect; /* Shorter */ @@ -176,8 +176,9 @@ Xedit(cmd, disk, mbr, tt, offset) EDIT("BIOS Ending sector", ASK_DEC, pp->esect, 1, maxsect, NULL); /* Fix up off/size values */ PRT_fix_BN(disk, pp); - }else{ + } else { u_int m; + /* Get data */ EDIT("Partition offset", ASK_DEC, pp->bs, 0, disk->real->size, NULL); @@ -189,7 +190,7 @@ Xedit(cmd, disk, mbr, tt, offset) PRT_fix_CHS(disk, pp); } #undef EDIT - return(ret); + return (ret); } int @@ -203,31 +204,30 @@ Xselect(cmd, disk, mbr, tt, offset) int off; int pn; - if(!isdigit(cmd->args[0])){ + if (!isdigit(cmd->args[0])) { printf("Invalid argument: %s <partition number>\n", cmd->cmd); - return(CMD_CONT); + return (CMD_CONT); } pn = atoi(cmd->args); off = mbr->part[pn].bs; /* Sanity checks */ - if(mbr->part[pn].id != DOSPTYP_EXTEND){ + if (mbr->part[pn].id != DOSPTYP_EXTEND) { printf("Partition %d is not an extended partition.\n", pn); - return(CMD_CONT); + return (CMD_CONT); } - if(!off){ + if (!off) { printf("Loop to offset 0! Not selected.\n"); - return(CMD_CONT); - }else{ + return (CMD_CONT); + } else { printf("Selected extended partition %d\n", pn); printf("New MBR at offset %d.\n", off); } /* Recursion is beautifull! */ USER_modify(disk, tt, off); - - return(CMD_CONT); + return (CMD_CONT); } int @@ -243,7 +243,7 @@ Xprint(cmd, disk, mbr, tt, offset) printf("Offset: %d\t", offset); MBR_print(mbr); - return(CMD_CONT); + return (CMD_CONT); } int @@ -263,7 +263,7 @@ Xwrite(cmd, disk, mbr, tt, offset) MBR_make(mbr, mbr_buf); MBR_write(fd, offset, mbr_buf); close(fd); - return(CMD_CLEAN); + return (CMD_CLEAN); } int @@ -276,7 +276,7 @@ Xexit(cmd, disk, r, tt, offset) { /* Nothing to do here */ - return(CMD_SAVE); + return (CMD_SAVE); } int @@ -290,7 +290,7 @@ Xabort(cmd, disk, mbr, tt, offset) exit(0); /* NOTREACHED */ - return(CMD_CONT); + return (CMD_CONT); } @@ -304,7 +304,7 @@ Xquit(cmd, disk, mbr, tt, offset) { /* Nothing to do here */ - return(CMD_EXIT); + return (CMD_EXIT); } int @@ -319,11 +319,9 @@ Xhelp(cmd, disk, mbr, tt, offset) int i; /* Hmm, print out cmd_table here... */ - for(i = 0; cmd_table[i].cmd != NULL; i++){ + for (i = 0; cmd_table[i].cmd != NULL; i++) printf("\t%s\t\t%s\n", cmd_table[i].cmd, cmd_table[i].help); - } - - return(CMD_CONT); + return (CMD_CONT); } int @@ -337,10 +335,8 @@ Xupdate(cmd, disk, mbr, tt, offset) /* Update code */ memcpy(mbr->code, tt->code, MBR_CODE_SIZE); - printf("Machine code updated.\n"); - - return(CMD_DIRTY); + return (CMD_DIRTY); } int @@ -354,26 +350,27 @@ Xflag(cmd, disk, mbr, tt, offset) int i, pn = -1; /* Parse partition table entry number */ - if(!isdigit(cmd->args[0])){ + if (!isdigit(cmd->args[0])) { printf("Invalid argument: %s <partition number>\n", cmd->cmd); - return(CMD_CONT); + return (CMD_CONT); } pn = atoi(cmd->args); - if(pn < 0 || pn > 3){ + if (pn < 0 || pn > 3) { printf("Invalid partition number.\n"); - return(CMD_CONT); + return (CMD_CONT); } /* Set active flag */ - for(i = 0; i < 4; i++){ - if(i == pn) mbr->part[i].flag = DOSACTIVE; - else mbr->part[i].flag = 0x00; + for (i = 0; i < 4; i++) { + if (i == pn) + mbr->part[i].flag = DOSACTIVE; + else + mbr->part[i].flag = 0x00; } printf("Partition %d marked active.\n", pn); - - return(CMD_DIRTY); + return (CMD_DIRTY); } int @@ -384,10 +381,13 @@ Xmanual(cmd, disk, mbr, tt, offset) mbr_t *tt; int offset; { + char *pager = "/usr/bin/less"; extern char manpage[]; FILE *f; - f = popen("/usr/bin/less", "w"); + if (getenv("PAGER")) + pager = getenv("PAGER"); + f = popen(pager, "w"); if (f) { (void) fwrite(manpage, strlen(manpage), 1, f); pclose(f); diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c index 0fcced3170a..7c3a9b2b962 100644 --- a/sbin/fdisk/disk.c +++ b/sbin/fdisk/disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.c,v 1.4 1997/10/16 01:47:09 deraadt Exp $ */ +/* $OpenBSD: disk.c,v 1.5 1997/10/19 23:29:36 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -48,7 +48,6 @@ #endif #include "disk.h" - int DISK_open(disk, mode) char *disk; @@ -58,12 +57,12 @@ DISK_open(disk, mode) struct stat st; fd = opendev(disk, mode, OPENDEV_PART, NULL); - if(fd < 0) err(1, "%s", disk); - if(fstat(fd, &st) < 0) err(1, "%s", disk); - - if(!S_ISCHR(st.st_mode) && !S_ISREG(st.st_mode)) + if (fd < 0) + err(1, "%s", disk); + if (fstat(fd, &st) < 0) + err(1, "%s", disk); + if (!S_ISCHR(st.st_mode) && !S_ISREG(st.st_mode)) err(1, "%s is not a character device or a regular file", disk); - return(fd); } @@ -89,14 +88,14 @@ DISK_getlabelmetrics(name) int fd; /* Get label metrics */ - if((fd = DISK_open(name, O_RDONLY)) >= 0){ + if ((fd = DISK_open(name, O_RDONLY)) >= 0) { lm = malloc(sizeof(DISK_metrics)); - if(ioctl(fd, DIOCGDINFO, &dl) < 0){ + if (ioctl(fd, DIOCGDINFO, &dl) < 0) { warn("DIOCGDINFO"); free(lm); lm = NULL; - }else{ + } else { lm->cylinders = dl.d_ncylinders; lm->heads = dl.d_ntracks; lm->sectors = dl.d_nsectors; @@ -131,7 +130,7 @@ DISK_getbiosmetrics(name) mib[2] = BIOS_DEV; size = sizeof(biosdev); - if(sysctl(mib, 3, &biosdev, &size, NULL, 0) < 0){ + if (sysctl(mib, 3, &biosdev, &size, NULL, 0) < 0) { warn("sysctl"); return (NULL); } @@ -139,7 +138,7 @@ DISK_getbiosmetrics(name) mib[2] = BIOS_GEOMETRY; size = sizeof(biosgeo); - if(sysctl(mib, 3, &biosgeo, &size, NULL, 0) < 0){ + if (sysctl(mib, 3, &biosgeo, &size, NULL, 0) < 0) { warn("sysctl"); return (NULL); } @@ -184,18 +183,18 @@ DISK_getmetrics(disk, user) disk->bios = DISK_getbiosmetrics(disk->name); /* If user supplied, use that */ - if(user){ + if (user) { disk->real = user; - return(0); + return (0); } /* If we have a label, use that */ - if(!disk->real && disk->label) + if (!disk->real && disk->label) disk->real = disk->label; /* Can not get geometry, punt */ - if(disk->real == NULL) - return(1); + if (disk->real == NULL) + return (1); /* If we have a bios, use that (if label looks bogus) * @@ -204,12 +203,12 @@ DISK_getmetrics(disk, user) * It needs to be, at least, a BSD device. * Or we need a mapping from biosdev -> BSD universe. */ - if(disk->bios) - if(disk->real->cylinders > 1024 || disk->real->heads > 255 - || disk->real->sectors > 63) + if (disk->bios) + if (disk->real->cylinders > 1024 || disk->real->heads > 255 || + disk->real->sectors > 63) disk->real = disk->bios; - return(0); + return (0); } int @@ -218,9 +217,9 @@ DISK_printmetrics(disk) { printf("Disk: %s\t", disk->name); - if(disk->real) + if (disk->real) printf("geometry: %d/%d/%d [%d sectors]\n", disk->real->cylinders, - disk->real->heads, disk->real->sectors, disk->real->size); + disk->real->heads, disk->real->sectors, disk->real->size); else printf("geometry: <none>\n"); diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index a2a931a22dd..6390dda337a 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.25 1997/10/16 01:47:10 deraadt Exp $ */ +/* $OpenBSD: fdisk.c,v 1.26 1997/10/19 23:29:36 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -49,13 +49,13 @@ usage() { extern char * __progname; fprintf(stderr, "usage: %s " - "[-ie] [-f mbrboot] [-c cyl -h head -s sect] disk\n" - "\t-i: initialize disk with virgin MBR\n" - "\t-e: edit MBRs on disk interactively\n" - "\t-f: specify non-standard MBR template\n" - "\t-chs: specify disk geometry\n" - "`disk' may be of the forms: sd0 or /dev/rsd0c.\n", - __progname); + "[-ie] [-f mbrboot] [-c cyl -h head -s sect] disk\n" + "\t-i: initialize disk with virgin MBR\n" + "\t-e: edit MBRs on disk interactively\n" + "\t-f: specify non-standard MBR template\n" + "\t-chs: specify disk geometry\n" + "`disk' may be of the forms: sd0 or /dev/rsd0c.\n", + __progname); exit(1); } @@ -74,72 +74,72 @@ main(argc, argv) mbr_t mbr; char mbr_buf[DEV_BSIZE]; - while((ch = getopt(argc, argv, "ief:c:h:s:")) != -1){ - switch(ch){ - case 'i': - i_flag = 1; - break; - - case 'e': - m_flag = 1; - break; - - case 'f': - mbrfile = optarg; - break; - - case 'c': - c_arg = atoi(optarg); - if(c_arg < 0 || c_arg > 1023) - errx(1, "Cylinder argument out of range."); - break; - - case 'h': - h_arg = atoi(optarg); - if(h_arg < 0 || h_arg > 255) - errx(1, "Head argument out of range."); - break; - - case 's': - s_arg = atoi(optarg); - if(s_arg < 1 || s_arg > 63) - errx(1, "Sector argument out of range."); - break; - - default: - usage(); + while ((ch = getopt(argc, argv, "ief:c:h:s:")) != -1) { + switch(ch) { + case 'i': + i_flag = 1; + break; + case 'e': + m_flag = 1; + break; + case 'f': + mbrfile = optarg; + break; + case 'c': + c_arg = atoi(optarg); + if (c_arg < 0 || c_arg > 1023) + errx(1, "Cylinder argument out of range."); + break; + case 'h': + h_arg = atoi(optarg); + if (h_arg < 0 || h_arg > 255) + errx(1, "Head argument out of range."); + break; + case 's': + s_arg = atoi(optarg); + if (s_arg < 1 || s_arg > 63) + errx(1, "Sector argument out of range."); + break; + default: + usage(); } } argc -= optind; argv += optind; /* Argument checking */ - if(argc != 1) + if (argc != 1) usage(); else disk.name = argv[0]; /* Put in supplied geometry if there */ - if(c_arg | h_arg | s_arg){ + if (c_arg | h_arg | s_arg) { usermetrics = malloc(sizeof(DISK_metrics)); - if(usermetrics != NULL){ - if(c_arg) usermetrics->cylinders = c_arg; - else errx(1, "Please specify a full geometry with [-chs]."); - if(h_arg) usermetrics->heads = h_arg; - else errx(1, "Please specify a full geometry with [-chs]."); - if(s_arg) usermetrics->sectors = s_arg; - else errx(1, "Please specify a full geometry with [-chs]."); + if (usermetrics != NULL) { + if (c_arg) + usermetrics->cylinders = c_arg; + else + errx(1, "Please specify a full geometry with [-chs]."); + if (h_arg) + usermetrics->heads = h_arg; + else + errx(1, "Please specify a full geometry with [-chs]."); + if (s_arg) + usermetrics->sectors = s_arg; + else + errx(1, "Please specify a full geometry with [-chs]."); } usermetrics->size = c_arg * h_arg * s_arg; - }else + } else usermetrics = NULL; /* Get the geometry */ - if(DISK_getmetrics(&disk, usermetrics)) + if (DISK_getmetrics(&disk, usermetrics)) errx(1, "Can't get disk geometry, please use [-chs] to specify."); /* Parse mbr template, to pass on later */ - if((fd = open(mbrfile, O_RDONLY)) < 0) + if ((fd = open(mbrfile, O_RDONLY)) < 0) err(1, "open mbr file"); MBR_read(fd, 0, mbr_buf); close(fd); @@ -147,19 +147,18 @@ main(argc, argv) /* Print out current MBRs on disk */ - if((i_flag + m_flag) == 0) + if ((i_flag + m_flag) == 0) exit(USER_print_disk(&disk)); /* Punt if no i or m */ - if((i_flag + m_flag) != 1) + if ((i_flag + m_flag) != 1) usage(); - /* Now do what we are supposed to */ - if(i_flag) + if (i_flag) USER_init(&disk, &mbr); - if(m_flag) + if (m_flag) USER_modify(&disk, &mbr, 0); return(0); diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index f46748999b3..a5adefd79b6 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.3 1997/10/16 01:47:11 deraadt Exp $ */ +/* $OpenBSD: mbr.c,v 1.4 1997/10/19 23:29:37 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -58,8 +58,9 @@ MBR_parse(mbr_buf, mbr) mbr->spare = getshort(&mbr_buf[MBR_SPARE_OFF]); mbr->signature = getshort(&mbr_buf[MBR_SIG_OFF]); - for(i = 0; i < NDOSPART; i++) - PRT_parse(&mbr_buf[MBR_PART_OFF + MBR_PART_SIZE * i], &mbr->part[i]); + for (i = 0; i < NDOSPART; i++) + PRT_parse(&mbr_buf[MBR_PART_OFF + MBR_PART_SIZE * i], + &mbr->part[i]); } void @@ -74,8 +75,9 @@ MBR_make(mbr, mbr_buf) putshort(&mbr_buf[MBR_SPARE_OFF], mbr->spare); putshort(&mbr_buf[MBR_SIG_OFF], mbr->signature); - for(i = 0; i < NDOSPART; i++) - PRT_make(&mbr->part[i], &mbr_buf[MBR_PART_OFF + MBR_PART_SIZE * i]); + for (i = 0; i < NDOSPART; i++) + PRT_make(&mbr->part[i], &mbr_buf[MBR_PART_OFF + + MBR_PART_SIZE * i]); } void @@ -86,13 +88,12 @@ MBR_print(mbr) /* Header */ printf("Signatures: 0x%X,0x%X\n", - (int)mbr->signature, (int)mbr->nt_serial); + (int)mbr->signature, (int)mbr->nt_serial); PRT_print(0, NULL); /* Entries */ - for(i = 0; i < NDOSPART; i++){ + for (i = 0; i < NDOSPART; i++) PRT_print(i, &mbr->part[i]); - } } int @@ -106,11 +107,11 @@ MBR_read(fd, where, buf) where *= DEV_BSIZE; off = lseek(fd, where, SEEK_SET); - if(off != where) return(off); - + if (off != where) + return(off); len = read(fd, buf, DEV_BSIZE); - if(len != DEV_BSIZE) return(len); - + if (len != DEV_BSIZE) + return(len); return(0); } @@ -125,11 +126,10 @@ MBR_write(fd, where, buf) where *= DEV_BSIZE; off = lseek(fd, where, SEEK_SET); - if(off != where) return(off); - + if (off != where) + return(off); len = write(fd, buf, DEV_BSIZE); - if(len != DEV_BSIZE) return(len); - + if (len != DEV_BSIZE) + return(len); return(0); } - diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index a101986eda0..381ae4910ef 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.4 1997/10/16 02:29:54 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.5 1997/10/19 23:29:37 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -46,7 +46,7 @@ ask_cmd(cmd) char lbuf[100], *cp, *buf; /* Get input */ - if(fgets(lbuf, sizeof lbuf, stdin) == NULL) + if (fgets(lbuf, sizeof lbuf, stdin) == NULL) errx(1, "eof"); lbuf[strlen(lbuf)-1] = '\0'; @@ -59,7 +59,7 @@ ask_cmd(cmd) buf = &cp[strspn(cp, " \t")]; strncpy(cmd->args, buf, 100); - return(0); + return (0); } int @@ -124,10 +124,10 @@ ask_yn(str) while (ch != '\n' && ch != EOF) ch = getchar(); - if(ch == EOF || first == EOF) + if (ch == EOF || first == EOF) errx(1, "eof"); - return(first == 'y' || first == 'Y'); + return (first == 'y' || first == 'Y'); } u_int16_t @@ -136,7 +136,7 @@ getshort(p) { unsigned char *cp = p; - return cp[0] | (cp[1] << 8); + return (cp[0] | (cp[1] << 8)); } void @@ -156,7 +156,7 @@ getlong(p) { unsigned char *cp = p; - return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24); + return (cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24)); } void @@ -171,4 +171,3 @@ putlong(p, l) *cp++ = l >> 16; *cp++ = l >> 24; } - diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index c45bc3c5f70..5be6f642254 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.5 1997/10/16 01:53:08 deraadt Exp $ */ +/* $OpenBSD: part.c,v 1.6 1997/10/19 23:29:38 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -102,7 +102,7 @@ PRT_printall() int i; printf("Choose from the following Partition id values:\n"); - for(i = 0; i < sizeof(part_types)/sizeof(struct part_type); i++) { + for (i = 0; i < sizeof(part_types)/sizeof(struct part_type); i++) { printf("%02X %s%s", part_types[i].type, part_types[i].sname, (i+1) % 4 ? " " : "\n"); } @@ -117,12 +117,12 @@ PRT_ascii_id(id) static char unknown[] = "<Unknown ID>"; int i; - for(i = 0; i < sizeof(part_types)/sizeof(struct part_type); i++){ - if(part_types[i].type == id) - return(part_types[i].sname); + for (i = 0; i < sizeof(part_types)/sizeof(struct part_type); i++) { + if (part_types[i].type == id) + return (part_types[i].sname); } - return(unknown); + return (unknown); } void @@ -176,11 +176,11 @@ PRT_print(num, partn) prt_t *partn; { - if(partn == NULL){ + if (partn == NULL) { printf(" Starting Ending\n"); printf(" #: id cyl hd sec - cyl hd sec [ start - size]\n"); printf("-------------------------------------------------------------------------\n"); - }else{ + } else { printf("%c%1d: %.2X %4d %3d %3d - %4d %3d %3d [%10d - %10d] %s\n", (partn->flag == 0x80)?'*':' ', num, partn->id, @@ -214,7 +214,7 @@ PRT_fix_BN(disk, part) end += part->esect - 1; /* XXX - Should handle this... */ - if(start > end) + if (start > end) warn("Start of partition after end!"); part->bs = start; diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 5c580ed1250..60eb7da2cbe 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.9 1997/10/17 08:07:15 deraadt Exp $ */ +/* $OpenBSD: user.c,v 1.10 1997/10/19 23:29:38 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -100,7 +100,7 @@ USER_init(disk, tt) "\t-----------------------------------------------------\n" "\t------ ATTENTION - UPDATING MASTER BOOT RECORD ------\n" "\t-----------------------------------------------------\n"); - if(ask_yn("\nDo you wish to write new MBR?")){ + if (ask_yn("\nDo you wish to write new MBR?")) { fd = DISK_open(disk->name, O_RDWR); MBR_make(tt, mbr_buf); MBR_write(fd, (off_t)0, mbr_buf); @@ -108,7 +108,7 @@ USER_init(disk, tt) } else printf("MBR is unchanged\n"); - return(0); + return (0); } int modified; @@ -125,7 +125,6 @@ USER_modify(disk, tt, offset) cmd_t cmd; int i, st, fd; - /* One level deeper */ editlevel += 1; @@ -151,47 +150,51 @@ again: if (cmd.cmd[0] == '\0') goto again; - for(i = 0; cmd_table[i].cmd != NULL; i++) - if(strstr(cmd_table[i].cmd, cmd.cmd)==cmd_table[i].cmd) + for (i = 0; cmd_table[i].cmd != NULL; i++) + if (strstr(cmd_table[i].cmd, cmd.cmd)==cmd_table[i].cmd) break; /* Quick hack to put in '?' == 'help' */ - if(!strcmp(cmd.cmd, "?")) + if (!strcmp(cmd.cmd, "?")) i = 0; /* Check for valid command */ - if(cmd_table[i].cmd == NULL){ + if (cmd_table[i].cmd == NULL) { printf("Invalid command '%s'. Try 'help'.\n", cmd.cmd); continue; - }else + } else strcpy(cmd.cmd, cmd_table[i].cmd); /* Call function */ st = cmd_table[i].fcn(&cmd, disk, &mbr, tt, offset); /* Update status */ - if(st == CMD_EXIT) break; - if(st == CMD_SAVE) break; - if(st == CMD_CLEAN) modified = 0; - if(st == CMD_DIRTY) modified = 1; - } while(1); + if (st == CMD_EXIT) + break; + if (st == CMD_SAVE) + break; + if (st == CMD_CLEAN) + modified = 0; + if (st == CMD_DIRTY) + modified = 1; + } while (1); /* Write out MBR */ - if(modified){ - if(st == CMD_SAVE){ + if (modified) { + if (st == CMD_SAVE) { printf("Writing current MBR to disk.\n"); fd = DISK_open(disk->name, O_RDWR); MBR_make(&mbr, mbr_buf); MBR_write(fd, offset, mbr_buf); close(fd); - }else + } else printf("Aborting changes to current MBR.\n"); } /* One level less */ editlevel -= 1; - return(0); + return (0); } int @@ -215,11 +218,11 @@ USER_print_disk(disk) MBR_print(&mbr); /* Print out extended partitions too */ - for(offset = i = 0; i < 4; i++) - if(mbr.part[i].id == DOSPTYP_EXTEND) + for (offset = i = 0; i < 4; i++) + if (mbr.part[i].id == DOSPTYP_EXTEND) offset = mbr.part[i].bs; - } while(offset); + } while (offset); - return(DISK_close(fd)); + return (DISK_close(fd)); } |