diff --git a/lib/libprocstat/cd9660.c b/lib/libprocstat/cd9660.c index de1140145527..ec37f49df0f6 100644 --- a/lib/libprocstat/cd9660.c +++ b/lib/libprocstat/cd9660.c @@ -1,89 +1,88 @@ /* * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 2000 Peter Edwards * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by Peter Edwards * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * 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. */ /* * XXX - * This had to be separated from fstat.c because cd9660s has namespace * conflicts with UFS. */ #include #include #include #include #include #include #include -#define _KERNEL +#define _WANT_ISO_MNT #include -#undef _KERNEL #include #include #include #include "libprocstat.h" #include "common_kvm.h" int isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct iso_node isonode; struct iso_mnt mnt; if (!kvm_read_all(kd, (unsigned long)VTOI(vp), &isonode, sizeof(isonode))) { warnx("can't read iso_node at %p", (void *)VTOI(vp)); return (1); } if (!kvm_read_all(kd, (unsigned long)isonode.i_mnt, &mnt, sizeof(mnt))) { warnx("can't read iso_mnt at %p", (void *)VTOI(vp)); return (1); } vn->vn_fsid = dev2udev(kd, mnt.im_dev); vn->vn_mode = (mode_t)isonode.inode.iso_mode; vn->vn_fileid = isonode.i_number; vn->vn_size = isonode.i_size; return (0); } diff --git a/lib/libprocstat/msdosfs.c b/lib/libprocstat/msdosfs.c index bb1ad65e6b1a..01345bb8d334 100644 --- a/lib/libprocstat/msdosfs.c +++ b/lib/libprocstat/msdosfs.c @@ -1,156 +1,147 @@ /*- * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 2000 Peter Edwards * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by Peter Edwards * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * 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 #include #include #include #include #include #include +#include #include -#define _KERNEL -#include +#define _WANT_MSDOSFS_INTERNALS #include #include -#undef _KERNEL - -#include #include +#include #include #include #include #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" struct dosmount { struct dosmount *next; struct msdosfsmount *kptr; /* Pointer in kernel space */ struct msdosfsmount data; /* User space copy of structure */ }; int msdosfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct denode denode; static struct dosmount *mounts; struct dosmount *mnt; u_long dirsperblk; int fileid; if (!kvm_read_all(kd, (unsigned long)VTODE(vp), &denode, sizeof(denode))) { warnx("can't read denode at %p", (void *)VTODE(vp)); return (1); } /* * Find msdosfsmount structure for the vnode's filesystem. Needed * for some filesystem parameters */ for (mnt = mounts; mnt; mnt = mnt->next) if (mnt->kptr == denode.de_pmp) break; if (!mnt) { if ((mnt = malloc(sizeof(struct dosmount))) == NULL) { warn("malloc()"); return (1); } if (!kvm_read_all(kd, (unsigned long)denode.de_pmp, &mnt->data, sizeof(mnt->data))) { free(mnt); warnx("can't read mount info at %p", (void *)denode.de_pmp); return (1); } mnt->next = mounts; mounts = mnt; mnt->kptr = denode.de_pmp; } vn->vn_fsid = dev2udev(kd, mnt->data.pm_dev); vn->vn_mode = 0555; vn->vn_mode |= denode.de_Attributes & ATTR_READONLY ? 0 : 0222; vn->vn_mode &= mnt->data.pm_mask; /* Distinguish directories and files. No "special" files in FAT. */ vn->vn_mode |= denode.de_Attributes & ATTR_DIRECTORY ? S_IFDIR : S_IFREG; vn->vn_size = denode.de_FileSize; /* * XXX - * Culled from msdosfs_vnops.c. There appears to be a problem * here, in that a directory has the same inode number as the first * file in the directory. stat(2) suffers from this problem also, so * I won't try to fix it here. * * The following computation of the fileid must be the same as that * used in msdosfs_readdir() to compute d_fileno. If not, pwd * doesn't work. */ dirsperblk = mnt->data.pm_BytesPerSec / sizeof(struct direntry); if (denode.de_Attributes & ATTR_DIRECTORY) { fileid = cntobn(&mnt->data, denode.de_StartCluster) * dirsperblk; if (denode.de_StartCluster == MSDOSFSROOT) fileid = 1; } else { fileid = cntobn(&mnt->data, denode.de_dirclust) * dirsperblk; if (denode.de_dirclust == MSDOSFSROOT) fileid = roottobn(&mnt->data, 0) * dirsperblk; fileid += denode.de_diroffset / sizeof(struct direntry); } vn->vn_fileid = fileid; return (0); } diff --git a/lib/libprocstat/smbfs.c b/lib/libprocstat/smbfs.c index 136cceacb471..cbd32cf8f597 100644 --- a/lib/libprocstat/smbfs.c +++ b/lib/libprocstat/smbfs.c @@ -1,79 +1,78 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2005-2009 Stanislav Sedov * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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 #include #include #include #include #include -#define _KERNEL +#define _WANT_MOUNT #include -#undef _KERNEL #include #include #include #include #include #include #include #include "libprocstat.h" #include "common_kvm.h" int smbfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct smbnode node; struct mount mnt; int error; assert(kd); assert(vn); error = kvm_read_all(kd, (unsigned long)VTOSMB(vp), &node, sizeof(node)); if (error != 0) { warnx("can't read smbfs fnode at %p", (void *)VTOSMB(vp)); return (1); } error = kvm_read_all(kd, (unsigned long)getvnodemount(vp), &mnt, sizeof(mnt)); if (error != 0) { warnx("can't read mount at %p for vnode %p", (void *)getvnodemount(vp), vp); return (1); } vn->vn_fileid = node.n_ino; if (vn->vn_fileid == 0) vn->vn_fileid = 2; vn->vn_fsid = mnt.mnt_stat.f_fsid.val[0]; return (0); } diff --git a/lib/libprocstat/udf.c b/lib/libprocstat/udf.c index 9a110950f8b0..3298af6dec5f 100644 --- a/lib/libprocstat/udf.c +++ b/lib/libprocstat/udf.c @@ -1,103 +1,101 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2005-2009 Stanislav Sedov * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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 #include #include #include #include #include -#define _KERNEL #include -#undef _KERNEL #include #include #include #include #include #include #include "libprocstat.h" #include "common_kvm.h" /* XXX */ struct udf_mnt { int im_flags; struct mount *im_mountp; struct g_consumer *im_cp; struct bufobj *im_bo; struct cdev *im_dev; struct vnode *im_devvp; int bsize; int bshift; int bmask; uint32_t part_start; uint32_t part_len; uint64_t root_id; struct long_ad root_icb; int p_sectors; int s_table_entries; void *s_table; void *im_d2l; }; struct udf_node { struct vnode *i_vnode; struct udf_mnt *udfmp; ino_t hash_id; long diroff; struct file_entry *fentry; }; #define VTON(vp) ((struct udf_node *)((vp)->v_data)) int udf_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct udf_node node; struct udf_mnt mnt; int error; assert(kd); assert(vn); error = kvm_read_all(kd, (unsigned long)VTON(vp), &node, sizeof(node)); if (error != 0) { warnx("can't read udf fnode at %p", (void *)VTON(vp)); return (1); } error = kvm_read_all(kd, (unsigned long)node.udfmp, &mnt, sizeof(mnt)); if (error != 0) { warnx("can't read udf_mnt at %p for vnode %p", (void *)node.udfmp, vp); return (1); } vn->vn_fileid = node.hash_id; vn->vn_fsid = dev2udev(kd, mnt.im_dev); return (0); } diff --git a/lib/libprocstat/zfs.c b/lib/libprocstat/zfs.c index 665b1e5abe24..010337c1919a 100644 --- a/lib/libprocstat/zfs.c +++ b/lib/libprocstat/zfs.c @@ -1,114 +1,113 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2007 Ulf Lilleengen * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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 /* __RENAME */ #include #include -#define _KERNEL +#define _WANT_MOUNT #include -#undef _KERNEL #include #include #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; size_t len; int size; len = sizeof(size); if (sysctlbyname("debug.sizeof.znode", &size, &len, NULL, 0) == -1) { warnx("error getting sysctl"); return (1); } dataptr = malloc(size); if (dataptr == 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)) { 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); goto bad; } /* Get the mount pointer, and read from the address. */ mountptr = getvnodemount(vp); if (!kvm_read_all(kd, (unsigned long)mountptr, &mount, sizeof(mount))) { warnx("can't read mount at %p", (void *)mountptr); goto bad; } /* * XXX Assume that this is a znode, but it can be a special node * 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); return (0); bad: free(dataptr); return (1); }