Commit | Line | Data |
---|---|---|
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 $ | |
27 | */ | |
28 | ||
29 | ||
30 | #include <sys/param.h> | |
31 | #include <sys/systm.h> | |
fad57d0e | 32 | #include <sys/nlookup.h> |
984263bc MD |
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 | ||
f91a71dd JS |
42 | #include <machine/inttypes.h> |
43 | ||
984263bc MD |
44 | #include <vm/vm.h> |
45 | #include <vm/vm_param.h> | |
46 | #if defined(__NetBSD__) | |
47 | #include <vm/vm_prot.h> | |
48 | #endif | |
49 | #include <vm/vm_page.h> | |
50 | #include <vm/vm_object.h> | |
51 | #include <vm/vm_extern.h> | |
54341a3b | 52 | |
7d1b9a3b | 53 | #include <sys/buf2.h> |
984263bc MD |
54 | |
55 | #if defined(__NetBSD__) | |
56 | #include <miscfs/specfs/specdev.h> | |
57 | #endif | |
58 | ||
1f2de5d4 MD |
59 | #include "hpfs.h" |
60 | #include "hpfsmount.h" | |
61 | #include "hpfs_subr.h" | |
984263bc | 62 | |
66a1ddf5 | 63 | extern struct vop_ops hpfs_vnode_vops; |
0961aa92 | 64 | |
984263bc MD |
65 | MALLOC_DEFINE(M_HPFSMNT, "HPFS mount", "HPFS mount structure"); |
66 | MALLOC_DEFINE(M_HPFSNO, "HPFS node", "HPFS node structure"); | |
984263bc | 67 | |
a6ee311a | 68 | static int hpfs_root (struct mount *, struct vnode **); |
acde96db MD |
69 | static int hpfs_statfs (struct mount *, struct statfs *, struct ucred *); |
70 | static int hpfs_unmount (struct mount *, int); | |
b9b0a6d0 MD |
71 | static int hpfs_vget (struct mount *mp, struct vnode *, |
72 | ino_t ino, struct vnode **vpp); | |
a6ee311a | 73 | static int hpfs_mountfs (struct vnode *, struct mount *, |
67863d04 | 74 | struct hpfs_args *); |
a6ee311a | 75 | static int hpfs_vptofh (struct vnode *, struct fid *); |
67863d04 MD |
76 | static int hpfs_fhtovp (struct mount *, struct vnode *, |
77 | struct fid *, struct vnode **); | |
984263bc | 78 | |
984263bc | 79 | |
984263bc | 80 | struct sockaddr; |
acde96db | 81 | static int hpfs_mount (struct mount *, char *, caddr_t, struct ucred *); |
a6ee311a RG |
82 | static int hpfs_init (struct vfsconf *); |
83 | static int hpfs_checkexp (struct mount *, struct sockaddr *, | |
84 | int *, struct ucred **); | |
984263bc MD |
85 | |
86 | /*ARGSUSED*/ | |
87 | static int | |
dd3af26c | 88 | hpfs_checkexp(struct mount *mp, |
dd3af26c | 89 | struct sockaddr *nam, |
dd3af26c | 90 | int *exflagsp, struct ucred **credanonp) |
984263bc | 91 | { |
f7aae92f RG |
92 | struct netcred *np; |
93 | struct hpfsmount *hpm = VFSTOHPFS(mp); | |
984263bc MD |
94 | |
95 | /* | |
96 | * Get the export permission structure for this <mp, client> tuple. | |
97 | */ | |
98 | np = vfs_export_lookup(mp, &hpm->hpm_export, nam); | |
99 | if (np == NULL) | |
100 | return (EACCES); | |
101 | ||
102 | *exflagsp = np->netc_exflags; | |
103 | *credanonp = &np->netc_anon; | |
104 | return (0); | |
105 | } | |
106 | ||
984263bc | 107 | static int |
dd3af26c | 108 | hpfs_init(struct vfsconf *vcp) |
984263bc MD |
109 | { |
110 | dprintf(("hpfs_init():\n")); | |
111 | ||
112 | hpfs_hphashinit(); | |
984263bc | 113 | return 0; |
984263bc MD |
114 | } |
115 | ||
116 | static int | |
acde96db | 117 | hpfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred) |
984263bc | 118 | { |
973c11b9 | 119 | size_t size; |
fad57d0e | 120 | int error; |
984263bc MD |
121 | struct vnode *devvp; |
122 | struct hpfs_args args; | |
4090d6ff | 123 | struct hpfsmount *hpmp = NULL; |
fad57d0e | 124 | struct nlookupdata nd; |
984263bc MD |
125 | |
126 | dprintf(("hpfs_mount():\n")); | |
127 | /* | |
128 | *** | |
129 | * Mounting non-root file system or updating a file system | |
130 | *** | |
131 | */ | |
132 | ||
133 | /* copy in user arguments*/ | |
fad57d0e MD |
134 | error = copyin(data, (caddr_t)&args, sizeof (struct hpfs_args)); |
135 | if (error) | |
984263bc MD |
136 | goto error_1; /* can't get arguments*/ |
137 | ||
138 | /* | |
139 | * If updating, check whether changing from read-only to | |
140 | * read/write; if there is no device name, that's all we do. | |
141 | */ | |
142 | if (mp->mnt_flag & MNT_UPDATE) { | |
143 | dprintf(("hpfs_mount: MNT_UPDATE: ")); | |
144 | ||
145 | hpmp = VFSTOHPFS(mp); | |
146 | ||
d8061892 | 147 | if (args.fspec == NULL) { |
984263bc | 148 | dprintf(("export 0x%x\n",args.export.ex_flags)); |
fad57d0e MD |
149 | error = vfs_export(mp, &hpmp->hpm_export, &args.export); |
150 | if (error) { | |
086c1d7e | 151 | kprintf("hpfs_mount: vfs_export failed %d\n", |
fad57d0e | 152 | error); |
984263bc | 153 | } |
984263bc MD |
154 | } else { |
155 | dprintf(("name [FAILED]\n")); | |
fad57d0e | 156 | error = EINVAL; |
984263bc | 157 | } |
0c77d800 | 158 | goto success; |
984263bc MD |
159 | } |
160 | ||
161 | /* | |
162 | * Not an update, or updating the name: look up the name | |
163 | * and verify that it refers to a sensible block device. | |
164 | */ | |
fad57d0e MD |
165 | devvp = NULL; |
166 | error = nlookup_init(&nd, args.fspec, UIO_USERSPACE, NLC_FOLLOW); | |
167 | if (error == 0) | |
168 | error = nlookup(&nd); | |
169 | if (error == 0) | |
28623bf9 | 170 | error = cache_vref(&nd.nl_nch, nd.nl_cred, &devvp); |
fad57d0e MD |
171 | nlookup_done(&nd); |
172 | if (error) | |
984263bc | 173 | goto error_1; |
984263bc | 174 | |
fad57d0e | 175 | if (!vn_isdisk(devvp, &error)) |
984263bc | 176 | goto error_2; |
984263bc MD |
177 | |
178 | /* | |
179 | ******************** | |
180 | * NEW MOUNT | |
181 | ******************** | |
182 | */ | |
183 | ||
984263bc MD |
184 | /* Save "mounted from" info for mount point (NULL pad)*/ |
185 | copyinstr( args.fspec, /* device name*/ | |
186 | mp->mnt_stat.f_mntfromname, /* save area*/ | |
187 | MNAMELEN - 1, /* max size*/ | |
188 | &size); /* real size*/ | |
189 | bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); | |
190 | ||
acde96db | 191 | error = hpfs_mountfs(devvp, mp, &args); |
fad57d0e | 192 | if (error) |
984263bc MD |
193 | goto error_2; |
194 | ||
195 | /* | |
75ffff0d JS |
196 | * Initialize FS stat information in mount struct; uses |
197 | * mp->mnt_stat.f_mntfromname. | |
984263bc MD |
198 | * |
199 | * This code is common to root and non-root mounts | |
200 | */ | |
acde96db | 201 | VFS_STATFS(mp, &mp->mnt_stat, cred); |
fad57d0e | 202 | return (error); |
984263bc MD |
203 | |
204 | error_2: /* error with devvp held*/ | |
205 | ||
206 | /* release devvp before failing*/ | |
207 | vrele(devvp); | |
208 | ||
209 | error_1: /* no state to back out*/ | |
210 | ||
211 | success: | |
fad57d0e | 212 | return (error); |
984263bc MD |
213 | } |
214 | ||
215 | /* | |
216 | * Common code for mount and mountroot | |
217 | */ | |
218 | int | |
acde96db | 219 | hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp) |
984263bc MD |
220 | { |
221 | int error, ncount, ronly; | |
222 | struct sublock *sup; | |
223 | struct spblock *spp; | |
224 | struct hpfsmount *hpmp; | |
225 | struct buf *bp = NULL; | |
226 | struct vnode *vp; | |
b13267a5 | 227 | cdev_t dev; |
984263bc MD |
228 | |
229 | dprintf(("hpfs_mountfs():\n")); | |
230 | /* | |
231 | * Disallow multiple mounts of the same device. | |
232 | * Disallow mounting of a device that is currently in use | |
233 | * (except for root, which might share swap device for miniroot). | |
234 | * Flush out any old buffers remaining from a previous use. | |
235 | */ | |
236 | error = vfs_mountedon(devvp); | |
237 | if (error) | |
238 | return (error); | |
8be7edad | 239 | ncount = vcount(devvp); |
984263bc MD |
240 | if (devvp->v_object) |
241 | ncount -= 1; | |
21739618 | 242 | if (ncount > 0) |
984263bc MD |
243 | return (EBUSY); |
244 | ||
acde96db | 245 | VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY); |
87de5057 | 246 | error = vinvalbuf(devvp, V_SAVE, 0, 0); |
acde96db | 247 | VOP__UNLOCK(devvp, 0); |
984263bc MD |
248 | if (error) |
249 | return (error); | |
250 | ||
251 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; | |
acde96db | 252 | VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY); |
87de5057 | 253 | error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, NULL); |
acde96db | 254 | VOP__UNLOCK(devvp, 0); |
984263bc MD |
255 | if (error) |
256 | return (error); | |
e4c9c0c8 | 257 | dev = devvp->v_rdev; |
984263bc MD |
258 | |
259 | /* | |
260 | * Do actual mount | |
261 | */ | |
e7b4468c | 262 | hpmp = kmalloc(sizeof(struct hpfsmount), M_HPFSMNT, M_WAITOK | M_ZERO); |
984263bc MD |
263 | |
264 | /* Read in SuperBlock */ | |
54078292 | 265 | error = bread(devvp, dbtodoff(SUBLOCK), SUSIZE, &bp); |
984263bc MD |
266 | if (error) |
267 | goto failed; | |
268 | bcopy(bp->b_data, &hpmp->hpm_su, sizeof(struct sublock)); | |
269 | brelse(bp); bp = NULL; | |
270 | ||
271 | /* Read in SpareBlock */ | |
54078292 | 272 | error = bread(devvp, dbtodoff(SPBLOCK), SPSIZE, &bp); |
984263bc MD |
273 | if (error) |
274 | goto failed; | |
275 | bcopy(bp->b_data, &hpmp->hpm_sp, sizeof(struct spblock)); | |
276 | brelse(bp); bp = NULL; | |
277 | ||
278 | sup = &hpmp->hpm_su; | |
279 | spp = &hpmp->hpm_sp; | |
280 | ||
281 | /* Check magic */ | |
282 | if (sup->su_magic != SU_MAGIC) { | |
086c1d7e | 283 | kprintf("hpfs_mountfs: SuperBlock MAGIC DOESN'T MATCH\n"); |
984263bc MD |
284 | error = EINVAL; |
285 | goto failed; | |
286 | } | |
287 | if (spp->sp_magic != SP_MAGIC) { | |
086c1d7e | 288 | kprintf("hpfs_mountfs: SpareBlock MAGIC DOESN'T MATCH\n"); |
984263bc MD |
289 | error = EINVAL; |
290 | goto failed; | |
291 | } | |
292 | ||
293 | mp->mnt_data = (qaddr_t)hpmp; | |
294 | hpmp->hpm_devvp = devvp; | |
e4c9c0c8 | 295 | hpmp->hpm_dev = dev; |
984263bc MD |
296 | hpmp->hpm_mp = mp; |
297 | hpmp->hpm_uid = argsp->uid; | |
298 | hpmp->hpm_gid = argsp->gid; | |
299 | hpmp->hpm_mode = argsp->mode; | |
300 | ||
301 | error = hpfs_bminit(hpmp); | |
302 | if (error) | |
303 | goto failed; | |
304 | ||
305 | error = hpfs_cpinit(hpmp, argsp); | |
306 | if (error) { | |
307 | hpfs_bmdeinit(hpmp); | |
308 | goto failed; | |
309 | } | |
66a1ddf5 | 310 | vfs_add_vnodeops(mp, &hpfs_vnode_vops, &mp->mnt_vn_norm_ops); |
984263bc MD |
311 | |
312 | error = hpfs_root(mp, &vp); | |
313 | if (error) { | |
314 | hpfs_cpdeinit(hpmp); | |
315 | hpfs_bmdeinit(hpmp); | |
316 | goto failed; | |
317 | } | |
318 | ||
319 | vput(vp); | |
320 | ||
2ac7d105 | 321 | mp->mnt_stat.f_fsid.val[0] = (long)devid_from_dev(dev); |
984263bc | 322 | mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; |
984263bc MD |
323 | mp->mnt_maxsymlinklen = 0; |
324 | mp->mnt_flag |= MNT_LOCAL; | |
e4c9c0c8 | 325 | dev->si_mountpoint = mp; |
984263bc MD |
326 | return (0); |
327 | ||
328 | failed: | |
329 | if (bp) | |
330 | brelse (bp); | |
a60655aa | 331 | mp->mnt_data = NULL; |
e4c9c0c8 | 332 | dev->si_mountpoint = NULL; |
12cdc371 | 333 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
3596743e | 334 | VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NULL); |
12cdc371 | 335 | vn_unlock(devvp); |
984263bc MD |
336 | return (error); |
337 | } | |
338 | ||
984263bc MD |
339 | |
340 | static int | |
acde96db | 341 | hpfs_unmount(struct mount *mp, int mntflags) |
984263bc MD |
342 | { |
343 | int error, flags, ronly; | |
f7aae92f | 344 | struct hpfsmount *hpmp = VFSTOHPFS(mp); |
984263bc MD |
345 | |
346 | dprintf(("hpfs_unmount():\n")); | |
347 | ||
348 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; | |
349 | ||
350 | flags = 0; | |
351 | if(mntflags & MNT_FORCE) | |
352 | flags |= FORCECLOSE; | |
353 | ||
354 | dprintf(("hpfs_unmount: vflushing...\n")); | |
355 | ||
356 | error = vflush(mp, 0, flags); | |
357 | if (error) { | |
086c1d7e | 358 | kprintf("hpfs_unmount: vflush failed: %d\n",error); |
984263bc MD |
359 | return (error); |
360 | } | |
361 | ||
e4c9c0c8 | 362 | hpmp->hpm_devvp->v_rdev->si_mountpoint = NULL; |
984263bc | 363 | |
12cdc371 | 364 | vn_lock(hpmp->hpm_devvp, LK_EXCLUSIVE | LK_RETRY); |
87de5057 | 365 | vinvalbuf(hpmp->hpm_devvp, V_SAVE, 0, 0); |
3596743e | 366 | error = VOP_CLOSE(hpmp->hpm_devvp, ronly ? FREAD : FREAD|FWRITE, NULL); |
12cdc371 | 367 | vn_unlock(hpmp->hpm_devvp); |
984263bc MD |
368 | |
369 | vrele(hpmp->hpm_devvp); | |
370 | ||
371 | dprintf(("hpfs_umount: freeing memory...\n")); | |
372 | hpfs_cpdeinit(hpmp); | |
373 | hpfs_bmdeinit(hpmp); | |
374 | mp->mnt_data = (qaddr_t)0; | |
375 | mp->mnt_flag &= ~MNT_LOCAL; | |
884717e1 | 376 | kfree(hpmp, M_HPFSMNT); |
984263bc MD |
377 | |
378 | return (0); | |
379 | } | |
380 | ||
381 | static int | |
dd3af26c | 382 | hpfs_root(struct mount *mp, struct vnode **vpp) |
984263bc MD |
383 | { |
384 | int error = 0; | |
385 | struct hpfsmount *hpmp = VFSTOHPFS(mp); | |
386 | ||
387 | dprintf(("hpfs_root():\n")); | |
b9b0a6d0 | 388 | error = VFS_VGET(mp, NULL, (ino_t)hpmp->hpm_su.su_rootfno, vpp); |
984263bc | 389 | if(error) { |
086c1d7e | 390 | kprintf("hpfs_root: VFS_VGET failed: %d\n",error); |
984263bc MD |
391 | return (error); |
392 | } | |
393 | ||
394 | return (error); | |
395 | } | |
396 | ||
397 | static int | |
acde96db | 398 | hpfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred) |
984263bc MD |
399 | { |
400 | struct hpfsmount *hpmp = VFSTOHPFS(mp); | |
401 | ||
402 | dprintf(("hpfs_statfs(): HPFS%d.%d\n", | |
403 | hpmp->hpm_su.su_hpfsver, hpmp->hpm_su.su_fnctver)); | |
404 | ||
984263bc | 405 | sbp->f_type = mp->mnt_vfc->vfc_typenum; |
984263bc MD |
406 | sbp->f_bsize = DEV_BSIZE; |
407 | sbp->f_iosize = DEV_BSIZE; | |
408 | sbp->f_blocks = hpmp->hpm_su.su_btotal; | |
409 | sbp->f_bfree = sbp->f_bavail = hpmp->hpm_bavail; | |
410 | sbp->f_ffree = 0; | |
411 | sbp->f_files = 0; | |
412 | if (sbp != &mp->mnt_stat) { | |
984263bc MD |
413 | bcopy((caddr_t)mp->mnt_stat.f_mntfromname, |
414 | (caddr_t)&sbp->f_mntfromname[0], MNAMELEN); | |
415 | } | |
416 | sbp->f_flags = mp->mnt_flag; | |
417 | ||
418 | return (0); | |
419 | } | |
420 | ||
984263bc MD |
421 | |
422 | /*ARGSUSED*/ | |
423 | static int | |
67863d04 MD |
424 | hpfs_fhtovp(struct mount *mp, struct vnode *rootvp, |
425 | struct fid *fhp, struct vnode **vpp) | |
984263bc MD |
426 | { |
427 | struct vnode *nvp; | |
428 | struct hpfid *hpfhp = (struct hpfid *)fhp; | |
429 | int error; | |
430 | ||
b9b0a6d0 | 431 | if ((error = VFS_VGET(mp, NULL, hpfhp->hpfid_ino, &nvp)) != 0) { |
984263bc MD |
432 | *vpp = NULLVP; |
433 | return (error); | |
434 | } | |
435 | /* XXX as unlink/rmdir/mkdir/creat are not currently possible | |
436 | * with HPFS, we don't need to check anything else for now */ | |
437 | *vpp = nvp; | |
438 | ||
439 | return (0); | |
440 | } | |
441 | ||
442 | static int | |
dd3af26c | 443 | hpfs_vptofh(struct vnode *vp, struct fid *fhp) |
984263bc | 444 | { |
f7aae92f RG |
445 | struct hpfsnode *hpp; |
446 | struct hpfid *hpfhp; | |
984263bc MD |
447 | |
448 | hpp = VTOHP(vp); | |
449 | hpfhp = (struct hpfid *)fhp; | |
450 | hpfhp->hpfid_len = sizeof(struct hpfid); | |
451 | hpfhp->hpfid_ino = hpp->h_no; | |
452 | /* hpfhp->hpfid_gen = hpp->h_gen; */ | |
453 | return (0); | |
454 | } | |
455 | ||
456 | static int | |
b9b0a6d0 | 457 | hpfs_vget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp) |
984263bc MD |
458 | { |
459 | struct hpfsmount *hpmp = VFSTOHPFS(mp); | |
460 | struct vnode *vp; | |
461 | struct hpfsnode *hp; | |
462 | struct buf *bp; | |
984263bc MD |
463 | int error; |
464 | ||
597382cf | 465 | dprintf(("hpfs_vget(0x%jx): ", ino)); |
984263bc MD |
466 | |
467 | *vpp = NULL; | |
468 | hp = NULL; | |
469 | vp = NULL; | |
470 | ||
87de5057 | 471 | if ((*vpp = hpfs_hphashvget(hpmp->hpm_dev, ino)) != NULL) { |
984263bc MD |
472 | dprintf(("hashed\n")); |
473 | return (0); | |
474 | } | |
475 | ||
476 | /* | |
477 | * We have to lock node creation for a while, | |
478 | * but then we have to call getnewvnode(), | |
479 | * this may cause hpfs_reclaim() to be called, | |
480 | * this may need to VOP_VGET() parent dir for | |
481 | * update reasons, and if parent is not in | |
482 | * hash, we have to lock node creation... | |
483 | * To solve this, we MALLOC, getnewvnode and init while | |
484 | * not locked (probability of node appearence | |
485 | * at that time is little, and anyway - we'll | |
486 | * check for it). | |
487 | */ | |
884717e1 | 488 | hp = kmalloc(sizeof(struct hpfsnode), M_HPFSNO, M_WAITOK); |
984263bc | 489 | |
6ddb7618 | 490 | error = getnewvnode(VT_HPFS, hpmp->hpm_mp, &vp, VLKTIMEOUT, 0); |
984263bc | 491 | if (error) { |
086c1d7e | 492 | kprintf("hpfs_vget: can't get new vnode\n"); |
884717e1 | 493 | kfree(hp, M_HPFSNO); |
984263bc MD |
494 | return (error); |
495 | } | |
496 | ||
497 | dprintf(("prenew ")); | |
498 | ||
499 | vp->v_data = hp; | |
500 | ||
501 | if (ino == (ino_t)hpmp->hpm_su.su_rootfno) | |
2247fe02 | 502 | vsetflags(vp, VROOT); |
984263bc | 503 | |
a3c18566 | 504 | lwkt_token_init(&hp->h_interlock, "hpfsilock"); |
984263bc MD |
505 | |
506 | hp->h_flag = H_INVAL; | |
507 | hp->h_vp = vp; | |
508 | hp->h_hpmp = hpmp; | |
509 | hp->h_no = ino; | |
510 | hp->h_dev = hpmp->hpm_dev; | |
511 | hp->h_uid = hpmp->hpm_uid; | |
512 | hp->h_gid = hpmp->hpm_uid; | |
513 | hp->h_mode = hpmp->hpm_mode; | |
514 | hp->h_devvp = hpmp->hpm_devvp; | |
597aea93 | 515 | vref(hp->h_devvp); |
984263bc | 516 | |
984263bc | 517 | do { |
87de5057 | 518 | if ((*vpp = hpfs_hphashvget(hpmp->hpm_dev, ino)) != NULL) { |
984263bc | 519 | dprintf(("hashed2\n")); |
5fd012e0 | 520 | vx_put(vp); |
984263bc MD |
521 | return (0); |
522 | } | |
acde96db | 523 | } while (LOCKMGR(&hpfs_hphash_lock, LK_EXCLUSIVE | LK_SLEEPFAIL)); |
984263bc MD |
524 | |
525 | hpfs_hphashins(hp); | |
526 | ||
acde96db | 527 | LOCKMGR(&hpfs_hphash_lock, LK_RELEASE); |
984263bc | 528 | |
54078292 | 529 | error = bread(hpmp->hpm_devvp, dbtodoff(ino), FNODESIZE, &bp); |
984263bc | 530 | if (error) { |
086c1d7e | 531 | kprintf("hpfs_vget: can't read ino %"PRId64"\n",ino); |
5fd012e0 | 532 | vx_put(vp); |
984263bc MD |
533 | return (error); |
534 | } | |
535 | bcopy(bp->b_data, &hp->h_fn, sizeof(struct fnode)); | |
536 | brelse(bp); | |
537 | ||
538 | if (hp->h_fn.fn_magic != FN_MAGIC) { | |
086c1d7e | 539 | kprintf("hpfs_vget: MAGIC DOESN'T MATCH\n"); |
5fd012e0 | 540 | vx_put(vp); |
984263bc MD |
541 | return (EINVAL); |
542 | } | |
543 | ||
544 | vp->v_type = hp->h_fn.fn_flag ? VDIR:VREG; | |
545 | hp->h_flag &= ~H_INVAL; | |
546 | ||
5fd012e0 | 547 | /* Return the locked and refd vnode */ |
fc36a10b | 548 | vx_downgrade(vp); |
984263bc MD |
549 | *vpp = vp; |
550 | ||
551 | return (0); | |
552 | } | |
553 | ||
984263bc | 554 | static struct vfsops hpfs_vfsops = { |
00369c4a | 555 | .vfs_flags = 0, |
43c45e8f HP |
556 | .vfs_mount = hpfs_mount, |
557 | .vfs_unmount = hpfs_unmount, | |
558 | .vfs_root = hpfs_root, | |
559 | .vfs_statfs = hpfs_statfs, | |
43c45e8f HP |
560 | .vfs_vget = hpfs_vget, |
561 | .vfs_fhtovp = hpfs_fhtovp, | |
562 | .vfs_checkexp = hpfs_checkexp, | |
563 | .vfs_vptofh = hpfs_vptofh, | |
564 | .vfs_init = hpfs_init, | |
565 | .vfs_uninit = hpfs_hphash_uninit | |
984263bc | 566 | }; |
984263bc | 567 | |
64b4604e | 568 | VFS_SET(hpfs_vfsops, hpfs, 0); |
e5e63c20 | 569 | MODULE_VERSION(hpfs, 1); |