/*
* 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.
* 3. 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.
*
* Id: ntfs_vnops.c,v 1.5 1999/05/12 09:43:06 semenu Exp
*
*/
#include <sys/unistd.h> /* for pathconf(2) constants */
static int ntfs_bypass(void *);
static int ntfs_read(void *);
static int ntfs_write(void *);
static int ntfs_getattr(void *);
static int ntfs_inactive(void *);
static int ntfs_print(void *);
static int ntfs_reclaim(void *);
static int ntfs_strategy(void *);
static int ntfs_access(void *);
static int ntfs_open(void *);
static int ntfs_close(void *);
static int ntfs_readdir(void *);
static int ntfs_lookup(void *);
static int ntfs_bmap(void *);
static int ntfs_fsync(void *);
static int ntfs_pathconf(void *);
/*
* This is a noop, simply returning what one has been given.
*/
int
ntfs_bmap(void *v)
{
struct vop_bmap_args /* {
struct vnode *a_vp;
daddr_t a_bn;
struct vnode **a_vpp;
daddr_t *a_bnp;
int *a_runp;
int *a_runb;
} */ *ap = v;
dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
if (ap->a_vpp != NULL)
*ap->a_vpp = ap->a_vp;
if (ap->a_bnp != NULL)
*ap->a_bnp = ap->a_bn;
if (ap->a_runp != NULL)
*ap->a_runp = 0;
return (0);
}
/*
* Last reference to an ntnode. If necessary, write or delete it.
*/
int
ntfs_inactive(void *v)
{
struct vop_inactive_v2_args /* {
struct vnode *a_vp;
bool *a_recycle;
} */ *ap = v;
struct vnode *vp __unused = ap->a_vp;
#ifdef NTFS_DEBUG
struct ntnode *ip = VTONT(vp);
#endif
dprintf(("ntfs_inactive: vnode: %p, ntnode: %llu\n", vp,
(unsigned long long)ip->i_number));
/* XXX since we don't support any filesystem changes
* right now, nothing more needs to be done
*/
return (0);
}
/*
* Reclaim an fnode/ntnode so that it can be used for other purposes.
*/
int
ntfs_reclaim(void *v)
{
struct vop_reclaim_v2_args /* {
struct vnode *a_vp;
} */ *ap = v;
struct vnode *vp = ap->a_vp;
struct fnode *fp = VTOF(vp);
struct ntnode *ip = FTONT(fp);
const int attrlen = strlen(fp->f_attrname);
int error;
VOP_UNLOCK(vp);
dprintf(("ntfs_reclaim: vnode: %p, ntnode: %llu\n", vp,
(unsigned long long)ip->i_number));
if ((error = ntfs_ntget(ip)) != 0)
return (error);
/*
* Disallow write attempts on read-only file systems;
* unless the file is a socket, fifo, or a block or
* character device resident on the file system.
*/
if (accmode & VWRITE) {
switch ((int)vp->v_type) {
case VDIR:
case VLNK:
case VREG:
if (vp->v_mount->mnt_flag & MNT_RDONLY)
return (EROFS);
break;
}
}
/*
* We now have a segment name to search for, and a directory
* to search.
*
* Before tediously performing a linear scan of the directory,
* check the name cache to see if the directory/name pair
* we are looking for is known already.
*/
if (cache_lookup(ap->a_dvp, cnp->cn_nameptr, cnp->cn_namelen,
cnp->cn_nameiop, cnp->cn_flags, NULL, ap->a_vpp)) {
return *ap->a_vpp == NULLVP ? ENOENT : 0;
}
if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
dprintf(("ntfs_lookup: faking . directory in %llu\n",
(unsigned long long)dip->i_number));
/*
* 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(void *v)
{
struct vop_fsync_args /* {
struct vnode *a_vp;
kauth_cred_t a_cred;
int a_flags;
off_t offlo;
off_t offhi;
} */ *ap = v;
struct vnode *vp = ap->a_vp;
if (ap->a_flags & FSYNC_CACHE) {
return EOPNOTSUPP;
}
return vflushbuf(vp, ap->a_flags);
}
/*
* Return POSIX pathconf information applicable to NTFS filesystem
*/
static int
ntfs_pathconf(void *v)
{
struct vop_pathconf_args /* {
struct vnode *a_vp;
int a_name;
register_t *a_retval;
} */ *ap = v;
switch (ap->a_name) {
case _PC_LINK_MAX:
*ap->a_retval = 1;
return (0);
case _PC_NAME_MAX:
*ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_namemax;
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);
case _PC_SYNC_IO:
*ap->a_retval = 1;
return (0);
case _PC_FILESIZEBITS:
*ap->a_retval = 64;
return (0);
default:
return genfs_pathconf(ap);
}
/* NOTREACHED */
}
/*
* Global vfs data structures
*/
vop_t **ntfs_vnodeop_p;