2 * Copyright (c) 2001 Dag-Erling Smørgrav
3 * Copyright (c) 1993 Jan-Simon Pendry
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95
43 #include <sys/param.h>
44 #include <sys/queue.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/mount.h>
50 #include <sys/mutex.h>
53 #include <sys/sysproto.h>
54 #include <sys/systm.h>
55 #include <sys/vnode.h>
59 #include <vm/vm_param.h>
61 #include <fs/pseudofs/pseudofs.h>
62 #include <fs/procfs/procfs.h>
65 * Filler function for proc/pid/self
68 procfs_doprocfile(PFS_FILL_ARGS)
70 char *fullpath = "unknown";
71 char *freepath = NULL;
78 vn_fullpath(td, textvp, &fullpath, &freepath);
80 sbuf_printf(sb, "%s", fullpath);
82 free(freepath, M_TEMP);
87 * Filler function for proc/curproc
90 procfs_docurproc(PFS_FILL_ARGS)
92 sbuf_printf(sb, "%ld", (long)td->td_proc->p_pid);
97 * Adjust mode for some nodes that need it
100 procfs_attr(PFS_ATTR_ARGS)
102 PROC_LOCK_ASSERT(p, MA_OWNED);
104 /* XXX inefficient, split into separate functions */
105 if (strcmp(pn->pn_name, "ctl") == 0 ||
106 strcmp(pn->pn_name, "note") == 0 ||
107 strcmp(pn->pn_name, "notepg") == 0)
109 else if (strcmp(pn->pn_name, "mem") == 0 ||
110 strcmp(pn->pn_name, "regs") == 0 ||
111 strcmp(pn->pn_name, "dbregs") == 0 ||
112 strcmp(pn->pn_name, "fpregs") == 0)
115 if ((p->p_flag & P_SUGID) && pn->pn_type != pfstype_procdir)
118 vap->va_uid = p->p_ucred->cr_uid;
119 vap->va_gid = p->p_ucred->cr_gid;
125 * Visibility: some files only exist for non-system processes
126 * Non-static because linprocfs uses it.
129 procfs_notsystem(PFS_VIS_ARGS)
131 PROC_LOCK_ASSERT(p, MA_OWNED);
132 return ((p->p_flag & P_SYSTEM) == 0);
136 * Visibility: some files are only visible to process that can debug
137 * the target process.
140 procfs_candebug(PFS_VIS_ARGS)
142 PROC_LOCK_ASSERT(p, MA_OWNED);
143 return ((p->p_flag & P_SYSTEM) == 0 && p_candebug(td, p) == 0);
150 procfs_init(PFS_INIT_ARGS)
152 struct pfs_node *root;
153 struct pfs_node *dir;
154 struct pfs_node *node;
158 pfs_create_link(root, "curproc", procfs_docurproc,
159 NULL, NULL, NULL, 0);
161 dir = pfs_create_dir(root, "pid",
162 procfs_attr, NULL, NULL, PFS_PROCDEP);
163 pfs_create_file(dir, "cmdline", procfs_doproccmdline,
164 NULL, NULL, NULL, PFS_RD);
165 pfs_create_file(dir, "ctl", procfs_doprocctl,
166 procfs_attr, NULL, NULL, PFS_WR);
167 pfs_create_file(dir, "dbregs", procfs_doprocdbregs,
168 procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW);
169 pfs_create_file(dir, "etype", procfs_doproctype,
170 NULL, NULL, NULL, PFS_RD);
171 pfs_create_file(dir, "fpregs", procfs_doprocfpregs,
172 procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW);
173 pfs_create_file(dir, "map", procfs_doprocmap,
174 NULL, procfs_notsystem, NULL, PFS_RD);
175 node = pfs_create_file(dir, "mem", procfs_doprocmem,
176 procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW);
177 node->pn_ioctl = procfs_ioctl;
178 node->pn_close = procfs_close;
179 pfs_create_file(dir, "note", procfs_doprocnote,
180 procfs_attr, procfs_candebug, NULL, PFS_WR);
181 pfs_create_file(dir, "notepg", procfs_doprocnote,
182 procfs_attr, procfs_candebug, NULL, PFS_WR);
183 pfs_create_file(dir, "regs", procfs_doprocregs,
184 procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW);
185 pfs_create_file(dir, "rlimit", procfs_doprocrlimit,
186 NULL, NULL, NULL, PFS_RD);
187 pfs_create_file(dir, "status", procfs_doprocstatus,
188 NULL, NULL, NULL, PFS_RD);
190 pfs_create_link(dir, "file", procfs_doprocfile,
191 NULL, procfs_notsystem, NULL, 0);
200 procfs_uninit(PFS_INIT_ARGS)
202 /* nothing to do, pseudofs will GC */