Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Mar 2006 12:06:18 +0000
From:      Ceri Davies <ceri@submonkey.net>
To:        hackers@FreeBSD.org
Subject:   Exposing a file's creation time via find(1)
Message-ID:  <20060324120618.GB17507@submonkey.net>

next in thread | raw e-mail | index | archive | help

--St7VIuEGZ6dlpu13
Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e"
Content-Disposition: inline


--cNdxnHkX5QqsyA0e
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable


While perusing my Daemon book I noticed that it mentioned the existence
of the st_birthtime field in struct stat.  I then also noticed that not
many utilities expose this: the Daemon mentions dump(8), restore(8) and
the only other one I could find was stat(1).

The attached patch adds st_birthtime related primaries to find(1), being
-Bmin, -Btime, -Bnewer et al.  These let you use an inode's real
creation time in find primitives.  I have chosen 'B' over 'b' to match
the format specifier from stat(1).  It seems to do the right thing on UFS
1, 2 and MSDOS file systems, but some more testing would be appreciated.

Cheers,

Ceri
--=20
That must be wonderful!  I don't understand it at all.
                                                  -- Moliere

--cNdxnHkX5QqsyA0e
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="find-Btime.diff"
Content-Transfer-Encoding: quoted-printable

Index: find.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/find/find.1,v
retrieving revision 1.73
diff -u -r1.73 find.1
--- find.1	14 Jun 2005 11:50:51 -0000	1.73
+++ find.1	24 Mar 2006 12:02:04 -0000
@@ -174,6 +174,34 @@
 .El
 .Sh PRIMARIES
 .Bl -tag -width indent
+.It Ic -Bmin Ar n
+True if the difference between the time of a file's inode creation
+and the time
+.Nm
+was started, rounded up to the next full minute, is
+.Ar n
+minutes.
+.It Ic -Bnewer Ar file
+Same as
+.Ic -newerBm .
+.It Ic -Btime Ar n Ns Op Cm smhdw
+If no units are specified, this primary evaluates to
+true if the difference between the time of a file's inode creation
+and the time
+.Nm
+was started, rounded up to the next full 24-hour period, is
+.Ar n
+24-hour periods.
+.Pp
+If units are specified, this primary evaluates to
+true if the difference between the time of last change of file status
+information and the time
+.Nm
+was started is exactly
+.Ar n
+units.
+Please refer to the
+.Ic -atime
 .It Ic -acl
 May be used in conjunction with other options to locate
 files with extended ACLs.
@@ -227,6 +255,7 @@
 or
 .Cm -
 modifier.
+primary description for information on supported time units.
 .It Ic -cmin Ar n
 True if the difference between the time of last change of file status
 information and the time
@@ -497,12 +526,16 @@
 .It Ic -newer Ns Ar X Ns Ar Y Ar file
 True if the current file has a more recent last access time
 .Ar ( X Ns =3D Ns Cm a ) ,
+inode creation time
+.Ar ( X Ns =3D Ns Cm B ) ,
 change time
 .Ar ( X Ns =3D Ns Cm c ) ,
 or modification time
 .Ar ( X Ns =3D Ns Cm m )
 than the last access time
 .Ar ( Y Ns =3D Ns Cm a ) ,
+inode creation time
+.Ar ( Y Ns =3D Ns Cm B ) ,
 change time
 .Ar ( Y Ns =3D Ns Cm c ) ,
 or modification time
Index: find.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/find/find.h,v
retrieving revision 1.17
diff -u -r1.17 find.h
--- find.h	28 May 2004 17:17:15 -0000	1.17
+++ find.h	24 Mar 2006 12:02:04 -0000
@@ -72,6 +72,8 @@
 #define	F_IGNCASE	0x00010000	/* iname ipath iregex */
 #define	F_EXACTTIME	F_IGNCASE	/* -[acm]time units syntax */
 #define F_EXECPLUS	0x00020000	/* -exec ... {} + */
+#define	F_TIME_B	0x00040000	/* one of -Btime, -Bnewer, -newerB* */
+#define	F_TIME2_B	0x00080000	/* one of -newer?B */
=20
 /* node definition */
 typedef struct _plandata {
Index: function.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/find/function.c,v
retrieving revision 1.54
diff -u -r1.54 function.c
--- function.c	25 Aug 2005 13:44:02 -0000	1.54
+++ function.c	24 Mar 2006 12:02:05 -0000
@@ -234,10 +234,10 @@
 } /* nextarg() */
=20
 /*
- * The value of n for the inode times (atime, ctime, and mtime) is a range,
- * i.e. n matches from (n - 1) to n 24 hour periods.  This interacts with
- * -n, such that "-mtime -1" would be less than 0 days, which isn't what t=
he
- * user wanted.  Correct so that -1 is "less than 1".
+ * The value of n for the inode times (atime, birthtime, ctime, mtime) is a
+ * range, i.e. n matches from (n - 1) to n 24 hour periods.  This interacts
+ * with -n, such that "-mtime -1" would be less than 0 days, which isn't w=
hat
+ * the user wanted.  Correct so that -1 is "less than 1".
  */
 #define	TIME_CORRECT(p) \
 	if (((p)->flags & F_ELG_MASK) =3D=3D F_LESSTHAN) \
@@ -248,6 +248,7 @@
  *
  *    True if the difference between the
  *		file access time (-amin)
