1*f0a7346dSsnj /* $NetBSD: ntfs.c,v 1.13 2014/10/18 08:33:30 snj Exp $ */
288a653acSjdolecek
388a653acSjdolecek /*-
488a653acSjdolecek * Copyright (c) 1999 The NetBSD Foundation, Inc.
588a653acSjdolecek * All rights reserved.
688a653acSjdolecek *
788a653acSjdolecek * This code is derived from software contributed to The NetBSD Foundation
888a653acSjdolecek * by Jaromir Dolecek.
988a653acSjdolecek *
1088a653acSjdolecek * Redistribution and use in source and binary forms, with or without
1188a653acSjdolecek * modification, are permitted provided that the following conditions
1288a653acSjdolecek * are met:
1388a653acSjdolecek * 1. Redistributions of source code must retain the above copyright
1488a653acSjdolecek * notice, this list of conditions and the following disclaimer.
1588a653acSjdolecek * 2. Redistributions in binary form must reproduce the above copyright
1688a653acSjdolecek * notice, this list of conditions and the following disclaimer in the
1788a653acSjdolecek * documentation and/or other materials provided with the distribution.
1888a653acSjdolecek *
1988a653acSjdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2088a653acSjdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2188a653acSjdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2288a653acSjdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2388a653acSjdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2488a653acSjdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2588a653acSjdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2688a653acSjdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2788a653acSjdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2888a653acSjdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2988a653acSjdolecek * POSSIBILITY OF SUCH DAMAGE.
3088a653acSjdolecek */
3188a653acSjdolecek
3288a653acSjdolecek #include <sys/cdefs.h>
33*f0a7346dSsnj __RCSID("$NetBSD: ntfs.c,v 1.13 2014/10/18 08:33:30 snj Exp $");
3488a653acSjdolecek
3588a653acSjdolecek #include <sys/param.h>
3688a653acSjdolecek #include <sys/time.h>
3788a653acSjdolecek #include <sys/proc.h>
3888a653acSjdolecek #include <sys/stat.h>
3988a653acSjdolecek #include <sys/vnode.h>
401a3b3e1fSjdolecek #include <sys/mount.h>
411a3b3e1fSjdolecek
4288a653acSjdolecek #include <ntfs/ntfs.h>
4388a653acSjdolecek #undef dprintf
4488a653acSjdolecek #include <ntfs/ntfs_inode.h>
4588a653acSjdolecek
460238a51cSjdolecek #include <err.h>
4788a653acSjdolecek #include <kvm.h>
4888a653acSjdolecek #include "fstat.h"
4988a653acSjdolecek
5088a653acSjdolecek int
ntfs_filestat(struct vnode * vp,struct filestat * fsp)5155388191Schristos ntfs_filestat(struct vnode *vp, struct filestat *fsp)
5288a653acSjdolecek {
5388a653acSjdolecek struct ntnode ntnode;
5488a653acSjdolecek struct fnode fn;
55facd78dcSjdolecek struct ntfsmount ntm;
5688a653acSjdolecek
5788a653acSjdolecek /* to get the ntnode, we have to go in two steps - firstly
5888a653acSjdolecek * to read appropriate struct fnode and then getting the address
59*f0a7346dSsnj * of ntnode and reading its contents */
6088a653acSjdolecek if (!KVM_READ(VTOF(vp), &fn, sizeof (fn))) {
610238a51cSjdolecek dprintf("can't read fnode at %p for pid %d", VTOF(vp), Pid);
6288a653acSjdolecek return 0;
6388a653acSjdolecek }
6488a653acSjdolecek if (!KVM_READ(FTONT(&fn), &ntnode, sizeof (ntnode))) {
650238a51cSjdolecek dprintf("can't read ntnode at %p for pid %d", FTONT(&fn), Pid);
6688a653acSjdolecek return 0;
6788a653acSjdolecek }
68facd78dcSjdolecek if (!KVM_READ(ntnode.i_mp, &ntm, sizeof (ntm))) {
690238a51cSjdolecek dprintf("can't read ntfsmount at %p for pid %d",
70facd78dcSjdolecek FTONT(&fn), Pid);
71facd78dcSjdolecek return 0;
72facd78dcSjdolecek }
7388a653acSjdolecek
7488a653acSjdolecek fsp->fsid = ntnode.i_dev & 0xffff;
75dadffc77Slukem fsp->fileid = ntnode.i_number;
769200b8eaSjdolecek fsp->mode = (mode_t)ntm.ntm_mode | getftype(vp->v_type);
7788a653acSjdolecek fsp->size = fn.f_size;
7888a653acSjdolecek fsp->rdev = 0; /* XXX */
7988a653acSjdolecek return 1;
8088a653acSjdolecek }
81