2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2007 Ulf Lilleengen
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
35 #include <sys/mount.h>
37 #include <sys/queue.h>
39 #include <sys/sysctl.h>
41 #include <sys/vnode.h>
43 #include <netinet/in.h>
51 #include "libprocstat.h"
52 #include "common_kvm.h"
56 zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)
59 struct mount mount, *mountptr;
66 if (sysctlbyname("debug.sizeof.znode", &size, &len, NULL, 0) == -1) {
67 warnx("error getting sysctl");
70 dataptr = malloc(size);
71 if (dataptr == NULL) {
72 warnx("error allocating memory for znode storage");
76 if ((size_t)size < offsetof_z_id + sizeof(uint64_t) ||
77 (size_t)size < offsetof_z_mode + sizeof(mode_t) ||
78 (size_t)size < offsetof_z_size + sizeof(uint64_t)) {
79 warnx("znode_t size is too small");
83 if ((size_t)size != sizeof_znode_t)
84 warnx("znode_t size mismatch, data could be wrong");
86 /* Since we have problems including vnode.h, we'll use the wrappers. */
87 znodeptr = getvnodedata(vp);
88 if (!kvm_read_all(kd, (unsigned long)znodeptr, dataptr,
90 warnx("can't read znode at %p", (void *)znodeptr);
94 /* Get the mount pointer, and read from the address. */
95 mountptr = getvnodemount(vp);
96 if (!kvm_read_all(kd, (unsigned long)mountptr, &mount, sizeof(mount))) {
97 warnx("can't read mount at %p", (void *)mountptr);
102 * XXX Assume that this is a znode, but it can be a special node
105 vn->vn_fsid = mount.mnt_stat.f_fsid.val[0];
106 vn->vn_fileid = *(uint64_t *)(void *)(dataptr + offsetof_z_id);
107 vn->vn_mode = *(mode_t *)(void *)(dataptr + offsetof_z_mode);
108 vn->vn_size = *(uint64_t *)(void *)(dataptr + offsetof_z_size);