History log of /freebsd-10.0-release/usr.bin/fstat/fstat.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 259065 07-Dec-2013 gjb

- Copy stable/10 (r259064) to releng/10.0 as part of the
10.0-RELEASE cycle.
- Update __FreeBSD_version [1]
- Set branch name to -RC1

[1] 10.0-CURRENT __FreeBSD_version value ended at '55', so
start releng/10.0 at '100' so the branch is started with
a value ending in zero.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 250223 03-May-2013 jhb

Similar to 233760 and 236717, export some more useful info about the
kernel-based POSIX semaphore descriptors to userland via procstat(1) and
fstat(1):
- Change sem file descriptors to track the pathname they are associated
with and add a ksem_info() method to copy the path out to a
caller-supplied buffer.
- Use the fo_stat() method of shared memory objects and ksem_info() to
export the path, mode, and value of a semaphore via struct kinfo_file.
- Add a struct semstat to the libprocstat(3) interface along with a
procstat_get_sem_info() to export the mode and value of a semaphore.
- Teach fstat about semaphores and to display their path, mode, and value.

MFC after: 2 weeks


# 235602 18-May-2012 gleb

Don't cast inode number or file size down to long or unsigned.

Since ino_t size is about to change to 64-bits, casts to long would
truncate 64-bit numbers on 32-bit archs.

Sponsored by: Google Summer of Code 2011


# 233760 01-Apr-2012 jhb

Export some more useful info about shared memory objects to userland
via procstat(1) and fstat(1):
- Change shm file descriptors to track the pathname they are associated
with and add a shm_path() method to copy the path out to a caller-supplied
buffer.
- Use the fo_stat() method of shared memory objects and shm_path() to
export the path, mode, and size of a shared memory object via
struct kinfo_file.
- Add a struct shmstat to the libprocstat(3) interface along with a
procstat_get_shm_info() to export the mode and size of a shared memory
object.
- Change procstat to always print out the path for a given object if it
is valid.
- Teach fstat about shared memory objects and to display their path,
mode, and size.

MFC after: 2 weeks


# 232233 27-Feb-2012 pluknet

Backout r230934 which didn't work with unix sockets and
several filesystem layers mounted at the specified path.

Pointy hat to: pluknet


# 230934 03-Feb-2012 pluknet

Print the owner process for unix domain sockets when restricted to the
specified files.

PR: bin/143962
MFC after: 2 weeks


# 228992 30-Dec-2011 uqs

Spelling fixes for usr.bin/


# 227239 06-Nov-2011 ed

Mark global functions and/or variables in fstat(1) static where possible.

This allows compilers and static analyzers to more thorough analysis.


# 225893 01-Oct-2011 ed

Correct column with for device numbers made in previous change.

The device number should be displayed using only five columns -- not eight.


# 225847 28-Sep-2011 ed

Get rid of major/minor number distinction.

As of FreeBSD 6, devices can only be opened through devfs. These device
nodes don't have major and minor numbers anymore. The st_rdev field in
struct stat is simply based a copy of st_ino.

Simply display device numbers as hexadecimal, using "%#jx". This is
allowed by POSIX, since it explicitly states things like the following
(example taken from ls(1)):

"If the file is a character special or block special file, the
size of the file may be replaced with implementation-defined
information associated with the device in question."

This makes the output of these commands more compact. For example, ls(1)
now uses approximately four columns less. While there, simplify the
column length calculation from ls(1) by calling snprintf() with a NULL
buffer.

Don't be afraid; if needed one can still obtain individual major/minor
numbers using stat(1).


# 221819 12-May-2011 imp

uintmax_t is a better type here...

Submitted by: avg@


# 221816 12-May-2011 imp

Fix printf int mismatch on 32-bit architectures...


# 221807 12-May-2011 stas

- Commit work from libprocstat project. These patches add support for runtime
file and processes information retrieval from the running kernel via sysctl
in the form of new library, libprocstat. The library also supports KVM backend
for analyzing memory crash dumps. Both procstat(1) and fstat(1) utilities have
been modified to take advantage of the library (as the bonus point the fstat(1)
utility no longer need superuser privileges to operate), and the procstat(1)
utility is now able to display information from memory dumps as well.

