1 /* $OpenBSD: kvm_ntfs.c,v 1.1 2009/06/24 13:04:24 millert 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 #if defined(LIBC_SCCS) && !defined(lint) 33 static char *rcsid = "$OpenBSD: kvm_ntfs.c,v 1.1 2009/06/24 13:04:24 millert Exp $"; 34 #endif /* LIBC_SCCS and not lint */ 35 36 #include <sys/param.h> 37 #include <sys/ucred.h> 38 #define _KERNEL 39 #include <sys/mount.h> 40 #undef _KERNEL 41 #include <sys/vnode.h> 42 #include <sys/sysctl.h> 43 44 #include <ntfs/ntfs.h> 45 #include <ntfs/ntfs_inode.h> 46 47 #include <limits.h> 48 #include <kvm.h> 49 #include <db.h> 50 51 #include "kvm_private.h" 52 53 extern mode_t _kvm_getftype(enum vtype); 54 55 int 56 _kvm_stat_ntfs(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) 57 { 58 struct ntnode ntnode; 59 struct fnode fn; 60 struct ntfsmount ntm; 61 62 /* 63 * To get the ntnode, we have to go in two steps - firstly 64 * to read appropriate struct fnode and then getting the address 65 * of ntnode and reading it's contents 66 */ 67 if (KREAD(kd, (u_long)VTOF(vp), &fn)) { 68 _kvm_err(kd, kd->program, "can't read fnode at %p", VTOF(vp)); 69 return (-1); 70 } 71 if (KREAD(kd, (u_long)FTONT(&fn), &ntnode)) { 72 _kvm_err(kd, kd->program, "can't read ntnode at %p", FTONT(&fn)); 73 return (-1); 74 } 75 if (KREAD(kd, (u_long)ntnode.i_mp, &ntm)) { 76 _kvm_err(kd, kd->program, "can't read ntfsmount at %p", 77 ntnode.i_mp); 78 return (-1); 79 } 80 81 kf->va_fsid = ntnode.i_dev & 0xffff; 82 kf->va_fileid = (long)ntnode.i_number; 83 kf->va_mode = (mode_t)ntm.ntm_mode | _kvm_getftype(vp->v_type); 84 kf->va_size = fn.f_size; 85 kf->va_rdev = 0; /* XXX */ 86 87 return (0); 88 } 89