Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/fsdb Add birthtime support and make time 64 bit.



details:   https://anonhg.NetBSD.org/src/rev/b716377e6890
branches:  trunk
changeset: 379360:b716377e6890
user:      christos <christos%NetBSD.org@localhost>
date:      Sat May 29 16:51:25 2021 +0000

description:
Add birthtime support and make time 64 bit.

diffstat:

 sbin/fsdb/fsdb.8     |  11 +++++++----
 sbin/fsdb/fsdb.c     |  43 ++++++++++++++++++++++++++++++++++---------
 sbin/fsdb/fsdbutil.c |  18 +++++++++++++-----
 3 files changed, 54 insertions(+), 18 deletions(-)

diffs (206 lines):

diff -r b8291ffe2ca1 -r b716377e6890 sbin/fsdb/fsdb.8
--- a/sbin/fsdb/fsdb.8  Sat May 29 16:49:57 2021 +0000
+++ b/sbin/fsdb/fsdb.8  Sat May 29 16:51:25 2021 +0000
@@ -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.
diff -r b8291ffe2ca1 -r b716377e6890 sbin/fsdb/fsdb.c
--- a/sbin/fsdb/fsdb.c  Sat May 29 16:49:57 2021 +0000
+++ b/sbin/fsdb/fsdb.c  Sat May 29 16:51:25 2021 +0000
@@ -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;
+}
diff -r b8291ffe2ca1 -r b716377e6890 sbin/fsdb/fsdbutil.c
--- a/sbin/fsdb/fsdbutil.c      Sat May 29 16:49:57 2021 +0000
+++ b/sbin/fsdb/fsdbutil.c      Sat May 29 16:51:25 2021 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index