Sat Aug 27 17:45:30 2011 UTC ()
Be more static.


(joerg)
diff -r1.26 -r1.27 src/sbin/mbrlabel/mbrlabel.c

cvs diff -r1.26 -r1.27 src/sbin/mbrlabel/mbrlabel.c (expand / switch to unified diff)

--- src/sbin/mbrlabel/mbrlabel.c 2005/12/28 06:03:15 1.26
+++ src/sbin/mbrlabel/mbrlabel.c 2011/08/27 17:45:30 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mbrlabel.c,v 1.26 2005/12/28 06:03:15 christos Exp $ */ 1/* $NetBSD: mbrlabel.c,v 1.27 2011/08/27 17:45:30 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1998 Wolfgang Solfrank. 4 * Copyright (C) 1998 Wolfgang Solfrank.
5 * Copyright (C) 1998 TooLs GmbH. 5 * Copyright (C) 1998 TooLs GmbH.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -23,108 +23,107 @@ @@ -23,108 +23,107 @@
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35#ifndef lint 35#ifndef lint
36__RCSID("$NetBSD: mbrlabel.c,v 1.26 2005/12/28 06:03:15 christos Exp $"); 36__RCSID("$NetBSD: mbrlabel.c,v 1.27 2011/08/27 17:45:30 joerg Exp $");
37#endif /* not lint */ 37#endif /* not lint */
38 38
39#include <stdio.h> 39#include <stdio.h>
40#include <err.h> 40#include <err.h>
41#include <errno.h> 41#include <errno.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <limits.h> 43#include <limits.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46#include <unistd.h> 46#include <unistd.h>
47#include <util.h> 47#include <util.h>
48 48
49#include <sys/param.h> 49#include <sys/param.h>
50#define FSTYPENAMES 50#define FSTYPENAMES
51#include <sys/disklabel.h> 51#include <sys/disklabel.h>
52#include <sys/bootblock.h> 52#include <sys/bootblock.h>
53#include <sys/ioctl.h> 53#include <sys/ioctl.h>
54 54
55#include "dkcksum.h" 55#include "dkcksum.h"
56#include "extern.h" 56#include "extern.h"
57 57
58int main(int, char **); 58__dead static void usage(void);
59void usage(void); 59static void getlabel(int);
60void getlabel(int); 60static void setlabel(int, int);
61void setlabel(int, int); 61static int getparts(int, u_int32_t, u_int32_t, int);
62int getparts(int, u_int32_t, u_int32_t, int); 62static u_int16_t getshort(void *);
63u_int16_t getshort(void *); 63static u_int32_t getlong(void *);
64u_int32_t getlong(void *); 
65 64
66struct disklabel label; 65struct disklabel label;
67 66
68void 67static void
69getlabel(int sd) 68getlabel(int sd)
70{ 69{
71 70
72 if (ioctl(sd, DIOCGDINFO, &label) < 0) { 71 if (ioctl(sd, DIOCGDINFO, &label) < 0) {
73 perror("get label"); 72 perror("get label");
74 exit(1); 73 exit(1);
75 } 74 }
76 /* 75 /*
77 * Some ports seem to not set the number of partitions 76 * Some ports seem to not set the number of partitions
78 * correctly, albeit they seem to set the raw partition ok! 77 * correctly, albeit they seem to set the raw partition ok!
79 */ 78 */
80 if (label.d_npartitions <= getrawpartition()) 79 if (label.d_npartitions <= getrawpartition())
81 label.d_npartitions = getrawpartition() + 1; 80 label.d_npartitions = getrawpartition() + 1;
82} 81}
83 82
84void 83static void
85setlabel(int sd, int doraw) 84setlabel(int sd, int doraw)
86{ 85{
87 int one = 1; 86 int one = 1;
88 87
89 label.d_checksum = 0; 88 label.d_checksum = 0;
90 label.d_checksum = dkcksum(&label); 89 label.d_checksum = dkcksum(&label);
91 if (ioctl(sd, doraw ? DIOCWDINFO : DIOCSDINFO, &label) < 0) { 90 if (ioctl(sd, doraw ? DIOCWDINFO : DIOCSDINFO, &label) < 0) {
92 perror("set label"); 91 perror("set label");
93 exit(1); 92 exit(1);
94 } 93 }
95 if (!doraw) 94 if (!doraw)
96 /* If we haven't written to the disk, don't discard on close */ 95 /* If we haven't written to the disk, don't discard on close */
97 ioctl(sd, DIOCKLABEL, &one); 96 ioctl(sd, DIOCKLABEL, &one);
98 97
99} 98}
100 99
101u_int16_t 100static u_int16_t
102getshort(void *p) 101getshort(void *p)
103{ 102{
104 unsigned char *cp = p; 103 unsigned char *cp = p;
105 104
106 return (cp[0] | (cp[1] << 8)); 105 return (cp[0] | (cp[1] << 8));
107} 106}
108 107
109u_int32_t 108static u_int32_t
110getlong(void *p) 109getlong(void *p)
111{ 110{
112 unsigned char *cp = p; 111 unsigned char *cp = p;
113 112
114 return (cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24)); 113 return (cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24));
115} 114}
116 115
117int 116static int
118getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose) 117getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose)
119{ 118{
120 unsigned char buf[DEV_BSIZE]; 119 unsigned char buf[DEV_BSIZE];
121 struct mbr_partition parts[MBR_PART_COUNT]; 120 struct mbr_partition parts[MBR_PART_COUNT];
122 struct partition npe; 121 struct partition npe;
123 off_t loff; 122 off_t loff;
124 int i, j, unused, changed; 123 int i, j, unused, changed;
125 124
126 changed = 0; 125 changed = 0;
127 loff = (off_t)off * DEV_BSIZE; 126 loff = (off_t)off * DEV_BSIZE;
128 127
129 if (lseek(sd, loff, SEEK_SET) != loff) { 128 if (lseek(sd, loff, SEEK_SET) != loff) {
130 perror("seek label"); 129 perror("seek label");
@@ -227,27 +226,27 @@ getparts(int sd, u_int32_t off, u_int32_ @@ -227,27 +226,27 @@ getparts(int sd, u_int32_t off, u_int32_
227 /* recursively scan extended partitions */ 226 /* recursively scan extended partitions */
228 for (i = 0; i < MBR_PART_COUNT; i++) { 227 for (i = 0; i < MBR_PART_COUNT; i++) {
229 u_int32_t poff; 228 u_int32_t poff;
230 229
231 if (MBR_IS_EXTENDED(parts[i].mbrp_type)) { 230 if (MBR_IS_EXTENDED(parts[i].mbrp_type)) {
232 poff = getlong(&parts[i].mbrp_start) + extoff; 231 poff = getlong(&parts[i].mbrp_start) + extoff;
233 changed += getparts(sd, poff, 232 changed += getparts(sd, poff,
234 extoff ? extoff : poff, verbose); 233 extoff ? extoff : poff, verbose);
235 } 234 }
236 } 235 }
237 return (changed); 236 return (changed);
238} 237}
239 238
240void 239static void
241usage(void) 240usage(void)
242{ 241{
243 fprintf(stderr, "usage: %s [-fqrw] [-s sector] rawdisk\n", 242 fprintf(stderr, "usage: %s [-fqrw] [-s sector] rawdisk\n",
244 getprogname()); 243 getprogname());
245 exit(1); 244 exit(1);
246} 245}
247 246
248 247
249int 248int
250main(int argc, char **argv) 249main(int argc, char **argv)
251{ 250{
252 int sd, ch, changed; 251 int sd, ch, changed;
253 char *ep, name[MAXPATHLEN]; 252 char *ep, name[MAXPATHLEN];