Home | History | Annotate | Line # | Download | only in adosfs
advfsops.c revision 1.73
      1  1.73      maxv /*	$NetBSD: advfsops.c,v 1.73 2015/03/28 19:24:05 maxv Exp $	*/
      2   1.1  jdolecek 
      3   1.1  jdolecek /*
      4   1.1  jdolecek  * Copyright (c) 1994 Christian E. Hopps
      5   1.1  jdolecek  * Copyright (c) 1996 Matthias Scheler
      6   1.1  jdolecek  * All rights reserved.
      7   1.1  jdolecek  *
      8   1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
      9   1.1  jdolecek  * modification, are permitted provided that the following conditions
     10   1.1  jdolecek  * are met:
     11   1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     12   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     13   1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     15   1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     16   1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     17   1.1  jdolecek  *    must display the following acknowledgement:
     18   1.1  jdolecek  *      This product includes software developed by Christian E. Hopps.
     19   1.1  jdolecek  * 4. The name of the author may not be used to endorse or promote products
     20   1.1  jdolecek  *    derived from this software without specific prior written permission
     21   1.1  jdolecek  *
     22   1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.1  jdolecek  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1  jdolecek  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1  jdolecek  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26   1.1  jdolecek  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27   1.1  jdolecek  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28   1.1  jdolecek  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29   1.1  jdolecek  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30   1.1  jdolecek  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31   1.1  jdolecek  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1  jdolecek  */
     33   1.1  jdolecek 
     34   1.1  jdolecek #include <sys/cdefs.h>
     35  1.73      maxv __KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.73 2015/03/28 19:24:05 maxv Exp $");
     36   1.1  jdolecek 
     37   1.1  jdolecek #if defined(_KERNEL_OPT)
     38   1.1  jdolecek #include "opt_compat_netbsd.h"
     39   1.1  jdolecek #endif
     40   1.1  jdolecek 
     41   1.1  jdolecek #include <sys/param.h>
     42   1.1  jdolecek #include <sys/systm.h>
     43   1.9    atatat #include <sys/sysctl.h>
     44   1.1  jdolecek #include <sys/vnode.h>
     45   1.1  jdolecek #include <sys/mount.h>
     46   1.1  jdolecek #include <sys/proc.h>
     47   1.1  jdolecek #include <sys/time.h>
     48   1.1  jdolecek #include <sys/malloc.h>
     49   1.1  jdolecek #include <sys/pool.h>
     50   1.1  jdolecek #include <sys/disklabel.h>
     51  1.65   mlelstv #include <sys/disk.h>
     52  1.48  dholland #include <miscfs/genfs/genfs.h>
     53   1.1  jdolecek #include <miscfs/specfs/specdev.h> /* XXX */
     54   1.1  jdolecek #include <sys/fcntl.h>
     55   1.1  jdolecek #include <sys/namei.h>
     56   1.1  jdolecek #include <sys/ioctl.h>
     57   1.1  jdolecek #include <sys/queue.h>
     58   1.1  jdolecek #include <sys/buf.h>
     59   1.1  jdolecek #include <sys/conf.h>
     60  1.28  christos #include <sys/kauth.h>
     61  1.51    rumble #include <sys/module.h>
     62   1.1  jdolecek #include <fs/adosfs/adosfs.h>
     63   1.1  jdolecek 
     64  1.51    rumble MODULE(MODULE_CLASS_VFS, adosfs, NULL);
     65  1.51    rumble 
     66  1.41     pooka VFS_PROTOS(adosfs);
     67   1.1  jdolecek 
     68  1.53    rumble static struct sysctllog *adosfs_sysctl_log;
     69  1.53    rumble 
     70  1.54       dsl int adosfs_mountfs(struct vnode *, struct mount *, struct lwp *);
     71  1.54       dsl int adosfs_loadbitmap(struct adosfsmount *);
     72   1.1  jdolecek 
     73  1.36     pooka struct pool adosfs_node_pool;
     74   1.2   thorpej 
     75  1.36     pooka MALLOC_JUSTDEFINE(M_ANODE, "adosfs anode","adosfs anode structures and tables");
     76   1.1  jdolecek 
     77  1.23      yamt static const struct genfs_ops adosfs_genfsops = {
     78  1.23      yamt 	.gop_size = genfs_size,
     79   1.1  jdolecek };
     80   1.1  jdolecek 
     81  1.54       dsl int (**adosfs_vnodeop_p)(void *);
     82   1.1  jdolecek 
     83   1.1  jdolecek int
     84  1.55       dsl adosfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
     85   1.1  jdolecek {
     86  1.44     pooka 	struct lwp *l = curlwp;
     87   1.1  jdolecek 	struct vnode *devvp;
     88  1.37       dsl 	struct adosfs_args *args = data;
     89   1.1  jdolecek 	struct adosfsmount *amp;
     90   1.1  jdolecek 	int error;
     91   1.1  jdolecek 	mode_t accessmode;
     92   1.1  jdolecek 
     93  1.70      maxv 	if (args == NULL)
     94  1.70      maxv 		return EINVAL;
     95  1.37       dsl 	if (*data_len < sizeof *args)
     96  1.37       dsl 		return EINVAL;
     97  1.37       dsl 
     98   1.1  jdolecek 	if (mp->mnt_flag & MNT_GETARGS) {
     99   1.1  jdolecek 		amp = VFSTOADOSFS(mp);
    100   1.1  jdolecek 		if (amp == NULL)
    101   1.1  jdolecek 			return EIO;
    102  1.37       dsl 		args->uid = amp->uid;
    103  1.37       dsl 		args->gid = amp->gid;
    104  1.37       dsl 		args->mask = amp->mask;
    105  1.37       dsl 		args->fspec = NULL;
    106  1.37       dsl 		*data_len = sizeof *args;
    107  1.37       dsl 		return 0;
    108   1.1  jdolecek 	}
    109  1.21     perry 
    110   1.1  jdolecek 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
    111   1.1  jdolecek 		return (EROFS);
    112  1.25      jmmv 
    113  1.37       dsl 	if ((mp->mnt_flag & MNT_UPDATE) && args->fspec == NULL)
    114  1.25      jmmv 		return EOPNOTSUPP;
    115  1.25      jmmv 
    116   1.1  jdolecek 	/*
    117   1.1  jdolecek 	 * Not an update, or updating the name: look up the name
    118   1.1  jdolecek 	 * and verify that it refers to a sensible block device.
    119   1.1  jdolecek 	 */
    120  1.58  dholland 	error = namei_simple_user(args->fspec,
    121  1.58  dholland 				NSM_FOLLOW_NOEMULROOT, &devvp);
    122  1.58  dholland 	if (error != 0)
    123   1.1  jdolecek 		return (error);
    124   1.1  jdolecek 
    125   1.1  jdolecek 	if (devvp->v_type != VBLK) {
    126   1.1  jdolecek 		vrele(devvp);
    127   1.1  jdolecek 		return (ENOTBLK);
    128   1.1  jdolecek 	}
    129   1.1  jdolecek 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    130   1.1  jdolecek 		vrele(devvp);
    131   1.1  jdolecek 		return (ENXIO);
    132   1.1  jdolecek 	}
    133   1.1  jdolecek 	/*
    134   1.1  jdolecek 	 * If mount by non-root, then verify that user has necessary
    135   1.1  jdolecek 	 * permissions on the device.
    136   1.1  jdolecek 	 */
    137  1.57      elad 	accessmode = VREAD;
    138  1.57      elad 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
    139  1.57      elad 		accessmode |= VWRITE;
    140  1.57      elad 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    141  1.64      elad 	error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
    142  1.64      elad 	    KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(accessmode));
    143  1.60   hannken 	VOP_UNLOCK(devvp);
    144  1.57      elad 	if (error) {
    145  1.57      elad 		vrele(devvp);
    146  1.57      elad 		return (error);
    147   1.1  jdolecek 	}
    148   1.1  jdolecek /* MNT_UPDATE? */
    149  1.26  christos 	if ((error = adosfs_mountfs(devvp, mp, l)) != 0) {
    150   1.1  jdolecek 		vrele(devvp);
    151   1.1  jdolecek 		return (error);
    152   1.1  jdolecek 	}
    153   1.1  jdolecek 	amp = VFSTOADOSFS(mp);
    154  1.37       dsl 	amp->uid = args->uid;
    155  1.37       dsl 	amp->gid = args->gid;
    156  1.37       dsl 	amp->mask = args->mask;
    157  1.37       dsl 	return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
    158  1.38     pooka 	    mp->mnt_op->vfs_name, mp, l);
    159   1.1  jdolecek }
    160   1.1  jdolecek 
    161   1.1  jdolecek int
    162  1.55       dsl adosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
    163   1.1  jdolecek {
    164   1.1  jdolecek 	struct disklabel dl;
    165   1.1  jdolecek 	struct partition *parp;
    166   1.1  jdolecek 	struct adosfsmount *amp;
    167   1.1  jdolecek 	struct buf *bp;
    168   1.1  jdolecek 	struct vnode *rvp;
    169  1.61     rmind 	size_t bitmap_sz = 0;
    170  1.71   hannken 	int error;
    171  1.65   mlelstv 	uint64_t numsecs;
    172  1.65   mlelstv 	unsigned secsize;
    173  1.65   mlelstv 	unsigned long secsperblk, blksperdisk, resvblks;
    174   1.1  jdolecek 
    175   1.1  jdolecek 	amp = NULL;
    176   1.1  jdolecek 
    177  1.47        ad 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0)
    178   1.1  jdolecek 		return (error);
    179   1.1  jdolecek 
    180  1.21     perry 	/*
    181  1.65   mlelstv 	 * open blkdev and read boot and root block
    182   1.1  jdolecek 	 */
    183  1.63   hannken 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    184  1.63   hannken 	if ((error = VOP_OPEN(devvp, FREAD, NOCRED)) != 0) {
    185  1.63   hannken 		VOP_UNLOCK(devvp);
    186   1.1  jdolecek 		return (error);
    187  1.63   hannken 	}
    188  1.65   mlelstv 
    189  1.65   mlelstv 	error = getdisksize(devvp, &numsecs, &secsize);
    190  1.65   mlelstv 	if (error)
    191  1.65   mlelstv 		goto fail;
    192  1.65   mlelstv 
    193  1.65   mlelstv 	amp = kmem_zalloc(sizeof(struct adosfsmount), KM_SLEEP);
    194  1.65   mlelstv 
    195  1.65   mlelstv 	/*
    196  1.65   mlelstv 	 * compute filesystem parameters from disklabel
    197  1.65   mlelstv 	 * on arch/amiga the disklabel is computed from the native
    198  1.65   mlelstv 	 * partition tables
    199  1.65   mlelstv 	 * - p_fsize is the filesystem block size
    200  1.65   mlelstv 	 * - p_frag is the number of sectors per filesystem block
    201  1.65   mlelstv 	 * - p_cpg is the number of reserved blocks (boot blocks)
    202  1.65   mlelstv 	 * - p_psize is reduced by the number of preallocated blocks
    203  1.65   mlelstv 	 *           at the end of a partition
    204  1.65   mlelstv 	 *
    205  1.65   mlelstv 	 * XXX
    206  1.65   mlelstv 	 * - bsize and secsperblk could be computed from the first sector
    207  1.65   mlelstv 	 *   of the root block
    208  1.65   mlelstv 	 * - resvblks (the number of boot blocks) can only be guessed
    209  1.65   mlelstv 	 *   by scanning for the root block as its position moves
    210  1.65   mlelstv 	 *   with resvblks
    211  1.65   mlelstv 	 */
    212  1.44     pooka 	error = VOP_IOCTL(devvp, DIOCGDINFO, &dl, FREAD, NOCRED);
    213  1.63   hannken 	VOP_UNLOCK(devvp);
    214   1.1  jdolecek 	if (error)
    215   1.1  jdolecek 		goto fail;
    216  1.65   mlelstv 	parp = &dl.d_partitions[DISKPART(devvp->v_rdev)];
    217  1.72  christos 	if (dl.d_type == DKTYPE_FLOPPY) {
    218  1.65   mlelstv 		amp->bsize = secsize;
    219  1.65   mlelstv 		secsperblk = 1;
    220  1.65   mlelstv 		resvblks   = 2;
    221  1.65   mlelstv 	} else if (parp->p_fsize > 0 && parp->p_frag > 0) {
    222   1.1  jdolecek 		amp->bsize = parp->p_fsize * parp->p_frag;
    223  1.65   mlelstv 		secsperblk = parp->p_frag;
    224  1.65   mlelstv 		resvblks   = parp->p_cpg;
    225  1.65   mlelstv 	} else {
    226   1.1  jdolecek 		error = EINVAL;
    227   1.1  jdolecek 		goto fail;
    228   1.1  jdolecek 	}
    229  1.65   mlelstv 	blksperdisk = numsecs / secsperblk;
    230   1.1  jdolecek 
    231  1.65   mlelstv 
    232  1.65   mlelstv 	/* The filesytem variant ('dostype') is stored in the boot block */
    233   1.1  jdolecek 	bp = NULL;
    234   1.1  jdolecek 	if ((error = bread(devvp, (daddr_t)BBOFF,
    235  1.73      maxv 			   amp->bsize, 0, &bp)) != 0) {
    236   1.1  jdolecek 		goto fail;
    237   1.1  jdolecek 	}
    238   1.1  jdolecek 	amp->dostype = adoswordn(bp, 0);
    239  1.42        ad 	brelse(bp, 0);
    240   1.1  jdolecek 
    241   1.1  jdolecek 	/* basic sanity checks */
    242   1.1  jdolecek 	if (amp->dostype < 0x444f5300 || amp->dostype > 0x444f5305) {
    243   1.1  jdolecek 		error = EINVAL;
    244   1.1  jdolecek 		goto fail;
    245   1.1  jdolecek 	}
    246   1.1  jdolecek 
    247  1.65   mlelstv 	amp->rootb = (blksperdisk - 1 + resvblks) / 2;
    248  1.65   mlelstv 	amp->numblks = blksperdisk - resvblks;
    249   1.1  jdolecek 
    250   1.1  jdolecek 	amp->nwords = amp->bsize >> 2;
    251   1.1  jdolecek 	amp->dbsize = amp->bsize - (IS_FFS(amp) ? 0 : OFS_DATA_OFFSET);
    252   1.1  jdolecek 	amp->devvp = devvp;
    253  1.21     perry 
    254  1.65   mlelstv 	amp->mp = mp;
    255   1.1  jdolecek 	mp->mnt_data = amp;
    256  1.18  jdolecek 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)devvp->v_rdev;
    257  1.18  jdolecek 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_ADOSFS);
    258  1.18  jdolecek 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    259  1.19     skrll 	mp->mnt_stat.f_namemax = ADMAXNAMELEN;
    260   1.1  jdolecek 	mp->mnt_fs_bshift = ffs(amp->bsize) - 1;
    261  1.65   mlelstv 	mp->mnt_dev_bshift = DEV_BSHIFT;
    262   1.1  jdolecek 	mp->mnt_flag |= MNT_LOCAL;
    263   1.1  jdolecek 
    264   1.1  jdolecek 	/*
    265   1.1  jdolecek 	 * get the root anode, if not a valid fs this will fail.
    266   1.1  jdolecek 	 */
    267   1.7   thorpej 	if ((error = VFS_ROOT(mp, &rvp)) != 0)
    268   1.1  jdolecek 		goto fail;
    269   1.1  jdolecek 	/* allocate and load bitmap, set free space */
    270  1.61     rmind 	bitmap_sz = ((amp->numblks + 31) / 32) * sizeof(*amp->bitmap);
    271  1.61     rmind 	amp->bitmap = kmem_alloc(bitmap_sz, KM_SLEEP);
    272   1.1  jdolecek 	if (amp->bitmap)
    273   1.1  jdolecek 		adosfs_loadbitmap(amp);
    274   1.1  jdolecek 	if (mp->mnt_flag & MNT_RDONLY && amp->bitmap) {
    275   1.1  jdolecek 		/*
    276   1.1  jdolecek 		 * Don't need the bitmap any more if it's read-only.
    277   1.1  jdolecek 		 */
    278  1.61     rmind 		kmem_free(amp->bitmap, bitmap_sz);
    279   1.1  jdolecek 		amp->bitmap = NULL;
    280   1.1  jdolecek 	}
    281   1.1  jdolecek 	vput(rvp);
    282   1.1  jdolecek 
    283   1.1  jdolecek 	return(0);
    284   1.1  jdolecek 
    285   1.1  jdolecek fail:
    286   1.1  jdolecek 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    287  1.44     pooka 	(void) VOP_CLOSE(devvp, FREAD, NOCRED);
    288  1.60   hannken 	VOP_UNLOCK(devvp);
    289   1.1  jdolecek 	if (amp && amp->bitmap)
    290  1.61     rmind 		kmem_free(amp->bitmap, bitmap_sz);
    291   1.1  jdolecek 	if (amp)
    292  1.61     rmind 		kmem_free(amp, sizeof(*amp));
    293   1.1  jdolecek 	return (error);
    294   1.1  jdolecek }
    295   1.1  jdolecek 
    296   1.1  jdolecek int
    297  1.55       dsl adosfs_start(struct mount *mp, int flags)
    298   1.1  jdolecek {
    299   1.1  jdolecek 
    300   1.1  jdolecek 	return (0);
    301   1.1  jdolecek }
    302   1.1  jdolecek 
    303   1.1  jdolecek int
    304  1.55       dsl adosfs_unmount(struct mount *mp, int mntflags)
    305   1.1  jdolecek {
    306   1.1  jdolecek 	struct adosfsmount *amp;
    307   1.1  jdolecek 	int error, flags;
    308   1.1  jdolecek 
    309   1.1  jdolecek 	flags = 0;
    310   1.1  jdolecek 	if (mntflags & MNT_FORCE)
    311   1.1  jdolecek 		flags |= FORCECLOSE;
    312   1.1  jdolecek 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    313   1.1  jdolecek 		return (error);
    314   1.1  jdolecek 	amp = VFSTOADOSFS(mp);
    315   1.1  jdolecek 	if (amp->devvp->v_type != VBAD)
    316  1.67   hannken 		spec_node_setmountedfs(amp->devvp, NULL);
    317   1.1  jdolecek 	vn_lock(amp->devvp, LK_EXCLUSIVE | LK_RETRY);
    318  1.44     pooka 	error = VOP_CLOSE(amp->devvp, FREAD, NOCRED);
    319   1.1  jdolecek 	vput(amp->devvp);
    320  1.61     rmind 	if (amp->bitmap) {
    321  1.61     rmind 		size_t bitmap_sz = ((amp->numblks + 31) / 32) *
    322  1.61     rmind 		    sizeof(*amp->bitmap);
    323  1.61     rmind 		kmem_free(amp->bitmap, bitmap_sz);
    324  1.61     rmind 	}
    325  1.61     rmind 	kmem_free(amp, sizeof(*amp));
    326   1.1  jdolecek 	mp->mnt_data = NULL;
    327   1.1  jdolecek 	mp->mnt_flag &= ~MNT_LOCAL;
    328   1.1  jdolecek 	return (error);
    329   1.1  jdolecek }
    330   1.1  jdolecek 
    331   1.1  jdolecek int
    332  1.55       dsl adosfs_root(struct mount *mp, struct vnode **vpp)
    333   1.1  jdolecek {
    334   1.1  jdolecek 	struct vnode *nvp;
    335   1.1  jdolecek 	int error;
    336   1.1  jdolecek 
    337   1.1  jdolecek 	if ((error = VFS_VGET(mp, (ino_t)VFSTOADOSFS(mp)->rootb, &nvp)) != 0)
    338   1.1  jdolecek 		return (error);
    339   1.1  jdolecek 	/* XXX verify it's a root block? */
    340   1.1  jdolecek 	*vpp = nvp;
    341   1.1  jdolecek 	return (0);
    342   1.1  jdolecek }
    343   1.1  jdolecek 
    344   1.1  jdolecek int
    345  1.55       dsl adosfs_statvfs(struct mount *mp, struct statvfs *sbp)
    346   1.1  jdolecek {
    347   1.1  jdolecek 	struct adosfsmount *amp;
    348   1.1  jdolecek 
    349   1.1  jdolecek 	amp = VFSTOADOSFS(mp);
    350   1.1  jdolecek 	sbp->f_bsize = amp->bsize;
    351  1.12  christos 	sbp->f_frsize = amp->bsize;
    352   1.1  jdolecek 	sbp->f_iosize = amp->dbsize;
    353   1.1  jdolecek 	sbp->f_blocks = amp->numblks;
    354   1.1  jdolecek 	sbp->f_bfree = amp->freeblks;
    355   1.1  jdolecek 	sbp->f_bavail = amp->freeblks;
    356  1.12  christos 	sbp->f_bresvd = 0;
    357   1.1  jdolecek 	sbp->f_files = 0;		/* who knows */
    358   1.1  jdolecek 	sbp->f_ffree = 0;		/* " " */
    359  1.12  christos 	sbp->f_favail = 0;		/* " " */
    360  1.12  christos 	sbp->f_fresvd = 0;
    361  1.12  christos 	copy_statvfs_info(sbp, mp);
    362   1.1  jdolecek 	return (0);
    363   1.1  jdolecek }
    364   1.1  jdolecek 
    365  1.21     perry /*
    366  1.71   hannken  * lookup an anode, if not found, create
    367  1.71   hannken  * return locked and referenced al la vget(vp, LK_EXCLUSIVE);
    368   1.1  jdolecek  */
    369   1.1  jdolecek int
    370  1.55       dsl adosfs_vget(struct mount *mp, ino_t an, struct vnode **vpp)
    371   1.1  jdolecek {
    372  1.71   hannken 	int error;
    373  1.71   hannken 
    374  1.71   hannken 	error = vcache_get(mp, &an, sizeof(an), vpp);
    375  1.71   hannken 	if (error)
    376  1.71   hannken 		return error;
    377  1.71   hannken 	error = vn_lock(*vpp, LK_EXCLUSIVE);
    378  1.71   hannken 	if (error) {
    379  1.71   hannken 		vrele(*vpp);
    380  1.71   hannken 		*vpp = NULL;
    381  1.71   hannken 		return error;
    382  1.71   hannken 	}
    383  1.71   hannken 	return 0;
    384  1.71   hannken }
    385  1.71   hannken 
    386  1.71   hannken /*
    387  1.71   hannken  * Initialize this vnode / anode pair.
    388  1.71   hannken  * Caller assures no other thread will try to load this inode.
    389  1.71   hannken  */
    390  1.71   hannken int
    391  1.71   hannken adosfs_loadvnode(struct mount *mp, struct vnode *vp,
    392  1.71   hannken     const void *key, size_t key_len, const void **new_key)
    393  1.71   hannken {
    394   1.1  jdolecek 	struct adosfsmount *amp;
    395   1.1  jdolecek 	struct anode *ap;
    396   1.1  jdolecek 	struct buf *bp;
    397  1.71   hannken 	ino_t an;
    398   1.1  jdolecek 	char *nam, *tmp;
    399   1.1  jdolecek 	int namlen, error;
    400   1.1  jdolecek 
    401  1.71   hannken 	KASSERT(key_len == sizeof(an));
    402  1.71   hannken 	memcpy(&an, key, key_len);
    403   1.1  jdolecek 	amp = VFSTOADOSFS(mp);
    404   1.1  jdolecek 
    405  1.71   hannken 	if ((error = bread(amp->devvp, an * amp->bsize / DEV_BSIZE,
    406  1.73      maxv 			   amp->bsize, 0, &bp)) != 0)
    407  1.71   hannken 		return error;
    408   1.1  jdolecek 
    409  1.71   hannken 	ap = pool_get(&adosfs_node_pool, PR_WAITOK);
    410   1.1  jdolecek 	memset(ap, 0, sizeof(struct anode));
    411   1.1  jdolecek 	ap->vp = vp;
    412   1.1  jdolecek 	ap->amp = amp;
    413   1.1  jdolecek 	ap->block = an;
    414   1.1  jdolecek 	ap->nwords = amp->nwords;
    415   1.1  jdolecek 
    416   1.1  jdolecek 	/*
    417   1.1  jdolecek 	 * get type and fill rest in based on that.
    418   1.1  jdolecek 	 */
    419   1.1  jdolecek 	switch (ap->type = adosfs_getblktype(amp, bp)) {
    420   1.1  jdolecek 	case AROOT:
    421   1.1  jdolecek 		vp->v_type = VDIR;
    422  1.43        ad 		vp->v_vflag |= VV_ROOT;
    423   1.1  jdolecek 		ap->mtimev.days = adoswordn(bp, ap->nwords - 10);
    424   1.1  jdolecek 		ap->mtimev.mins = adoswordn(bp, ap->nwords - 9);
    425   1.1  jdolecek 		ap->mtimev.ticks = adoswordn(bp, ap->nwords - 8);
    426   1.1  jdolecek 		ap->created.days = adoswordn(bp, ap->nwords - 7);
    427   1.1  jdolecek 		ap->created.mins = adoswordn(bp, ap->nwords - 6);
    428   1.1  jdolecek 		ap->created.ticks = adoswordn(bp, ap->nwords - 5);
    429   1.1  jdolecek 		break;
    430   1.1  jdolecek 	case ALDIR:
    431   1.1  jdolecek 	case ADIR:
    432   1.1  jdolecek 		vp->v_type = VDIR;
    433   1.1  jdolecek 		break;
    434   1.1  jdolecek 	case ALFILE:
    435   1.1  jdolecek 	case AFILE:
    436   1.1  jdolecek 		vp->v_type = VREG;
    437   1.1  jdolecek 		ap->fsize = adoswordn(bp, ap->nwords - 47);
    438   1.1  jdolecek 		break;
    439   1.1  jdolecek 	case ASLINK:		/* XXX soft link */
    440   1.1  jdolecek 		vp->v_type = VLNK;
    441   1.1  jdolecek 		/*
    442   1.1  jdolecek 		 * convert from BCPL string and
    443   1.1  jdolecek 		 * from: "part:dir/file" to: "/part/dir/file"
    444   1.1  jdolecek 		 */
    445  1.34      yamt 		nam = (char *)bp->b_data + (6 * sizeof(long));
    446   1.1  jdolecek 		namlen = strlen(nam);
    447   1.1  jdolecek 		tmp = nam;
    448   1.1  jdolecek 		while (*tmp && *tmp != ':')
    449   1.1  jdolecek 			tmp++;
    450   1.1  jdolecek 		if (*tmp == 0) {
    451   1.1  jdolecek 			ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
    452   1.1  jdolecek 			memcpy(ap->slinkto, nam, namlen);
    453   1.1  jdolecek 		} else if (*nam == ':') {
    454   1.1  jdolecek 			ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
    455   1.1  jdolecek 			memcpy(ap->slinkto, nam, namlen);
    456   1.1  jdolecek 			ap->slinkto[0] = '/';
    457   1.1  jdolecek 		} else {
    458   1.1  jdolecek 			ap->slinkto = malloc(namlen + 2, M_ANODE, M_WAITOK);
    459   1.1  jdolecek 			ap->slinkto[0] = '/';
    460   1.1  jdolecek 			memcpy(&ap->slinkto[1], nam, namlen);
    461   1.1  jdolecek 			ap->slinkto[tmp - nam + 1] = '/';
    462   1.1  jdolecek 			namlen++;
    463   1.1  jdolecek 		}
    464   1.1  jdolecek 		ap->slinkto[namlen] = 0;
    465   1.1  jdolecek 		ap->fsize = namlen;
    466   1.1  jdolecek 		break;
    467   1.1  jdolecek 	default:
    468  1.71   hannken 		error = EINVAL;
    469  1.71   hannken 		goto bad;
    470   1.1  jdolecek 	}
    471   1.1  jdolecek 
    472   1.1  jdolecek 	/*
    473   1.1  jdolecek 	 * Get appropriate data from this block;  hard link needs
    474   1.1  jdolecek 	 * to get other data from the "real" block.
    475   1.1  jdolecek 	 */
    476   1.1  jdolecek 
    477   1.1  jdolecek 	/*
    478   1.1  jdolecek 	 * copy in name (from original block)
    479   1.1  jdolecek 	 */
    480  1.34      yamt 	nam = (char *)bp->b_data + (ap->nwords - 20) * sizeof(u_int32_t);
    481   1.1  jdolecek 	namlen = *(u_char *)nam++;
    482   1.1  jdolecek 	if (namlen > 30) {
    483   1.1  jdolecek #ifdef DIAGNOSTIC
    484  1.24  christos 		printf("adosfs: aget: name length too long blk %llu\n",
    485  1.24  christos 		    (unsigned long long)an);
    486   1.1  jdolecek #endif
    487  1.71   hannken 		error = EINVAL;
    488  1.71   hannken 		goto bad;
    489   1.1  jdolecek 	}
    490   1.1  jdolecek 	memcpy(ap->name, nam, namlen);
    491   1.1  jdolecek 	ap->name[namlen] = 0;
    492   1.1  jdolecek 
    493  1.21     perry 	/*
    494  1.21     perry 	 * if dir alloc hash table and copy it in
    495   1.1  jdolecek 	 */
    496   1.1  jdolecek 	if (vp->v_type == VDIR) {
    497   1.1  jdolecek 		int i;
    498   1.1  jdolecek 
    499   1.1  jdolecek 		ap->tab = malloc(ANODETABSZ(ap) * 2, M_ANODE, M_WAITOK);
    500   1.1  jdolecek 		ap->ntabent = ANODETABENT(ap);
    501   1.1  jdolecek 		ap->tabi = (int *)&ap->tab[ap->ntabent];
    502   1.1  jdolecek 		memset(ap->tabi, 0, ANODETABSZ(ap));
    503   1.1  jdolecek 		for (i = 0; i < ap->ntabent; i++)
    504   1.1  jdolecek 			ap->tab[i] = adoswordn(bp, i + 6);
    505   1.1  jdolecek 	}
    506   1.1  jdolecek 
    507   1.1  jdolecek 	/*
    508   1.1  jdolecek 	 * misc.
    509   1.1  jdolecek 	 */
    510   1.1  jdolecek 	ap->pblock = adoswordn(bp, ap->nwords - 3);
    511   1.1  jdolecek 	ap->hashf = adoswordn(bp, ap->nwords - 4);
    512   1.1  jdolecek 	ap->linknext = adoswordn(bp, ap->nwords - 10);
    513   1.1  jdolecek 	ap->linkto = adoswordn(bp, ap->nwords - 11);
    514   1.1  jdolecek 
    515   1.1  jdolecek 	/*
    516   1.1  jdolecek 	 * setup last indirect block cache.
    517   1.1  jdolecek 	 */
    518   1.1  jdolecek 	ap->lastlindblk = 0;
    519   1.1  jdolecek 	if (ap->type == AFILE)  {
    520   1.1  jdolecek 		ap->lastindblk = ap->block;
    521   1.1  jdolecek 		if (adoswordn(bp, ap->nwords - 10))
    522   1.1  jdolecek 			ap->linkto = ap->block;
    523   1.1  jdolecek 	} else if (ap->type == ALFILE) {
    524   1.1  jdolecek 		ap->lastindblk = ap->linkto;
    525  1.42        ad 		brelse(bp, 0);
    526   1.1  jdolecek 		bp = NULL;
    527   1.1  jdolecek 		error = bread(amp->devvp, ap->linkto * amp->bsize / DEV_BSIZE,
    528  1.73      maxv 		    amp->bsize, 0, &bp);
    529  1.71   hannken 		if (error)
    530  1.71   hannken 			goto bad;
    531   1.1  jdolecek 		ap->fsize = adoswordn(bp, ap->nwords - 47);
    532   1.1  jdolecek 	}
    533   1.1  jdolecek 
    534   1.1  jdolecek 	if (ap->type == AROOT) {
    535   1.1  jdolecek 		ap->adprot = 15;
    536   1.1  jdolecek 		ap->uid = amp->uid;
    537   1.1  jdolecek 		ap->gid = amp->gid;
    538   1.1  jdolecek 	} else {
    539   1.1  jdolecek 		ap->adprot = adoswordn(bp, ap->nwords - 48) ^ 15;
    540   1.1  jdolecek 		/*
    541   1.1  jdolecek 		 * ADOS directories do not have a `x' protection bit as
    542   1.1  jdolecek 		 * it is known in VFS; this functionality is fulfilled
    543   1.1  jdolecek 		 * by the ADOS `r' bit.
    544   1.1  jdolecek 		 *
    545   1.1  jdolecek 		 * To retain the ADOS behaviour, fake execute permissions
    546   1.1  jdolecek 		 * in that case.
    547   1.1  jdolecek 		 */
    548   1.1  jdolecek 		if ((ap->type == ADIR || ap->type == ALDIR) &&
    549   1.1  jdolecek 		    (ap->adprot & 0x00000008) == 0)
    550   1.1  jdolecek 			ap->adprot &= ~0x00000002;
    551   1.1  jdolecek 
    552   1.1  jdolecek 		/*
    553   1.1  jdolecek 		 * Get uid/gid from extensions in file header
    554   1.1  jdolecek 		 * (really need to know if this is a muFS partition)
    555   1.1  jdolecek 		 */
    556   1.1  jdolecek 		ap->uid = (adoswordn(bp, ap->nwords - 49) >> 16) & 0xffff;
    557   1.1  jdolecek 		ap->gid = adoswordn(bp, ap->nwords - 49) & 0xffff;
    558   1.1  jdolecek 		if (ap->uid || ap->gid) {
    559   1.1  jdolecek 			if (ap->uid == 0xffff)
    560   1.1  jdolecek 				ap->uid = 0;
    561   1.1  jdolecek 			if (ap->gid == 0xffff)
    562   1.1  jdolecek 				ap->gid = 0;
    563   1.1  jdolecek 			ap->adprot |= 0x40000000;	/* Kludge */
    564   1.1  jdolecek 		}
    565   1.1  jdolecek 		else {
    566   1.1  jdolecek 			/*
    567   1.1  jdolecek 			 * uid & gid extension don't exist,
    568   1.1  jdolecek 			 * so use the mount-point uid/gid
    569   1.1  jdolecek 			 */
    570   1.1  jdolecek 			ap->uid = amp->uid;
    571   1.1  jdolecek 			ap->gid = amp->gid;
    572   1.1  jdolecek 		}
    573   1.1  jdolecek 	}
    574   1.1  jdolecek 	ap->mtime.days = adoswordn(bp, ap->nwords - 23);
    575   1.1  jdolecek 	ap->mtime.mins = adoswordn(bp, ap->nwords - 22);
    576   1.1  jdolecek 	ap->mtime.ticks = adoswordn(bp, ap->nwords - 21);
    577   1.1  jdolecek 
    578  1.42        ad 	brelse(bp, 0);
    579  1.71   hannken 	vp->v_tag = VT_ADOSFS;
    580  1.71   hannken 	vp->v_op = adosfs_vnodeop_p;
    581  1.71   hannken 	vp->v_data = ap;
    582  1.71   hannken 	genfs_node_init(vp, &adosfs_genfsops);
    583  1.39     pooka 	uvm_vnp_setsize(vp, ap->fsize);
    584  1.71   hannken 	*new_key = &ap->block;
    585  1.71   hannken 	return 0;
    586  1.71   hannken 
    587  1.71   hannken bad:
    588  1.71   hannken 	if (bp)
    589  1.71   hannken 		brelse(bp, 0);
    590  1.71   hannken 	pool_put(&adosfs_node_pool, ap);
    591  1.71   hannken 	return error;
    592   1.1  jdolecek }
    593   1.1  jdolecek 
    594   1.1  jdolecek /*
    595   1.1  jdolecek  * Load the bitmap into memory, and count the number of available
    596   1.1  jdolecek  * blocks.
    597   1.1  jdolecek  * The bitmap will be released if the filesystem is read-only;  it's
    598   1.1  jdolecek  * only needed to find the free space.
    599   1.1  jdolecek  */
    600   1.1  jdolecek int
    601  1.55       dsl adosfs_loadbitmap(struct adosfsmount *amp)
    602   1.1  jdolecek {
    603   1.1  jdolecek 	struct buf *bp, *mapbp;
    604   1.1  jdolecek 	u_long bn;
    605   1.1  jdolecek 	int blkix, endix, mapix;
    606   1.1  jdolecek 	int bmsize;
    607   1.1  jdolecek 	int error;
    608   1.1  jdolecek 
    609   1.1  jdolecek 	bp = mapbp = NULL;
    610   1.1  jdolecek 	bn = amp->rootb;
    611   1.1  jdolecek 	if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE, amp->bsize,
    612  1.73      maxv 	    0, &bp)) != 0) {
    613   1.1  jdolecek 		return (error);
    614   1.1  jdolecek 	}
    615   1.1  jdolecek 	blkix = amp->nwords - 49;
    616   1.1  jdolecek 	endix = amp->nwords - 24;
    617   1.1  jdolecek 	mapix = 0;
    618   1.1  jdolecek 	bmsize = (amp->numblks + 31) / 32;
    619   1.1  jdolecek 	while (mapix < bmsize) {
    620   1.1  jdolecek 		int n;
    621   1.1  jdolecek 		u_long bits;
    622   1.1  jdolecek 
    623   1.1  jdolecek 		if (adoswordn(bp, blkix) == 0)
    624   1.1  jdolecek 			break;
    625   1.1  jdolecek 		if (mapbp != NULL)
    626  1.42        ad 			brelse(mapbp, 0);
    627   1.1  jdolecek 		if ((error = bread(amp->devvp,
    628   1.1  jdolecek 		    adoswordn(bp, blkix) * amp->bsize / DEV_BSIZE, amp->bsize,
    629  1.73      maxv 		     0, &mapbp)) != 0)
    630   1.1  jdolecek 			break;
    631   1.1  jdolecek 		if (adoscksum(mapbp, amp->nwords)) {
    632   1.1  jdolecek #ifdef DIAGNOSTIC
    633   1.1  jdolecek 			printf("adosfs: loadbitmap - cksum of blk %d failed\n",
    634   1.1  jdolecek 			    adoswordn(bp, blkix));
    635   1.1  jdolecek #endif
    636   1.1  jdolecek 			/* XXX Force read-only?  Set free space 0? */
    637   1.1  jdolecek 			break;
    638   1.1  jdolecek 		}
    639   1.1  jdolecek 		n = 1;
    640   1.1  jdolecek 		while (n < amp->nwords && mapix < bmsize) {
    641   1.1  jdolecek 			amp->bitmap[mapix++] = bits = adoswordn(mapbp, n);
    642   1.1  jdolecek 			++n;
    643   1.1  jdolecek 			if (mapix == bmsize && amp->numblks & 31)
    644   1.1  jdolecek 				bits &= ~(0xffffffff << (amp->numblks & 31));
    645   1.1  jdolecek 			while (bits) {
    646   1.1  jdolecek 				if (bits & 1)
    647   1.1  jdolecek 					++amp->freeblks;
    648   1.1  jdolecek 				bits >>= 1;
    649   1.1  jdolecek 			}
    650   1.1  jdolecek 		}
    651   1.1  jdolecek 		++blkix;
    652   1.1  jdolecek 		if (mapix < bmsize && blkix == endix) {
    653   1.1  jdolecek 			bn = adoswordn(bp, blkix);
    654  1.42        ad 			brelse(bp, 0);
    655   1.1  jdolecek 			if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE,
    656  1.73      maxv 			    amp->bsize, 0, &bp)) != 0)
    657   1.1  jdolecek 				break;
    658   1.1  jdolecek 			/*
    659   1.1  jdolecek 			 * Why is there no checksum on these blocks?
    660   1.1  jdolecek 			 */
    661   1.1  jdolecek 			blkix = 0;
    662   1.1  jdolecek 			endix = amp->nwords - 1;
    663   1.1  jdolecek 		}
    664   1.1  jdolecek 	}
    665   1.1  jdolecek 	if (bp)
    666  1.42        ad 		brelse(bp, 0);
    667   1.1  jdolecek 	if (mapbp)
    668  1.42        ad 		brelse(mapbp, 0);
    669   1.1  jdolecek 	return (error);
    670   1.1  jdolecek }
    671   1.1  jdolecek 
    672   1.1  jdolecek 
    673   1.1  jdolecek /*
    674   1.1  jdolecek  * File handle to vnode
    675   1.1  jdolecek  *
    676   1.1  jdolecek  * Have to be really careful about stale file handles:
    677   1.1  jdolecek  * - check that the inode number is in range
    678   1.1  jdolecek  * - call iget() to get the locked inode
    679   1.1  jdolecek  * - check for an unallocated inode (i_mode == 0)
    680   1.1  jdolecek  * - check that the generation number matches
    681   1.1  jdolecek  */
    682   1.1  jdolecek 
    683   1.1  jdolecek struct ifid {
    684   1.1  jdolecek 	ushort	ifid_len;
    685   1.1  jdolecek 	ushort	ifid_pad;
    686   1.1  jdolecek 	int	ifid_ino;
    687   1.1  jdolecek 	long	ifid_start;
    688   1.1  jdolecek };
    689   1.1  jdolecek 
    690   1.1  jdolecek int
    691  1.55       dsl adosfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    692   1.1  jdolecek {
    693  1.29    martin 	struct ifid ifh;
    694   1.1  jdolecek #if 0
    695   1.1  jdolecek 	struct anode *ap;
    696   1.1  jdolecek #endif
    697   1.1  jdolecek 	struct vnode *nvp;
    698   1.1  jdolecek 	int error;
    699   1.1  jdolecek 
    700  1.29    martin 	if (fhp->fid_len != sizeof(struct ifid))
    701  1.29    martin 		return EINVAL;
    702  1.29    martin 
    703   1.1  jdolecek #ifdef ADOSFS_DIAGNOSTIC
    704  1.59       phx 	printf("adfhtovp(%p, %p, %p)\n", mp, fhp, vpp);
    705   1.1  jdolecek #endif
    706  1.21     perry 
    707  1.29    martin 	memcpy(&ifh, fhp, sizeof(ifh));
    708  1.29    martin 
    709  1.29    martin 	if ((error = VFS_VGET(mp, ifh.ifid_ino, &nvp)) != 0) {
    710   1.1  jdolecek 		*vpp = NULLVP;
    711   1.1  jdolecek 		return (error);
    712   1.1  jdolecek 	}
    713   1.1  jdolecek #if 0
    714   1.1  jdolecek 	ap = VTOA(nvp);
    715   1.1  jdolecek 	if (ap->inode.iso_mode == 0) {
    716   1.1  jdolecek 		vput(nvp);
    717   1.1  jdolecek 		*vpp = NULLVP;
    718   1.1  jdolecek 		return (ESTALE);
    719   1.1  jdolecek 	}
    720   1.1  jdolecek #endif
    721   1.1  jdolecek 	*vpp = nvp;
    722   1.1  jdolecek 	return(0);
    723   1.1  jdolecek }
    724   1.1  jdolecek 
    725   1.1  jdolecek int
    726  1.55       dsl adosfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
    727   1.1  jdolecek {
    728   1.1  jdolecek 	struct anode *ap = VTOA(vp);
    729  1.29    martin 	struct ifid ifh;
    730  1.21     perry 
    731  1.29    martin 	if (*fh_size < sizeof(struct ifid)) {
    732  1.29    martin 		*fh_size = sizeof(struct ifid);
    733  1.29    martin 		return E2BIG;
    734  1.29    martin 	}
    735  1.29    martin 	*fh_size = sizeof(struct ifid);
    736  1.29    martin 
    737  1.29    martin 	memset(&ifh, 0, sizeof(ifh));
    738  1.29    martin 	ifh.ifid_len = sizeof(struct ifid);
    739  1.29    martin 	ifh.ifid_ino = ap->block;
    740  1.29    martin 	ifh.ifid_start = ap->block;
    741  1.29    martin 	memcpy(fhp, &ifh, sizeof(ifh));
    742  1.21     perry 
    743   1.1  jdolecek #ifdef ADOSFS_DIAGNOSTIC
    744  1.59       phx 	printf("advptofh(%p, %p)\n", vp, fhp);
    745   1.1  jdolecek #endif
    746   1.1  jdolecek 	return(0);
    747   1.1  jdolecek }
    748   1.1  jdolecek 
    749   1.1  jdolecek int
    750  1.55       dsl adosfs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
    751   1.1  jdolecek {
    752   1.1  jdolecek #ifdef ADOSFS_DIAGNOSTIC
    753  1.59       phx 	printf("ad_sync(%p, %d)\n", mp, waitfor);
    754   1.1  jdolecek #endif
    755   1.1  jdolecek 	return(0);
    756   1.1  jdolecek }
    757   1.1  jdolecek 
    758   1.1  jdolecek void
    759  1.56    cegger adosfs_init(void)
    760   1.1  jdolecek {
    761  1.36     pooka 
    762  1.11    atatat 	malloc_type_attach(M_ANODE);
    763  1.15    atatat 	pool_init(&adosfs_node_pool, sizeof(struct anode), 0, 0, 0, "adosndpl",
    764  1.35        ad 	    &pool_allocator_nointr, IPL_NONE);
    765   1.1  jdolecek }
    766   1.1  jdolecek 
    767   1.1  jdolecek void
    768  1.56    cegger adosfs_done(void)
    769   1.1  jdolecek {
    770  1.36     pooka 
    771   1.1  jdolecek 	pool_destroy(&adosfs_node_pool);
    772  1.11    atatat 	malloc_type_detach(M_ANODE);
    773   1.1  jdolecek }
    774   1.1  jdolecek 
    775   1.1  jdolecek /*
    776   1.1  jdolecek  * vfs generic function call table
    777   1.1  jdolecek  */
    778   1.1  jdolecek 
    779  1.21     perry extern const struct vnodeopv_desc adosfs_vnodeop_opv_desc;
    780   1.1  jdolecek 
    781   1.1  jdolecek const struct vnodeopv_desc *adosfs_vnodeopv_descs[] = {
    782   1.1  jdolecek 	&adosfs_vnodeop_opv_desc,
    783   1.1  jdolecek 	NULL,
    784   1.1  jdolecek };
    785   1.1  jdolecek 
    786   1.1  jdolecek struct vfsops adosfs_vfsops = {
    787  1.69   hannken 	.vfs_name = MOUNT_ADOSFS,
    788  1.69   hannken 	.vfs_min_mount_data = sizeof (struct adosfs_args),
    789  1.69   hannken 	.vfs_mount = adosfs_mount,
    790  1.69   hannken 	.vfs_start = adosfs_start,
    791  1.69   hannken 	.vfs_unmount = adosfs_unmount,
    792  1.69   hannken 	.vfs_root = adosfs_root,
    793  1.69   hannken 	.vfs_quotactl = (void *)eopnotsupp,
    794  1.69   hannken 	.vfs_statvfs = adosfs_statvfs,
    795  1.69   hannken 	.vfs_sync = adosfs_sync,
    796  1.69   hannken 	.vfs_vget = adosfs_vget,
    797  1.71   hannken 	.vfs_loadvnode = adosfs_loadvnode,
    798  1.69   hannken 	.vfs_fhtovp = adosfs_fhtovp,
    799  1.69   hannken 	.vfs_vptofh = adosfs_vptofh,
    800  1.69   hannken 	.vfs_init = adosfs_init,
    801  1.69   hannken 	.vfs_done = adosfs_done,
    802  1.69   hannken 	.vfs_snapshot = (void *)eopnotsupp,
    803  1.69   hannken 	.vfs_extattrctl = vfs_stdextattrctl,
    804  1.69   hannken 	.vfs_suspendctl = (void *)eopnotsupp,
    805  1.69   hannken 	.vfs_renamelock_enter = genfs_renamelock_enter,
    806  1.69   hannken 	.vfs_renamelock_exit = genfs_renamelock_exit,
    807  1.69   hannken 	.vfs_fsync = (void *)eopnotsupp,
    808  1.69   hannken 	.vfs_opv_descs = adosfs_vnodeopv_descs
    809   1.1  jdolecek };
    810  1.51    rumble 
    811  1.51    rumble static int
    812  1.51    rumble adosfs_modcmd(modcmd_t cmd, void *arg)
    813  1.51    rumble {
    814  1.53    rumble 	int error;
    815  1.51    rumble 
    816  1.51    rumble 	switch (cmd) {
    817  1.51    rumble 	case MODULE_CMD_INIT:
    818  1.53    rumble 		error = vfs_attach(&adosfs_vfsops);
    819  1.53    rumble 		if (error != 0)
    820  1.53    rumble 			break;
    821  1.53    rumble 		sysctl_createv(&adosfs_sysctl_log, 0, NULL, NULL,
    822  1.53    rumble 			       CTLFLAG_PERMANENT,
    823  1.53    rumble 			       CTLTYPE_NODE, "adosfs",
    824  1.53    rumble 			       SYSCTL_DESCR("AmigaDOS file system"),
    825  1.53    rumble 			       NULL, 0, NULL, 0,
    826  1.53    rumble 			       CTL_VFS, 16, CTL_EOL);
    827  1.53    rumble 		/*
    828  1.53    rumble 		 * XXX the "16" above could be dynamic, thereby eliminating
    829  1.53    rumble 		 * one more instance of the "number to vfs" mapping problem,
    830  1.53    rumble 		 * but "16" is the order as taken from sys/mount.h
    831  1.53    rumble 		 */
    832  1.53    rumble 		break;
    833  1.51    rumble 	case MODULE_CMD_FINI:
    834  1.53    rumble 		error = vfs_detach(&adosfs_vfsops);
    835  1.53    rumble 		if (error != 0)
    836  1.53    rumble 			break;
    837  1.53    rumble 		sysctl_teardown(&adosfs_sysctl_log);
    838  1.53    rumble 		break;
    839  1.51    rumble 	default:
    840  1.53    rumble 		error = ENOTTY;
    841  1.53    rumble 		break;
    842  1.51    rumble 	}
    843  1.53    rumble 
    844  1.53    rumble 	return (error);
    845  1.51    rumble }
    846