Sat May 29 16:51:25 2021 UTC ()
Add birthtime support and make time 64 bit.


(christos)
diff -r1.26 -r1.27 src/sbin/fsdb/fsdb.8
diff -r1.51 -r1.52 src/sbin/fsdb/fsdb.c
diff -r1.22 -r1.23 src/sbin/fsdb/fsdbutil.c

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

--- src/sbin/fsdb/fsdb.8 2017/08/05 20:25:41 1.26
+++ src/sbin/fsdb/fsdb.8 2021/05/29 16:51:25 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: fsdb.8,v 1.26 2017/08/05 20:25:41 wiz Exp $ 1.\" $NetBSD: fsdb.8,v 1.27 2021/05/29 16:51:25 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1996, 2017 The NetBSD Foundation, Inc. 3.\" Copyright (c) 1996, 2017 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by John T. Kohl. 7.\" by John T. Kohl.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd August 3, 2017 30.Dd May 29, 2021
31.Dt FSDB 8 31.Dt FSDB 8
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm fsdb 34.Nm fsdb
35.Nd FFS debugging/editing tool 35.Nd FFS debugging/editing tool
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.Nm 37.Nm
38.Op Fl dFn 38.Op Fl dFn
39.Fl f Ar fsname 39.Fl f Ar fsname
40.Sh DESCRIPTION 40.Sh DESCRIPTION
41.Nm 41.Nm
42opens 42opens
43.Ar fsname 43.Ar fsname
@@ -197,41 +197,44 @@ Change the owner of the current inode to @@ -197,41 +197,44 @@ Change the owner of the current inode to
197.Ar uid . 197.Ar uid .
198.Pp 198.Pp
199.It Cm chgrp Ar gid 199.It Cm chgrp Ar gid
200Change the group of the current inode to 200Change the group of the current inode to
201.Ar gid . 201.Ar gid .
202.Pp 202.Pp
203.It Cm chgen Ar gen 203.It Cm chgen Ar gen
204Change the generation number of the current inode to 204Change the generation number of the current inode to
205.Ar gen . 205.Ar gen .
206.Pp 206.Pp
207.It Cm mtime Ar time 207.It Cm mtime Ar time
208.It Cm ctime Ar time 208.It Cm ctime Ar time
209.It Cm atime Ar time 209.It Cm atime Ar time
210Change the modification, change, or access time (respectively) on the 210.It Cm birthtime Ar time
 211Change the modification, change, access time, or birthtime (respectively) on the
211current inode to 212current inode to
212.Ar time . 213.Ar time .
213.Ar Time 214.Ar Time
214should be in the format 215should be in the format
215.Em YYYYMMDDHHMMSS[.nsec] 216.Em YYYYMMDDHHMMSS[.nsec]
216where 217where
217.Em nsec 218.Em nsec
218is an optional nanosecond specification. 219is an optional nanosecond specification.
219If no nanoseconds are specified, the 220If no nanoseconds are specified, the
220.Va mtimensec , 221.Va mtimensec ,
221.Va ctimensec , 222.Va ctimensec ,
 223.Va atimensec ,
222or 224or
223.Va atimensec 225.Va birthtimensec
224field will be set to zero. 226field will be set to zero.
 227The birthtime field is only available on ufs2 filesystems.
225.Pp 228.Pp
226.It Cm quit , Cm q , Cm exit , Aq Em EOF 229.It Cm quit , Cm q , Cm exit , Aq Em EOF
227Exit the program. 230Exit the program.
228.El 231.El
229.Sh SEE ALSO 232.Sh SEE ALSO
230.Xr editline 3 , 233.Xr editline 3 ,
231.Xr fs 5 , 234.Xr fs 5 ,
232.Xr clri 8 , 235.Xr clri 8 ,
233.Xr fsck 8 236.Xr fsck 8
234.Sh HISTORY 237.Sh HISTORY
235.Nm 238.Nm
236uses the source code for 239uses the source code for
237.Xr fsck 8 240.Xr fsck 8

cvs diff -r1.51 -r1.52 src/sbin/fsdb/fsdb.c (expand / switch to unified diff)

