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
31 #include <sys/param.h>
33 #include <sys/mount.h>
35 #include <sys/queue.h>
37 #include <sys/sysctl.h>
39 #include <sys/vnode.h>
41 #include <netinet/in.h>
49 #include "libprocstat.h"
50 #include "common_kvm.h"
54 zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)
57 struct mount mount, *mountptr;
64 if (sysctlbyname("debug.sizeof.znode", &size, &len, NULL, 0) == -1) {
65 warnx("error getting sysctl");
68 dataptr = malloc(size);
69 if (dataptr == NULL) {
70 warnx("error allocating memory for znode storage");
74 if ((size_t)size < offsetof_z_id + sizeof(uint64_t) ||
75 (size_t)size < offsetof_z_mode + sizeof(mode_t) ||
76 (size_t)size < offsetof_z_size + sizeof(uint64_t)) {
77 warnx("znode_t size is too small");
81 if ((size_t)size != sizeof_znode_t)
82 warnx("znode_t size mismatch, data could be wrong");
84 /* Since we have problems including vnode.h, we'll use the wrappers. */
85 znodeptr = getvnodedata(vp);
86 if (!kvm_read_all(kd, (unsigned long)znodeptr, dataptr,
88 warnx("can't read znode at %p", (void *)znodeptr);
92 /* Get the mount pointer, and read from the address. */
93 mountptr = getvnodemount(vp);
94 if (!kvm_read_all(kd, (unsigned long)mountptr, &mount, sizeof(mount))) {
95 warnx("can't read mount at %p", (void *)mountptr);
100 * XXX Assume that this is a znode, but it can be a special node
103 vn->vn_fsid = mount.mnt_stat.f_fsid.val[0];
104 vn->vn_fileid = *(uint64_t *)(void *)(dataptr + offsetof_z_id);
105 vn->vn_mode = *(mode_t *)(void *)(dataptr + offsetof_z_mode);
106 vn->vn_size = *(uint64_t *)(void *)(dataptr + offsetof_z_size);