History log of /freebsd-current/usr.bin/stat/stat.c
Revision Date Author Comments
# 49eeca74 07-Jan-2024 LO WEN-CHIEN <s111062113@m111.nthu.edu.tw>

stat(1): Fix grammar error in stat.c

Event: Advanced UNIX Programming Course (Fall’23) at NTHU
Pull Request: https://github.com/freebsd/freebsd-src/pull/1014


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# b61a5730 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD

The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 37399d5b 29-Jan-2023 Jamie Landeg-Jones <jamie@catflap.org>

usr.bin/stat: Fix error message formatting.

PR: bin/261657
MFC after: 3 days


# 050e4bca 28-Jan-2023 Alexander Naumochkin <alexander.naumochkin@gmail.com>

stat(1): Do not pass S_IFBLK to devname unconditionally

PR: 269190
Reviewed by: kib
MFC after: 1 week


# 20f8331a 30-Oct-2021 Stefan Eßer <se@FreeBSD.org>

usr.bin/stat: honour locale for "-t %+"

The man page states that "-t %+" prints time information in the same
format as date with no format specifier.

This was not the case, the format used was always that of date for the
POSIX locale.

The fix suggested by the reporter leads to output that matches the
documentation.

Reported by: Jamie Landeg-Jones <jamie@catflap.org>
MFC after: 3 days


# f35f34b1 01-May-2019 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add 'Birth' to 'stat -x' output. Current Linux stat(1)
also includes that.

Reviewed by: cem
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20130


# a04ed761 10-Aug-2018 Conrad Meyer <cem@FreeBSD.org>

stat(1): cache id->name resolution

When invoked on a large list of files, it is most common for a small number of
uids/gids to own most of the results.

Like ls(1), use pwcache(3) to avoid repeatedly looking up the same IDs.

Example microbenchmark and non-scientific results:

$ time (find /usr/src -type f -print0 | xargs -0 stat >/dev/null)

BEFORE:
3.62s user 5.23s system 102% cpu 8.655 total
3.47s user 5.38s system 102% cpu 8.647 total

AFTER:
1.23s user 1.81s system 108% cpu 2.810 total
1.43s user 1.54s system 107% cpu 2.754 total

Does this microbenchmark have any real-world significance? Until a use case
is demonstrated otherwise, I doubt it. Ordinarily I would be resistant to
optimizing pointless microbenchmarks in base utilities (e.g., recent totally
gratuitous changes to yes(1)). However, the pwcache(3) APIs actually
simplify stat(1) logic ever so slightly compared to the raw APIs they wrap,
so I think this is at worst harmless.

PR: 230491
Reported by: Thomas Hurst <tom AT hur.st>
Discussed with: gad@


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# 5d49c30c 25-Apr-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use MIN() instead of MAX() as the previous syntax was wrote in a weird and
confused way: "prec > 9 ? 9 : prec".

Submitted by: pfg, ngie and luke <luke.tw@gmail.com>
MFC after: 2 weeks.


# cadc2836 21-Apr-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use macro MAX() from sys/param.h.

MFC after: 2 weeks.


# 55298f03 11-May-2014 Thomas Quinot <thomas@FreeBSD.org>

Minor fixes to previous change introducing switch -H, as per comments
on -arch.

Reviewed by: gleb


# 4d6bab26 07-May-2014 Thomas Quinot <thomas@FreeBSD.org>

Introduce a new command line switch '-H' for stat(1)
causing arguments to be interpreted as NFS file handles.

Reviewed by: -arch (jhb, eadler)
MFC after: 1 month


# bf70bece 19-Oct-2012 Ed Schouten <ed@FreeBSD.org>

More -Wmissing-variable-declarations fixes.

