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