| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: clri.c,v 1.20 2008/07/20 01:20:21 lukem Exp $ */ | | 1 | /* $NetBSD: clri.c,v 1.21 2009/03/16 13:01:21 lukem Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1990, 1993 | | 4 | * Copyright (c) 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Rich $alz of BBN Inc. | | 8 | * Rich $alz of BBN Inc. |
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. |
| @@ -32,27 +32,27 @@ | | | @@ -32,27 +32,27 @@ |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | #ifndef lint | | 36 | #ifndef lint |
37 | __COPYRIGHT("@(#) Copyright (c) 1990, 1993\ | | 37 | __COPYRIGHT("@(#) Copyright (c) 1990, 1993\ |
38 | The Regents of the University of California. All rights reserved."); | | 38 | The Regents of the University of California. All rights reserved."); |
39 | #endif /* not lint */ | | 39 | #endif /* not lint */ |
40 | | | 40 | |
41 | #ifndef lint | | 41 | #ifndef lint |
42 | #if 0 | | 42 | #if 0 |
43 | static char sccsid[] = "@(#)clri.c 8.3 (Berkeley) 4/28/95"; | | 43 | static char sccsid[] = "@(#)clri.c 8.3 (Berkeley) 4/28/95"; |
44 | #else | | 44 | #else |
45 | __RCSID("$NetBSD: clri.c,v 1.20 2008/07/20 01:20:21 lukem Exp $"); | | 45 | __RCSID("$NetBSD: clri.c,v 1.21 2009/03/16 13:01:21 lukem Exp $"); |
46 | #endif | | 46 | #endif |
47 | #endif /* not lint */ | | 47 | #endif /* not lint */ |
48 | | | 48 | |
49 | #include <sys/param.h> | | 49 | #include <sys/param.h> |
50 | #include <sys/time.h> | | 50 | #include <sys/time.h> |
51 | | | 51 | |
52 | #include <ufs/ufs/dinode.h> | | 52 | #include <ufs/ufs/dinode.h> |
53 | #include <ufs/ufs/ufs_bswap.h> | | 53 | #include <ufs/ufs/ufs_bswap.h> |
54 | #include <ufs/ffs/fs.h> | | 54 | #include <ufs/ffs/fs.h> |
55 | #include <ufs/ffs/ffs_extern.h> | | 55 | #include <ufs/ffs/ffs_extern.h> |
56 | | | 56 | |
57 | #include <err.h> | | 57 | #include <err.h> |
58 | #include <errno.h> | | 58 | #include <errno.h> |
| @@ -112,27 +112,27 @@ main(int argc, char *argv[]) | | | @@ -112,27 +112,27 @@ main(int argc, char *argv[]) |
112 | break; | | 112 | break; |
113 | case FS_UFS2_MAGIC_SWAPPED: | | 113 | case FS_UFS2_MAGIC_SWAPPED: |
114 | is_ufs2 = 1; | | 114 | is_ufs2 = 1; |
115 | /*FALLTHROUGH*/ | | 115 | /*FALLTHROUGH*/ |
116 | case FS_UFS1_MAGIC_SWAPPED: | | 116 | case FS_UFS1_MAGIC_SWAPPED: |
117 | needswap = 1; | | 117 | needswap = 1; |
118 | break; | | 118 | break; |
119 | default: | | 119 | default: |
120 | continue; | | 120 | continue; |
121 | } | | 121 | } |
122 | | | 122 | |
123 | /* check we haven't found an alternate */ | | 123 | /* check we haven't found an alternate */ |
124 | if (is_ufs2 || sbp->fs_old_flags & FS_FLAGS_UPDATED) { | | 124 | if (is_ufs2 || sbp->fs_old_flags & FS_FLAGS_UPDATED) { |
125 | if (sblockloc != ufs_rw64(sbp->fs_sblockloc, needswap)) | | 125 | if ((uint64_t)sblockloc != ufs_rw64(sbp->fs_sblockloc, needswap)) |
126 | continue; | | 126 | continue; |
127 | } else { | | 127 | } else { |
128 | if (sblockloc == SBLOCK_UFS2) | | 128 | if (sblockloc == SBLOCK_UFS2) |
129 | continue; | | 129 | continue; |
130 | } | | 130 | } |
131 | | | 131 | |
132 | break; | | 132 | break; |
133 | } | | 133 | } |
134 | | | 134 | |
135 | /* check that inode numbers are valid */ | | 135 | /* check that inode numbers are valid */ |
136 | imax = ufs_rw32(sbp->fs_ncg, needswap) * | | 136 | imax = ufs_rw32(sbp->fs_ncg, needswap) * |
137 | ufs_rw32(sbp->fs_ipg, needswap); | | 137 | ufs_rw32(sbp->fs_ipg, needswap); |
138 | for (i = 1; i < (argc - 1); i++) | | 138 | for (i = 1; i < (argc - 1); i++) |
| @@ -156,43 +156,43 @@ main(int argc, char *argv[]) | | | @@ -156,43 +156,43 @@ main(int argc, char *argv[]) |
156 | while (*++argv) { | | 156 | while (*++argv) { |
157 | /* get the inode number. */ | | 157 | /* get the inode number. */ |
158 | inonum = atoi(*argv); | | 158 | inonum = atoi(*argv); |
159 | (void)printf("clearing %d\n", inonum); | | 159 | (void)printf("clearing %d\n", inonum); |
160 | | | 160 | |
161 | /* read in the appropriate block. */ | | 161 | /* read in the appropriate block. */ |
162 | offset = ino_to_fsba(sbp, inonum); /* inode to fs blk */ | | 162 | offset = ino_to_fsba(sbp, inonum); /* inode to fs blk */ |
163 | offset = fsbtodb(sbp, offset); /* fs blk disk blk */ | | 163 | offset = fsbtodb(sbp, offset); /* fs blk disk blk */ |
164 | offset *= DEV_BSIZE; /* disk blk to bytes */ | | 164 | offset *= DEV_BSIZE; /* disk blk to bytes */ |
165 | | | 165 | |
166 | /* seek and read the block */ | | 166 | /* seek and read the block */ |
167 | if (lseek(fd, offset, SEEK_SET) < 0) | | 167 | if (lseek(fd, offset, SEEK_SET) < 0) |
168 | err(1, "%s", fs); | | 168 | err(1, "%s", fs); |
169 | if (read(fd, ibuf, bsize) != bsize) | | 169 | if ((size_t)read(fd, ibuf, bsize) != bsize) |
170 | err(1, "%s", fs); | | 170 | err(1, "%s", fs); |
171 | | | 171 | |
172 | /* get the inode within the block. */ | | 172 | /* get the inode within the block. */ |
173 | if (is_ufs2) { | | 173 | if (is_ufs2) { |
174 | ip2 = &((struct ufs2_dinode *)ibuf) | | 174 | ip2 = &((struct ufs2_dinode *)ibuf) |
175 | [ino_to_fsbo(sbp, inonum)]; | | 175 | [ino_to_fsbo(sbp, inonum)]; |
176 | /* clear the inode, and bump the generation count. */ | | 176 | /* clear the inode, and bump the generation count. */ |
177 | generation = ip2->di_gen + 1; | | 177 | generation = ip2->di_gen + 1; |
178 | memset(ip2, 0, sizeof(*ip2)); | | 178 | memset(ip2, 0, sizeof(*ip2)); |
179 | ip2->di_gen = generation; | | 179 | ip2->di_gen = generation; |
180 | } else { | | 180 | } else { |
181 | ip1 = &((struct ufs1_dinode *)ibuf) | | 181 | ip1 = &((struct ufs1_dinode *)ibuf) |
182 | [ino_to_fsbo(sbp, inonum)]; | | 182 | [ino_to_fsbo(sbp, inonum)]; |
183 | /* clear the inode, and bump the generation count. */ | | 183 | /* clear the inode, and bump the generation count. */ |
184 | generation = ip1->di_gen + 1; | | 184 | generation = ip1->di_gen + 1; |
185 | memset(ip1, 0, sizeof(*ip1)); | | 185 | memset(ip1, 0, sizeof(*ip1)); |
186 | ip1->di_gen = generation; | | 186 | ip1->di_gen = generation; |
187 | } | | 187 | } |
188 | | | 188 | |
189 | /* backup and write the block */ | | 189 | /* backup and write the block */ |
190 | if (lseek(fd, offset, SEEK_SET) < 0) | | 190 | if (lseek(fd, offset, SEEK_SET) < 0) |
191 | err(1, "%s", fs); | | 191 | err(1, "%s", fs); |
192 | if (write(fd, ibuf, bsize) != bsize) | | 192 | if ((size_t)write(fd, ibuf, bsize) != bsize) |
193 | err(1, "%s", fs); | | 193 | err(1, "%s", fs); |
194 | (void)fsync(fd); | | 194 | (void)fsync(fd); |
195 | } | | 195 | } |
196 | (void)close(fd); | | 196 | (void)close(fd); |
197 | exit(0); | | 197 | exit(0); |
198 | } | | 198 | } |