In addition to adding `static' where possible:

- bin/date: Move `retval' into extern.h to make it visible to date.c.
- bin/ed: Move globally used variables into ed.h.
- sbin/camcontrol: Move `verbose' into camcontrol.h and fix shadow warnings.
- usr.bin/calendar: Remove unneeded variables.
- usr.bin/chat: Make `line' local instead of global.
- usr.bin/elfdump: Comment out unneeded function.
- usr.bin/rlogin: Use _Noreturn instead of __dead2.
- usr.bin/tset: Pull `Ospeed' into extern.h.
- usr.sbin/mfiutil: Put global variables in mfiutil.h.
- usr.sbin/pkg: Remove unused `os_corres'.
- usr.sbin/quotaon, usr.sbin/repquota: Remove unused `qfname'.


# 49399277 10-Feb-2011 Doug Barton <dougb@FreeBSD.org>

Synthesize the change from NetBSD's 1.33:

"Do not crash if a date cannot be represented (localtime returning
NULL), use the Epoch value instead."

Obtained from: njoly@NetBSD.org


# 34aba78b 17-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in the relevant changes from NetBSD's 1.31:

"Use strlcpy, not strncpy, when the desired semantics are strlcpy's
rather than strncpy's."

Note: NetBSD's 1.32 is their adoption of our r216206

Obtained from: dholland@NetBSD.org


# de28c1d6 09-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in the change from OpenBSD's 1.14:

"synchronize synopsis and usage; "-l", "-r", "-s" and "-x" are mutually
exclusive; while here, slightly improve spacing in the source code
so it fits on a 80-column display again.

diff greatly improved by martynas@"

Obtained from: sobrado@OpenBSD.org


# da78facc 05-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in the following changes from NetBSD. See the discussion at:
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=44128

1.29
"Don't printf time_t with %d; fixes PR 44128 from yamt. With this change it
successfully prints mtimes after 2038."

1.30
"Improve previous with comments."

Obtained from: dholland@NetBSD.org (both)


# d7233fd6 05-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Fix an "unused variable" error that gets us all the way to WARNS=6


# 9b3f4394 05-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in the update from NetBSD 1.28:

"Fix WARNS=4 issues (-Wcast-qual -Wsign-compare)"

Because of code differences I had to hand-apply parts of the patch,
so responsibility for errors goes to me.

Obtained from: lukem@NetBSD.org


# b9f9338e 05-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in a new feature, adding a -f option to readlink to print the path
of the target, similar to realpath(1). See the discussion at:
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=34662

This brings in the following changes:
1.24
"PR/34662: martijnb at atlas dot ipv6 dot stack dot nl: readlink doesn't
grok -f, and there's no alternative (+fix)

Patch applied with minor tweak (%y -> %R, as it was already taken) plus
some nits from myself. Thanks!"

Obtained from: elad@NetBSD.org

1.25
"Fix a segfault when doing 'stat -f %R' on the stdin file handle, instead
fake the filename '(stdin)' like the %N format."

Obtained from: mlelstv@NetBSD.org

1.27
"The ofmt variable is actually a bit mask (not the character that was
in the format string) so that we can "or" it with the bits in the
formats variable. This fixes the missing " -> " in front of the real
path (when you use %SR).

Also, the ?: needs another space."

Obtained from: atatat@NetBSD.org

I am purposely omitting the following changes:
1.23 A humanize_number(3) clone that should better be implemented by
actually using humanize_number(3)
1.26 This is the removal of license clause 3 and 4, already handled
by imp in r203971


# 578800b5 05-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in the change from NetBSD 1.22:

"Fix a trivial truncation case, and eliminate a corner case that might
print a nul character."

I am purposely bypassing the following versions:
1.19 A build infrastructure change that does not apply to us
1.20 A feature I am not interested in, but don't object if someone else
wants to pick it up
1.21 A build infrastructure change that does not apply to us

Obtained from: atatat@NetBSD.org


# ccdbe8ce 05-Dec-2010 Doug Barton <dougb@FreeBSD.org>

Bring in the change from NetBSD 1.18:

"If using stat (the -L flag) and it fails, fall back to lstat(). It
may be the case that we're examining a broken symlink, and anything is
better than nothing."

The changes in 1.14 through 1.17 were not relevant to us.

Obtained from: atatat@NetBSD.org


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 5d05d542 01-May-2010 Jilles Tjoelker <jilles@FreeBSD.org>

MFC r207153: stat: Allow -f %Sf to display the file flags symbolically.

PR: 124349


# 24d9be57 24-Apr-2010 Jilles Tjoelker <jilles@FreeBSD.org>

stat: Allow -f %Sf to display the file flags symbolically.

I have changed the patch slightly to show '-' if there are no flags just
like ls -ldo does.

PR: 124349
Submitted by: Ighighi
MFC after: 1 week


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 89f84ab0 16-Feb-2010 Warner Losh <imp@FreeBSD.org>

The NetBSD Foundation has granted permission to remove clause 3 and 4
from their software.

Obtained from: NetBSD


# 42dc9c5a 11-Feb-2009 Ed Schouten <ed@FreeBSD.org>

Let stat(1) use fdevname(3).

Because we now have a reliable library function that converts file
descriptors to character device names, let stat(1) use this. This means
it can now do the following:

$ stat -f %N
/dev/pts/0

I've changed main() to set file properly, so output() is never called
with file set to NULL.

Approved by: dougb (older version, still used devname)


# df8a2f1a 11-Feb-2009 Maxim Konovalov <maxim@FreeBSD.org>

o Print an octal representation of suid, sgid and sticky bits with -x flag.

PR: bin/131569
Submitted by: Jaakko Heinonen
Reported by: Yannick Cadin
MFC after: 1 week


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# dad5d4e0 05-Oct-2003 Doug Barton <dougb@FreeBSD.org>

Resolve conflicts


# a2aef6fe 05-Oct-2003 Doug Barton <dougb@FreeBSD.org>

Import NetBSD's 1.13 version. This contains no functional changes, just
support for cross and host builds on more platforms.

Obtained from: Andrew Brown <atatat@NetBSD.org>, and Luke Mewburn <lukem@NetBSD.org>


# 1cee9d8d 11-May-2003 Doug Barton <dougb@FreeBSD.org>

Import NetBSD's 1.10 version, which includes the ability to display
the new inode birthtime field, a few other small cleanups, and
synchronization with our #include <sys/types.h>.

Approved by: re (bmah)
Obtained from: Andrew Brown <atatat@NetBSD.org>


# 7d5b77ef 25-Oct-2002 Doug Barton <dougb@FreeBSD.org>

Adjust the size passed to readlink so that the null termination
falls within the range of the path variable.

Cribbed from the latest NetBSD source.

Obtained from: provos@NetBSD.org


# 782ce287 14-Aug-2002 Doug Barton <dougb@FreeBSD.org>

I was too conservative with my header changes, so restore some sanity
via bde. atatat@NetBSD.org made basically the same change in their
version, so bring over their CVS Id which I neglected last time.

Obtained from: bde, Andrew Brown <atatat@NetBSD.org>


# 5b812a14 13-Aug-2002 Doug Barton <dougb@FreeBSD.org>

A cooperative effort...

1. Update the code to the latest from NetBSD, which includes:
* A new command line option to suppress stat(2) errors
* Output is now done via stdio
* Fixes for bitwise OR'ing of letters

2. Andrew from NetBSD merged in our own Johan's readlink patches.

3. Andrew also merged in some brucifications.

I made some small contributions to the header cleanup, and tried
to generally improve the overall style(9)'ishness. I also documented
the new -q option and added the *LINKS to the Makefile.

All responsibility for mistakes in merging the contributions
from the above is mine.

Obtained from: Andrew Brown <atatat@NetBSD.org>, bde, johan


# 06b6d7d8 06-Jun-2002 Doug Barton <dougb@FreeBSD.org>

Virgin import of NetBSD's stat(1)