Module Name: src Committed By: christos Date: Thu Feb 4 23:55:43 UTC 2010
Modified Files: src/sbin/fsck: fsutil.c fsutil.h src/sbin/fsck_ext2fs: inode.c pass1.c src/sbin/fsck_ffs: inode.c src/sbin/fsck_lfs: inode.c Log Message: Centralize time printing and deal with ctime possibly returning NULL. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/fsck/fsutil.c cvs rdiff -u -r1.14 -r1.15 src/sbin/fsck/fsutil.h cvs rdiff -u -r1.30 -r1.31 src/sbin/fsck_ext2fs/inode.c cvs rdiff -u -r1.20 -r1.21 src/sbin/fsck_ext2fs/pass1.c cvs rdiff -u -r1.62 -r1.63 src/sbin/fsck_ffs/inode.c cvs rdiff -u -r1.40 -r1.41 src/sbin/fsck_lfs/inode.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/fsck/fsutil.c diff -u src/sbin/fsck/fsutil.c:1.18 src/sbin/fsck/fsutil.c:1.19 --- src/sbin/fsck/fsutil.c:1.18 Sun Mar 16 19:17:55 2008 +++ src/sbin/fsck/fsutil.c Thu Feb 4 18:55:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fsutil.c,v 1.18 2008/03/16 23:17:55 lukem Exp $ */ +/* $NetBSD: fsutil.c,v 1.19 2010/02/04 23:55:42 christos Exp $ */ /* * Copyright (c) 1990, 1993 @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: fsutil.c,v 1.18 2008/03/16 23:17:55 lukem Exp $"); +__RCSID("$NetBSD: fsutil.c,v 1.19 2010/02/04 23:55:42 christos Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -244,3 +244,15 @@ */ return (origname); } + +const char * +print_mtime(time_t t) +{ + static char b[128]; + char *p = ctime(&t); + if (p != NULL) + (void)snprintf(b, sizeof(b), "%12.12s %4.4s ", &p[4], &p[20]); + else + (void)snprintf(b, sizeof(b), "%lld ", (long long)t); + return b; +} Index: src/sbin/fsck/fsutil.h diff -u src/sbin/fsck/fsutil.h:1.14 src/sbin/fsck/fsutil.h:1.15 --- src/sbin/fsck/fsutil.h:1.14 Tue Oct 20 21:07:46 2009 +++ src/sbin/fsck/fsutil.h Thu Feb 4 18:55:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fsutil.h,v 1.14 2009/10/21 01:07:46 snj Exp $ */ +/* $NetBSD: fsutil.h,v 1.15 2010/02/04 23:55:42 christos Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -44,6 +44,7 @@ const char *cdevname(void); void setcdevname(const char *, int); int hotroot(void); +const char *print_mtime(time_t); #define CHECK_PREEN 1 #define CHECK_VERBOSE 2 Index: src/sbin/fsck_ext2fs/inode.c diff -u src/sbin/fsck_ext2fs/inode.c:1.30 src/sbin/fsck_ext2fs/inode.c:1.31 --- src/sbin/fsck_ext2fs/inode.c:1.30 Mon Oct 19 14:41:08 2009 +++ src/sbin/fsck_ext2fs/inode.c Thu Feb 4 18:55:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: inode.c,v 1.30 2009/10/19 18:41:08 bouyer Exp $ */ +/* $NetBSD: inode.c,v 1.31 2010/02/04 23:55:42 christos Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -58,7 +58,7 @@ #if 0 static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95"; #else -__RCSID("$NetBSD: inode.c,v 1.30 2009/10/19 18:41:08 bouyer Exp $"); +__RCSID("$NetBSD: inode.c,v 1.31 2010/02/04 23:55:42 christos Exp $"); #endif #endif /* not lint */ @@ -612,9 +612,7 @@ pinode(ino_t ino) { struct ext2fs_dinode *dp; - char *p; struct passwd *pw; - time_t t; uid_t uid; printf(" I=%llu ", (unsigned long long)ino); @@ -635,9 +633,7 @@ if (preen) printf("%s: ", cdevname()); printf("SIZE=%llu ", (long long)inosize(dp)); - t = fs2h32(dp->e2di_mtime); - p = ctime(&t); - printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); + printf("MTIME=%s ", print_mtime(fs2h32(dp->e2di_mtime))); } void Index: src/sbin/fsck_ext2fs/pass1.c diff -u src/sbin/fsck_ext2fs/pass1.c:1.20 src/sbin/fsck_ext2fs/pass1.c:1.21 --- src/sbin/fsck_ext2fs/pass1.c:1.20 Mon Oct 19 14:41:08 2009 +++ src/sbin/fsck_ext2fs/pass1.c Thu Feb 4 18:55:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: pass1.c,v 1.20 2009/10/19 18:41:08 bouyer Exp $ */ +/* $NetBSD: pass1.c,v 1.21 2010/02/04 23:55:42 christos Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -58,7 +58,7 @@ #if 0 static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93"; #else -__RCSID("$NetBSD: pass1.c,v 1.20 2009/10/19 18:41:08 bouyer Exp $"); +__RCSID("$NetBSD: pass1.c,v 1.21 2010/02/04 23:55:42 christos Exp $"); #endif #endif /* not lint */ @@ -201,10 +201,9 @@ } lastino = inumber; if (dp->e2di_dtime != 0) { - time_t t = fs2h32(dp->e2di_dtime); - char *p = ctime(&t); - pwarn("INODE I=%llu HAS DTIME=%12.12s %4.4s", - (unsigned long long)inumber, &p[4], &p[20]); + pwarn("INODE I=%llu HAS DTIME=%s", + (unsigned long long)inumber, + print_mtime(fs2h32(dp->e2di_dtime))); if (preen) { printf(" (CORRECTED)\n"); } Index: src/sbin/fsck_ffs/inode.c diff -u src/sbin/fsck_ffs/inode.c:1.62 src/sbin/fsck_ffs/inode.c:1.63 --- src/sbin/fsck_ffs/inode.c:1.62 Sat Apr 11 03:32:42 2009 +++ src/sbin/fsck_ffs/inode.c Thu Feb 4 18:55:43 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: inode.c,v 1.62 2009/04/11 07:32:42 lukem Exp $ */ +/* $NetBSD: inode.c,v 1.63 2010/02/04 23:55:43 christos Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: inode.c,v 1.62 2009/04/11 07:32:42 lukem Exp $"); +__RCSID("$NetBSD: inode.c,v 1.63 2010/02/04 23:55:43 christos Exp $"); #endif #endif /* not lint */ @@ -636,9 +636,7 @@ pinode(ino_t ino) { union dinode *dp; - char *p; struct passwd *pw; - time_t t; printf(" I=%llu ", (unsigned long long)ino); if (ino < ROOTINO || ino > maxino) @@ -655,9 +653,7 @@ if (preen) printf("%s: ", cdevname()); printf("SIZE=%llu ", (unsigned long long)iswap64(DIP(dp, size))); - t = iswap32(DIP(dp, mtime)); - p = ctime(&t); - printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); + printf("MTIME=%s ", print_mtime(iswap32(DIP(dp, mtime)))); } void Index: src/sbin/fsck_lfs/inode.c diff -u src/sbin/fsck_lfs/inode.c:1.40 src/sbin/fsck_lfs/inode.c:1.41 --- src/sbin/fsck_lfs/inode.c:1.40 Thu Oct 9 12:56:23 2008 +++ src/sbin/fsck_lfs/inode.c Thu Feb 4 18:55:43 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: inode.c,v 1.40 2008/10/09 16:56:23 christos Exp $ */ +/* $NetBSD: inode.c,v 1.41 2010/02/04 23:55:43 christos Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -520,9 +520,7 @@ pinode(ino_t ino) { struct ufs1_dinode *dp; - char *p; struct passwd *pw; - time_t t; printf(" I=%llu ", (unsigned long long)ino); if (ino < ROOTINO || ino >= maxino) @@ -540,9 +538,7 @@ if (preen) printf("%s: ", cdevname()); printf("SIZE=%llu ", (unsigned long long) dp->di_size); - t = dp->di_mtime; - p = ctime(&t); - printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); + printf("MTIME=%s ", print_mtime(dp->di_mtime)); } }