Home | History | Annotate | Line # | Download | only in ntfs
ntfs_vfsops.c revision 1.10.2.10
      1  1.10.2.10     skrll /*	$NetBSD: ntfs_vfsops.c,v 1.10.2.10 2005/11/10 14:09:27 skrll Exp $	*/
      2        1.1  jdolecek 
      3        1.1  jdolecek /*-
      4        1.1  jdolecek  * Copyright (c) 1998, 1999 Semen Ustimenko
      5        1.1  jdolecek  * All rights reserved.
      6        1.1  jdolecek  *
      7        1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
      8        1.1  jdolecek  * modification, are permitted provided that the following conditions
      9        1.1  jdolecek  * are met:
     10        1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     11        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     12        1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     15        1.1  jdolecek  *
     16        1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17        1.1  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18        1.1  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19        1.1  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20        1.1  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21        1.1  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22        1.1  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23        1.1  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24        1.1  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25        1.1  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26        1.1  jdolecek  * SUCH DAMAGE.
     27        1.1  jdolecek  *
     28        1.1  jdolecek  *	Id: ntfs_vfsops.c,v 1.7 1999/05/31 11:28:30 phk Exp
     29        1.1  jdolecek  */
     30        1.1  jdolecek 
     31        1.1  jdolecek #include <sys/cdefs.h>
     32  1.10.2.10     skrll __KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.10.2.10 2005/11/10 14:09:27 skrll Exp $");
     33        1.1  jdolecek 
     34        1.1  jdolecek #include <sys/param.h>
     35        1.1  jdolecek #include <sys/systm.h>
     36        1.1  jdolecek #include <sys/namei.h>
     37        1.1  jdolecek #include <sys/proc.h>
     38        1.1  jdolecek #include <sys/kernel.h>
     39        1.1  jdolecek #include <sys/vnode.h>
     40        1.1  jdolecek #include <sys/mount.h>
     41        1.1  jdolecek #include <sys/buf.h>
     42        1.1  jdolecek #include <sys/fcntl.h>
     43        1.1  jdolecek #include <sys/malloc.h>
     44   1.10.2.2     skrll #include <sys/sysctl.h>
     45        1.1  jdolecek #include <sys/device.h>
     46        1.1  jdolecek #include <sys/conf.h>
     47        1.1  jdolecek 
     48        1.1  jdolecek #if defined(__NetBSD__)
     49        1.1  jdolecek #include <uvm/uvm_extern.h>
     50        1.1  jdolecek #else
     51        1.1  jdolecek #include <vm/vm.h>
     52        1.1  jdolecek #endif
     53        1.1  jdolecek 
     54        1.1  jdolecek #include <miscfs/specfs/specdev.h>
     55        1.1  jdolecek 
     56        1.1  jdolecek #include <fs/ntfs/ntfs.h>
     57        1.1  jdolecek #include <fs/ntfs/ntfs_inode.h>
     58        1.1  jdolecek #include <fs/ntfs/ntfs_subr.h>
     59        1.1  jdolecek #include <fs/ntfs/ntfs_vfsops.h>
     60        1.1  jdolecek #include <fs/ntfs/ntfs_ihash.h>
     61        1.1  jdolecek #include <fs/ntfs/ntfsmount.h>
     62        1.1  jdolecek 
     63        1.1  jdolecek MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
     64        1.1  jdolecek MALLOC_DEFINE(M_NTFSNTNODE,"NTFS ntnode",  "NTFS ntnode information");
     65        1.1  jdolecek MALLOC_DEFINE(M_NTFSFNODE,"NTFS fnode",  "NTFS fnode information");
     66        1.1  jdolecek MALLOC_DEFINE(M_NTFSDIR,"NTFS dir",  "NTFS dir buffer");
     67        1.1  jdolecek 
     68        1.1  jdolecek #if defined(__FreeBSD__)
     69  1.10.2.10     skrll static int	ntfs_mount(struct mount *, char *, caddr_t,
     70  1.10.2.10     skrll 				struct nameidata *, struct proc *);
     71        1.1  jdolecek #else
     72  1.10.2.10     skrll static int	ntfs_mount(struct mount *, const char *, void *,
     73  1.10.2.10     skrll 				struct nameidata *, struct lwp *);
     74        1.1  jdolecek #endif
     75  1.10.2.10     skrll static int	ntfs_quotactl(struct mount *, int, uid_t, void *,
     76  1.10.2.10     skrll 				   struct lwp *);
     77  1.10.2.10     skrll static int	ntfs_root(struct mount *, struct vnode **);
     78  1.10.2.10     skrll static int	ntfs_start(struct mount *, int, struct lwp *);
     79  1.10.2.10     skrll static int	ntfs_statvfs(struct mount *, struct statvfs *,
     80  1.10.2.10     skrll 				 struct lwp *);
     81  1.10.2.10     skrll static int	ntfs_sync(struct mount *, int, struct ucred *,
     82  1.10.2.10     skrll 			       struct lwp *);
     83  1.10.2.10     skrll static int	ntfs_unmount(struct mount *, int, struct lwp *);
     84  1.10.2.10     skrll static int	ntfs_vget(struct mount *mp, ino_t ino,
     85  1.10.2.10     skrll 			       struct vnode **vpp);
     86  1.10.2.10     skrll static int	ntfs_mountfs(struct vnode *, struct mount *,
     87  1.10.2.10     skrll 				  struct ntfs_args *, struct lwp *);
     88  1.10.2.10     skrll static int	ntfs_vptofh(struct vnode *, struct fid *);
     89        1.1  jdolecek 
     90        1.1  jdolecek #if defined(__FreeBSD__)
     91  1.10.2.10     skrll static int	ntfs_init(struct vfsconf *);
     92  1.10.2.10     skrll static int	ntfs_fhtovp(struct mount *, struct fid *,
     93        1.1  jdolecek 				 struct sockaddr *, struct vnode **,
     94  1.10.2.10     skrll 				 int *, struct ucred **);
     95        1.1  jdolecek #elif defined(__NetBSD__)
     96  1.10.2.10     skrll static void	ntfs_init(void);
     97  1.10.2.10     skrll static void	ntfs_reinit(void);
     98  1.10.2.10     skrll static void	ntfs_done(void);
     99  1.10.2.10     skrll static int	ntfs_fhtovp(struct mount *, struct fid *,
    100  1.10.2.10     skrll 				 struct vnode **);
    101  1.10.2.10     skrll static int	ntfs_mountroot(void);
    102        1.1  jdolecek #else
    103  1.10.2.10     skrll static int	ntfs_init(void);
    104  1.10.2.10     skrll static int	ntfs_fhtovp(struct mount *, struct fid *,
    105        1.1  jdolecek 				 struct mbuf *, struct vnode **,
    106  1.10.2.10     skrll 				 int *, struct ucred **);
    107        1.1  jdolecek #endif
    108        1.1  jdolecek 
    109  1.10.2.10     skrll static const struct genfs_ops ntfs_genfsops = {
    110  1.10.2.10     skrll 	.gop_write = genfs_compat_gop_write,
    111        1.1  jdolecek };
    112        1.1  jdolecek 
    113        1.1  jdolecek #ifdef __NetBSD__
    114        1.1  jdolecek 
    115   1.10.2.2     skrll SYSCTL_SETUP(sysctl_vfs_ntfs_setup, "sysctl vfs.ntfs subtree setup")
    116        1.1  jdolecek {
    117   1.10.2.2     skrll 
    118   1.10.2.2     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    119   1.10.2.2     skrll 		       CTLFLAG_PERMANENT,
    120   1.10.2.2     skrll 		       CTLTYPE_NODE, "vfs", NULL,
    121   1.10.2.2     skrll 		       NULL, 0, NULL, 0,
    122   1.10.2.2     skrll 		       CTL_VFS, CTL_EOL);
    123   1.10.2.2     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    124   1.10.2.2     skrll 		       CTLFLAG_PERMANENT,
    125   1.10.2.2     skrll 		       CTLTYPE_NODE, "ntfs",
    126   1.10.2.2     skrll 		       SYSCTL_DESCR("NTFS file system"),
    127   1.10.2.2     skrll 		       NULL, 0, NULL, 0,
    128   1.10.2.2     skrll 		       CTL_VFS, 20, CTL_EOL);
    129   1.10.2.2     skrll 	/*
    130   1.10.2.2     skrll 	 * XXX the "20" above could be dynamic, thereby eliminating
    131   1.10.2.2     skrll 	 * one more instance of the "number to vfs" mapping problem,
    132   1.10.2.2     skrll 	 * but "20" is the order as taken from sys/mount.h
    133   1.10.2.2     skrll 	 */
    134        1.1  jdolecek }
    135        1.1  jdolecek 
    136        1.1  jdolecek static int
    137        1.1  jdolecek ntfs_mountroot()
    138        1.1  jdolecek {
    139        1.1  jdolecek 	struct mount *mp;
    140   1.10.2.6     skrll 	struct lwp *l = curlwp;	/* XXX */
    141        1.1  jdolecek 	int error;
    142        1.1  jdolecek 	struct ntfs_args args;
    143        1.1  jdolecek 
    144        1.1  jdolecek 	if (root_device->dv_class != DV_DISK)
    145        1.1  jdolecek 		return (ENODEV);
    146        1.1  jdolecek 
    147        1.1  jdolecek 	if ((error = vfs_rootmountalloc(MOUNT_NTFS, "root_device", &mp))) {
    148        1.1  jdolecek 		vrele(rootvp);
    149        1.1  jdolecek 		return (error);
    150        1.1  jdolecek 	}
    151        1.1  jdolecek 
    152        1.1  jdolecek 	args.flag = 0;
    153        1.1  jdolecek 	args.uid = 0;
    154        1.1  jdolecek 	args.gid = 0;
    155        1.1  jdolecek 	args.mode = 0777;
    156        1.1  jdolecek 
    157   1.10.2.6     skrll 	if ((error = ntfs_mountfs(rootvp, mp, &args, l)) != 0) {
    158        1.1  jdolecek 		mp->mnt_op->vfs_refcount--;
    159        1.1  jdolecek 		vfs_unbusy(mp);
    160        1.1  jdolecek 		free(mp, M_MOUNT);
    161        1.1  jdolecek 		return (error);
    162        1.1  jdolecek 	}
    163        1.1  jdolecek 
    164        1.1  jdolecek 	simple_lock(&mountlist_slock);
    165        1.1  jdolecek 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    166        1.1  jdolecek 	simple_unlock(&mountlist_slock);
    167   1.10.2.6     skrll 	(void)ntfs_statvfs(mp, &mp->mnt_stat, l);
    168        1.1  jdolecek 	vfs_unbusy(mp);
    169        1.1  jdolecek 	return (0);
    170        1.1  jdolecek }
    171        1.1  jdolecek 
    172        1.1  jdolecek static void
    173        1.1  jdolecek ntfs_init()
    174        1.1  jdolecek {
    175        1.5  christos #ifdef _LKM
    176        1.5  christos 	malloc_type_attach(M_NTFSMNT);
    177        1.5  christos 	malloc_type_attach(M_NTFSNTNODE);
    178        1.5  christos 	malloc_type_attach(M_NTFSFNODE);
    179        1.5  christos 	malloc_type_attach(M_NTFSDIR);
    180        1.5  christos 	malloc_type_attach(M_NTFSNTHASH);
    181        1.6  christos 	malloc_type_attach(M_NTFSNTVATTR);
    182        1.7  christos 	malloc_type_attach(M_NTFSRDATA);
    183        1.7  christos 	malloc_type_attach(M_NTFSDECOMP);
    184        1.7  christos 	malloc_type_attach(M_NTFSRUN);
    185        1.5  christos #endif
    186        1.1  jdolecek 	ntfs_nthashinit();
    187        1.1  jdolecek 	ntfs_toupper_init();
    188        1.1  jdolecek }
    189        1.1  jdolecek 
    190        1.1  jdolecek static void
    191        1.1  jdolecek ntfs_reinit()
    192        1.1  jdolecek {
    193        1.1  jdolecek 	ntfs_nthashreinit();
    194        1.1  jdolecek }
    195        1.1  jdolecek 
    196        1.1  jdolecek static void
    197        1.1  jdolecek ntfs_done()
    198        1.1  jdolecek {
    199        1.1  jdolecek 	ntfs_nthashdone();
    200        1.5  christos #ifdef _LKM
    201        1.5  christos 	malloc_type_detach(M_NTFSMNT);
    202        1.5  christos 	malloc_type_detach(M_NTFSNTNODE);
    203        1.5  christos 	malloc_type_detach(M_NTFSFNODE);
    204        1.5  christos 	malloc_type_detach(M_NTFSDIR);
    205        1.5  christos 	malloc_type_detach(M_NTFSNTHASH);
    206        1.6  christos 	malloc_type_detach(M_NTFSNTVATTR);
    207        1.7  christos 	malloc_type_detach(M_NTFSRDATA);
    208        1.7  christos 	malloc_type_detach(M_NTFSDECOMP);
    209        1.7  christos 	malloc_type_detach(M_NTFSRUN);
    210        1.5  christos #endif
    211        1.1  jdolecek }
    212        1.1  jdolecek 
    213        1.1  jdolecek #elif defined(__FreeBSD__)
    214        1.1  jdolecek 
    215        1.1  jdolecek static int
    216        1.1  jdolecek ntfs_init (
    217        1.1  jdolecek 	struct vfsconf *vcp )
    218        1.1  jdolecek {
    219        1.1  jdolecek 	ntfs_nthashinit();
    220        1.1  jdolecek 	ntfs_toupper_init();
    221        1.1  jdolecek 	return 0;
    222        1.1  jdolecek }
    223        1.1  jdolecek 
    224        1.1  jdolecek #endif /* NetBSD */
    225        1.1  jdolecek 
    226        1.1  jdolecek static int
    227   1.10.2.8     skrll ntfs_mount (
    228        1.1  jdolecek 	struct mount *mp,
    229        1.1  jdolecek #if defined(__FreeBSD__)
    230        1.1  jdolecek 	char *path,
    231        1.1  jdolecek 	caddr_t data,
    232        1.1  jdolecek #else
    233        1.1  jdolecek 	const char *path,
    234        1.1  jdolecek 	void *data,
    235        1.1  jdolecek #endif
    236        1.1  jdolecek 	struct nameidata *ndp,
    237   1.10.2.6     skrll #if defined(__FreeBSD__)
    238        1.1  jdolecek 	struct proc *p )
    239   1.10.2.6     skrll #else
    240   1.10.2.6     skrll 	struct lwp *l )
    241   1.10.2.6     skrll #endif
    242        1.1  jdolecek {
    243   1.10.2.7     skrll 	int		err = 0, flags;
    244        1.1  jdolecek 	struct vnode	*devvp;
    245        1.1  jdolecek 	struct ntfs_args args;
    246        1.1  jdolecek 
    247        1.1  jdolecek 	if (mp->mnt_flag & MNT_GETARGS) {
    248        1.1  jdolecek 		struct ntfsmount *ntmp = VFSTONTFS(mp);
    249        1.1  jdolecek 		if (ntmp == NULL)
    250        1.1  jdolecek 			return EIO;
    251        1.1  jdolecek 		args.fspec = NULL;
    252        1.1  jdolecek 		args.uid = ntmp->ntm_uid;
    253        1.1  jdolecek 		args.gid = ntmp->ntm_gid;
    254        1.1  jdolecek 		args.mode = ntmp->ntm_mode;
    255        1.1  jdolecek 		args.flag = ntmp->ntm_flag;
    256        1.1  jdolecek 		return copyout(&args, data, sizeof(args));
    257        1.1  jdolecek 	}
    258        1.1  jdolecek 	/*
    259        1.1  jdolecek 	 ***
    260        1.1  jdolecek 	 * Mounting non-root file system or updating a file system
    261        1.1  jdolecek 	 ***
    262        1.1  jdolecek 	 */
    263        1.1  jdolecek 
    264        1.1  jdolecek 	/* copy in user arguments*/
    265   1.10.2.2     skrll 	err = copyin(data, &args, sizeof (struct ntfs_args));
    266        1.1  jdolecek 	if (err)
    267   1.10.2.7     skrll 		return (err);		/* can't get arguments*/
    268        1.1  jdolecek 
    269        1.1  jdolecek 	/*
    270        1.1  jdolecek 	 * If updating, check whether changing from read-only to
    271        1.1  jdolecek 	 * read/write; if there is no device name, that's all we do.
    272        1.1  jdolecek 	 */
    273        1.1  jdolecek 	if (mp->mnt_flag & MNT_UPDATE) {
    274        1.1  jdolecek 		printf("ntfs_mount(): MNT_UPDATE not supported\n");
    275   1.10.2.7     skrll 		return (EINVAL);
    276        1.1  jdolecek 	}
    277        1.1  jdolecek 
    278        1.1  jdolecek 	/*
    279        1.1  jdolecek 	 * Not an update, or updating the name: look up the name
    280        1.1  jdolecek 	 * and verify that it refers to a sensible block device.
    281        1.1  jdolecek 	 */
    282   1.10.2.6     skrll #ifdef __FreeBSD__
    283        1.1  jdolecek 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
    284   1.10.2.6     skrll #else
    285   1.10.2.6     skrll 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
    286   1.10.2.6     skrll #endif
    287        1.1  jdolecek 	err = namei(ndp);
    288        1.1  jdolecek 	if (err) {
    289        1.1  jdolecek 		/* can't get devvp!*/
    290   1.10.2.7     skrll 		return (err);
    291        1.1  jdolecek 	}
    292        1.1  jdolecek 
    293        1.1  jdolecek 	devvp = ndp->ni_vp;
    294        1.1  jdolecek 
    295        1.1  jdolecek 	if (devvp->v_type != VBLK) {
    296        1.1  jdolecek 		err = ENOTBLK;
    297   1.10.2.7     skrll 		goto fail;
    298        1.1  jdolecek 	}
    299        1.1  jdolecek #ifdef __FreeBSD__
    300        1.1  jdolecek 	if (bdevsw(devvp->v_rdev) == NULL) {
    301        1.1  jdolecek #else
    302        1.1  jdolecek 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    303        1.1  jdolecek #endif
    304        1.1  jdolecek 		err = ENXIO;
    305   1.10.2.7     skrll 		goto fail;
    306        1.1  jdolecek 	}
    307        1.1  jdolecek 	if (mp->mnt_flag & MNT_UPDATE) {
    308        1.1  jdolecek #if 0
    309        1.1  jdolecek 		/*
    310        1.1  jdolecek 		 ********************
    311        1.1  jdolecek 		 * UPDATE
    312        1.1  jdolecek 		 ********************
    313        1.1  jdolecek 		 */
    314        1.1  jdolecek 
    315   1.10.2.7     skrll 		if (devvp != ntmp->um_devvp) {
    316        1.1  jdolecek 			err = EINVAL;	/* needs translation */
    317   1.10.2.7     skrll 			goto fail;
    318   1.10.2.7     skrll 		}
    319   1.10.2.7     skrll 
    320        1.1  jdolecek 		/*
    321        1.1  jdolecek 		 * Update device name only on success
    322        1.1  jdolecek 		 */
    323   1.10.2.7     skrll 		err = set_statvfs_info(NULL, UIO_USERSPACE, args.fspec,
    324   1.10.2.7     skrll 		    UIO_USERSPACE, mp, p);
    325   1.10.2.7     skrll 		if (err)
    326   1.10.2.7     skrll 			goto fail;
    327   1.10.2.7     skrll 
    328   1.10.2.7     skrll 		vrele(devvp);
    329        1.1  jdolecek #endif
    330        1.1  jdolecek 	} else {
    331        1.1  jdolecek 		/*
    332        1.1  jdolecek 		 ********************
    333        1.1  jdolecek 		 * NEW MOUNT
    334        1.1  jdolecek 		 ********************
    335        1.1  jdolecek 		 */
    336        1.1  jdolecek 
    337        1.1  jdolecek 		/*
    338        1.1  jdolecek 		 * Since this is a new mount, we want the names for
    339        1.1  jdolecek 		 * the device and the mount point copied in.  If an
    340        1.1  jdolecek 		 * error occurs,  the mountpoint is discarded by the
    341        1.1  jdolecek 		 * upper level code.
    342        1.1  jdolecek 		 */
    343   1.10.2.7     skrll 
    344        1.1  jdolecek 		/* Save "last mounted on" info for mount point (NULL pad)*/
    345   1.10.2.2     skrll 		err = set_statvfs_info(path, UIO_USERSPACE, args.fspec,
    346   1.10.2.6     skrll 		    UIO_USERSPACE, mp, l);
    347   1.10.2.7     skrll 		if (err)
    348   1.10.2.7     skrll 			goto fail;
    349   1.10.2.7     skrll 
    350   1.10.2.7     skrll 		/*
    351   1.10.2.7     skrll 		 * Disallow multiple mounts of the same device.
    352   1.10.2.7     skrll 		 * Disallow mounting of a device that is currently in use
    353   1.10.2.7     skrll 		 * (except for root, which might share swap device for
    354   1.10.2.7     skrll 		 * miniroot).
    355   1.10.2.7     skrll 		 */
    356   1.10.2.7     skrll 		err = vfs_mountedon(devvp);
    357   1.10.2.7     skrll 		if (err)
    358   1.10.2.7     skrll 			goto fail;
    359   1.10.2.7     skrll 		if (vcount(devvp) > 1 && devvp != rootvp) {
    360   1.10.2.7     skrll 			err = EBUSY;
    361   1.10.2.7     skrll 			goto fail;
    362   1.10.2.7     skrll 		}
    363   1.10.2.7     skrll 		if (mp->mnt_flag & MNT_RDONLY)
    364   1.10.2.7     skrll 			flags = FREAD;
    365   1.10.2.7     skrll 		else
    366   1.10.2.7     skrll 			flags = FREAD|FWRITE;
    367   1.10.2.7     skrll 		err = VOP_OPEN(devvp, flags, FSCRED, l);
    368   1.10.2.7     skrll 		if (err)
    369   1.10.2.7     skrll 			goto fail;
    370   1.10.2.7     skrll 		err = ntfs_mountfs(devvp, mp, &args, l);
    371   1.10.2.7     skrll 		if (err) {
    372   1.10.2.7     skrll 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    373   1.10.2.7     skrll 			(void)VOP_CLOSE(devvp, flags, NOCRED, l);
    374   1.10.2.7     skrll 			VOP_UNLOCK(devvp, 0);
    375   1.10.2.7     skrll 			goto fail;
    376        1.4  christos 		}
    377        1.1  jdolecek 	}
    378        1.1  jdolecek 
    379        1.1  jdolecek #ifdef __FreeBSD__
    380   1.10.2.2     skrll dostatvfs:
    381        1.1  jdolecek #endif
    382        1.1  jdolecek 	/*
    383        1.1  jdolecek 	 * Initialize FS stat information in mount struct; uses both
    384        1.1  jdolecek 	 * mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
    385        1.1  jdolecek 	 *
    386        1.1  jdolecek 	 * This code is common to root and non-root mounts
    387        1.1  jdolecek 	 */
    388   1.10.2.6     skrll 	(void)VFS_STATVFS(mp, &mp->mnt_stat, l);
    389   1.10.2.7     skrll 	return (err);
    390        1.1  jdolecek 
    391   1.10.2.7     skrll fail:
    392        1.1  jdolecek 	vrele(devvp);
    393   1.10.2.7     skrll 	return (err);
    394        1.1  jdolecek }
    395        1.1  jdolecek 
    396        1.1  jdolecek /*
    397        1.1  jdolecek  * Common code for mount and mountroot
    398        1.1  jdolecek  */
    399        1.1  jdolecek int
    400   1.10.2.6     skrll ntfs_mountfs(devvp, mp, argsp, l)
    401        1.1  jdolecek 	struct vnode *devvp;
    402        1.1  jdolecek 	struct mount *mp;
    403        1.1  jdolecek 	struct ntfs_args *argsp;
    404   1.10.2.6     skrll 	struct lwp *l;
    405        1.1  jdolecek {
    406        1.1  jdolecek 	struct buf *bp;
    407        1.1  jdolecek 	struct ntfsmount *ntmp;
    408        1.1  jdolecek 	dev_t dev = devvp->v_rdev;
    409   1.10.2.7     skrll 	int error, ronly, i;
    410        1.1  jdolecek 	struct vnode *vp;
    411        1.1  jdolecek 
    412        1.1  jdolecek 	/*
    413        1.1  jdolecek 	 * Flush out any old buffers remaining from a previous use.
    414        1.1  jdolecek 	 */
    415   1.10.2.7     skrll 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    416   1.10.2.6     skrll 	error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_ucred, l, 0, 0);
    417   1.10.2.7     skrll 	VOP_UNLOCK(devvp, 0);
    418        1.1  jdolecek 	if (error)
    419        1.1  jdolecek 		return (error);
    420        1.1  jdolecek 
    421        1.1  jdolecek 	ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    422        1.1  jdolecek 
    423        1.1  jdolecek 	bp = NULL;
    424        1.1  jdolecek 
    425        1.1  jdolecek 	error = bread(devvp, BBLOCK, BBSIZE, NOCRED, &bp);
    426        1.1  jdolecek 	if (error)
    427        1.1  jdolecek 		goto out;
    428        1.1  jdolecek 	ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK );
    429        1.1  jdolecek 	bzero( ntmp, sizeof *ntmp );
    430        1.1  jdolecek 	bcopy( bp->b_data, &ntmp->ntm_bootfile, sizeof(struct bootfile) );
    431        1.1  jdolecek 	brelse( bp );
    432        1.1  jdolecek 	bp = NULL;
    433        1.1  jdolecek 
    434        1.1  jdolecek 	if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
    435        1.1  jdolecek 		error = EINVAL;
    436        1.1  jdolecek 		dprintf(("ntfs_mountfs: invalid boot block\n"));
    437        1.1  jdolecek 		goto out;
    438        1.1  jdolecek 	}
    439        1.1  jdolecek 
    440        1.1  jdolecek 	{
    441        1.1  jdolecek 		int8_t cpr = ntmp->ntm_mftrecsz;
    442        1.1  jdolecek 		if( cpr > 0 )
    443        1.1  jdolecek 			ntmp->ntm_bpmftrec = ntmp->ntm_spc * cpr;
    444        1.1  jdolecek 		else
    445        1.1  jdolecek 			ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps;
    446        1.1  jdolecek 	}
    447        1.1  jdolecek 	dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
    448        1.1  jdolecek 		ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
    449        1.1  jdolecek 		ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec));
    450        1.1  jdolecek 	dprintf(("ntfs_mountfs(): mftcn: 0x%x|0x%x\n",
    451        1.1  jdolecek 		(u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn));
    452        1.1  jdolecek 
    453        1.1  jdolecek 	ntmp->ntm_mountp = mp;
    454        1.1  jdolecek 	ntmp->ntm_dev = dev;
    455        1.1  jdolecek 	ntmp->ntm_devvp = devvp;
    456        1.1  jdolecek 	ntmp->ntm_uid = argsp->uid;
    457        1.1  jdolecek 	ntmp->ntm_gid = argsp->gid;
    458        1.1  jdolecek 	ntmp->ntm_mode = argsp->mode;
    459        1.1  jdolecek 	ntmp->ntm_flag = argsp->flag;
    460        1.1  jdolecek 	mp->mnt_data = ntmp;
    461        1.1  jdolecek 
    462        1.1  jdolecek 	/* set file name encode/decode hooks XXX utf-8 only for now */
    463        1.1  jdolecek 	ntmp->ntm_wget = ntfs_utf8_wget;
    464        1.1  jdolecek 	ntmp->ntm_wput = ntfs_utf8_wput;
    465        1.1  jdolecek 	ntmp->ntm_wcmp = ntfs_utf8_wcmp;
    466        1.1  jdolecek 
    467        1.1  jdolecek 	dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
    468        1.1  jdolecek 		(ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
    469        1.1  jdolecek 		(ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
    470        1.1  jdolecek 		ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode));
    471        1.1  jdolecek 
    472        1.1  jdolecek 	/*
    473   1.10.2.8     skrll 	 * We read in some system nodes to do not allow
    474        1.1  jdolecek 	 * reclaim them and to have everytime access to them.
    475   1.10.2.8     skrll 	 */
    476        1.1  jdolecek 	{
    477        1.1  jdolecek 		int pi[3] = { NTFS_MFTINO, NTFS_ROOTINO, NTFS_BITMAPINO };
    478        1.1  jdolecek 		for (i=0; i<3; i++) {
    479   1.10.2.3     skrll 			error = VFS_VGET(mp, pi[i], &(ntmp->ntm_sysvn[pi[i]]));
    480        1.1  jdolecek 			if(error)
    481        1.1  jdolecek 				goto out1;
    482        1.1  jdolecek 			ntmp->ntm_sysvn[pi[i]]->v_flag |= VSYSTEM;
    483        1.1  jdolecek 			VREF(ntmp->ntm_sysvn[pi[i]]);
    484        1.1  jdolecek 			vput(ntmp->ntm_sysvn[pi[i]]);
    485        1.1  jdolecek 		}
    486        1.1  jdolecek 	}
    487        1.1  jdolecek 
    488        1.1  jdolecek 	/* read the Unicode lowercase --> uppercase translation table,
    489        1.1  jdolecek 	 * if necessary */
    490        1.1  jdolecek 	if ((error = ntfs_toupper_use(mp, ntmp)))
    491        1.1  jdolecek 		goto out1;
    492        1.1  jdolecek 
    493        1.1  jdolecek 	/*
    494        1.1  jdolecek 	 * Scan $BitMap and count free clusters
    495        1.1  jdolecek 	 */
    496        1.1  jdolecek 	error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
    497        1.1  jdolecek 	if(error)
    498        1.1  jdolecek 		goto out1;
    499        1.1  jdolecek 
    500        1.1  jdolecek 	/*
    501        1.1  jdolecek 	 * Read and translate to internal format attribute
    502   1.10.2.8     skrll 	 * definition file.
    503        1.1  jdolecek 	 */
    504        1.1  jdolecek 	{
    505        1.1  jdolecek 		int num,j;
    506        1.1  jdolecek 		struct attrdef ad;
    507        1.1  jdolecek 
    508        1.1  jdolecek 		/* Open $AttrDef */
    509   1.10.2.8     skrll 		error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp );
    510   1.10.2.8     skrll 		if(error)
    511        1.1  jdolecek 			goto out1;
    512        1.1  jdolecek 
    513        1.1  jdolecek 		/* Count valid entries */
    514        1.1  jdolecek 		for(num=0;;num++) {
    515        1.1  jdolecek 			error = ntfs_readattr(ntmp, VTONT(vp),
    516        1.1  jdolecek 					NTFS_A_DATA, NULL,
    517        1.1  jdolecek 					num * sizeof(ad), sizeof(ad),
    518        1.1  jdolecek 					&ad, NULL);
    519        1.1  jdolecek 			if (error)
    520        1.1  jdolecek 				goto out1;
    521        1.1  jdolecek 			if (ad.ad_name[0] == 0)
    522        1.1  jdolecek 				break;
    523        1.1  jdolecek 		}
    524        1.1  jdolecek 
    525        1.1  jdolecek 		/* Alloc memory for attribute definitions */
    526        1.1  jdolecek 		ntmp->ntm_ad = (struct ntvattrdef *) malloc(
    527        1.1  jdolecek 			num * sizeof(struct ntvattrdef),
    528        1.1  jdolecek 			M_NTFSMNT, M_WAITOK);
    529        1.1  jdolecek 
    530        1.1  jdolecek 		ntmp->ntm_adnum = num;
    531        1.1  jdolecek 
    532        1.1  jdolecek 		/* Read them and translate */
    533        1.1  jdolecek 		for(i=0;i<num;i++){
    534        1.1  jdolecek 			error = ntfs_readattr(ntmp, VTONT(vp),
    535        1.1  jdolecek 					NTFS_A_DATA, NULL,
    536        1.1  jdolecek 					i * sizeof(ad), sizeof(ad),
    537        1.1  jdolecek 					&ad, NULL);
    538        1.1  jdolecek 			if (error)
    539        1.1  jdolecek 				goto out1;
    540        1.1  jdolecek 			j = 0;
    541        1.1  jdolecek 			do {
    542        1.1  jdolecek 				ntmp->ntm_ad[i].ad_name[j] = ad.ad_name[j];
    543        1.1  jdolecek 			} while(ad.ad_name[j++]);
    544        1.1  jdolecek 			ntmp->ntm_ad[i].ad_namelen = j - 1;
    545        1.1  jdolecek 			ntmp->ntm_ad[i].ad_type = ad.ad_type;
    546        1.1  jdolecek 		}
    547        1.1  jdolecek 
    548        1.1  jdolecek 		vput(vp);
    549        1.1  jdolecek 	}
    550        1.1  jdolecek 
    551        1.1  jdolecek #if defined(__FreeBSD__)
    552        1.1  jdolecek 	mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
    553        1.1  jdolecek 	mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
    554        1.1  jdolecek #else
    555   1.10.2.2     skrll 	mp->mnt_stat.f_fsidx.__fsid_val[0] = dev;
    556   1.10.2.2     skrll 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_NTFS);
    557   1.10.2.2     skrll 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    558   1.10.2.5     skrll 	mp->mnt_stat.f_namemax = NTFS_MAXFILENAME;
    559        1.1  jdolecek #endif
    560        1.1  jdolecek 	mp->mnt_flag |= MNT_LOCAL;
    561        1.1  jdolecek 	devvp->v_specmountpoint = mp;
    562        1.1  jdolecek 	return (0);
    563        1.1  jdolecek 
    564        1.1  jdolecek out1:
    565        1.1  jdolecek 	for(i=0;i<NTFS_SYSNODESNUM;i++)
    566        1.1  jdolecek 		if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
    567        1.1  jdolecek 
    568        1.1  jdolecek 	if (vflush(mp,NULLVP,0))
    569        1.1  jdolecek 		dprintf(("ntfs_mountfs: vflush failed\n"));
    570        1.1  jdolecek 
    571        1.1  jdolecek out:
    572        1.1  jdolecek 	devvp->v_specmountpoint = NULL;
    573        1.1  jdolecek 	if (bp)
    574        1.1  jdolecek 		brelse(bp);
    575        1.1  jdolecek 
    576        1.1  jdolecek 	return (error);
    577        1.1  jdolecek }
    578        1.1  jdolecek 
    579        1.1  jdolecek static int
    580        1.1  jdolecek ntfs_start (
    581        1.1  jdolecek 	struct mount *mp,
    582        1.1  jdolecek 	int flags,
    583   1.10.2.6     skrll 	struct lwp *l )
    584        1.1  jdolecek {
    585        1.1  jdolecek 	return (0);
    586        1.1  jdolecek }
    587        1.1  jdolecek 
    588        1.1  jdolecek static int
    589   1.10.2.8     skrll ntfs_unmount(
    590        1.1  jdolecek 	struct mount *mp,
    591        1.1  jdolecek 	int mntflags,
    592   1.10.2.6     skrll 	struct lwp *l)
    593        1.1  jdolecek {
    594        1.1  jdolecek 	struct ntfsmount *ntmp;
    595        1.1  jdolecek 	int error, ronly = 0, flags, i;
    596        1.1  jdolecek 
    597        1.1  jdolecek 	dprintf(("ntfs_unmount: unmounting...\n"));
    598        1.1  jdolecek 	ntmp = VFSTONTFS(mp);
    599        1.1  jdolecek 
    600        1.1  jdolecek 	flags = 0;
    601        1.1  jdolecek 	if(mntflags & MNT_FORCE)
    602        1.1  jdolecek 		flags |= FORCECLOSE;
    603        1.1  jdolecek 
    604        1.1  jdolecek 	dprintf(("ntfs_unmount: vflushing...\n"));
    605        1.1  jdolecek 	error = vflush(mp,NULLVP,flags | SKIPSYSTEM);
    606        1.1  jdolecek 	if (error) {
    607        1.1  jdolecek 		dprintf(("ntfs_unmount: vflush failed: %d\n",error));
    608        1.1  jdolecek 		return (error);
    609        1.1  jdolecek 	}
    610        1.1  jdolecek 
    611        1.1  jdolecek 	/* Check if only system vnodes are rest */
    612        1.1  jdolecek 	for(i=0;i<NTFS_SYSNODESNUM;i++)
    613   1.10.2.8     skrll 		 if((ntmp->ntm_sysvn[i]) &&
    614        1.1  jdolecek 		    (ntmp->ntm_sysvn[i]->v_usecount > 1)) return (EBUSY);
    615        1.1  jdolecek 
    616        1.1  jdolecek 	/* Dereference all system vnodes */
    617        1.1  jdolecek 	for(i=0;i<NTFS_SYSNODESNUM;i++)
    618        1.1  jdolecek 		 if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
    619        1.1  jdolecek 
    620        1.1  jdolecek 	/* vflush system vnodes */
    621        1.1  jdolecek 	error = vflush(mp,NULLVP,flags);
    622        1.1  jdolecek 	if (error) {
    623        1.1  jdolecek 		/* XXX should this be panic() ? */
    624        1.1  jdolecek 		printf("ntfs_unmount: vflush failed(sysnodes): %d\n",error);
    625        1.1  jdolecek 	}
    626        1.1  jdolecek 
    627        1.1  jdolecek 	/* Check if the type of device node isn't VBAD before
    628        1.1  jdolecek 	 * touching v_specinfo.  If the device vnode is revoked, the
    629        1.1  jdolecek 	 * field is NULL and touching it causes null pointer derefercence.
    630        1.1  jdolecek 	 */
    631        1.1  jdolecek 	if (ntmp->ntm_devvp->v_type != VBAD)
    632        1.1  jdolecek 		ntmp->ntm_devvp->v_specmountpoint = NULL;
    633        1.1  jdolecek 
    634   1.10.2.6     skrll 	vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, l, 0, 0);
    635        1.1  jdolecek 
    636        1.1  jdolecek 	/* lock the device vnode before calling VOP_CLOSE() */
    637   1.10.2.2     skrll 	vn_lock(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY);
    638        1.1  jdolecek 	error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
    639   1.10.2.6     skrll 		NOCRED, l);
    640        1.3  jdolecek 	VOP_UNLOCK(ntmp->ntm_devvp, 0);
    641        1.1  jdolecek 
    642        1.1  jdolecek 	vrele(ntmp->ntm_devvp);
    643        1.1  jdolecek 
    644        1.1  jdolecek 	/* free the toupper table, if this has been last mounted ntfs volume */
    645        1.1  jdolecek 	ntfs_toupper_unuse();
    646        1.1  jdolecek 
    647        1.1  jdolecek 	dprintf(("ntfs_umount: freeing memory...\n"));
    648        1.1  jdolecek 	mp->mnt_data = NULL;
    649        1.1  jdolecek 	mp->mnt_flag &= ~MNT_LOCAL;
    650        1.1  jdolecek 	free(ntmp->ntm_ad, M_NTFSMNT);
    651        1.1  jdolecek 	FREE(ntmp, M_NTFSMNT);
    652        1.1  jdolecek 	return (error);
    653        1.1  jdolecek }
    654        1.1  jdolecek 
    655        1.1  jdolecek static int
    656        1.1  jdolecek ntfs_root(
    657        1.1  jdolecek 	struct mount *mp,
    658   1.10.2.6     skrll 	struct vnode **vpp)
    659        1.1  jdolecek {
    660        1.1  jdolecek 	struct vnode *nvp;
    661        1.1  jdolecek 	int error = 0;
    662        1.1  jdolecek 
    663        1.1  jdolecek 	dprintf(("ntfs_root(): sysvn: %p\n",
    664        1.1  jdolecek 		VFSTONTFS(mp)->ntm_sysvn[NTFS_ROOTINO]));
    665   1.10.2.3     skrll 	error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, &nvp);
    666        1.1  jdolecek 	if(error) {
    667        1.1  jdolecek 		printf("ntfs_root: VFS_VGET failed: %d\n",error);
    668        1.1  jdolecek 		return (error);
    669        1.1  jdolecek 	}
    670        1.1  jdolecek 
    671        1.1  jdolecek 	*vpp = nvp;
    672        1.1  jdolecek 	return (0);
    673        1.1  jdolecek }
    674        1.1  jdolecek 
    675   1.10.2.2     skrll /*
    676   1.10.2.2     skrll  * Do operations associated with quotas, not supported
    677   1.10.2.2     skrll  */
    678   1.10.2.2     skrll /* ARGSUSED */
    679        1.1  jdolecek static int
    680   1.10.2.8     skrll ntfs_quotactl (
    681        1.1  jdolecek 	struct mount *mp,
    682        1.1  jdolecek 	int cmds,
    683        1.1  jdolecek 	uid_t uid,
    684   1.10.2.2     skrll 	void *arg,
    685   1.10.2.6     skrll 	struct lwp *l)
    686        1.1  jdolecek {
    687   1.10.2.2     skrll 
    688        1.1  jdolecek 	return EOPNOTSUPP;
    689        1.1  jdolecek }
    690        1.1  jdolecek 
    691        1.1  jdolecek int
    692        1.1  jdolecek ntfs_calccfree(
    693        1.1  jdolecek 	struct ntfsmount *ntmp,
    694        1.1  jdolecek 	cn_t *cfreep)
    695        1.1  jdolecek {
    696        1.1  jdolecek 	struct vnode *vp;
    697        1.1  jdolecek 	u_int8_t *tmp;
    698        1.1  jdolecek 	int j, error;
    699   1.10.2.2     skrll 	cn_t cfree = 0;
    700        1.1  jdolecek 	size_t bmsize, i;
    701        1.1  jdolecek 
    702        1.1  jdolecek 	vp = ntmp->ntm_sysvn[NTFS_BITMAPINO];
    703        1.1  jdolecek 
    704        1.1  jdolecek 	bmsize = VTOF(vp)->f_size;
    705        1.1  jdolecek 
    706        1.1  jdolecek 	tmp = (u_int8_t *) malloc(bmsize, M_TEMP, M_WAITOK);
    707        1.1  jdolecek 
    708        1.1  jdolecek 	error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
    709        1.1  jdolecek 			       0, bmsize, tmp, NULL);
    710        1.1  jdolecek 	if (error)
    711        1.1  jdolecek 		goto out;
    712        1.1  jdolecek 
    713        1.1  jdolecek 	for(i=0;i<bmsize;i++)
    714        1.1  jdolecek 		for(j=0;j<8;j++)
    715        1.1  jdolecek 			if(~tmp[i] & (1 << j)) cfree++;
    716        1.1  jdolecek 	*cfreep = cfree;
    717        1.1  jdolecek 
    718        1.1  jdolecek     out:
    719        1.1  jdolecek 	free(tmp, M_TEMP);
    720        1.1  jdolecek 	return(error);
    721        1.1  jdolecek }
    722        1.1  jdolecek 
    723        1.1  jdolecek static int
    724   1.10.2.2     skrll ntfs_statvfs(
    725        1.1  jdolecek 	struct mount *mp,
    726   1.10.2.2     skrll 	struct statvfs *sbp,
    727   1.10.2.6     skrll 	struct lwp *l)
    728        1.1  jdolecek {
    729        1.1  jdolecek 	struct ntfsmount *ntmp = VFSTONTFS(mp);
    730        1.1  jdolecek 	u_int64_t mftallocated;
    731        1.1  jdolecek 
    732   1.10.2.2     skrll 	dprintf(("ntfs_statvfs():\n"));
    733        1.1  jdolecek 
    734        1.1  jdolecek 	mftallocated = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_allocated;
    735        1.1  jdolecek 
    736        1.1  jdolecek #if defined(__FreeBSD__)
    737        1.1  jdolecek 	sbp->f_type = mp->mnt_vfc->vfc_typenum;
    738        1.1  jdolecek #endif
    739        1.1  jdolecek 	sbp->f_bsize = ntmp->ntm_bps;
    740   1.10.2.2     skrll 	sbp->f_frsize = sbp->f_bsize; /* XXX */
    741        1.1  jdolecek 	sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
    742        1.1  jdolecek 	sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
    743        1.1  jdolecek 	sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(ntmp->ntm_cfree);
    744   1.10.2.2     skrll 	sbp->f_ffree = sbp->f_favail = sbp->f_bfree / ntmp->ntm_bpmftrec;
    745        1.1  jdolecek 	sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
    746   1.10.2.2     skrll 	    sbp->f_ffree;
    747   1.10.2.2     skrll 	sbp->f_fresvd = sbp->f_bresvd = 0; /* XXX */
    748   1.10.2.2     skrll 	sbp->f_flag = mp->mnt_flag;
    749   1.10.2.2     skrll 	copy_statvfs_info(sbp, mp);
    750        1.1  jdolecek 	return (0);
    751        1.1  jdolecek }
    752        1.1  jdolecek 
    753        1.1  jdolecek static int
    754        1.1  jdolecek ntfs_sync (
    755        1.1  jdolecek 	struct mount *mp,
    756        1.1  jdolecek 	int waitfor,
    757        1.1  jdolecek 	struct ucred *cred,
    758   1.10.2.6     skrll 	struct lwp *l)
    759        1.1  jdolecek {
    760        1.1  jdolecek 	/*dprintf(("ntfs_sync():\n"));*/
    761        1.1  jdolecek 	return (0);
    762        1.1  jdolecek }
    763        1.1  jdolecek 
    764        1.1  jdolecek /*ARGSUSED*/
    765        1.1  jdolecek static int
    766        1.1  jdolecek ntfs_fhtovp(
    767        1.1  jdolecek #if defined(__FreeBSD__)
    768        1.1  jdolecek 	struct mount *mp,
    769        1.1  jdolecek 	struct fid *fhp,
    770        1.1  jdolecek 	struct sockaddr *nam,
    771        1.1  jdolecek 	struct vnode **vpp,
    772        1.1  jdolecek 	int *exflagsp,
    773        1.1  jdolecek 	struct ucred **credanonp)
    774        1.1  jdolecek #elif defined(__NetBSD__)
    775        1.1  jdolecek 	struct mount *mp,
    776        1.1  jdolecek 	struct fid *fhp,
    777   1.10.2.3     skrll 	struct vnode **vpp)
    778        1.1  jdolecek #else
    779        1.1  jdolecek 	struct mount *mp,
    780        1.1  jdolecek 	struct fid *fhp,
    781        1.1  jdolecek 	struct mbuf *nam,
    782        1.1  jdolecek 	struct vnode **vpp,
    783        1.1  jdolecek 	int *exflagsp,
    784        1.1  jdolecek 	struct ucred **credanonp)
    785        1.1  jdolecek #endif
    786        1.1  jdolecek {
    787        1.1  jdolecek 	struct ntfid *ntfhp = (struct ntfid *)fhp;
    788        1.1  jdolecek 	int error;
    789        1.1  jdolecek 
    790  1.10.2.10     skrll 	ddprintf(("ntfs_fhtovp(): %s: %llu\n", mp->mnt_stat.f_mntonname,
    791  1.10.2.10     skrll 	    (unsigned long long)ntfhp->ntfid_ino));
    792        1.1  jdolecek 
    793        1.1  jdolecek 	error = ntfs_vgetex(mp, ntfhp->ntfid_ino, ntfhp->ntfid_attr, NULL,
    794   1.10.2.6     skrll 			LK_EXCLUSIVE | LK_RETRY, 0, vpp);
    795        1.1  jdolecek 	if (error != 0) {
    796        1.1  jdolecek 		*vpp = NULLVP;
    797        1.1  jdolecek 		return (error);
    798        1.1  jdolecek 	}
    799        1.1  jdolecek 
    800        1.1  jdolecek 	/* XXX as unlink/rmdir/mkdir/creat are not currently possible
    801        1.1  jdolecek 	 * with NTFS, we don't need to check anything else for now */
    802        1.1  jdolecek 	return (0);
    803        1.1  jdolecek }
    804        1.1  jdolecek 
    805        1.1  jdolecek static int
    806        1.1  jdolecek ntfs_vptofh(
    807        1.1  jdolecek 	struct vnode *vp,
    808        1.1  jdolecek 	struct fid *fhp)
    809        1.1  jdolecek {
    810        1.1  jdolecek 	struct ntnode *ntp;
    811        1.1  jdolecek 	struct ntfid *ntfhp;
    812        1.1  jdolecek 	struct fnode *fn;
    813        1.1  jdolecek 
    814        1.1  jdolecek 	ddprintf(("ntfs_fhtovp(): %s: %p\n", vp->v_mount->mnt_stat.f_mntonname,
    815        1.1  jdolecek 		vp));
    816        1.1  jdolecek 
    817        1.1  jdolecek 	fn = VTOF(vp);
    818        1.1  jdolecek 	ntp = VTONT(vp);
    819        1.1  jdolecek 	ntfhp = (struct ntfid *)fhp;
    820        1.1  jdolecek 	ntfhp->ntfid_len = sizeof(struct ntfid);
    821        1.1  jdolecek 	ntfhp->ntfid_ino = ntp->i_number;
    822        1.1  jdolecek 	ntfhp->ntfid_attr = fn->f_attrtype;
    823        1.1  jdolecek #ifdef notyet
    824        1.1  jdolecek 	ntfhp->ntfid_gen = ntp->i_gen;
    825        1.1  jdolecek #endif
    826        1.1  jdolecek 	return (0);
    827        1.1  jdolecek }
    828        1.1  jdolecek 
    829        1.1  jdolecek int
    830        1.1  jdolecek ntfs_vgetex(
    831        1.1  jdolecek 	struct mount *mp,
    832        1.1  jdolecek 	ino_t ino,
    833        1.1  jdolecek 	u_int32_t attrtype,
    834        1.1  jdolecek 	char *attrname,
    835        1.1  jdolecek 	u_long lkflags,
    836        1.1  jdolecek 	u_long flags,
    837   1.10.2.8     skrll 	struct vnode **vpp)
    838        1.1  jdolecek {
    839        1.1  jdolecek 	int error;
    840        1.1  jdolecek 	struct ntfsmount *ntmp;
    841        1.1  jdolecek 	struct ntnode *ip;
    842        1.1  jdolecek 	struct fnode *fp;
    843        1.1  jdolecek 	struct vnode *vp;
    844   1.10.2.2     skrll 	enum vtype f_type = VBAD;
    845        1.1  jdolecek 
    846  1.10.2.10     skrll 	dprintf(("ntfs_vgetex: ino: %llu, attr: 0x%x:%s, lkf: 0x%lx, f:"
    847  1.10.2.10     skrll 	    " 0x%lx\n", (unsigned long long)ino, attrtype,
    848  1.10.2.10     skrll 	    attrname ? attrname : "", (u_long)lkflags, (u_long)flags));
    849        1.1  jdolecek 
    850        1.1  jdolecek 	ntmp = VFSTONTFS(mp);
    851        1.1  jdolecek 	*vpp = NULL;
    852        1.1  jdolecek 
    853        1.1  jdolecek 	/* Get ntnode */
    854        1.1  jdolecek 	error = ntfs_ntlookup(ntmp, ino, &ip);
    855        1.1  jdolecek 	if (error) {
    856        1.1  jdolecek 		printf("ntfs_vget: ntfs_ntget failed\n");
    857        1.1  jdolecek 		return (error);
    858        1.1  jdolecek 	}
    859        1.1  jdolecek 
    860        1.1  jdolecek 	/* It may be not initialized fully, so force load it */
    861        1.1  jdolecek 	if (!(flags & VG_DONTLOADIN) && !(ip->i_flag & IN_LOADED)) {
    862        1.1  jdolecek 		error = ntfs_loadntnode(ntmp, ip);
    863        1.1  jdolecek 		if(error) {
    864  1.10.2.10     skrll 			printf("ntfs_vget: CAN'T LOAD ATTRIBUTES FOR INO:"
    865  1.10.2.10     skrll 			    " %llu\n", (unsigned long long)ip->i_number);
    866        1.1  jdolecek 			ntfs_ntput(ip);
    867        1.1  jdolecek 			return (error);
    868        1.1  jdolecek 		}
    869        1.1  jdolecek 	}
    870        1.1  jdolecek 
    871        1.1  jdolecek 	error = ntfs_fget(ntmp, ip, attrtype, attrname, &fp);
    872        1.1  jdolecek 	if (error) {
    873        1.1  jdolecek 		printf("ntfs_vget: ntfs_fget failed\n");
    874        1.1  jdolecek 		ntfs_ntput(ip);
    875        1.1  jdolecek 		return (error);
    876        1.1  jdolecek 	}
    877        1.1  jdolecek 
    878        1.1  jdolecek 	if (!(flags & VG_DONTVALIDFN) && !(fp->f_flag & FN_VALID)) {
    879        1.1  jdolecek 		if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
    880        1.1  jdolecek 		    (fp->f_attrtype == NTFS_A_DATA && fp->f_attrname == NULL)) {
    881        1.1  jdolecek 			f_type = VDIR;
    882        1.1  jdolecek 		} else if (flags & VG_EXT) {
    883        1.1  jdolecek 			f_type = VNON;
    884        1.1  jdolecek 			fp->f_size = fp->f_allocated = 0;
    885        1.1  jdolecek 		} else {
    886   1.10.2.8     skrll 			f_type = VREG;
    887        1.1  jdolecek 
    888   1.10.2.8     skrll 			error = ntfs_filesize(ntmp, fp,
    889        1.1  jdolecek 					      &fp->f_size, &fp->f_allocated);
    890        1.1  jdolecek 			if (error) {
    891        1.1  jdolecek 				ntfs_ntput(ip);
    892        1.1  jdolecek 				return (error);
    893        1.1  jdolecek 			}
    894        1.1  jdolecek 		}
    895        1.1  jdolecek 
    896        1.1  jdolecek 		fp->f_flag |= FN_VALID;
    897        1.1  jdolecek 	}
    898        1.1  jdolecek 
    899        1.1  jdolecek 	/*
    900        1.1  jdolecek 	 * We may be calling vget() now. To avoid potential deadlock, we need
    901        1.1  jdolecek 	 * to release ntnode lock, since due to locking order vnode
    902        1.1  jdolecek 	 * lock has to be acquired first.
    903        1.1  jdolecek 	 * ntfs_fget() bumped ntnode usecount, so ntnode won't be recycled
    904        1.1  jdolecek 	 * prematurely.
    905        1.1  jdolecek 	 */
    906        1.1  jdolecek 	ntfs_ntput(ip);
    907        1.1  jdolecek 
    908        1.1  jdolecek 	if (FTOV(fp)) {
    909        1.1  jdolecek 		/* vget() returns error if the vnode has been recycled */
    910   1.10.2.3     skrll 		if (vget(FTOV(fp), lkflags) == 0) {
    911        1.1  jdolecek 			*vpp = FTOV(fp);
    912        1.1  jdolecek 			return (0);
    913        1.1  jdolecek 		}
    914        1.1  jdolecek 	}
    915        1.1  jdolecek 
    916        1.1  jdolecek 	error = getnewvnode(VT_NTFS, ntmp->ntm_mountp, ntfs_vnodeop_p, &vp);
    917        1.1  jdolecek 	if(error) {
    918        1.1  jdolecek 		ntfs_frele(fp);
    919        1.1  jdolecek 		ntfs_ntput(ip);
    920        1.1  jdolecek 		return (error);
    921        1.1  jdolecek 	}
    922  1.10.2.10     skrll 	dprintf(("ntfs_vget: vnode: %p for ntnode: %llu\n", vp,
    923  1.10.2.10     skrll 	    (unsigned long long)ino));
    924        1.1  jdolecek 
    925        1.1  jdolecek #ifdef __FreeBSD__
    926        1.1  jdolecek 	lockinit(&fp->f_lock, PINOD, "fnode", 0, 0);
    927        1.1  jdolecek #endif
    928        1.1  jdolecek 	fp->f_vp = vp;
    929        1.1  jdolecek 	vp->v_data = fp;
    930   1.10.2.2     skrll 	if (f_type != VBAD)
    931   1.10.2.2     skrll 		vp->v_type = f_type;
    932        1.1  jdolecek 
    933        1.1  jdolecek 	if (ino == NTFS_ROOTINO)
    934        1.1  jdolecek 		vp->v_flag |= VROOT;
    935        1.1  jdolecek 
    936        1.1  jdolecek 	if (lkflags & LK_TYPE_MASK) {
    937        1.3  jdolecek 		error = vn_lock(vp, lkflags);
    938        1.1  jdolecek 		if (error) {
    939        1.1  jdolecek 			vput(vp);
    940        1.1  jdolecek 			return (error);
    941        1.1  jdolecek 		}
    942        1.1  jdolecek 	}
    943        1.1  jdolecek 
    944        1.1  jdolecek 	genfs_node_init(vp, &ntfs_genfsops);
    945        1.1  jdolecek 	VREF(ip->i_devvp);
    946        1.1  jdolecek 	*vpp = vp;
    947        1.1  jdolecek 	return (0);
    948        1.1  jdolecek }
    949        1.1  jdolecek 
    950        1.1  jdolecek static int
    951        1.1  jdolecek ntfs_vget(
    952        1.1  jdolecek 	struct mount *mp,
    953        1.1  jdolecek 	ino_t ino,
    954   1.10.2.6     skrll 	struct vnode **vpp)
    955        1.1  jdolecek {
    956        1.1  jdolecek 	return ntfs_vgetex(mp, ino, NTFS_A_DATA, NULL,
    957   1.10.2.6     skrll 			LK_EXCLUSIVE | LK_RETRY, 0, vpp);
    958        1.1  jdolecek }
    959        1.1  jdolecek 
    960        1.1  jdolecek #if defined(__FreeBSD__)
    961        1.1  jdolecek static struct vfsops ntfs_vfsops = {
    962        1.1  jdolecek 	ntfs_mount,
    963        1.1  jdolecek 	ntfs_start,
    964        1.1  jdolecek 	ntfs_unmount,
    965        1.1  jdolecek 	ntfs_root,
    966        1.1  jdolecek 	ntfs_quotactl,
    967   1.10.2.2     skrll 	ntfs_statvfs,
    968        1.1  jdolecek 	ntfs_sync,
    969        1.1  jdolecek 	ntfs_vget,
    970        1.1  jdolecek 	ntfs_fhtovp,
    971        1.1  jdolecek 	ntfs_vptofh,
    972        1.1  jdolecek 	ntfs_init,
    973        1.1  jdolecek 	NULL
    974        1.1  jdolecek };
    975        1.1  jdolecek VFS_SET(ntfs_vfsops, ntfs, 0);
    976        1.1  jdolecek #elif defined(__NetBSD__)
    977        1.1  jdolecek extern const struct vnodeopv_desc ntfs_vnodeop_opv_desc;
    978        1.1  jdolecek 
    979        1.1  jdolecek const struct vnodeopv_desc * const ntfs_vnodeopv_descs[] = {
    980        1.1  jdolecek 	&ntfs_vnodeop_opv_desc,
    981        1.1  jdolecek 	NULL,
    982        1.1  jdolecek };
    983        1.1  jdolecek 
    984        1.1  jdolecek struct vfsops ntfs_vfsops = {
    985        1.1  jdolecek 	MOUNT_NTFS,
    986        1.1  jdolecek 	ntfs_mount,
    987        1.1  jdolecek 	ntfs_start,
    988        1.1  jdolecek 	ntfs_unmount,
    989        1.1  jdolecek 	ntfs_root,
    990        1.1  jdolecek 	ntfs_quotactl,
    991   1.10.2.2     skrll 	ntfs_statvfs,
    992        1.1  jdolecek 	ntfs_sync,
    993        1.1  jdolecek 	ntfs_vget,
    994        1.1  jdolecek 	ntfs_fhtovp,
    995        1.1  jdolecek 	ntfs_vptofh,
    996        1.1  jdolecek 	ntfs_init,
    997        1.1  jdolecek 	ntfs_reinit,
    998        1.1  jdolecek 	ntfs_done,
    999        1.1  jdolecek 	ntfs_mountroot,
   1000   1.10.2.2     skrll 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
   1001   1.10.2.7     skrll 	vfs_stdextattrctl,
   1002        1.1  jdolecek 	ntfs_vnodeopv_descs,
   1003        1.1  jdolecek };
   1004   1.10.2.9     skrll VFS_ATTACH(ntfs_vfsops);
   1005        1.1  jdolecek #endif
   1006