Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Mar 2006 16:50:59 +0000
From:      Ceri Davies <ceri@submonkey.net>
To:        John Baldwin <jhb@freebsd.org>
Cc:        hackers@freebsd.org
Subject:   Re: Exposing a file's creation time via find(1)
Message-ID:  <20060324165059.GC15948@submonkey.net>
In-Reply-To: <200603241041.00233.jhb@freebsd.org>
References:  <20060324120618.GB17507@submonkey.net> <20060324135528.GA15948@submonkey.net> <200603241041.00233.jhb@freebsd.org>

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

--qFgkTsE6LiHkLPZw
Content-Type: multipart/mixed; boundary="bajzpZikUji1w+G9"
Content-Disposition: inline


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

On Fri, Mar 24, 2006 at 10:40:58AM -0500, John Baldwin wrote:
> On Friday 24 March 2006 08:55, Ceri Davies wrote:
> > On Fri, Mar 24, 2006 at 12:06:18PM +0000, Ceri Davies wrote:
> > >=20
> > > While perusing my Daemon book I noticed that it mentioned the existen=
ce
> > > of the st_birthtime field in struct stat.  I then also noticed that n=
ot
> > > many utilities expose this: the Daemon mentions dump(8), restore(8) a=
nd
> > > the only other one I could find was stat(1).
> > >=20
> > > The attached patch adds st_birthtime related primaries to find(1), be=
ing
> > > -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 appreciat=
ed.
> >=20
> > Note that there is a line out of place in the manpage diff - this is
> > corrected in a later version of the patch at
> > http://people.FreeBSD.org/~ceri/find-Btime.diff
>=20
> Could you add a new flag to ls to use birthtime for -t while you are at
> it?  Good luck finding a flag to use though. :-P

That's the exact reason I didn't do it this round :)

Andrzej Tobola sent me this patch for ls -U pretty much immediately.

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

--bajzpZikUji1w+G9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=ls-U
Content-Transfer-Encoding: quoted-printable

# Dodanie do ls opcji -U - sortowanie po czasie kreacji
# Provide option -U - sort by time of file/directory creation

--- /usr/src/bin/ls/cmp.c-OLD	Fri Jun  3 16:12:35 2005
+++ /usr/src/bin/ls/cmp.c	Thu Jul  7 03:56:55 2005
@@ -115,6 +115,32 @@
 }
=20
 int
+birthcmp(const FTSENT *a, const FTSENT *b)
+{
+
+	if (b->fts_statp->st_birthtimespec.tv_sec >
+	    a->fts_statp->st_birthtimespec.tv_sec)
+		return (1);
+	if (b->fts_statp->st_birthtimespec.tv_sec <
+	    a->fts_statp->st_birthtimespec.tv_sec)
+		return (-1);
+	if (b->fts_statp->st_birthtimespec.tv_nsec >
+	    a->fts_statp->st_birthtimespec.tv_nsec)
+		return (1);
+	if (b->fts_statp->st_birthtimespec.tv_nsec <
+	    a->fts_statp->st_birthtimespec.tv_nsec)
+		return (-1);
+	return (strcoll(a->fts_name, b->fts_name));
+}
+
+int
+revbirthcmp(const FTSENT *a, const FTSENT *b)
+{
+
+	return (birthcmp(b, a));
+}
+
+int
 statcmp(const FTSENT *a, const FTSENT *b)
 {
=20
--- /usr/src/bin/ls/extern.h-OLD	Fri Jun  3 16:12:35 2005
+++ /usr/src/bin/ls/extern.h	Thu Jul  7 03:51:38 2005
@@ -32,6 +32,8 @@
=20
 int	 acccmp(const FTSENT *, const FTSENT *);
 int	 revacccmp(const FTSENT *, const FTSENT *);
+int	 birthcmp(const FTSENT *, const FTSENT *);
+int	 revbirthcmp(const FTSENT *, const FTSENT *);
 int	 modcmp(const FTSENT *, const FTSENT *);
 int	 revmodcmp(const FTSENT *, const FTSENT *);
 int	 namecmp(const FTSENT *, const FTSENT *);
--- /usr/src/bin/ls/ls.1-OLD	Fri Jun  3 16:12:35 2005
+++ /usr/src/bin/ls/ls.1	Thu Jul  7 04:03:27 2005
@@ -143,6 +143,8 @@
 .Dq ell )
 option, display complete time information for the file, including
 month, day, hour, minute, second, and year.
