1999-12-03 20:37:40 +00:00
|
|
|
/* $NetBSD: ntfs_vnops.c,v 1.23 1999/10/31 19:45:27 jdolecek Exp $ */
|
1999-05-12 09:43:09 +00:00
|
|
|
|
2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
1999-02-03 04:07:38 +00:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* John Heidemann of the UCLA Ficus project.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1999-02-03 04:07:38 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1999-02-03 04:07:38 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_pager.h>
|
|
|
|
#include <vm/vnode_pager.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
/*#define NTFS_DEBUG 1*/
|
2001-05-26 11:57:45 +00:00
|
|
|
#include <fs/ntfs/ntfs.h>
|
|
|
|
#include <fs/ntfs/ntfs_inode.h>
|
|
|
|
#include <fs/ntfs/ntfs_subr.h>
|
1999-12-03 20:37:40 +00:00
|
|
|
|
|
|
|
#include <sys/unistd.h> /* for pathconf(2) constants */
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_read_t ntfs_read;
|
|
|
|
static vop_write_t ntfs_write;
|
|
|
|
static vop_getattr_t ntfs_getattr;
|
|
|
|
static vop_inactive_t ntfs_inactive;
|
|
|
|
static vop_reclaim_t ntfs_reclaim;
|
|
|
|
static vop_bmap_t ntfs_bmap;
|
|
|
|
static vop_strategy_t ntfs_strategy;
|
|
|
|
static vop_access_t ntfs_access;
|
|
|
|
static vop_open_t ntfs_open;
|
|
|
|
static vop_close_t ntfs_close;
|
|
|
|
static vop_readdir_t ntfs_readdir;
|
2004-12-01 23:16:38 +00:00
|
|
|
static vop_cachedlookup_t ntfs_lookup;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_fsync_t ntfs_fsync;
|
2004-12-01 23:16:38 +00:00
|
|
|
static vop_pathconf_t ntfs_pathconf;
|
2007-02-15 22:08:35 +00:00
|
|
|
static vop_vptofh_t ntfs_vptofh;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
int ntfs_prtactive = 1; /* 1 => print out reclaim of active vnodes */
|
|
|
|
|
2002-09-25 23:55:06 +00:00
|
|
|
/*
|
|
|
|
* This is a noop, simply returning what one has been given.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ntfs_bmap(ap)
|
|
|
|
struct vop_bmap_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
daddr_t a_bn;
|
2004-11-15 09:18:27 +00:00
|
|
|
struct bufobj **a_bop;
|
2002-09-25 23:55:06 +00:00
|
|
|
daddr_t *a_bnp;
|
|
|
|
int *a_runp;
|
|
|
|
int *a_runb;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
2004-12-12 12:02:34 +00:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
2002-09-25 23:55:06 +00:00
|
|
|
dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
|
2004-11-15 09:18:27 +00:00
|
|
|
if (ap->a_bop != NULL)
|
2005-01-27 13:50:27 +00:00
|
|
|
*ap->a_bop = &vp->v_bufobj;
|
2002-09-25 23:55:06 +00:00
|
|
|
if (ap->a_bnp != NULL)
|
|
|
|
*ap->a_bnp = ap->a_bn;
|
|
|
|
if (ap->a_runp != NULL)
|
|
|
|
*ap->a_runp = 0;
|
|
|
|
if (ap->a_runb != NULL)
|
|
|
|
*ap->a_runb = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
|
|
|
ntfs_read(ap)
|
|
|
|
struct vop_read_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct vnode *vp = ap->a_vp;
|
1999-02-19 12:31:02 +00:00
|
|
|
register struct fnode *fp = VTOF(vp);
|
|
|
|
register struct ntnode *ip = FTONT(fp);
|
1999-02-03 04:07:38 +00:00
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
struct ntfsmount *ntmp = ip->i_mp;
|
2002-07-31 00:42:57 +00:00
|
|
|
struct buf *bp;
|
|
|
|
daddr_t cn;
|
|
|
|
int resid, off, toread;
|
1999-02-03 04:07:38 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
dprintf(("ntfs_read: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/* don't allow reading after end of file */
|
|
|
|
if (uio->uio_offset > fp->f_size)
|
2002-07-31 00:42:57 +00:00
|
|
|
return (0);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2006-11-20 19:28:36 +00:00
|
|
|
resid = MIN(uio->uio_resid, fp->f_size - uio->uio_offset);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2002-07-31 00:42:57 +00:00
|
|
|
dprintf((", resid: %d\n", resid));
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
while (resid) {
|
|
|
|
cn = ntfs_btocn(uio->uio_offset);
|
|
|
|
off = ntfs_btocnoff(uio->uio_offset);
|
|
|
|
|
2006-11-20 19:28:36 +00:00
|
|
|
toread = MIN(off + resid, ntfs_cntob(1));
|
2002-07-31 00:42:57 +00:00
|
|
|
|
|
|
|
error = bread(vp, cn, ntfs_cntob(1), NOCRED, &bp);
|
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = uiomove(bp->b_data + off, toread - off, uio);
|
|
|
|
if(error) {
|
|
|
|
brelse(bp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
brelse(bp);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2002-07-31 00:42:57 +00:00
|
|
|
resid -= toread - off;
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
2002-07-31 00:42:57 +00:00
|
|
|
return (error);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_getattr(ap)
|
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1999-02-03 04:07:38 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct vnode *vp = ap->a_vp;
|
1999-02-19 12:31:02 +00:00
|
|
|
register struct fnode *fp = VTOF(vp);
|
|
|
|
register struct ntnode *ip = FTONT(fp);
|
1999-02-03 04:07:38 +00:00
|
|
|
register struct vattr *vap = ap->a_vap;
|
|
|
|
|
|
|
|
dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
vap->va_fsid = dev2udev(ip->i_dev);
|
1999-02-03 04:07:38 +00:00
|
|
|
vap->va_fileid = ip->i_number;
|
1999-12-03 20:37:40 +00:00
|
|
|
vap->va_mode = ip->i_mp->ntm_mode;
|
2006-10-21 08:17:17 +00:00
|
|
|
vap->va_nlink = (ip->i_nlink || ip->i_flag & IN_LOADED ? ip->i_nlink : 1);
|
1999-12-03 20:37:40 +00:00
|
|
|
vap->va_uid = ip->i_mp->ntm_uid;
|
|
|
|
vap->va_gid = ip->i_mp->ntm_gid;
|
2008-09-20 19:49:15 +00:00
|
|
|
vap->va_rdev = NODEV;
|
1999-02-19 12:31:02 +00:00
|
|
|
vap->va_size = fp->f_size;
|
|
|
|
vap->va_bytes = fp->f_allocated;
|
|
|
|
vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
|
|
|
|
vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
|
|
|
|
vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
|
1999-02-03 04:07:38 +00:00
|
|
|
vap->va_flags = ip->i_flag;
|
|
|
|
vap->va_gen = 0;
|
|
|
|
vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
|
1999-12-03 20:37:40 +00:00
|
|
|
vap->va_type = vp->v_type;
|
1999-02-03 04:07:38 +00:00
|
|
|
vap->va_filerev = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Last reference to an ntnode. If necessary, write or delete it.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ntfs_inactive(ap)
|
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct vnode *vp = ap->a_vp;
|
1999-12-03 20:37:40 +00:00
|
|
|
#ifdef NTFS_DEBUG
|
1999-02-03 04:07:38 +00:00
|
|
|
register struct ntnode *ip = VTONT(vp);
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2002-09-25 02:32:42 +00:00
|
|
|
if (ntfs_prtactive && vrefcnt(vp) != 0)
|
1999-02-03 04:07:38 +00:00
|
|
|
vprint("ntfs_inactive: pushing active", vp);
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/* XXX since we don't support any filesystem changes
|
|
|
|
* right now, nothing more needs to be done
|
1999-02-03 04:07:38 +00:00
|
|
|
*/
|
1999-12-03 20:37:40 +00:00
|
|
|
return (0);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-12-03 20:37:40 +00:00
|
|
|
* Reclaim an fnode/ntnode so that it can be used for other purposes.
|
1999-02-03 04:07:38 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
ntfs_reclaim(ap)
|
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct vnode *vp = ap->a_vp;
|
1999-02-19 12:31:02 +00:00
|
|
|
register struct fnode *fp = VTOF(vp);
|
|
|
|
register struct ntnode *ip = FTONT(fp);
|
1999-04-20 21:06:44 +00:00
|
|
|
int error;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2002-09-25 02:32:42 +00:00
|
|
|
if (ntfs_prtactive && vrefcnt(vp) != 0)
|
1999-12-03 20:37:40 +00:00
|
|
|
vprint("ntfs_reclaim: pushing active", vp);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2006-01-17 17:29:03 +00:00
|
|
|
/*
|
|
|
|
* Destroy the vm object and flush associated pages.
|
|
|
|
*/
|
|
|
|
vnode_destroy_vobject(vp);
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
if ((error = ntfs_ntget(ip)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
/* Purge old data structures associated with the inode. */
|
|
|
|
ntfs_frele(fp);
|
1999-04-20 21:06:44 +00:00
|
|
|
ntfs_ntput(ip);
|
1999-12-03 20:37:40 +00:00
|
|
|
vp->v_data = NULL;
|
1999-04-20 21:06:44 +00:00
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the logical to physical mapping if not done already,
|
|
|
|
* then call the device strategy routine.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ntfs_strategy(ap)
|
|
|
|
struct vop_strategy_args /* {
|
|
|
|
struct buf *a_bp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct buf *bp = ap->a_bp;
|
2004-10-27 06:48:21 +00:00
|
|
|
register struct vnode *vp = ap->a_vp;
|
1999-02-19 12:31:02 +00:00
|
|
|
register struct fnode *fp = VTOF(vp);
|
|
|
|
register struct ntnode *ip = FTONT(fp);
|
|
|
|
struct ntfsmount *ntmp = ip->i_mp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
dprintf(("ntfs_strategy: offset: %d, blkno: %d, lblkno: %d\n",
|
|
|
|
(u_int32_t)bp->b_offset,(u_int32_t)bp->b_blkno,
|
|
|
|
(u_int32_t)bp->b_lblkno));
|
1999-12-03 20:37:40 +00:00
|
|
|
|
2006-11-20 19:28:36 +00:00
|
|
|
dprintf(("strategy: bcount: %d flags: 0x%x\n",
|
1999-02-19 12:31:02 +00:00
|
|
|
(u_int32_t)bp->b_bcount,bp->b_flags));
|
|
|
|
|
2000-03-20 10:44:49 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ) {
|
1999-02-19 12:31:02 +00:00
|
|
|
u_int32_t toread;
|
|
|
|
|
|
|
|
if (ntfs_cntob(bp->b_blkno) >= fp->f_size) {
|
|
|
|
clrbuf(bp);
|
|
|
|
error = 0;
|
|
|
|
} else {
|
2006-11-20 19:28:36 +00:00
|
|
|
toread = MIN(bp->b_bcount,
|
1999-02-19 12:31:02 +00:00
|
|
|
fp->f_size-ntfs_cntob(bp->b_blkno));
|
|
|
|
dprintf(("ntfs_strategy: toread: %d, fsize: %d\n",
|
|
|
|
toread,(u_int32_t)fp->f_size));
|
|
|
|
|
|
|
|
error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
|
|
|
|
fp->f_attrname, ntfs_cntob(bp->b_blkno),
|
1999-12-03 20:37:40 +00:00
|
|
|
toread, bp->b_data, NULL);
|
1999-02-19 12:31:02 +00:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
printf("ntfs_strategy: ntfs_readattr failed\n");
|
|
|
|
bp->b_error = error;
|
2000-04-02 15:24:56 +00:00
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
1999-02-19 12:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bzero(bp->b_data + toread, bp->b_bcount - toread);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
size_t tmp;
|
|
|
|
u_int32_t towrite;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) {
|
|
|
|
printf("ntfs_strategy: CAN'T EXTEND FILE\n");
|
|
|
|
bp->b_error = error = EFBIG;
|
2000-04-02 15:24:56 +00:00
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
1999-02-19 12:31:02 +00:00
|
|
|
} else {
|
2006-11-20 19:28:36 +00:00
|
|
|
towrite = MIN(bp->b_bcount,
|
1999-02-19 12:31:02 +00:00
|
|
|
fp->f_size-ntfs_cntob(bp->b_blkno));
|
|
|
|
dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n",
|
|
|
|
towrite,(u_int32_t)fp->f_size));
|
|
|
|
|
|
|
|
error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
|
|
|
|
fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite,
|
1999-12-03 20:37:40 +00:00
|
|
|
bp->b_data, &tmp, NULL);
|
1999-02-19 12:31:02 +00:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
printf("ntfs_strategy: ntfs_writeattr fail\n");
|
|
|
|
bp->b_error = error;
|
2000-04-02 15:24:56 +00:00
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
1999-02-19 12:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
bufdone(bp);
|
2008-12-16 21:13:11 +00:00
|
|
|
return (0);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-02-19 12:31:02 +00:00
|
|
|
ntfs_write(ap)
|
|
|
|
struct vop_write_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
struct ucred *a_cred;
|
1999-02-03 04:07:38 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
1999-02-19 12:31:02 +00:00
|
|
|
register struct vnode *vp = ap->a_vp;
|
|
|
|
register struct fnode *fp = VTOF(vp);
|
|
|
|
register struct ntnode *ip = FTONT(fp);
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
struct ntfsmount *ntmp = ip->i_mp;
|
|
|
|
u_int64_t towrite;
|
|
|
|
size_t written;
|
|
|
|
int error;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
dprintf(("ntfs_write: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
|
1999-12-03 20:37:40 +00:00
|
|
|
dprintf(("ntfs_write: filesize: %d",(u_int32_t)fp->f_size));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
if (uio->uio_resid + uio->uio_offset > fp->f_size) {
|
|
|
|
printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
|
1999-02-19 12:31:02 +00:00
|
|
|
return (EFBIG);
|
|
|
|
}
|
|
|
|
|
2006-11-20 19:28:36 +00:00
|
|
|
towrite = MIN(uio->uio_resid, fp->f_size - uio->uio_offset);
|
1999-02-19 12:31:02 +00:00
|
|
|
|
|
|
|
dprintf((", towrite: %d\n",(u_int32_t)towrite));
|
|
|
|
|
|
|
|
error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
|
1999-12-03 20:37:40 +00:00
|
|
|
fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
|
|
|
|
#ifdef NTFS_DEBUG
|
|
|
|
if (error)
|
|
|
|
printf("ntfs_write: ntfs_writeattr failed: %d\n", error);
|
1999-02-03 04:07:38 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
return (error);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ntfs_access(ap)
|
|
|
|
struct vop_access_args /* {
|
|
|
|
struct vnode *a_vp;
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode_t a_accmode;
|
1999-02-03 04:07:38 +00:00
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1999-02-03 04:07:38 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct ntnode *ip = VTONT(vp);
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode_t accmode = ap->a_accmode;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
dprintf(("ntfs_access: %d\n",ip->i_number));
|
|
|
|
|
|
|
|
/*
|
2002-05-16 21:28:32 +00:00
|
|
|
* Disallow write attempts on read-only filesystems;
|
1999-02-03 04:07:38 +00:00
|
|
|
* unless the file is a socket, fifo, or a block or
|
2002-05-16 21:28:32 +00:00
|
|
|
* character device resident on the filesystem.
|
1999-02-03 04:07:38 +00:00
|
|
|
*/
|
2008-10-28 13:44:11 +00:00
|
|
|
if (accmode & VWRITE) {
|
1999-02-19 12:31:02 +00:00
|
|
|
switch ((int)vp->v_type) {
|
1999-02-03 04:07:38 +00:00
|
|
|
case VDIR:
|
|
|
|
case VLNK:
|
|
|
|
case VREG:
|
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-20 08:36:26 +00:00
|
|
|
return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid,
|
2008-10-28 13:44:11 +00:00
|
|
|
ip->i_mp->ntm_gid, ap->a_accmode, ap->a_cred, NULL));
|
2000-08-20 08:36:26 +00:00
|
|
|
}
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open called.
|
|
|
|
*
|
|
|
|
* Nothing to do.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
ntfs_open(ap)
|
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1999-02-03 04:07:38 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
2005-12-04 02:12:43 +00:00
|
|
|
#ifdef NTFS_DEBUG
|
1999-02-03 04:07:38 +00:00
|
|
|
register struct vnode *vp = ap->a_vp;
|
|
|
|
register struct ntnode *ip = VTONT(vp);
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
printf("ntfs_open: %d\n",ip->i_number);
|
1999-02-03 04:07:38 +00:00
|
|
|
#endif
|
|
|
|
|
2005-01-27 13:50:27 +00:00
|
|
|
vnode_create_vobject(ap->a_vp, VTOF(ap->a_vp)->f_size, ap->a_td);
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
/*
|
|
|
|
* Files marked append-only must be opened for appending.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close called.
|
|
|
|
*
|
|
|
|
* Update the times on the inode.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
ntfs_close(ap)
|
|
|
|
struct vop_close_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_fflag;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1999-02-03 04:07:38 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
2005-12-04 02:12:43 +00:00
|
|
|
#ifdef NTFS_DEBUG
|
1999-02-03 04:07:38 +00:00
|
|
|
register struct vnode *vp = ap->a_vp;
|
|
|
|
register struct ntnode *ip = VTONT(vp);
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
printf("ntfs_close: %d\n",ip->i_number);
|
1999-02-03 04:07:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ntfs_readdir(ap)
|
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
int *a_ncookies;
|
|
|
|
u_int **cookies;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct vnode *vp = ap->a_vp;
|
1999-02-19 12:31:02 +00:00
|
|
|
register struct fnode *fp = VTOF(vp);
|
|
|
|
register struct ntnode *ip = FTONT(fp);
|
1999-02-03 04:07:38 +00:00
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
struct ntfsmount *ntmp = ip->i_mp;
|
2003-09-26 20:26:25 +00:00
|
|
|
int i, j, error = 0;
|
|
|
|
wchar c;
|
1999-02-03 04:07:38 +00:00
|
|
|
u_int32_t faked = 0, num;
|
|
|
|
int ncookies = 0;
|
|
|
|
struct dirent cde;
|
|
|
|
off_t off;
|
|
|
|
|
|
|
|
dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
|
|
|
|
|
|
|
|
off = uio->uio_offset;
|
|
|
|
|
|
|
|
/* Simulate . in every dir except ROOT */
|
|
|
|
if( ip->i_number != NTFS_ROOTINO ) {
|
|
|
|
struct dirent dot = { NTFS_ROOTINO,
|
|
|
|
sizeof(struct dirent), DT_DIR, 1, "." };
|
|
|
|
|
|
|
|
if( uio->uio_offset < sizeof(struct dirent) ) {
|
|
|
|
dot.d_fileno = ip->i_number;
|
|
|
|
error = uiomove((char *)&dot,sizeof(struct dirent),uio);
|
|
|
|
if(error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ncookies ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simulate .. in every dir including ROOT */
|
|
|
|
if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
|
|
|
|
struct dirent dotdot = { NTFS_ROOTINO,
|
|
|
|
sizeof(struct dirent), DT_DIR, 2, ".." };
|
|
|
|
|
|
|
|
error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
|
|
|
|
if(error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ncookies ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
|
|
|
|
num = uio->uio_offset / sizeof(struct dirent) - faked;
|
|
|
|
|
|
|
|
while( uio->uio_resid >= sizeof(struct dirent) ) {
|
|
|
|
struct attr_indexentry *iep;
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
error = ntfs_ntreaddir(ntmp, fp, num, &iep);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
if(error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if( NULL == iep )
|
|
|
|
break;
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
|
|
|
|
iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
|
|
|
|
{
|
|
|
|
if(!ntfs_isnamepermitted(ntmp,iep))
|
|
|
|
continue;
|
|
|
|
|
2003-09-26 20:26:25 +00:00
|
|
|
for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
|
|
|
|
c = NTFS_U28(iep->ie_fname[i]);
|
|
|
|
if (c&0xFF00)
|
|
|
|
cde.d_name[j++] = (char)(c>>8);
|
|
|
|
cde.d_name[j] = (char)c&0xFF;
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
2003-09-26 20:26:25 +00:00
|
|
|
cde.d_name[j] = '\0';
|
1999-12-03 20:37:40 +00:00
|
|
|
dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
|
|
|
|
num, cde.d_name, iep->ie_fnametype,
|
|
|
|
iep->ie_flag));
|
2003-09-26 20:26:25 +00:00
|
|
|
cde.d_namlen = j;
|
1999-12-03 20:37:40 +00:00
|
|
|
cde.d_fileno = iep->ie_number;
|
|
|
|
cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
|
|
|
|
cde.d_reclen = sizeof(struct dirent);
|
|
|
|
dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
|
|
|
|
|
|
|
|
error = uiomove((char *)&cde, sizeof(struct dirent), uio);
|
|
|
|
if(error)
|
|
|
|
return (error);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
ncookies++;
|
|
|
|
num++;
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
|
|
|
|
ncookies,(u_int)(uio->uio_offset - off)));
|
|
|
|
dprintf(("ntfs_readdir: off: %d resid: %d\n",
|
|
|
|
(u_int32_t)uio->uio_offset,uio->uio_resid));
|
|
|
|
|
|
|
|
if (!error && ap->a_ncookies != NULL) {
|
|
|
|
struct dirent* dpStart;
|
|
|
|
struct dirent* dp;
|
|
|
|
u_long *cookies;
|
|
|
|
u_long *cookiep;
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
|
1999-02-03 04:07:38 +00:00
|
|
|
if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
|
|
|
|
panic("ntfs_readdir: unexpected uio from NFS server");
|
|
|
|
dpStart = (struct dirent *)
|
1999-05-12 09:43:09 +00:00
|
|
|
((caddr_t)uio->uio_iov->iov_base -
|
|
|
|
(uio->uio_offset - off));
|
2008-10-23 15:53:51 +00:00
|
|
|
cookies = malloc(ncookies * sizeof(u_long),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_TEMP, M_WAITOK);
|
1999-02-03 04:07:38 +00:00
|
|
|
for (dp = dpStart, cookiep = cookies, i=0;
|
|
|
|
i < ncookies;
|
|
|
|
dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
|
|
|
|
off += dp->d_reclen;
|
|
|
|
*cookiep++ = (u_int) off;
|
|
|
|
}
|
|
|
|
*ap->a_ncookies = ncookies;
|
|
|
|
*ap->a_cookies = cookies;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (ap->a_eofflag)
|
|
|
|
*ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
|
|
|
|
*/
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ntfs_lookup(ap)
|
2004-12-01 23:16:38 +00:00
|
|
|
struct vop_cachedlookup_args /* {
|
1999-02-03 04:07:38 +00:00
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct vnode *dvp = ap->a_dvp;
|
|
|
|
register struct ntnode *dip = VTONT(dvp);
|
|
|
|
struct ntfsmount *ntmp = dip->i_mp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct ucred *cred = cnp->cn_cred;
|
|
|
|
int error;
|
2005-03-28 14:26:01 +00:00
|
|
|
dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d\n",
|
1999-12-03 20:37:40 +00:00
|
|
|
(int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
|
2005-03-28 13:45:09 +00:00
|
|
|
dip->i_number));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread);
|
1999-02-03 04:07:38 +00:00
|
|
|
if(error)
|
|
|
|
return (error);
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(dvp->v_mount->mnt_flag & MNT_RDONLY) &&
|
|
|
|
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
|
|
|
|
return (EROFS);
|
|
|
|
|
|
|
|
if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
|
1999-02-03 04:07:38 +00:00
|
|
|
dprintf(("ntfs_lookup: faking . directory in %d\n",
|
|
|
|
dip->i_number));
|
|
|
|
|
|
|
|
VREF(dvp);
|
|
|
|
*ap->a_vpp = dvp;
|
1999-12-03 20:37:40 +00:00
|
|
|
error = 0;
|
|
|
|
} else if (cnp->cn_flags & ISDOTDOT) {
|
1999-02-03 04:07:38 +00:00
|
|
|
struct ntvattr *vap;
|
|
|
|
|
|
|
|
dprintf(("ntfs_lookup: faking .. directory in %d\n",
|
|
|
|
dip->i_number));
|
|
|
|
|
|
|
|
error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
|
|
|
|
if(error)
|
|
|
|
return (error);
|
|
|
|
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(dvp,0);
|
1999-02-03 04:07:38 +00:00
|
|
|
dprintf(("ntfs_lookup: parentdir: %d\n",
|
|
|
|
vap->va_a_name->n_pnumber));
|
2002-03-17 01:25:47 +00:00
|
|
|
error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber,
|
|
|
|
LK_EXCLUSIVE, ap->a_vpp);
|
1999-02-03 04:07:38 +00:00
|
|
|
ntfs_ntvattrrele(vap);
|
1999-12-03 20:37:40 +00:00
|
|
|
if (error) {
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY);
|
1999-12-03 20:37:40 +00:00
|
|
|
return (error);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
1999-04-20 21:06:44 +00:00
|
|
|
error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
|
1999-12-03 20:37:40 +00:00
|
|
|
if (error) {
|
|
|
|
dprintf(("ntfs_ntlookupfile: returned %d\n", error));
|
1999-02-03 04:07:38 +00:00
|
|
|
return (error);
|
1999-12-03 20:37:40 +00:00
|
|
|
}
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
dprintf(("ntfs_lookup: found ino: %d\n",
|
|
|
|
VTONT(*ap->a_vpp)->i_number));
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
|
|
|
|
if (cnp->cn_flags & MAKEENTRY)
|
|
|
|
cache_enter(dvp, *ap->a_vpp, cnp);
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush the blocks of a file to disk.
|
|
|
|
*
|
|
|
|
* This function is worthless for vnodes that represent directories. Maybe we
|
|
|
|
* could just do a sync if they try an fsync on a directory file.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ntfs_fsync(ap)
|
|
|
|
struct vop_fsync_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
int a_waitfor;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1999-02-03 04:07:38 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return POSIX pathconf information applicable to NTFS filesystem
|
|
|
|
*/
|
|
|
|
int
|
2004-12-01 23:16:38 +00:00
|
|
|
ntfs_pathconf(ap)
|
|
|
|
struct vop_pathconf_args *ap;
|
1999-12-03 20:37:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
*ap->a_retval = NTFS_MAXFILENAME;
|
|
|
|
return (0);
|
|
|
|
case _PC_PATH_MAX:
|
|
|
|
*ap->a_retval = PATH_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
*ap->a_retval = 0;
|
|
|
|
return (0);
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1999-02-03 04:07:38 +00:00
|
|
|
|
2007-02-15 22:08:35 +00:00
|
|
|
int
|
|
|
|
ntfs_vptofh(ap)
|
|
|
|
struct vop_vptofh_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct fid *a_fhp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
register struct ntnode *ntp;
|
|
|
|
register struct ntfid *ntfhp;
|
|
|
|
|
|
|
|
ddprintf(("ntfs_fhtovp(): %p\n", ap->a_vp));
|
|
|
|
|
|
|
|
ntp = VTONT(ap->a_vp);
|
|
|
|
ntfhp = (struct ntfid *)ap->a_fhp;
|
|
|
|
ntfhp->ntfid_len = sizeof(struct ntfid);
|
|
|
|
ntfhp->ntfid_ino = ntp->i_number;
|
|
|
|
/* ntfhp->ntfid_gen = ntp->i_gen; */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
/*
|
|
|
|
* Global vfs data structures
|
|
|
|
*/
|
2004-12-01 23:16:38 +00:00
|
|
|
struct vop_vector ntfs_vnodeops = {
|
2005-01-13 18:59:48 +00:00
|
|
|
.vop_default = &default_vnodeops,
|
|
|
|
|
|
|
|
.vop_access = ntfs_access,
|
|
|
|
.vop_bmap = ntfs_bmap,
|
|
|
|
.vop_cachedlookup = ntfs_lookup,
|
|
|
|
.vop_close = ntfs_close,
|
|
|
|
.vop_fsync = ntfs_fsync,
|
|
|
|
.vop_getattr = ntfs_getattr,
|
|
|
|
.vop_inactive = ntfs_inactive,
|
|
|
|
.vop_lookup = vfs_cache_lookup,
|
|
|
|
.vop_open = ntfs_open,
|
|
|
|
.vop_pathconf = ntfs_pathconf,
|
|
|
|
.vop_read = ntfs_read,
|
|
|
|
.vop_readdir = ntfs_readdir,
|
|
|
|
.vop_reclaim = ntfs_reclaim,
|
|
|
|
.vop_strategy = ntfs_strategy,
|
|
|
|
.vop_write = ntfs_write,
|
2007-02-15 22:08:35 +00:00
|
|
|
.vop_vptofh = ntfs_vptofh,
|
2004-12-01 23:16:38 +00:00
|
|
|
};
|