| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fsirand.c,v 1.28 2008/04/28 20:23:08 martin Exp $ */ | | 1 | /* $NetBSD: fsirand.c,v 1.29 2011/08/27 17:36:05 joerg Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,59 +21,59 @@ | | | @@ -21,59 +21,59 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __RCSID("$NetBSD: fsirand.c,v 1.28 2008/04/28 20:23:08 martin Exp $"); | | 34 | __RCSID("$NetBSD: fsirand.c,v 1.29 2011/08/27 17:36:05 joerg Exp $"); |
35 | #endif /* lint */ | | 35 | #endif /* lint */ |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/time.h> | | 38 | #include <sys/time.h> |
39 | #include <sys/vnode.h> | | 39 | #include <sys/vnode.h> |
40 | #include <sys/disklabel.h> | | 40 | #include <sys/disklabel.h> |
41 | #include <sys/ioctl.h> | | 41 | #include <sys/ioctl.h> |
42 | | | 42 | |
43 | #include <ctype.h> | | 43 | #include <ctype.h> |
44 | #include <err.h> | | 44 | #include <err.h> |
45 | #include <errno.h> | | 45 | #include <errno.h> |
46 | #include <fcntl.h> | | 46 | #include <fcntl.h> |
47 | #include <stdio.h> | | 47 | #include <stdio.h> |
48 | #include <stdlib.h> | | 48 | #include <stdlib.h> |
49 | #include <string.h> | | 49 | #include <string.h> |
50 | #include <unistd.h> | | 50 | #include <unistd.h> |
51 | #include <util.h> | | 51 | #include <util.h> |
52 | #include <signal.h> | | 52 | #include <signal.h> |
53 | | | 53 | |
54 | #include <ufs/ufs/ufs_bswap.h> | | 54 | #include <ufs/ufs/ufs_bswap.h> |
55 | | | 55 | |
56 | #include <ufs/ufs/dinode.h> | | 56 | #include <ufs/ufs/dinode.h> |
57 | #include <ufs/ffs/fs.h> | | 57 | #include <ufs/ffs/fs.h> |
58 | #include <ufs/ffs/ffs_extern.h> | | 58 | #include <ufs/ffs/ffs_extern.h> |
59 | | | 59 | |
60 | static void usage(void); | | 60 | __dead static void usage(void); |
61 | static void getsblock(int, const char *, struct fs *); | | 61 | static void getsblock(int, const char *, struct fs *); |
62 | static void fixinodes(int, struct fs *, struct disklabel *, int, long); | | 62 | static void fixinodes(int, struct fs *, struct disklabel *, int, long); |
63 | static void statussig(int); | | 63 | static void statussig(int); |
64 | | | 64 | |
65 | int needswap, ino, imax, is_ufs2; | | 65 | int needswap, ino, imax, is_ufs2; |
66 | time_t tstart; | | 66 | static time_t tstart; |
67 | | | 67 | |
68 | static void | | 68 | static void |
69 | usage(void) | | 69 | usage(void) |
70 | { | | 70 | { |
71 | | | 71 | |
72 | (void) fprintf(stderr, | | 72 | (void) fprintf(stderr, |
73 | "usage: %s [-F] [-p] [-x <constant>] <special>\n", | | 73 | "usage: %s [-F] [-p] [-x <constant>] <special>\n", |
74 | getprogname()); | | 74 | getprogname()); |
75 | exit(1); | | 75 | exit(1); |
76 | } | | 76 | } |
77 | | | 77 | |
78 | | | 78 | |
79 | static const off_t sblock_try[] = SBLOCKSEARCH; | | 79 | static const off_t sblock_try[] = SBLOCKSEARCH; |
| @@ -189,27 +189,27 @@ fixinodes(int fd, struct fs *fs, struct | | | @@ -189,27 +189,27 @@ fixinodes(int fd, struct fs *fs, struct |
189 | if (lseek(fd, sp, SEEK_SET) == (off_t) -1) | | 189 | if (lseek(fd, sp, SEEK_SET) == (off_t) -1) |
190 | err(1, "Seeking to inode %d failed", ino); | | 190 | err(1, "Seeking to inode %d failed", ino); |
191 | | | 191 | |
192 | if (write(fd, buf, size) != size) | | 192 | if (write(fd, buf, size) != size) |
193 | err(1, "Writing inodes %d+%d failed", ino, inopb); | | 193 | err(1, "Writing inodes %d+%d failed", ino, inopb); |
194 | } | | 194 | } |
195 | free(buf); | | 195 | free(buf); |
196 | } | | 196 | } |
197 | | | 197 | |
198 | /* | | 198 | /* |
199 | * statussig(): | | 199 | * statussig(): |
200 | * display current status | | 200 | * display current status |
201 | */ | | 201 | */ |
202 | void | | 202 | static void |
203 | statussig(int dummy) | | 203 | statussig(int dummy) |
204 | { | | 204 | { |
205 | char msgbuf[256]; | | 205 | char msgbuf[256]; |
206 | int len, deltat; | | 206 | int len, deltat; |
207 | time_t tnow, elapsed; | | 207 | time_t tnow, elapsed; |
208 | | | 208 | |
209 | (void)time(&tnow); | | 209 | (void)time(&tnow); |
210 | elapsed = tnow - tstart; | | 210 | elapsed = tnow - tstart; |
211 | len = snprintf(msgbuf, sizeof(msgbuf), | | 211 | len = snprintf(msgbuf, sizeof(msgbuf), |
212 | "fsirand: completed inode %d of %d (%3.2f%%)", | | 212 | "fsirand: completed inode %d of %d (%3.2f%%)", |
213 | ino, imax, (ino * 100.0) / imax); | | 213 | ino, imax, (ino * 100.0) / imax); |
214 | if (imax - ino) { | | 214 | if (imax - ino) { |
215 | deltat = tstart - tnow + (1.0 * (tnow - tstart)) / ino * imax; | | 215 | deltat = tstart - tnow + (1.0 * (tnow - tstart)) / ino * imax; |