filecore_vfsops.c revision 1.5.2.9 1 /* $NetBSD: filecore_vfsops.c,v 1.5.2.9 2005/01/17 19:32:12 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * filecore_vfsops.c 1.1 1998/6/26
32 */
33
34 /*-
35 * Copyright (c) 1998 Andrew McMurry
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * filecore_vfsops.c 1.1 1998/6/26
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.5.2.9 2005/01/17 19:32:12 skrll Exp $");
70
71 #if defined(_KERNEL_OPT)
72 #include "opt_compat_netbsd.h"
73 #endif
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/namei.h>
78 #include <sys/proc.h>
79 #include <sys/vnode.h>
80 #include <miscfs/specfs/specdev.h>
81 #include <sys/mount.h>
82 #include <sys/buf.h>
83 #include <sys/file.h>
84 #include <sys/device.h>
85 #include <sys/errno.h>
86 #include <sys/malloc.h>
87 #include <sys/pool.h>
88 #include <sys/conf.h>
89 #include <sys/sysctl.h>
90
91 #include <fs/filecorefs/filecore.h>
92 #include <fs/filecorefs/filecore_extern.h>
93 #include <fs/filecorefs/filecore_node.h>
94 #include <fs/filecorefs/filecore_mount.h>
95
96 MALLOC_DEFINE(M_FILECOREMNT, "filecore mount", "Filecore FS mount structures");
97
98 extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;
99
100 const struct vnodeopv_desc * const filecore_vnodeopv_descs[] = {
101 &filecore_vnodeop_opv_desc,
102 NULL,
103 };
104
105 struct vfsops filecore_vfsops = {
106 MOUNT_FILECORE,
107 filecore_mount,
108 filecore_start,
109 filecore_unmount,
110 filecore_root,
111 filecore_quotactl,
112 filecore_statvfs,
113 filecore_sync,
114 filecore_vget,
115 filecore_fhtovp,
116 filecore_vptofh,
117 filecore_init,
118 filecore_reinit,
119 filecore_done,
120 NULL,
121 NULL, /* filecore_mountroot */
122 filecore_checkexp,
123 (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
124 vfs_stdextattrctl,
125 filecore_vnodeopv_descs,
126 };
127
128 struct genfs_ops filecore_genfsops = {
129 genfs_size,
130 };
131
132 /*
133 * Called by vfs_mountroot when iso is going to be mounted as root.
134 *
135 * Name is updated by mount(8) after booting.
136 */
137
138 static int filecore_mountfs __P((struct vnode *devvp, struct mount *mp,
139 struct lwp *l, struct filecore_args *argp));
140
141 #if 0
142 int
143 filecore_mountroot()
144 {
145 struct mount *mp;
146 extern struct vnode *rootvp;
147 struct proc *p = curproc; /* XXX */
148 int error;
149 struct filecore_args args;
150
151 if (root_device->dv_class != DV_DISK)
152 return (ENODEV);
153
154 /*
155 * Get vnodes for swapdev and rootdev.
156 */
157 if (bdevvp(rootdev, &rootvp))
158 panic("filecore_mountroot: can't setup rootvp");
159
160 if ((error = vfs_rootmountalloc(MOUNT_FILECORE, "root_device", &mp)) != 0)
161 return (error);
162
163 args.flags = FILECOREMNT_ROOT;
164 if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
165 mp->mnt_op->vfs_refcount--;
166 vfs_unbusy(mp);
167 free(mp, M_MOUNT);
168 return (error);
169 }
170 simple_lock(&mountlist_slock);
171 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
172 simple_unlock(&mountlist_slock);
173 (void)filecore_statvfs(mp, &mp->mnt_stat, p);
174 vfs_unbusy(mp);
175 return (0);
176 }
177 #endif
178
179 /*
180 * VFS Operations.
181 *
182 * mount system call
183 */
184 int
185 filecore_mount(mp, path, data, ndp, l)
186 struct mount *mp;
187 const char *path;
188 void *data;
189 struct nameidata *ndp;
190 struct lwp *l;
191 {
192 struct vnode *devvp;
193 struct filecore_args args;
194 struct proc *p;
195 int error;
196 struct filecore_mnt *fcmp = NULL;
197
198 p = l->l_proc;
199 if (mp->mnt_flag & MNT_GETARGS) {
200 fcmp = VFSTOFILECORE(mp);
201 if (fcmp == NULL)
202 return EIO;
203 args.flags = fcmp->fc_mntflags;
204 args.uid = fcmp->fc_uid;
205 args.gid = fcmp->fc_gid;
206 args.fspec = NULL;
207 vfs_showexport(mp, &args.export, &fcmp->fc_export);
208 return copyout(&args, data, sizeof(args));
209 }
210 error = copyin(data, &args, sizeof (struct filecore_args));
211 if (error)
212 return (error);
213
214 if ((mp->mnt_flag & MNT_RDONLY) == 0)
215 return (EROFS);
216
217 /*
218 * If updating, check whether changing from read-only to
219 * read/write; if there is no device name, that's all we do.
220 */
221 if (mp->mnt_flag & MNT_UPDATE) {
222 fcmp = VFSTOFILECORE(mp);
223 if (args.fspec == 0)
224 return (vfs_export(mp, &fcmp->fc_export, &args.export));
225 }
226 /*
227 * Not an update, or updating the name: look up the name
228 * and verify that it refers to a sensible block device.
229 */
230 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
231 if ((error = namei(ndp)) != 0)
232 return (error);
233 devvp = ndp->ni_vp;
234
235 if (devvp->v_type != VBLK) {
236 vrele(devvp);
237 return ENOTBLK;
238 }
239 if (bdevsw_lookup(devvp->v_rdev) == NULL) {
240 vrele(devvp);
241 return ENXIO;
242 }
243 /*
244 * If mount by non-root, then verify that user has necessary
245 * permissions on the device.
246 */
247 if (p->p_ucred->cr_uid != 0) {
248 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
249 error = VOP_ACCESS(devvp, VREAD, p->p_ucred, l);
250 VOP_UNLOCK(devvp, 0);
251 if (error) {
252 vrele(devvp);
253 return (error);
254 }
255 }
256 if ((mp->mnt_flag & MNT_UPDATE) == 0)
257 error = filecore_mountfs(devvp, mp, l, &args);
258 else {
259 if (devvp != fcmp->fc_devvp)
260 error = EINVAL; /* needs translation */
261 else
262 vrele(devvp);
263 }
264 if (error) {
265 vrele(devvp);
266 return error;
267 }
268 fcmp = VFSTOFILECORE(mp);
269 return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
270 mp, l);
271 }
272
273 /*
274 * Common code for mount and mountroot
275 */
276 static int
277 filecore_mountfs(devvp, mp, l, argp)
278 struct vnode *devvp;
279 struct mount *mp;
280 struct lwp *l;
281 struct filecore_args *argp;
282 {
283 struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
284 struct buf *bp = NULL;
285 dev_t dev = devvp->v_rdev;
286 int error = EINVAL;
287 int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
288 extern struct vnode *rootvp;
289 struct filecore_disc_record *fcdr;
290 unsigned map;
291 unsigned log2secsize;
292
293 if (!ronly)
294 return EROFS;
295
296 /*
297 * Disallow multiple mounts of the same device.
298 * Disallow mounting of a device that is currently in use
299 * (except for root, which might share swap device for miniroot).
300 * Flush out any old buffers remaining from a previous use.
301 */
302 if ((error = vfs_mountedon(devvp)) != 0)
303 return error;
304 if (vcount(devvp) > 1 && devvp != rootvp)
305 return EBUSY;
306 if ((error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_ucred, l, 0, 0))
307 != 0)
308 return (error);
309
310 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, l);
311 if (error)
312 return error;
313
314 /* Read the filecore boot block to check FS validity and to find the map */
315 error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
316 FILECORE_BOOTBLOCK_SIZE, NOCRED, &bp);
317 #ifdef FILECORE_DEBUG_BR
318 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
319 FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
320 bp, error);
321 #endif
322 if (error != 0)
323 goto out;
324 if (filecore_bbchecksum(bp->b_data) != 0) {
325 error = EINVAL;
326 goto out;
327 }
328 fcdr = (struct filecore_disc_record *)(bp->b_data+FILECORE_BB_DISCREC);
329 map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
330 * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
331 << fcdr->log2bpmb) >> fcdr->log2secsize;
332 log2secsize = fcdr->log2secsize;
333 bp->b_flags |= B_AGE;
334 #ifdef FILECORE_DEBUG_BR
335 printf("brelse(%p) vf1\n", bp);
336 #endif
337 brelse(bp);
338 bp = NULL;
339
340 /* Read the bootblock in the map */
341 error = bread(devvp, map, 1 << log2secsize, NOCRED, &bp);
342 #ifdef FILECORE_DEBUG_BR
343 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
344 map, 1 << log2secsize, bp, error);
345 #endif
346 if (error != 0)
347 goto out;
348 fcdr = (struct filecore_disc_record *)(bp->b_data + 4);
349 fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
350 memset(fcmp, 0, sizeof *fcmp);
351 if (fcdr->log2bpmb > fcdr->log2secsize)
352 fcmp->log2bsize = fcdr->log2bpmb;
353 else fcmp->log2bsize = fcdr->log2secsize;
354 fcmp->blksize = 1 << fcmp->log2bsize;
355 memcpy(&fcmp->drec, fcdr, sizeof(*fcdr));
356 fcmp->map = map;
357 fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
358 / (fcdr->idlen + 1);
359 fcmp->mask = (1 << fcdr->idlen) - 1;
360 if (fcdr->big_flag & 1) {
361 fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
362 + fcdr->disc_size) / fcmp->blksize;
363 } else {
364 fcmp->nblks=fcdr->disc_size / fcmp->blksize;
365 }
366
367 bp->b_flags |= B_AGE;
368 #ifdef FILECORE_DEBUG_BR
369 printf("brelse(%p) vf2\n", bp);
370 #endif
371 brelse(bp);
372 bp = NULL;
373
374 mp->mnt_data = fcmp;
375 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
376 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FILECORE);
377 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
378 mp->mnt_stat.f_namemax = 10;
379 mp->mnt_flag |= MNT_LOCAL;
380 mp->mnt_dev_bshift = fcdr->log2secsize;
381 mp->mnt_fs_bshift = fcmp->log2bsize;
382
383 fcmp->fc_mountp = mp;
384 fcmp->fc_dev = dev;
385 fcmp->fc_devvp = devvp;
386 fcmp->fc_mntflags = argp->flags;
387 if (argp->flags & FILECOREMNT_USEUID) {
388 fcmp->fc_uid = l->l_proc->p_cred->p_ruid;
389 fcmp->fc_gid = l->l_proc->p_cred->p_rgid;
390 } else {
391 fcmp->fc_uid = argp->uid;
392 fcmp->fc_gid = argp->gid;
393 }
394
395 return 0;
396 out:
397 if (bp) {
398 #ifdef FILECORE_DEBUG_BR
399 printf("brelse(%p) vf3\n", bp);
400 #endif
401 brelse(bp);
402 }
403 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
404 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, l);
405 VOP_UNLOCK(devvp, 0);
406 if (fcmp) {
407 free(fcmp, M_FILECOREMNT);
408 mp->mnt_data = NULL;
409 }
410 return error;
411 }
412
413 /*
414 * Make a filesystem operational.
415 * Nothing to do at the moment.
416 */
417 /* ARGSUSED */
418 int
419 filecore_start(mp, flags, l)
420 struct mount *mp;
421 int flags;
422 struct lwp *l;
423 {
424 return 0;
425 }
426
427 /*
428 * unmount system call
429 */
430 int
431 filecore_unmount(mp, mntflags, l)
432 struct mount *mp;
433 int mntflags;
434 struct lwp *l;
435 {
436 struct filecore_mnt *fcmp;
437 int error, flags = 0;
438
439 if (mntflags & MNT_FORCE)
440 flags |= FORCECLOSE;
441 #if 0
442 mntflushbuf(mp, 0);
443 if (mntinvalbuf(mp))
444 return EBUSY;
445 #endif
446 if ((error = vflush(mp, NULLVP, flags)) != 0)
447 return (error);
448
449 fcmp = VFSTOFILECORE(mp);
450
451 if (fcmp->fc_devvp->v_type != VBAD)
452 fcmp->fc_devvp->v_specmountpoint = NULL;
453 vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
454 error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED, l);
455 vput(fcmp->fc_devvp);
456 free(fcmp, M_FILECOREMNT);
457 mp->mnt_data = NULL;
458 mp->mnt_flag &= ~MNT_LOCAL;
459 return (error);
460 }
461
462 /*
463 * Return root of a filesystem
464 */
465 int
466 filecore_root(mp, vpp)
467 struct mount *mp;
468 struct vnode **vpp;
469 {
470 struct vnode *nvp;
471 int error;
472
473 if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
474 return (error);
475 *vpp = nvp;
476 return (0);
477 }
478
479 /*
480 * Do operations associated with quotas, not supported
481 */
482 /* ARGSUSED */
483 int
484 filecore_quotactl(mp, cmd, uid, arg, l)
485 struct mount *mp;
486 int cmd;
487 uid_t uid;
488 void *arg;
489 struct lwp *l;
490 {
491
492 return (EOPNOTSUPP);
493 }
494
495 /*
496 * Get file system statistics.
497 */
498 int
499 filecore_statvfs(mp, sbp, l)
500 struct mount *mp;
501 struct statvfs *sbp;
502 struct lwp *l;
503 {
504 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
505
506 sbp->f_bsize = fcmp->blksize;
507 sbp->f_frsize = sbp->f_bsize; /* XXX */
508 sbp->f_iosize = sbp->f_bsize; /* XXX */
509 sbp->f_blocks = fcmp->nblks;
510 sbp->f_bfree = 0; /* total free blocks */
511 sbp->f_bavail = 0; /* blocks free for non superuser */
512 sbp->f_bresvd = 0; /* reserved blocks */
513 sbp->f_files = 0; /* total files */
514 sbp->f_ffree = 0; /* free file nodes for non superuser */
515 sbp->f_favail = 0; /* free file nodes */
516 sbp->f_fresvd = 0; /* reserved file nodes */
517 copy_statvfs_info(sbp, mp);
518 return 0;
519 }
520
521 /* ARGSUSED */
522 int
523 filecore_sync(mp, waitfor, cred, l)
524 struct mount *mp;
525 int waitfor;
526 struct ucred *cred;
527 struct lwp *l;
528 {
529 return (0);
530 }
531
532 /*
533 * File handle to vnode
534 *
535 * Have to be really careful about stale file handles:
536 * - check that the inode number is in range
537 * - call iget() to get the locked inode
538 * - check for an unallocated inode (i_mode == 0)
539 * - check that the generation number matches
540 */
541
542 struct ifid {
543 ushort ifid_len;
544 ushort ifid_pad;
545 u_int32_t ifid_ino;
546 };
547
548 /* ARGSUSED */
549 int
550 filecore_fhtovp(mp, fhp, vpp)
551 struct mount *mp;
552 struct fid *fhp;
553 struct vnode **vpp;
554 {
555 struct ifid *ifhp = (struct ifid *)fhp;
556 struct vnode *nvp;
557 struct filecore_node *ip;
558 int error;
559
560 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
561 *vpp = NULLVP;
562 return (error);
563 }
564 ip = VTOI(nvp);
565 if (filecore_staleinode(ip)) {
566 vput(nvp);
567 *vpp = NULLVP;
568 return (ESTALE);
569 }
570 *vpp = nvp;
571 return (0);
572 }
573
574 /* ARGSUSED */
575 int
576 filecore_checkexp(mp, nam, exflagsp, credanonp)
577 struct mount *mp;
578 struct mbuf *nam;
579 int *exflagsp;
580 struct ucred **credanonp;
581 {
582 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
583 struct netcred *np;
584
585 /*
586 * Get the export permission structure for this <mp, client> tuple.
587 */
588 np = vfs_export_lookup(mp, &fcmp->fc_export, nam);
589 if (np == NULL)
590 return (EACCES);
591
592 *exflagsp = np->netc_exflags;
593 *credanonp = &np->netc_anon;
594 return (0);
595 }
596
597 /* This looks complicated. Look at other vgets as well as the iso9660 one.
598 *
599 * The filecore inode number is made up of 1 byte directory entry index and
600 * 3 bytes of the internal disc address of the directory. On a read-only
601 * filesystem this is unique. For a read-write version we may not be able to
602 * do vget, see msdosfs.
603 */
604
605 int
606 filecore_vget(mp, ino, vpp)
607 struct mount *mp;
608 ino_t ino;
609 struct vnode **vpp;
610 {
611 struct filecore_mnt *fcmp;
612 struct filecore_node *ip;
613 struct buf *bp;
614 struct vnode *vp;
615 dev_t dev;
616 int error;
617
618 fcmp = VFSTOFILECORE(mp);
619 dev = fcmp->fc_dev;
620 if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
621 return (0);
622
623 /* Allocate a new vnode/filecore_node. */
624 if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
625 != 0) {
626 *vpp = NULLVP;
627 return (error);
628 }
629 ip = pool_get(&filecore_node_pool, PR_WAITOK);
630 memset(ip, 0, sizeof(struct filecore_node));
631 vp->v_data = ip;
632 ip->i_vnode = vp;
633 ip->i_dev = dev;
634 ip->i_number = ino;
635 ip->i_block = -1;
636 ip->i_parent = -2;
637
638 /*
639 * Put it onto its hash chain and lock it so that other requests for
640 * this inode will block if they arrive while we are sleeping waiting
641 * for old data structures to be purged or for the contents of the
642 * disk portion of this inode to be read.
643 */
644 filecore_ihashins(ip);
645
646 if (ino == FILECORE_ROOTINO) {
647 /* Here we need to construct a root directory inode */
648 memcpy(ip->i_dirent.name, "root", 4);
649 ip->i_dirent.load = 0;
650 ip->i_dirent.exec = 0;
651 ip->i_dirent.len = FILECORE_DIR_SIZE;
652 ip->i_dirent.addr = fcmp->drec.root;
653 ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
654
655 } else {
656 /* Read in Data from Directory Entry */
657 if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
658 FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
659 vput(vp);
660 #ifdef FILECORE_DEBUG_BR
661 printf("brelse(%p) vf4\n", bp);
662 #endif
663 brelse(bp);
664 *vpp = NULL;
665 return (error);
666 }
667
668 memcpy(&ip->i_dirent,
669 fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
670 sizeof(struct filecore_direntry));
671 #ifdef FILECORE_DEBUG_BR
672 printf("brelse(%p) vf5\n", bp);
673 #endif
674 brelse(bp);
675 }
676
677 ip->i_mnt = fcmp;
678 ip->i_devvp = fcmp->fc_devvp;
679 ip->i_diroff = 0;
680 VREF(ip->i_devvp);
681
682 /*
683 * Setup type
684 */
685 vp->v_type = VREG;
686 if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
687 vp->v_type = VDIR;
688
689 /*
690 * Initialize the associated vnode
691 */
692 switch (vp->v_type) {
693 case VFIFO:
694 case VCHR:
695 case VBLK:
696 /*
697 * Devices not supported.
698 */
699 vput(vp);
700 return (EOPNOTSUPP);
701 case VLNK:
702 case VNON:
703 case VSOCK:
704 case VDIR:
705 case VBAD:
706 case VREG:
707 break;
708 }
709
710 if (ino == FILECORE_ROOTINO)
711 vp->v_flag |= VROOT;
712
713 /*
714 * XXX need generation number?
715 */
716
717 genfs_node_init(vp, &filecore_genfsops);
718 vp->v_size = ip->i_size;
719 *vpp = vp;
720 return (0);
721 }
722
723 /*
724 * Vnode pointer to File handle
725 */
726 /* ARGSUSED */
727 int
728 filecore_vptofh(vp, fhp)
729 struct vnode *vp;
730 struct fid *fhp;
731 {
732 struct filecore_node *ip = VTOI(vp);
733 struct ifid *ifhp;
734
735 ifhp = (struct ifid *)fhp;
736 ifhp->ifid_len = sizeof(struct ifid);
737 ifhp->ifid_ino = ip->i_number;
738 return 0;
739 }
740
741 SYSCTL_SETUP(sysctl_vfs_filecore_setup, "sysctl vfs.filecore subtree setup")
742 {
743
744 sysctl_createv(clog, 0, NULL, NULL,
745 CTLFLAG_PERMANENT,
746 CTLTYPE_NODE, "vfs", NULL,
747 NULL, 0, NULL, 0,
748 CTL_VFS, CTL_EOL);
749 sysctl_createv(clog, 0, NULL, NULL,
750 CTLFLAG_PERMANENT,
751 CTLTYPE_NODE, "filecore",
752 SYSCTL_DESCR("Acorn FILECORE file system"),
753 NULL, 0, NULL, 0,
754 CTL_VFS, 19, CTL_EOL);
755 /*
756 * XXX the "19" above could be dynamic, thereby eliminating
757 * one more instance of the "number to vfs" mapping problem,
758 * but "19" is the order as taken from sys/mount.h
759 */
760 }
761