Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sbin/disklabel Pull up revisions 1.90-1.95 (requested b...



details:   https://anonhg.NetBSD.org/src/rev/69d17fc8380f
branches:  netbsd-1-5
changeset: 490754:69d17fc8380f
user:      he <he%NetBSD.org@localhost>
date:      Mon Feb 26 22:26:34 2001 +0000

description:
Pull up revisions 1.90-1.95 (requested by lukem):
  Several fixes and enhancements:
  o with ``-I'', initialize the label if it's not there, it's
    corrupt, or there's no ``fake'' label.
  o correct partition table header
  o move some functions into a separate file for other programs
    to use
  o fix examples and cross references
  o various cleanups

diffstat:

 sbin/disklabel/disklabel.c |  530 +++++++++++++++++---------------------------
 1 files changed, 207 insertions(+), 323 deletions(-)

diffs (truncated from 1101 to 300 lines):

diff -r 651c6c1f9bf2 -r 69d17fc8380f sbin/disklabel/disklabel.c
--- a/sbin/disklabel/disklabel.c        Mon Feb 26 22:26:18 2001 +0000
+++ b/sbin/disklabel/disklabel.c        Mon Feb 26 22:26:34 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.84.2.5 2000/10/18 02:52:44 tv Exp $    */
+/*     $NetBSD: disklabel.c,v 1.84.2.6 2001/02/26 22:26:34 he Exp $    */
 
 /*
  * Copyright (c) 1987, 1993
@@ -40,16 +40,16 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
        The Regents of the University of California.  All rights reserved.\n");
-#endif /* not lint */
+#endif /* not lint */
 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)disklabel.c        8.4 (Berkeley) 5/4/95";
 /* from static char sccsid[] = "@(#)disklabel.c        1.2 (Symmetric) 11/28/85"; */
 #else
-__RCSID("$NetBSD: disklabel.c,v 1.84.2.5 2000/10/18 02:52:44 tv Exp $");
+__RCSID("$NetBSD: disklabel.c,v 1.84.2.6 2001/02/26 22:26:34 he Exp $");
 #endif
-#endif /* not lint */
+#endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/file.h>
@@ -97,17 +97,18 @@
 #define NUMBOOT 0
 #endif
 
-extern char *__progname;
+extern char    *__progname;
 
 #define        DEFEDITOR       _PATH_VI
 
 static char    *dkname;
-static char    *specname;
 static char    tmpfil[MAXPATHLEN];
 
 static char    namebuf[BBSIZE], *np = namebuf;
 static struct  disklabel lab;
-char   bootarea[BBSIZE];
+
+char    bootarea[BBSIZE];
+char   *specname;
 
 
 #if NUMBOOT > 0
@@ -119,65 +120,70 @@
 static char    boot0[MAXPATHLEN];
 #if NUMBOOT > 1
 static char    boot1[MAXPATHLEN];
-#endif
-#endif
+#endif /* NUMBOOT > 1 */
+#endif /* NUMBOOT > 0 */
 
 static enum    {
        UNSPEC, EDIT, READ, RESTORE, SETWRITEABLE, WRITE, WRITEBOOT, INTERACT
 } op = UNSPEC;
 
-static int     rflag;
-static int     tflag;
-static int     Cflag;
-static int     Iflag;
+static int     rflag;
+static int     tflag;
+       int     Cflag;
+static int     Iflag;
 
 #ifdef DEBUG
 static int     debug;
 #define OPTIONS        "BCINRWb:def:irs:tw"
-#else
+#else  /* ! DEBUG */
 #define OPTIONS        "BCINRWb:ef:irs:tw"
-#endif
+#endif /* ! DEBUG */
 
 #ifdef USE_MBR
-static struct mbr_partition *dosdp;    /* i386 DOS partition, if found */
-static int mbrpt_nobsd; /* MBR partition table exists, but no BSD partition */
-static struct mbr_partition *readmbr __P((int));
-#endif
+static struct mbr_partition    *dosdp; /* i386 DOS partition, if found */
+static int                      mbrpt_nobsd;   /*
+                                                * MBR partition table exists,
+                                                * but no BSD partition
+                                                */
+static struct mbr_partition    *readmbr(int);
+#endif /* USE_MBR */
+
 #ifdef __arm32__
-static u_int filecore_partition_offset;
-static u_int get_filecore_partition __P((int));
-static int filecore_checksum __P((u_char *));
+static u_int            filecore_partition_offset;
+static u_int            get_filecore_partition(int);
+static int              filecore_checksum(u_char *);
 #endif /* __arm32__ */
+
 #if defined(USE_MBR) || (defined(__arm32__) && defined(notyet))
-static void confirm __P((const char *));
+static void             confirm(const char *);
 #endif
 
-int main __P((int, char *[]));
+int                     main(int, char *[]);
 
