Re: Exposing a file's creation time via find(1)
On Fri, Mar 24, 2006 at 12:06:18PM +, Ceri Davies wrote: 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. 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 Ceri -- That must be wonderful! I don't understand it at all. -- Moliere pgpO9ttWPUjTV.pgp Description: PGP signature
Re: Exposing a file's creation time via find(1)
On Friday 24 March 2006 08:55, Ceri Davies wrote: On Fri, Mar 24, 2006 at 12:06:18PM +, Ceri Davies wrote: 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. 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 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 -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Exposing a file's creation time via find(1)
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 +, Ceri Davies wrote: 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. 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 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 -- That must be wonderful! I don't understand it at all. -- Moliere # 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 @@ } 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) { --- /usr/src/bin/ls/extern.h-OLDFri Jun 3 16:12:35 2005 +++ /usr/src/bin/ls/extern.hThu Jul 7 03:51:38 2005 @@ -32,6 +32,8 @@ 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-OLDFri Jun 3 16:12:35 2005 +++ /usr/src/bin/ls/ls.1Thu 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.cThu Nov 10 15:15:31 2005 @@ -104,6 +104,7 @@ /* 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 @@ fts_options = FTS_PHYSICAL; while ((ch = getopt(argc, argv, - 1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx)) != -1) { + 1ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx)) != -1) { switch (ch) { /* * The -1, -C, -x and -l options all override each other so @@ -208,14 +209,21 @@ f_longform = 0; f_singlecol = 0; break; - /* The -c and -u options override each other. */ + /* The -c -u and -U options override each other. */ case 'c': f_statustime = 1; f_accesstime = 0; + f_birthtime = 0; break; case 'u': f_accesstime = 1; f_statustime = 0; + f_birthtime = 0; + break; + case 'U': + f_birthtime = 1; + f_accesstime = 0; + f_statustime = 0; break; case 'F': f_type = 1; @@ -412,6 +420,8 @@
Re: Exposing a file's creation time via find(1)
On Friday 24 March 2006 11:50, Ceri Davies wrote: 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 +, Ceri Davies wrote: 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. 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 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. Yeah, I just committed it, so you don't have to worry about that bikeshed. :) -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]