--- src/sbin/fsdb/fsdb.c 2020/04/05 15:25:40 1.51
+++ src/sbin/fsdb/fsdb.c 2021/05/29 16:51:25 1.52
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fsdb.c,v 1.51 2020/04/05 15:25:40 joerg Exp $ */ 1/* $NetBSD: fsdb.c,v 1.52 2021/05/29 16:51:25 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 2017 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 2017 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 John T. Kohl. 8 * by John T. Kohl.
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,27 +21,27 @@ @@ -21,27 +21,27 @@
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: fsdb.c,v 1.51 2020/04/05 15:25:40 joerg Exp $"); 34__RCSID("$NetBSD: fsdb.c,v 1.52 2021/05/29 16:51:25 christos Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/stat.h> 38#include <sys/stat.h>
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/time.h> 40#include <sys/time.h>
41#include <sys/mount.h> 41#include <sys/mount.h>
42#include <ctype.h> 42#include <ctype.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <grp.h> 44#include <grp.h>
45#include <histedit.h> 45#include <histedit.h>
46#include <limits.h> 46#include <limits.h>
47#include <pwd.h> 47#include <pwd.h>
@@ -127,27 +127,27 @@ struct ufs2_dinode ufs2_zino; @@ -127,27 +127,27 @@ struct ufs2_dinode ufs2_zino;
127struct wrinfo { 127struct wrinfo {
128 off_t size; 128 off_t size;
129 off_t written_size; 129 off_t written_size;
130 int fd; 130 int fd;
131}; 131};
132 132
133__dead static void usage(void); 133__dead static void usage(void);
134static int cmdloop(void); 134static int cmdloop(void);
135static char *prompt(EditLine *); 135static char *prompt(EditLine *);
136static int scannames(struct inodesc *); 136static int scannames(struct inodesc *);
137static int dolookup(char *); 137static int dolookup(char *);
138static int chinumfunc(struct inodesc *); 138static int chinumfunc(struct inodesc *);
139static int chnamefunc(struct inodesc *); 139static int chnamefunc(struct inodesc *);
140static int dotime(char *, int32_t *, int32_t *); 140static int dotime(char *, int64_t *, int32_t *);
141static void print_blks32(int32_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp); 141static void print_blks32(int32_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp);
142static void print_blks64(int64_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp); 142static void print_blks64(int64_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp);
143static void print_indirblks32(uint32_t blk, int ind_level, 143static void print_indirblks32(uint32_t blk, int ind_level,
144 uint64_t *blknum, struct wrinfo *wrp); 144 uint64_t *blknum, struct wrinfo *wrp);
145static void print_indirblks64(uint64_t blk, int ind_level, 145static void print_indirblks64(uint64_t blk, int ind_level,
146 uint64_t *blknum, struct wrinfo *wrp); 146 uint64_t *blknum, struct wrinfo *wrp);
147static int compare_blk32(uint32_t *, uint32_t); 147static int compare_blk32(uint32_t *, uint32_t);
148static int compare_blk64(uint64_t *, uint64_t); 148static int compare_blk64(uint64_t *, uint64_t);
149static int founddatablk(uint64_t); 149static int founddatablk(uint64_t);
150static int find_blks32(uint32_t *buf, int size, uint32_t *blknum); 150static int find_blks32(uint32_t *buf, int size, uint32_t *blknum);
151static int find_blks64(uint64_t *buf, int size, uint64_t *blknum); 151static int find_blks64(uint64_t *buf, int size, uint64_t *blknum);
152static int find_indirblks32(uint32_t blk, int ind_level, 152static int find_indirblks32(uint32_t blk, int ind_level,
153 uint32_t *blknum); 153 uint32_t *blknum);
@@ -232,26 +232,27 @@ CMDFUNC(findblk); /* find block */ @@ -232,26 +232,27 @@ CMDFUNC(findblk); /* find block */
232CMDFUNC(rm); /* remove name */ 232CMDFUNC(rm); /* remove name */
233CMDFUNC(ln); /* add name */ 233CMDFUNC(ln); /* add name */
234CMDFUNC(newtype); /* change type */ 234CMDFUNC(newtype); /* change type */
235CMDFUNC(chmode); /* change mode */ 235CMDFUNC(chmode); /* change mode */
236CMDFUNC(chlen); /* change length */ 236CMDFUNC(chlen); /* change length */
237CMDFUNC(chaflags); /* change flags */ 237CMDFUNC(chaflags); /* change flags */
238CMDFUNC(chgen); /* change generation */ 238CMDFUNC(chgen); /* change generation */
239CMDFUNC(chowner); /* change owner */ 239CMDFUNC(chowner); /* change owner */
240CMDFUNC(chgroup); /* Change group */ 240CMDFUNC(chgroup); /* Change group */
241CMDFUNC(back); /* pop back to last ino */ 241CMDFUNC(back); /* pop back to last ino */
242CMDFUNC(chmtime); /* Change mtime */ 242CMDFUNC(chmtime); /* Change mtime */
243CMDFUNC(chctime); /* Change ctime */ 243CMDFUNC(chctime); /* Change ctime */
244CMDFUNC(chatime); /* Change atime */ 244CMDFUNC(chatime); /* Change atime */
 245CMDFUNC(chbirthtime); /* Change birthtime */
