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
This commit is contained in:
Jiajie Chen 2023-01-24 00:36:59 +08:00 committed by Mateusz Guzik
parent 8089749d38
commit dec7db4960
2 changed files with 4 additions and 1 deletions

View File

@ -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);
}

View File

@ -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. */