Merge from vendor branch ZLIB:
[dragonfly.git] / sys / vfs / hpfs / hpfs_vfsops.c
1 /*-
2  * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
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  * $FreeBSD: src/sys/fs/hpfs/hpfs_vfsops.c,v 1.3.2.2 2001/12/25 01:44:45 dillon Exp $
27  * $DragonFly: src/sys/vfs/hpfs/hpfs_vfsops.c,v 1.22 2004/10/12 19:20:56 dillon Exp $
28  */
29
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/namei.h>
34 #include <sys/conf.h>
35 #include <sys/proc.h>
36 #include <sys/kernel.h>
37 #include <sys/vnode.h>
38 #include <sys/mount.h>
39 #include <sys/buf.h>
40 #include <sys/fcntl.h>
41 #include <sys/malloc.h>
42
43 #include <vm/vm.h>
44 #include <vm/vm_param.h>
45 #if defined(__NetBSD__)
46 #include <vm/vm_prot.h>
47 #endif
48 #include <vm/vm_page.h>
49 #include <vm/vm_object.h>
50 #include <vm/vm_extern.h>
51 #include <sys/buf2.h>
52
53 #if defined(__NetBSD__)
54 #include <miscfs/specfs/specdev.h>
55 #endif
56
57 #include "hpfs.h"
58 #include "hpfsmount.h"
59 #include "hpfs_subr.h"
60
61 extern struct vnodeopv_entry_desc hpfs_vnodeop_entries[];
62
63 #if defined(__DragonFly__)
64 MALLOC_DEFINE(M_HPFSMNT, "HPFS mount", "HPFS mount structure");
65 MALLOC_DEFINE(M_HPFSNO, "HPFS node", "HPFS node structure");
66 #endif
67
68 static int      hpfs_root (struct mount *, struct vnode **);
69 static int      hpfs_statfs (struct mount *, struct statfs *,
70                                  struct thread *);
71 static int      hpfs_unmount (struct mount *, int, struct thread *);
72 static int      hpfs_vget (struct mount *mp, ino_t ino,
73                                struct vnode **vpp);
74 static int      hpfs_mountfs (struct vnode *, struct mount *, 
75                                   struct hpfs_args *, struct thread *);
76 static int      hpfs_vptofh (struct vnode *, struct fid *);
77 static int      hpfs_fhtovp (struct mount *, struct fid *,
78                                  struct vnode **);
79
80 #if !defined(__DragonFly__)
81 static int      hpfs_quotactl (struct mount *, int, uid_t, caddr_t,
82                                    struct proc *);
83 static int      hpfs_start (struct mount *, int, struct proc *);
84 static int      hpfs_sync (struct mount *, int, struct ucred *,
85                                struct proc *);
86 #endif
87
88 #if defined(__DragonFly__)
89 struct sockaddr;
90 static int      hpfs_mount (struct mount *, char *, caddr_t, struct thread *);
91 static int      hpfs_init (struct vfsconf *);
92 static int      hpfs_checkexp (struct mount *, struct sockaddr *,
93                                    int *, struct ucred **);
94 #else /* defined(__NetBSD__) */
95 static int      hpfs_mount (struct mount *, const char *, void *,
96                                 struct nameidata *, struct proc *);
97 static void     hpfs_init (void);
98 static int      hpfs_mountroot (void);
99 static int      hpfs_sysctl (int *, u_int, void *, size_t *, void *,
100                                  size_t, struct proc *);
101 static int      hpfs_checkexp (struct mount *, struct mbuf *,
102                                    int *, struct ucred **);
103 #endif
104
105 /*ARGSUSED*/
106 static int
107 hpfs_checkexp(struct mount *mp,
108 #if defined(__DragonFly__)
109               struct sockaddr *nam,
110 #else /* defined(__NetBSD__) */
111               struct mbuf *nam,
112 #endif
113               int *exflagsp, struct ucred **credanonp)
114 {
115         struct netcred *np;
116         struct hpfsmount *hpm = VFSTOHPFS(mp);
117
118         /*
119          * Get the export permission structure for this <mp, client> tuple.
120          */
121         np = vfs_export_lookup(mp, &hpm->hpm_export, nam);
122         if (np == NULL)
123                 return (EACCES);
124
125         *exflagsp = np->netc_exflags;
126         *credanonp = &np->netc_anon;
127         return (0);
128 }
129
130 #if !defined(__DragonFly__)
131 /*ARGSUSED*/
132 static int
133 hpfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
134             size_t newlen, struct thread *td)
135 {
136         return (EINVAL);
137 }
138
139 static int
140 hpfs_mountroot(void)
141 {
142         return (EINVAL);
143 }
144 #endif
145
146 #if defined(__DragonFly__)
147 static int
148 hpfs_init(struct vfsconf *vcp)
149 #else /* defined(__NetBSD__) */
150 static void
151 hpfs_init(void)
152 #endif
153 {
154         dprintf(("hpfs_init():\n"));
155         
156         hpfs_hphashinit();
157 #if defined(__DragonFly__)
158         return 0;
159 #endif
160 }
161
162 static int
163 hpfs_mount(struct mount *mp,
164 #if defined(__DragonFly__)
165            char *path, caddr_t data,
166 #else /* defined(__NetBSD__) */
167            const char *path, void *data,
168 #endif
169            struct thread *td)
170 {
171         u_int           size;
172         int             err = 0;
173         struct vnode    *devvp;
174         struct hpfs_args args;
175         struct hpfsmount *hpmp = 0;
176         struct nameidata nd;
177
178         dprintf(("hpfs_mount():\n"));
179         /*
180          ***
181          * Mounting non-root file system or updating a file system
182          ***
183          */
184
185         /* copy in user arguments*/
186         err = copyin(data, (caddr_t)&args, sizeof (struct hpfs_args));
187         if (err)
188                 goto error_1;           /* can't get arguments*/
189
190         /*
191          * If updating, check whether changing from read-only to
192          * read/write; if there is no device name, that's all we do.
193          */
194         if (mp->mnt_flag & MNT_UPDATE) {
195                 dprintf(("hpfs_mount: MNT_UPDATE: "));
196
197                 hpmp = VFSTOHPFS(mp);
198
199                 if (args.fspec == 0) {
200                         dprintf(("export 0x%x\n",args.export.ex_flags));
201                         err = vfs_export(mp, &hpmp->hpm_export, &args.export);
202                         if (err) {
203                                 printf("hpfs_mount: vfs_export failed %d\n",
204                                         err);
205                         }
206                         goto success;
207                 } else {
208                         dprintf(("name [FAILED]\n"));
209                         err = EINVAL;
210                         goto success;
211                 }
212                 dprintf(("\n"));
213         }
214
215         /*
216          * Not an update, or updating the name: look up the name
217          * and verify that it refers to a sensible block device.
218          */
219         NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_USERSPACE, args.fspec, td);
220         err = namei(&nd);
221         if (err) {
222                 /* can't get devvp!*/
223                 goto error_1;
224         }
225
226         devvp = nd.ni_vp;
227         /* XXX NDFREE */
228
229 #if defined(__DragonFly__)
230         if (!vn_isdisk(devvp, &err)) 
231                 goto error_2;
232 #else /* defined(__NetBSD__) */
233         if (devvp->v_type != VBLK) {
234                 err = ENOTBLK;
235                 goto error_2;
236         }
237         if (umajor(devvp->v_udev) >= nblkdev) {
238                 err = ENXIO;
239                 goto error_2;
240         }
241 #endif
242
243         /*
244          ********************
245          * NEW MOUNT
246          ********************
247          */
248
249         /*
250          * Since this is a new mount, we want the names for
251          * the device and the mount point copied in.  If an
252          * error occurs,  the mountpoint is discarded by the
253          * upper level code.
254          */
255         /* Save "last mounted on" info for mount point (NULL pad)*/
256         copyinstr(      path,                           /* mount point*/
257                         mp->mnt_stat.f_mntonname,       /* save area*/
258                         MNAMELEN - 1,                   /* max size*/
259                         &size);                         /* real size*/
260         bzero( mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
261
262         /* Save "mounted from" info for mount point (NULL pad)*/
263         copyinstr(      args.fspec,                     /* device name*/
264                         mp->mnt_stat.f_mntfromname,     /* save area*/
265                         MNAMELEN - 1,                   /* max size*/
266                         &size);                         /* real size*/
267         bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
268
269         err = hpfs_mountfs(devvp, mp, &args, td);
270         if (err)
271                 goto error_2;
272
273         /*
274          * Initialize FS stat information in mount struct; uses both
275          * mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
276          *
277          * This code is common to root and non-root mounts
278          */
279         (void)VFS_STATFS(mp, &mp->mnt_stat, td);
280
281         goto success;
282
283
284 error_2:        /* error with devvp held*/
285
286         /* release devvp before failing*/
287         vrele(devvp);
288
289 error_1:        /* no state to back out*/
290
291 success:
292         return( err);
293 }
294
295 /*
296  * Common code for mount and mountroot
297  */
298 int
299 hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp,
300              struct thread *td)
301 {
302         int error, ncount, ronly;
303         struct sublock *sup;
304         struct spblock *spp;
305         struct hpfsmount *hpmp;
306         struct buf *bp = NULL;
307         struct vnode *vp;
308         dev_t dev;
309
310         dprintf(("hpfs_mountfs():\n"));
311         /*
312          * Disallow multiple mounts of the same device.
313          * Disallow mounting of a device that is currently in use
314          * (except for root, which might share swap device for miniroot).
315          * Flush out any old buffers remaining from a previous use.
316          */
317         error = vfs_mountedon(devvp);
318         if (error)
319                 return (error);
320         ncount = count_udev(devvp->v_udev);
321 #if defined(__DragonFly__)
322         if (devvp->v_object)
323                 ncount -= 1;
324 #endif
325         if (ncount > 0)
326                 return (EBUSY);
327
328 #if defined(__DragonFly__)
329         VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, td);
330         error = vinvalbuf(devvp, V_SAVE, td, 0, 0);
331         VOP__UNLOCK(devvp, 0, td);
332 #else
333         error = vinvalbuf(devvp, V_SAVE, td, 0, 0);
334 #endif
335         if (error)
336                 return (error);
337
338         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
339         VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, td);
340         error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, td);
341         VOP__UNLOCK(devvp, 0, td);
342         if (error)
343                 return (error);
344         dev = devvp->v_rdev;
345
346         /*
347          * Do actual mount
348          */
349         hpmp = malloc(sizeof(struct hpfsmount), M_HPFSMNT, M_WAITOK);
350         bzero(hpmp, sizeof(struct hpfsmount));
351
352         /* Read in SuperBlock */
353         error = bread(devvp, SUBLOCK, SUSIZE, &bp);
354         if (error)
355                 goto failed;
356         bcopy(bp->b_data, &hpmp->hpm_su, sizeof(struct sublock));
357         brelse(bp); bp = NULL;
358
359         /* Read in SpareBlock */
360         error = bread(devvp, SPBLOCK, SPSIZE, &bp);
361         if (error)
362                 goto failed;
363         bcopy(bp->b_data, &hpmp->hpm_sp, sizeof(struct spblock));
364         brelse(bp); bp = NULL;
365
366         sup = &hpmp->hpm_su;
367         spp = &hpmp->hpm_sp;
368
369         /* Check magic */
370         if (sup->su_magic != SU_MAGIC) {
371                 printf("hpfs_mountfs: SuperBlock MAGIC DOESN'T MATCH\n");
372                 error = EINVAL;
373                 goto failed;
374         }
375         if (spp->sp_magic != SP_MAGIC) {
376                 printf("hpfs_mountfs: SpareBlock MAGIC DOESN'T MATCH\n");
377                 error = EINVAL;
378                 goto failed;
379         }
380
381         mp->mnt_data = (qaddr_t)hpmp;
382         hpmp->hpm_devvp = devvp;
383         hpmp->hpm_dev = dev;
384         hpmp->hpm_mp = mp;
385         hpmp->hpm_uid = argsp->uid;
386         hpmp->hpm_gid = argsp->gid;
387         hpmp->hpm_mode = argsp->mode;
388
389         error = hpfs_bminit(hpmp);
390         if (error)
391                 goto failed;
392
393         error = hpfs_cpinit(hpmp, argsp);
394         if (error) {
395                 hpfs_bmdeinit(hpmp);
396                 goto failed;
397         }
398         vfs_add_vnodeops(&mp->mnt_vn_ops, hpfs_vnodeop_entries);
399
400         error = hpfs_root(mp, &vp);
401         if (error) {
402                 hpfs_cpdeinit(hpmp);
403                 hpfs_bmdeinit(hpmp);
404                 goto failed;
405         }
406
407         vput(vp);
408
409 #if defined(__DragonFly__)
410         mp->mnt_stat.f_fsid.val[0] = (long)dev2udev(dev);
411         mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
412 #else
413         mp->mnt_stat.f_fsid.val[0] = (long)dev;
414         mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_HPFS);
415 #endif
416         mp->mnt_maxsymlinklen = 0;
417         mp->mnt_flag |= MNT_LOCAL;
418         dev->si_mountpoint = mp;
419         return (0);
420
421 failed:
422         if (bp)
423                 brelse (bp);
424         mp->mnt_data = (qaddr_t)NULL;
425 #if defined(__DragonFly__)
426         dev->si_mountpoint = NULL;
427 #else
428         devvp->v_specflags &= ~SI_MOUNTEDON;
429 #endif
430         (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, td);
431         return (error);
432 }
433
434 #if !defined(__DragonFly__)
435 static int
436 hpfs_start(struct mount *mp, int flags, struct thread *td)
437 {
438         return (0);
439 }
440 #endif
441
442 static int
443 hpfs_unmount(struct mount *mp, int mntflags, struct thread *td)
444 {
445         int error, flags, ronly;
446         struct hpfsmount *hpmp = VFSTOHPFS(mp);
447
448         dprintf(("hpfs_unmount():\n"));
449
450         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
451
452         flags = 0;
453         if(mntflags & MNT_FORCE)
454                 flags |= FORCECLOSE;
455
456         dprintf(("hpfs_unmount: vflushing...\n"));
457         
458         error = vflush(mp, 0, flags);
459         if (error) {
460                 printf("hpfs_unmount: vflush failed: %d\n",error);
461                 return (error);
462         }
463
464 #if defined(__DragonFly__)
465         hpmp->hpm_devvp->v_rdev->si_mountpoint = NULL;
466 #else
467         hpmp->hpm_devvp->v_specflags &= ~SI_MOUNTEDON;
468 #endif
469
470         vinvalbuf(hpmp->hpm_devvp, V_SAVE, td, 0, 0);
471         error = VOP_CLOSE(hpmp->hpm_devvp, ronly ? FREAD : FREAD|FWRITE, td);
472
473         vrele(hpmp->hpm_devvp);
474
475         dprintf(("hpfs_umount: freeing memory...\n"));
476         hpfs_cpdeinit(hpmp);
477         hpfs_bmdeinit(hpmp);
478         mp->mnt_data = (qaddr_t)0;
479         mp->mnt_flag &= ~MNT_LOCAL;
480         FREE(hpmp, M_HPFSMNT);
481
482         return (0);
483 }
484
485 static int
486 hpfs_root(struct mount *mp, struct vnode **vpp)
487 {
488         int error = 0;
489         struct hpfsmount *hpmp = VFSTOHPFS(mp);
490
491         dprintf(("hpfs_root():\n"));
492         error = VFS_VGET(mp, (ino_t)hpmp->hpm_su.su_rootfno, vpp);
493         if(error) {
494                 printf("hpfs_root: VFS_VGET failed: %d\n",error);
495                 return (error);
496         }
497
498         return (error);
499 }
500
501 static int
502 hpfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
503 {
504         struct hpfsmount *hpmp = VFSTOHPFS(mp);
505
506         dprintf(("hpfs_statfs(): HPFS%d.%d\n",
507                 hpmp->hpm_su.su_hpfsver, hpmp->hpm_su.su_fnctver));
508
509 #if defined(__DragonFly__)
510         sbp->f_type = mp->mnt_vfc->vfc_typenum;
511 #else /* defined(__NetBSD__) */
512         sbp->f_type = 0;
513 #endif
514         sbp->f_bsize = DEV_BSIZE;
515         sbp->f_iosize = DEV_BSIZE;
516         sbp->f_blocks = hpmp->hpm_su.su_btotal;
517         sbp->f_bfree = sbp->f_bavail = hpmp->hpm_bavail;
518         sbp->f_ffree = 0;
519         sbp->f_files = 0;
520         if (sbp != &mp->mnt_stat) {
521                 bcopy((caddr_t)mp->mnt_stat.f_mntonname,
522                         (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
523                 bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
524                         (caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
525         }
526         sbp->f_flags = mp->mnt_flag;
527         
528         return (0);
529 }
530
531 #if !defined(__DragonFly__)
532 static int
533 hpfs_sync(struct mount *mp, int waitfor, struct ucred *cred,
534           struct thread *td)
535 {
536         return (0);
537 }
538
539 static int
540 hpfs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
541               struct thread *td)
542 {
543         printf("hpfs_quotactl():\n");
544         return (EOPNOTSUPP);
545 }
546 #endif
547
548 /*ARGSUSED*/
549 static int
550 hpfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
551 {
552         struct vnode *nvp;
553         struct hpfid *hpfhp = (struct hpfid *)fhp;
554         int error;
555
556         if ((error = VFS_VGET(mp, hpfhp->hpfid_ino, &nvp)) != 0) {
557                 *vpp = NULLVP;
558                 return (error);
559         }
560         /* XXX as unlink/rmdir/mkdir/creat are not currently possible
561          * with HPFS, we don't need to check anything else for now */
562         *vpp = nvp;
563
564         return (0);
565 }
566
567 static int
568 hpfs_vptofh(struct vnode *vp, struct fid *fhp)
569 {
570         struct hpfsnode *hpp;
571         struct hpfid *hpfhp;
572
573         hpp = VTOHP(vp);
574         hpfhp = (struct hpfid *)fhp;
575         hpfhp->hpfid_len = sizeof(struct hpfid);
576         hpfhp->hpfid_ino = hpp->h_no;
577         /* hpfhp->hpfid_gen = hpp->h_gen; */
578         return (0);
579 }
580
581 static int
582 hpfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp) 
583 {
584         struct hpfsmount *hpmp = VFSTOHPFS(mp);
585         struct vnode *vp;
586         struct hpfsnode *hp;
587         struct buf *bp;
588         struct thread *td = curthread;  /* XXX */
589         int error;
590
591         dprintf(("hpfs_vget(0x%x): ",ino));
592
593         *vpp = NULL;
594         hp = NULL;
595         vp = NULL;
596
597         if ((*vpp = hpfs_hphashvget(hpmp->hpm_dev, ino, td)) != NULL) {
598                 dprintf(("hashed\n"));
599                 return (0);
600         }
601
602         /*
603          * We have to lock node creation for a while,
604          * but then we have to call getnewvnode(), 
605          * this may cause hpfs_reclaim() to be called,
606          * this may need to VOP_VGET() parent dir for
607          * update reasons, and if parent is not in
608          * hash, we have to lock node creation...
609          * To solve this, we MALLOC, getnewvnode and init while
610          * not locked (probability of node appearence
611          * at that time is little, and anyway - we'll
612          * check for it).
613          */
614         MALLOC(hp, struct hpfsnode *, sizeof(struct hpfsnode), 
615                 M_HPFSNO, M_WAITOK);
616
617         error = getnewvnode(VT_HPFS, hpmp->hpm_mp, hpmp->hpm_mp->mnt_vn_ops,
618                             &vp, VLKTIMEOUT, 0);
619         if (error) {
620                 printf("hpfs_vget: can't get new vnode\n");
621                 FREE(hp, M_HPFSNO);
622                 return (error);
623         }
624
625         dprintf(("prenew "));
626
627         vp->v_data = hp;
628
629         if (ino == (ino_t)hpmp->hpm_su.su_rootfno) 
630                 vp->v_flag |= VROOT;
631
632         lwkt_token_init(&hp->h_interlock);
633
634         hp->h_flag = H_INVAL;
635         hp->h_vp = vp;
636         hp->h_hpmp = hpmp;
637         hp->h_no = ino;
638         hp->h_dev = hpmp->hpm_dev;
639         hp->h_uid = hpmp->hpm_uid;
640         hp->h_gid = hpmp->hpm_uid;
641         hp->h_mode = hpmp->hpm_mode;
642         hp->h_devvp = hpmp->hpm_devvp;
643         vref(hp->h_devvp);
644
645         do {
646                 if ((*vpp = hpfs_hphashvget(hpmp->hpm_dev, ino, td)) != NULL) {
647                         dprintf(("hashed2\n"));
648                         vx_put(vp);
649                         return (0);
650                 }
651         } while(LOCKMGR(&hpfs_hphash_lock,LK_EXCLUSIVE|LK_SLEEPFAIL,NULL,NULL));
652
653         hpfs_hphashins(hp);
654
655         LOCKMGR(&hpfs_hphash_lock, LK_RELEASE, NULL, NULL);
656
657         error = bread(hpmp->hpm_devvp, ino, FNODESIZE, &bp);
658         if (error) {
659                 printf("hpfs_vget: can't read ino %d\n",ino);
660                 vx_put(vp);
661                 return (error);
662         }
663         bcopy(bp->b_data, &hp->h_fn, sizeof(struct fnode));
664         brelse(bp);
665
666         if (hp->h_fn.fn_magic != FN_MAGIC) {
667                 printf("hpfs_vget: MAGIC DOESN'T MATCH\n");
668                 vx_put(vp);
669                 return (EINVAL);
670         }
671
672         vp->v_type = hp->h_fn.fn_flag ? VDIR:VREG;
673         hp->h_flag &= ~H_INVAL;
674
675         /* Return the locked and refd vnode */
676         *vpp = vp;
677
678         return (0);
679 }
680
681 #if defined(__DragonFly__)
682 static struct vfsops hpfs_vfsops = {
683         hpfs_mount,
684         vfs_stdstart,
685         hpfs_unmount,
686         hpfs_root,
687         vfs_stdquotactl,
688         hpfs_statfs,
689         vfs_stdsync,
690         hpfs_vget,
691         hpfs_fhtovp,
692         hpfs_checkexp,
693         hpfs_vptofh,
694         hpfs_init,
695         hpfs_hphash_uninit,
696         vfs_stdextattrctl,
697 };
698 VFS_SET(hpfs_vfsops, hpfs, 0);
699 #else /* defined(__NetBSD__) */
700 extern struct vnodeopv_desc hpfs_vnodeop_opv_desc;
701
702 struct vnodeopv_desc *hpfs_vnodeopv_descs[] = {
703         &hpfs_vnodeop_opv_desc,
704         NULL,
705 };
706
707 struct vfsops hpfs_vfsops = {
708         MOUNT_HPFS,
709         hpfs_mount,
710         hpfs_start,
711         hpfs_unmount,
712         hpfs_root,
713         hpfs_quotactl,
714         hpfs_statfs,
715         hpfs_sync,
716         hpfs_vget,
717         hpfs_fhtovp,
718         hpfs_vptofh,
719         hpfs_init,
720         hpfs_sysctl,
721         hpfs_mountroot,
722         hpfs_checkexp,
723         hpfs_vnodeopv_descs,
724 };
725 #endif