1 /* $NetBSD: ntfs_vfsops.c,v 1.23 1999/11/15 19:38:14 jdolecek Exp $ */
4 * Copyright (c) 1998, 1999 Semen Ustimenko
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $FreeBSD: src/sys/ntfs/ntfs_vfsops.c,v 1.20.2.5 2001/12/25 01:44:45 dillon Exp $
29 * $DragonFly: src/sys/vfs/ntfs/ntfs_vfsops.c,v 1.21 2004/08/28 19:02:21 dillon Exp $
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/namei.h>
38 #include <sys/kernel.h>
39 #include <sys/vnode.h>
40 #include <sys/mount.h>
42 #include <sys/fcntl.h>
43 #include <sys/malloc.h>
44 #include <sys/systm.h>
45 #if defined(__NetBSD__)
46 #include <sys/device.h>
50 #include <vm/vm_param.h>
51 #if defined(__NetBSD__)
52 #include <vm/vm_prot.h>
54 #include <vm/vm_page.h>
55 #include <vm/vm_object.h>
56 #include <vm/vm_extern.h>
57 #include <vm/vm_zone.h>
59 #if defined(__NetBSD__)
60 #include <miscfs/specfs/specdev.h>
63 /*#define NTFS_DEBUG 1*/
65 #include "ntfs_inode.h"
66 #include "ntfs_subr.h"
67 #include "ntfs_vfsops.h"
68 #include "ntfs_ihash.h"
69 #include "ntfsmount.h"
71 extern struct vnodeopv_entry_desc ntfs_vnodeop_entries[];
73 #if defined(__DragonFly__)
74 MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
75 MALLOC_DEFINE(M_NTFSNTNODE,"NTFS ntnode", "NTFS ntnode information");
76 MALLOC_DEFINE(M_NTFSFNODE,"NTFS fnode", "NTFS fnode information");
77 MALLOC_DEFINE(M_NTFSDIR,"NTFS dir", "NTFS dir buffer");
80 static int ntfs_root (struct mount *, struct vnode **);
81 static int ntfs_statfs (struct mount *, struct statfs *,
83 static int ntfs_unmount (struct mount *, int, struct thread *);
84 static int ntfs_vget (struct mount *mp, ino_t ino,
86 static int ntfs_mountfs (struct vnode *, struct mount *,
87 struct ntfs_args *, struct thread *);
88 static int ntfs_vptofh (struct vnode *, struct fid *);
89 static int ntfs_fhtovp (struct mount *, struct fid *,
92 #if !defined (__DragonFly__)
93 static int ntfs_quotactl (struct mount *, int, uid_t, caddr_t,
95 static int ntfs_start (struct mount *, int, struct thread *);
96 static int ntfs_sync (struct mount *, int, struct ucred *,
100 #if defined(__DragonFly__)
102 static int ntfs_mount (struct mount *, char *, caddr_t,
103 struct nameidata *, struct thread *);
104 static int ntfs_init (struct vfsconf *);
105 static int ntfs_checkexp (struct mount *, struct sockaddr *,
106 int *, struct ucred **);
107 #elif defined(__NetBSD__)
108 static int ntfs_mount (struct mount *, const char *, void *,
109 struct nameidata *, struct thread *);
110 static void ntfs_init (void);
111 static int ntfs_mountroot (void);
112 static int ntfs_sysctl (int *, u_int, void *, size_t *, void *,
113 size_t, struct thread *);
114 static int ntfs_checkexp (struct mount *, struct mbuf *,
115 int *, struct ucred **);
119 * Verify a remote client has export rights and return these rights via.
120 * exflagsp and credanonp.
123 ntfs_checkexp(struct mount *mp,
124 #if defined(__DragonFly__)
125 struct sockaddr *nam,
126 #else /* defined(__NetBSD__) */
129 int *exflagsp, struct ucred **credanonp)
132 struct ntfsmount *ntm = VFSTONTFS(mp);
135 * Get the export permission structure for this <mp, client> tuple.
137 np = vfs_export_lookup(mp, &ntm->ntm_export, nam);
141 *exflagsp = np->netc_exflags;
142 *credanonp = &np->netc_anon;
146 #if defined(__NetBSD__)
149 ntfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
150 size_t newlen, struct thread *td)
159 extern struct vnode *rootvp;
160 struct thread *td = curthread; /* XXX */
161 struct ntfs_args args;
165 if (root_device->dv_class != DV_DISK)
169 * Get vnodes for rootdev.
171 if (bdevvp(rootdev, &rootvp))
172 panic("ntfs_mountroot: can't setup rootvp");
174 if ((error = vfs_rootmountalloc(MOUNT_NTFS, "root_device", &mp))) {
184 if ((error = ntfs_mountfs(rootvp, mp, &args, td)) != 0) {
185 mp->mnt_op->vfs_refcount--;
192 lwkt_gettoken(&ilock, &mountlist_token);
193 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
194 lwkt_reltoken(&ilock);
195 (void)ntfs_statfs(mp, &mp->mnt_stat, td);
207 #elif defined(__DragonFly__)
210 ntfs_init(struct vfsconf *vcp)
220 ntfs_mount(struct mount *mp,
221 #if defined(__DragonFly__)
222 char *path, caddr_t data,
224 const char *path, void *data,
226 struct nameidata *ndp, struct thread *td)
231 struct ntfs_args args;
235 * Use NULL path to flag a root mount
240 * Mounting root file system
244 /* Get vnode for root device*/
245 if( bdevvp( rootdev, &rootvp))
246 panic("ffs_mountroot: can't setup bdevvp for root");
249 * FS specific handling
251 mp->mnt_flag |= MNT_RDONLY; /* XXX globally applicable?*/
256 if( ( err = ntfs_mountfs(rootvp, mp, &args, td)) != 0) {
257 /* fs specific cleanup (if any)*/
261 goto dostatfs; /* success*/
268 * Mounting non-root file system or updating a file system
272 /* copy in user arguments*/
273 err = copyin(data, (caddr_t)&args, sizeof (struct ntfs_args));
275 goto error_1; /* can't get arguments*/
278 * If updating, check whether changing from read-only to
279 * read/write; if there is no device name, that's all we do.
281 if (mp->mnt_flag & MNT_UPDATE) {
282 /* if not updating name...*/
283 if (args.fspec == 0) {
285 * Process export requests. Jumping to "success"
286 * will return the vfs_export() error code.
288 struct ntfsmount *ntm = VFSTONTFS(mp);
289 err = vfs_export(mp, &ntm->ntm_export, &args.export);
293 printf("ntfs_mount(): MNT_UPDATE not supported\n");
299 * Not an update, or updating the name: look up the name
300 * and verify that it refers to a sensible block device.
302 NDINIT(ndp, NAMEI_LOOKUP, CNP_FOLLOW, UIO_USERSPACE, args.fspec, td);
305 /* can't get devvp!*/
308 NDFREE(ndp, NDF_ONLY_PNBUF);
311 #if defined(__DragonFly__)
312 if (!vn_isdisk(devvp, &err))
315 if (devvp->v_type != VBLK) {
319 if (umajor(devvp->v_udev) >= nblkdev) {
324 if (mp->mnt_flag & MNT_UPDATE) {
332 if (devvp != ntmp->um_devvp)
333 err = EINVAL; /* needs translation */
337 * Update device name only on success
340 /* Save "mounted from" info for mount point (NULL pad)*/
341 copyinstr( args.fspec,
342 mp->mnt_stat.f_mntfromname,
345 bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
356 * Since this is a new mount, we want the names for
357 * the device and the mount point copied in. If an
358 * error occurs, the mountpoint is discarded by the
361 /* Save "last mounted on" info for mount point (NULL pad)*/
362 copyinstr( path, /* mount point*/
363 mp->mnt_stat.f_mntonname, /* save area*/
364 MNAMELEN - 1, /* max size*/
365 &size); /* real size*/
366 bzero( mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
368 /* Save "mounted from" info for mount point (NULL pad)*/
369 copyinstr( args.fspec, /* device name*/
370 mp->mnt_stat.f_mntfromname, /* save area*/
371 MNAMELEN - 1, /* max size*/
372 &size); /* real size*/
373 bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
375 err = ntfs_mountfs(devvp, mp, &args, td);
385 * Initialize FS stat information in mount struct; uses both
386 * mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
388 * This code is common to root and non-root mounts
390 (void)VFS_STATFS(mp, &mp->mnt_stat, td);
395 error_2: /* error with devvp held*/
397 /* release devvp before failing*/
400 error_1: /* no state to back out*/
407 * Common code for mount and mountroot
410 ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp,
414 struct ntfsmount *ntmp;
416 int error, ronly, ncount, i;
420 KKASSERT(td->td_proc);
421 cred = td->td_proc->p_ucred;
424 * Disallow multiple mounts of the same device.
425 * Disallow mounting of a device that is currently in use
426 * (except for root, which might share swap device for miniroot).
427 * Flush out any old buffers remaining from a previous use.
429 error = vfs_mountedon(devvp);
432 ncount = count_udev(devvp->v_udev);
433 #if defined(__DragonFly__)
437 if (ncount > 1 && devvp != rootvp)
439 #if defined(__DragonFly__)
440 VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, td);
441 error = vinvalbuf(devvp, V_SAVE, td, 0, 0);
442 VOP__UNLOCK(devvp, 0, td);
444 error = vinvalbuf(devvp, V_SAVE, td, 0, 0);
449 ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
450 VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, td);
451 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, td);
452 VOP__UNLOCK(devvp, 0, td);
459 error = bread(devvp, BBLOCK, BBSIZE, &bp);
462 ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK );
463 bzero( ntmp, sizeof *ntmp );
464 bcopy( bp->b_data, &ntmp->ntm_bootfile, sizeof(struct bootfile) );
468 if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
470 dprintf(("ntfs_mountfs: invalid boot block\n"));
475 int8_t cpr = ntmp->ntm_mftrecsz;
477 ntmp->ntm_bpmftrec = ntmp->ntm_spc * cpr;
479 ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps;
481 dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
482 ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
483 ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec));
484 dprintf(("ntfs_mountfs(): mftcn: 0x%x|0x%x\n",
485 (u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn));
487 ntmp->ntm_mountp = mp;
489 ntmp->ntm_devvp = devvp;
490 ntmp->ntm_uid = argsp->uid;
491 ntmp->ntm_gid = argsp->gid;
492 ntmp->ntm_mode = argsp->mode;
493 ntmp->ntm_flag = argsp->flag;
495 /* Copy in the 8-bit to Unicode conversion table */
496 if (argsp->flag & NTFSMNT_U2WTABLE) {
497 ntfs_82u_init(ntmp, argsp->u2w);
499 ntfs_82u_init(ntmp, NULL);
502 /* Initialize Unicode to 8-bit table from 8toU table */
503 ntfs_u28_init(ntmp, ntmp->ntm_82u);
505 mp->mnt_data = (qaddr_t)ntmp;
507 dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
508 (ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
509 (ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
510 ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode));
512 vfs_add_vnodeops(&mp->mnt_vn_ops, ntfs_vnodeop_entries);
515 * We read in some system nodes to do not allow
516 * reclaim them and to have everytime access to them.
519 int pi[3] = { NTFS_MFTINO, NTFS_ROOTINO, NTFS_BITMAPINO };
520 for (i=0; i<3; i++) {
521 error = VFS_VGET(mp, pi[i], &(ntmp->ntm_sysvn[pi[i]]));
524 ntmp->ntm_sysvn[pi[i]]->v_flag |= VSYSTEM;
525 vref(ntmp->ntm_sysvn[pi[i]]);
526 vput(ntmp->ntm_sysvn[pi[i]]);
530 /* read the Unicode lowercase --> uppercase translation table,
532 if ((error = ntfs_toupper_use(mp, ntmp)))
536 * Scan $BitMap and count free clusters
538 error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
543 * Read and translate to internal format attribute
551 error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp );
555 /* Count valid entries */
557 error = ntfs_readattr(ntmp, VTONT(vp),
559 num * sizeof(ad), sizeof(ad),
563 if (ad.ad_name[0] == 0)
567 /* Alloc memory for attribute definitions */
568 MALLOC(ntmp->ntm_ad, struct ntvattrdef *,
569 num * sizeof(struct ntvattrdef),
570 M_NTFSMNT, M_WAITOK);
572 ntmp->ntm_adnum = num;
574 /* Read them and translate */
576 error = ntfs_readattr(ntmp, VTONT(vp),
578 i * sizeof(ad), sizeof(ad),
584 ntmp->ntm_ad[i].ad_name[j] = ad.ad_name[j];
585 } while(ad.ad_name[j++]);
586 ntmp->ntm_ad[i].ad_namelen = j - 1;
587 ntmp->ntm_ad[i].ad_type = ad.ad_type;
593 #if defined(__DragonFly__)
594 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
595 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
597 mp->mnt_stat.f_fsid.val[0] = dev;
598 mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_NTFS);
600 mp->mnt_maxsymlinklen = 0;
601 mp->mnt_flag |= MNT_LOCAL;
602 dev->si_mountpoint = mp;
607 for(i=0;i<NTFS_SYSNODESNUM;i++)
608 if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
610 if (vflush(mp, 0, 0))
611 dprintf(("ntfs_mountfs: vflush failed\n"));
614 dev->si_mountpoint = NULL;
618 #if defined __NetBSD__
619 /* lock the device vnode before calling VOP_CLOSE() */
620 VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, td);
621 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, td);
622 VOP__UNLOCK(devvp, 0, td);
624 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, td);
630 #if !defined(__DragonFly__)
632 ntfs_start(struct mount *mp, int flags, struct thread *td)
639 ntfs_unmount(struct mount *mp, int mntflags, struct thread *td)
641 struct ntfsmount *ntmp;
642 int error, ronly = 0, flags, i;
644 dprintf(("ntfs_unmount: unmounting...\n"));
645 ntmp = VFSTONTFS(mp);
648 if(mntflags & MNT_FORCE)
651 dprintf(("ntfs_unmount: vflushing...\n"));
652 error = vflush(mp, 0, flags | SKIPSYSTEM);
654 printf("ntfs_unmount: vflush failed: %d\n",error);
658 /* Check if only system vnodes are rest */
659 for(i=0;i<NTFS_SYSNODESNUM;i++)
660 if((ntmp->ntm_sysvn[i]) &&
661 (ntmp->ntm_sysvn[i]->v_usecount > 1)) return (EBUSY);
663 /* Dereference all system vnodes */
664 for(i=0;i<NTFS_SYSNODESNUM;i++)
665 if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
667 /* vflush system vnodes */
668 error = vflush(mp, 0, flags);
670 printf("ntfs_unmount: vflush failed(sysnodes): %d\n",error);
672 /* Check if the type of device node isn't VBAD before
673 * touching v_specinfo. If the device vnode is revoked, the
674 * field is NULL and touching it causes null pointer derefercence.
676 if (ntmp->ntm_devvp->v_type != VBAD)
677 ntmp->ntm_devvp->v_rdev->si_mountpoint = NULL;
679 vinvalbuf(ntmp->ntm_devvp, V_SAVE, td, 0, 0);
681 #if defined(__NetBSD__)
682 /* lock the device vnode before calling VOP_CLOSE() */
683 VOP_LOCK(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY);
684 error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE, td);
685 VOP__UNLOCK(ntmp->ntm_devvp, 0, td);
687 error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE, td);
690 vrele(ntmp->ntm_devvp);
692 /* free the toupper table, if this has been last mounted ntfs volume */
693 ntfs_toupper_unuse();
695 dprintf(("ntfs_umount: freeing memory...\n"));
696 ntfs_u28_uninit(ntmp);
697 ntfs_82u_uninit(ntmp);
698 mp->mnt_data = (qaddr_t)0;
699 mp->mnt_flag &= ~MNT_LOCAL;
700 FREE(ntmp->ntm_ad, M_NTFSMNT);
701 FREE(ntmp, M_NTFSMNT);
706 ntfs_root(struct mount *mp, struct vnode **vpp)
711 dprintf(("ntfs_root(): sysvn: %p\n",
712 VFSTONTFS(mp)->ntm_sysvn[NTFS_ROOTINO]));
713 error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, &nvp);
715 printf("ntfs_root: VFS_VGET failed: %d\n",error);
723 #if !defined(__DragonFly__)
725 ntfs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
728 printf("\nntfs_quotactl():\n");
734 ntfs_calccfree(struct ntfsmount *ntmp, cn_t *cfreep)
742 vp = ntmp->ntm_sysvn[NTFS_BITMAPINO];
744 bmsize = VTOF(vp)->f_size;
746 MALLOC(tmp, u_int8_t *, bmsize, M_TEMP, M_WAITOK);
748 error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
749 0, bmsize, tmp, NULL);
753 for(i=0;i<bmsize;i++)
755 if(~tmp[i] & (1 << j)) cfree++;
764 ntfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
766 struct ntfsmount *ntmp = VFSTONTFS(mp);
767 u_int64_t mftsize,mftallocated;
769 dprintf(("ntfs_statfs():\n"));
771 mftsize = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_size;
772 mftallocated = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_allocated;
774 #if defined(__DragonFly__)
775 sbp->f_type = mp->mnt_vfc->vfc_typenum;
776 #elif defined(__NetBSD__)
779 sbp->f_type = MOUNT_NTFS;
781 sbp->f_bsize = ntmp->ntm_bps;
782 sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
783 sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
784 sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(ntmp->ntm_cfree);
785 sbp->f_ffree = sbp->f_bfree / ntmp->ntm_bpmftrec;
786 sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
788 if (sbp != &mp->mnt_stat) {
789 bcopy((caddr_t)mp->mnt_stat.f_mntonname,
790 (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
791 bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
792 (caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
794 sbp->f_flags = mp->mnt_flag;
796 strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
802 #if !defined(__DragonFly__)
804 ntfs_sync(struct mount *mp, int waitfor, struct ucred *cred, struct thread *td)
806 /*dprintf(("ntfs_sync():\n"));*/
813 ntfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
816 struct ntfid *ntfhp = (struct ntfid *)fhp;
819 ddprintf(("ntfs_fhtovp(): %d\n", ntfhp->ntfid_ino));
821 if ((error = VFS_VGET(mp, ntfhp->ntfid_ino, &nvp)) != 0) {
825 /* XXX as unlink/rmdir/mkdir/creat are not currently possible
826 * with NTFS, we don't need to check anything else for now */
833 ntfs_vptofh(struct vnode *vp, struct fid *fhp)
838 ddprintf(("ntfs_fhtovp(): %p\n", vp));
841 ntfhp = (struct ntfid *)fhp;
842 ntfhp->ntfid_len = sizeof(struct ntfid);
843 ntfhp->ntfid_ino = ntp->i_number;
844 /* ntfhp->ntfid_gen = ntp->i_gen; */
849 ntfs_vgetex(struct mount *mp, ino_t ino, u_int32_t attrtype, char *attrname,
850 u_long lkflags, u_long flags, struct thread *td,
854 struct ntfsmount *ntmp;
860 dprintf(("ntfs_vgetex: ino: %d, attr: 0x%x:%s, lkf: 0x%lx, f: 0x%lx\n",
861 ino, attrtype, attrname?attrname:"", (u_long)lkflags,
864 ntmp = VFSTONTFS(mp);
868 error = ntfs_ntlookup(ntmp, ino, &ip);
870 printf("ntfs_vget: ntfs_ntget failed\n");
874 /* It may be not initialized fully, so force load it */
875 if (!(flags & VG_DONTLOADIN) && !(ip->i_flag & IN_LOADED)) {
876 error = ntfs_loadntnode(ntmp, ip);
878 printf("ntfs_vget: CAN'T LOAD ATTRIBUTES FOR INO: %d\n",
885 error = ntfs_fget(ntmp, ip, attrtype, attrname, &fp);
887 printf("ntfs_vget: ntfs_fget failed\n");
893 if (!(flags & VG_DONTVALIDFN) && !(fp->f_flag & FN_VALID)) {
894 if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
895 (fp->f_attrtype == NTFS_A_DATA && fp->f_attrname == NULL)) {
897 } else if (flags & VG_EXT) {
899 fp->f_size = fp->f_allocated = 0;
903 error = ntfs_filesize(ntmp, fp,
904 &fp->f_size, &fp->f_allocated);
911 fp->f_flag |= FN_VALID;
915 VGET(FTOV(fp), lkflags, td);
921 error = getnewvnode(VT_NTFS, ntmp->ntm_mountp,
922 ntmp->ntm_mountp->mnt_vn_ops, &vp,
929 dprintf(("ntfs_vget: vnode: %p for ntnode: %d\n", vp,ino));
935 if (ino == NTFS_ROOTINO)
940 if (lkflags & LK_TYPE_MASK) {
941 KKASSERT((lkflags & LK_INTERLOCK) == 0);
942 error = VN_LOCK(vp, lkflags, td);
955 ntfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
957 return ntfs_vgetex(mp, ino, NTFS_A_DATA, NULL,
958 LK_EXCLUSIVE | LK_RETRY, 0, curthread, vpp);
961 #if defined(__DragonFly__)
962 static struct vfsops ntfs_vfsops = {
975 ntfs_nthash_uninit, /* see ntfs_ihash.c */
978 VFS_SET(ntfs_vfsops, ntfs, 0);
979 #elif defined(__NetBSD__)
980 extern struct vnodeopv_desc ntfs_vnodeop_opv_desc;
982 struct vnodeopv_desc *ntfs_vnodeopv_descs[] = {
983 &ntfs_vnodeop_opv_desc,
987 struct vfsops ntfs_vfsops = {
1003 ntfs_vnodeopv_descs,
1005 #else /* !NetBSD && !FreeBSD */
1006 static struct vfsops ntfs_vfsops = {
1019 VFS_SET(ntfs_vfsops, ntfs, MOUNT_NTFS, 0);