11558Srgrimes/* $NetBSD: ntfs.c,v 1.11 2008/04/28 20:24:12 martin Exp $ */ 298542Smckusick 398542Smckusick/*- 498542Smckusick * Copyright (c) 1999 The NetBSD Foundation, Inc. 598542Smckusick * All rights reserved. 698542Smckusick * 798542Smckusick * This code is derived from software contributed to The NetBSD Foundation 898542Smckusick * by Jaromir Dolecek. 9110884Smckusick * 1098542Smckusick * Redistribution and use in source and binary forms, with or without 111558Srgrimes * modification, are permitted provided that the following conditions 121558Srgrimes * are met: 131558Srgrimes * 1. Redistributions of source code must retain the above copyright 141558Srgrimes * notice, this list of conditions and the following disclaimer. 151558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161558Srgrimes * notice, this list of conditions and the following disclaimer in the 171558Srgrimes * documentation and/or other materials provided with the distribution. 181558Srgrimes * 191558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201558Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211558Srgrimes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221558Srgrimes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231558Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241558Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251558Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261558Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271558Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281558Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291558Srgrimes * POSSIBILITY OF SUCH DAMAGE. 301558Srgrimes */ 311558Srgrimes 321558Srgrimes#include <sys/cdefs.h> 331558Srgrimes__RCSID("$NetBSD: ntfs.c,v 1.11 2008/04/28 20:24:12 martin Exp $"); 341558Srgrimes 351558Srgrimes#include <sys/param.h> 361558Srgrimes#include <sys/time.h> 371558Srgrimes#include <sys/proc.h> 381558Srgrimes#include <sys/stat.h> 39114589Sobrien#include <sys/vnode.h> 401558Srgrimes#include <sys/mount.h> 4137664Scharnier 4237664Scharnier#include <ntfs/ntfs.h> 4337664Scharnier#undef dprintf 441558Srgrimes#include <ntfs/ntfs_inode.h> 451558Srgrimes 461558Srgrimes#include <err.h> 4737664Scharnier#include <kvm.h> 48114589Sobrien#include "fstat.h" 4937664Scharnier 50114589Sobrienint 51114589Sobrienntfs_filestat(struct vnode *vp, struct filestat *fsp) 521558Srgrimes{ 531558Srgrimes struct ntnode ntnode; 541558Srgrimes struct fnode fn; 551558Srgrimes struct ntfsmount ntm; 561558Srgrimes 571558Srgrimes /* to get the ntnode, we have to go in two steps - firstly 5895357Sphk * to read appropriate struct fnode and then getting the address 591558Srgrimes * of ntnode and reading it's contents */ 601558Srgrimes if (!KVM_READ(VTOF(vp), &fn, sizeof (fn))) { 611558Srgrimes dprintf("can't read fnode at %p for pid %d", VTOF(vp), Pid); 621558Srgrimes return 0; 6337707Scharnier } 6437707Scharnier if (!KVM_READ(FTONT(&fn), &ntnode, sizeof (ntnode))) { 651558Srgrimes dprintf("can't read ntnode at %p for pid %d", FTONT(&fn), Pid); 6623682Speter return 0; 671558Srgrimes } 681558Srgrimes if (!KVM_READ(ntnode.i_mp, &ntm, sizeof (ntm))) { 6937664Scharnier dprintf("can't read ntfsmount at %p for pid %d", 701558Srgrimes FTONT(&fn), Pid); 71135460Spjd return 0; 721558Srgrimes } 7393777Sbde 741558Srgrimes fsp->fsid = ntnode.i_dev & 0xffff; 751558Srgrimes fsp->fileid = ntnode.i_number; 761558Srgrimes fsp->mode = (mode_t)ntm.ntm_mode | getftype(vp->v_type); 771558Srgrimes fsp->size = fn.f_size; 781558Srgrimes fsp->rdev = 0; /* XXX */ 791558Srgrimes return 1; 80204654Ssobomax} 81204654Ssobomax