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: > > > > > > 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-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 @@ 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 @@ /* 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 @@ sortfcn = revnamecmp; else if (f_accesstime) sortfcn = revacccmp; + else if (f_birthtime) + sortfcn = revbirthcmp; else if (f_statustime) sortfcn = revstatcmp; else if (f_sizesort) @@ -423,6 +433,8 @@ sortfcn = namecmp; else if (f_accesstime) sortfcn = acccmp; + else if (f_birthtime) + sortfcn = birthcmp; else if (f_statustime) sortfcn = 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 */ 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
pgpiGPUni3N74.pgp
Description: PGP signature