4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * clri filsys inumber ...
48 #include <sys/param.h>
49 #include <sys/types.h>
50 #include <sys/mntent.h>
52 #include <sys/vnode.h>
53 #include <sys/fs/ufs_inode.h>
54 #include <sys/fs/ufs_fs.h>
58 #define ISIZE (sizeof (struct dinode))
59 #define NI (MAXBSIZE/ISIZE)
61 static struct dinode buf
[NI
];
67 #define sblock sb_un.sblk
71 static int read_sb(int fd
, const char *dev
);
72 static int isnumber(const char *s
);
75 main(int argc
, char *argv
[])
86 (void) printf("ufs usage: clri filsys inumber ...\n");
89 f
= open64(argv
[1], 2);
91 (void) printf("cannot open %s\n", argv
[1]);
95 if ((sbrr
= read_sb(f
, argv
[1])) != 0) {
99 if ((sblock
.fs_magic
!= FS_MAGIC
) &&
100 (sblock
.fs_magic
!= MTB_UFS_MAGIC
)) {
101 (void) printf("bad super block magic number\n");
105 if (sblock
.fs_magic
== FS_MAGIC
&&
106 (sblock
.fs_version
!= UFS_EFISTYLE4NONEFI_VERSION_2
&&
107 sblock
.fs_version
!= UFS_VERSION_MIN
)) {
109 "unrecognized version of UFS on-disk format: %d\n",
114 if (sblock
.fs_magic
== MTB_UFS_MAGIC
&&
115 (sblock
.fs_version
> MTB_UFS_VERSION_1
||
116 sblock
.fs_version
< MTB_UFS_VERSION_MIN
)) {
118 "unrecognized version of UFS on-disk format: %d\n",
123 /* If fs is logged, roll the log. */
124 if (sblock
.fs_logbno
) {
125 switch (rl_roll_log(argv
[1])) {
128 * Reread the superblock. Rolling the log may have
131 if ((sbrr
= read_sb(f
, argv
[1])) != 0) {
136 (void) printf("Warning: Cannot roll log for %s. %s. "
137 "Inodes will be cleared anyway.\n",
138 argv
[1], strerror(errno
));
141 (void) printf("Cannot roll log for %s. "
142 "Inodes will be cleared anyway.\n",
148 for (i
= 2; i
< argc
; i
++) {
149 if (!isnumber(argv
[i
])) {
150 (void) printf("%s: is not a number\n", argv
[i
]);
156 (void) printf("%s: is zero\n", argv
[i
]);
160 off
= fsbtodb(&sblock
, itod(&sblock
, n
));
162 (void) llseek(f
, off
, 0);
163 if (read(f
, (char *)buf
, sblock
.fs_bsize
) != sblock
.fs_bsize
) {
164 (void) printf("%s: read error\n", argv
[i
]);
172 * Update the time in superblock, so fsck will check this filesystem.
174 (void) llseek(f
, (offset_t
)(SBLOCK
* DEV_BSIZE
), 0);
176 sblock
.fs_time
= (time32_t
)t
;
177 if (write(f
, &sblock
, SBSIZE
) != SBSIZE
) {
178 (void) printf("cannot update %s\n", argv
[1]);
182 for (i
= 2; i
< argc
; i
++) {
184 (void) printf("clearing %u\n", n
);
185 off
= fsbtodb(&sblock
, itod(&sblock
, n
));
187 (void) llseek(f
, off
, 0);
188 (void) read(f
, (char *)buf
, sblock
.fs_bsize
);
189 j
= itoo(&sblock
, n
);
191 memset(&buf
[j
], 0, ISIZE
);
192 buf
[j
].di_gen
= gen
+ 1;
193 (void) llseek(f
, off
, 0);
194 (void) write(f
, (char *)buf
, sblock
.fs_bsize
);
203 isnumber(const char *s
)
207 while ((c
= *s
++) != '\0')
208 if (c
< '0' || c
> '9')
214 read_sb(int fd
, const char *dev
)
216 (void) llseek(fd
, (offset_t
)(SBLOCK
* DEV_BSIZE
), 0);
217 if (read(fd
, &sblock
, SBSIZE
) != SBSIZE
) {
218 (void) printf("cannot read %s\n", dev
);