Home | History | Annotate | Line # | Download | only in adosfs
advnops.c revision 1.24.10.2
      1  1.24.10.2  ad /*	$NetBSD: advnops.c,v 1.24.10.2 2007/07/29 12:15:46 ad Exp $	*/
      2  1.24.10.2  ad 
      3  1.24.10.2  ad /*
      4  1.24.10.2  ad  * Copyright (c) 1994 Christian E. Hopps
      5  1.24.10.2  ad  * Copyright (c) 1996 Matthias Scheler
      6  1.24.10.2  ad  * All rights reserved.
      7  1.24.10.2  ad  *
      8  1.24.10.2  ad  * Redistribution and use in source and binary forms, with or without
      9  1.24.10.2  ad  * modification, are permitted provided that the following conditions
     10  1.24.10.2  ad  * are met:
     11  1.24.10.2  ad  * 1. Redistributions of source code must retain the above copyright
     12  1.24.10.2  ad  *    notice, this list of conditions and the following disclaimer.
     13  1.24.10.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.24.10.2  ad  *    notice, this list of conditions and the following disclaimer in the
     15  1.24.10.2  ad  *    documentation and/or other materials provided with the distribution.
     16  1.24.10.2  ad  * 3. All advertising materials mentioning features or use of this software
     17  1.24.10.2  ad  *    must display the following acknowledgement:
     18  1.24.10.2  ad  *      This product includes software developed by Christian E. Hopps.
     19  1.24.10.2  ad  * 4. The name of the author may not be used to endorse or promote products
     20  1.24.10.2  ad  *    derived from this software without specific prior written permission
     21  1.24.10.2  ad  *
     22  1.24.10.2  ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.24.10.2  ad  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.24.10.2  ad  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.24.10.2  ad  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.24.10.2  ad  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.24.10.2  ad  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.24.10.2  ad  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.24.10.2  ad  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.24.10.2  ad  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.24.10.2  ad  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.24.10.2  ad  */
     33  1.24.10.2  ad 
     34  1.24.10.2  ad #include <sys/cdefs.h>
     35  1.24.10.2  ad __KERNEL_RCSID(0, "$NetBSD: advnops.c,v 1.24.10.2 2007/07/29 12:15:46 ad Exp $");
     36  1.24.10.2  ad 
     37  1.24.10.2  ad #if defined(_KERNEL_OPT)
     38  1.24.10.2  ad #include "opt_quota.h"
     39  1.24.10.2  ad #endif
     40  1.24.10.2  ad 
     41  1.24.10.2  ad #include <sys/param.h>
     42  1.24.10.2  ad #include <sys/systm.h>
     43  1.24.10.2  ad #include <sys/vnode.h>
     44  1.24.10.2  ad #include <sys/mount.h>
     45  1.24.10.2  ad #include <sys/time.h>
     46  1.24.10.2  ad #include <sys/queue.h>
     47  1.24.10.2  ad #include <sys/namei.h>
     48  1.24.10.2  ad #include <sys/buf.h>
     49  1.24.10.2  ad #include <sys/dirent.h>
     50  1.24.10.2  ad #include <sys/inttypes.h>
     51  1.24.10.2  ad #include <sys/malloc.h>
     52  1.24.10.2  ad #include <sys/pool.h>
     53  1.24.10.2  ad #include <sys/stat.h>
     54  1.24.10.2  ad #include <sys/unistd.h>
     55  1.24.10.2  ad #include <sys/proc.h>
     56  1.24.10.2  ad #include <sys/kauth.h>
     57  1.24.10.2  ad 
     58  1.24.10.2  ad #include <miscfs/genfs/genfs.h>
     59  1.24.10.2  ad #include <miscfs/specfs/specdev.h>
     60  1.24.10.2  ad #include <fs/adosfs/adosfs.h>
     61  1.24.10.2  ad 
     62  1.24.10.2  ad extern struct vnodeops adosfs_vnodeops;
     63  1.24.10.2  ad 
     64  1.24.10.2  ad #define	adosfs_open	genfs_nullop
     65  1.24.10.2  ad int	adosfs_getattr	__P((void *));
     66  1.24.10.2  ad int	adosfs_read	__P((void *));
     67  1.24.10.2  ad int	adosfs_write	__P((void *));
     68  1.24.10.2  ad #define	adosfs_fcntl	genfs_fcntl
     69  1.24.10.2  ad #define	adosfs_ioctl	genfs_enoioctl
     70  1.24.10.2  ad #define	adosfs_poll	genfs_poll
     71  1.24.10.2  ad int	adosfs_strategy	__P((void *));
     72  1.24.10.2  ad int	adosfs_link	__P((void *));
     73  1.24.10.2  ad int	adosfs_symlink	__P((void *));
     74  1.24.10.2  ad #define	adosfs_abortop	genfs_abortop
     75  1.24.10.2  ad int	adosfs_bmap	__P((void *));
     76  1.24.10.2  ad int	adosfs_print	__P((void *));
     77  1.24.10.2  ad int	adosfs_readdir	__P((void *));
     78  1.24.10.2  ad int	adosfs_access	__P((void *));
     79  1.24.10.2  ad int	adosfs_readlink	__P((void *));
     80  1.24.10.2  ad int	adosfs_inactive	__P((void *));
     81  1.24.10.2  ad int	adosfs_reclaim	__P((void *));
     82  1.24.10.2  ad int	adosfs_pathconf	__P((void *));
     83  1.24.10.2  ad 
     84  1.24.10.2  ad #define adosfs_close 	genfs_nullop
     85  1.24.10.2  ad #define adosfs_fsync 	genfs_nullop
     86  1.24.10.2  ad #define	adosfs_lease_check	genfs_lease_check
     87  1.24.10.2  ad #define adosfs_seek 	genfs_seek
     88  1.24.10.2  ad 
     89  1.24.10.2  ad #define adosfs_advlock 	genfs_einval
     90  1.24.10.2  ad #define adosfs_bwrite 	genfs_eopnotsupp
     91  1.24.10.2  ad #define adosfs_create 	genfs_eopnotsupp
     92  1.24.10.2  ad #define adosfs_mkdir 	genfs_eopnotsupp
     93  1.24.10.2  ad #define adosfs_mknod 	genfs_eopnotsupp
     94  1.24.10.2  ad #define adosfs_revoke	genfs_revoke
     95  1.24.10.2  ad #define adosfs_mmap 	genfs_mmap
     96  1.24.10.2  ad #define adosfs_remove 	genfs_eopnotsupp
     97  1.24.10.2  ad #define adosfs_rename 	genfs_eopnotsupp
     98  1.24.10.2  ad #define adosfs_rmdir 	genfs_eopnotsupp
     99  1.24.10.2  ad #define adosfs_setattr 	genfs_eopnotsupp
    100  1.24.10.2  ad 
    101  1.24.10.2  ad const struct vnodeopv_entry_desc adosfs_vnodeop_entries[] = {
    102  1.24.10.2  ad 	{ &vop_default_desc, vn_default_error },
    103  1.24.10.2  ad 	{ &vop_lookup_desc, adosfs_lookup },		/* lookup */
    104  1.24.10.2  ad 	{ &vop_create_desc, adosfs_create },		/* create */
    105  1.24.10.2  ad 	{ &vop_mknod_desc, adosfs_mknod },		/* mknod */
    106  1.24.10.2  ad 	{ &vop_open_desc, adosfs_open },		/* open */
    107  1.24.10.2  ad 	{ &vop_close_desc, adosfs_close },		/* close */
    108  1.24.10.2  ad 	{ &vop_access_desc, adosfs_access },		/* access */
    109  1.24.10.2  ad 	{ &vop_getattr_desc, adosfs_getattr },		/* getattr */
    110  1.24.10.2  ad 	{ &vop_setattr_desc, adosfs_setattr },		/* setattr */
    111  1.24.10.2  ad 	{ &vop_read_desc, adosfs_read },		/* read */
    112  1.24.10.2  ad 	{ &vop_write_desc, adosfs_write },		/* write */
    113  1.24.10.2  ad 	{ &vop_lease_desc, adosfs_lease_check },	/* lease */
    114  1.24.10.2  ad 	{ &vop_fcntl_desc, adosfs_fcntl },		/* fcntl */
    115  1.24.10.2  ad 	{ &vop_ioctl_desc, adosfs_ioctl },		/* ioctl */
    116  1.24.10.2  ad 	{ &vop_poll_desc, adosfs_poll },		/* poll */
    117  1.24.10.2  ad 	{ &vop_kqfilter_desc, genfs_kqfilter },		/* kqfilter */
    118  1.24.10.2  ad 	{ &vop_revoke_desc, adosfs_revoke },		/* revoke */
    119  1.24.10.2  ad 	{ &vop_mmap_desc, adosfs_mmap },		/* mmap */
    120  1.24.10.2  ad 	{ &vop_fsync_desc, adosfs_fsync },		/* fsync */
    121  1.24.10.2  ad 	{ &vop_seek_desc, adosfs_seek },		/* seek */
    122  1.24.10.2  ad 	{ &vop_remove_desc, adosfs_remove },		/* remove */
    123  1.24.10.2  ad 	{ &vop_link_desc, adosfs_link },		/* link */
    124  1.24.10.2  ad 	{ &vop_rename_desc, adosfs_rename },		/* rename */
    125  1.24.10.2  ad 	{ &vop_mkdir_desc, adosfs_mkdir },		/* mkdir */
    126  1.24.10.2  ad 	{ &vop_rmdir_desc, adosfs_rmdir },		/* rmdir */
    127  1.24.10.2  ad 	{ &vop_symlink_desc, adosfs_symlink },		/* symlink */
    128  1.24.10.2  ad 	{ &vop_readdir_desc, adosfs_readdir },		/* readdir */
    129  1.24.10.2  ad 	{ &vop_readlink_desc, adosfs_readlink },	/* readlink */
    130  1.24.10.2  ad 	{ &vop_abortop_desc, adosfs_abortop },		/* abortop */
    131  1.24.10.2  ad 	{ &vop_inactive_desc, adosfs_inactive },	/* inactive */
    132  1.24.10.2  ad 	{ &vop_reclaim_desc, adosfs_reclaim },		/* reclaim */
    133  1.24.10.2  ad 	{ &vop_lock_desc, genfs_lock },			/* lock */
    134  1.24.10.2  ad 	{ &vop_unlock_desc, genfs_unlock },		/* unlock */
    135  1.24.10.2  ad 	{ &vop_bmap_desc, adosfs_bmap },		/* bmap */
    136  1.24.10.2  ad 	{ &vop_strategy_desc, adosfs_strategy },	/* strategy */
    137  1.24.10.2  ad 	{ &vop_print_desc, adosfs_print },		/* print */
    138  1.24.10.2  ad 	{ &vop_islocked_desc, genfs_islocked },		/* islocked */
    139  1.24.10.2  ad 	{ &vop_pathconf_desc, adosfs_pathconf },	/* pathconf */
    140  1.24.10.2  ad 	{ &vop_advlock_desc, adosfs_advlock },		/* advlock */
    141  1.24.10.2  ad 	{ &vop_bwrite_desc, adosfs_bwrite },		/* bwrite */
    142  1.24.10.2  ad 	{ &vop_getpages_desc, genfs_getpages },		/* getpages */
    143  1.24.10.2  ad 	{ &vop_putpages_desc, genfs_putpages },		/* putpages */
    144  1.24.10.2  ad 	{ NULL, NULL }
    145  1.24.10.2  ad };
    146  1.24.10.2  ad 
    147  1.24.10.2  ad const struct vnodeopv_desc adosfs_vnodeop_opv_desc =
    148  1.24.10.2  ad 	{ &adosfs_vnodeop_p, adosfs_vnodeop_entries };
    149  1.24.10.2  ad 
    150  1.24.10.2  ad int
    151  1.24.10.2  ad adosfs_getattr(v)
    152  1.24.10.2  ad 	void *v;
    153  1.24.10.2  ad {
    154  1.24.10.2  ad 	struct vop_getattr_args /* {
    155  1.24.10.2  ad 		struct vnode *a_vp;
    156  1.24.10.2  ad 		struct vattr *a_vap;
    157  1.24.10.2  ad 		kauth_cred_t a_cred;
    158  1.24.10.2  ad 		struct lwp *a_l;
    159  1.24.10.2  ad 	} */ *sp = v;
    160  1.24.10.2  ad 	struct vattr *vap;
    161  1.24.10.2  ad 	struct adosfsmount *amp;
    162  1.24.10.2  ad 	struct anode *ap;
    163  1.24.10.2  ad 	u_long fblks;
    164  1.24.10.2  ad 
    165  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    166  1.24.10.2  ad 	advopprint(sp);
    167  1.24.10.2  ad #endif
    168  1.24.10.2  ad 	vap = sp->a_vap;
    169  1.24.10.2  ad 	ap = VTOA(sp->a_vp);
    170  1.24.10.2  ad 	amp = ap->amp;
    171  1.24.10.2  ad 	vattr_null(vap);
    172  1.24.10.2  ad 	vap->va_uid = ap->uid;
    173  1.24.10.2  ad 	vap->va_gid = ap->gid;
    174  1.24.10.2  ad 	vap->va_fsid = sp->a_vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
    175  1.24.10.2  ad 	vap->va_atime.tv_sec = vap->va_mtime.tv_sec = vap->va_ctime.tv_sec =
    176  1.24.10.2  ad 		ap->mtime.days * 24 * 60 * 60 + ap->mtime.mins * 60 +
    177  1.24.10.2  ad 		ap->mtime.ticks / 50 + (8 * 365 + 2) * 24 * 60 * 60;
    178  1.24.10.2  ad 	vap->va_atime.tv_nsec = vap->va_mtime.tv_nsec = vap->va_ctime.tv_nsec = 0;
    179  1.24.10.2  ad 	vap->va_gen = 0;
    180  1.24.10.2  ad 	vap->va_flags = 0;
    181  1.24.10.2  ad 	vap->va_rdev = NODEV;
    182  1.24.10.2  ad 	vap->va_fileid = ap->block;
    183  1.24.10.2  ad 	vap->va_type = sp->a_vp->v_type;
    184  1.24.10.2  ad 	vap->va_mode = adunixprot(ap->adprot) & amp->mask;
    185  1.24.10.2  ad 	if (sp->a_vp->v_type == VDIR) {
    186  1.24.10.2  ad 		vap->va_nlink = 1;	/* XXX bogus, oh well */
    187  1.24.10.2  ad 		vap->va_bytes = amp->bsize;
    188  1.24.10.2  ad 		vap->va_size = amp->bsize;
    189  1.24.10.2  ad 	} else {
    190  1.24.10.2  ad 		/*
    191  1.24.10.2  ad 		 * XXX actually we can track this if we were to walk the list
    192  1.24.10.2  ad 		 * of links if it exists.
    193  1.24.10.2  ad 		 * XXX for now, just set nlink to 2 if this is a hard link
    194  1.24.10.2  ad 		 * to a file, or a file with a hard link.
    195  1.24.10.2  ad 		 */
    196  1.24.10.2  ad 		vap->va_nlink = 1 + (ap->linkto != 0);
    197  1.24.10.2  ad 		/*
    198  1.24.10.2  ad 		 * round up to nearest blocks add number of file list
    199  1.24.10.2  ad 		 * blocks needed and mutiply by number of bytes per block.
    200  1.24.10.2  ad 		 */
    201  1.24.10.2  ad 		fblks = howmany(ap->fsize, amp->dbsize);
    202  1.24.10.2  ad 		fblks += howmany(fblks, ANODENDATBLKENT(ap));
    203  1.24.10.2  ad 		vap->va_bytes = fblks * amp->dbsize;
    204  1.24.10.2  ad 		vap->va_size = ap->fsize;
    205  1.24.10.2  ad 
    206  1.24.10.2  ad 		vap->va_blocksize = amp->dbsize;
    207  1.24.10.2  ad 	}
    208  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    209  1.24.10.2  ad 	printf(" 0)");
    210  1.24.10.2  ad #endif
    211  1.24.10.2  ad 	return(0);
    212  1.24.10.2  ad }
    213  1.24.10.2  ad /*
    214  1.24.10.2  ad  * are things locked??? they need to be to avoid this being
    215  1.24.10.2  ad  * deleted or changed (data block pointer blocks moving about.)
    216  1.24.10.2  ad  */
    217  1.24.10.2  ad int
    218  1.24.10.2  ad adosfs_read(v)
    219  1.24.10.2  ad 	void *v;
    220  1.24.10.2  ad {
    221  1.24.10.2  ad 	struct vop_read_args /* {
    222  1.24.10.2  ad 		struct vnode *a_vp;
    223  1.24.10.2  ad 		struct uio *a_uio;
    224  1.24.10.2  ad 		int a_ioflag;
    225  1.24.10.2  ad 		kauth_cred_t a_cred;
    226  1.24.10.2  ad 	} */ *sp = v;
    227  1.24.10.2  ad 	struct vnode *vp = sp->a_vp;
    228  1.24.10.2  ad 	struct adosfsmount *amp;
    229  1.24.10.2  ad 	struct anode *ap;
    230  1.24.10.2  ad 	struct uio *uio;
    231  1.24.10.2  ad 	struct buf *bp;
    232  1.24.10.2  ad 	daddr_t lbn;
    233  1.24.10.2  ad 	int size, diff, error;
    234  1.24.10.2  ad 	long n, on;
    235  1.24.10.2  ad 
    236  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    237  1.24.10.2  ad 	advopprint(sp);
    238  1.24.10.2  ad #endif
    239  1.24.10.2  ad 	error = 0;
    240  1.24.10.2  ad 	uio = sp->a_uio;
    241  1.24.10.2  ad 	ap = VTOA(sp->a_vp);
    242  1.24.10.2  ad 	amp = ap->amp;
    243  1.24.10.2  ad 	/*
    244  1.24.10.2  ad 	 * Return EOF for character devices, EIO for others
    245  1.24.10.2  ad 	 */
    246  1.24.10.2  ad 	if (sp->a_vp->v_type != VREG) {
    247  1.24.10.2  ad 		error = EIO;
    248  1.24.10.2  ad 		goto reterr;
    249  1.24.10.2  ad 	}
    250  1.24.10.2  ad 	if (uio->uio_resid == 0)
    251  1.24.10.2  ad 		goto reterr;
    252  1.24.10.2  ad 	if (uio->uio_offset < 0) {
    253  1.24.10.2  ad 		error = EINVAL;
    254  1.24.10.2  ad 		goto reterr;
    255  1.24.10.2  ad 	}
    256  1.24.10.2  ad 
    257  1.24.10.2  ad 	/*
    258  1.24.10.2  ad 	 * to expensive to let general algorithm figure out that
    259  1.24.10.2  ad 	 * we are beyond the file.  Do it now.
    260  1.24.10.2  ad 	 */
    261  1.24.10.2  ad 	if (uio->uio_offset >= ap->fsize)
    262  1.24.10.2  ad 		goto reterr;
    263  1.24.10.2  ad 
    264  1.24.10.2  ad 	/*
    265  1.24.10.2  ad 	 * taken from ufs_read()
    266  1.24.10.2  ad 	 */
    267  1.24.10.2  ad 
    268  1.24.10.2  ad 	if (vp->v_type == VREG && IS_FFS(amp)) {
    269  1.24.10.2  ad 		const int advice = IO_ADV_DECODE(sp->a_ioflag);
    270  1.24.10.2  ad 		error = 0;
    271  1.24.10.2  ad 
    272  1.24.10.2  ad 		while (uio->uio_resid > 0) {
    273  1.24.10.2  ad 			void *win;
    274  1.24.10.2  ad 			int flags;
    275  1.24.10.2  ad 			vsize_t bytelen = MIN(ap->fsize - uio->uio_offset,
    276  1.24.10.2  ad 					      uio->uio_resid);
    277  1.24.10.2  ad 
    278  1.24.10.2  ad 			if (bytelen == 0) {
    279  1.24.10.2  ad 				break;
    280  1.24.10.2  ad 			}
    281  1.24.10.2  ad 			win = ubc_alloc(&vp->v_uobj, uio->uio_offset,
    282  1.24.10.2  ad 					&bytelen, advice, UBC_READ);
    283  1.24.10.2  ad 			error = uiomove(win, bytelen, uio);
    284  1.24.10.2  ad 			flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
    285  1.24.10.2  ad 			ubc_release(win, flags);
    286  1.24.10.2  ad 			if (error) {
    287  1.24.10.2  ad 				break;
    288  1.24.10.2  ad 			}
    289  1.24.10.2  ad 		}
    290  1.24.10.2  ad 		goto out;
    291  1.24.10.2  ad 	}
    292  1.24.10.2  ad 
    293  1.24.10.2  ad 	do {
    294  1.24.10.2  ad 		size = amp->dbsize;
    295  1.24.10.2  ad 		lbn = uio->uio_offset / size;
    296  1.24.10.2  ad 		on = uio->uio_offset % size;
    297  1.24.10.2  ad 		n = MIN(size - on, uio->uio_resid);
    298  1.24.10.2  ad 		diff = ap->fsize - uio->uio_offset;
    299  1.24.10.2  ad 		/*
    300  1.24.10.2  ad 		 * check for EOF
    301  1.24.10.2  ad 		 */
    302  1.24.10.2  ad 		if (diff <= 0)
    303  1.24.10.2  ad 			return(0);
    304  1.24.10.2  ad 		if (diff < n)
    305  1.24.10.2  ad 			n = diff;
    306  1.24.10.2  ad 		/*
    307  1.24.10.2  ad 		 * read ahead could possibly be worth something
    308  1.24.10.2  ad 		 * but not much as ados makes little attempt to
    309  1.24.10.2  ad 		 * make things contigous
    310  1.24.10.2  ad 		 */
    311  1.24.10.2  ad 		error = bread(sp->a_vp, lbn, amp->bsize, NOCRED, &bp);
    312  1.24.10.2  ad 		if (error) {
    313  1.24.10.2  ad 			brelse(bp);
    314  1.24.10.2  ad 			goto reterr;
    315  1.24.10.2  ad 		}
    316  1.24.10.2  ad 		if (!IS_FFS(amp)) {
    317  1.24.10.2  ad 			if (bp->b_resid > 0)
    318  1.24.10.2  ad 				error = EIO; /* OFS needs the complete block */
    319  1.24.10.2  ad 			else if (adoswordn(bp, 0) != BPT_DATA) {
    320  1.24.10.2  ad #ifdef DIAGNOSTIC
    321  1.24.10.2  ad 				printf("adosfs: bad primary type blk %" PRId64 "\n",
    322  1.24.10.2  ad 				    bp->b_blkno / (amp->bsize / DEV_BSIZE));
    323  1.24.10.2  ad #endif
    324  1.24.10.2  ad 				error = EINVAL;
    325  1.24.10.2  ad 			} else if (adoscksum(bp, ap->nwords)) {
    326  1.24.10.2  ad #ifdef DIAGNOSTIC
    327  1.24.10.2  ad 				printf("adosfs: blk %" PRId64 " failed cksum.\n",
    328  1.24.10.2  ad 				    bp->b_blkno / (amp->bsize / DEV_BSIZE));
    329  1.24.10.2  ad #endif
    330  1.24.10.2  ad 				error = EINVAL;
    331  1.24.10.2  ad 			}
    332  1.24.10.2  ad 		}
    333  1.24.10.2  ad 
    334  1.24.10.2  ad 		if (error) {
    335  1.24.10.2  ad 			brelse(bp);
    336  1.24.10.2  ad 			goto reterr;
    337  1.24.10.2  ad 		}
    338  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    339  1.24.10.2  ad 		printf(" %" PRId64 "+%ld-%" PRId64 "+%ld", lbn, on, lbn, n);
    340  1.24.10.2  ad #endif
    341  1.24.10.2  ad 		n = MIN(n, size - bp->b_resid);
    342  1.24.10.2  ad 		error = uiomove((char *)bp->b_data + on +
    343  1.24.10.2  ad 				amp->bsize - amp->dbsize, (int)n, uio);
    344  1.24.10.2  ad 		brelse(bp);
    345  1.24.10.2  ad 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
    346  1.24.10.2  ad 
    347  1.24.10.2  ad out:
    348  1.24.10.2  ad reterr:
    349  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    350  1.24.10.2  ad 	printf(" %d)", error);
    351  1.24.10.2  ad #endif
    352  1.24.10.2  ad 	return(error);
    353  1.24.10.2  ad }
    354  1.24.10.2  ad 
    355  1.24.10.2  ad int
    356  1.24.10.2  ad adosfs_write(v)
    357  1.24.10.2  ad 	void *v;
    358  1.24.10.2  ad {
    359  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    360  1.24.10.2  ad 	struct vop_write_args /* {
    361  1.24.10.2  ad 		struct vnode *a_vp;
    362  1.24.10.2  ad 		struct uio *a_uio;
    363  1.24.10.2  ad 		int a_ioflag;
    364  1.24.10.2  ad 		kauth_cred_t a_cred;
    365  1.24.10.2  ad 	} */ *sp = v;
    366  1.24.10.2  ad 	advopprint(sp);
    367  1.24.10.2  ad 	printf(" EOPNOTSUPP)");
    368  1.24.10.2  ad #endif
    369  1.24.10.2  ad 	return(EOPNOTSUPP);
    370  1.24.10.2  ad }
    371  1.24.10.2  ad 
    372  1.24.10.2  ad /*
    373  1.24.10.2  ad  * Just call the device strategy routine
    374  1.24.10.2  ad  */
    375  1.24.10.2  ad int
    376  1.24.10.2  ad adosfs_strategy(v)
    377  1.24.10.2  ad 	void *v;
    378  1.24.10.2  ad {
    379  1.24.10.2  ad 	struct vop_strategy_args /* {
    380  1.24.10.2  ad 		struct vnode *a_vp;
    381  1.24.10.2  ad 		struct buf *a_bp;
    382  1.24.10.2  ad 	} */ *sp = v;
    383  1.24.10.2  ad 	struct buf *bp;
    384  1.24.10.2  ad 	struct anode *ap;
    385  1.24.10.2  ad 	struct vnode *vp;
    386  1.24.10.2  ad 	int error;
    387  1.24.10.2  ad 
    388  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    389  1.24.10.2  ad 	advopprint(sp);
    390  1.24.10.2  ad #endif
    391  1.24.10.2  ad 	bp = sp->a_bp;
    392  1.24.10.2  ad 	if (bp->b_vp == NULL) {
    393  1.24.10.2  ad 		bp->b_error = EIO;
    394  1.24.10.2  ad 		biodone(bp);
    395  1.24.10.2  ad 		error = EIO;
    396  1.24.10.2  ad 		goto reterr;
    397  1.24.10.2  ad 	}
    398  1.24.10.2  ad 	vp = sp->a_vp;
    399  1.24.10.2  ad 	ap = VTOA(vp);
    400  1.24.10.2  ad 	if (bp->b_blkno == bp->b_lblkno) {
    401  1.24.10.2  ad 		error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
    402  1.24.10.2  ad 		if (error) {
    403  1.24.10.2  ad 			bp->b_flags = error;
    404  1.24.10.2  ad 			biodone(bp);
    405  1.24.10.2  ad 			goto reterr;
    406  1.24.10.2  ad 		}
    407  1.24.10.2  ad 	}
    408  1.24.10.2  ad 	if ((long)bp->b_blkno == -1) {
    409  1.24.10.2  ad 		biodone(bp);
    410  1.24.10.2  ad 		error = 0;
    411  1.24.10.2  ad 		goto reterr;
    412  1.24.10.2  ad 	}
    413  1.24.10.2  ad 	vp = ap->amp->devvp;
    414  1.24.10.2  ad 	error = VOP_STRATEGY(vp, bp);
    415  1.24.10.2  ad reterr:
    416  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    417  1.24.10.2  ad 	printf(" %d)", error);
    418  1.24.10.2  ad #endif
    419  1.24.10.2  ad 	return(error);
    420  1.24.10.2  ad }
    421  1.24.10.2  ad 
    422  1.24.10.2  ad int
    423  1.24.10.2  ad adosfs_link(v)
    424  1.24.10.2  ad 	void *v;
    425  1.24.10.2  ad {
    426  1.24.10.2  ad 	struct vop_link_args /* {
    427  1.24.10.2  ad 		struct vnode *a_dvp;
    428  1.24.10.2  ad 		struct vnode *a_vp;
    429  1.24.10.2  ad 		struct componentname *a_cnp;
    430  1.24.10.2  ad 	} */ *ap = v;
    431  1.24.10.2  ad 
    432  1.24.10.2  ad 	VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
    433  1.24.10.2  ad 	vput(ap->a_dvp);
    434  1.24.10.2  ad 	return (EROFS);
    435  1.24.10.2  ad }
    436  1.24.10.2  ad 
    437  1.24.10.2  ad int
    438  1.24.10.2  ad adosfs_symlink(v)
    439  1.24.10.2  ad 	void *v;
    440  1.24.10.2  ad {
    441  1.24.10.2  ad 	struct vop_symlink_args /* {
    442  1.24.10.2  ad 		struct vnode *a_dvp;
    443  1.24.10.2  ad 		struct vnode **a_vpp;
    444  1.24.10.2  ad 		struct componentname *a_cnp;
    445  1.24.10.2  ad 		struct vattr *a_vap;
    446  1.24.10.2  ad 		char *a_target;
    447  1.24.10.2  ad 	} */ *ap = v;
    448  1.24.10.2  ad 
    449  1.24.10.2  ad 	VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
    450  1.24.10.2  ad 	vput(ap->a_dvp);
    451  1.24.10.2  ad 	return (EROFS);
    452  1.24.10.2  ad }
    453  1.24.10.2  ad 
    454  1.24.10.2  ad /*
    455  1.24.10.2  ad  * Wait until the vnode has finished changing state.
    456  1.24.10.2  ad  */
    457  1.24.10.2  ad int
    458  1.24.10.2  ad adosfs_bmap(v)
    459  1.24.10.2  ad 	void *v;
    460  1.24.10.2  ad {
    461  1.24.10.2  ad 	struct vop_bmap_args /* {
    462  1.24.10.2  ad 		struct vnode *a_vp;
    463  1.24.10.2  ad 		daddr_t  a_bn;
    464  1.24.10.2  ad 		struct vnode **a_vpp;
    465  1.24.10.2  ad 		daddr_t *a_bnp;
    466  1.24.10.2  ad 		int *a_runp;
    467  1.24.10.2  ad 	} */ *sp = v;
    468  1.24.10.2  ad 	struct anode *ap;
    469  1.24.10.2  ad 	struct buf *flbp;
    470  1.24.10.2  ad 	long nb, flblk, flblkoff, fcnt;
    471  1.24.10.2  ad 	daddr_t *bnp;
    472  1.24.10.2  ad 	daddr_t bn;
    473  1.24.10.2  ad 	int error;
    474  1.24.10.2  ad 
    475  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    476  1.24.10.2  ad 	advopprint(sp);
    477  1.24.10.2  ad #endif
    478  1.24.10.2  ad 	ap = VTOA(sp->a_vp);
    479  1.24.10.2  ad 	bn = sp->a_bn;
    480  1.24.10.2  ad 	bnp = sp->a_bnp;
    481  1.24.10.2  ad 	if (sp->a_runp) {
    482  1.24.10.2  ad 		*sp->a_runp = 0;
    483  1.24.10.2  ad 	}
    484  1.24.10.2  ad 	error = 0;
    485  1.24.10.2  ad 
    486  1.24.10.2  ad 	if (sp->a_vpp != NULL)
    487  1.24.10.2  ad 		*sp->a_vpp = ap->amp->devvp;
    488  1.24.10.2  ad 	if (bnp == NULL)
    489  1.24.10.2  ad 		goto reterr;
    490  1.24.10.2  ad 	if (bn < 0) {
    491  1.24.10.2  ad 		error = EFBIG;
    492  1.24.10.2  ad 		goto reterr;
    493  1.24.10.2  ad 	}
    494  1.24.10.2  ad 	if (sp->a_vp->v_type != VREG) {
    495  1.24.10.2  ad 		error = EINVAL;
    496  1.24.10.2  ad 		goto reterr;
    497  1.24.10.2  ad 	}
    498  1.24.10.2  ad 
    499  1.24.10.2  ad 	/*
    500  1.24.10.2  ad 	 * walk the chain of file list blocks until we find
    501  1.24.10.2  ad 	 * the one that will yield the block pointer we need.
    502  1.24.10.2  ad 	 */
    503  1.24.10.2  ad 	if (ap->type == AFILE)
    504  1.24.10.2  ad 		nb = ap->block;			/* pointer to ourself */
    505  1.24.10.2  ad 	else if (ap->type == ALFILE)
    506  1.24.10.2  ad 		nb = ap->linkto;		/* pointer to real file */
    507  1.24.10.2  ad 	else {
    508  1.24.10.2  ad 		error = EINVAL;
    509  1.24.10.2  ad 		goto reterr;
    510  1.24.10.2  ad 	}
    511  1.24.10.2  ad 
    512  1.24.10.2  ad 	flblk = bn / ANODENDATBLKENT(ap);
    513  1.24.10.2  ad 	flbp = NULL;
    514  1.24.10.2  ad 
    515  1.24.10.2  ad 	/*
    516  1.24.10.2  ad 	 * check last indirect block cache
    517  1.24.10.2  ad 	 */
    518  1.24.10.2  ad 	if (flblk < ap->lastlindblk)
    519  1.24.10.2  ad 		fcnt = 0;
    520  1.24.10.2  ad 	else {
    521  1.24.10.2  ad 		flblk -= ap->lastlindblk;
    522  1.24.10.2  ad 		fcnt = ap->lastlindblk;
    523  1.24.10.2  ad 		nb = ap->lastindblk;
    524  1.24.10.2  ad 	}
    525  1.24.10.2  ad 	while (flblk >= 0) {
    526  1.24.10.2  ad 		if (flbp)
    527  1.24.10.2  ad 			brelse(flbp);
    528  1.24.10.2  ad 		if (nb == 0) {
    529  1.24.10.2  ad #ifdef DIAGNOSTIC
    530  1.24.10.2  ad 			printf("adosfs: bad file list chain.\n");
    531  1.24.10.2  ad #endif
    532  1.24.10.2  ad 			error = EINVAL;
    533  1.24.10.2  ad 			goto reterr;
    534  1.24.10.2  ad 		}
    535  1.24.10.2  ad 		error = bread(ap->amp->devvp, nb * ap->amp->bsize / DEV_BSIZE,
    536  1.24.10.2  ad 			      ap->amp->bsize, NOCRED, &flbp);
    537  1.24.10.2  ad 		if (error) {
    538  1.24.10.2  ad 			brelse(flbp);
    539  1.24.10.2  ad 			goto reterr;
    540  1.24.10.2  ad 		}
    541  1.24.10.2  ad 		if (adoscksum(flbp, ap->nwords)) {
    542  1.24.10.2  ad #ifdef DIAGNOSTIC
    543  1.24.10.2  ad 			printf("adosfs: blk %ld failed cksum.\n", nb);
    544  1.24.10.2  ad #endif
    545  1.24.10.2  ad 			brelse(flbp);
    546  1.24.10.2  ad 			error = EINVAL;
    547  1.24.10.2  ad 			goto reterr;
    548  1.24.10.2  ad 		}
    549  1.24.10.2  ad 		/*
    550  1.24.10.2  ad 		 * update last indirect block cache
    551  1.24.10.2  ad 		 */
    552  1.24.10.2  ad 		ap->lastlindblk = fcnt++;
    553  1.24.10.2  ad 		ap->lastindblk = nb;
    554  1.24.10.2  ad 
    555  1.24.10.2  ad 		nb = adoswordn(flbp, ap->nwords - 2);
    556  1.24.10.2  ad 		flblk--;
    557  1.24.10.2  ad 	}
    558  1.24.10.2  ad 	/*
    559  1.24.10.2  ad 	 * calculate offset of block number in table.  The table starts
    560  1.24.10.2  ad 	 * at nwords - 51 and goes to offset 6 or less if indicated by the
    561  1.24.10.2  ad 	 * valid table entries stored at offset ADBI_NBLKTABENT.
    562  1.24.10.2  ad 	 */
    563  1.24.10.2  ad 	flblkoff = bn % ANODENDATBLKENT(ap);
    564  1.24.10.2  ad 	if (flblkoff < adoswordn(flbp, 2 /* ADBI_NBLKTABENT */)) {
    565  1.24.10.2  ad 		flblkoff = (ap->nwords - 51) - flblkoff;
    566  1.24.10.2  ad 		*bnp = adoswordn(flbp, flblkoff) * ap->amp->bsize / DEV_BSIZE;
    567  1.24.10.2  ad 	} else {
    568  1.24.10.2  ad #ifdef DIAGNOSTIC
    569  1.24.10.2  ad 		printf("flblk offset %ld too large in lblk %ld blk %" PRId64 "\n",
    570  1.24.10.2  ad 		    flblkoff, (long)bn, flbp->b_blkno);
    571  1.24.10.2  ad #endif
    572  1.24.10.2  ad 		error = EINVAL;
    573  1.24.10.2  ad 	}
    574  1.24.10.2  ad 	brelse(flbp);
    575  1.24.10.2  ad reterr:
    576  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    577  1.24.10.2  ad 	if (error == 0 && bnp)
    578  1.24.10.2  ad 		printf(" %lld => %lld", (long long)bn, (long long)*bnp);
    579  1.24.10.2  ad 	printf(" %d)\n", error);
    580  1.24.10.2  ad #endif
    581  1.24.10.2  ad 	return(error);
    582  1.24.10.2  ad }
    583  1.24.10.2  ad 
    584  1.24.10.2  ad /*
    585  1.24.10.2  ad  * Print out the contents of a adosfs vnode.
    586  1.24.10.2  ad  */
    587  1.24.10.2  ad /* ARGSUSED */
    588  1.24.10.2  ad int
    589  1.24.10.2  ad adosfs_print(v)
    590  1.24.10.2  ad 	void *v;
    591  1.24.10.2  ad {
    592  1.24.10.2  ad #if 0
    593  1.24.10.2  ad 	struct vop_print_args /* {
    594  1.24.10.2  ad 		struct vnode *a_vp;
    595  1.24.10.2  ad 	} */ *sp = v;
    596  1.24.10.2  ad #endif
    597  1.24.10.2  ad 	return(0);
    598  1.24.10.2  ad }
    599  1.24.10.2  ad 
    600  1.24.10.2  ad int
    601  1.24.10.2  ad adosfs_readdir(v)
    602  1.24.10.2  ad 	void *v;
    603  1.24.10.2  ad {
    604  1.24.10.2  ad 	struct vop_readdir_args /* {
    605  1.24.10.2  ad 		struct vnode *a_vp;
    606  1.24.10.2  ad 		struct uio *a_uio;
    607  1.24.10.2  ad 		kauth_cred_t a_cred;
    608  1.24.10.2  ad 		int *a_eofflag;
    609  1.24.10.2  ad 		off_t **a_cookies;
    610  1.24.10.2  ad 		int *a_ncookies;
    611  1.24.10.2  ad 	} */ *sp = v;
    612  1.24.10.2  ad 	int error, first, useri, chainc, hashi, scanned;
    613  1.24.10.2  ad 	u_long nextbn;
    614  1.24.10.2  ad 	struct dirent ad, *adp;
    615  1.24.10.2  ad 	struct anode *pap, *ap;
    616  1.24.10.2  ad 	struct vnode *vp;
    617  1.24.10.2  ad 	struct uio *uio = sp->a_uio;
    618  1.24.10.2  ad 	off_t uoff = uio->uio_offset;
    619  1.24.10.2  ad 	off_t *cookies = NULL;
    620  1.24.10.2  ad 	int ncookies = 0;
    621  1.24.10.2  ad 
    622  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    623  1.24.10.2  ad 	advopprint(sp);
    624  1.24.10.2  ad #endif
    625  1.24.10.2  ad 
    626  1.24.10.2  ad 	if (sp->a_vp->v_type != VDIR) {
    627  1.24.10.2  ad 		error = ENOTDIR;
    628  1.24.10.2  ad 		goto reterr;
    629  1.24.10.2  ad 	}
    630  1.24.10.2  ad 
    631  1.24.10.2  ad 	if (uoff < 0) {
    632  1.24.10.2  ad 		error = EINVAL;
    633  1.24.10.2  ad 		goto reterr;
    634  1.24.10.2  ad 	}
    635  1.24.10.2  ad 
    636  1.24.10.2  ad 	pap = VTOA(sp->a_vp);
    637  1.24.10.2  ad 	adp = &ad;
    638  1.24.10.2  ad 	error = nextbn = hashi = chainc = scanned = 0;
    639  1.24.10.2  ad 	first = useri = uoff / sizeof ad;
    640  1.24.10.2  ad 
    641  1.24.10.2  ad 	/*
    642  1.24.10.2  ad 	 * If offset requested is not on a slot boundary
    643  1.24.10.2  ad 	 */
    644  1.24.10.2  ad 	if (uoff % sizeof ad) {
    645  1.24.10.2  ad 		error = EINVAL;
    646  1.24.10.2  ad 		goto reterr;
    647  1.24.10.2  ad 	}
    648  1.24.10.2  ad 
    649  1.24.10.2  ad 	for (;;) {
    650  1.24.10.2  ad 		if (hashi == pap->ntabent) {
    651  1.24.10.2  ad 			*sp->a_eofflag = 1;
    652  1.24.10.2  ad 			break;
    653  1.24.10.2  ad 		}
    654  1.24.10.2  ad 		if (pap->tab[hashi] == 0) {
    655  1.24.10.2  ad 			hashi++;
    656  1.24.10.2  ad 			continue;
    657  1.24.10.2  ad 		}
    658  1.24.10.2  ad 		if (nextbn == 0)
    659  1.24.10.2  ad 			nextbn = pap->tab[hashi];
    660  1.24.10.2  ad 
    661  1.24.10.2  ad 		/*
    662  1.24.10.2  ad 		 * First determine if we can skip this chain
    663  1.24.10.2  ad 		 */
    664  1.24.10.2  ad 		if (chainc == 0) {
    665  1.24.10.2  ad 			int skip;
    666  1.24.10.2  ad 
    667  1.24.10.2  ad 			skip = useri - scanned;
    668  1.24.10.2  ad 			if (pap->tabi[hashi] > 0 && pap->tabi[hashi] <= skip) {
    669  1.24.10.2  ad 				scanned += pap->tabi[hashi];
    670  1.24.10.2  ad 				hashi++;
    671  1.24.10.2  ad 				nextbn = 0;
    672  1.24.10.2  ad 				continue;
    673  1.24.10.2  ad 			}
    674  1.24.10.2  ad 		}
    675  1.24.10.2  ad 
    676  1.24.10.2  ad 		/*
    677  1.24.10.2  ad 		 * Now [continue to] walk the chain
    678  1.24.10.2  ad 		 */
    679  1.24.10.2  ad 		ap = NULL;
    680  1.24.10.2  ad 		do {
    681  1.24.10.2  ad 			error = VFS_VGET(pap->amp->mp, (ino_t)nextbn, &vp);
    682  1.24.10.2  ad 			if (error)
    683  1.24.10.2  ad 				goto reterr;
    684  1.24.10.2  ad 			ap = VTOA(vp);
    685  1.24.10.2  ad 			scanned++;
    686  1.24.10.2  ad 			chainc++;
    687  1.24.10.2  ad 			nextbn = ap->hashf;
    688  1.24.10.2  ad 
    689  1.24.10.2  ad 			/*
    690  1.24.10.2  ad 			 * check for end of chain.
    691  1.24.10.2  ad 			 */
    692  1.24.10.2  ad 			if (nextbn == 0) {
    693  1.24.10.2  ad 				pap->tabi[hashi] = chainc;
    694  1.24.10.2  ad 				hashi++;
    695  1.24.10.2  ad 				chainc = 0;
    696  1.24.10.2  ad 			} else if (pap->tabi[hashi] <= 0 &&
    697  1.24.10.2  ad 			    -chainc < pap->tabi[hashi])
    698  1.24.10.2  ad 				pap->tabi[hashi] = -chainc;
    699  1.24.10.2  ad 
    700  1.24.10.2  ad 			if (useri >= scanned) {
    701  1.24.10.2  ad 				vput(vp);
    702  1.24.10.2  ad 				ap = NULL;
    703  1.24.10.2  ad 			}
    704  1.24.10.2  ad 		} while (ap == NULL && nextbn != 0);
    705  1.24.10.2  ad 
    706  1.24.10.2  ad 		/*
    707  1.24.10.2  ad 		 * We left the loop but without a result so do main over.
    708  1.24.10.2  ad 		 */
    709  1.24.10.2  ad 		if (ap == NULL)
    710  1.24.10.2  ad 			continue;
    711  1.24.10.2  ad 		/*
    712  1.24.10.2  ad 		 * Fill in dirent record
    713  1.24.10.2  ad 		 */
    714  1.24.10.2  ad 		memset(adp, 0, sizeof *adp);
    715  1.24.10.2  ad 		adp->d_fileno = ap->block;
    716  1.24.10.2  ad 		/*
    717  1.24.10.2  ad 		 * This deserves a function in kern/vfs_subr.c
    718  1.24.10.2  ad 		 */
    719  1.24.10.2  ad 		switch (ATOV(ap)->v_type) {
    720  1.24.10.2  ad 		case VREG:
    721  1.24.10.2  ad 			adp->d_type = DT_REG;
    722  1.24.10.2  ad 			break;
    723  1.24.10.2  ad 		case VDIR:
    724  1.24.10.2  ad 			adp->d_type = DT_DIR;
    725  1.24.10.2  ad 			break;
    726  1.24.10.2  ad 		case VLNK:
    727  1.24.10.2  ad 			adp->d_type = DT_LNK;
    728  1.24.10.2  ad 			break;
    729  1.24.10.2  ad 		default:
    730  1.24.10.2  ad 			adp->d_type = DT_UNKNOWN;
    731  1.24.10.2  ad 			break;
    732  1.24.10.2  ad 		}
    733  1.24.10.2  ad 		adp->d_namlen = strlen(ap->name);
    734  1.24.10.2  ad 		memcpy(adp->d_name, ap->name, adp->d_namlen);
    735  1.24.10.2  ad 		adp->d_reclen = _DIRENT_SIZE(adp);
    736  1.24.10.2  ad 		vput(vp);
    737  1.24.10.2  ad 
    738  1.24.10.2  ad 		if (adp->d_reclen > uio->uio_resid) {
    739  1.24.10.2  ad 			if (useri == first)	/* no room for even one entry */
    740  1.24.10.2  ad 				error = EINVAL;
    741  1.24.10.2  ad 			break;
    742  1.24.10.2  ad 		}
    743  1.24.10.2  ad 		error = uiomove(adp, adp->d_reclen, uio);
    744  1.24.10.2  ad 		if (error)
    745  1.24.10.2  ad 			break;
    746  1.24.10.2  ad 		useri++;
    747  1.24.10.2  ad 	}
    748  1.24.10.2  ad 	ncookies = useri - first;
    749  1.24.10.2  ad 	uio->uio_offset = uoff + ncookies * sizeof ad;
    750  1.24.10.2  ad reterr:
    751  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    752  1.24.10.2  ad 	printf(" %d)", error);
    753  1.24.10.2  ad #endif
    754  1.24.10.2  ad 	if (sp->a_ncookies != NULL) {
    755  1.24.10.2  ad 		*sp->a_ncookies = ncookies;
    756  1.24.10.2  ad 		if (!error) {
    757  1.24.10.2  ad 			*sp->a_cookies = cookies =
    758  1.24.10.2  ad 			   malloc(ncookies * sizeof *cookies, M_TEMP, M_WAITOK);
    759  1.24.10.2  ad 
    760  1.24.10.2  ad 			while (ncookies--) {
    761  1.24.10.2  ad 				uoff += sizeof ad;
    762  1.24.10.2  ad 				*cookies++ = uoff;
    763  1.24.10.2  ad 			}
    764  1.24.10.2  ad 		} else
    765  1.24.10.2  ad 			*sp->a_cookies = NULL;
    766  1.24.10.2  ad 	}
    767  1.24.10.2  ad 
    768  1.24.10.2  ad 	return(error);
    769  1.24.10.2  ad }
    770  1.24.10.2  ad 
    771  1.24.10.2  ad 
    772  1.24.10.2  ad int
    773  1.24.10.2  ad adosfs_access(v)
    774  1.24.10.2  ad 	void *v;
    775  1.24.10.2  ad {
    776  1.24.10.2  ad 	struct vop_access_args /* {
    777  1.24.10.2  ad 		struct vnode *a_vp;
    778  1.24.10.2  ad 		int  a_mode;
    779  1.24.10.2  ad 		kauth_cred_t a_cred;
    780  1.24.10.2  ad 		struct lwp *a_l;
    781  1.24.10.2  ad 	} */ *sp = v;
    782  1.24.10.2  ad 	struct anode *ap;
    783  1.24.10.2  ad 	struct vnode *vp = sp->a_vp;
    784  1.24.10.2  ad 	int error;
    785  1.24.10.2  ad 
    786  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    787  1.24.10.2  ad 	advopprint(sp);
    788  1.24.10.2  ad #endif
    789  1.24.10.2  ad 
    790  1.24.10.2  ad 	ap = VTOA(vp);
    791  1.24.10.2  ad #ifdef DIAGNOSTIC
    792  1.24.10.2  ad 	if (!VOP_ISLOCKED(vp)) {
    793  1.24.10.2  ad 		vprint("adosfs_access: not locked", sp->a_vp);
    794  1.24.10.2  ad 		panic("adosfs_access: not locked");
    795  1.24.10.2  ad 	}
    796  1.24.10.2  ad #endif
    797  1.24.10.2  ad 	/*
    798  1.24.10.2  ad 	 * Disallow write attempts unless the file is a socket,
    799  1.24.10.2  ad 	 * fifo, or a block or character device resident on the
    800  1.24.10.2  ad 	 * file system.
    801  1.24.10.2  ad 	 */
    802  1.24.10.2  ad 	if (sp->a_mode & VWRITE) {
    803  1.24.10.2  ad 		switch (vp->v_type) {
    804  1.24.10.2  ad 		case VDIR:
    805  1.24.10.2  ad 		case VLNK:
    806  1.24.10.2  ad 		case VREG:
    807  1.24.10.2  ad 			return (EROFS);
    808  1.24.10.2  ad 		default:
    809  1.24.10.2  ad 			break;
    810  1.24.10.2  ad 		}
    811  1.24.10.2  ad 	}
    812  1.24.10.2  ad #ifdef QUOTA
    813  1.24.10.2  ad #endif
    814  1.24.10.2  ad 	error = vaccess(sp->a_vp->v_type, adunixprot(ap->adprot) & ap->amp->mask,
    815  1.24.10.2  ad 	    ap->uid, ap->gid, sp->a_mode, sp->a_cred);
    816  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    817  1.24.10.2  ad 	printf(" %d)", error);
    818  1.24.10.2  ad #endif
    819  1.24.10.2  ad 	return(error);
    820  1.24.10.2  ad }
    821  1.24.10.2  ad 
    822  1.24.10.2  ad int
    823  1.24.10.2  ad adosfs_readlink(v)
    824  1.24.10.2  ad 	void *v;
    825  1.24.10.2  ad {
    826  1.24.10.2  ad 	struct vop_readlink_args /* {
    827  1.24.10.2  ad 		struct vnode *a_vp;
    828  1.24.10.2  ad 		struct uio *a_uio;
    829  1.24.10.2  ad 		kauth_cred_t a_cred;
    830  1.24.10.2  ad 	} */ *sp = v;
    831  1.24.10.2  ad 	struct anode *ap;
    832  1.24.10.2  ad 	int error;
    833  1.24.10.2  ad 
    834  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    835  1.24.10.2  ad 	advopprint(sp);
    836  1.24.10.2  ad #endif
    837  1.24.10.2  ad 	ap = VTOA(sp->a_vp);
    838  1.24.10.2  ad 	error = uiomove(ap->slinkto, strlen(ap->slinkto), sp->a_uio);
    839  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    840  1.24.10.2  ad 	printf(" %d)", error);
    841  1.24.10.2  ad #endif
    842  1.24.10.2  ad 	return (error);
    843  1.24.10.2  ad }
    844  1.24.10.2  ad 
    845  1.24.10.2  ad /*ARGSUSED*/
    846  1.24.10.2  ad int
    847  1.24.10.2  ad adosfs_inactive(v)
    848  1.24.10.2  ad 	void *v;
    849  1.24.10.2  ad {
    850  1.24.10.2  ad 	struct vop_inactive_args /* {
    851  1.24.10.2  ad 		struct vnode *a_vp;
    852  1.24.10.2  ad 		struct lwp *a_l;
    853  1.24.10.2  ad 	} */ *sp = v;
    854  1.24.10.2  ad 	struct vnode *vp = sp->a_vp;
    855  1.24.10.2  ad 	struct lwp *l = sp->a_l;
    856  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    857  1.24.10.2  ad 	advopprint(sp);
    858  1.24.10.2  ad #endif
    859  1.24.10.2  ad 	VOP_UNLOCK(vp, 0);
    860  1.24.10.2  ad 	/* XXX this needs to check if file was deleted */
    861  1.24.10.2  ad 	vrecycle(vp, NULL, l);
    862  1.24.10.2  ad 
    863  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    864  1.24.10.2  ad 	printf(" 0)");
    865  1.24.10.2  ad #endif
    866  1.24.10.2  ad 	return(0);
    867  1.24.10.2  ad }
    868  1.24.10.2  ad 
    869  1.24.10.2  ad /*
    870  1.24.10.2  ad  * the kernel wants its vnode back.
    871  1.24.10.2  ad  * no lock needed we are being called from vclean()
    872  1.24.10.2  ad  */
    873  1.24.10.2  ad int
    874  1.24.10.2  ad adosfs_reclaim(v)
    875  1.24.10.2  ad 	void *v;
    876  1.24.10.2  ad {
    877  1.24.10.2  ad 	struct vop_reclaim_args /* {
    878  1.24.10.2  ad 		struct vnode *a_vp;
    879  1.24.10.2  ad 	} */ *sp = v;
    880  1.24.10.2  ad 	struct vnode *vp;
    881  1.24.10.2  ad 	struct anode *ap;
    882  1.24.10.2  ad 
    883  1.24.10.2  ad #ifdef ADOSFS_DIAGNOSTIC
    884  1.24.10.2  ad 	printf("(reclaim 0)");
    885  1.24.10.2  ad #endif
    886  1.24.10.2  ad 	vp = sp->a_vp;
    887  1.24.10.2  ad 	ap = VTOA(vp);
    888  1.24.10.2  ad 	LIST_REMOVE(ap, link);
    889  1.24.10.2  ad 	cache_purge(vp);
    890  1.24.10.2  ad 	if (vp->v_type == VDIR && ap->tab)
    891  1.24.10.2  ad 		free(ap->tab, M_ANODE);
    892  1.24.10.2  ad 	else if (vp->v_type == VLNK && ap->slinkto)
    893  1.24.10.2  ad 		free(ap->slinkto, M_ANODE);
    894  1.24.10.2  ad 	genfs_node_destroy(vp);
    895  1.24.10.2  ad 	pool_put(&adosfs_node_pool, ap);
    896  1.24.10.2  ad 	vp->v_data = NULL;
    897  1.24.10.2  ad 	return(0);
    898  1.24.10.2  ad }
    899  1.24.10.2  ad 
    900  1.24.10.2  ad /*
    901  1.24.10.2  ad  * POSIX pathconf info, grabbed from kern/u fs, probably need to
    902  1.24.10.2  ad  * investigate exactly what each return type means as they are probably
    903  1.24.10.2  ad  * not valid currently
    904  1.24.10.2  ad  */
    905  1.24.10.2  ad int
    906  1.24.10.2  ad adosfs_pathconf(v)
    907  1.24.10.2  ad 	void *v;
    908  1.24.10.2  ad {
    909  1.24.10.2  ad 	struct vop_pathconf_args /* {
    910  1.24.10.2  ad 		struct vnode *a_vp;
    911  1.24.10.2  ad 		int a_name;
    912  1.24.10.2  ad 		register_t *a_retval;
    913  1.24.10.2  ad 	} */ *ap = v;
    914  1.24.10.2  ad 
    915  1.24.10.2  ad 	switch (ap->a_name) {
    916  1.24.10.2  ad 	case _PC_LINK_MAX:
    917  1.24.10.2  ad 		*ap->a_retval = LINK_MAX;
    918  1.24.10.2  ad 		return (0);
    919  1.24.10.2  ad 	case _PC_NAME_MAX:
    920  1.24.10.2  ad 		*ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_namemax;
    921  1.24.10.2  ad 		return (0);
    922  1.24.10.2  ad 	case _PC_PATH_MAX:
    923  1.24.10.2  ad 		*ap->a_retval = PATH_MAX;
    924  1.24.10.2  ad 		return (0);
    925  1.24.10.2  ad 	case _PC_PIPE_BUF:
    926  1.24.10.2  ad 		*ap->a_retval = PIPE_BUF;
    927  1.24.10.2  ad 		return (0);
    928  1.24.10.2  ad 	case _PC_CHOWN_RESTRICTED:
    929  1.24.10.2  ad 		*ap->a_retval = 1;
    930  1.24.10.2  ad 		return (0);
    931  1.24.10.2  ad 	case _PC_VDISABLE:
    932  1.24.10.2  ad 		*ap->a_retval = _POSIX_VDISABLE;
    933  1.24.10.2  ad 		return (0);
    934  1.24.10.2  ad 	case _PC_SYNC_IO:
    935  1.24.10.2  ad 		*ap->a_retval = 1;
    936  1.24.10.2  ad 		return (0);
    937  1.24.10.2  ad 	case _PC_FILESIZEBITS:
    938  1.24.10.2  ad 		*ap->a_retval = 32;
    939  1.24.10.2  ad 		return (0);
    940  1.24.10.2  ad 	default:
    941  1.24.10.2  ad 		return (EINVAL);
    942  1.24.10.2  ad 	}
    943  1.24.10.2  ad 	/* NOTREACHED */
    944  1.24.10.2  ad }
    945