1 /* $OpenBSD: kvm_ntfs.c,v 1.6 2021/09/10 00:02:43 deraadt Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jaromir Dolecek. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/types.h> 33 #include <sys/time.h> 34 #include <sys/ucred.h> 35 #define _KERNEL 36 #include <sys/mount.h> 37 #undef _KERNEL 38 #include <sys/vnode.h> 39 #include <sys/sysctl.h> 40 41 #include <ntfs/ntfs.h> 42 #include <ntfs/ntfs_inode.h> 43 44 #include <limits.h> 45 #include <kvm.h> 46 #include <db.h> 47 48 #include "kvm_private.h" 49 #include "kvm_file.h" 50 51 int 52 _kvm_stat_ntfs(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) 53 { 54 struct ntnode ntnode; 55 struct fnode fn; 56 struct ntfsmount ntm; 57 58 /* 59 * To get the ntnode, we have to go in two steps - firstly 60 * to read appropriate struct fnode and then getting the address 61 * of ntnode and reading it's contents 62 */ 63 if (KREAD(kd, (u_long)VTOF(vp), &fn)) { 64 _kvm_err(kd, kd->program, "can't read fnode at %p", VTOF(vp)); 65 return (-1); 66 } 67 if (KREAD(kd, (u_long)FTONT(&fn), &ntnode)) { 68 _kvm_err(kd, kd->program, "can't read ntnode at %p", FTONT(&fn)); 69 return (-1); 70 } 71 if (KREAD(kd, (u_long)ntnode.i_mp, &ntm)) { 72 _kvm_err(kd, kd->program, "can't read ntfsmount at %p", 73 ntnode.i_mp); 74 return (-1); 75 } 76 77 kf->va_fsid = ntnode.i_dev & 0xffff; 78 kf->va_fileid = (long)ntnode.i_number; 79 kf->va_mode = (mode_t)ntm.ntm_mode | _kvm_getftype(vp->v_type); 80 kf->va_size = fn.f_size; 81 kf->va_rdev = 0; /* XXX */ 82 kf->va_nlink = 1; 83 84 return (0); 85 } 86