Home | History | Annotate | Line # | Download | only in nilfs
nilfs_vnops.c revision 1.4.4.2
      1  1.4.4.2    rmind /* $NetBSD: nilfs_vnops.c,v 1.4.4.2 2010/07/03 01:19:50 rmind Exp $ */
      2      1.1  reinoud 
      3      1.1  reinoud /*
      4      1.1  reinoud  * Copyright (c) 2008, 2009 Reinoud Zandijk
      5      1.1  reinoud  * All rights reserved.
      6      1.1  reinoud  *
      7      1.1  reinoud  * Redistribution and use in source and binary forms, with or without
      8      1.1  reinoud  * modification, are permitted provided that the following conditions
      9      1.1  reinoud  * are met:
     10      1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     11      1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     12      1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     15      1.1  reinoud  *
     16      1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1  reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1  reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1  reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1  reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21      1.1  reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22      1.1  reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23      1.1  reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24      1.1  reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25      1.1  reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26      1.1  reinoud  *
     27      1.1  reinoud  */
     28      1.1  reinoud 
     29      1.1  reinoud #include <sys/cdefs.h>
     30      1.1  reinoud #ifndef lint
     31  1.4.4.2    rmind __KERNEL_RCSID(0, "$NetBSD: nilfs_vnops.c,v 1.4.4.2 2010/07/03 01:19:50 rmind Exp $");
     32      1.1  reinoud #endif /* not lint */
     33      1.1  reinoud 
     34      1.1  reinoud 
     35      1.1  reinoud #include <sys/param.h>
     36      1.1  reinoud #include <sys/systm.h>
     37      1.1  reinoud #include <sys/namei.h>
     38      1.1  reinoud #include <sys/resourcevar.h>	/* defines plimit structure in proc struct */
     39      1.1  reinoud #include <sys/kernel.h>
     40      1.1  reinoud #include <sys/file.h>		/* define FWRITE ... */
     41      1.1  reinoud #include <sys/stat.h>
     42      1.1  reinoud #include <sys/buf.h>
     43      1.1  reinoud #include <sys/proc.h>
     44      1.1  reinoud #include <sys/mount.h>
     45      1.1  reinoud #include <sys/vnode.h>
     46      1.1  reinoud #include <sys/signalvar.h>
     47      1.1  reinoud #include <sys/malloc.h>
     48      1.1  reinoud #include <sys/dirent.h>
     49      1.1  reinoud #include <sys/lockf.h>
     50      1.1  reinoud #include <sys/kauth.h>
     51      1.1  reinoud 
     52      1.1  reinoud #include <miscfs/genfs/genfs.h>
     53      1.1  reinoud #include <uvm/uvm_extern.h>
     54      1.1  reinoud 
     55      1.1  reinoud #include <fs/nilfs/nilfs_mount.h>
     56      1.1  reinoud #include "nilfs.h"
     57      1.1  reinoud #include "nilfs_subr.h"
     58      1.1  reinoud #include "nilfs_bswap.h"
     59      1.1  reinoud 
     60      1.1  reinoud 
     61      1.1  reinoud #define VTOI(vnode) ((struct nilfs_node *) (vnode)->v_data)
     62      1.1  reinoud 
     63      1.1  reinoud 
     64      1.1  reinoud /* externs */
     65      1.1  reinoud extern int prtactive;
     66      1.1  reinoud 
     67      1.1  reinoud /* implementations of vnode functions; table follows at end */
     68      1.1  reinoud /* --------------------------------------------------------------------- */
     69      1.1  reinoud 
     70      1.1  reinoud int
     71      1.1  reinoud nilfs_inactive(void *v)
     72      1.1  reinoud {
     73      1.1  reinoud 	struct vop_inactive_args /* {
     74      1.1  reinoud 		struct vnode *a_vp;
     75      1.1  reinoud 		bool         *a_recycle;
     76      1.1  reinoud 	} */ *ap = v;
     77      1.1  reinoud 	struct vnode *vp = ap->a_vp;
     78      1.1  reinoud 	struct nilfs_node *nilfs_node = VTOI(vp);
     79      1.1  reinoud 
     80      1.1  reinoud 	DPRINTF(NODE, ("nilfs_inactive called for nilfs_node %p\n", VTOI(vp)));
     81      1.1  reinoud 
     82      1.1  reinoud 	if (nilfs_node == NULL) {
     83      1.1  reinoud 		DPRINTF(NODE, ("nilfs_inactive: inactive NULL NILFS node\n"));
     84  1.4.4.2    rmind 		VOP_UNLOCK(vp);
     85      1.1  reinoud 		return 0;
     86      1.1  reinoud 	}
     87      1.1  reinoud 
     88      1.1  reinoud 	/*
     89      1.1  reinoud 	 * Optionally flush metadata to disc. If the file has not been
     90      1.1  reinoud 	 * referenced anymore in a directory we ought to free up the resources
     91      1.1  reinoud 	 * on disc if applicable.
     92      1.1  reinoud 	 */
     93  1.4.4.2    rmind 	VOP_UNLOCK(vp);
     94      1.1  reinoud 
     95      1.1  reinoud 	return 0;
     96      1.1  reinoud }
     97      1.1  reinoud 
     98      1.1  reinoud /* --------------------------------------------------------------------- */
     99      1.1  reinoud 
    100      1.1  reinoud int
    101      1.1  reinoud nilfs_reclaim(void *v)
    102      1.1  reinoud {
    103      1.1  reinoud 	struct vop_reclaim_args /* {
    104      1.1  reinoud 		struct vnode *a_vp;
    105      1.1  reinoud 	} */ *ap = v;
    106      1.1  reinoud 	struct vnode *vp = ap->a_vp;
    107      1.1  reinoud 	struct nilfs_node *nilfs_node = VTOI(vp);
    108      1.1  reinoud 
    109      1.1  reinoud 	DPRINTF(NODE, ("nilfs_reclaim called for node %p\n", nilfs_node));
    110      1.1  reinoud 	if (prtactive && vp->v_usecount > 1)
    111      1.1  reinoud 		vprint("nilfs_reclaim(): pushing active", vp);
    112      1.1  reinoud 
    113      1.1  reinoud 	if (nilfs_node == NULL) {
    114      1.1  reinoud 		DPRINTF(NODE, ("nilfs_reclaim(): null nilfsnode\n"));
    115      1.1  reinoud 		return 0;
    116      1.1  reinoud 	}
    117      1.1  reinoud 
    118      1.1  reinoud 	/* update note for closure */
    119      1.1  reinoud 	nilfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
    120      1.1  reinoud 
    121      1.1  reinoud 	/* purge old data from namei */
    122      1.1  reinoud 	cache_purge(vp);
    123      1.1  reinoud 
    124      1.1  reinoud 	/* dispose all node knowledge */
    125      1.1  reinoud 	nilfs_dispose_node(&nilfs_node);
    126      1.1  reinoud 
    127      1.1  reinoud 	return 0;
    128      1.1  reinoud }
    129      1.1  reinoud 
    130      1.1  reinoud /* --------------------------------------------------------------------- */
    131      1.1  reinoud 
    132      1.1  reinoud int
    133      1.1  reinoud nilfs_read(void *v)
    134      1.1  reinoud {
    135      1.1  reinoud 	struct vop_read_args /* {
    136      1.1  reinoud 		struct vnode *a_vp;
    137      1.1  reinoud 		struct uio *a_uio;
    138      1.1  reinoud 		int a_ioflag;
    139      1.1  reinoud 		kauth_cred_t a_cred;
    140      1.1  reinoud 	} */ *ap = v;
    141      1.1  reinoud 	struct vnode *vp     = ap->a_vp;
    142      1.1  reinoud 	struct uio   *uio    = ap->a_uio;
    143      1.1  reinoud 	int           ioflag = ap->a_ioflag;
    144      1.1  reinoud 	int           advice = IO_ADV_DECODE(ap->a_ioflag);
    145      1.1  reinoud 	struct uvm_object    *uobj;
    146      1.1  reinoud 	struct nilfs_node      *nilfs_node = VTOI(vp);
    147      1.1  reinoud 	uint64_t file_size;
    148      1.1  reinoud 	vsize_t len;
    149      1.1  reinoud 	int error;
    150      1.1  reinoud 	int flags;
    151      1.1  reinoud 
    152      1.1  reinoud 	DPRINTF(READ, ("nilfs_read called\n"));
    153      1.1  reinoud 
    154      1.1  reinoud 	/* can this happen? some filingsystems have this check */
    155      1.1  reinoud 	if (uio->uio_offset < 0)
    156      1.1  reinoud 		return EINVAL;
    157      1.1  reinoud 	if (uio->uio_resid == 0)
    158      1.1  reinoud 		return 0;
    159      1.1  reinoud 
    160      1.1  reinoud 	/* protect against rogue programs reading raw directories and links */
    161      1.1  reinoud 	if ((ioflag & IO_ALTSEMANTICS) == 0) {
    162      1.1  reinoud 		if (vp->v_type == VDIR)
    163      1.1  reinoud 			return EISDIR;
    164      1.1  reinoud 		/* all but regular files just give EINVAL */
    165      1.1  reinoud 		if (vp->v_type != VREG)
    166      1.1  reinoud 			return EINVAL;
    167      1.1  reinoud 	}
    168      1.1  reinoud 
    169      1.1  reinoud 	assert(nilfs_node);
    170      1.1  reinoud 	file_size = nilfs_rw64(nilfs_node->inode.i_size);
    171      1.1  reinoud 
    172      1.1  reinoud 	/* read contents using buffercache */
    173      1.1  reinoud 	uobj = &vp->v_uobj;
    174      1.1  reinoud 	flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
    175      1.1  reinoud 	error = 0;
    176      1.1  reinoud 	while (uio->uio_resid > 0) {
    177      1.1  reinoud 		/* reached end? */
    178      1.1  reinoud 		if (file_size <= uio->uio_offset)
    179      1.1  reinoud 			break;
    180      1.1  reinoud 
    181      1.1  reinoud 		/* maximise length to file extremity */
    182      1.1  reinoud 		len = MIN(file_size - uio->uio_offset, uio->uio_resid);
    183      1.1  reinoud 		if (len == 0)
    184      1.1  reinoud 			break;
    185      1.1  reinoud 
    186      1.1  reinoud 		/* ubc, here we come, prepare to trap */
    187      1.1  reinoud 		error = ubc_uiomove(uobj, uio, len, advice,
    188      1.1  reinoud 		    UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
    189      1.1  reinoud 		if (error)
    190      1.1  reinoud 			break;
    191      1.1  reinoud 	}
    192      1.1  reinoud 
    193      1.1  reinoud 	/* note access time unless not requested */
    194      1.1  reinoud 	if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) {
    195      1.1  reinoud 		nilfs_node->i_flags |= IN_ACCESS;
    196      1.1  reinoud 		if ((ioflag & IO_SYNC) == IO_SYNC)
    197      1.1  reinoud 			error = nilfs_update(vp, NULL, NULL, NULL, UPDATE_WAIT);
    198      1.1  reinoud 	}
    199      1.1  reinoud 
    200      1.1  reinoud 	return error;
    201      1.1  reinoud }
    202      1.1  reinoud 
    203      1.1  reinoud /* --------------------------------------------------------------------- */
    204      1.1  reinoud 
    205      1.1  reinoud int
    206      1.1  reinoud nilfs_write(void *v)
    207      1.1  reinoud {
    208      1.1  reinoud 	struct vop_write_args /* {
    209      1.1  reinoud 		struct vnode *a_vp;
    210      1.1  reinoud 		struct uio *a_uio;
    211      1.1  reinoud 		int a_ioflag;
    212      1.1  reinoud 		kauth_cred_t a_cred;
    213      1.1  reinoud 	} */ *ap = v;
    214      1.1  reinoud 	struct vnode *vp     = ap->a_vp;
    215      1.1  reinoud 	struct uio   *uio    = ap->a_uio;
    216      1.1  reinoud 	int           ioflag = ap->a_ioflag;
    217      1.1  reinoud 	int           advice = IO_ADV_DECODE(ap->a_ioflag);
    218      1.1  reinoud 	struct uvm_object    *uobj;
    219      1.1  reinoud 	struct nilfs_node      *nilfs_node = VTOI(vp);
    220      1.1  reinoud 	uint64_t file_size, old_size;
    221      1.1  reinoud 	vsize_t len;
    222      1.1  reinoud 	int error;
    223      1.1  reinoud 	int flags, resid, extended;
    224      1.1  reinoud 
    225      1.1  reinoud 	DPRINTF(WRITE, ("nilfs_write called\n"));
    226      1.1  reinoud 
    227      1.1  reinoud 	/* can this happen? some filingsystems have this check */
    228      1.1  reinoud 	if (uio->uio_offset < 0)
    229      1.1  reinoud 		return EINVAL;
    230      1.1  reinoud 	if (uio->uio_resid == 0)
    231      1.1  reinoud 		return 0;
    232      1.1  reinoud 
    233      1.1  reinoud 	/* protect against rogue programs writing raw directories or links */
    234      1.1  reinoud 	if ((ioflag & IO_ALTSEMANTICS) == 0) {
    235      1.1  reinoud 		if (vp->v_type == VDIR)
    236      1.1  reinoud 			return EISDIR;
    237      1.1  reinoud 		/* all but regular files just give EINVAL for now */
    238      1.1  reinoud 		if (vp->v_type != VREG)
    239      1.1  reinoud 			return EINVAL;
    240      1.1  reinoud 	}
    241      1.1  reinoud 
    242      1.1  reinoud 	assert(nilfs_node);
    243      1.1  reinoud 	panic("nilfs_write() called\n");
    244      1.1  reinoud return EIO;
    245      1.1  reinoud 
    246      1.1  reinoud 	/* remember old file size */
    247      1.1  reinoud 	assert(nilfs_node);
    248      1.1  reinoud 	file_size = nilfs_rw64(nilfs_node->inode.i_size);
    249      1.1  reinoud 	old_size = file_size;
    250      1.1  reinoud 
    251      1.1  reinoud 	/* if explicitly asked to append, uio_offset can be wrong? */
    252      1.1  reinoud 	if (ioflag & IO_APPEND)
    253      1.1  reinoud 		uio->uio_offset = file_size;
    254      1.1  reinoud 
    255      1.1  reinoud #if 0
    256      1.1  reinoud 	extended = (uio->uio_offset + uio->uio_resid > file_size);
    257      1.1  reinoud 	if (extended) {
    258      1.1  reinoud 		DPRINTF(WRITE, ("extending file from %"PRIu64" to %"PRIu64"\n",
    259      1.1  reinoud 			file_size, uio->uio_offset + uio->uio_resid));
    260      1.1  reinoud 		error = nilfs_grow_node(nilfs_node, uio->uio_offset + uio->uio_resid);
    261      1.1  reinoud 		if (error)
    262      1.1  reinoud 			return error;
    263      1.1  reinoud 		file_size = uio->uio_offset + uio->uio_resid;
    264      1.1  reinoud 	}
    265      1.1  reinoud #endif
    266      1.1  reinoud 
    267      1.1  reinoud 	/* write contents using buffercache */
    268      1.1  reinoud 	uobj = &vp->v_uobj;
    269      1.1  reinoud 	flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
    270      1.1  reinoud 	resid = uio->uio_resid;
    271      1.1  reinoud 	error = 0;
    272      1.1  reinoud 
    273      1.1  reinoud 	uvm_vnp_setwritesize(vp, file_size);
    274      1.1  reinoud 	while (uio->uio_resid > 0) {
    275      1.1  reinoud 		/* maximise length to file extremity */
    276      1.1  reinoud 		len = MIN(file_size - uio->uio_offset, uio->uio_resid);
    277      1.1  reinoud 		if (len == 0)
    278      1.1  reinoud 			break;
    279      1.1  reinoud 
    280      1.1  reinoud 		/* ubc, here we come, prepare to trap */
    281      1.1  reinoud 		error = ubc_uiomove(uobj, uio, len, advice,
    282      1.1  reinoud 		    UBC_WRITE | UBC_UNMAP_FLAG(vp));
    283      1.1  reinoud 		if (error)
    284      1.1  reinoud 			break;
    285      1.1  reinoud 	}
    286      1.1  reinoud 	uvm_vnp_setsize(vp, file_size);
    287      1.1  reinoud 
    288      1.1  reinoud 	/* mark node changed and request update */
    289      1.1  reinoud 	nilfs_node->i_flags |= IN_CHANGE | IN_UPDATE;
    290      1.1  reinoud 
    291      1.1  reinoud 	/*
    292      1.1  reinoud 	 * XXX TODO FFS has code here to reset setuid & setgid when we're not
    293      1.1  reinoud 	 * the superuser as a precaution against tampering.
    294      1.1  reinoud 	 */
    295      1.1  reinoud 
    296      1.1  reinoud 	/* if we wrote a thing, note write action on vnode */
    297      1.1  reinoud 	if (resid > uio->uio_resid)
    298      1.1  reinoud 		VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
    299      1.1  reinoud 
    300      1.1  reinoud 	if (error) {
    301      1.1  reinoud 		/* bring back file size to its former size */
    302      1.1  reinoud 		/* take notice of its errors? */
    303      1.1  reinoud //		(void) nilfs_chsize(vp, (u_quad_t) old_size, NOCRED);
    304      1.1  reinoud 
    305      1.1  reinoud 		/* roll back uio */
    306      1.1  reinoud 		uio->uio_offset -= resid - uio->uio_resid;
    307      1.1  reinoud 		uio->uio_resid = resid;
    308      1.1  reinoud 	} else {
    309      1.1  reinoud 		/* if we write and we're synchronous, update node */
    310      1.1  reinoud 		if ((resid > uio->uio_resid) && ((ioflag & IO_SYNC) == IO_SYNC))
    311      1.1  reinoud 			error = nilfs_update(vp, NULL, NULL, NULL, UPDATE_WAIT);
    312      1.1  reinoud 	}
    313      1.1  reinoud 
    314      1.1  reinoud 	return error;
    315      1.1  reinoud }
    316      1.1  reinoud 
    317      1.1  reinoud 
    318      1.1  reinoud /* --------------------------------------------------------------------- */
    319      1.1  reinoud 
    320      1.1  reinoud /*
    321  1.4.4.2    rmind  * bmap functionality that translates logical block numbers to the virtual
    322  1.4.4.2    rmind  * block numbers to be stored on the vnode itself.
    323      1.1  reinoud  */
    324      1.1  reinoud 
    325      1.1  reinoud int
    326      1.1  reinoud nilfs_trivial_bmap(void *v)
    327      1.1  reinoud {
    328      1.1  reinoud 	struct vop_bmap_args /* {
    329      1.1  reinoud 		struct vnode *a_vp;
    330      1.1  reinoud 		daddr_t a_bn;
    331      1.1  reinoud 		struct vnode **a_vpp;
    332      1.1  reinoud 		daddr_t *a_bnp;
    333      1.1  reinoud 		int *a_runp;
    334      1.1  reinoud 	} */ *ap = v;
    335      1.1  reinoud 	struct vnode  *vp  = ap->a_vp;	/* our node	*/
    336      1.1  reinoud 	struct vnode **vpp = ap->a_vpp;	/* return node	*/
    337      1.1  reinoud 	daddr_t *bnp  = ap->a_bnp;	/* translated	*/
    338      1.1  reinoud 	daddr_t  bn   = ap->a_bn;	/* origional	*/
    339      1.1  reinoud 	int     *runp = ap->a_runp;
    340      1.1  reinoud 	struct nilfs_node *node = VTOI(vp);
    341  1.4.4.2    rmind 	uint64_t *l2vmap;
    342      1.1  reinoud 	uint32_t blocksize;
    343  1.4.4.2    rmind 	int blks, run, error;
    344      1.1  reinoud 
    345      1.1  reinoud 	DPRINTF(TRANSLATE, ("nilfs_bmap() called\n"));
    346      1.1  reinoud 	/* XXX could return `-1' to indicate holes/zero's */
    347      1.1  reinoud 
    348      1.1  reinoud 	blocksize = node->nilfsdev->blocksize;
    349  1.4.4.2    rmind 	blks = MAXPHYS / blocksize;
    350      1.1  reinoud 
    351  1.4.4.2    rmind 	/* get mapping memory */
    352  1.4.4.2    rmind 	l2vmap = malloc(sizeof(uint64_t) * blks, M_TEMP, M_WAITOK);
    353  1.4.4.2    rmind 
    354  1.4.4.2    rmind 	/* get virtual block numbers for the vnode's buffer span */
    355  1.4.4.2    rmind 	error = nilfs_btree_nlookup(node, bn, blks, l2vmap);
    356  1.4.4.2    rmind 	if (error) {
    357  1.4.4.2    rmind 		free(l2vmap, M_TEMP);
    358  1.4.4.2    rmind 		return error;
    359  1.4.4.2    rmind 	}
    360  1.4.4.2    rmind 
    361  1.4.4.2    rmind 	/* store virtual blocks on our own vp */
    362      1.1  reinoud 	if (vpp)
    363      1.1  reinoud 		*vpp = vp;
    364      1.1  reinoud 
    365  1.4.4.2    rmind 	/* start at virt[0] */
    366  1.4.4.2    rmind 	*bnp = l2vmap[0];
    367  1.4.4.2    rmind 
    368  1.4.4.2    rmind 	/* get runlength */
    369  1.4.4.2    rmind 	run = 1;
    370  1.4.4.2    rmind 	while ((run < blks) && (l2vmap[run] == *bnp + run))
    371  1.4.4.2    rmind 		run++;
    372  1.4.4.2    rmind 
    373  1.4.4.2    rmind 	/* set runlength */
    374      1.1  reinoud 	if (runp)
    375  1.4.4.2    rmind 		*runp = run;
    376  1.4.4.2    rmind 
    377  1.4.4.2    rmind 	DPRINTF(TRANSLATE, ("\tstart %"PRIu64" -> %"PRIu64" run %d\n",
    378  1.4.4.2    rmind 		bn, *bnp, run));
    379  1.4.4.2    rmind 
    380  1.4.4.2    rmind 	/* mark not translated on virtual block number 0 */
    381  1.4.4.2    rmind 	if (*bnp == 0)
    382  1.4.4.2    rmind 		*bnp = -1;
    383      1.1  reinoud 
    384      1.1  reinoud 	/* return success */
    385  1.4.4.2    rmind 	free(l2vmap, M_TEMP);
    386      1.1  reinoud 	return 0;
    387      1.1  reinoud }
    388      1.1  reinoud 
    389      1.1  reinoud /* --------------------------------------------------------------------- */
    390      1.1  reinoud 
    391      1.1  reinoud static void
    392      1.1  reinoud nilfs_read_filebuf(struct nilfs_node *node, struct buf *bp)
    393      1.1  reinoud {
    394      1.1  reinoud 	struct nilfs_device *nilfsdev = node->nilfsdev;
    395      1.1  reinoud 	struct buf *nbp;
    396      1.1  reinoud 	uint64_t *l2vmap, *v2pmap;
    397      1.1  reinoud 	uint64_t from, blks;
    398      1.1  reinoud 	uint32_t blocksize, buf_offset;
    399      1.1  reinoud 	uint8_t  *buf_pos;
    400      1.1  reinoud 	int blk2dev = nilfsdev->blocksize / DEV_BSIZE;
    401      1.1  reinoud 	int i, error;
    402      1.1  reinoud 
    403      1.1  reinoud 	/*
    404      1.1  reinoud 	 * Translate all the block sectors into a series of buffers to read
    405      1.1  reinoud 	 * asynchronously from the nilfs device. Note that this lookup may
    406      1.1  reinoud 	 * induce readin's too.
    407      1.1  reinoud 	 */
    408      1.1  reinoud 
    409      1.1  reinoud 	blocksize = nilfsdev->blocksize;
    410      1.1  reinoud 
    411      1.1  reinoud 	from = bp->b_blkno;
    412      1.1  reinoud 	blks = bp->b_bcount / blocksize;
    413      1.1  reinoud 
    414      1.1  reinoud 	DPRINTF(READ, ("\tread in from inode %"PRIu64" blkno %"PRIu64" "
    415      1.1  reinoud 			"+ %"PRIu64" blocks\n", node->ino, from, blks));
    416      1.1  reinoud 
    417      1.1  reinoud 	DPRINTF(READ, ("\t\tblkno %"PRIu64" "
    418      1.1  reinoud 			"+ %d bytes\n", bp->b_blkno, bp->b_bcount));
    419      1.1  reinoud 
    420      1.1  reinoud 	/* get mapping memory */
    421      1.1  reinoud 	l2vmap = malloc(sizeof(uint64_t) * blks, M_TEMP, M_WAITOK);
    422      1.1  reinoud 	v2pmap = malloc(sizeof(uint64_t) * blks, M_TEMP, M_WAITOK);
    423      1.1  reinoud 
    424      1.1  reinoud 	/* get virtual block numbers for the vnode's buffer span */
    425  1.4.4.2    rmind 	for (i = 0; i < blks; i++)
    426  1.4.4.2    rmind 		l2vmap[i] = from + i;
    427      1.1  reinoud 
    428      1.1  reinoud 	/* translate virtual block numbers to physical block numbers */
    429      1.1  reinoud 	error = nilfs_nvtop(node, blks, l2vmap, v2pmap);
    430      1.1  reinoud 	if (error)
    431      1.1  reinoud 		goto out;
    432      1.1  reinoud 
    433      1.1  reinoud 	/* issue translated blocks */
    434      1.1  reinoud 	bp->b_resid = bp->b_bcount;
    435      1.1  reinoud 	for (i = 0; i < blks; i++) {
    436      1.1  reinoud 		DPRINTF(READ, ("read_filebuf : ino %"PRIu64" blk %d -> "
    437      1.1  reinoud 			"%"PRIu64" -> %"PRIu64"\n",
    438      1.1  reinoud 			node->ino, i, l2vmap[i], v2pmap[i]));
    439      1.1  reinoud 
    440      1.1  reinoud 		buf_offset = i * blocksize;
    441      1.1  reinoud 		buf_pos    = (uint8_t *) bp->b_data + buf_offset;
    442      1.1  reinoud 
    443      1.1  reinoud 		/* note virtual block 0 marks not mapped */
    444      1.1  reinoud 		if (l2vmap[i] == 0) {
    445      1.1  reinoud 			memset(buf_pos, 0, blocksize);
    446      1.1  reinoud 			nestiobuf_done(bp, blocksize, 0);
    447      1.1  reinoud 			continue;
    448      1.1  reinoud 		}
    449      1.1  reinoud 
    450      1.1  reinoud 		/* nest iobuf */
    451      1.1  reinoud 		nbp = getiobuf(NULL, true);
    452      1.1  reinoud 		nestiobuf_setup(bp, nbp, buf_offset, blocksize);
    453      1.1  reinoud 		KASSERT(nbp->b_vp == node->vnode);
    454      1.1  reinoud 		/* nbp is B_ASYNC */
    455      1.1  reinoud 
    456      1.1  reinoud 		nbp->b_lblkno   = i;
    457      1.1  reinoud 		nbp->b_blkno    = v2pmap[i] * blk2dev;	/* in DEV_BSIZE */
    458      1.1  reinoud 		nbp->b_rawblkno = nbp->b_blkno;
    459      1.1  reinoud 
    460      1.1  reinoud 		VOP_STRATEGY(nilfsdev->devvp, nbp);
    461      1.1  reinoud 	}
    462      1.1  reinoud 
    463      1.1  reinoud 	if ((bp->b_flags & B_ASYNC) == 0)
    464      1.1  reinoud 		biowait(bp);
    465      1.1  reinoud 
    466      1.1  reinoud out:
    467      1.1  reinoud 	free(l2vmap, M_TEMP);
    468      1.1  reinoud 	free(v2pmap, M_TEMP);
    469      1.1  reinoud 	if (error) {
    470      1.1  reinoud 		bp->b_error = EIO;
    471      1.1  reinoud 		biodone(bp);
    472      1.1  reinoud 	}
    473      1.1  reinoud }
    474      1.1  reinoud 
    475      1.1  reinoud 
    476      1.1  reinoud static void
    477      1.1  reinoud nilfs_write_filebuf(struct nilfs_node *node, struct buf *bp)
    478      1.1  reinoud {
    479      1.1  reinoud 	/* TODO pass on to segment collector */
    480      1.1  reinoud 	panic("nilfs_strategy writing called\n");
    481      1.1  reinoud }
    482      1.1  reinoud 
    483      1.1  reinoud 
    484      1.1  reinoud int
    485      1.1  reinoud nilfs_vfsstrategy(void *v)
    486      1.1  reinoud {
    487      1.1  reinoud 	struct vop_strategy_args /* {
    488      1.1  reinoud 		struct vnode *a_vp;
    489      1.1  reinoud 		struct buf *a_bp;
    490      1.1  reinoud 	} */ *ap = v;
    491      1.1  reinoud 	struct vnode *vp = ap->a_vp;
    492      1.1  reinoud 	struct buf   *bp = ap->a_bp;
    493      1.1  reinoud 	struct nilfs_node *node = VTOI(vp);
    494      1.1  reinoud 
    495      1.1  reinoud 	DPRINTF(STRATEGY, ("nilfs_strategy called\n"));
    496      1.1  reinoud 
    497      1.1  reinoud 	/* check if we ought to be here */
    498      1.1  reinoud 	if (vp->v_type == VBLK || vp->v_type == VCHR)
    499      1.1  reinoud 		panic("nilfs_strategy: spec");
    500      1.1  reinoud 
    501      1.1  reinoud 	/* translate if needed and pass on */
    502      1.1  reinoud 	if (bp->b_flags & B_READ) {
    503      1.1  reinoud 		nilfs_read_filebuf(node, bp);
    504      1.1  reinoud 		return bp->b_error;
    505      1.1  reinoud 	}
    506      1.1  reinoud 
    507      1.1  reinoud 	/* send to segment collector */
    508      1.1  reinoud 	nilfs_write_filebuf(node, bp);
    509      1.1  reinoud 	return bp->b_error;
    510      1.1  reinoud }
    511      1.1  reinoud 
    512      1.1  reinoud /* --------------------------------------------------------------------- */
    513      1.1  reinoud 
    514      1.1  reinoud int
    515      1.1  reinoud nilfs_readdir(void *v)
    516      1.1  reinoud {
    517      1.1  reinoud 	struct vop_readdir_args /* {
    518      1.1  reinoud 		struct vnode *a_vp;
    519      1.1  reinoud 		struct uio *a_uio;
    520      1.1  reinoud 		kauth_cred_t a_cred;
    521      1.1  reinoud 		int *a_eofflag;
    522      1.1  reinoud 		off_t **a_cookies;
    523      1.1  reinoud 		int *a_ncookies;
    524      1.1  reinoud 	} */ *ap = v;
    525      1.1  reinoud 	struct uio *uio = ap->a_uio;
    526      1.1  reinoud 	struct vnode *vp = ap->a_vp;
    527      1.1  reinoud 	struct nilfs_node *node = VTOI(vp);
    528      1.1  reinoud 	struct nilfs_dir_entry *ndirent;
    529      1.1  reinoud 	struct dirent dirent;
    530      1.1  reinoud 	struct buf *bp;
    531      1.1  reinoud 	uint64_t file_size, diroffset, transoffset, blkoff;
    532      1.1  reinoud 	uint64_t blocknr;
    533      1.1  reinoud 	uint32_t blocksize = node->nilfsdev->blocksize;
    534      1.1  reinoud 	uint8_t *pos, name_len;
    535      1.1  reinoud 	int error;
    536      1.1  reinoud 
    537      1.1  reinoud 	DPRINTF(READDIR, ("nilfs_readdir called\n"));
    538      1.1  reinoud 
    539      1.1  reinoud 	if (vp->v_type != VDIR)
    540      1.1  reinoud 		return ENOTDIR;
    541      1.1  reinoud 
    542      1.1  reinoud 	file_size = nilfs_rw64(node->inode.i_size);
    543      1.1  reinoud 
    544      1.1  reinoud 	/* we are called just as long as we keep on pushing data in */
    545      1.1  reinoud 	error = 0;
    546      1.1  reinoud 	if ((uio->uio_offset < file_size) &&
    547      1.1  reinoud 	    (uio->uio_resid >= sizeof(struct dirent))) {
    548      1.1  reinoud 		diroffset   = uio->uio_offset;
    549      1.1  reinoud 		transoffset = diroffset;
    550      1.1  reinoud 
    551      1.1  reinoud 		blocknr = diroffset / blocksize;
    552      1.1  reinoud 		blkoff  = diroffset % blocksize;
    553      1.1  reinoud 		error = nilfs_bread(node, blocknr, NOCRED, 0, &bp);
    554      1.1  reinoud 		if (error)
    555      1.1  reinoud 			return EIO;
    556      1.1  reinoud 		while (diroffset < file_size) {
    557      1.1  reinoud 			DPRINTF(READDIR, ("readdir : offset = %"PRIu64"\n",
    558      1.1  reinoud 				diroffset));
    559      1.1  reinoud 			if (blkoff >= blocksize) {
    560      1.1  reinoud 				blkoff = 0; blocknr++;
    561      1.1  reinoud 				brelse(bp, BC_AGE);
    562      1.1  reinoud 				error = nilfs_bread(node, blocknr, NOCRED, 0,
    563      1.1  reinoud 						&bp);
    564      1.1  reinoud 				if (error)
    565      1.1  reinoud 					return EIO;
    566      1.1  reinoud 			}
    567      1.1  reinoud 
    568      1.1  reinoud 			/* read in one dirent */
    569      1.1  reinoud 			pos = (uint8_t *) bp->b_data + blkoff;
    570      1.1  reinoud 			ndirent = (struct nilfs_dir_entry *) pos;
    571      1.1  reinoud 
    572      1.1  reinoud 			name_len = ndirent->name_len;
    573      1.1  reinoud 			memset(&dirent, 0, sizeof(struct dirent));
    574      1.1  reinoud 			dirent.d_fileno = nilfs_rw64(ndirent->inode);
    575      1.1  reinoud 			dirent.d_type   = ndirent->file_type;	/* 1:1 ? */
    576      1.1  reinoud 			dirent.d_namlen = name_len;
    577      1.1  reinoud 			strncpy(dirent.d_name, ndirent->name, name_len);
    578      1.1  reinoud 			dirent.d_reclen = _DIRENT_SIZE(&dirent);
    579      1.1  reinoud 			DPRINTF(READDIR, ("copying `%*.*s`\n", name_len,
    580      1.1  reinoud 				name_len, dirent.d_name));
    581      1.1  reinoud 
    582      1.1  reinoud 			/*
    583      1.1  reinoud 			 * If there isn't enough space in the uio to return a
    584      1.1  reinoud 			 * whole dirent, break off read
    585      1.1  reinoud 			 */
    586      1.1  reinoud 			if (uio->uio_resid < _DIRENT_SIZE(&dirent))
    587      1.1  reinoud 				break;
    588      1.1  reinoud 
    589      1.1  reinoud 			/* transfer */
    590      1.1  reinoud 			if (name_len)
    591      1.1  reinoud 				uiomove(&dirent, _DIRENT_SIZE(&dirent), uio);
    592      1.1  reinoud 
    593      1.1  reinoud 			/* advance */
    594      1.1  reinoud 			diroffset += nilfs_rw16(ndirent->rec_len);
    595      1.1  reinoud 			blkoff    += nilfs_rw16(ndirent->rec_len);
    596      1.1  reinoud 
    597      1.1  reinoud 			/* remember the last entry we transfered */
    598      1.1  reinoud 			transoffset = diroffset;
    599      1.1  reinoud 		}
    600      1.1  reinoud 		brelse(bp, BC_AGE);
    601      1.1  reinoud 
    602      1.1  reinoud 		/* pass on last transfered offset */
    603      1.1  reinoud 		uio->uio_offset = transoffset;
    604      1.1  reinoud 	}
    605      1.1  reinoud 
    606      1.1  reinoud 	if (ap->a_eofflag)
    607      1.1  reinoud 		*ap->a_eofflag = (uio->uio_offset >= file_size);
    608      1.1  reinoud 
    609      1.1  reinoud 	return error;
    610      1.1  reinoud }
    611      1.1  reinoud 
    612      1.1  reinoud /* --------------------------------------------------------------------- */
    613      1.1  reinoud 
    614      1.1  reinoud int
    615      1.1  reinoud nilfs_lookup(void *v)
    616      1.1  reinoud {
    617      1.1  reinoud 	struct vop_lookup_args /* {
    618      1.1  reinoud 		struct vnode *a_dvp;
    619      1.1  reinoud 		struct vnode **a_vpp;
    620      1.1  reinoud 		struct componentname *a_cnp;
    621      1.1  reinoud 	} */ *ap = v;
    622      1.1  reinoud 	struct vnode *dvp = ap->a_dvp;
    623      1.1  reinoud 	struct vnode **vpp = ap->a_vpp;
    624      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
    625      1.1  reinoud 	struct nilfs_node  *dir_node, *res_node;
    626      1.1  reinoud 	struct nilfs_mount *ump;
    627      1.1  reinoud 	uint64_t ino;
    628      1.1  reinoud 	const char *name;
    629      1.1  reinoud 	int namelen, nameiop, islastcn, mounted_ro;
    630      1.1  reinoud 	int vnodetp;
    631      1.1  reinoud 	int error, found;
    632      1.1  reinoud 
    633      1.1  reinoud 	dir_node = VTOI(dvp);
    634      1.1  reinoud 	ump = dir_node->ump;
    635      1.1  reinoud 	*vpp = NULL;
    636      1.1  reinoud 
    637      1.1  reinoud 	DPRINTF(LOOKUP, ("nilfs_lookup called\n"));
    638      1.1  reinoud 
    639      1.1  reinoud 	/* simplify/clarification flags */
    640      1.1  reinoud 	nameiop     = cnp->cn_nameiop;
    641      1.1  reinoud 	islastcn    = cnp->cn_flags & ISLASTCN;
    642      1.1  reinoud 	mounted_ro  = dvp->v_mount->mnt_flag & MNT_RDONLY;
    643      1.1  reinoud 
    644      1.1  reinoud 	/* check exec/dirread permissions first */
    645      1.1  reinoud 	error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred);
    646      1.1  reinoud 	if (error)
    647      1.1  reinoud 		return error;
    648      1.1  reinoud 
    649      1.1  reinoud 	DPRINTF(LOOKUP, ("\taccess ok\n"));
    650      1.1  reinoud 
    651      1.1  reinoud 	/*
    652      1.1  reinoud 	 * If requesting a modify on the last path element on a read-only
    653      1.1  reinoud 	 * filingsystem, reject lookup; XXX why is this repeated in every FS ?
    654      1.1  reinoud 	 */
    655      1.1  reinoud 	if (islastcn && mounted_ro && (nameiop == DELETE || nameiop == RENAME))
    656      1.1  reinoud 		return EROFS;
    657      1.1  reinoud 
    658      1.1  reinoud 	DPRINTF(LOOKUP, ("\tlooking up cnp->cn_nameptr '%s'\n",
    659      1.1  reinoud 	    cnp->cn_nameptr));
    660      1.1  reinoud 	/* look in the nami cache; returns 0 on success!! */
    661      1.1  reinoud 	error = cache_lookup(dvp, vpp, cnp);
    662      1.1  reinoud 	if (error >= 0)
    663      1.1  reinoud 		return error;
    664      1.1  reinoud 
    665      1.1  reinoud 	DPRINTF(LOOKUP, ("\tNOT found in cache\n"));
    666      1.1  reinoud 
    667      1.1  reinoud 	/*
    668      1.1  reinoud 	 * Obviously, the file is not (anymore) in the namecache, we have to
    669      1.1  reinoud 	 * search for it. There are three basic cases: '.', '..' and others.
    670      1.1  reinoud 	 *
    671      1.1  reinoud 	 * Following the guidelines of VOP_LOOKUP manpage and tmpfs.
    672      1.1  reinoud 	 */
    673      1.1  reinoud 	error = 0;
    674      1.1  reinoud 	if ((cnp->cn_namelen == 1) && (cnp->cn_nameptr[0] == '.')) {
    675      1.1  reinoud 		DPRINTF(LOOKUP, ("\tlookup '.'\n"));
    676      1.1  reinoud 		/* special case 1 '.' */
    677      1.4    pooka 		vref(dvp);
    678      1.1  reinoud 		*vpp = dvp;
    679      1.1  reinoud 		/* done */
    680      1.1  reinoud 	} else if (cnp->cn_flags & ISDOTDOT) {
    681      1.1  reinoud 		/* special case 2 '..' */
    682      1.1  reinoud 		DPRINTF(LOOKUP, ("\tlookup '..'\n"));
    683      1.1  reinoud 
    684      1.1  reinoud 		/* get our node */
    685      1.1  reinoud 		name    = "..";
    686      1.1  reinoud 		namelen = 2;
    687      1.1  reinoud 		error = nilfs_lookup_name_in_dir(dvp, name, namelen,
    688      1.1  reinoud 				&ino, &found);
    689      1.1  reinoud 		if (error)
    690      1.1  reinoud 			goto out;
    691      1.1  reinoud 		if (!found)
    692      1.1  reinoud 			error = ENOENT;
    693      1.1  reinoud 
    694      1.1  reinoud 		/* first unlock parent */
    695  1.4.4.2    rmind 		VOP_UNLOCK(dvp);
    696      1.1  reinoud 
    697      1.1  reinoud 		if (error == 0) {
    698      1.1  reinoud 			DPRINTF(LOOKUP, ("\tfound '..'\n"));
    699      1.1  reinoud 			/* try to create/reuse the node */
    700      1.1  reinoud 			error = nilfs_get_node(ump, ino, &res_node);
    701      1.1  reinoud 
    702      1.1  reinoud 			if (!error) {
    703      1.1  reinoud 				DPRINTF(LOOKUP,
    704      1.1  reinoud 					("\tnode retrieved/created OK\n"));
    705      1.1  reinoud 				*vpp = res_node->vnode;
    706      1.1  reinoud 			}
    707      1.1  reinoud 		}
    708      1.1  reinoud 
    709      1.1  reinoud 		/* try to relock parent */
    710      1.1  reinoud 		vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
    711      1.1  reinoud 	} else {
    712      1.1  reinoud 		DPRINTF(LOOKUP, ("\tlookup file\n"));
    713      1.1  reinoud 		/* all other files */
    714      1.1  reinoud 		/* lookup filename in the directory returning its inode */
    715      1.1  reinoud 		name    = cnp->cn_nameptr;
    716      1.1  reinoud 		namelen = cnp->cn_namelen;
    717      1.1  reinoud 		error = nilfs_lookup_name_in_dir(dvp, name, namelen,
    718      1.1  reinoud 				&ino, &found);
    719      1.1  reinoud 		if (error)
    720      1.1  reinoud 			goto out;
    721      1.1  reinoud 		if (!found) {
    722      1.1  reinoud 			DPRINTF(LOOKUP, ("\tNOT found\n"));
    723      1.1  reinoud 			/*
    724      1.1  reinoud 			 * UGH, didn't find name. If we're creating or
    725      1.1  reinoud 			 * renaming on the last name this is OK and we ought
    726      1.1  reinoud 			 * to return EJUSTRETURN if its allowed to be created.
    727      1.1  reinoud 			 */
    728      1.1  reinoud 			error = ENOENT;
    729      1.1  reinoud 			if (islastcn &&
    730      1.1  reinoud 				(nameiop == CREATE || nameiop == RENAME))
    731      1.1  reinoud 					error = 0;
    732      1.1  reinoud 			if (!error) {
    733      1.1  reinoud 				error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
    734      1.1  reinoud 				if (!error) {
    735      1.1  reinoud 					/* keep the component name */
    736      1.1  reinoud 					cnp->cn_flags |= SAVENAME;
    737      1.1  reinoud 					error = EJUSTRETURN;
    738      1.1  reinoud 				}
    739      1.1  reinoud 			}
    740      1.1  reinoud 			/* done */
    741      1.1  reinoud 		} else {
    742      1.1  reinoud 			/* try to create/reuse the node */
    743      1.1  reinoud 			error = nilfs_get_node(ump, ino, &res_node);
    744      1.1  reinoud 			if (!error) {
    745      1.1  reinoud 				/*
    746      1.1  reinoud 				 * If we are not at the last path component
    747      1.1  reinoud 				 * and found a non-directory or non-link entry
    748      1.1  reinoud 				 * (which may itself be pointing to a
    749      1.1  reinoud 				 * directory), raise an error.
    750      1.1  reinoud 				 */
    751      1.1  reinoud 				vnodetp = res_node->vnode->v_type;
    752      1.1  reinoud 				if ((vnodetp != VDIR) && (vnodetp != VLNK)) {
    753      1.1  reinoud 					if (!islastcn)
    754      1.1  reinoud 						error = ENOTDIR;
    755      1.1  reinoud 				}
    756      1.1  reinoud 
    757      1.1  reinoud 			}
    758      1.1  reinoud 			if (!error) {
    759      1.1  reinoud 				*vpp = res_node->vnode;
    760      1.1  reinoud 			}
    761      1.1  reinoud 		}
    762      1.1  reinoud 	}
    763      1.1  reinoud 
    764      1.1  reinoud out:
    765      1.1  reinoud 	/*
    766      1.1  reinoud 	 * Store result in the cache if requested. If we are creating a file,
    767      1.1  reinoud 	 * the file might not be found and thus putting it into the namecache
    768      1.1  reinoud 	 * might be seen as negative caching.
    769      1.1  reinoud 	 */
    770      1.1  reinoud 	if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
    771      1.1  reinoud 		cache_enter(dvp, *vpp, cnp);
    772      1.1  reinoud 
    773      1.1  reinoud 	DPRINTFIF(LOOKUP, error, ("nilfs_lookup returing error %d\n", error));
    774      1.1  reinoud 
    775      1.1  reinoud 	return error;
    776      1.1  reinoud }
    777      1.1  reinoud 
    778      1.1  reinoud /* --------------------------------------------------------------------- */
    779      1.1  reinoud 
    780      1.1  reinoud static void
    781      1.1  reinoud nilfs_ctime_to_timespec(struct timespec *ts, uint64_t ctime)
    782      1.1  reinoud {
    783      1.1  reinoud 	ts->tv_sec  = ctime;
    784      1.1  reinoud 	ts->tv_nsec = 0;
    785      1.1  reinoud }
    786      1.1  reinoud 
    787      1.1  reinoud 
    788      1.1  reinoud int
    789      1.1  reinoud nilfs_getattr(void *v)
    790      1.1  reinoud {
    791      1.1  reinoud 	struct vop_getattr_args /* {
    792      1.1  reinoud 		struct vnode *a_vp;
    793      1.1  reinoud 		struct vattr *a_vap;
    794      1.1  reinoud 		kauth_cred_t a_cred;
    795      1.1  reinoud 		struct lwp   *a_l;
    796      1.1  reinoud 	} */ *ap = v;
    797      1.1  reinoud 	struct vnode       *vp  = ap->a_vp;
    798      1.1  reinoud 	struct vattr       *vap = ap->a_vap;
    799      1.1  reinoud 	struct nilfs_node  *node = VTOI(vp);
    800      1.1  reinoud 	struct nilfs_inode *inode = &node->inode;
    801      1.1  reinoud 
    802      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_getattr called\n"));
    803      1.1  reinoud 
    804      1.1  reinoud 	/* basic info */
    805      1.4    pooka 	vattr_null(vap);
    806      1.1  reinoud 	vap->va_type      = vp->v_type;
    807      1.1  reinoud 	vap->va_mode      = nilfs_rw16(inode->i_mode);	/* XXX same? */
    808      1.1  reinoud 	vap->va_nlink     = nilfs_rw16(inode->i_links_count);
    809      1.1  reinoud 	vap->va_uid       = nilfs_rw32(inode->i_uid);
    810      1.1  reinoud 	vap->va_gid       = nilfs_rw32(inode->i_gid);
    811      1.1  reinoud 	vap->va_fsid      = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
    812      1.1  reinoud 	vap->va_fileid    = node->ino;
    813      1.1  reinoud 	vap->va_size      = nilfs_rw64(inode->i_size);
    814      1.1  reinoud 	vap->va_blocksize = node->nilfsdev->blocksize;
    815      1.1  reinoud 
    816      1.1  reinoud 	/* times */
    817      1.1  reinoud 	nilfs_ctime_to_timespec(&vap->va_atime, nilfs_rw64(inode->i_mtime));
    818      1.1  reinoud 	nilfs_ctime_to_timespec(&vap->va_mtime, nilfs_rw64(inode->i_mtime));
    819      1.1  reinoud 	nilfs_ctime_to_timespec(&vap->va_ctime, nilfs_rw64(inode->i_ctime));
    820      1.1  reinoud 	nilfs_ctime_to_timespec(&vap->va_birthtime, nilfs_rw64(inode->i_ctime));
    821      1.1  reinoud 
    822      1.1  reinoud 	vap->va_gen       = nilfs_rw32(inode->i_generation);
    823      1.1  reinoud 	vap->va_flags     = 0;	/* vattr flags */
    824      1.1  reinoud 	vap->va_bytes     = nilfs_rw64(inode->i_blocks) * vap->va_blocksize;
    825      1.1  reinoud 	vap->va_filerev   = vap->va_gen;  /* XXX file revision? same as gen? */
    826      1.1  reinoud 	vap->va_vaflags   = 0;  /* XXX chflags flags */
    827      1.1  reinoud 
    828      1.1  reinoud 	return 0;
    829      1.1  reinoud }
    830      1.1  reinoud 
    831      1.1  reinoud /* --------------------------------------------------------------------- */
    832      1.1  reinoud 
    833      1.1  reinoud #if 0
    834      1.1  reinoud static int
    835      1.1  reinoud nilfs_chown(struct vnode *vp, uid_t new_uid, gid_t new_gid,
    836      1.1  reinoud 	  kauth_cred_t cred)
    837      1.1  reinoud {
    838      1.1  reinoud 	return EINVAL;
    839      1.1  reinoud }
    840      1.1  reinoud 
    841      1.1  reinoud 
    842      1.1  reinoud static int
    843      1.1  reinoud nilfs_chmod(struct vnode *vp, mode_t mode, kauth_cred_t cred)
    844      1.1  reinoud {
    845      1.1  reinoud 
    846      1.1  reinoud 	return EINVAL;
    847      1.1  reinoud }
    848      1.1  reinoud 
    849      1.1  reinoud 
    850      1.1  reinoud /* exported */
    851      1.1  reinoud int
    852      1.1  reinoud nilfs_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred)
    853      1.1  reinoud {
    854      1.1  reinoud 	return EINVAL;
    855      1.1  reinoud }
    856      1.1  reinoud 
    857      1.1  reinoud 
    858      1.1  reinoud static int
    859      1.1  reinoud nilfs_chflags(struct vnode *vp, mode_t mode, kauth_cred_t cred)
    860      1.1  reinoud {
    861      1.1  reinoud 	return EINVAL;
    862      1.1  reinoud }
    863      1.1  reinoud 
    864      1.1  reinoud 
    865      1.1  reinoud static int
    866      1.1  reinoud nilfs_chtimes(struct vnode *vp,
    867      1.1  reinoud 	struct timespec *atime, struct timespec *mtime,
    868      1.1  reinoud 	struct timespec *birthtime, int setattrflags,
    869      1.1  reinoud 	kauth_cred_t cred)
    870      1.1  reinoud {
    871      1.1  reinoud 	return EINVAL;
    872      1.1  reinoud }
    873      1.1  reinoud #endif
    874      1.1  reinoud 
    875      1.1  reinoud 
    876      1.1  reinoud int
    877      1.1  reinoud nilfs_setattr(void *v)
    878      1.1  reinoud {
    879      1.1  reinoud 	struct vop_setattr_args /* {
    880      1.1  reinoud 		struct vnode *a_vp;
    881      1.1  reinoud 		struct vattr *a_vap;
    882      1.1  reinoud 		kauth_cred_t a_cred;
    883      1.1  reinoud 		struct lwp   *a_l;
    884      1.1  reinoud 	} */ *ap = v;
    885      1.1  reinoud 	struct vnode *vp = ap->a_vp;
    886      1.1  reinoud 
    887      1.1  reinoud 	vp = vp;
    888      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_setattr called\n"));
    889      1.1  reinoud 	return EINVAL;
    890      1.1  reinoud }
    891      1.1  reinoud 
    892      1.1  reinoud /* --------------------------------------------------------------------- */
    893      1.1  reinoud 
    894      1.1  reinoud /*
    895      1.1  reinoud  * Return POSIX pathconf information for NILFS file systems.
    896      1.1  reinoud  */
    897      1.1  reinoud int
    898      1.1  reinoud nilfs_pathconf(void *v)
    899      1.1  reinoud {
    900      1.1  reinoud 	struct vop_pathconf_args /* {
    901      1.1  reinoud 		struct vnode *a_vp;
    902      1.1  reinoud 		int a_name;
    903      1.1  reinoud 		register_t *a_retval;
    904      1.1  reinoud 	} */ *ap = v;
    905      1.1  reinoud 	uint32_t bits;
    906      1.1  reinoud 
    907      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_pathconf called\n"));
    908      1.1  reinoud 
    909      1.1  reinoud 	switch (ap->a_name) {
    910      1.1  reinoud 	case _PC_LINK_MAX:
    911      1.1  reinoud 		*ap->a_retval = (1<<16)-1;	/* 16 bits */
    912      1.1  reinoud 		return 0;
    913      1.1  reinoud 	case _PC_NAME_MAX:
    914      1.1  reinoud 		*ap->a_retval = NAME_MAX;
    915      1.1  reinoud 		return 0;
    916      1.1  reinoud 	case _PC_PATH_MAX:
    917      1.1  reinoud 		*ap->a_retval = PATH_MAX;
    918      1.1  reinoud 		return 0;
    919      1.1  reinoud 	case _PC_PIPE_BUF:
    920      1.1  reinoud 		*ap->a_retval = PIPE_BUF;
    921      1.1  reinoud 		return 0;
    922      1.1  reinoud 	case _PC_CHOWN_RESTRICTED:
    923      1.1  reinoud 		*ap->a_retval = 1;
    924      1.1  reinoud 		return 0;
    925      1.1  reinoud 	case _PC_NO_TRUNC:
    926      1.1  reinoud 		*ap->a_retval = 1;
    927      1.1  reinoud 		return 0;
    928      1.1  reinoud 	case _PC_SYNC_IO:
    929      1.1  reinoud 		*ap->a_retval = 0;     /* synchronised is off for performance */
    930      1.1  reinoud 		return 0;
    931      1.1  reinoud 	case _PC_FILESIZEBITS:
    932      1.1  reinoud 		/* 64 bit file offsets -> 2+floor(2log(2^64-1)) = 2 + 63 = 65 */
    933      1.1  reinoud 		bits = 64; /* XXX ought to deliver 65 */
    934      1.1  reinoud #if 0
    935      1.1  reinoud 		if (nilfs_node)
    936      1.1  reinoud 			bits = 64 * vp->v_mount->mnt_dev_bshift;
    937      1.1  reinoud #endif
    938      1.1  reinoud 		*ap->a_retval = bits;
    939      1.1  reinoud 		return 0;
    940      1.1  reinoud 	}
    941      1.1  reinoud 
    942      1.1  reinoud 	return EINVAL;
    943      1.1  reinoud }
    944      1.1  reinoud 
    945      1.1  reinoud 
    946      1.1  reinoud /* --------------------------------------------------------------------- */
    947      1.1  reinoud 
    948      1.1  reinoud int
    949      1.1  reinoud nilfs_open(void *v)
    950      1.1  reinoud {
    951      1.1  reinoud 	struct vop_open_args /* {
    952      1.1  reinoud 		struct vnode *a_vp;
    953      1.1  reinoud 		int a_mode;
    954      1.1  reinoud 		kauth_cred_t a_cred;
    955      1.1  reinoud 		struct proc *a_p;
    956      1.1  reinoud 	} */ *ap = v;
    957      1.1  reinoud 	int flags;
    958      1.1  reinoud 
    959      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_open called\n"));
    960      1.1  reinoud 
    961      1.1  reinoud 	/*
    962      1.1  reinoud 	 * Files marked append-only must be opened for appending.
    963      1.1  reinoud 	 */
    964      1.1  reinoud 	flags = 0;
    965      1.1  reinoud 	if ((flags & APPEND) && (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
    966      1.1  reinoud 		return (EPERM);
    967      1.1  reinoud 
    968      1.1  reinoud 	return 0;
    969      1.1  reinoud }
    970      1.1  reinoud 
    971      1.1  reinoud 
    972      1.1  reinoud /* --------------------------------------------------------------------- */
    973      1.1  reinoud 
    974      1.1  reinoud int
    975      1.1  reinoud nilfs_close(void *v)
    976      1.1  reinoud {
    977      1.1  reinoud 	struct vop_close_args /* {
    978      1.1  reinoud 		struct vnode *a_vp;
    979      1.1  reinoud 		int a_fflag;
    980      1.1  reinoud 		kauth_cred_t a_cred;
    981      1.1  reinoud 		struct proc *a_p;
    982      1.1  reinoud 	} */ *ap = v;
    983      1.1  reinoud 	struct vnode *vp = ap->a_vp;
    984      1.1  reinoud 	struct nilfs_node *nilfs_node = VTOI(vp);
    985      1.1  reinoud 
    986      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_close called\n"));
    987      1.1  reinoud 	nilfs_node = nilfs_node;	/* shut up gcc */
    988      1.1  reinoud 
    989  1.4.4.1    rmind 	mutex_enter(vp->v_interlock);
    990      1.1  reinoud 		if (vp->v_usecount > 1)
    991      1.1  reinoud 			nilfs_itimes(nilfs_node, NULL, NULL, NULL);
    992  1.4.4.1    rmind 	mutex_exit(vp->v_interlock);
    993      1.1  reinoud 
    994      1.1  reinoud 	return 0;
    995      1.1  reinoud }
    996      1.1  reinoud 
    997      1.1  reinoud 
    998      1.1  reinoud /* --------------------------------------------------------------------- */
    999      1.1  reinoud 
   1000      1.2     elad static int
   1001      1.2     elad nilfs_check_possible(struct vnode *vp, struct vattr *vap, mode_t mode)
   1002      1.1  reinoud {
   1003      1.1  reinoud 	int flags;
   1004      1.1  reinoud 
   1005      1.1  reinoud 	/* check if we are allowed to write */
   1006      1.2     elad 	switch (vap->va_type) {
   1007      1.1  reinoud 	case VDIR:
   1008      1.1  reinoud 	case VLNK:
   1009      1.1  reinoud 	case VREG:
   1010      1.1  reinoud 		/*
   1011      1.1  reinoud 		 * normal nodes: check if we're on a read-only mounted
   1012      1.1  reinoud 		 * filingsystem and bomb out if we're trying to write.
   1013      1.1  reinoud 		 */
   1014      1.1  reinoud 		if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY))
   1015      1.1  reinoud 			return EROFS;
   1016      1.1  reinoud 		break;
   1017      1.1  reinoud 	case VBLK:
   1018      1.1  reinoud 	case VCHR:
   1019      1.1  reinoud 	case VSOCK:
   1020      1.1  reinoud 	case VFIFO:
   1021      1.1  reinoud 		/*
   1022      1.1  reinoud 		 * special nodes: even on read-only mounted filingsystems
   1023      1.1  reinoud 		 * these are allowed to be written to if permissions allow.
   1024      1.1  reinoud 		 */
   1025      1.1  reinoud 		break;
   1026      1.1  reinoud 	default:
   1027      1.1  reinoud 		/* no idea what this is */
   1028      1.1  reinoud 		return EINVAL;
   1029      1.1  reinoud 	}
   1030      1.1  reinoud 
   1031      1.1  reinoud 	/* noone may write immutable files */
   1032      1.1  reinoud 	/* TODO: get chflags(2) flags */
   1033      1.1  reinoud 	flags = 0;
   1034      1.1  reinoud 	if ((mode & VWRITE) && (flags & IMMUTABLE))
   1035      1.1  reinoud 		return EPERM;
   1036      1.1  reinoud 
   1037      1.2     elad 	return 0;
   1038      1.2     elad }
   1039      1.2     elad 
   1040      1.2     elad static int
   1041      1.2     elad nilfs_check_permitted(struct vnode *vp, struct vattr *vap, mode_t mode,
   1042      1.2     elad     kauth_cred_t cred)
   1043      1.2     elad {
   1044      1.2     elad 
   1045      1.1  reinoud 	/* ask the generic genfs_can_access to advice on security */
   1046      1.1  reinoud 	return genfs_can_access(vp->v_type,
   1047      1.2     elad 			vap->va_mode, vap->va_uid, vap->va_gid,
   1048      1.1  reinoud 			mode, cred);
   1049      1.1  reinoud }
   1050      1.1  reinoud 
   1051      1.2     elad int
   1052      1.2     elad nilfs_access(void *v)
   1053      1.2     elad {
   1054      1.2     elad 	struct vop_access_args /* {
   1055      1.2     elad 		struct vnode *a_vp;
   1056      1.2     elad 		int a_mode;
   1057      1.2     elad 		kauth_cred_t a_cred;
   1058      1.2     elad 		struct proc *a_p;
   1059      1.2     elad 	} */ *ap = v;
   1060      1.2     elad 	struct vnode    *vp   = ap->a_vp;
   1061      1.2     elad 	mode_t	         mode = ap->a_mode;
   1062      1.2     elad 	kauth_cred_t     cred = ap->a_cred;
   1063      1.2     elad 	/* struct nilfs_node *nilfs_node = VTOI(vp); */
   1064      1.2     elad 	struct vattr vap;
   1065      1.2     elad 	int error;
   1066      1.2     elad 
   1067      1.2     elad 	DPRINTF(VFSCALL, ("nilfs_access called\n"));
   1068      1.2     elad 
   1069      1.2     elad 	error = VOP_GETATTR(vp, &vap, NULL);
   1070      1.2     elad 	if (error)
   1071      1.2     elad 		return error;
   1072      1.2     elad 
   1073      1.2     elad 	error = nilfs_check_possible(vp, &vap, mode);
   1074      1.2     elad 	if (error)
   1075      1.2     elad 		return error;
   1076      1.2     elad 
   1077      1.2     elad 	error = nilfs_check_permitted(vp, &vap, mode, cred);
   1078      1.2     elad 
   1079      1.2     elad 	return error;
   1080      1.2     elad }
   1081      1.2     elad 
   1082      1.1  reinoud /* --------------------------------------------------------------------- */
   1083      1.1  reinoud 
   1084      1.1  reinoud int
   1085      1.1  reinoud nilfs_create(void *v)
   1086      1.1  reinoud {
   1087      1.1  reinoud 	struct vop_create_args /* {
   1088      1.1  reinoud 		struct vnode *a_dvp;
   1089      1.1  reinoud 		struct vnode **a_vpp;
   1090      1.1  reinoud 		struct componentname *a_cnp;
   1091      1.1  reinoud 		struct vattr *a_vap;
   1092      1.1  reinoud 	} */ *ap = v;
   1093      1.1  reinoud 	struct vnode  *dvp = ap->a_dvp;
   1094      1.1  reinoud 	struct vnode **vpp = ap->a_vpp;
   1095      1.1  reinoud 	struct vattr  *vap  = ap->a_vap;
   1096      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1097      1.1  reinoud 	int error;
   1098      1.1  reinoud 
   1099      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_create called\n"));
   1100      1.1  reinoud 	error = nilfs_create_node(dvp, vpp, vap, cnp);
   1101      1.1  reinoud 
   1102      1.1  reinoud 	if (error || !(cnp->cn_flags & SAVESTART))
   1103      1.1  reinoud 		PNBUF_PUT(cnp->cn_pnbuf);
   1104      1.1  reinoud 	vput(dvp);
   1105      1.1  reinoud 	return error;
   1106      1.1  reinoud }
   1107      1.1  reinoud 
   1108      1.1  reinoud /* --------------------------------------------------------------------- */
   1109      1.1  reinoud 
   1110      1.1  reinoud int
   1111      1.1  reinoud nilfs_mknod(void *v)
   1112      1.1  reinoud {
   1113      1.1  reinoud 	struct vop_mknod_args /* {
   1114      1.1  reinoud 		struct vnode *a_dvp;
   1115      1.1  reinoud 		struct vnode **a_vpp;
   1116      1.1  reinoud 		struct componentname *a_cnp;
   1117      1.1  reinoud 		struct vattr *a_vap;
   1118      1.1  reinoud 	} */ *ap = v;
   1119      1.1  reinoud 	struct vnode  *dvp = ap->a_dvp;
   1120      1.1  reinoud 	struct vnode **vpp = ap->a_vpp;
   1121      1.1  reinoud 	struct vattr  *vap  = ap->a_vap;
   1122      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1123      1.1  reinoud 	int error;
   1124      1.1  reinoud 
   1125      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_mknod called\n"));
   1126      1.1  reinoud 	error = nilfs_create_node(dvp, vpp, vap, cnp);
   1127      1.1  reinoud 
   1128      1.1  reinoud 	if (error || !(cnp->cn_flags & SAVESTART))
   1129      1.1  reinoud 		PNBUF_PUT(cnp->cn_pnbuf);
   1130      1.1  reinoud 	vput(dvp);
   1131      1.1  reinoud 	return error;
   1132      1.1  reinoud }
   1133      1.1  reinoud 
   1134      1.1  reinoud /* --------------------------------------------------------------------- */
   1135      1.1  reinoud 
   1136      1.1  reinoud int
   1137      1.1  reinoud nilfs_mkdir(void *v)
   1138      1.1  reinoud {
   1139      1.1  reinoud 	struct vop_mkdir_args /* {
   1140      1.1  reinoud 		struct vnode *a_dvp;
   1141      1.1  reinoud 		struct vnode **a_vpp;
   1142      1.1  reinoud 		struct componentname *a_cnp;
   1143      1.1  reinoud 		struct vattr *a_vap;
   1144      1.1  reinoud 	} */ *ap = v;
   1145      1.1  reinoud 	struct vnode  *dvp = ap->a_dvp;
   1146      1.1  reinoud 	struct vnode **vpp = ap->a_vpp;
   1147      1.1  reinoud 	struct vattr  *vap  = ap->a_vap;
   1148      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1149      1.1  reinoud 	int error;
   1150      1.1  reinoud 
   1151      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_mkdir called\n"));
   1152      1.1  reinoud 	error = nilfs_create_node(dvp, vpp, vap, cnp);
   1153      1.1  reinoud 
   1154      1.1  reinoud 	if (error || !(cnp->cn_flags & SAVESTART))
   1155      1.1  reinoud 		PNBUF_PUT(cnp->cn_pnbuf);
   1156      1.1  reinoud 	vput(dvp);
   1157      1.1  reinoud 	return error;
   1158      1.1  reinoud }
   1159      1.1  reinoud 
   1160      1.1  reinoud /* --------------------------------------------------------------------- */
   1161      1.1  reinoud 
   1162      1.1  reinoud static int
   1163      1.1  reinoud nilfs_do_link(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
   1164      1.1  reinoud {
   1165      1.1  reinoud 	struct nilfs_node *nilfs_node, *dir_node;
   1166      1.1  reinoud 	struct vattr vap;
   1167      1.1  reinoud 	int error;
   1168      1.1  reinoud 
   1169      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_link called\n"));
   1170      1.1  reinoud 	error = 0;
   1171      1.1  reinoud 
   1172      1.1  reinoud 	/* some quick checks */
   1173      1.1  reinoud 	if (vp->v_type == VDIR)
   1174      1.1  reinoud 		return EPERM;		/* can't link a directory */
   1175      1.1  reinoud 	if (dvp->v_mount != vp->v_mount)
   1176      1.1  reinoud 		return EXDEV;		/* can't link across devices */
   1177      1.1  reinoud 	if (dvp == vp)
   1178      1.1  reinoud 		return EPERM;		/* can't be the same */
   1179      1.1  reinoud 
   1180      1.1  reinoud 	/* lock node */
   1181      1.1  reinoud 	error = vn_lock(vp, LK_EXCLUSIVE);
   1182      1.1  reinoud 	if (error)
   1183      1.1  reinoud 		return error;
   1184      1.1  reinoud 
   1185      1.1  reinoud 	/* get attributes */
   1186      1.1  reinoud 	dir_node = VTOI(dvp);
   1187      1.1  reinoud 	nilfs_node = VTOI(vp);
   1188      1.1  reinoud 
   1189      1.1  reinoud 	error = VOP_GETATTR(vp, &vap, FSCRED);
   1190  1.4.4.2    rmind 	if (error) {
   1191  1.4.4.2    rmind 		VOP_UNLOCK(vp);
   1192      1.1  reinoud 		return error;
   1193  1.4.4.2    rmind 	}
   1194      1.1  reinoud 
   1195      1.1  reinoud 	/* check link count overflow */
   1196  1.4.4.2    rmind 	if (vap.va_nlink >= (1<<16)-1) {	/* uint16_t */
   1197  1.4.4.2    rmind 		VOP_UNLOCK(vp);
   1198      1.1  reinoud 		return EMLINK;
   1199  1.4.4.2    rmind 	}
   1200      1.1  reinoud 
   1201  1.4.4.2    rmind 	error = nilfs_dir_attach(dir_node->ump, dir_node, nilfs_node,
   1202  1.4.4.2    rmind 	    &vap, cnp);
   1203  1.4.4.2    rmind 	if (error)
   1204  1.4.4.2    rmind 		VOP_UNLOCK(vp);
   1205  1.4.4.2    rmind 	return error;
   1206      1.1  reinoud }
   1207      1.1  reinoud 
   1208      1.1  reinoud int
   1209      1.1  reinoud nilfs_link(void *v)
   1210      1.1  reinoud {
   1211      1.1  reinoud 	struct vop_link_args /* {
   1212      1.1  reinoud 		struct vnode *a_dvp;
   1213      1.1  reinoud 		struct vnode *a_vp;
   1214      1.1  reinoud 		struct componentname *a_cnp;
   1215      1.1  reinoud 	} */ *ap = v;
   1216      1.1  reinoud 	struct vnode *dvp = ap->a_dvp;
   1217      1.1  reinoud 	struct vnode *vp  = ap->a_vp;
   1218      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1219      1.1  reinoud 	int error;
   1220      1.1  reinoud 
   1221      1.1  reinoud 	error = nilfs_do_link(dvp, vp, cnp);
   1222      1.1  reinoud 	if (error)
   1223      1.1  reinoud 		VOP_ABORTOP(dvp, cnp);
   1224      1.1  reinoud 
   1225      1.1  reinoud 	VN_KNOTE(vp, NOTE_LINK);
   1226      1.1  reinoud 	VN_KNOTE(dvp, NOTE_WRITE);
   1227      1.1  reinoud 	vput(dvp);
   1228      1.1  reinoud 
   1229      1.1  reinoud 	return error;
   1230      1.1  reinoud }
   1231      1.1  reinoud 
   1232      1.1  reinoud /* --------------------------------------------------------------------- */
   1233      1.1  reinoud 
   1234      1.1  reinoud static int
   1235      1.1  reinoud nilfs_do_symlink(struct nilfs_node *nilfs_node, char *target)
   1236      1.1  reinoud {
   1237      1.1  reinoud 	return EROFS;
   1238      1.1  reinoud }
   1239      1.1  reinoud 
   1240      1.1  reinoud 
   1241      1.1  reinoud int
   1242      1.1  reinoud nilfs_symlink(void *v)
   1243      1.1  reinoud {
   1244      1.1  reinoud 	struct vop_symlink_args /* {
   1245      1.1  reinoud 		struct vnode *a_dvp;
   1246      1.1  reinoud 		struct vnode **a_vpp;
   1247      1.1  reinoud 		struct componentname *a_cnp;
   1248      1.1  reinoud 		struct vattr *a_vap;
   1249      1.1  reinoud 		char *a_target;
   1250      1.1  reinoud 	} */ *ap = v;
   1251      1.1  reinoud 	struct vnode  *dvp = ap->a_dvp;
   1252      1.1  reinoud 	struct vnode **vpp = ap->a_vpp;
   1253      1.1  reinoud 	struct vattr  *vap  = ap->a_vap;
   1254      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1255      1.1  reinoud 	struct nilfs_node *dir_node;
   1256      1.1  reinoud 	struct nilfs_node *nilfs_node;
   1257      1.1  reinoud 	int error;
   1258      1.1  reinoud 
   1259      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_symlink called\n"));
   1260      1.1  reinoud 	DPRINTF(VFSCALL, ("\tlinking to `%s`\n",  ap->a_target));
   1261      1.1  reinoud 	error = nilfs_create_node(dvp, vpp, vap, cnp);
   1262      1.1  reinoud 	KASSERT(((error == 0) && (*vpp != NULL)) || ((error && (*vpp == NULL))));
   1263      1.1  reinoud 	if (!error) {
   1264      1.1  reinoud 		dir_node = VTOI(dvp);
   1265      1.1  reinoud 		nilfs_node = VTOI(*vpp);
   1266      1.1  reinoud 		KASSERT(nilfs_node);
   1267      1.1  reinoud 		error = nilfs_do_symlink(nilfs_node, ap->a_target);
   1268      1.1  reinoud 		if (error) {
   1269      1.1  reinoud 			/* remove node */
   1270      1.1  reinoud 			nilfs_shrink_node(nilfs_node, 0);
   1271      1.1  reinoud 			nilfs_dir_detach(nilfs_node->ump, dir_node, nilfs_node, cnp);
   1272      1.1  reinoud 		}
   1273      1.1  reinoud 	}
   1274      1.1  reinoud 	if (error || !(cnp->cn_flags & SAVESTART))
   1275      1.1  reinoud 		PNBUF_PUT(cnp->cn_pnbuf);
   1276      1.1  reinoud 	vput(dvp);
   1277      1.1  reinoud 	return error;
   1278      1.1  reinoud }
   1279      1.1  reinoud 
   1280      1.1  reinoud /* --------------------------------------------------------------------- */
   1281      1.1  reinoud 
   1282      1.1  reinoud int
   1283      1.1  reinoud nilfs_readlink(void *v)
   1284      1.1  reinoud {
   1285      1.1  reinoud 	struct vop_readlink_args /* {
   1286      1.1  reinoud 		struct vnode *a_vp;
   1287      1.1  reinoud 		struct uio *a_uio;
   1288      1.1  reinoud 		kauth_cred_t a_cred;
   1289      1.1  reinoud 	} */ *ap = v;
   1290      1.1  reinoud #if 0
   1291      1.1  reinoud 	struct vnode *vp = ap->a_vp;
   1292      1.1  reinoud 	struct uio *uio = ap->a_uio;
   1293      1.1  reinoud 	kauth_cred_t cred = ap->a_cred;
   1294      1.1  reinoud 	struct nilfs_node *nilfs_node;
   1295      1.1  reinoud 	struct pathcomp pathcomp;
   1296      1.1  reinoud 	struct vattr vattr;
   1297      1.1  reinoud 	uint8_t *pathbuf, *targetbuf, *tmpname;
   1298      1.1  reinoud 	uint8_t *pathpos, *targetpos;
   1299      1.1  reinoud 	char *mntonname;
   1300      1.1  reinoud 	int pathlen, targetlen, namelen, mntonnamelen, len, l_ci;
   1301      1.1  reinoud 	int first, error;
   1302      1.1  reinoud #endif
   1303      1.1  reinoud 	ap = ap;
   1304      1.1  reinoud 
   1305      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_readlink called\n"));
   1306      1.1  reinoud 
   1307      1.1  reinoud 	return EROFS;
   1308      1.1  reinoud }
   1309      1.1  reinoud 
   1310      1.1  reinoud /* --------------------------------------------------------------------- */
   1311      1.1  reinoud 
   1312      1.1  reinoud /* note: i tried to follow the logics of the tmpfs rename code */
   1313      1.1  reinoud int
   1314      1.1  reinoud nilfs_rename(void *v)
   1315      1.1  reinoud {
   1316      1.1  reinoud 	struct vop_rename_args /* {
   1317      1.1  reinoud 		struct vnode *a_fdvp;
   1318      1.1  reinoud 		struct vnode *a_fvp;
   1319      1.1  reinoud 		struct componentname *a_fcnp;
   1320      1.1  reinoud 		struct vnode *a_tdvp;
   1321      1.1  reinoud 		struct vnode *a_tvp;
   1322      1.1  reinoud 		struct componentname *a_tcnp;
   1323      1.1  reinoud 	} */ *ap = v;
   1324      1.1  reinoud 	struct vnode *tvp = ap->a_tvp;
   1325      1.1  reinoud 	struct vnode *tdvp = ap->a_tdvp;
   1326      1.1  reinoud 	struct vnode *fvp = ap->a_fvp;
   1327      1.1  reinoud 	struct vnode *fdvp = ap->a_fdvp;
   1328      1.1  reinoud 	struct componentname *tcnp = ap->a_tcnp;
   1329      1.1  reinoud 	struct componentname *fcnp = ap->a_fcnp;
   1330      1.1  reinoud 	struct nilfs_node *fnode, *fdnode, *tnode, *tdnode;
   1331      1.1  reinoud 	struct vattr fvap, tvap;
   1332      1.1  reinoud 	int error;
   1333      1.1  reinoud 
   1334      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_rename called\n"));
   1335      1.1  reinoud 
   1336      1.1  reinoud 	/* disallow cross-device renames */
   1337      1.1  reinoud 	if (fvp->v_mount != tdvp->v_mount ||
   1338      1.1  reinoud 	    (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
   1339      1.1  reinoud 		error = EXDEV;
   1340      1.1  reinoud 		goto out_unlocked;
   1341      1.1  reinoud 	}
   1342      1.1  reinoud 
   1343      1.1  reinoud 	fnode  = VTOI(fvp);
   1344      1.1  reinoud 	fdnode = VTOI(fdvp);
   1345      1.1  reinoud 	tnode  = (tvp == NULL) ? NULL : VTOI(tvp);
   1346      1.1  reinoud 	tdnode = VTOI(tdvp);
   1347      1.1  reinoud 
   1348      1.1  reinoud 	/* lock our source dir */
   1349      1.1  reinoud 	if (fdnode != tdnode) {
   1350      1.1  reinoud 		error = vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY);
   1351      1.1  reinoud 		if (error != 0)
   1352      1.1  reinoud 			goto out_unlocked;
   1353      1.1  reinoud 	}
   1354      1.1  reinoud 
   1355      1.1  reinoud 	/* get info about the node to be moved */
   1356      1.1  reinoud 	error = VOP_GETATTR(fvp, &fvap, FSCRED);
   1357      1.1  reinoud 	KASSERT(error == 0);
   1358      1.1  reinoud 
   1359      1.1  reinoud 	/* check when to delete the old already existing entry */
   1360      1.1  reinoud 	if (tvp) {
   1361      1.1  reinoud 		/* get info about the node to be moved to */
   1362      1.1  reinoud 		error = VOP_GETATTR(fvp, &tvap, FSCRED);
   1363      1.1  reinoud 		KASSERT(error == 0);
   1364      1.1  reinoud 
   1365      1.1  reinoud 		/* if both dirs, make sure the destination is empty */
   1366      1.1  reinoud 		if (fvp->v_type == VDIR && tvp->v_type == VDIR) {
   1367      1.1  reinoud 			if (tvap.va_nlink > 2) {
   1368      1.1  reinoud 				error = ENOTEMPTY;
   1369      1.1  reinoud 				goto out;
   1370      1.1  reinoud 			}
   1371      1.1  reinoud 		}
   1372      1.1  reinoud 		/* if moving dir, make sure destination is dir too */
   1373      1.1  reinoud 		if (fvp->v_type == VDIR && tvp->v_type != VDIR) {
   1374      1.1  reinoud 			error = ENOTDIR;
   1375      1.1  reinoud 			goto out;
   1376      1.1  reinoud 		}
   1377      1.1  reinoud 		/* if we're moving a non-directory, make sure dest is no dir */
   1378      1.1  reinoud 		if (fvp->v_type != VDIR && tvp->v_type == VDIR) {
   1379      1.1  reinoud 			error = EISDIR;
   1380      1.1  reinoud 			goto out;
   1381      1.1  reinoud 		}
   1382      1.1  reinoud 	}
   1383      1.1  reinoud 
   1384      1.1  reinoud 	/* dont allow renaming directories acros directory for now */
   1385      1.1  reinoud 	if (fdnode != tdnode) {
   1386      1.1  reinoud 		if (fvp->v_type == VDIR) {
   1387      1.1  reinoud 			error = EINVAL;
   1388      1.1  reinoud 			goto out;
   1389      1.1  reinoud 		}
   1390      1.1  reinoud 	}
   1391      1.1  reinoud 
   1392      1.1  reinoud 	/* remove existing entry if present */
   1393      1.1  reinoud 	if (tvp)
   1394      1.1  reinoud 		nilfs_dir_detach(tdnode->ump, tdnode, tnode, tcnp);
   1395      1.1  reinoud 
   1396      1.1  reinoud 	/* create new directory entry for the node */
   1397      1.1  reinoud 	error = nilfs_dir_attach(tdnode->ump, tdnode, fnode, &fvap, tcnp);
   1398      1.1  reinoud 	if (error)
   1399      1.1  reinoud 		goto out;
   1400      1.1  reinoud 
   1401      1.1  reinoud 	/* unlink old directory entry for the node, if failing, unattach new */
   1402      1.1  reinoud 	error = nilfs_dir_detach(tdnode->ump, fdnode, fnode, fcnp);
   1403      1.1  reinoud 	if (error)
   1404      1.1  reinoud 		nilfs_dir_detach(tdnode->ump, tdnode, fnode, tcnp);
   1405      1.1  reinoud 
   1406      1.1  reinoud out:
   1407      1.1  reinoud         if (fdnode != tdnode)
   1408  1.4.4.2    rmind                 VOP_UNLOCK(fdvp);
   1409      1.1  reinoud 
   1410      1.1  reinoud out_unlocked:
   1411      1.1  reinoud 	VOP_ABORTOP(tdvp, tcnp);
   1412      1.1  reinoud 	if (tdvp == tvp)
   1413      1.1  reinoud 		vrele(tdvp);
   1414      1.1  reinoud 	else
   1415      1.1  reinoud 		vput(tdvp);
   1416      1.1  reinoud 	if (tvp)
   1417      1.1  reinoud 		vput(tvp);
   1418      1.1  reinoud 	VOP_ABORTOP(fdvp, fcnp);
   1419      1.1  reinoud 
   1420      1.1  reinoud 	/* release source nodes. */
   1421      1.1  reinoud 	vrele(fdvp);
   1422      1.1  reinoud 	vrele(fvp);
   1423      1.1  reinoud 
   1424      1.1  reinoud 	return error;
   1425      1.1  reinoud }
   1426      1.1  reinoud 
   1427      1.1  reinoud /* --------------------------------------------------------------------- */
   1428      1.1  reinoud 
   1429      1.1  reinoud int
   1430      1.1  reinoud nilfs_remove(void *v)
   1431      1.1  reinoud {
   1432      1.1  reinoud 	struct vop_remove_args /* {
   1433      1.1  reinoud 		struct vnode *a_dvp;
   1434      1.1  reinoud 		struct vnode *a_vp;
   1435      1.1  reinoud 		struct componentname *a_cnp;
   1436      1.1  reinoud 	} */ *ap = v;
   1437      1.1  reinoud 	struct vnode *dvp = ap->a_dvp;
   1438      1.1  reinoud 	struct vnode *vp  = ap->a_vp;
   1439      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1440      1.3  mbalmer 	struct nilfs_node *dir_node = VTOI(dvp);
   1441      1.1  reinoud 	struct nilfs_node *nilfs_node = VTOI(vp);
   1442      1.1  reinoud 	struct nilfs_mount *ump = dir_node->ump;
   1443      1.1  reinoud 	int error;
   1444      1.1  reinoud 
   1445      1.1  reinoud 	DPRINTF(VFSCALL, ("nilfs_remove called\n"));
   1446      1.1  reinoud 	if (vp->v_type != VDIR) {
   1447      1.1  reinoud 		error = nilfs_dir_detach(ump, dir_node, nilfs_node, cnp);
   1448      1.1  reinoud 		DPRINTFIF(NODE, error, ("\tgot error removing file\n"));
   1449      1.1  reinoud 	} else {
   1450      1.1  reinoud 		DPRINTF(NODE, ("\tis a directory: perm. denied\n"));
   1451      1.1  reinoud 		error = EPERM;
   1452      1.1  reinoud 	}
   1453      1.1  reinoud 
   1454      1.1  reinoud 	if (error == 0) {
   1455      1.1  reinoud 		VN_KNOTE(vp, NOTE_DELETE);
   1456      1.1  reinoud 		VN_KNOTE(dvp, NOTE_WRITE);
   1457      1.1  reinoud 	}
   1458      1.1  reinoud 
   1459      1.1  reinoud 	if (dvp == vp)
   1460      1.1  reinoud 		vrele(vp);
   1461      1.1  reinoud 	else
   1462      1.1  reinoud 		vput(vp);
   1463      1.1  reinoud 	vput(dvp);
   1464      1.1  reinoud 
   1465      1.1  reinoud 	return error;
   1466      1.1  reinoud }
   1467      1.1  reinoud 
   1468      1.1  reinoud /* --------------------------------------------------------------------- */
   1469      1.1  reinoud 
   1470      1.1  reinoud int
   1471      1.1  reinoud nilfs_rmdir(void *v)
   1472      1.1  reinoud {
   1473      1.1  reinoud 	struct vop_rmdir_args /* {
   1474      1.1  reinoud 		struct vnode *a_dvp;
   1475      1.1  reinoud 		struct vnode *a_vp;
   1476      1.1  reinoud 		struct componentname *a_cnp;
   1477      1.1  reinoud 	} */ *ap = v;
   1478      1.1  reinoud 	struct vnode *vp = ap->a_vp;
   1479      1.1  reinoud 	struct vnode *dvp = ap->a_dvp;
   1480      1.1  reinoud 	struct componentname *cnp = ap->a_cnp;
   1481      1.3  mbalmer 	struct nilfs_node *dir_node = VTOI(dvp);
   1482      1.1  reinoud 	struct nilfs_node *nilfs_node = VTOI(vp);
   1483      1.1  reinoud 	struct nilfs_mount *ump = dir_node->ump;
   1484      1.1  reinoud 	int refcnt, error;
   1485      1.1  reinoud 
   1486      1.1  reinoud 	DPRINTF(NOTIMPL, ("nilfs_rmdir called\n"));
   1487      1.1  reinoud 
   1488      1.1  reinoud 	/* don't allow '.' to be deleted */
   1489      1.1  reinoud 	if (dir_node == nilfs_node) {
   1490      1.1  reinoud 		vrele(dvp);
   1491      1.1  reinoud 		vput(vp);
   1492      1.1  reinoud 		return EINVAL;
   1493      1.1  reinoud 	}
   1494      1.1  reinoud 
   1495      1.1  reinoud 	/* check to see if the directory is empty */
   1496      1.1  reinoud 	error = 0;
   1497      1.1  reinoud 	refcnt = 2; /* XXX */
   1498      1.1  reinoud 	if (refcnt > 1) {
   1499      1.1  reinoud 		/* NOT empty */
   1500      1.1  reinoud 		vput(dvp);
   1501      1.1  reinoud 		vput(vp);
   1502      1.1  reinoud 		return ENOTEMPTY;
   1503      1.1  reinoud 	}
   1504      1.1  reinoud 
   1505      1.1  reinoud 	/* detach the node from the directory */
   1506      1.1  reinoud 	error = nilfs_dir_detach(ump, dir_node, nilfs_node, cnp);
   1507      1.1  reinoud 	if (error == 0) {
   1508      1.1  reinoud 		cache_purge(vp);
   1509      1.1  reinoud //		cache_purge(dvp);	/* XXX from msdosfs, why? */
   1510      1.1  reinoud 		VN_KNOTE(vp, NOTE_DELETE);
   1511      1.1  reinoud 	}
   1512      1.1  reinoud 	DPRINTFIF(NODE, error, ("\tgot error removing file\n"));
   1513      1.1  reinoud 
   1514      1.1  reinoud 	/* unput the nodes and exit */
   1515      1.1  reinoud 	vput(dvp);
   1516      1.1  reinoud 	vput(vp);
   1517      1.1  reinoud 
   1518      1.1  reinoud 	return error;
   1519      1.1  reinoud }
   1520      1.1  reinoud 
   1521      1.1  reinoud /* --------------------------------------------------------------------- */
   1522      1.1  reinoud 
   1523      1.1  reinoud int
   1524      1.1  reinoud nilfs_fsync(void *v)
   1525      1.1  reinoud {
   1526      1.1  reinoud 	struct vop_fsync_args /* {
   1527      1.1  reinoud 		struct vnode *a_vp;
   1528      1.1  reinoud 		kauth_cred_t a_cred;
   1529      1.1  reinoud 		int a_flags;
   1530      1.1  reinoud 		off_t offlo;
   1531      1.1  reinoud 		off_t offhi;
   1532      1.1  reinoud 		struct proc *a_p;
   1533      1.1  reinoud 	} */ *ap = v;
   1534      1.1  reinoud 	struct vnode *vp = ap->a_vp;
   1535      1.1  reinoud //	struct nilfs_node *nilfs_node = VTOI(vp);
   1536      1.1  reinoud //	int error, flags, wait;
   1537      1.1  reinoud 
   1538      1.1  reinoud 	DPRINTF(STRATEGY, ("nilfs_fsync called : %s, %s\n",
   1539      1.1  reinoud 		(ap->a_flags & FSYNC_WAIT)     ? "wait":"no wait",
   1540      1.1  reinoud 		(ap->a_flags & FSYNC_DATAONLY) ? "data_only":"complete"));
   1541      1.1  reinoud 
   1542      1.1  reinoud 	vp = vp;
   1543      1.1  reinoud 	return 0;
   1544      1.1  reinoud }
   1545      1.1  reinoud 
   1546      1.1  reinoud /* --------------------------------------------------------------------- */
   1547      1.1  reinoud 
   1548      1.1  reinoud int
   1549      1.1  reinoud nilfs_advlock(void *v)
   1550      1.1  reinoud {
   1551      1.1  reinoud 	struct vop_advlock_args /* {
   1552      1.1  reinoud 		struct vnode *a_vp;
   1553      1.1  reinoud 		void *a_id;
   1554      1.1  reinoud 		int a_op;
   1555      1.1  reinoud 		struct flock *a_fl;
   1556      1.1  reinoud 		int a_flags;
   1557      1.1  reinoud 	} */ *ap = v;
   1558      1.1  reinoud 	struct vnode *vp = ap->a_vp;
   1559      1.1  reinoud 	struct nilfs_node *nilfs_node = VTOI(vp);
   1560      1.1  reinoud 	uint64_t file_size;
   1561      1.1  reinoud 
   1562      1.1  reinoud 	DPRINTF(LOCKING, ("nilfs_advlock called\n"));
   1563      1.1  reinoud 
   1564      1.1  reinoud 	assert(nilfs_node);
   1565      1.1  reinoud 	file_size = nilfs_rw64(nilfs_node->inode.i_size);
   1566      1.1  reinoud 
   1567      1.1  reinoud 	return lf_advlock(ap, &nilfs_node->lockf, file_size);
   1568      1.1  reinoud }
   1569      1.1  reinoud 
   1570      1.1  reinoud /* --------------------------------------------------------------------- */
   1571      1.1  reinoud 
   1572      1.1  reinoud 
   1573      1.1  reinoud /* Global vfs vnode data structures for nilfss */
   1574      1.1  reinoud int (**nilfs_vnodeop_p) __P((void *));
   1575      1.1  reinoud 
   1576      1.1  reinoud const struct vnodeopv_entry_desc nilfs_vnodeop_entries[] = {
   1577      1.1  reinoud 	{ &vop_default_desc, vn_default_error },
   1578      1.1  reinoud 	{ &vop_lookup_desc, nilfs_lookup },	/* lookup */
   1579      1.1  reinoud 	{ &vop_create_desc, nilfs_create },	/* create */
   1580      1.1  reinoud 	{ &vop_mknod_desc, nilfs_mknod },	/* mknod */	/* TODO */
   1581      1.1  reinoud 	{ &vop_open_desc, nilfs_open },		/* open */
   1582      1.1  reinoud 	{ &vop_close_desc, nilfs_close },	/* close */
   1583      1.1  reinoud 	{ &vop_access_desc, nilfs_access },	/* access */
   1584      1.1  reinoud 	{ &vop_getattr_desc, nilfs_getattr },	/* getattr */
   1585      1.1  reinoud 	{ &vop_setattr_desc, nilfs_setattr },	/* setattr */	/* TODO chflags */
   1586      1.1  reinoud 	{ &vop_read_desc, nilfs_read },		/* read */
   1587      1.1  reinoud 	{ &vop_write_desc, nilfs_write },	/* write */	/* WRITE */
   1588      1.1  reinoud 	{ &vop_fcntl_desc, genfs_fcntl },	/* fcntl */	/* TODO? */
   1589      1.1  reinoud 	{ &vop_ioctl_desc, genfs_enoioctl },	/* ioctl */	/* TODO? */
   1590      1.1  reinoud 	{ &vop_poll_desc, genfs_poll },		/* poll */	/* TODO/OK? */
   1591      1.1  reinoud 	{ &vop_kqfilter_desc, genfs_kqfilter },	/* kqfilter */	/* ? */
   1592      1.1  reinoud 	{ &vop_revoke_desc, genfs_revoke },	/* revoke */	/* TODO? */
   1593      1.1  reinoud 	{ &vop_mmap_desc, genfs_mmap },		/* mmap */	/* OK? */
   1594      1.1  reinoud 	{ &vop_fsync_desc, nilfs_fsync },	/* fsync */
   1595      1.1  reinoud 	{ &vop_seek_desc, genfs_seek },		/* seek */
   1596      1.1  reinoud 	{ &vop_remove_desc, nilfs_remove },	/* remove */
   1597      1.1  reinoud 	{ &vop_link_desc, nilfs_link },		/* link */	/* TODO */
   1598      1.1  reinoud 	{ &vop_rename_desc, nilfs_rename },	/* rename */ 	/* TODO */
   1599      1.1  reinoud 	{ &vop_mkdir_desc, nilfs_mkdir },	/* mkdir */
   1600      1.1  reinoud 	{ &vop_rmdir_desc, nilfs_rmdir },	/* rmdir */
   1601      1.1  reinoud 	{ &vop_symlink_desc, nilfs_symlink },	/* symlink */	/* TODO */
   1602      1.1  reinoud 	{ &vop_readdir_desc, nilfs_readdir },	/* readdir */
   1603      1.1  reinoud 	{ &vop_readlink_desc, nilfs_readlink },	/* readlink */	/* TEST ME */
   1604      1.1  reinoud 	{ &vop_abortop_desc, genfs_abortop },	/* abortop */	/* TODO/OK? */
   1605      1.1  reinoud 	{ &vop_inactive_desc, nilfs_inactive },	/* inactive */
   1606      1.1  reinoud 	{ &vop_reclaim_desc, nilfs_reclaim },	/* reclaim */
   1607      1.1  reinoud 	{ &vop_lock_desc, genfs_lock },		/* lock */
   1608      1.1  reinoud 	{ &vop_unlock_desc, genfs_unlock },	/* unlock */
   1609      1.1  reinoud 	{ &vop_bmap_desc, nilfs_trivial_bmap },	/* bmap */	/* 1:1 bmap */
   1610      1.1  reinoud 	{ &vop_strategy_desc, nilfs_vfsstrategy },/* strategy */
   1611      1.1  reinoud /*	{ &vop_print_desc, nilfs_print },	*/	/* print */
   1612      1.1  reinoud 	{ &vop_islocked_desc, genfs_islocked },	/* islocked */
   1613      1.1  reinoud 	{ &vop_pathconf_desc, nilfs_pathconf },	/* pathconf */
   1614      1.1  reinoud 	{ &vop_advlock_desc, nilfs_advlock },	/* advlock */	/* TEST ME */
   1615      1.1  reinoud 	{ &vop_bwrite_desc, vn_bwrite },	/* bwrite */	/* ->strategy */
   1616      1.1  reinoud 	{ &vop_getpages_desc, genfs_getpages },	/* getpages */
   1617      1.1  reinoud 	{ &vop_putpages_desc, genfs_putpages },	/* putpages */
   1618      1.1  reinoud 	{ NULL, NULL }
   1619      1.1  reinoud };
   1620      1.1  reinoud 
   1621      1.1  reinoud 
   1622      1.1  reinoud const struct vnodeopv_desc nilfs_vnodeop_opv_desc = {
   1623      1.1  reinoud 	&nilfs_vnodeop_p, nilfs_vnodeop_entries
   1624      1.1  reinoud };
   1625      1.1  reinoud 
   1626