The newly introduced fuser(1) utility also uses this library and able to operate
via sysctl and kvm backends.

The library is by no means complete (e.g. KVM backend is missing vnode name
resolution routines, and there're no manpages for the library itself) so I
plan to improve it further. I'm commiting it so it will get wider exposure
and review.

We won't be able to MFC this work as it relies on changes in HEAD, which
was introduced some time ago, that break kernel ABI. OTOH we may be able
to merge the library with KVM backend if we really need it there.

Discussed with: rwatson


# 216370 11-Dec-2010 joel

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# 196399 20-Aug-2009 avg

fstat: fix fsid comparison when executed on systems with 64-bit long

This affects only fstat on zfs and devfs, only on 64-bit systems
and only when fsid is greater than 2^31 - 1.
When fstat examines a file via stat(2) it takes uint32_t st_dev
and assigns to (signed) (64-bit) long fsid, this results in
a positive value.
When fstat examines opened files it takes int32_t f_fsid.val[0]
and assigns to (signed) (64-bit) long fsid, this results in
a negative value.
So, while initially st_dev and f_fsid.val[0] have the same bit
values they get promoted to different 64-bit values because
of the signed-vs-unsigned difference.

A fix is to use "more natural" positive numbers by introducing
intermediate unsigned cast for f_fsid.val[0].

Reviewed by: jhb, lulf
Approved by: re (kib)
MFC after: 1 week (to stable/7)


# 194880 24-Jun-2009 dfr

Don't use sys/nfs/rpcv2.h - it is part of the old kernel RPC implementation
and will be removed.


# 181905 20-Aug-2008 ed

Integrate the new MPSAFE TTY layer to the FreeBSD operating system.

The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:

- Improved driver model:

The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.

If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.

- Improved hotplugging:

With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).

The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.

- Improved performance:

One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.

Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.

Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan


# 179828 16-Jun-2008 kib

Struct cdev is always the member of the struct cdev_priv. When devfs
needed to promote cdev to cdev_priv, the si_priv pointer was followed.

Use member2struct() to calculate address of the wrapping cdev_priv.
Rename si_priv to __si_reserved.

Tested by: pho
Reviewed by: ed
MFC after: 2 weeks


# 179759 12-Jun-2008 ed

Fix build of fstat after minor() changes.

Even though I ran a `make universe' to see whether the changes to the
device minor number macro's broke the build, I was not expecting `make
universe' to silently continue if build errors occured, thus causing me
to overlook the build error.

Approved by: philip (mentor)
Pointyhat to: me


# 179320 26-May-2008 pjd

Use _WANT_FILE to make struct file visible from userland. This is
similar to _WANT_UCRED and _WANT_PRISON and seems to be much nicer than
defining _KERNEL.
It is also needed for my sys/refcount.h change going in soon.


# 178831 07-May-2008 jhb

Only output details about the current working directory of a process if
the vnode pointer is not NULL. This avoids spurious warnings in fstat -v
output for kernel processes.

MFC after: 1 week
PR: amd64/123456
Submitted by: KOIE Hidetaka | hide koie.org


# 173376 05-Nov-2007 lulf

- Add ZFS-support to fstat(1). This allows ZFS-filsystems to be including in
the open file-listing. It is added as a separate source file, so it can
respect WITH_/WITHOUT_CDDL as compile-flags.
- The warnlevel of the Makefile was decreased to quell solaris #pragma
warnings.
- Expect that fstat(1) doesn't work with kernel compiled with
DEBUG_VFS_LOCKS/DEBUG_LOCKS for now.

Approved by: pjd (mentor)


# 167367 09-Mar-2007 emaste

KERN_PROC_ALL produces a kinfo_proc for each thread in a process, which
caused fstat to produce duplicated output for threaded processes. Instead
use KERN_PROC_PROC to get just one kinfo_proc per process.

MFC After: 2 weeks


# 154152 09-Jan-2006 tegge

Add marker vnodes to ensure that all vnodes associated with the mount point are
iterated over when using MNT_VNODE_FOREACH.