+.It Fl U
+Use time when file was created for sorting or printing.
 .It Fl W
 Display whiteouts when scanning directories.
 .It Fl Z

--- /usr/src/bin/ls/ls.c.orig	Thu Nov 10 05:44:07 2005
+++ /usr/src/bin/ls/ls.c	Thu Nov 10 15:15:31 2005
@@ -104,6 +104,7 @@
=20
 /* flags */
        int f_accesstime;	/* use time of last access */
+       int f_birthtime;		/* use time of birth */
        int f_flags;		/* show flags associated with a file */
        int f_humanval;		/* show human-readable file sizes */
        int f_inode;		/* print inode */
@@ -179,7 +180,7 @@
=20
 	fts_options =3D FTS_PHYSICAL;
  	while ((ch =3D getopt(argc, argv,
-	    "1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) !=3D -1) {
+	    "1ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx")) !=3D -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C, -x and -l options all override each other so
@@ -208,14 +209,21 @@
 			f_longform =3D 0;
 			f_singlecol =3D 0;
 			break;
-		/* The -c and -u options override each other. */
+		/* The -c -u and -U options override each other. */
 		case 'c':
 			f_statustime =3D 1;
 			f_accesstime =3D 0;
+			f_birthtime =3D 0;
 			break;
 		case 'u':
 			f_accesstime =3D 1;
 			f_statustime =3D 0;
+			f_birthtime =3D 0;
+			break;
+		case 'U':
+			f_birthtime =3D 1;
+			f_accesstime =3D 0;
+			f_statustime =3D 0;
 			break;
 		case 'F':
 			f_type =3D 1;
@@ -412,6 +420,8 @@
 			sortfcn =3D revnamecmp;
 		else if (f_accesstime)
 			sortfcn =3D revacccmp;
+		else if (f_birthtime)
+			sortfcn =3D revbirthcmp;
 		else if (f_statustime)
 			sortfcn =3D revstatcmp;
 		else if (f_sizesort)
@@ -423,6 +433,8 @@
 			sortfcn =3D namecmp;
 		else if (f_accesstime)
 			sortfcn =3D acccmp;
+		else if (f_birthtime)
+			sortfcn =3D birthcmp;
 		else if (f_statustime)
 			sortfcn =3D statcmp;
 		else if (f_sizesort)

--- /usr/src/bin/ls/ls.h-OLD	Mon Jan 10 21:06:05 2005
+++ /usr/src/bin/ls/ls.h	Thu Jul  7 03:53:17 2005
@@ -38,6 +38,7 @@
 extern long blocksize;		/* block size units */
=20
 extern int f_accesstime;	/* use time of last access */
+extern int f_birthtime;	/* use time of file creation */
 extern int f_flags;		/* show flags associated with a file */
 extern int f_humanval;		/* show human-readable file sizes */
 extern int f_label;		/* show MAC label */

--- /usr/src/bin/ls/util.c.orig	Wed Nov 16 13:00:04 2005
+++ /usr/src/bin/ls/util.c	Wed Nov 16 14:31:10 2005
@@ -222,9 +222,9 @@
 {
 	(void)fprintf(stderr,
 #ifdef COLORLS
-	"usage: ls [-ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1]"
+	"usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1]"
 #else
-	"usage: ls [-ABCFHILPRSTWZabcdfghiklmnopqrstuwx1]"
+	"usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuwx1]"
 #endif
 		      " [file ...]\n");
 	exit(1);
--- /usr/src/bin/ls/print.c-OLD	Mon Jan 10 21:06:05 2005
+++ /usr/src/bin/ls/print.c	Thu Jul  7 04:13:43 2005
@@ -190,6 +190,8 @@
 			printsize(dp->s_size, sp->st_size);
 		if (f_accesstime)
 			printtime(sp->st_atime);
+		else if (f_birthtime)
+			printtime(sp->st_birthtime);
 		else if (f_statustime)
 			printtime(sp->st_ctime);
 		else

--bajzpZikUji1w+G9--

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

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

iD8DBQFEJCNzocfcwTS3JF8RAq4eAKCSTknb86mkhlEz+wudS2gOxkJJQgCfVcyw
apn671BsxR1jO0kcg5PSj9c=
=DL1T
-----END PGP SIGNATURE-----

--qFgkTsE6LiHkLPZw--



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