]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/ntfs/ntfs_vfsops.c
First version.
[FreeBSD/FreeBSD.git] / sys / ntfs / ntfs_vfsops.c
1 /*-
2  * Copyright (c) 1998, 1999 Semen Ustimenko
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *      $Id: ntfs_vfsops.c,v 1.9 1999/02/02 01:54:54 semen Exp $
27  */
28
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/namei.h>
33 #include <sys/conf.h>
34 #include <sys/proc.h>
35 #include <sys/kernel.h>
36 #include <sys/vnode.h>
37 #include <sys/mount.h>
38 #include <sys/buf.h>
39 #include <sys/fcntl.h>
40 #include <sys/malloc.h>
41
42 #include <vm/vm.h>
43 #include <vm/vm_param.h>
44 #include <vm/vm_prot.h>
45 #include <vm/vm_page.h>
46 #include <vm/vm_object.h>
47 #include <vm/vm_extern.h>
48
49 #include <miscfs/specfs/specdev.h>
50
51 /*#define NTFS_DEBUG 1*/
52 #include <ntfs/ntfs.h>
53 #include <ntfs/ntfs_inode.h>
54 #include <ntfs/ntfs_subr.h>
55 #include <ntfs/ntfs_extern.h>
56 #include <ntfs/ntfsmount.h>
57
58 #if __FreeBSD_version >= 300000
59 MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
60 MALLOC_DEFINE(M_NTFSNODE,"NTFS node",  "NTFS node information");
61 MALLOC_DEFINE(M_NTFSDIR,"NTFS dir",  "NTFS dir buffer");
62 #endif
63
64 static int      ntfs_mount __P((struct mount *, char *, caddr_t,
65                                 struct nameidata *, struct proc *));
66 static int      ntfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
67                                    struct proc *));
68 static int      ntfs_root __P((struct mount *, struct vnode **));
69 static int      ntfs_start __P((struct mount *, int, struct proc *));
70 static int      ntfs_statfs __P((struct mount *, struct statfs *,
71                                  struct proc *));
72 static int      ntfs_sync __P((struct mount *, int, struct ucred *,
73                                struct proc *));
74 static int      ntfs_unmount __P((struct mount *, int, struct proc *));
75 static int      ntfs_vget __P((struct mount *mp, ino_t ino,
76                                struct vnode **vpp));
77 static int      ntfs_mountfs __P((register struct vnode *, struct mount *, 
78                                   struct ntfs_args *, struct proc *));
79 static int      ntfs_vptofh __P((struct vnode *, struct fid *));
80
81 #if __FreeBSD_version >= 300000
82 static int      ntfs_init __P((struct vfsconf *));
83 static int      ntfs_fhtovp __P((struct mount *, struct fid *,
84                                  struct sockaddr *, struct vnode **,
85                                  int *, struct ucred **));
86 #else
87 static int      ntfs_init __P((void));
88 static int      ntfs_fhtovp __P((struct mount *, struct fid *,
89                                  struct mbuf *, struct vnode **,
90                                  int *, struct ucred **));
91 #endif
92
93 #if __FreeBSD_version >= 300000
94 static int
95 ntfs_init (
96         struct vfsconf *vcp )
97 #else
98 static int
99 ntfs_init ()
100 #endif
101 {
102         static first=1;
103
104         if(!first) return (0);
105         first = 1;
106
107         printf("ntfs_init(): \n");
108
109         ntfs_ihashinit();
110
111         return 0;
112 }
113
114 static int
115 ntfs_mount ( 
116         struct mount *mp,
117         char *path,
118         caddr_t data,
119         struct nameidata *ndp,
120         struct proc *p )
121 {
122         u_int           size;
123         int             err = 0;
124         struct vnode    *devvp;
125         struct ntfs_args args;
126
127         /*
128          * Use NULL path to flag a root mount
129          */
130         if( path == NULL) {
131                 /*
132                  ***
133                  * Mounting root file system
134                  ***
135                  */
136         
137                 /* Get vnode for root device*/
138                 if( bdevvp( rootdev, &rootvp))
139                         panic("ffs_mountroot: can't setup bdevvp for root");
140
141                 /*
142                  * FS specific handling
143                  */
144                 mp->mnt_flag |= MNT_RDONLY;     /* XXX globally applicable?*/
145
146                 /*
147                  * Attempt mount
148                  */
149                 if( ( err = ntfs_mountfs(rootvp, mp, &args, p)) != 0) {
150                         /* fs specific cleanup (if any)*/
151                         goto error_1;
152                 }
153
154                 goto dostatfs;          /* success*/
155
156         }
157
158         /*
159          ***
160          * Mounting non-root file system or updating a file system
161          ***
162          */
163
164         /* copy in user arguments*/
165         err = copyin(data, (caddr_t)&args, sizeof (struct ntfs_args));
166         if (err)
167                 goto error_1;           /* can't get arguments*/
168
169         /*
170          * If updating, check whether changing from read-only to
171          * read/write; if there is no device name, that's all we do.
172          */
173         if (mp->mnt_flag & MNT_UPDATE) {
174                 printf("ntfs_mount(): MNT_UPDATE not supported\n");
175                 err = EINVAL;
176                 goto error_1;
177
178 #if 0
179                 ump = VFSTOUFS(mp);
180                 fs = ump->um_fs;
181                 err = 0;
182                 if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
183                         flags = WRITECLOSE;
184                         if (mp->mnt_flag & MNT_FORCE)
185                                 flags |= FORCECLOSE;
186                         if (vfs_busy(mp)) {
187                                 err = EBUSY;
188                                 goto error_1;
189                         }
190                         err = ffs_flushfiles(mp, flags, p);
191                         vfs_unbusy(mp);
192                 }
193                 if (!err && (mp->mnt_flag & MNT_RELOAD))
194                         err = ffs_reload(mp, ndp->ni_cnd.cn_cred, p);
195                 if (err) {
196                         goto error_1;
197                 }
198                 if (fs->fs_ronly && (mp->mnt_flag & MNT_WANTRDWR)) {
199                         if (!fs->fs_clean) {
200                                 if (mp->mnt_flag & MNT_FORCE) {
201                                         printf("WARNING: %s was not properly dismounted.\n",fs->fs_fsmnt);
202                                 } else {
203                                         printf("WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck.\n",
204                                             fs->fs_fsmnt);
205                                         err = EPERM;
206                                         goto error_1;
207                                 }
208                         }
209                         fs->fs_ronly = 0;
210                 }
211                 if (fs->fs_ronly == 0) {
212                         fs->fs_clean = 0;
213                         ffs_sbupdate(ump, MNT_WAIT);
214                 }
215                 /* if not updating name...*/
216                 if (args.fspec == 0) {
217                         /*
218                          * Process export requests.  Jumping to "success"
219                          * will return the vfs_export() error code.
220                          */
221                         err = vfs_export(mp, &ump->um_export, &args.export);
222                         goto success;
223                 }
224 #endif
225         }
226
227         /*
228          * Not an update, or updating the name: look up the name
229          * and verify that it refers to a sensible block device.
230          */
231         NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
232         err = namei(ndp);
233         if (err) {
234                 /* can't get devvp!*/
235                 goto error_1;
236         }
237
238         devvp = ndp->ni_vp;
239
240         if (devvp->v_type != VBLK) {
241                 err = ENOTBLK;
242                 goto error_2;
243         }
244         if (major(devvp->v_rdev) >= nblkdev) {
245                 err = ENXIO;
246                 goto error_2;
247         }
248         if (mp->mnt_flag & MNT_UPDATE) {
249 #if 0
250                 /*
251                  ********************
252                  * UPDATE
253                  ********************
254                  */
255
256                 if (devvp != ntmp->um_devvp)
257                         err = EINVAL;   /* needs translation */
258                 else
259                         vrele(devvp);
260                 /*
261                  * Update device name only on success
262                  */
263                 if( !err) {
264                         /* Save "mounted from" info for mount point (NULL pad)*/
265                         copyinstr(      args.fspec,
266                                         mp->mnt_stat.f_mntfromname,
267                                         MNAMELEN - 1,
268                                         &size);
269                         bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
270                 }
271 #endif
272         } else {
273                 /*
274                  ********************
275                  * NEW MOUNT
276                  ********************
277                  */
278
279                 /*
280                  * Since this is a new mount, we want the names for
281                  * the device and the mount point copied in.  If an
282                  * error occurs,  the mountpoint is discarded by the
283                  * upper level code.
284                  */
285                 /* Save "last mounted on" info for mount point (NULL pad)*/
286                 copyinstr(      path,                           /* mount point*/
287                                 mp->mnt_stat.f_mntonname,       /* save area*/
288                                 MNAMELEN - 1,                   /* max size*/
289                                 &size);                         /* real size*/
290                 bzero( mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
291
292                 /* Save "mounted from" info for mount point (NULL pad)*/
293                 copyinstr(      args.fspec,                     /* device name*/
294                                 mp->mnt_stat.f_mntfromname,     /* save area*/
295                                 MNAMELEN - 1,                   /* max size*/
296                                 &size);                         /* real size*/
297                 bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
298
299                 err = ntfs_mountfs(devvp, mp, &args, p);
300         }
301         if (err) {
302                 goto error_2;
303         }
304
305 dostatfs:
306         /*
307          * Initialize FS stat information in mount struct; uses both
308          * mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
309          *
310          * This code is common to root and non-root mounts
311          */
312         (void)VFS_STATFS(mp, &mp->mnt_stat, p);
313
314         goto success;
315
316
317 error_2:        /* error with devvp held*/
318
319         /* release devvp before failing*/
320         vrele(devvp);
321
322 error_1:        /* no state to back out*/
323
324 success:
325         return( err);
326 }
327
328 /*
329  * Common code for mount and mountroot
330  */
331 int
332 ntfs_mountfs(devvp, mp, argsp, p)
333         register struct vnode *devvp;
334         struct mount *mp;
335         struct ntfs_args *argsp;
336         struct proc *p;
337 {
338         struct buf *bp;
339         struct ntfsmount *ntmp;
340         dev_t dev = devvp->v_rdev;
341         int error, ronly, ncount, i;
342         struct vnode *vp;
343
344         /*
345          * Disallow multiple mounts of the same device.
346          * Disallow mounting of a device that is currently in use
347          * (except for root, which might share swap device for miniroot).
348          * Flush out any old buffers remaining from a previous use.
349          */
350         error = vfs_mountedon(devvp);
351         if (error)
352                 return (error);
353         ncount = vcount(devvp);
354         if (devvp->v_object)
355                 ncount -= 1;
356         if (ncount > 1 && devvp != rootvp)
357                 return (EBUSY);
358 #if __FreeBSD_version >= 300000
359         vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
360         error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
361         VOP_UNLOCK(devvp, 0, p);
362 #else
363         error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
364 #endif
365         if (error)
366                 return (error);
367
368         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
369         error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
370         if (error)
371                 return (error);
372
373         bp = NULL;
374
375         error = bread(devvp, BBLOCK, BBSIZE, NOCRED, &bp);
376         if (error)
377                 goto out;
378         ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK );
379         bzero( ntmp, sizeof *ntmp );
380         bcopy( bp->b_data, &ntmp->ntm_bootfile, sizeof(struct bootfile) );
381         brelse( bp );
382         bp = NULL;
383
384         {
385                 int8_t cpr = ntmp->ntm_mftrecsz;
386                 if( cpr > 0 )
387                         ntmp->ntm_bpmftrec = ntmp->ntm_spc * cpr;
388                 else
389                         ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps;
390         }
391         printf("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
392                 ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
393                 ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec);
394         printf("ntfs_mountfs(): mftcn: 0x%x|0x%x\n",
395                 (u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn);
396
397         ntmp->ntm_mountp = mp;
398         ntmp->ntm_dev = dev;
399         ntmp->ntm_devvp = devvp;
400         ntmp->ntm_uid = argsp->uid;
401         ntmp->ntm_gid = argsp->gid;
402         ntmp->ntm_mode = argsp->mode;
403         ntmp->ntm_flag = argsp->flag;
404         mp->mnt_data = (qaddr_t)ntmp;
405
406         printf("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
407                 (ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
408                 (ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
409                 ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode);
410
411         printf("ntfs_mountfs(): reading system nodes...\n");
412         {
413                 i = NTFS_MFTINO;
414                 error = VFS_VGET(mp, i, &ntmp->ntm_sysvn[i]);
415                 if(error)
416                         goto out1;
417                 VREF(ntmp->ntm_sysvn[i]);
418                 vput(ntmp->ntm_sysvn[i]);
419         }
420
421         MALLOC( ntmp->ntm_upcase, wchar *, 65536 * sizeof(wchar),
422                 M_NTFSMNT, M_WAITOK);
423
424         printf("ntfs_mountfs(): opening $UpCase\n");
425         error = VFS_VGET(mp, NTFS_UPCASEINO, &vp );
426         if(error) 
427                 goto out1;
428         printf("ntfs_mountfs(): reading $UpCase\n");
429         error = ntfs_breadattr( ntmp, VTONT(vp), NTFS_A_DATA, NULL,
430                         0, 65536*sizeof(wchar), ntmp->ntm_upcase);
431         printf("ntfs_mountfs(): closing $UpCase\n");
432         vput(vp);
433         if(error) 
434                 goto out1;
435
436         {
437                 int num,j;
438                 struct attrdef ad;
439
440                 printf("ntfs_mountfs(): opening $AttrDef\n");
441                 error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp );
442                 if(error) 
443                         goto out1;
444
445                 for(num=0;;num++) {
446                         error = ntfs_breadattr(ntmp, VTONT(vp),
447                                         NTFS_A_DATA, NULL,
448                                         num * sizeof(ad), sizeof(ad),
449                                         &ad);
450                         if (error)
451                                 goto out1;
452                         if (ad.ad_name[0] == 0)
453                                 break;
454                 }
455                 printf("ntfs_mountfs(): reading %d attrdefs\n",num);
456
457                 MALLOC(ntmp->ntm_ad, struct ntvattrdef *,
458                         num * sizeof(struct ntvattrdef),
459                         M_NTFSMNT, M_WAITOK);
460
461                 ntmp->ntm_adnum = num;
462
463                 for(i=0;i<num;i++){
464                         error = ntfs_breadattr(ntmp, VTONT(vp),
465                                         NTFS_A_DATA, NULL,
466                                         i * sizeof(ad), sizeof(ad),
467                                         &ad);
468                         if (error)
469                                 goto out1;
470                         j = 0;
471                         do {
472                                 ntmp->ntm_ad[i].ad_name[j] = ad.ad_name[j];
473                         } while(ad.ad_name[j++]);
474                         ntmp->ntm_ad[i].ad_namelen = j - 1;
475                         ntmp->ntm_ad[i].ad_type = ad.ad_type;
476                         printf("ntfs_mountfs(): attribute: %s, type: 0x%x\n",
477                                 ntmp->ntm_ad[i].ad_name,
478                                 ntmp->ntm_ad[i].ad_type);
479                 }
480                 printf("ntfs_mountfs(): closing $AttrDef\n");
481                 vput(vp);
482         }
483
484         mp->mnt_stat.f_fsid.val[0] = (long)dev;
485 #if __FreeBSD_version >= 300000
486         mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
487 #else
488         mp->mnt_stat.f_fsid.val[1] = MOUNT_NTFS;
489 #endif
490         mp->mnt_maxsymlinklen = 0;
491         mp->mnt_flag |= MNT_LOCAL;
492 #if __FreeBSD_version >= 300000
493         devvp->v_specmountpoint = mp;
494 #else
495         devvp->v_specflags |= SI_MOUNTEDON;
496 #endif
497         return (0);
498 out1:
499         for(i=0;i<NTFS_SYSNODESNUM;i++)
500                 if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
501 out:
502 #if __FreeBSD_version >= 300000
503         devvp->v_specmountpoint = NULL;
504 #else
505         devvp->v_specflags |= SI_MOUNTEDON;
506 #endif
507         if (bp)
508                 brelse(bp);
509         (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
510         return (error);
511 }
512
513 static int
514 ntfs_start (
515         struct mount *mp,
516         int flags,
517         struct proc *p )
518 {
519         printf("\nntfs_start():\n");
520         return (0);
521 }
522
523 static int
524 ntfs_unmount( 
525         struct mount *mp,
526         int mntflags,
527         struct proc *p)
528 {
529         register struct ntfsmount *ntmp;
530         int error, ronly = 0, flags, i;
531
532         printf("ntfs_unmount: unmounting...\n");
533         ntmp = VFSTONTFS(mp);
534
535         flags = 0;
536         if(mntflags & MNT_FORCE)
537                 flags |= FORCECLOSE;
538
539         printf("ntfs_unmount: vflushing...\n");
540         for(i=0;i<NTFS_SYSNODESNUM;i++)
541                  if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
542         error = vflush(mp,NULLVP,flags);
543         if (error) {
544                 printf("ntfs_unmount: vflush failed: %d\n",error);
545                 return (error);
546         }
547
548 #if __FreeBSD_version >= 300000
549         ntmp->ntm_devvp->v_specmountpoint = NULL;
550 #else
551         ntmp->ntm_devvp->v_specflags &= ~SI_MOUNTEDON;
552
553         VOP_LOCK(ntmp->ntm_devvp);
554         vnode_pager_uncache(ntmp->ntm_devvp);
555         VOP_UNLOCK(ntmp->ntm_devvp);
556 #endif
557
558         vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, p, 0, 0);
559         error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
560                 NOCRED, p);
561
562         vrele(ntmp->ntm_devvp);
563
564         printf("ntfs_umount: freeing memory...\n");
565         mp->mnt_data = (qaddr_t)0;
566         mp->mnt_flag &= ~MNT_LOCAL;
567         FREE(ntmp->ntm_ad, M_NTFSMNT);
568         FREE(ntmp->ntm_upcase, M_NTFSMNT);
569         FREE(ntmp, M_NTFSMNT);
570         return (error);
571 }
572
573 static int
574 ntfs_root(
575         struct mount *mp,
576         struct vnode **vpp )
577 {
578         struct vnode *nvp;
579         int error = 0;
580
581         dprintf(("ntfs_root():\n"));
582         error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, &nvp);
583         if(error) {
584                 printf("ntfs_root: VFS_VGET failed: %d\n",error);
585                 return (error);
586         }
587
588         *vpp = nvp;
589         return (0);
590 }
591
592 static int
593 ntfs_quotactl ( 
594         struct mount *mp,
595         int cmds,
596         uid_t uid,
597         caddr_t arg,
598         struct proc *p)
599 {
600         printf("\nntfs_quotactl():\n");
601         return EOPNOTSUPP;
602 }
603
604 static int
605 ntfs_statfs(
606         struct mount *mp,
607         struct statfs *sbp,
608         struct proc *p)
609 {
610         struct ntfsmount *ntmp = VFSTONTFS(mp);
611         u_int64_t mftsize,mftallocated,bmsize,bmallocated;
612         struct vnode *vp;
613         int error,j,i;
614         u_int8_t *tmp;
615
616         dprintf(("ntfs_statfs():"));
617
618         ntfs_filesize(ntmp, VTONT(ntmp->ntm_sysvn[NTFS_MFTINO]),
619                       &mftsize, &mftallocated);
620
621         error = VFS_VGET(mp, NTFS_BITMAPINO, &vp);
622         if(error)
623                 return (error);
624
625         ntfs_filesize(ntmp, VTONT(vp), &bmsize, &bmallocated);
626
627         MALLOC(tmp, u_int8_t *, bmsize,M_TEMP, M_WAITOK);
628
629         error = ntfs_breadattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
630                                0, bmsize, tmp);
631         if(error) {
632                 FREE(tmp, M_TEMP);
633                 vput(vp);
634                 return (error);
635         }
636         vput(vp);
637
638         sbp->f_bfree = 0;
639         for(i=0;i<bmsize;i++)
640                 for(j=0;j<8;j++)
641                         if(~tmp[i] & (1 << j)) sbp->f_bfree++;
642
643         FREE(tmp, M_TEMP);
644
645 #if __FreeBSD_version >= 300000
646         sbp->f_type = mp->mnt_vfc->vfc_typenum;
647 #else
648         sbp->f_type = MOUNT_NTFS;
649 #endif
650         sbp->f_bsize = ntmp->ntm_bps;
651         sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
652         sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
653         sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(sbp->f_bfree);
654         sbp->f_ffree = sbp->f_bfree / ntmp->ntm_bpmftrec;
655         sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
656                        sbp->f_ffree;
657         if (sbp != &mp->mnt_stat) {
658                 bcopy((caddr_t)mp->mnt_stat.f_mntonname,
659                         (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
660                 bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
661                         (caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
662         }
663         
664         return (0);
665 }
666
667 static int
668 ntfs_sync (
669         struct mount *mp,
670         int waitfor,
671         struct ucred *cred,
672         struct proc *p)
673 {
674         /*dprintf(("ntfs_sync():\n"));*/
675         return (0);
676 }
677
678 #if __FreeBSD_version >= 300000
679 static int
680 ntfs_fhtovp(
681         struct mount *mp,
682         struct fid *fhp,
683         struct sockaddr *nam,
684         struct vnode **vpp,
685         int *exflagsp,
686         struct ucred **credanonp)
687 #else
688 static int
689 ntfs_fhtovp(
690         struct mount *mp,
691         struct fid *fhp,
692         struct mbuf *nam,
693         struct vnode **vpp,
694         int *exflagsp,
695         struct ucred **credanonp)
696 #endif
697 {
698         printf("\ntfs_fhtovp():\n");
699         return 0;
700 }
701
702 static int
703 ntfs_vptofh(
704         struct vnode *vp,
705         struct fid *fhp)
706 {
707         printf("ntfs_vptofh():\n");
708         return EOPNOTSUPP;
709 }
710
711 static int
712 ntfs_vget(
713         struct mount *mp,
714         ino_t ino,
715         struct vnode **vpp) 
716 {
717         int error=0;
718         struct vnode *vp;
719         register struct ntfsmount *ntmp;
720         struct ntnode *ip;
721
722         dprintf(("ntfs_vget: ino: %d\n",ino));
723
724         ntmp = VFSTONTFS(mp);
725
726         *vpp = NULL;            
727         
728         dprintf(("ntfs_ntvget: ihashlookup\n"));
729         if( (*vpp = ntfs_ihashget(ntmp->ntm_dev, ino)) != NULL )
730                 return (0);
731
732         error = ntfs_ntget(ntmp,ino,&ip);
733         if(error) {
734                 printf("ntfs_vget: ntfs_ntget failed\n");
735                 return (error);
736         }
737
738         error = getnewvnode(VT_NTFS, ntmp->ntm_mountp, ntfs_vnodeop_p, &vp);
739         if(error) {
740                 /* XXX */
741                 ntfs_ntrele(ip);
742                 return (error);
743         }
744         ip->i_vnode = vp;
745         vp->v_data = ip;
746         vp->v_type = ip->i_type;        
747
748         ntfs_ihashins(ip);
749
750         VREF(ip->i_devvp);
751
752         error = ntfs_loadnode(ntmp, ip);
753         if(error) {
754                 printf("ntfs_vget: CAN'T LOAD ATTRIBUTES FOR INO: %d\n",
755                        ip->i_number);
756                 vput(vp);
757                 return (error);
758         }
759
760         *vpp = vp;
761
762         return (0);
763 }
764
765 #if __FreeBSD_version >= 300000
766 static struct vfsops ntfs_vfsops = {
767         ntfs_mount,
768         ntfs_start,
769         ntfs_unmount,
770         ntfs_root,
771         ntfs_quotactl,
772         ntfs_statfs,
773         ntfs_sync,
774         ntfs_vget,
775         ntfs_fhtovp,
776         ntfs_vptofh,
777         ntfs_init,
778         NULL,
779         NULL
780 };
781 VFS_SET(ntfs_vfsops, ntfs, 0);
782 #else
783 static struct vfsops ntfs_vfsops = {
784         ntfs_mount,
785         ntfs_start,
786         ntfs_unmount,
787         ntfs_root,
788         ntfs_quotactl,
789         ntfs_statfs,
790         ntfs_sync,
791         ntfs_vget,
792         ntfs_fhtovp,
793         ntfs_vptofh,
794         ntfs_init,
795 };
796
797 VFS_SET(ntfs_vfsops, ntfs, MOUNT_NTFS, 0);
798 #endif
799
800