Module Name:    src
Committed By:   christos
Date:           Sat May 29 16:51:25 UTC 2021

Modified Files:
        src/sbin/fsdb: fsdb.8 fsdb.c fsdbutil.c

Log Message:
Add birthtime support and make time 64 bit.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sbin/fsdb/fsdb.8
cvs rdiff -u -r1.51 -r1.52 src/sbin/fsdb/fsdb.c
cvs rdiff -u -r1.22 -r1.23 src/sbin/fsdb/fsdbutil.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/fsdb/fsdb.8
diff -u src/sbin/fsdb/fsdb.8:1.26 src/sbin/fsdb/fsdb.8:1.27
--- src/sbin/fsdb/fsdb.8:1.26	Sat Aug  5 16:25:41 2017
+++ src/sbin/fsdb/fsdb.8	Sat May 29 12:51:25 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fsdb.8,v 1.26 2017/08/05 20:25:41 wiz Exp $
+.\"	$NetBSD: fsdb.8,v 1.27 2021/05/29 16:51:25 christos Exp $
 .\"
 .\" Copyright (c) 1996, 2017 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd August 3, 2017
+.Dd May 29, 2021
 .Dt FSDB 8
 .Os
 .Sh NAME
@@ -207,7 +207,8 @@ Change the generation number of the curr
 .It Cm mtime Ar time
 .It Cm ctime Ar time
 .It Cm atime Ar time
-Change the modification, change, or access time (respectively) on the
+.It Cm birthtime Ar time
+Change the modification, change, access time, or birthtime (respectively) on the
 current inode to
 .Ar time .
 .Ar Time
@@ -219,9 +220,11 @@ is an optional nanosecond specification.
 If no nanoseconds are specified, the
 .Va mtimensec ,
 .Va ctimensec ,
+.Va atimensec ,
 or
-.Va atimensec
+.Va birthtimensec
 field will be set to zero.
+The birthtime field is only available on ufs2 filesystems.
 .Pp
 .It Cm quit , Cm q , Cm exit , Aq Em EOF
 Exit the program.

Index: src/sbin/fsdb/fsdb.c
diff -u src/sbin/fsdb/fsdb.c:1.51 src/sbin/fsdb/fsdb.c:1.52
--- src/sbin/fsdb/fsdb.c:1.51	Sun Apr  5 11:25:40 2020
+++ src/sbin/fsdb/fsdb.c	Sat May 29 12:51:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fsdb.c,v 1.51 2020/04/05 15:25:40 joerg Exp $	*/
+/*	$NetBSD: fsdb.c,v 1.52 2021/05/29 16:51:25 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fsdb.c,v 1.51 2020/04/05 15:25:40 joerg Exp $");
+__RCSID("$NetBSD: fsdb.c,v 1.52 2021/05/29 16:51:25 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -137,7 +137,7 @@ static int scannames(struct inodesc *);
 static int dolookup(char *);
 static int chinumfunc(struct inodesc *);
 static int chnamefunc(struct inodesc *);
-static int dotime(char *, int32_t *, int32_t *);
+static int dotime(char *, int64_t *, int32_t *);
 static void print_blks32(int32_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp);
 static void print_blks64(int64_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp);
 static void print_indirblks32(uint32_t blk, int ind_level,
@@ -242,6 +242,7 @@ CMDFUNC(back);			/* pop back to last ino
 CMDFUNC(chmtime);		/* Change mtime */
 CMDFUNC(chctime);		/* Change ctime */
 CMDFUNC(chatime);		/* Change atime */
+CMDFUNC(chbirthtime);		/* Change birthtime */
 CMDFUNC(chinum);		/* Change inode # of dirent */
 CMDFUNC(chname);		/* Change dirname of dirent */
 
@@ -278,6 +279,8 @@ static struct cmdtable cmds[] = {
 	{"mtime", "Change mtime of current inode to MTIME", 2, 2, chmtime},
 	{"ctime", "Change ctime of current inode to CTIME", 2, 2, chctime},
 	{"atime", "Change atime of current inode to ATIME", 2, 2, chatime},
+	{"birthtime", "Change atime of current inode to BIRTHTIME", 2, 2,
+	    chbirthtime},
 	{"quit", "Exit", 1, 1, quit},
 	{"q", "Exit", 1, 1, quit},
 	{"exit", "Exit", 1, 1, quit},
@@ -1357,11 +1360,11 @@ CMDFUNC(chgroup)
 }
 
 static int