Reviewed by: truckman


# 152105 05-Nov-2005 csjp

Un-break processing of device major/minor values with fstat -n. We do
this by accessing the cdev_priv element of the cdev structure. Looking
forward we need a better way to handle this, as this structure shouldn't
be frobbed by userspace.

Submitted by: Doug Steinwand
PR: bin/88203
MFC after: 1 week
Discussed with: phk


# 148573 30-Jul-2005 csjp

Introduce kdevtoname, which when given the kernel address of a
cdev structure, returns the device name associated with it through
the __si_namebuf member. This un-breaks the processing of devices.

This is a RELENG_6 candidate.

Reviewed by: phk


# 146466 21-May-2005 ru

Sync program's usage() with manpage's SYNOPSIS.


# 143651 15-Mar-2005 phk

Dike out unwarranted si_udev fondling.


# 140958 29-Jan-2005 phk

Report jail directory if set.

Sanity-check fd_lastfile.

PR: 62699
Patch by: "Mark W. Krentel" <krentel@dreamscape.com>


# 140078 11-Jan-2005 ssouhlal

Get the vnode from file.f_vnode instead of file.f_data.

Nowadays, f_data points to the vnode only if the underlying filesystem
doesn't use it for other purposes (devfs uses it to store the cdev,
for example).

Found by: csjp
Reviewed by: csjp
Approved by: phk, wes, grehan (mentor)
MFC after: 1 week


# 137352 07-Nov-2004 phk

filedesc0 is an internal detail of the kernel, don't look at it.


# 132477 21-Jul-2004 silby

Slide pipe.h include after the _KERNEL define in preparation for disallowing
non-_KERNEL inclusions of pipe.h


# 131293 29-Jun-2004 dwmalone

1) ANSIfy.
2) Use %p to print a pointer.
3) Use longs for fileids and ino to avoid comparing signed and unsigned.
4) Make the KVM_READ macro a little more cranky.
5) Set WARNS while I'm here.


# 130640 17-Jun-2004 phk

Second half of the dev_t cleanup.

The big lines are:
NODEV -> NULL
NOUDEV -> NODEV
udev_t -> dev_t
udev2dev() -> findcdev()

Various minor adjustments including handling of userland access to kernel
space struct cdev etc.


# 130489 14-Jun-2004 rwatson

Teach fstat(1) about new location for socket state flags relating to
socket buffer state.

Submitted by: rik
Reminded by: le


# 116780 24-Jun-2003 jmg

fix this code properly. msdosfs can't have device nodes on them.
comment how to read device nodes from ufs (if an adventurous soul wants
to fix it!).

Reviewed by: bde


# 116717 23-Jun-2003 maxim

o Fix rev. 1.41, print a header. -STABLE is OK.

PR: bin/53585
Submitted by: Alexey Dokuchaev <danfe@regency.nsu.ru>


# 116556 19-Jun-2003 jmg

correct spelling of struct cdev * from dev_t which is a 32bit type and
isn't very useful for passing pointers on LP64 systems.

device names on sparc64 and alpha should now work.


# 109153 12-Jan-2003 dillon

Bow to the whining masses and change a union back into void *. Retain
removal of unnecessary casts and throw in some minor cleanups to see if
anyone complains, just for the hell of it.


# 109123 11-Jan-2003 dillon

Change struct file f_data to un_data, a union of the correct struct
pointer types, and remove a huge number of casts from code using it.

Change struct xfile xf_data to xun_data (ABI is still compatible).

If we need to add a #define for f_data and xf_data we can, but I don't
think it will be necessary. There are no operational changes in this
commit.


# 104043 27-Sep-2002 phk

Rename struct specinfo to the more appropriate struct cdev.

Agreed on: jake, rwatson, jhb


# 103325 14-Sep-2002 njl

Userland changes to go with vnode->v_tag change.


# 101872 14-Aug-2002 bmilekic

Unbreak building of fstat following version 1.23 of
src/sys/ufs/ufs/quota.h by including mount.h before ufs/quota.h.


# 99112 30-Jun-2002 obrien

Consistently use FBSDID


