diff options
Diffstat (limited to 'sbin/disklabel/disklabel.c')
-rw-r--r-- | sbin/disklabel/disklabel.c | 108 |
1 files changed, 75 insertions, 33 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 43d5ca4..d3337c1 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -51,12 +51,16 @@ static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 1/7/94"; #include <sys/file.h> #include <sys/ioctl.h> #include <sys/stat.h> +#include <sys/wait.h> #define DKTYPENAMES #include <sys/disklabel.h> #include <ufs/ffs/fs.h> #include <unistd.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <stdarg.h> #include <ctype.h> #include "pathnames.h" @@ -89,6 +93,24 @@ static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 1/7/94"; #endif #endif +void makelabel __P((char *, char *, struct disklabel *)); +int writelabel __P((int, char *, struct disklabel *)); +void l_perror __P((char *)); +struct disklabel * readlabel __P((int)); +struct disklabel * makebootarea __P((char *, struct disklabel *, int)); +void display __P((FILE *, struct disklabel *)); +int edit __P((struct disklabel *, int)); +int editit __P((void)); +char * skip __P((char *)); +char * word __P((char *)); +int getasciilabel __P((FILE *, struct disklabel *)); +int checklabel __P((struct disklabel *)); +void setbootflag __P((struct disklabel *)); +void Warning (char *, ...); +void Perror __P((char *)); +void usage __P((void)); +extern u_short dkcksum __P((struct disklabel *)); + #define DEFEDITOR _PATH_VI #define streq(a,b) (strcmp(a,b) == 0) @@ -125,7 +147,7 @@ int debug; #define OPTIONS "BNRWb:ers:w" #endif - +int main(argc, argv) int argc; char *argv[]; @@ -308,14 +330,14 @@ main(argc, argv) * effect, set the names of the primary and secondary boot files * if specified. */ +void makelabel(type, name, lp) char *type, *name; register struct disklabel *lp; { register struct disklabel *dp; char *strcpy(); - - dp = getdiskbyname(type); + dp = getdiskbyname(type); if (dp == NULL) { fprintf(stderr, "%s: unknown disk type\n", type); exit(1); @@ -354,12 +376,15 @@ makelabel(type, name, lp) (void)strncpy(lp->d_packname, name, sizeof(lp->d_packname)); } +int writelabel(f, boot, lp) int f; char *boot; register struct disklabel *lp; { +#ifdef vax register int i; +#endif int flag; setbootflag(lp); @@ -428,6 +453,7 @@ writelabel(f, boot, lp) return (0); } +void l_perror(s) char *s; { @@ -514,8 +540,10 @@ makebootarea(boot, dp, f) int b; #if NUMBOOT > 0 char *dkbasename; +#if NUMBOOT == 1 struct stat sb; #endif +#endif /* XXX */ if (dp->d_secsize == 0) { @@ -602,7 +630,8 @@ makebootarea(boot, dp, f) b = open(bootxx, O_RDONLY); if (b < 0) Perror(bootxx); - if (read(b, &boot[dp->d_secsize], (int)(dp->d_bbsize-dp->d_secsize)) < 0) + if (read(b, &boot[dp->d_secsize], + (int)(dp->d_bbsize-dp->d_secsize)) < 0) Perror(bootxx); #else if (read(b, boot, (int)dp->d_bbsize) < 0) @@ -636,6 +665,7 @@ makebootarea(boot, dp, f) return (lp); } +void display(f, lp) FILE *f; register struct disklabel *lp; @@ -648,8 +678,10 @@ display(f, lp) fprintf(f, "type: %s\n", dktypenames[lp->d_type]); else fprintf(f, "type: %d\n", lp->d_type); - fprintf(f, "disk: %.*s\n", sizeof(lp->d_typename), lp->d_typename); - fprintf(f, "label: %.*s\n", sizeof(lp->d_packname), lp->d_packname); + fprintf(f, "disk: %.*s\n", (int)sizeof(lp->d_typename), + lp->d_typename); + fprintf(f, "label: %.*s\n", (int)sizeof(lp->d_packname), + lp->d_packname); fprintf(f, "flags:"); if (lp->d_flags & D_REMOVABLE) fprintf(f, " removeable"); @@ -658,18 +690,19 @@ display(f, lp) if (lp->d_flags & D_BADSECT) fprintf(f, " badsect"); fprintf(f, "\n"); - fprintf(f, "bytes/sector: %d\n", lp->d_secsize); - fprintf(f, "sectors/track: %d\n", lp->d_nsectors); - fprintf(f, "tracks/cylinder: %d\n", lp->d_ntracks); - fprintf(f, "sectors/cylinder: %d\n", lp->d_secpercyl); - fprintf(f, "cylinders: %d\n", lp->d_ncylinders); - fprintf(f, "sectors/unit: %d\n", lp->d_secperunit); + fprintf(f, "bytes/sector: %ld\n", lp->d_secsize); + fprintf(f, "sectors/track: %ld\n", lp->d_nsectors); + fprintf(f, "tracks/cylinder: %ld\n", lp->d_ntracks); + fprintf(f, "sectors/cylinder: %ld\n", lp->d_secpercyl); + fprintf(f, "cylinders: %ld\n", lp->d_ncylinders); + fprintf(f, "sectors/unit: %ld\n", lp->d_secperunit); fprintf(f, "rpm: %d\n", lp->d_rpm); fprintf(f, "interleave: %d\n", lp->d_interleave); fprintf(f, "trackskew: %d\n", lp->d_trackskew); fprintf(f, "cylinderskew: %d\n", lp->d_cylskew); - fprintf(f, "headswitch: %d\t\t# milliseconds\n", lp->d_headswitch); - fprintf(f, "track-to-track seek: %d\t# milliseconds\n", lp->d_trkseek); + fprintf(f, "headswitch: %ld\t\t# milliseconds\n", lp->d_headswitch); + fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", + lp->d_trkseek); fprintf(f, "drivedata: "); for (i = NDDATA - 1; i >= 0; i--) if (lp->d_drivedata[i]) @@ -677,14 +710,14 @@ display(f, lp) if (i < 0) i = 0; for (j = 0; j <= i; j++) - fprintf(f, "%d ", lp->d_drivedata[j]); + fprintf(f, "%ld ", lp->d_drivedata[j]); fprintf(f, "\n\n%d partitions:\n", lp->d_npartitions); fprintf(f, "# size offset fstype [fsize bsize bps/cpg]\n"); pp = lp->d_partitions; for (i = 0; i < lp->d_npartitions; i++, pp++) { if (pp->p_size) { - fprintf(f, " %c: %8d %8d ", 'a' + i, + fprintf(f, " %c: %8ld %8ld ", 'a' + i, pp->p_size, pp->p_offset); if ((unsigned) pp->p_fstype < FSMAXTYPES) fprintf(f, "%8.8s", fstypenames[pp->p_fstype]); @@ -693,18 +726,18 @@ display(f, lp) switch (pp->p_fstype) { case FS_UNUSED: /* XXX */ - fprintf(f, " %5d %5d %5.5s ", + fprintf(f, " %5ld %5ld %5.5s ", pp->p_fsize, pp->p_fsize * pp->p_frag, ""); break; case FS_BSDFFS: - fprintf(f, " %5d %5d %5d ", + fprintf(f, " %5ld %5ld %5d ", pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg); break; case FS_BSDLFS: - fprintf(f, " %5d %5d %5d", + fprintf(f, " %5ld %5ld %5d", pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg); break; @@ -713,13 +746,13 @@ display(f, lp) fprintf(f, "%20.20s", ""); break; } - fprintf(f, "\t# (Cyl. %4d", + fprintf(f, "\t# (Cyl. %4ld", pp->p_offset / lp->d_secpercyl); if (pp->p_offset % lp->d_secpercyl) putc('*', f); else putc(' ', f); - fprintf(f, "- %d", + fprintf(f, "- %ld", (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1); @@ -731,6 +764,7 @@ display(f, lp) fflush(f); } +int edit(lp, f) struct disklabel *lp; int f; @@ -738,7 +772,6 @@ edit(lp, f) register int c; struct disklabel label; FILE *fd; - char *mktemp(); (void) mktemp(tmpfil); fd = fopen(tmpfil, "w"); @@ -778,6 +811,7 @@ edit(lp, f) return (1); } +int editit() { register int pid, xpid; @@ -850,6 +884,7 @@ word(cp) * in the same format as that put out by display(), * and fill in lp. */ +int getasciilabel(f, lp) FILE *f; register struct disklabel *lp; @@ -863,7 +898,7 @@ getasciilabel(f, lp) lp->d_sbsize = SBSIZE; /* XXX */ while (fgets(line, sizeof(line) - 1, f)) { lineno++; - if (cp = index(line,'\n')) + if ((cp = index(line,'\n')) != 0) *cp = '\0'; cp = skip(line); if (cp == NULL) @@ -1165,6 +1200,7 @@ getasciilabel(f, lp) * Check disklabel for errors and fill in * derived fields according to supplied values. */ +int checklabel(lp) register struct disklabel *lp; { @@ -1173,19 +1209,19 @@ checklabel(lp) char part; if (lp->d_secsize == 0) { - fprintf(stderr, "sector size %d\n", lp->d_secsize); + fprintf(stderr, "sector size %ld\n", lp->d_secsize); return (1); } if (lp->d_nsectors == 0) { - fprintf(stderr, "sectors/track %d\n", lp->d_nsectors); + fprintf(stderr, "sectors/track %ld\n", lp->d_nsectors); return (1); } if (lp->d_ntracks == 0) { - fprintf(stderr, "tracks/cylinder %d\n", lp->d_ntracks); + fprintf(stderr, "tracks/cylinder %ld\n", lp->d_ntracks); return (1); } if (lp->d_ncylinders == 0) { - fprintf(stderr, "cylinders/unit %d\n", lp->d_ncylinders); + fprintf(stderr, "cylinders/unit %ld\n", lp->d_ncylinders); errors++; } if (lp->d_rpm == 0) @@ -1195,12 +1231,12 @@ checklabel(lp) if (lp->d_secperunit == 0) lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders; if (lp->d_bbsize == 0) { - fprintf(stderr, "boot block size %d\n", lp->d_bbsize); + fprintf(stderr, "boot block size %ld\n", lp->d_bbsize); errors++; } else if (lp->d_bbsize % lp->d_secsize) Warning("boot block size %% sector-size != 0"); if (lp->d_sbsize == 0) { - fprintf(stderr, "super block size %d\n", lp->d_sbsize); + fprintf(stderr, "super block size %ld\n", lp->d_sbsize); errors++; } else if (lp->d_sbsize % lp->d_secsize) Warning("super block size %% sector-size != 0"); @@ -1228,7 +1264,7 @@ checklabel(lp) } if (pp->p_offset + pp->p_size > lp->d_secperunit) { fprintf(stderr, - "partition %c: partition extends past end of unit\n", + "partition %c: partition extends past end of unit\n", part); errors++; } @@ -1249,6 +1285,7 @@ checklabel(lp) * This allows newfs to prevent creation of a filesystem where it might * clobber bootstrap code. */ +void setbootflag(lp) register struct disklabel *lp; { @@ -1288,15 +1325,19 @@ setbootflag(lp) } /*VARARGS1*/ -Warning(fmt, a1, a2, a3, a4, a5) - char *fmt; +void +Warning(char *fmt, ...) { + va_list ap; fprintf(stderr, "Warning, "); - fprintf(stderr, fmt, a1, a2, a3, a4, a5); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); + va_end(ap); } +void Perror(str) char *str; { @@ -1304,6 +1345,7 @@ Perror(str) exit(4); } +void usage() { #if NUMBOOT > 0 |