245CMDFUNC(chinum); /* Change inode # of dirent */ 246CMDFUNC(chinum); /* Change inode # of dirent */
246CMDFUNC(chname); /* Change dirname of dirent */ 247CMDFUNC(chname); /* Change dirname of dirent */
247 248
248static struct cmdtable cmds[] = { 249static struct cmdtable cmds[] = {
249 {"help", "Print out help", 1, 1, helpfn}, 250 {"help", "Print out help", 1, 1, helpfn},
250 {"?", "Print out help", 1, 1, helpfn}, 251 {"?", "Print out help", 1, 1, helpfn},
251 {"inode", "Set active inode to INUM", 2, 2, focus}, 252 {"inode", "Set active inode to INUM", 2, 2, focus},
252 {"clri", "Clear inode INUM", 2, 2, zapi}, 253 {"clri", "Clear inode INUM", 2, 2, zapi},
253 {"lookup", "Set active inode by looking up NAME", 2, 2, focusname}, 254 {"lookup", "Set active inode by looking up NAME", 2, 2, focusname},
254 {"cd", "Set active inode by looking up NAME", 2, 2, focusname}, 255 {"cd", "Set active inode by looking up NAME", 2, 2, focusname},
255 {"back", "Go to previous active inode", 1, 1, back}, 256 {"back", "Go to previous active inode", 1, 1, back},
256 {"active", "Print active inode", 1, 1, active}, 257 {"active", "Print active inode", 1, 1, active},
257 {"print", "Print active inode", 1, 1, active}, 258 {"print", "Print active inode", 1, 1, active},
@@ -268,26 +269,28 @@ static struct cmdtable cmds[] = { @@ -268,26 +269,28 @@ static struct cmdtable cmds[] = {
268 {"chinum", "Change dir entry number INDEX to INUM", 3, 3, chinum}, 269 {"chinum", "Change dir entry number INDEX to INUM", 3, 3, chinum},
269 {"chname", "Change dir entry number INDEX to NAME", 3, 3, chname}, 270 {"chname", "Change dir entry number INDEX to NAME", 3, 3, chname},
270 {"chtype", "Change type of current inode to TYPE", 2, 2, newtype}, 271 {"chtype", "Change type of current inode to TYPE", 2, 2, newtype},
271 {"chmod", "Change mode of current inode to MODE", 2, 2, chmode}, 272 {"chmod", "Change mode of current inode to MODE", 2, 2, chmode},
272 {"chown", "Change owner of current inode to OWNER", 2, 2, chowner}, 273 {"chown", "Change owner of current inode to OWNER", 2, 2, chowner},
273 {"chlen", "Change length of current inode to LENGTH", 2, 2, chlen}, 274 {"chlen", "Change length of current inode to LENGTH", 2, 2, chlen},
274 {"chgrp", "Change group of current inode to GROUP", 2, 2, chgroup}, 275 {"chgrp", "Change group of current inode to GROUP", 2, 2, chgroup},
275 {"chflags", "Change flags of current inode to FLAGS", 2, 2, chaflags}, 276 {"chflags", "Change flags of current inode to FLAGS", 2, 2, chaflags},
276 {"chgen", "Change generation number of current inode to GEN", 2, 2, 277 {"chgen", "Change generation number of current inode to GEN", 2, 2,
277 chgen}, 278 chgen},
278 {"mtime", "Change mtime of current inode to MTIME", 2, 2, chmtime}, 279 {"mtime", "Change mtime of current inode to MTIME", 2, 2, chmtime},
279 {"ctime", "Change ctime of current inode to CTIME", 2, 2, chctime}, 280 {"ctime", "Change ctime of current inode to CTIME", 2, 2, chctime},
280 {"atime", "Change atime of current inode to ATIME", 2, 2, chatime}, 281 {"atime", "Change atime of current inode to ATIME", 2, 2, chatime},
 282 {"birthtime", "Change atime of current inode to BIRTHTIME", 2, 2,
 283 chbirthtime},
281 {"quit", "Exit", 1, 1, quit}, 284 {"quit", "Exit", 1, 1, quit},
282 {"q", "Exit", 1, 1, quit}, 285 {"q", "Exit", 1, 1, quit},
283 {"exit", "Exit", 1, 1, quit}, 286 {"exit", "Exit", 1, 1, quit},
284 { .cmd = NULL}, 287 { .cmd = NULL},
285}; 288};
286 289
287static int 290static int
288helpfn(int argc, char *argv[]) 291helpfn(int argc, char *argv[])
289{ 292{
290 struct cmdtable *cmdtp; 293 struct cmdtable *cmdtp;
291 294
292 printf("Commands are:\n%-10s %5s %5s %s\n", 295 printf("Commands are:\n%-10s %5s %5s %s\n",
293 "command", "min argc", "max argc", "what"); 296 "command", "min argc", "max argc", "what");
@@ -1347,31 +1350,31 @@ CMDFUNC(chgroup) @@ -1347,31 +1350,31 @@ CMDFUNC(chgroup)
1347 return 1; 1350 return 1;
1348 } 1351 }
1349 } 1352 }
1350 if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT) 1353 if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT)
1351 curinode->dp1.di_ogid = iswap32(gid); 1354 curinode->dp1.di_ogid = iswap32(gid);
1352 else 1355 else
1353 DIP_SET(curinode, gid, iswap32(gid)); 1356 DIP_SET(curinode, gid, iswap32(gid));
1354 inodirty(); 1357 inodirty();
1355 printactive(); 1358 printactive();
1356 return 0; 1359 return 0;
1357} 1360}
1358 1361
1359static int 1362static int
1360dotime(char *name, int32_t *rsec, int32_t *rnsec) 1363dotime(char *name, int64_t *rsec, int32_t *rnsec)
1361{ 1364{
1362 char *p, *val; 1365 char *p, *val;
1363 struct tm t; 1366 struct tm t;
1364 int32_t sec; 1367 int64_t sec;
1365 int32_t nsec; 1368 int32_t nsec;
1366 p = strchr(name, '.'); 1369 p = strchr(name, '.');
1367 if (p) { 1370 if (p) {
1368 *p = '\0'; 1371 *p = '\0';
1369 nsec = strtoul(++p, &val, 0); 1372 nsec = strtoul(++p, &val, 0);
1370 if (val == p || *val != '\0' || nsec >= 1000000000 || nsec < 0) { 1373 if (val == p || *val != '\0' || nsec >= 1000000000 || nsec < 0) {
1371 warnx("invalid nanoseconds"); 1374 warnx("invalid nanoseconds");
1372 goto badformat; 1375 goto badformat;
1373 } 1376 }
1374 } else 1377 } else
1375 nsec = 0; 1378 nsec = 0;
1376 if (strlen(name) != 14) { 1379 if (strlen(name) != 14) {
1377badformat: 1380badformat:
@@ -1395,56 +1398,78 @@ badformat: @@ -1395,56 +1398,78 @@ badformat:
1395 t.tm_hour = VAL(); 1398 t.tm_hour = VAL();
1396 t.tm_hour = VAL() + t.tm_hour * 10; 1399 t.tm_hour = VAL() + t.tm_hour * 10;
1397 t.tm_min = VAL(); 1400 t.tm_min = VAL();
1398 t.tm_min = VAL() + t.tm_min * 10; 1401 t.tm_min = VAL() + t.tm_min * 10;
1399 t.tm_sec = VAL(); 1402 t.tm_sec = VAL();
1400 t.tm_sec = VAL() + t.tm_sec * 10; 1403 t.tm_sec = VAL() + t.tm_sec * 10;
1401 t.tm_isdst = -1; 1404 t.tm_isdst = -1;
1402 1405
1403 sec = mktime(&t); 1406 sec = mktime(&t);
1404 if (sec == -1) { 1407 if (sec == -1) {
1405 warnx("date/time out of range"); 1408 warnx("date/time out of range");
1406 return 1; 1409 return 1;
1407 } 1410 }
1408 *rsec = iswap32(sec); 1411 *rsec = iswap64(sec);
1409 *rnsec = iswap32(nsec); 1412 *rnsec = iswap32(nsec);
1410 return 0; 1413 return 0;
1411} 1414}
1412 1415
1413CMDFUNC(chmtime) 1416CMDFUNC(chmtime)
1414{ 1417{
1415 int32_t rsec, nsec; 1418 int64_t rsec;
 1419 int32_t nsec;
1416 1420
1417 if (dotime(argv[1], &rsec, &nsec)) 1421 if (dotime(argv[1], &rsec, &nsec))
1418 return 1; 1422 return 1;
1419 DIP_SET(curinode, mtime, rsec); 1423 DIP_SET(curinode, mtime, rsec);
1420 DIP_SET(curinode, mtimensec, nsec); 1424 DIP_SET(curinode, mtimensec, nsec);
1421 inodirty(); 1425 inodirty();
1422 printactive(); 1426 printactive();
1423 return 0; 1427 return 0;
1424} 1428}
1425 1429
1426CMDFUNC(chatime) 1430CMDFUNC(chatime)
1427{ 1431{
1428 int32_t rsec, nsec; 1432 int64_t rsec;
 1433 int32_t nsec;
1429 1434
1430 if (dotime(argv[1], &rsec, &nsec)) 1435 if (dotime(argv[1], &rsec, &nsec))
1431 return 1; 1436 return 1;
1432 DIP_SET(curinode, atime, rsec); 1437 DIP_SET(curinode, atime, rsec);
1433 DIP_SET(curinode, atimensec, nsec); 1438 DIP_SET(curinode, atimensec, nsec);
1434 inodirty(); 1439 inodirty();
1435 printactive(); 1440 printactive();
1436 return 0; 1441 return 0;
1437} 1442}
1438 1443
1439CMDFUNC(chctime) 1444CMDFUNC(chctime)
1440{ 1445{
1441 int32_t rsec, nsec; 1446 int64_t rsec;
 1447 int32_t nsec;
1442 1448
1443 if (dotime(argv[1], &rsec, &nsec)) 1449 if (dotime(argv[1], &rsec, &nsec))
1444 return 1; 1450 return 1;
1445 DIP_SET(curinode, ctime, rsec); 1451 DIP_SET(curinode, ctime, rsec);
1446 DIP_SET(curinode, ctimensec, nsec); 1452 DIP_SET(curinode, ctimensec, nsec);
1447 inodirty(); 1453 inodirty();
1448 printactive(); 1454 printactive();
1449 return 0; 1455 return 0;
1450} 1456}
 1457
 1458CMDFUNC(chbirthtime)
 1459{
 1460 int64_t rsec;
 1461 int32_t nsec;
 1462
 1463 if (!is_ufs2) {
 1464 warnx("birthtime can only be set in ufs2");
 1465 return 1;
 1466 }
 1467
 1468 if (dotime(argv[1], &rsec, &nsec))
 1469 return 1;
 1470 curinode->dp2.di_birthtime = rsec;
 1471 curinode->dp2.di_birthnsec = nsec;
 1472 inodirty();
 1473 printactive();
 1474 return 0;
 1475}

cvs diff -r1.22 -r1.23 src/sbin/fsdb/fsdbutil.c (expand / switch to unified diff)

--- src/sbin/fsdb/fsdbutil.c 2009/04/11 06:53:53 1.22
+++ src/sbin/fsdb/fsdbutil.c 2021/05/29 16:51:25 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fsdbutil.c,v 1.22 2009/04/11 06:53:53 lukem Exp $ */ 1/* $NetBSD: fsdbutil.c,v 1.23 2021/05/29 16:51:25 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996 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 John T. Kohl. 8 * by John T. Kohl.
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,27 +21,27 @@ @@ -21,27 +21,27 @@
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: fsdbutil.c,v 1.22 2009/04/11 06:53:53 lukem Exp $"); 34__RCSID("$NetBSD: fsdbutil.c,v 1.23 2021/05/29 16:51:25 christos Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/stat.h> 38#include <sys/stat.h>
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/time.h> 40#include <sys/time.h>
41#include <sys/mount.h> 41#include <sys/mount.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <grp.h> 43#include <grp.h>
44#include <pwd.h> 44#include <pwd.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
@@ -133,36 +133,44 @@ printstat(const char *cp, ino_t inum, un @@ -133,36 +133,44 @@ printstat(const char *cp, ino_t inum, un
133 putchar('\n'); 133 putchar('\n');
134 break; 134 break;
135 case IFSOCK: 135 case IFSOCK:
136 puts("socket"); 136 puts("socket");
137 break; 137 break;
138 case IFIFO: 138 case IFIFO:
139 puts("fifo"); 139 puts("fifo");
140 break; 140 break;
141 } 141 }
142 printf("I=%llu MODE=%o SIZE=%llu", (unsigned long long)inum, mode, 142 printf("I=%llu MODE=%o SIZE=%llu", (unsigned long long)inum, mode,
143 (unsigned long long)size); 143 (unsigned long long)size);
144 t = is_ufs2 ? iswap64(dp->dp2.di_mtime) : iswap32(dp->dp1.di_mtime); 144 t = is_ufs2 ? iswap64(dp->dp2.di_mtime) : iswap32(dp->dp1.di_mtime);
145 p = ctime(&t); 145 p = ctime(&t);
146 printf("\n\tMTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20], 146 printf("\n\t MTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
147 iswap32(DIP(dp, mtimensec))); 147 iswap32(DIP(dp, mtimensec)));
148 t = is_ufs2 ? iswap64(dp->dp2.di_ctime) : iswap32(dp->dp1.di_ctime); 148 t = is_ufs2 ? iswap64(dp->dp2.di_ctime) : iswap32(dp->dp1.di_ctime);
149 p = ctime(&t); 149 p = ctime(&t);
150 printf("\n\tCTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20], 150 printf("\n\t CTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
151 iswap32(DIP(dp, ctimensec))); 151 iswap32(DIP(dp, ctimensec)));
152 t = is_ufs2 ? iswap64(dp->dp2.di_atime) : iswap32(dp->dp1.di_atime); 152 t = is_ufs2 ? iswap64(dp->dp2.di_atime) : iswap32(dp->dp1.di_atime);
153 p = ctime(&t); 153 p = ctime(&t);
154 printf("\n\tATIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20], 154 printf("\n\t ATIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
155 iswap32(DIP(dp,atimensec))); 155 iswap32(DIP(dp,atimensec)));
 156 if (is_ufs2) {
 157 t = iswap64(dp->dp2.di_birthtime);
 158 p = ctime(&t);
 159 printf("\n\tBIRTHTIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20],
 160 iswap32(dp->dp2.di_birthnsec));
 161 } else {
 162 printf("\n");
 163 }
156 164
157 if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT) 165 if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT)
158 uid = iswap16(dp->dp1.di_ouid); 166 uid = iswap16(dp->dp1.di_ouid);
159 else 167 else
160 uid = iswap32(DIP(dp, uid)); 168 uid = iswap32(DIP(dp, uid));
161 if ((pw = getpwuid(uid)) != NULL) 169 if ((pw = getpwuid(uid)) != NULL)
162 printf("OWNER=%s ", pw->pw_name); 170 printf("OWNER=%s ", pw->pw_name);
163 else 171 else
164 printf("OWNUID=%u ", uid); 172 printf("OWNUID=%u ", uid);
165 if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT) 173 if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT)
166 gid = iswap16(dp->dp1.di_ogid); 174 gid = iswap16(dp->dp1.di_ogid);
167 else 175 else
168 gid = iswap32(DIP(dp, gid)); 176 gid = iswap32(DIP(dp, gid));