# 98542 21-Jun-2002 mckusick

This commit adds basic support for the UFS2 filesystem. The UFS2
filesystem expands the inode to 256 bytes to make space for 64-bit
block pointers. It also adds a file-creation time field, an ability
to use jumbo blocks per inode to allow extent like pointer density,
and space for extended attributes (up to twice the filesystem block
size worth of attributes, e.g., on a 16K filesystem, there is space
for 32K of attributes). UFS2 fully supports and runs existing UFS1
filesystems. New filesystems built using newfs can be built in either
UFS1 or UFS2 format using the -O option. In this commit UFS1 is
the default format, so if you want to build UFS2 format filesystems,
you must specify -O 2. This default will be changed to UFS2 when
UFS2 proves itself to be stable. In this commit the boot code for
reading UFS2 filesystems is not compiled (see /sys/boot/common/ufsread.c)
as there is insufficient space in the boot block. Once the size of the
boot block is increased, this code can be defined.

Things to note: the definition of SBSIZE has changed to SBLOCKSIZE.
The header file <ufs/ufs/dinode.h> must be included before
<ufs/ffs/fs.h> so as to get the definitions of ufs2_daddr_t and
ufs_lbn_t.

Still TODO:
Verify that the first level bootstraps work for all the architectures.
Convert the utility ffsinfo to understand UFS2 and test growfs.
Add support for the extended attribute storage. Update soft updates
to ensure integrity of extended attribute storage. Switch the
current extended attribute interfaces to use the extended attribute
storage. Add the extent like functionality (framework is there,
but is currently never used).

Sponsored by: DARPA & NAI Labs.
Reviewed by: Poul-Henning Kamp <phk@freebsd.org>


# 97946 06-Jun-2002 des

Factor out some code in preparation for un-kmeming fstat(1).

Sponsored by: DARPA, NAI Labs


# 93427 30-Mar-2002 dwmalone

Fix constness warnings.
Remove register keyword.
Don't initialise "badtype" in declaration - it was initialised below anyway.
Remove prototype for strcpy.


# 92920 21-Mar-2002 imp

remove __P


# 88051 17-Dec-2001 green

Add support for devfs. In other words, for -CURRENT, make work at all
again for normal device nodes.


# 86100 05-Nov-2001 dwmalone

Anding the fsid with 0xffff was causing aliasing problems.

PR: 17405, 16320
Submitted by: Mark W. Krentel <krentel@dreamscape.com>
Submitted by: Peter Edwards <peter.edwards@ireland.com>
MFC after: 2 weeks


# 84768 10-Oct-2001 bde

Compensate for "Compensate for header dethreading" by backing it out.


# 83653 18-Sep-2001 peter

Userland part of nfs client/server split and cleanup.


# 82664 31-Aug-2001 ru

SECURITY: Drop `setgid kmem' bit as early as possible.


# 80355 25-Jul-2001 mjacob

Fix 64 bit issues so that sockstat && fstat work correctly on alpha.

PR: 29231
Submitted by: pherman@frenchfries.net
MFC after: 2 weeks


# 78401 18-Jun-2001 roam

Teach fstat(1) about FIFO's - it's OK to display them as regular files.
While I'm here, fix two second-level indents to be four spaces.

Reviewed by: dd, -audit


# 77435 29-May-2001 phk

Remove MFS


# 77099 23-May-2001 phk

define _KERNEL before including <sys/conf.h>


# 76169 01-May-2001 markm

Compensate for header dethreading.


# 76117 29-Apr-2001 grog

Revert consequences of changes to mount.h, part 2.

Requested by: bde


# 75853 23-Apr-2001 grog

Include correct header files, in preparation for fixing sys/mount.h.

Suggested-by: phk


# 72527 15-Feb-2001 iedowse

Fix `fstat -m' (show memory-mapped files), which was broken by
revision 1.25. When evaluating the termination condition for the
iteration over all map entries, we must take care to use the kernel
versions of all pointers. The code was comparing a kernel pointer
to a pointer within a local variable, so the loop never terminated.


# 69896 12-Dec-2000 mckusick

Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.


# 69564 04-Dec-2000 alfred

