From 152b2be9793a84eb6000cf86ce768d6da37c4508 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Mon, 16 Jun 2025 20:26:13 +0100 Subject: [PATCH 1/9] sys/mount.h: Hoist sys/types.h include Summary: This header uses various types that come from here regardless of whether _KERNEL is defined, so unconditionally include it rather than relying on other headers implicitly including it for when _KERNEL is not defined. Subscribers: imp Differential Revision: https://reviews.freebsd.org/D50884 --- sys/sys/mount.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 66822a5aadc26b..d3ab6d7c9cae7b 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -32,10 +32,10 @@ #ifndef _SYS_MOUNT_H_ #define _SYS_MOUNT_H_ +#include #include #include #ifdef _KERNEL -#include #include #include #include From 277df87cc928a068b5cc74f1be755ef83e31ff3f Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Fri, 6 Jun 2025 13:17:30 +0100 Subject: [PATCH 2/9] sys/mount.h: Add missing headers so it's standalone for _WANT_MOUNT Reviewers: imp, kib, markj, mjg Differential Revision: https://reviews.freebsd.org/D50716 --- sys/sys/mount.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/sys/mount.h b/sys/sys/mount.h index d3ab6d7c9cae7b..a6f858e023956a 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -41,6 +41,10 @@ #include #include #include +#elif defined(_WANT_MOUNT) +#include +#include +#include #endif /* From c24da2bb282430d18384ad29563fa741e800fa26 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Fri, 6 Jun 2025 13:20:10 +0100 Subject: [PATCH 3/9] cd9660: Add _WANT_ISO_MNT Summary: This allows struct iso_mnt to be defined for userspace without resorting to the gross hack of defining _KERNEL. Reviewers: imp, kib, markj Differential Revision: https://reviews.freebsd.org/D50717 --- sys/fs/cd9660/iso.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/fs/cd9660/iso.h b/sys/fs/cd9660/iso.h index 63ce5f50949a1f..40047cc92de65b 100644 --- a/sys/fs/cd9660/iso.h +++ b/sys/fs/cd9660/iso.h @@ -212,7 +212,7 @@ struct iso_extended_attributes { u_char len_au [ISODCL (247, 250)]; /* 723 */ }; -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_WANT_ISO_MNT) /* CD-ROM Format type */ enum ISO_FTYPE { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP, @@ -253,6 +253,10 @@ struct iso_mnt { void *im_l2d; }; +#endif /* defined(_KERNEL) || defined(_WANT_ISO_MNT) */ + +#ifdef _KERNEL + struct ifid { u_short ifid_len; u_short ifid_pad; From 4438efec053cf180460f6cd98d52a6c78be4dafa Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Mon, 16 Jun 2025 20:45:50 +0100 Subject: [PATCH 4/9] msdosfs: Don't #ifdef out msdosfsmount members Summary: Whilst these aren't used by makefs, they do little harm existing once the needed headers are included, and having structs change layout based on defines like this can be fraught. This will be particularly true once this code is exposed by defines other than _KERNEL and MAKEFS, as any consumer will be able to opt into exposing this kernel type and all the definitions should match. Subscribers: imp Differential Revision: https://reviews.freebsd.org/D50885 --- sys/fs/msdosfs/msdosfsmount.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/fs/msdosfs/msdosfsmount.h b/sys/fs/msdosfs/msdosfsmount.h index 8f15bc2eaf42e5..adfc7e4d0e88e9 100644 --- a/sys/fs/msdosfs/msdosfsmount.h +++ b/sys/fs/msdosfs/msdosfsmount.h @@ -58,8 +58,11 @@ #ifndef MAKEFS #include #include -#include +#else +#include +#include #endif +#include #include #ifdef MALLOC_DECLARE @@ -114,11 +117,9 @@ struct msdosfsmount { void *pm_w2u; /* Unicode->Local iconv handle */ void *pm_u2d; /* Unicode->DOS iconv handle */ void *pm_d2u; /* DOS->Local iconv handle */ -#ifndef MAKEFS struct lock pm_fatlock; /* lockmgr protecting allocations */ struct lock pm_checkpath_lock; /* protects doscheckpath result */ struct task pm_rw2ro_task; /* context for emergency remount ro */ -#endif }; /* From b08f4650074ed61c044a2b244c8fbbfc73984fdd Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Fri, 6 Jun 2025 13:22:33 +0100 Subject: [PATCH 5/9] msdosfs: Add _WANT_MSDOSFS_INTERNALS to replace MAKEFS in headers Summary: This lets other bits of userspace expose these various definitions too. The function prototypes surely won't be useful in other contexts, but the various types are, and it's not worth hiding the prototypes unless they end up causing issues, but so long as they aren't called they shouldn't be a problem. Note the MAKEFS define continues to exist, but only for use in newfs_msdos, as those sources are reused by makefs with some changed behaviour. Test Plan: imp, kib, markj Subscribers: imp Differential Revision: https://reviews.freebsd.org/D50718 --- sys/fs/msdosfs/denode.h | 4 ++-- sys/fs/msdosfs/fat.h | 4 ++-- sys/fs/msdosfs/msdosfsmount.h | 10 +++++----- usr.sbin/makefs/msdos/Makefile.inc | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sys/fs/msdosfs/denode.h b/sys/fs/msdosfs/denode.h index 0d31b0583fa6bd..e6928fb4605214 100644 --- a/sys/fs/msdosfs/denode.h +++ b/sys/fs/msdosfs/denode.h @@ -212,7 +212,7 @@ struct denode { ((dep)->de_Attributes & ATTR_DIRECTORY) ? 0 : (dep)->de_FileSize), \ putushort((dp)->deHighClust, (dep)->de_StartCluster >> 16)) -#if defined(_KERNEL) || defined(MAKEFS) +#if defined(_KERNEL) || defined(_WANT_MSDOSFS_INTERNALS) #define VTODE(vp) ((struct denode *)(vp)->v_data) #define DETOV(de) ((de)->de_vnode) @@ -294,5 +294,5 @@ int removede(struct denode *pdep, struct denode *dep); int detrunc(struct denode *dep, u_long length, int flags, struct ucred *cred); int doscheckpath( struct denode *source, struct denode *target, daddr_t *wait_scn); -#endif /* _KERNEL || MAKEFS */ +#endif /* _KERNEL || _WANT_MSDOSFS_INTERNALS */ #endif /* !_FS_MSDOSFS_DENODE_H_ */ diff --git a/sys/fs/msdosfs/fat.h b/sys/fs/msdosfs/fat.h index a88bfb94e91daf..344cd5a9416dbf 100644 --- a/sys/fs/msdosfs/fat.h +++ b/sys/fs/msdosfs/fat.h @@ -81,7 +81,7 @@ #define MSDOSFSEOF(pmp, cn) ((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS) -#if defined (_KERNEL) || defined(MAKEFS) +#if defined (_KERNEL) || defined(_WANT_MSDOSFS_INTERNALS) /* * These are the values for the function argument to the function * fatentry(). @@ -110,5 +110,5 @@ markvoldirty(struct msdosfsmount *pmp, bool dirty) return (markvoldirty_upgrade(pmp, dirty, false)); } -#endif /* _KERNEL || MAKEFS */ +#endif /* _KERNEL || _WANT_MSDOSFS_INTERNALS */ #endif /* !_FS_MSDOSFS_FAT_H_ */ diff --git a/sys/fs/msdosfs/msdosfsmount.h b/sys/fs/msdosfs/msdosfsmount.h index adfc7e4d0e88e9..fcaac544a74d56 100644 --- a/sys/fs/msdosfs/msdosfsmount.h +++ b/sys/fs/msdosfs/msdosfsmount.h @@ -52,10 +52,10 @@ #ifndef _MSDOSFS_MSDOSFSMOUNT_H_ #define _MSDOSFS_MSDOSFSMOUNT_H_ -#if defined (_KERNEL) || defined(MAKEFS) +#if defined(_KERNEL) || defined(_WANT_MSDOSFS_INTERNALS) #include -#ifndef MAKEFS +#ifdef _KERNEL #include #include #else @@ -246,9 +246,9 @@ struct msdosfs_fileno { #define MSDOSFS_ASSERT_MP_LOCKED(pmp) \ lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED) -#endif /* _KERNEL || MAKEFS */ +#endif /* _KERNEL || _WANT_MSDOSFS_INTERNALS */ -#ifndef MAKEFS +#ifdef _KERNEL /* * Arguments to mount MSDOS filesystems. */ @@ -266,7 +266,7 @@ struct msdosfs_args { char *cs_local; /* Local Charset */ mode_t dirmask; /* dir mask to be applied for msdosfs perms */ }; -#endif /* MAKEFS */ +#endif /* _KERNEL */ /* * Msdosfs mount options: diff --git a/usr.sbin/makefs/msdos/Makefile.inc b/usr.sbin/makefs/msdos/Makefile.inc index 78ddc7804b31e3..cfa9e0e114c2fe 100644 --- a/usr.sbin/makefs/msdos/Makefile.inc +++ b/usr.sbin/makefs/msdos/Makefile.inc @@ -3,7 +3,7 @@ MSDOS_NEWFS= ${SRCTOP}/sbin/newfs_msdos .PATH: ${SRCDIR}/msdos ${MSDOS} ${MSDOS_NEWFS} -CFLAGS+= -DMAKEFS -I${MSDOS} -I${MSDOS_NEWFS} +CFLAGS+= -DMAKEFS -D_WANT_MSDOSFS_INTERNALS -I${MSDOS} -I${MSDOS_NEWFS} SRCS+= mkfs_msdos.c SRCS+= msdosfs_conv.c msdosfs_denode.c msdosfs_fat.c msdosfs_lookup.c From 57d469024d8a4bb65bba0fc43f99956b145018c3 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Fri, 6 Jun 2025 13:27:59 +0100 Subject: [PATCH 6/9] libprocstat: Drop all _KERNEL defines outside of zfs_defs.c Summary: Defining _KERNEL is a historical hack that can often break due to the environment not actually being that of a kernel build. Now that we have other targeted macros we can define instead that don't have far-reaching implications like _KERNEL we can drop this. Reviewers: imp, kib, markj Differential Revision: https://reviews.freebsd.org/D50719 --- lib/libprocstat/cd9660.c | 3 +-- lib/libprocstat/msdosfs.c | 15 +++------------ lib/libprocstat/smbfs.c | 3 +-- lib/libprocstat/udf.c | 2 -- lib/libprocstat/zfs.c | 3 +-- 5 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/libprocstat/cd9660.c b/lib/libprocstat/cd9660.c index de1140145527af..ec37f49df0f6b4 100644 --- a/lib/libprocstat/cd9660.c +++ b/lib/libprocstat/cd9660.c @@ -52,9 +52,8 @@ #include -#define _KERNEL +#define _WANT_ISO_MNT #include -#undef _KERNEL #include #include diff --git a/lib/libprocstat/msdosfs.c b/lib/libprocstat/msdosfs.c index bb1ad65e6b1a4e..01345bb8d3349a 100644 --- a/lib/libprocstat/msdosfs.c +++ b/lib/libprocstat/msdosfs.c @@ -44,17 +44,15 @@ #include #include #include +#include #include -#define _KERNEL -#include +#define _WANT_MSDOSFS_INTERNALS #include #include -#undef _KERNEL - -#include #include +#include #include #include @@ -62,13 +60,6 @@ #include #include -/* - * XXX - - * VTODE is defined in denode.h only if _KERNEL is defined, but that leads to - * header explosion - */ -#define VTODE(vp) ((struct denode *)getvnodedata(vp)) - #include "libprocstat.h" #include "common_kvm.h" diff --git a/lib/libprocstat/smbfs.c b/lib/libprocstat/smbfs.c index 136cceacb47155..cbd32cf8f59727 100644 --- a/lib/libprocstat/smbfs.c +++ b/lib/libprocstat/smbfs.c @@ -32,9 +32,8 @@ #include #include #include -#define _KERNEL +#define _WANT_MOUNT #include -#undef _KERNEL #include diff --git a/lib/libprocstat/udf.c b/lib/libprocstat/udf.c index 9a110950f8b05f..3298af6dec5fc6 100644 --- a/lib/libprocstat/udf.c +++ b/lib/libprocstat/udf.c @@ -32,9 +32,7 @@ #include #include #include -#define _KERNEL #include -#undef _KERNEL #include diff --git a/lib/libprocstat/zfs.c b/lib/libprocstat/zfs.c index 665b1e5abe24fc..010337c1919adb 100644 --- a/lib/libprocstat/zfs.c +++ b/lib/libprocstat/zfs.c @@ -31,9 +31,8 @@ #include #include -#define _KERNEL +#define _WANT_MOUNT #include -#undef _KERNEL #include #include #include From 9ab14f249e900393176d3f3499e50294c024c431 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Fri, 6 Jun 2025 13:29:34 +0100 Subject: [PATCH 7/9] openzfs: Add a _WANT_ZNODE that defines struct znode / znode_t for userspace Summary: Note that ZNODE_OS_FIELDS needs to change to using struct vnode over vnode_t (matching struct zfsvfs rather than vnode_t) since vnode_t is only defined in the kernel SPL, not the userspace SPL (libspl). Reviewers: imp, kib, markj, mm Subscribers: delphij Differential Revision: https://reviews.freebsd.org/D50720 --- .../openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h | 9 ++++++++- sys/contrib/openzfs/include/sys/zfs_vfsops.h | 2 +- sys/contrib/openzfs/include/sys/zfs_znode.h | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h b/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h index b292818750d9de..15e3affba0e871 100644 --- a/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h +++ b/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h @@ -29,6 +29,7 @@ #ifndef _FREEBSD_ZFS_SYS_ZNODE_IMPL_H #define _FREEBSD_ZFS_SYS_ZNODE_IMPL_H +#ifdef _KERNEL #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#endif #ifdef __cplusplus extern "C" { @@ -54,7 +56,7 @@ extern "C" { */ #define ZNODE_OS_FIELDS \ struct zfsvfs *z_zfsvfs; \ - vnode_t *z_vnode; \ + struct vnode *z_vnode; \ char *z_cached_symlink; \ uint64_t z_uid; \ uint64_t z_gid; \ @@ -62,6 +64,8 @@ extern "C" { uint64_t z_atime[2]; \ uint64_t z_links; +#ifdef _KERNEL + #define ZFS_LINK_MAX UINT64_MAX /* @@ -183,6 +187,9 @@ extern int zfs_znode_parent_and_name(struct znode *zp, struct znode **dzpp, char *buf, uint64_t buflen); extern int zfs_rlimit_fsize(off_t fsize); + +#endif /* _KERNEL */ + #ifdef __cplusplus } #endif diff --git a/sys/contrib/openzfs/include/sys/zfs_vfsops.h b/sys/contrib/openzfs/include/sys/zfs_vfsops.h index 18cc31e7183fec..8b8f73cf354097 100644 --- a/sys/contrib/openzfs/include/sys/zfs_vfsops.h +++ b/sys/contrib/openzfs/include/sys/zfs_vfsops.h @@ -27,7 +27,7 @@ #ifndef _SYS_ZFS_VFSOPS_H #define _SYS_ZFS_VFSOPS_H -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_WANT_ZNODE) #include #endif diff --git a/sys/contrib/openzfs/include/sys/zfs_znode.h b/sys/contrib/openzfs/include/sys/zfs_znode.h index b3a267e16f3ea1..2fedaff78534d8 100644 --- a/sys/contrib/openzfs/include/sys/zfs_znode.h +++ b/sys/contrib/openzfs/include/sys/zfs_znode.h @@ -163,8 +163,9 @@ extern int zfs_obj_to_pobj(objset_t *osp, sa_handle_t *hdl, sa_attr_type_t *sa_table, uint64_t *pobjp, int *is_xattrdir); extern int zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value); -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_WANT_ZNODE) #include +#include /* * Directory entry locks control access to directory entries. @@ -219,7 +220,9 @@ typedef struct znode { */ ZNODE_OS_FIELDS; } znode_t; +#endif +#ifdef _KERNEL /* Verifies the znode is valid. */ static inline int zfs_verify_zp(znode_t *zp) From 1e527e86879327371d819e7e797177801686f721 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Fri, 6 Jun 2025 13:45:53 +0100 Subject: [PATCH 8/9] libprocstat: Drop zfs_defs.c hack, including its _KERNEL define Summary: Now that we have a _WANT_ZNODE we can use that instead of defining _KERNEL, and we're able to move the code back into zfs.c using a real znode_t pointer. Reviewers: imp, kib, markj, mm Subscribers: delphij Differential Revision: https://reviews.freebsd.org/D50721 --- lib/libprocstat/Makefile | 23 ++++---- lib/libprocstat/zfs.c | 49 +++++++++-------- lib/libprocstat/zfs/Makefile | 30 ----------- lib/libprocstat/zfs/Makefile.depend | 11 ---- lib/libprocstat/zfs_defs.c | 81 ----------------------------- lib/libprocstat/zfs_defs.h | 36 ------------- 6 files changed, 38 insertions(+), 192 deletions(-) delete mode 100644 lib/libprocstat/zfs/Makefile delete mode 100644 lib/libprocstat/zfs/Makefile.depend delete mode 100644 lib/libprocstat/zfs_defs.c delete mode 100644 lib/libprocstat/zfs_defs.h diff --git a/lib/libprocstat/Makefile b/lib/libprocstat/Makefile index 229adc6015f716..e20518910ba3ef 100644 --- a/lib/libprocstat/Makefile +++ b/lib/libprocstat/Makefile @@ -52,18 +52,23 @@ MLINKS+=libprocstat.3 procstat_close.3 \ libprocstat.3 procstat_open_kvm.3 \ libprocstat.3 procstat_open_sysctl.3 -# XXX This is a hack. .if ${MK_CDDL} != "no" CFLAGS+= -DLIBPROCSTAT_ZFS SRCS+= zfs.c -OBJS+= zfs/zfs_defs.o -SUBDIR= zfs -zfs/zfs_defs.o: .PHONY - @cd ${.CURDIR}/zfs && ${MAKE} zfs_defs.o -zfs/zfs_defs.pico: .PHONY - @cd ${.CURDIR}/zfs && ${MAKE} zfs_defs.pico -zfs/zfs_defs.pieo: .PHONY - @cd ${.CURDIR}/zfs && ${MAKE} zfs_defs.pieo +ZFSTOP= ${SRCTOP}/sys/contrib/openzfs +CFLAGS.zfs.c+= -DIN_BASE +CFLAGS.zfs.c+= -DHAVE_ISSETUGID +CFLAGS.zfs.c+= -DZFS_DEBUG +CFLAGS.zfs.c+= -I${ZFSTOP}/include +CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libspl/include +CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libspl/include/os/freebsd +CFLAGS.zfs.c+= -I${ZFSTOP}/include/os/freebsd/zfs +CFLAGS.zfs.c+= -I${ZFSTOP}/module/icp/include +CFLAGS.zfs.c+= -I${SRCTOP}/sys +CFLAGS.zfs.c+= -I${SRCTOP}/sys/modules/zfs +CFLAGS.zfs.c+= -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h +CFLAGS.zfs.c+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h +CFLAGS.zfs.c+= -Wno-cast-qual .endif .include diff --git a/lib/libprocstat/zfs.c b/lib/libprocstat/zfs.c index 010337c1919adb..6dc23d7573fde7 100644 --- a/lib/libprocstat/zfs.c +++ b/lib/libprocstat/zfs.c @@ -26,10 +26,6 @@ * SUCH DAMAGE. */ -#include /* __RENAME */ - -#include - #include #define _WANT_MOUNT #include @@ -38,26 +34,28 @@ #include #include #include +#define _WANT_ZNODE +#include +#include #include #include #include +#include #include #include #define ZFS #include "libprocstat.h" #include "common_kvm.h" -#include "zfs_defs.h" int zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct mount mount, *mountptr; - void *znodeptr; - char *dataptr; + znode_t *kznodeptr, *znode; size_t len; int size; @@ -66,27 +64,30 @@ zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) warnx("error getting sysctl"); return (1); } - dataptr = malloc(size); - if (dataptr == NULL) { + znode = malloc(size); + if (znode == NULL) { warnx("error allocating memory for znode storage"); return (1); } - if ((size_t)size < offsetof_z_id + sizeof(uint64_t) || - (size_t)size < offsetof_z_mode + sizeof(mode_t) || - (size_t)size < offsetof_z_size + sizeof(uint64_t)) { + if ((size_t)size != sizeof(znode_t)) + warnx("znode_t size mismatch, data could be wrong"); + + if ((size_t)size < offsetof(znode_t, z_id) + sizeof(znode->z_id) || + (size_t)size < offsetof(znode_t, z_mode) + sizeof(znode->z_mode) || + (size_t)size < offsetof(znode_t, z_size) + sizeof(znode->z_size)) { warnx("znode_t size is too small"); goto bad; } - if ((size_t)size != sizeof_znode_t) - warnx("znode_t size mismatch, data could be wrong"); - - /* Since we have problems including vnode.h, we'll use the wrappers. */ - znodeptr = getvnodedata(vp); - if (!kvm_read_all(kd, (unsigned long)znodeptr, dataptr, - (size_t)size)) { - warnx("can't read znode at %p", (void *)znodeptr); + /* + * OpenZFS's libspl provides a dummy sys/vnode.h that shadows ours so + * struct vnode is an incomplete type. Use the wrapper until that is + * resolved. + */ + kznodeptr = getvnodedata(vp); + if (!kvm_read_all(kd, (unsigned long)kznodeptr, znode, (size_t)size)) { + warnx("can't read znode at %p", (void *)kznodeptr); goto bad; } @@ -102,12 +103,10 @@ zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) * under .zfs/. */ vn->vn_fsid = mount.mnt_stat.f_fsid.val[0]; - vn->vn_fileid = *(uint64_t *)(void *)(dataptr + offsetof_z_id); - vn->vn_mode = *(mode_t *)(void *)(dataptr + offsetof_z_mode); - vn->vn_size = *(uint64_t *)(void *)(dataptr + offsetof_z_size); - free(dataptr); + vn->vn_fileid = znode->z_id; + vn->vn_mode = znode->z_mode; + vn->vn_size = znode->z_size; return (0); bad: - free(dataptr); return (1); } diff --git a/lib/libprocstat/zfs/Makefile b/lib/libprocstat/zfs/Makefile deleted file mode 100644 index 5e1ebd44d1d33f..00000000000000 --- a/lib/libprocstat/zfs/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -.PATH: ${.CURDIR:H} - -SRCS= zfs_defs.c -OBJS= zfs_defs.o -WARNS?= 1 - -FORTIFY_SOURCE= 0 - -# We fake a kernel compilation environment in order to get the definition for -# 'zpool_t'. -CFLAGS+= -DIN_BASE -D__KERNEL__ -D_KERNEL -UKLD_TIED -DKLD_MODULE -CFLAGS+= -DHAVE_ISSETUGID -D_SYS_VMEM_H_ - -CFLAGS+= -fno-builtin -nostdlib - -CFLAGS+= -I${.CURDIR} -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd -CFLAGS+= -I${SRCTOP}/sys/contrib/ck/include -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include -CFLAGS+= -I${SRCTOP}/sys -I. -I.. - -CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h - -all: ${OBJS} -CLEANFILES= ${OBJS} - -.include diff --git a/lib/libprocstat/zfs/Makefile.depend b/lib/libprocstat/zfs/Makefile.depend deleted file mode 100644 index 993ab0638f4ae7..00000000000000 --- a/lib/libprocstat/zfs/Makefile.depend +++ /dev/null @@ -1,11 +0,0 @@ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - include \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif diff --git a/lib/libprocstat/zfs_defs.c b/lib/libprocstat/zfs_defs.c deleted file mode 100644 index 7f935c827118ee..00000000000000 --- a/lib/libprocstat/zfs_defs.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2020 Andriy Gapon - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -/* - * Prevent some headers from getting included and fake some types - * in order to allow this file to compile without bringing in - * too many kernel build dependencies. - */ -#define _OPENSOLARIS_SYS_PATHNAME_H_ -#define _OPENSOLARIS_SYS_POLICY_H_ -#define _VNODE_PAGER_ - - -enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD, - VMARKER }; - -/* - * Vnode attributes. A field value of VNOVAL represents a field whose value - * is unavailable (getattr) or which is not to be changed (setattr). - */ -struct vattr { - enum vtype va_type; /* vnode type (for create) */ - u_short va_mode; /* files access mode and type */ - u_short va_padding0; - uid_t va_uid; /* owner user id */ - gid_t va_gid; /* owner group id */ - nlink_t va_nlink; /* number of references to file */ - dev_t va_fsid; /* filesystem id */ - ino_t va_fileid; /* file id */ - u_quad_t va_size; /* file size in bytes */ - long va_blocksize; /* blocksize preferred for i/o */ - struct timespec va_atime; /* time of last access */ - struct timespec va_mtime; /* time of last modification */ - struct timespec va_ctime; /* time file changed */ - struct timespec va_birthtime; /* time file created */ - u_long va_gen; /* generation number of file */ - u_long va_flags; /* flags defined for file */ - dev_t va_rdev; /* device the special file represents */ - u_quad_t va_bytes; /* bytes of disk space held by file */ - u_quad_t va_filerev; /* file modification number */ - u_int va_vaflags; /* operations flags, see below */ - long va_spare; /* remain quad aligned */ -}; - -#define _WANT_MOUNT -#include -#include - -size_t sizeof_znode_t = sizeof(znode_t); -size_t offsetof_z_id = offsetof(znode_t, z_id); -size_t offsetof_z_size = offsetof(znode_t, z_size); -size_t offsetof_z_mode = offsetof(znode_t, z_mode); - -/* Keep pcpu.h satisfied. */ -uintptr_t *__start_set_pcpu; -uintptr_t *__stop_set_pcpu; diff --git a/lib/libprocstat/zfs_defs.h b/lib/libprocstat/zfs_defs.h deleted file mode 100644 index de17efba5630c4..00000000000000 --- a/lib/libprocstat/zfs_defs.h +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2020 Andriy Gapon - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _LIBPROCSTAT_ZFS_DEFS_H -#define _LIBPROCSTAT_ZFS_DEFS_H - -extern size_t sizeof_znode_t; -extern size_t offsetof_z_id; -extern size_t offsetof_z_size; -extern size_t offsetof_z_mode; - -#endif /* _LIBPROCSTAT_ZFS_DEFS_H */ From 59272345318f3080357796c6f9b33c545606aeee Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Mon, 16 Jun 2025 22:16:13 +0100 Subject: [PATCH 9/9] tools/build: Provide extra headers on non-FreeBSD These will be needed by future changes to continue to allow building makefs as a bootstrap tool on Linux and macOS. This also requires defining __sbintime_t in our cross-build sys/_types. --- tools/build/Makefile | 6 ++++++ tools/build/cross-build/include/common/sys/_types.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/tools/build/Makefile b/tools/build/Makefile index 40ac498bfbb461..83f589ce38642a 100644 --- a/tools/build/Makefile +++ b/tools/build/Makefile @@ -270,6 +270,12 @@ subr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c cp ${.ALLSRC} ${.TARGET} SRCS+= subr_capability.c CLEANFILES+= subr_capability.c + +# Headers needed for msdosfs use in makefs +SYSINCS+= ${SRCTOP}/sys/sys/_callout.h +SYSINCS+= ${SRCTOP}/sys/sys/_lock.h +SYSINCS+= ${SRCTOP}/sys/sys/_lockmgr.h +SYSINCS+= ${SRCTOP}/sys/sys/_task.h .endif # ${MAKE.OS} != "FreeBSD" CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h diff --git a/tools/build/cross-build/include/common/sys/_types.h b/tools/build/cross-build/include/common/sys/_types.h index 408f0537d1e626..dc1b76f2506378 100644 --- a/tools/build/cross-build/include/common/sys/_types.h +++ b/tools/build/cross-build/include/common/sys/_types.h @@ -48,3 +48,6 @@ typedef __builtin_va_list __va_list; /* Needed for opensolaris compat. */ typedef __int64_t off64_t; + +/* Needed for sys/_callout.h */ +typedef __int64_t __sbintime_t;