Source-Changes-HG archive

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

[src/trunk]: src/sbin/mbrlabel - remove unused arg to getparts()



details:   https://anonhg.NetBSD.org/src/rev/b1fa1585f7f7
branches:  trunk
changeset: 503917:b1fa1585f7f7
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Feb 18 03:36:07 2001 +0000

description:
- remove unused arg to getparts()
- clean up WARNS=2 problems
- implement getshort()
- use getshort() with MBR_MAGICOFF to test if the magic number is OK, rather
  than using hard-coded magic numbers

diffstat:

 sbin/mbrlabel/mbrlabel.c |  35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diffs (120 lines):

diff -r 0fd792264791 -r b1fa1585f7f7 sbin/mbrlabel/mbrlabel.c
--- a/sbin/mbrlabel/mbrlabel.c  Sun Feb 18 03:09:50 2001 +0000
+++ b/sbin/mbrlabel/mbrlabel.c  Sun Feb 18 03:36:07 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbrlabel.c,v 1.14 2001/02/04 20:08:24 christos Exp $   */
+/*     $NetBSD: mbrlabel.c,v 1.15 2001/02/18 03:36:07 lukem Exp $      */
 
 /*
  * Copyright (C) 1998 Wolfgang Solfrank.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mbrlabel.c,v 1.14 2001/02/04 20:08:24 christos Exp $");
+__RCSID("$NetBSD: mbrlabel.c,v 1.15 2001/02/18 03:36:07 lukem Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
@@ -52,15 +52,14 @@
 #include "dkcksum.h"
 #include "extern.h"
 
-#define        FIRSTPART       0
-
 int    main(int, char **);
 void   usage(void);
 void   getlabel(int);
 void   setlabel(int, int);
-int    getparts(int, int, u_int32_t, u_int32_t, int);
+int    getparts(int, u_int32_t, u_int32_t, int);
 int    nbsdtype(int);
-u_int32_t getlong(void *p);
+u_int16_t      getshort(void *);
+u_int32_t      getlong(void *);
 
 struct disklabel label;
 extern char *__progname;
@@ -122,6 +121,14 @@
        return (FS_OTHER);
 }
 
+u_int16_t
+getshort(void *p)
+{
+       unsigned char *cp = p;
+
+       return (cp[0] | (cp[1] << 8));
+}
+
 u_int32_t
 getlong(void *p)
 {
@@ -131,7 +138,7 @@
 }
 
 int
-getparts(int sd, int np, u_int32_t off, u_int32_t extoff, int verbose)
+getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose)
 {
        unsigned char           buf[DEV_BSIZE];
        struct mbr_partition    parts[NMBRPART];
@@ -150,7 +157,7 @@
                perror("read label");
                exit(1);
        }
-       if (buf[0x1fe] != 0x55 || buf[0x1ff] != 0xaa)
+       if (getshort(buf + MBR_MAGICOFF) != MBR_MAGIC)
                return (changed);
        memcpy(parts, buf + MBR_PARTOFF, sizeof parts);
 
@@ -241,7 +248,7 @@
 
                if (MBR_IS_EXTENDED(parts[i].mbrp_typ)) {
                        poff = getlong(&parts[i].mbrp_start) + extoff;
-                       changed += getparts(sd, np, poff,
+                       changed += getparts(sd, poff,
                            extoff ? extoff : poff, verbose);
                }
        }
@@ -264,12 +271,12 @@
        int     force;                  /* force label update */
        int     raw;                    /* update on-disk label as well */
        int     verbose;                /* verbose output */
-       int     write;                  /* update in-core label if changed */
+       int     write_it;               /* update in-core label if changed */
 
        force = 0;
        raw = 0;
        verbose = 1;
-       write = 0;
+       write_it = 0;
        while ((ch = getopt(argc, argv, "fqrw")) != -1) {
                switch (ch) {
                case 'f':
@@ -282,7 +289,7 @@
                        raw = 1;
                        break;
                case 'w':
-                       write = 1;
+                       write_it = 1;
                        break;
                default:
                        usage();
@@ -298,14 +305,14 @@
                exit(1);
        }
        getlabel(sd);
-       changed = getparts(sd, FIRSTPART, MBR_BBSECTOR, 0, verbose);
+       changed = getparts(sd, MBR_BBSECTOR, 0, verbose);
 
        if (verbose) {
                putchar('\n');
                showpartitions(stdout, &label, 0);
                putchar('\n');
        }
-       if (write) {
+       if (write_it) {
                if (! changed && ! force)
                        printf("No change; not updating disk label.\n");
                else {



Home | Main Index | Thread Index | Old Index