-static void makedisktab __P((FILE *, struct disklabel *));
-static void makelabel __P((char *, char *, struct disklabel *));
-static void l_perror __P((char *));
-static struct disklabel *readlabel __P((int));
-static struct disklabel *makebootarea __P((char *, struct disklabel *, int));
-static int edit __P((struct disklabel *, int));
-static int editit __P((void));
-static char *skip __P((char *));
-static char *word __P((char *));
-static int getasciilabel __P((FILE *, struct disklabel *));
+static void             makedisktab(FILE *, struct disklabel *);
+static void             makelabel(const char *, const char *,
+                           struct disklabel *);
+static void             l_perror(const char *);
+static struct disklabel        *readlabel(int);
+static struct disklabel        *makebootarea(char *, struct disklabel *, int);
+static int              edit(struct disklabel *, int);
+static int              editit(void);
+static char            *skip(char *);
+static char            *word(char *);
+static int              getasciilabel(FILE *, struct disklabel *);
 #if NUMBOOT > 0
-static void setbootflag __P((struct disklabel *));
+static void             setbootflag(struct disklabel *);
 #endif
-static void usage __P((void));
+static void             usage(void);
 
 int
-main(argc, argv)
-       int argc;
-       char *argv[];
+main(int argc, char *argv[])
 {
        struct disklabel *lp;
-       FILE *t;
-       int ch, f, writeable, error = 0;
+       FILE    *t;
+       int      ch, f, writeable, error;
 
+       error = 0;
        while ((ch = getopt(argc, argv, OPTIONS)) != -1)
                switch (ch) {
 #if NUMBOOT > 0
@@ -191,8 +197,8 @@
                case 's':
                        bootxx = optarg;
                        break;
-#endif
-#endif
+#endif /* NUMBOOT > 1 */
+#endif /* NUMBOOT > 0 */
                case 'C':
                        ++Cflag;
                        break;
@@ -262,10 +268,10 @@
                if (op == UNSPEC)
                        op = READ;
        }
-#else
+#else  /* NUMBOOT <= 0 */
        if (op == UNSPEC)
                op = READ;
-#endif
+#endif /* NUMBOOT <= 0 */
 
        if (argc < 1)
                usage();
@@ -287,7 +293,8 @@
         * partition, if present.
         */
        dosdp = readmbr(f);
-#endif
+#endif /* USE_MBR */
+
 #ifdef __arm32__
        /*
         * Check for the presence of a RiscOS filecore boot block
@@ -299,6 +306,7 @@
         */
        filecore_partition_offset = get_filecore_partition(f);
 #endif /* __arm32__ */
+
        switch (op) {
 
        case EDIT:
@@ -329,8 +337,8 @@
                if (tflag)
                        makedisktab(stdout, lp);
                else {
-                       showinfo(stdout, lp);
-                       showpartitions(stdout, lp);
+                       showinfo(stdout, lp, specname);
+                       showpartitions(stdout, lp, Cflag);
                }
                error = checklabel(lp);
                break;
@@ -383,9 +391,11 @@
                        error = 1;
                break;
        }
-#endif
+#endif /* NUMBOOT > 0 */
+
        case UNSPEC:
                usage();
+
        }
        exit(error);
 }
@@ -396,9 +406,7 @@
  * if specified.
  */
 static void
-makelabel(type, name, lp)
-       char *type, *name;
-       struct disklabel *lp;
+makelabel(const char *type, const char *name, struct disklabel *lp)
 {
        struct disklabel *dp;
 
@@ -406,6 +414,7 @@
        if (dp == NULL)
                errx(1, "unknown disk type: %s", type);
        *lp = *dp;
+
 #if NUMBOOT > 0
        /*
         * Set bootstrap name(s).
@@ -422,6 +431,7 @@
                        (void)strcpy(boot0, lp->d_boot0);
                xxboot = boot0;
        }
+
 #if NUMBOOT > 1
        if (!bootxx && lp->d_boot1) {
                if (*lp->d_boot1 != '/')
@@ -431,8 +441,9 @@
                        (void)strcpy(boot1, lp->d_boot1);
                bootxx = boot1;
        }
-#endif
-#endif
+#endif /* NUMBOOT > 1 */
+#endif /* NUMBOOT > 0 */
+
        /* d_packname is union d_boot[01], so zero */
        (void) memset(lp->d_packname, 0, sizeof(lp->d_packname));
        if (name)
@@ -441,10 +452,9 @@
 
 #if defined(USE_MBR) || (defined(__arm32__) && defined(notyet))
 static void
-confirm(txt)
-       const char *txt;
+confirm(const char *txt)
 {
-       int first, ch;
+       int     first, ch;
 
        (void) printf("%s? [n]: ", txt);
        (void) fflush(stdout);
@@ -454,17 +464,15 @@
        if (first != 'y' && first != 'Y')
                exit(0);
 }
-#endif
+#endif /* USE_MBR || __arm32__ && notyet */
 
 int
-writelabel(f, boot, lp)
-       int f;
-       char *boot;
-       struct disklabel *lp;
+writelabel(int f, const char *boot, struct disklabel *lp)
 {
-       int writeable;
-       off_t sectoffset = 0;
+       int     writeable;
+       off_t   sectoffset;
 
+       sectoffset = 0;
 #if NUMBOOT > 0
        setbootflag(lp);
 #endif
@@ -476,15 +484,15 @@
 #ifdef __sparc__
        /* Let the kernel deal with SunOS disklabel compatibility */



Home | Main Index | Thread Index | Old Index