-dotime(char *name, int32_t *rsec, int32_t *rnsec)
+dotime(char *name, int64_t *rsec, int32_t *rnsec)
 {
 	char   *p, *val;
 	struct tm t;
-	int32_t sec;
+	int64_t sec;
 	int32_t nsec;
 	p = strchr(name, '.');
 	if (p) {
@@ -1405,14 +1408,15 @@ badformat:
 		warnx("date/time out of range");
 		return 1;
 	}
-	*rsec = iswap32(sec);
+	*rsec = iswap64(sec);
 	*rnsec = iswap32(nsec);
 	return 0;
 }
 
 CMDFUNC(chmtime)
 {
-	int32_t rsec, nsec;
+	int64_t rsec;
+	int32_t nsec;
 
 	if (dotime(argv[1], &rsec, &nsec))
 		return 1;
@@ -1425,7 +1429,8 @@ CMDFUNC(chmtime)
 
 CMDFUNC(chatime)
 {
-	int32_t rsec, nsec;
+	int64_t rsec;
+	int32_t nsec;
 
 	if (dotime(argv[1], &rsec, &nsec))
 		return 1;
@@ -1438,7 +1443,8 @@ CMDFUNC(chatime)
 
 CMDFUNC(chctime)
 {
-	int32_t rsec, nsec;
+	int64_t rsec;
+	int32_t nsec;
 
 	if (dotime(argv[1], &rsec, &nsec))
 		return 1;
@@ -1448,3 +1454,22 @@ CMDFUNC(chctime)
 	printactive();
 	return 0;
 }
+
+CMDFUNC(chbirthtime)
+{
+	int64_t rsec;
+	int32_t nsec;
+
+	if (!is_ufs2) {
+		warnx("birthtime can only be set in ufs2");
+		return 1;
+	}
+
+	if (dotime(argv[1], &rsec, &nsec))
+		return 1;
+	curinode->dp2.di_birthtime = rsec;
+	curinode->dp2.di_birthnsec = nsec;
+	inodirty();
+	printactive();
+	return 0;
+}

Index: src/sbin/fsdb/fsdbutil.c
diff -u src/sbin/fsdb/fsdbutil.c:1.22 src/sbin/fsdb/fsdbutil.c:1.23
--- src/sbin/fsdb/fsdbutil.c:1.22	Sat Apr 11 02:53:53 2009
+++ src/sbin/fsdb/fsdbutil.c	Sat May 29 12:51:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fsdbutil.c,v 1.22 2009/04/11 06:53:53 lukem Exp $	*/
+/*	$NetBSD: fsdbutil.c,v 1.23 2021/05/29 16:51:25 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fsdbutil.c,v 1.22 2009/04/11 06:53:53 lukem Exp $");
+__RCSID("$NetBSD: fsdbutil.c,v 1.23 2021/05/29 16:51:25 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -143,16 +143,24 @@ printstat(const char *cp, ino_t inum, un
 	    (unsigned long long)size);
 	t = is_ufs2 ? iswap64(dp->dp2.di_mtime) : iswap32(dp->dp1.di_mtime);
 	p = ctime(&t);
-	printf("\n\tMTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
+	printf("\n\t    MTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
 	    iswap32(DIP(dp, mtimensec)));
 	t = is_ufs2 ? iswap64(dp->dp2.di_ctime) : iswap32(dp->dp1.di_ctime);
 	p = ctime(&t);
-	printf("\n\tCTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
+	printf("\n\t    CTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
 	    iswap32(DIP(dp, ctimensec)));
 	t = is_ufs2 ? iswap64(dp->dp2.di_atime) : iswap32(dp->dp1.di_atime);
 	p = ctime(&t);
-	printf("\n\tATIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20],
+	printf("\n\t    ATIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
 	    iswap32(DIP(dp,atimensec)));
+	if (is_ufs2) {
+		t = iswap64(dp->dp2.di_birthtime);
+		p = ctime(&t);
+		printf("\n\tBIRTHTIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20],
+		    iswap32(dp->dp2.di_birthnsec));
+	} else {
+		printf("\n");
+	}
 
 	if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT)
 		uid = iswap16(dp->dp1.di_ouid);

Reply via email to