+ *		file birth time (-Bmin)
  *		last change of file status information (-cmin)
  *		file modification time (-mmin)
  *    and the current time is n min periods.
@@ -261,6 +262,9 @@
 	} else if (plan->flags & F_TIME_A) {
 		COMPARE((now - entry->fts_statp->st_atime +
 		    60 - 1) / 60, plan->t_data);
+	} else if (plan->flags & F_TIME_B) {
+		COMPARE((now - entry->fts_statp->st_birthtime +
+		    60 - 1) / 60, plan->t_data);
 	} else {
 		COMPARE((now - entry->fts_statp->st_mtime +
 		    60 - 1) / 60, plan->t_data);
@@ -287,6 +291,7 @@
  *
  *	True if the difference between the
  *		file access time (-atime)
+ *		file birth time (-Btime)
  *		last change of file status information (-ctime)
  *		file modification time (-mtime)
  *	and the current time is n 24 hour periods.
@@ -299,6 +304,8 @@
=20
 	if (plan->flags & F_TIME_A)
 		xtime =3D entry->fts_statp->st_atime;
+	else if (plan->flags & F_TIME_B)
+		xtime =3D entry->fts_statp->st_birthtime;
 	else if (plan->flags & F_TIME_C)
 		xtime =3D entry->fts_statp->st_ctime;
 	else
@@ -1065,6 +1072,8 @@
 		return entry->fts_statp->st_ctime > plan->t_data;
 	else if (plan->flags & F_TIME_A)
 		return entry->fts_statp->st_atime > plan->t_data;
+	else if (plan->flags & F_TIME_B)
+		return entry->fts_statp->st_birthtime > plan->t_data;
 	else
 		return entry->fts_statp->st_mtime > plan->t_data;
 }
Index: option.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/find/option.c,v
retrieving revision 1.23
diff -u -r1.23 option.c
--- option.c	29 Jul 2004 03:29:44 -0000	1.23
+++ option.c	24 Mar 2006 12:02:05 -0000
@@ -68,6 +68,9 @@
 	{ "-and",	c_and,		NULL,		0 },
 	{ "-anewer",	c_newer,	f_newer,	F_TIME_A },
 	{ "-atime",	c_Xtime,	f_Xtime,	F_TIME_A },
+	{ "-Bmin",	c_Xmin,		f_Xmin,		F_TIME_B },
+	{ "-Bnewer",	c_newer,	f_newer,	F_TIME_B },
+	{ "-Btime",	c_Xtime,	f_Xtime,	F_TIME_B },
 	{ "-cmin",	c_Xmin,		f_Xmin,		F_TIME_C },
 	{ "-cnewer",	c_newer,	f_newer,	F_TIME_C },
 	{ "-ctime",	c_Xtime,	f_Xtime,	F_TIME_C },
@@ -95,14 +98,22 @@
 	{ "-name",	c_name,		f_name,		0 },
 	{ "-newer",	c_newer,	f_newer,	0 },
 	{ "-neweraa",	c_newer,	f_newer,	F_TIME_A | F_TIME2_A },
+	{ "-neweraB",	c_newer,	f_newer,	F_TIME_A | F_TIME2_B },
 	{ "-newerac",	c_newer,	f_newer,	F_TIME_A | F_TIME2_C },
 	{ "-neweram",	c_newer,	f_newer,	F_TIME_A },
 	{ "-newerat",	c_newer,	f_newer,	F_TIME_A | F_TIME2_T },
+	{ "-newerBa",	c_newer,	f_newer,	F_TIME_B | F_TIME2_A },
+	{ "-newerBB",	c_newer,	f_newer,	F_TIME_B | F_TIME2_B },
+	{ "-newerBc",	c_newer,	f_newer,	F_TIME_B | F_TIME2_C },
+	{ "-newerBm",	c_newer,	f_newer,	F_TIME_B },
+	{ "-newerBt",	c_newer,	f_newer,	F_TIME_B | F_TIME2_T },
 	{ "-newerca",	c_newer,	f_newer,	F_TIME_C | F_TIME2_A },
+	{ "-newercB",	c_newer,	f_newer,	F_TIME_C | F_TIME2_B },
 	{ "-newercc",	c_newer,	f_newer,	F_TIME_C | F_TIME2_C },
 	{ "-newercm",	c_newer,	f_newer,	F_TIME_C },
 	{ "-newerct",	c_newer,	f_newer,	F_TIME_C | F_TIME2_T },
 	{ "-newerma",	c_newer,	f_newer,	F_TIME2_A },
+	{ "-newermB",	c_newer,	f_newer,	F_TIME2_B },
 	{ "-newermc",	c_newer,	f_newer,	F_TIME2_C },
 	{ "-newermm",	c_newer,	f_newer,	0 },
 	{ "-newermt",	c_newer,	f_newer,	F_TIME2_T },

--cNdxnHkX5QqsyA0e--

--St7VIuEGZ6dlpu13
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (FreeBSD)

iD8DBQFEI+C6ocfcwTS3JF8RAgapAJ4yVyh2JDnop0VBb+iJrY54s9O1oACgl57A
SuKzfyjowVwqbZyaZuO+t6s=
=o0xB
-----END PGP SIGNATURE-----

--St7VIuEGZ6dlpu13--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060324120618.GB17507>