2 * Copyright (c) 1992, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software donated to Berkeley by
6 * the UCLA Ficus project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)umap_vfsops.c 8.8 (Berkeley) 5/14/95
38 * $FreeBSD: src/sys/miscfs/umapfs/umap_vfsops.c,v 1.31.2.2 2001/09/11 09:49:53 kris Exp $
39 * $DragonFly: src/sys/vfs/umapfs/Attic/umap_vfsops.c,v 1.20 2006/05/06 18:48:53 dillon Exp $
44 * (See mount_umap(8) for a description of this layer.)
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
51 #include <sys/vnode.h>
52 #include <sys/mount.h>
53 #include <sys/nlookup.h>
54 #include <sys/malloc.h>
56 #include <vm/vm_zone.h>
58 extern struct vnodeopv_entry_desc umap_vnodeop_entries[];
60 static MALLOC_DEFINE(M_UMAPFSMNT, "UMAP mount", "UMAP mount structure");
62 static int umapfs_fhtovp (struct mount *mp, struct fid *fidp,
64 static int umapfs_checkexp (struct mount *mp, struct sockaddr *nam,
65 int *extflagsp, struct ucred **credanonp);
66 static int umapfs_mount (struct mount *mp, char *path, caddr_t data,
68 static int umapfs_quotactl (struct mount *mp, int cmd, uid_t uid,
69 caddr_t arg, struct ucred *cred);
70 static int umapfs_root (struct mount *mp, struct vnode **vpp);
71 static int umapfs_statfs (struct mount *mp, struct statfs *sbp,
73 static int umapfs_unmount (struct mount *mp, int mntflags);
74 static int umapfs_vget (struct mount *mp, ino_t ino,
76 static int umapfs_vptofh (struct vnode *vp, struct fid *fhp);
77 static int umapfs_extattrctl (struct mount *mp, int cmd,
78 const char *attrname, caddr_t arg,
85 umapfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
87 struct umap_args args;
88 struct vnode *lowerrootvp, *vp;
89 struct vnode *umapm_rootvp;
90 struct umap_mount *amp;
91 struct nlookupdata nd;
101 if ((error = suser_cred(cred, 0)) != 0)
105 printf("umapfs_mount(mp = %p)\n", (void *)mp);
111 if (mp->mnt_flag & MNT_UPDATE) {
118 error = copyin(data, (caddr_t)&args, sizeof(struct umap_args));
126 error = nlookup_init(&nd, args.target, UIO_USERSPACE, NLC_FOLLOW);
128 error = nlookup(&nd);
130 error = cache_vget(nd.nl_ncp, nd.nl_cred, LK_EXCLUSIVE,
138 * Sanity check on lower vnode
141 printf("vp = %p, check for VDIR...\n", (void *)lowerrootvp);
143 if (lowerrootvp->v_type != VDIR) {
149 printf("mp = %p\n", (void *)mp);
152 amp = (struct umap_mount *) malloc(sizeof(struct umap_mount),
153 M_UMAPFSMNT, M_WAITOK); /* XXX */
156 * Save reference to underlying FS
158 amp->umapm_vfs = lowerrootvp->v_mount;
161 * Now copy in the number of entries and maps for umap mapping.
163 if (args.nentries > MAPFILEENTRIES || args.gnentries >
169 amp->info_nentries = args.nentries;
170 amp->info_gnentries = args.gnentries;
171 error = copyin(args.mapdata, (caddr_t)amp->info_mapdata,
172 2*sizeof(u_long)*args.nentries);
177 printf("umap_mount:nentries %d\n",args.nentries);
178 for (i = 0; i < args.nentries; i++)
179 printf(" %lu maps to %lu\n", amp->info_mapdata[i][0],
180 amp->info_mapdata[i][1]);
183 error = copyin(args.gmapdata, (caddr_t)amp->info_gmapdata,
184 2*sizeof(u_long)*args.gnentries);
189 printf("umap_mount:gnentries %d\n",args.gnentries);
190 for (i = 0; i < args.gnentries; i++)
191 printf(" group %lu maps to %lu\n",
192 amp->info_gmapdata[i][0],
193 amp->info_gmapdata[i][1]);
196 vfs_add_vnodeops(mp, &mp->mnt_vn_norm_ops,
197 umap_vnodeop_entries, 0);
200 * Save reference. Each mount also holds
201 * a reference on the root vnode.
203 error = umap_node_create(mp, lowerrootvp, &vp);
205 * Unlock the node (either the lower or the alias)
209 * Make sure the node alias worked
213 free(amp, M_UMAPFSMNT); /* XXX */
218 * Keep a held reference to the root vnode.
219 * It is vrele'd in umapfs_unmount.
222 umapm_rootvp->v_flag |= VROOT;
223 amp->umapm_rootvp = umapm_rootvp;
224 if (UMAPVPTOLOWERVP(umapm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
225 mp->mnt_flag |= MNT_LOCAL;
226 mp->mnt_data = (qaddr_t) amp;
229 (void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
231 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
232 (void)umapfs_statfs(mp, &mp->mnt_stat, cred);
237 * Free reference to umap layer
240 umapfs_unmount(struct mount *mp, int mntflags)
246 printf("umapfs_unmount(mp = %p)\n", (void *)mp);
249 if (mntflags & MNT_FORCE)
253 * Clear out buffer cache. I don't think we
254 * ever get anything cached at this level at the
255 * moment, but who knows...
259 if (mntinvalbuf(mp, 1))
262 /* There is 1 extra root vnode reference (umapm_rootvp). */
263 error = vflush(mp, 1, flags);
268 * Finally, throw away the umap_mount structure
270 free(mp->mnt_data, M_UMAPFSMNT); /* XXX */
276 umapfs_root(struct mount *mp, struct vnode **vpp)
281 printf("umapfs_root(mp = %p, vp = %p->%p)\n",
282 (void *)mp, (void *)MOUNTTOUMAPMOUNT(mp)->umapm_rootvp,
283 (void *)UMAPVPTOLOWERVP(MOUNTTOUMAPMOUNT(mp)->umapm_rootvp));
287 * Return locked reference to root.
289 vp = MOUNTTOUMAPMOUNT(mp)->umapm_rootvp;
291 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
297 umapfs_quotactl(struct mount *mp, int cmd, uid_t uid,
298 caddr_t arg, struct ucred *cred)
300 return (VFS_QUOTACTL(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, cmd, uid, arg, cred));
304 umapfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
310 printf("umapfs_statfs(mp = %p, vp = %p->%p)\n",
311 (void *)mp, (void *)MOUNTTOUMAPMOUNT(mp)->umapm_rootvp,
312 (void *)UMAPVPTOLOWERVP(MOUNTTOUMAPMOUNT(mp)->umapm_rootvp));
315 bzero(&mstat, sizeof(mstat));
317 error = VFS_STATFS(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, &mstat, cred);
321 /* now copy across the "interesting" information and fake the rest */
322 sbp->f_type = mstat.f_type;
323 sbp->f_flags = mstat.f_flags;
324 sbp->f_bsize = mstat.f_bsize;
325 sbp->f_iosize = mstat.f_iosize;
326 sbp->f_blocks = mstat.f_blocks;
327 sbp->f_bfree = mstat.f_bfree;
328 sbp->f_bavail = mstat.f_bavail;
329 sbp->f_files = mstat.f_files;
330 sbp->f_ffree = mstat.f_ffree;
331 if (sbp != &mp->mnt_stat) {
332 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
333 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
339 umapfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
342 return (VFS_VGET(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, ino, vpp));
346 umapfs_fhtovp(struct mount *mp, struct fid *fidp, struct vnode **vpp)
349 return (VFS_FHTOVP(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, fidp, vpp));
353 umapfs_checkexp(struct mount *mp, struct sockaddr *nam, int *exflagsp,
354 struct ucred **credanonp)
357 return (VFS_CHECKEXP(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, nam,
358 exflagsp, credanonp));
362 umapfs_vptofh(struct vnode *vp, struct fid *fhp)
364 return (VFS_VPTOFH(UMAPVPTOLOWERVP(vp), fhp));
368 umapfs_extattrctl(struct mount *mp, int cmd, const char *attrname,
369 caddr_t arg, struct ucred *cred)
371 return (VFS_EXTATTRCTL(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, cmd, attrname,
376 static struct vfsops umap_vfsops = {
377 .vfs_mount = umapfs_mount,
378 .vfs_unmount = umapfs_unmount,
379 .vfs_root = umapfs_root,
380 .vfs_quotactl = umapfs_quotactl,
381 .vfs_statfs = umapfs_statfs,
382 .vfs_sync = vfs_stdsync,
383 .vfs_vget = umapfs_vget,
384 .vfs_fhtovp = umapfs_fhtovp,
385 .vfs_checkexp = umapfs_checkexp,
386 .vfs_vptofh = umapfs_vptofh,
387 .vfs_init = umapfs_init,
388 .vfs_extattrctl = umapfs_extattrctl
391 VFS_SET(umap_vfsops, umap, VFCF_LOOPBACK);