1*0b082c0eSderaadt /* $OpenBSD: kvm_ntfs.c,v 1.6 2021/09/10 00:02:43 deraadt Exp $ */
29938c243Smillert
39938c243Smillert /*-
49938c243Smillert * Copyright (c) 1999 The NetBSD Foundation, Inc.
59938c243Smillert * All rights reserved.
69938c243Smillert *
79938c243Smillert * This code is derived from software contributed to The NetBSD Foundation
89938c243Smillert * by Jaromir Dolecek.
99938c243Smillert *
109938c243Smillert * Redistribution and use in source and binary forms, with or without
119938c243Smillert * modification, are permitted provided that the following conditions
129938c243Smillert * are met:
139938c243Smillert * 1. Redistributions of source code must retain the above copyright
149938c243Smillert * notice, this list of conditions and the following disclaimer.
159938c243Smillert * 2. Redistributions in binary form must reproduce the above copyright
169938c243Smillert * notice, this list of conditions and the following disclaimer in the
179938c243Smillert * documentation and/or other materials provided with the distribution.
189938c243Smillert *
199938c243Smillert * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
209938c243Smillert * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
219938c243Smillert * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
229938c243Smillert * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
239938c243Smillert * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
249938c243Smillert * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
259938c243Smillert * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269938c243Smillert * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279938c243Smillert * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
289938c243Smillert * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
299938c243Smillert * POSSIBILITY OF SUCH DAMAGE.
309938c243Smillert */
319938c243Smillert
32*0b082c0eSderaadt #include <sys/types.h>
33*0b082c0eSderaadt #include <sys/time.h>
349938c243Smillert #include <sys/ucred.h>
359938c243Smillert #define _KERNEL
369938c243Smillert #include <sys/mount.h>
379938c243Smillert #undef _KERNEL
389938c243Smillert #include <sys/vnode.h>
399938c243Smillert #include <sys/sysctl.h>
409938c243Smillert
419938c243Smillert #include <ntfs/ntfs.h>
429938c243Smillert #include <ntfs/ntfs_inode.h>
439938c243Smillert
449938c243Smillert #include <limits.h>
459938c243Smillert #include <kvm.h>
469938c243Smillert #include <db.h>
479938c243Smillert
489938c243Smillert #include "kvm_private.h"
4926de9129Sguenther #include "kvm_file.h"
509938c243Smillert
519938c243Smillert int
_kvm_stat_ntfs(kvm_t * kd,struct kinfo_file * kf,struct vnode * vp)52cef0bbe1Sguenther _kvm_stat_ntfs(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
539938c243Smillert {
549938c243Smillert struct ntnode ntnode;
559938c243Smillert struct fnode fn;
569938c243Smillert struct ntfsmount ntm;
579938c243Smillert
589938c243Smillert /*
599938c243Smillert * To get the ntnode, we have to go in two steps - firstly
609938c243Smillert * to read appropriate struct fnode and then getting the address
619938c243Smillert * of ntnode and reading it's contents
629938c243Smillert */
639938c243Smillert if (KREAD(kd, (u_long)VTOF(vp), &fn)) {
649938c243Smillert _kvm_err(kd, kd->program, "can't read fnode at %p", VTOF(vp));
659938c243Smillert return (-1);
669938c243Smillert }
679938c243Smillert if (KREAD(kd, (u_long)FTONT(&fn), &ntnode)) {
689938c243Smillert _kvm_err(kd, kd->program, "can't read ntnode at %p", FTONT(&fn));
699938c243Smillert return (-1);
709938c243Smillert }
719938c243Smillert if (KREAD(kd, (u_long)ntnode.i_mp, &ntm)) {
729938c243Smillert _kvm_err(kd, kd->program, "can't read ntfsmount at %p",
739938c243Smillert ntnode.i_mp);
749938c243Smillert return (-1);
759938c243Smillert }
769938c243Smillert
779938c243Smillert kf->va_fsid = ntnode.i_dev & 0xffff;
789938c243Smillert kf->va_fileid = (long)ntnode.i_number;
799938c243Smillert kf->va_mode = (mode_t)ntm.ntm_mode | _kvm_getftype(vp->v_type);
809938c243Smillert kf->va_size = fn.f_size;
819938c243Smillert kf->va_rdev = 0; /* XXX */
828cdd1cc4Sguenther kf->va_nlink = 1;
839938c243Smillert
849938c243Smillert return (0);
859938c243Smillert }
86