Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / emulation / linux / i386 / linprocfs / linprocfs_vfsops.c
1 /*
2  * Copyright (c) 2000 Dag-Erling Coïdan Smørgrav
3  * Copyright (c) 1999 Pierre Beyssac
4  * Copyright (c) 1993 Jan-Simon Pendry
5  * Copyright (c) 1993
6  *      The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Jan-Simon Pendry.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      @(#)procfs_vfsops.c     8.7 (Berkeley) 5/10/95
40  *
41  * $FreeBSD: src/sys/i386/linux/linprocfs/linprocfs_vfsops.c,v 1.2.2.3 2001/10/15 20:42:01 des Exp $
42  */
43
44 /*
45  * procfs VFS interface
46  */
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/proc.h>
52 #include <sys/syslog.h>
53 #include <sys/mount.h>
54 #include <sys/vnode.h>
55 #include <i386/linux/linprocfs/linprocfs.h>
56
57 static int      linprocfs_mount __P((struct mount *mp, char *path, caddr_t data,
58                                   struct nameidata *ndp, struct proc *p));
59 static int      linprocfs_statfs __P((struct mount *mp, struct statfs *sbp,
60                                    struct proc *p));
61 static int      linprocfs_unmount __P((struct mount *mp, int mntflags,
62                                     struct proc *p));
63
64 /*
65  * VFS Operations.
66  *
67  * mount system call
68  */
69 /* ARGSUSED */
70 static int
71 linprocfs_mount(mp, path, data, ndp, p)
72         struct mount *mp;
73         char *path;
74         caddr_t data;
75         struct nameidata *ndp;
76         struct proc *p;
77 {
78         size_t size;
79         int error;
80
81         if (mp->mnt_flag & MNT_UPDATE)
82                 return (EOPNOTSUPP);
83
84         if (mp->mnt_vfc->vfc_refcount == 1 && (error = at_exit(linprocfs_exit))) {
85                 printf("linprocfs:  cannot register linprocfs_exit with at_exit\n");
86                 return(error);
87         }
88
89         mp->mnt_flag |= MNT_LOCAL;
90         mp->mnt_data = 0;
91         vfs_getnewfsid(mp);
92
93         (void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
94         bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
95
96         size = sizeof("linprocfs") - 1;
97         bcopy("linprocfs", mp->mnt_stat.f_mntfromname, size);
98         bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
99         (void)linprocfs_statfs(mp, &mp->mnt_stat, p);
100
101         return (0);
102 }
103
104 /*
105  * unmount system call
106  */
107 static int
108 linprocfs_unmount(mp, mntflags, p)
109         struct mount *mp;
110         int mntflags;
111         struct proc *p;
112 {
113         int error;
114         int flags = 0;
115
116         if (mntflags & MNT_FORCE)
117                 flags |= FORCECLOSE;
118
119         error = vflush(mp, 0, flags);
120         if (error)
121                 return (error);
122
123         if (mp->mnt_vfc->vfc_refcount == 1)
124                 rm_at_exit(linprocfs_exit);
125
126         return (0);
127 }
128
129 int
130 linprocfs_root(mp, vpp)
131         struct mount *mp;
132         struct vnode **vpp;
133 {
134
135         return (linprocfs_allocvp(mp, vpp, 0, Proot));
136 }
137
138 /*
139  * Get file system statistics.
140  */
141 static int
142 linprocfs_statfs(mp, sbp, p)
143         struct mount *mp;
144         struct statfs *sbp;
145         struct proc *p;
146 {
147         sbp->f_bsize = PAGE_SIZE;
148         sbp->f_iosize = PAGE_SIZE;
149         sbp->f_blocks = 1;      /* avoid divide by zero in some df's */
150         sbp->f_bfree = 0;
151         sbp->f_bavail = 0;
152         sbp->f_files = maxproc;                 /* approx */
153         sbp->f_ffree = maxproc - nprocs;        /* approx */
154
155         if (sbp != &mp->mnt_stat) {
156                 sbp->f_type = mp->mnt_vfc->vfc_typenum;
157                 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
158                 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
159                 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
160         }
161
162         return (0);
163 }
164
165 static struct vfsops linprocfs_vfsops = {
166         linprocfs_mount,
167         vfs_stdstart,
168         linprocfs_unmount,
169         linprocfs_root,
170         vfs_stdquotactl,
171         linprocfs_statfs,
172         vfs_stdsync,
173         vfs_stdvget,
174         vfs_stdfhtovp,
175         vfs_stdcheckexp,
176         vfs_stdvptofh,
177         vfs_stdinit,
178 };
179
180 VFS_SET(linprocfs_vfsops, linprocfs, VFCF_SYNTHETIC);
181 MODULE_DEPEND(linprocfs, procfs, 1, 1, 1);