1 /*
2  * Copyright (c) 1993 The Regents of the University of California.
3  * Copyright (c) 1993 Jan-Simon Pendry
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Jan-Simon Pendry.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)procfs_vfsops.c	8.2 (Berkeley) 01/06/94
12  *
13  * From:
14  *	$Id: procfs_vfsops.c,v 3.1 1993/12/15 09:40:17 jsp Exp $
15  */
16 
17 /*
18  * procfs VFS interface
19  */
20 
21 #include <sys/param.h>
22 #include <sys/time.h>
23 #include <sys/kernel.h>
24 #include <sys/proc.h>
25 #include <sys/buf.h>
26 #include <sys/syslog.h>
27 #include <sys/mount.h>
28 #include <sys/signalvar.h>
29 #include <sys/vnode.h>
30 #include <miscfs/procfs/procfs.h>
31 #include <vm/vm.h>			/* for PAGE_SIZE */
32 
33 /*
34  * VFS Operations.
35  *
36  * mount system call
37  */
38 /* ARGSUSED */
39 procfs_mount(mp, path, data, ndp, p)
40 	struct mount *mp;
41 	char *path;
42 	caddr_t data;
43 	struct nameidata *ndp;
44 	struct proc *p;
45 {
46 	u_int size;
47 	int error;
48 
49 	if (UIO_MX & (UIO_MX-1)) {
50 		log(LOG_ERR, "procfs: invalid directory entry size");
51 		return (EINVAL);
52 	}
53 
54 	if (mp->mnt_flag & MNT_UPDATE)
55 		return (EOPNOTSUPP);
56 
57 	mp->mnt_flag |= MNT_LOCAL;
58 	mp->mnt_data = 0;
59 	getnewfsid(mp, MOUNT_PROCFS);
60 
61 	(void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
62 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
63 
64 	size = sizeof("procfs") - 1;
65 	bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
66 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
67 
68 	return (0);
69 }
70 
71 /*
72  * unmount system call
73  */
74 procfs_unmount(mp, mntflags, p)
75 	struct mount *mp;
76 	int mntflags;
77 	struct proc *p;
78 {
79 	int error;
80 	extern int doforce;
81 	int flags = 0;
82 
83 	if (mntflags & MNT_FORCE) {
84 		/* procfs can never be rootfs so don't check for it */
85 		if (!doforce)
86 			return (EINVAL);
87 		flags |= FORCECLOSE;
88 	}
89 
90 	if (error = vflush(mp, 0, flags))
91 		return (error);
92 
93 	return (0);
94 }
95 
96 procfs_root(mp, vpp)
97 	struct mount *mp;
98 	struct vnode **vpp;
99 {
100 	struct pfsnode *pfs;
101 	struct vnode *vp;
102 	int error;
103 
104 	error = procfs_allocvp(mp, &vp, (pid_t) 0, Proot);
105 	if (error)
106 		return (error);
107 
108 	vp->v_type = VDIR;
109 	vp->v_flag = VROOT;
110 	pfs = VTOPFS(vp);
111 
112 	*vpp = vp;
113 	return (0);
114 }
115 
116 /*
117  */
118 /* ARGSUSED */
119 procfs_start(mp, flags, p)
120 	struct mount *mp;
121 	int flags;
122 	struct proc *p;
123 {
124 
125 	return (0);
126 }
127 
128 /*
129  * Get file system statistics.
130  */
131 procfs_statfs(mp, sbp, p)
132 	struct mount *mp;
133 	struct statfs *sbp;
134 	struct proc *p;
135 {
136 	sbp->f_type = MOUNT_PROCFS;
137 	sbp->f_bsize = PAGE_SIZE;
138 	sbp->f_iosize = PAGE_SIZE;
139 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
140 	sbp->f_bfree = 0;
141 	sbp->f_bavail = 0;
142 	sbp->f_files = maxproc;			/* approx */
143 	sbp->f_ffree = maxproc - nprocs;	/* approx */
144 
145 	if (sbp != &mp->mnt_stat) {
146 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
147 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
148 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
149 	}
150 
151 	return (0);
152 }
153 
154 
155 procfs_quotactl(mp, cmds, uid, arg, p)
156 	struct mount *mp;
157 	int cmds;
158 	uid_t uid;
159 	caddr_t arg;
160 	struct proc *p;
161 {
162 
163 	return (EOPNOTSUPP);
164 }
165 
166 procfs_sync(mp, waitfor)
167 	struct mount *mp;
168 	int waitfor;
169 {
170 
171 	return (0);
172 }
173 
174 procfs_vget(mp, ino, vpp)
175 	struct mount *mp;
176 	ino_t ino;
177 	struct vnode **vpp;
178 {
179 
180 	return (EOPNOTSUPP);
181 }
182 
183 procfs_fhtovp(mp, fhp, vpp)
184 	struct mount *mp;
185 	struct fid *fhp;
186 	struct vnode **vpp;
187 {
188 
189 	return (EINVAL);
190 }
191 
192 procfs_vptofh(vp, fhp)
193 	struct vnode *vp;
194 	struct fid *fhp;
195 {
196 
197 	return EINVAL;
198 }
199 
200 procfs_init()
201 {
202 
203 	return (0);
204 }
205 
206 struct vfsops procfs_vfsops = {
207 	procfs_mount,
208 	procfs_start,
209 	procfs_unmount,
210 	procfs_root,
211 	procfs_quotactl,
212 	procfs_statfs,
213 	procfs_sync,
214 	procfs_vget,
215 	procfs_fhtovp,
216 	procfs_vptofh,
217 	procfs_init,
218 };
219