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