ad9d42e8513a7dd312134f28785a3ae1e3c2547b
[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  * $DragonFly: src/sys/emulation/linux/i386/linprocfs/linprocfs_vfsops.c,v 1.8 2004/12/17 00:18:05 dillon Exp $
43  */
44
45 /*
46  * procfs VFS interface
47  */
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/proc.h>
53 #include <sys/syslog.h>
54 #include <sys/mount.h>
55 #include <sys/vnode.h>
56 #include "linprocfs.h"
57
58 extern struct vnodeopv_entry_desc linprocfs_vnodeop_entries[];
59
60 static int      linprocfs_mount (struct mount *mp, char *path, caddr_t data,
61                                   struct thread *td);
62 static int      linprocfs_statfs (struct mount *mp, struct statfs *sbp,
63                                    struct thread *td);
64 static int      linprocfs_unmount (struct mount *mp, int mntflags,
65                                     struct thread *td);
66
67 /*
68  * VFS Operations.
69  *
70  * mount system call
71  */
72 /* ARGSUSED */
73 static int
74 linprocfs_mount(mp, path, data, td)
75         struct mount *mp;
76         char *path;
77         caddr_t data;
78         struct thread *td;
79 {
80         size_t size;
81         int error;
82
83         if (mp->mnt_flag & MNT_UPDATE)
84                 return (EOPNOTSUPP);
85
86         if (mp->mnt_vfc->vfc_refcount == 1 && (error = at_exit(linprocfs_exit))) {
87                 printf("linprocfs:  cannot register linprocfs_exit with at_exit\n");
88                 return(error);
89         }
90
91         mp->mnt_flag |= MNT_LOCAL;
92         mp->mnt_data = 0;
93         vfs_getnewfsid(mp);
94
95         vfs_add_vnodeops(mp, &mp->mnt_vn_norm_ops, linprocfs_vnodeop_entries);
96
97         (void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
98         bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
99
100         size = sizeof("linprocfs") - 1;
101         bcopy("linprocfs", mp->mnt_stat.f_mntfromname, size);
102         bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
103         (void)linprocfs_statfs(mp, &mp->mnt_stat, td);
104
105         return (0);
106 }
107
108 /*
109  * unmount system call
110  */
111 static int
112 linprocfs_unmount(mp, mntflags, td)
113         struct mount *mp;
114         int mntflags;
115         struct thread *td;
116 {
117         int error;
118         int flags = 0;
119
120         if (mntflags & MNT_FORCE)
121                 flags |= FORCECLOSE;
122
123         error = vflush(mp, 0, flags);
124         if (error)
125                 return (error);
126
127         if (mp->mnt_vfc->vfc_refcount == 1)
128                 rm_at_exit(linprocfs_exit);
129
130         return (0);
131 }
132
133 int
134 linprocfs_root(mp, vpp)
135         struct mount *mp;
136         struct vnode **vpp;
137 {
138
139         return (linprocfs_allocvp(mp, vpp, 0, Proot));
140 }
141
142 /*
143  * Get file system statistics.
144  */
145 static int
146 linprocfs_statfs(mp, sbp, td)
147         struct mount *mp;
148         struct statfs *sbp;
149         struct thread *td;
150 {
151         sbp->f_bsize = PAGE_SIZE;
152         sbp->f_iosize = PAGE_SIZE;
153         sbp->f_blocks = 1;      /* avoid divide by zero in some df's */
154         sbp->f_bfree = 0;
155         sbp->f_bavail = 0;
156         sbp->f_files = maxproc;                 /* approx */
157         sbp->f_ffree = maxproc - nprocs;        /* approx */
158
159         if (sbp != &mp->mnt_stat) {
160                 sbp->f_type = mp->mnt_vfc->vfc_typenum;
161                 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
162                 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
163                 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
164         }
165
166         return (0);
167 }
168
169 static struct vfsops linprocfs_vfsops = {
170         linprocfs_mount,
171         vfs_stdstart,
172         linprocfs_unmount,
173         linprocfs_root,
174         vfs_stdquotactl,
175         linprocfs_statfs,
176         vfs_stdsync,
177         vfs_stdvget,
178         vfs_stdfhtovp,
179         vfs_stdcheckexp,
180         vfs_stdvptofh,
181         vfs_stdinit,
182 };
183
184 VFS_SET(linprocfs_vfsops, linprocfs, VFCF_SYNTHETIC);
185 MODULE_DEPEND(linprocfs, procfs, 1, 1, 1);