git: dec7db49602d - main - Add kf_file_nlink field to kf_file and populate it
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Jan 2023 18:13:59 UTC
The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=dec7db49602df75119f6b57d32f1eb58e0040abc commit dec7db49602df75119f6b57d32f1eb58e0040abc Author: Jiajie Chen <c@jia.je> AuthorDate: 2023-01-23 16:36:59 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2023-01-23 17:09:52 +0000 Add kf_file_nlink field to kf_file and populate it This will allow user-space programs (e.g. lsof) to locate deleted files whose nlink equals zero. Prior to this commit, programs has to use stat(kf_path) to get nlink, but that will fail if the file is deleted. [mjg: s/fail/file in the commit message] Reviewed by: mjg Differential Revision: https://reviews.freebsd.org/D38169 --- sys/kern/vfs_vnops.c | 1 + sys/sys/user.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 48d15ce6ab25..a49070b6060d 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -2792,6 +2792,7 @@ vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif) kif->kf_un.kf_file.kf_file_rdev = va.va_rdev; kif->kf_un.kf_file.kf_file_rdev_freebsd11 = kif->kf_un.kf_file.kf_file_rdev; /* truncate */ + kif->kf_un.kf_file.kf_file_nlink = va.va_nlink; return (0); } diff --git a/sys/sys/user.h b/sys/sys/user.h index edbe6a8655ff..42799a70fbfc 100644 --- a/sys/sys/user.h +++ b/sys/sys/user.h @@ -389,7 +389,9 @@ struct kinfo_file { int kf_file_type; /* Space for future use */ int kf_spareint[3]; - uint64_t kf_spareint64[30]; + uint64_t kf_spareint64[29]; + /* Number of references to file. */ + uint64_t kf_file_nlink; /* Vnode filesystem id. */ uint64_t kf_file_fsid; /* File device. */