1*77228a74Ssimonb /* $NetBSD: zfs.c,v 1.1 2022/06/19 11:31:19 simonb Exp $ */
2*77228a74Ssimonb
3*77228a74Ssimonb /*-
4*77228a74Ssimonb * Copyright (c) 2022 The NetBSD Foundation, Inc.
5*77228a74Ssimonb * All rights reserved.
6*77228a74Ssimonb *
7*77228a74Ssimonb * This code is derived from software contributed to The NetBSD Foundation
8*77228a74Ssimonb * by Simon Burge.
9*77228a74Ssimonb *
10*77228a74Ssimonb * Redistribution and use in source and binary forms, with or without
11*77228a74Ssimonb * modification, are permitted provided that the following conditions
12*77228a74Ssimonb * are met:
13*77228a74Ssimonb * 1. Redistributions of source code must retain the above copyright
14*77228a74Ssimonb * notice, this list of conditions and the following disclaimer.
15*77228a74Ssimonb * 2. Redistributions in binary form must reproduce the above copyright
16*77228a74Ssimonb * notice, this list of conditions and the following disclaimer in the
17*77228a74Ssimonb * documentation and/or other materials provided with the distribution.
18*77228a74Ssimonb *
19*77228a74Ssimonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*77228a74Ssimonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*77228a74Ssimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*77228a74Ssimonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*77228a74Ssimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*77228a74Ssimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*77228a74Ssimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*77228a74Ssimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*77228a74Ssimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*77228a74Ssimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*77228a74Ssimonb * POSSIBILITY OF SUCH DAMAGE.
30*77228a74Ssimonb */
31*77228a74Ssimonb
32*77228a74Ssimonb #include <sys/cdefs.h>
33*77228a74Ssimonb __RCSID("$NetBSD: zfs.c,v 1.1 2022/06/19 11:31:19 simonb Exp $");
34*77228a74Ssimonb
35*77228a74Ssimonb #include <sys/param.h>
36*77228a74Ssimonb #include <sys/time.h>
37*77228a74Ssimonb #include <sys/vnode.h>
38*77228a74Ssimonb #define __EXPOSE_MOUNT
39*77228a74Ssimonb #include <sys/mount.h>
40*77228a74Ssimonb
41*77228a74Ssimonb #include "zfs_znode.h"
42*77228a74Ssimonb
43*77228a74Ssimonb #include <kvm.h>
44*77228a74Ssimonb #include <err.h>
45*77228a74Ssimonb #include "fstat.h"
46*77228a74Ssimonb
47*77228a74Ssimonb int
zfs_filestat(struct vnode * vp,struct filestat * fsp)48*77228a74Ssimonb zfs_filestat(struct vnode *vp, struct filestat *fsp)
49*77228a74Ssimonb {
50*77228a74Ssimonb znode_t inode;
51*77228a74Ssimonb struct mount mt;
52*77228a74Ssimonb
53*77228a74Ssimonb if (!KVM_READ(VTOZ(vp), &inode, sizeof (inode))) {
54*77228a74Ssimonb dprintf("can't read inode at %p for pid %d", VTOZ(vp), Pid);
55*77228a74Ssimonb return 0;
56*77228a74Ssimonb }
57*77228a74Ssimonb if (!KVM_READ(vp->v_mount, &mt, sizeof(mt))) {
58*77228a74Ssimonb dprintf("can't read mount at %p for pid %d",
59*77228a74Ssimonb vp->v_mount, Pid);
60*77228a74Ssimonb return 0;
61*77228a74Ssimonb }
62*77228a74Ssimonb /*
63*77228a74Ssimonb * XXX: fsid should be something like
64*77228a74Ssimonb * ((struct zfsvfs *)vp->v_mount->mnt_data)->
65*77228a74Ssimonb * z_os->os_ds_dataset->ds_fsid_guid
66*77228a74Ssimonb * but ZFS headers are pretty much impossible to include
67*77228a74Ssimonb * from userland.
68*77228a74Ssimonb */
69*77228a74Ssimonb fsp->fsid = mt.mnt_stat.f_fsidx.__fsid_val[0];
70*77228a74Ssimonb fsp->fileid = inode.z_id;
71*77228a74Ssimonb fsp->mode = inode.z_mode;
72*77228a74Ssimonb fsp->size = inode.z_size;
73*77228a74Ssimonb fsp->rdev = 0;
74*77228a74Ssimonb return 1;
75*77228a74Ssimonb }
76