1 /*
2  * Copyright (c) 1993 Jan-Simon Pendry
3  * Copyright (c) 1993
4  *	The Regents of the University of California.  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.7 (Berkeley) 05/10/95
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/systm.h>
23 #include <sys/time.h>
24 #include <sys/kernel.h>
25 #include <sys/proc.h>
26 #include <sys/buf.h>
27 #include <sys/syslog.h>
28 #include <sys/mount.h>
29 #include <sys/signalvar.h>
30 #include <sys/vnode.h>
31 #include <miscfs/procfs/procfs.h>
32 #include <vm/vm.h>			/* for PAGE_SIZE */
33 
34 /*
35  * VFS Operations.
36  *
37  * mount system call
38  */
39 /* ARGSUSED */
40 procfs_mount(mp, path, data, ndp, p)
41 	struct mount *mp;
42 	char *path;
43 	caddr_t data;
44 	struct nameidata *ndp;
45 	struct proc *p;
46 {
47 	u_int size;
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 	vfs_getnewfsid(mp);
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 	int flags = 0;
81 
82 	if (mntflags & MNT_FORCE)
83 		flags |= FORCECLOSE;
84 
85 	if (error = vflush(mp, 0, flags))
86 		return (error);
87 
88 	return (0);
89 }
90 
91 procfs_root(mp, vpp)
92 	struct mount *mp;
93 	struct vnode **vpp;
94 {
95 
96 	return (procfs_allocvp(mp, vpp, 0, Proot));
97 }
98 
99 /* ARGSUSED */
100 procfs_start(mp, flags, p)
101 	struct mount *mp;
102 	int flags;
103 	struct proc *p;
104 {
105 
106 	return (0);
107 }
108 
109 /*
110  * Get file system statistics.
111  */
112 procfs_statfs(mp, sbp, p)
113 	struct mount *mp;
114 	struct statfs *sbp;
115 	struct proc *p;
116 {
117 	sbp->f_bsize = PAGE_SIZE;
118 	sbp->f_iosize = PAGE_SIZE;
119 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
120 	sbp->f_bfree = 0;
121 	sbp->f_bavail = 0;
122 	sbp->f_files = maxproc;			/* approx */
123 	sbp->f_ffree = maxproc - nprocs;	/* approx */
124 
125 	if (sbp != &mp->mnt_stat) {
126 		sbp->f_type = mp->mnt_vfc->vfc_typenum;
127 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
128 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
129 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
130 	}
131 
132 	return (0);
133 }
134 
135 procfs_init(vfsp)
136 	struct vfsconf *vfsp;
137 {
138 
139 	return (0);
140 }
141 
142 #define procfs_fhtovp ((int (*) __P((struct mount *, struct fid *, \
143 	    struct mbuf *, struct vnode **, int *, struct ucred **)))einval)
144 #define procfs_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
145 	    struct proc *)))eopnotsupp)
146 #define procfs_sync ((int (*) __P((struct mount *, int, struct ucred *, \
147 	    struct proc *)))nullop)
148 #define procfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
149 	    size_t, struct proc *)))eopnotsupp)
150 #define procfs_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
151 	    eopnotsupp)
152 #define procfs_vptofh ((int (*) __P((struct vnode *, struct fid *)))einval)
153 
154 struct vfsops procfs_vfsops = {
155 	procfs_mount,
156 	procfs_start,
157 	procfs_unmount,
158 	procfs_root,
159 	procfs_quotactl,
160 	procfs_statfs,
161 	procfs_sync,
162 	procfs_vget,
163 	procfs_fhtovp,
164 	procfs_vptofh,
165 	procfs_init,
166 	procfs_sysctl,
167 };
168