remove struct mount from useland visibility


# 59029 05-Apr-2000 green

Add a new options: -m enables searching for memory-mapped files.

It is not default because it's an expensive option by nature, making the
search take 2-3 times as long.

PR: 17555
Submitted by: Ian Dowse <iedowse@maths.tcd.ie>


# 58125 16-Mar-2000 green

Support more filesystems in fstat(1): now you can use fstat(1) to
find out if files on msdosfs and cd9660 filestores are open.
There was also a movement of some common things to a header, a
small cleanup.

PR: bin/16364 bin/7043
Submitted by: Peter Edwards <peter.edwards@openet-telecom.com>


# 57345 19-Feb-2000 shin

Fixed a little bit strange INET6 output.

Specified by: Ben Smithurst <ben@scientia.demon.co.uk>
Approved by: jkh


# 55206 29-Dec-1999 peter

Change #ifdef KERNEL to #ifdef _KERNEL in the public headers. "KERNEL"
is an application space macro and the applications are supposed to be free
to use it as they please (but cannot). This is consistant with the other
BSD's who made this change quite some time ago. More commits to come.


# 53133 13-Nov-1999 green

Make fstat work with file arguments again after being broken by dev_t
changes. Thanks, Mr. Edwards!

Submitted by: Peter Edwards <peter.edwards@ireland.com>


# 50477 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 48463 02-Jul-1999 ru

o use getprotobynumber(3) instead of hardcoded protocol names.
Divert(4) sockets will now appear as "internet raw divert"
instead of "internet raw 254".

o -Wall tweak.

Reviewed by: bde


# 37453 06-Jul-1998 bde

Fixed printf format errors.


# 36110 16-May-1998 markm

Include correct header to get definition of struct sockaddr_un.


# 29592 18-Sep-1997 dima

Fix argument string for getopt.

Submitted by: dillon@best.net


# 28948 30-Aug-1997 alex

Display file size as an unsigned long.


# 27311 10-Jul-1997 charnier

Typo.


# 27272 08-Jul-1997 charnier

Use err(3).


# 24382 29-Mar-1997 bde

Removed `#define KERNEL'. This was a hack-around for nfs.h being broken
in the Lite2 merge to not export some nfs constants. It started causing
warnings when I added a kernel-only #define for DIRBLKSIZ.

Removed `#define NFS'. This was an old, bad interface for telling
<sys/mount.h> to export nfs stuff.


# 24360 29-Mar-1997 imp

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 23693 11-Mar-1997 peter

Merge from Lite2


# 18570 29-Sep-1996 bde

Include <fcntl.h> so that this doesn't depend on the KERNEL version
of <sys/file.h> including <sys/fcntl.h>. Only the !KERNEL version
of <sys/file.h> will do that when I unspam the kernel headers.


# 17813 24-Aug-1996 peter

Locate the text inode, closes PR#1070


# 17808 24-Aug-1996 peter

Quick attempt to decode DTYPE_PIPE files and print something meaningful
for them. Otherwise, it does strange things when it hits one..


# 9336 27-Jun-1995 dfr

Changes to support version 3 of the NFS protocol.
The version 2 support has been tested (client+server) against FreeBSD-2.0,
IRIX 5.3 and FreeBSD-current (using a loopback mount). The version 2 support
is stable AFAIK.
The version 3 support has been tested with a loopback mount and minimally
against an IRIX 5.3 server. It needs more testing and may have problems.
I have patched amd to support the new variable length filehandles although
it will still only use version 2 of the protocol.

Before booting a kernel with these changes, nfs clients will need to at least
build and install /usr/sbin/mount_nfs. Servers will need to build and
install /usr/sbin/mountd.

NFS diskless support is untested.

Obtained from: Rick Macklem <rick@snowhite.cis.uoguelph.ca>


# 8874 30-May-1995 rgrimes

Remove trailing whitespace.


# 7726 09-Apr-1995 dg

Added #include <sys/queue.h>


# 1591 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1590,
which included commits to RCS files with non-trunk default branches.


# 1590 27-May-1994 rgrimes

BSD 4.4 Lite Usr.bin Sources