2005-05-30 01:55:33 +04:00
|
|
|
/* $NetBSD: procfs_vnops.c,v 1.123 2005/05/29 21:55:34 christos Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-08-24 16:59:09 +04:00
|
|
|
/*
|
1998-03-01 05:20:01 +03:00
|
|
|
* Copyright (c) 1993, 1995
|
1994-06-08 15:33:09 +04:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-08-24 20:25:07 +04:00
|
|
|
*
|
1994-01-05 10:51:08 +03:00
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
1993-08-24 20:25:07 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1993 Jan-Simon Pendry
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1993-08-24 20:25:07 +04:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1994-01-05 10:51:08 +03:00
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1993-08-24 20:25:07 +04:00
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95
|
1993-08-24 20:25:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* procfs vnode interface
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-10 16:33:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-05-30 01:55:33 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.123 2005/05/29 21:55:34 christos Exp $");
|
2001-11-10 16:33:40 +03:00
|
|
|
|
1993-12-18 06:48:27 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/file.h>
|
2003-01-03 16:21:17 +03:00
|
|
|
#include <sys/filedesc.h>
|
1993-12-18 06:48:27 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/namei.h>
|
1994-01-05 10:51:08 +03:00
|
|
|
#include <sys/malloc.h>
|
2001-01-17 03:09:07 +03:00
|
|
|
#include <sys/mount.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/dirent.h>
|
1993-12-18 06:48:27 +03:00
|
|
|
#include <sys/resourcevar.h>
|
1997-05-05 11:34:09 +04:00
|
|
|
#include <sys/stat.h>
|
2002-05-09 19:44:44 +04:00
|
|
|
#include <sys/ptrace.h>
|
1997-05-05 11:34:09 +04:00
|
|
|
|
2000-06-28 06:44:06 +04:00
|
|
|
#include <uvm/uvm_extern.h> /* for PAGE_SIZE */
|
1997-05-05 11:34:09 +04:00
|
|
|
|
1994-01-06 00:56:02 +03:00
|
|
|
#include <machine/reg.h>
|
1996-09-02 03:47:48 +04:00
|
|
|
|
|
|
|
#include <miscfs/genfs/genfs.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <miscfs/procfs/procfs.h>
|
1994-01-06 00:56:02 +03:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
/*
|
|
|
|
* Vnode Operations.
|
|
|
|
*
|
|
|
|
*/
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
static int procfs_validfile_linux __P((struct proc *, struct mount *));
|
2004-10-01 20:32:16 +04:00
|
|
|
static int procfs_root_readdir_callback(struct proc *, void *);
|
2000-08-10 03:30:49 +04:00
|
|
|
|
1993-08-24 16:59:09 +04:00
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* This is a list of the valid names in the
|
|
|
|
* process-specific sub-directories. It is
|
|
|
|
* used in procfs_lookup and procfs_readdir
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
2003-04-17 22:08:28 +04:00
|
|
|
static const struct proc_target {
|
1995-02-03 19:18:46 +03:00
|
|
|
u_char pt_type;
|
|
|
|
u_char pt_namlen;
|
2003-04-17 22:08:28 +04:00
|
|
|
const char *pt_name;
|
1995-02-03 19:18:46 +03:00
|
|
|
pfstype pt_pfstype;
|
2003-06-30 02:28:00 +04:00
|
|
|
int (*pt_valid) __P((struct proc *, struct mount *));
|
1995-02-03 19:18:46 +03:00
|
|
|
} proc_targets[] = {
|
1994-01-05 10:51:08 +03:00
|
|
|
#define N(s) sizeof(s)-1, s
|
1995-02-03 19:18:46 +03:00
|
|
|
/* name type validp */
|
2003-09-27 17:29:02 +04:00
|
|
|
{ DT_DIR, N("."), PFSproc, NULL },
|
|
|
|
{ DT_DIR, N(".."), PFSroot, NULL },
|
|
|
|
{ DT_DIR, N("fd"), PFSfd, NULL },
|
|
|
|
{ DT_REG, N("file"), PFSfile, procfs_validfile },
|
|
|
|
{ DT_REG, N("mem"), PFSmem, NULL },
|
|
|
|
{ DT_REG, N("regs"), PFSregs, procfs_validregs },
|
|
|
|
{ DT_REG, N("fpregs"), PFSfpregs, procfs_validfpregs },
|
|
|
|
{ DT_REG, N("ctl"), PFSctl, NULL },
|
|
|
|
{ DT_REG, N("stat"), PFSstat, procfs_validfile_linux },
|
|
|
|
{ DT_REG, N("status"), PFSstatus, NULL },
|
|
|
|
{ DT_REG, N("note"), PFSnote, NULL },
|
|
|
|
{ DT_REG, N("notepg"), PFSnotepg, NULL },
|
|
|
|
{ DT_REG, N("map"), PFSmap, procfs_validmap },
|
|
|
|
{ DT_REG, N("maps"), PFSmaps, procfs_validmap },
|
|
|
|
{ DT_REG, N("cmdline"), PFScmdline, NULL },
|
|
|
|
{ DT_REG, N("exe"), PFSfile, procfs_validfile_linux },
|
2001-12-05 03:58:05 +03:00
|
|
|
#ifdef __HAVE_PROCFS_MACHDEP
|
|
|
|
PROCFS_MACHDEP_NODETYPE_DEFNS
|
|
|
|
#endif
|
1994-01-05 10:51:08 +03:00
|
|
|
#undef N
|
1993-08-24 16:59:09 +04:00
|
|
|
};
|
2003-04-17 22:08:28 +04:00
|
|
|
static const int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2001-01-17 03:09:07 +03:00
|
|
|
/*
|
|
|
|
* List of files in the root directory. Note: the validate function will
|
|
|
|
* be called with p == NULL for these ones.
|
|
|
|
*/
|
2003-04-17 22:08:28 +04:00
|
|
|
static const struct proc_target proc_root_targets[] = {
|
2001-01-17 03:09:07 +03:00
|
|
|
#define N(s) sizeof(s)-1, s
|
|
|
|
/* name type validp */
|
2003-09-27 17:29:02 +04:00
|
|
|
{ DT_REG, N("meminfo"), PFSmeminfo, procfs_validfile_linux },
|
|
|
|
{ DT_REG, N("cpuinfo"), PFScpuinfo, procfs_validfile_linux },
|
|
|
|
{ DT_REG, N("uptime"), PFSuptime, procfs_validfile_linux },
|
2004-09-20 21:53:08 +04:00
|
|
|
{ DT_REG, N("mounts"), PFSmounts, procfs_validfile_linux },
|
2001-01-17 03:09:07 +03:00
|
|
|
#undef N
|
|
|
|
};
|
2003-04-17 22:08:28 +04:00
|
|
|
static const int nproc_root_targets =
|
2001-01-17 03:09:07 +03:00
|
|
|
sizeof(proc_root_targets) / sizeof(proc_root_targets[0]);
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
int procfs_lookup __P((void *));
|
2003-04-11 01:53:32 +04:00
|
|
|
#define procfs_create genfs_eopnotsupp
|
|
|
|
#define procfs_mknod genfs_eopnotsupp
|
1996-02-10 01:39:56 +03:00
|
|
|
int procfs_open __P((void *));
|
|
|
|
int procfs_close __P((void *));
|
|
|
|
int procfs_access __P((void *));
|
|
|
|
int procfs_getattr __P((void *));
|
|
|
|
int procfs_setattr __P((void *));
|
|
|
|
#define procfs_read procfs_rw
|
|
|
|
#define procfs_write procfs_rw
|
1999-08-04 00:19:16 +04:00
|
|
|
#define procfs_fcntl genfs_fcntl
|
1998-08-10 12:11:10 +04:00
|
|
|
#define procfs_ioctl genfs_enoioctl
|
1996-09-07 16:40:22 +04:00
|
|
|
#define procfs_poll genfs_poll
|
1998-03-01 05:20:01 +03:00
|
|
|
#define procfs_revoke genfs_revoke
|
1996-09-02 03:47:48 +04:00
|
|
|
#define procfs_fsync genfs_nullop
|
|
|
|
#define procfs_seek genfs_nullop
|
2003-04-11 01:53:32 +04:00
|
|
|
#define procfs_remove genfs_eopnotsupp
|
1996-02-10 01:39:56 +03:00
|
|
|
int procfs_link __P((void *));
|
2003-04-11 01:53:32 +04:00
|
|
|
#define procfs_rename genfs_eopnotsupp
|
|
|
|
#define procfs_mkdir genfs_eopnotsupp
|
|
|
|
#define procfs_rmdir genfs_eopnotsupp
|
1996-02-10 01:39:56 +03:00
|
|
|
int procfs_symlink __P((void *));
|
|
|
|
int procfs_readdir __P((void *));
|
|
|
|
int procfs_readlink __P((void *));
|
1996-09-02 03:47:48 +04:00
|
|
|
#define procfs_abortop genfs_abortop
|
1996-02-10 01:39:56 +03:00
|
|
|
int procfs_inactive __P((void *));
|
|
|
|
int procfs_reclaim __P((void *));
|
1999-07-08 05:26:21 +04:00
|
|
|
#define procfs_lock genfs_lock
|
|
|
|
#define procfs_unlock genfs_unlock
|
2001-06-03 06:21:35 +04:00
|
|
|
#define procfs_bmap genfs_badop
|
1996-09-02 03:47:48 +04:00
|
|
|
#define procfs_strategy genfs_badop
|
1996-02-10 01:39:56 +03:00
|
|
|
int procfs_print __P((void *));
|
|
|
|
int procfs_pathconf __P((void *));
|
1999-07-08 05:26:21 +04:00
|
|
|
#define procfs_islocked genfs_islocked
|
1998-08-13 14:06:31 +04:00
|
|
|
#define procfs_advlock genfs_einval
|
1996-09-02 03:47:48 +04:00
|
|
|
#define procfs_blkatoff genfs_eopnotsupp
|
|
|
|
#define procfs_valloc genfs_eopnotsupp
|
|
|
|
#define procfs_vfree genfs_nullop
|
|
|
|
#define procfs_truncate genfs_eopnotsupp
|
|
|
|
#define procfs_update genfs_nullop
|
|
|
|
#define procfs_bwrite genfs_eopnotsupp
|
2001-12-06 07:27:40 +03:00
|
|
|
#define procfs_putpages genfs_null_putpages
|
1996-02-10 01:39:56 +03:00
|
|
|
|
2003-01-03 16:21:17 +03:00
|
|
|
static int atoi __P((const char *, size_t));
|
1996-02-10 01:39:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* procfs vnode operations.
|
|
|
|
*/
|
|
|
|
int (**procfs_vnodeop_p) __P((void *));
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_entry_desc procfs_vnodeop_entries[] = {
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_default_desc, vn_default_error },
|
|
|
|
{ &vop_lookup_desc, procfs_lookup }, /* lookup */
|
|
|
|
{ &vop_create_desc, procfs_create }, /* create */
|
|
|
|
{ &vop_mknod_desc, procfs_mknod }, /* mknod */
|
|
|
|
{ &vop_open_desc, procfs_open }, /* open */
|
|
|
|
{ &vop_close_desc, procfs_close }, /* close */
|
|
|
|
{ &vop_access_desc, procfs_access }, /* access */
|
|
|
|
{ &vop_getattr_desc, procfs_getattr }, /* getattr */
|
|
|
|
{ &vop_setattr_desc, procfs_setattr }, /* setattr */
|
|
|
|
{ &vop_read_desc, procfs_read }, /* read */
|
|
|
|
{ &vop_write_desc, procfs_write }, /* write */
|
1999-08-04 00:19:16 +04:00
|
|
|
{ &vop_fcntl_desc, procfs_fcntl }, /* fcntl */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_ioctl_desc, procfs_ioctl }, /* ioctl */
|
1996-09-07 16:40:22 +04:00
|
|
|
{ &vop_poll_desc, procfs_poll }, /* poll */
|
1998-03-01 05:20:01 +03:00
|
|
|
{ &vop_revoke_desc, procfs_revoke }, /* revoke */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_fsync_desc, procfs_fsync }, /* fsync */
|
|
|
|
{ &vop_seek_desc, procfs_seek }, /* seek */
|
|
|
|
{ &vop_remove_desc, procfs_remove }, /* remove */
|
|
|
|
{ &vop_link_desc, procfs_link }, /* link */
|
|
|
|
{ &vop_rename_desc, procfs_rename }, /* rename */
|
|
|
|
{ &vop_mkdir_desc, procfs_mkdir }, /* mkdir */
|
|
|
|
{ &vop_rmdir_desc, procfs_rmdir }, /* rmdir */
|
|
|
|
{ &vop_symlink_desc, procfs_symlink }, /* symlink */
|
|
|
|
{ &vop_readdir_desc, procfs_readdir }, /* readdir */
|
|
|
|
{ &vop_readlink_desc, procfs_readlink }, /* readlink */
|
|
|
|
{ &vop_abortop_desc, procfs_abortop }, /* abortop */
|
|
|
|
{ &vop_inactive_desc, procfs_inactive }, /* inactive */
|
|
|
|
{ &vop_reclaim_desc, procfs_reclaim }, /* reclaim */
|
|
|
|
{ &vop_lock_desc, procfs_lock }, /* lock */
|
|
|
|
{ &vop_unlock_desc, procfs_unlock }, /* unlock */
|
|
|
|
{ &vop_bmap_desc, procfs_bmap }, /* bmap */
|
|
|
|
{ &vop_strategy_desc, procfs_strategy }, /* strategy */
|
|
|
|
{ &vop_print_desc, procfs_print }, /* print */
|
|
|
|
{ &vop_islocked_desc, procfs_islocked }, /* islocked */
|
|
|
|
{ &vop_pathconf_desc, procfs_pathconf }, /* pathconf */
|
|
|
|
{ &vop_advlock_desc, procfs_advlock }, /* advlock */
|
|
|
|
{ &vop_blkatoff_desc, procfs_blkatoff }, /* blkatoff */
|
|
|
|
{ &vop_valloc_desc, procfs_valloc }, /* valloc */
|
|
|
|
{ &vop_vfree_desc, procfs_vfree }, /* vfree */
|
|
|
|
{ &vop_truncate_desc, procfs_truncate }, /* truncate */
|
|
|
|
{ &vop_update_desc, procfs_update }, /* update */
|
2001-12-06 07:27:40 +03:00
|
|
|
{ &vop_putpages_desc, procfs_putpages }, /* putpages */
|
2001-06-03 06:21:35 +04:00
|
|
|
{ NULL, NULL }
|
1996-02-10 01:39:56 +03:00
|
|
|
};
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc procfs_vnodeop_opv_desc =
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &procfs_vnodeop_p, procfs_vnodeop_entries };
|
1993-08-24 16:59:09 +04:00
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* set things up for doing i/o on
|
|
|
|
* the pfsnode (vp). (vp) is locked
|
|
|
|
* on entry, and should be left locked
|
|
|
|
* on exit.
|
1993-08-24 16:59:09 +04:00
|
|
|
*
|
1994-01-05 10:51:08 +03:00
|
|
|
* for procfs we don't need to do anything
|
|
|
|
* in particular for i/o. all that is done
|
|
|
|
* is to support exclusive open on process
|
|
|
|
* memory images.
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_open(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct pfsnode *pfs = VTOPFS(ap->a_vp);
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p1, *p2;
|
2002-01-12 21:51:56 +03:00
|
|
|
int error;
|
1997-08-13 02:47:18 +04:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
p1 = ap->a_p; /* tracer */
|
1997-08-27 12:52:51 +04:00
|
|
|
p2 = PFIND(pfs->pfs_pid); /* traced */
|
1997-08-13 02:47:18 +04:00
|
|
|
|
|
|
|
if (p2 == NULL)
|
|
|
|
return (ENOENT); /* was ESRCH, jsp */
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
switch (pfs->pfs_type) {
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSmem:
|
1996-02-10 01:39:56 +03:00
|
|
|
if (((pfs->pfs_flags & FWRITE) && (ap->a_mode & O_EXCL)) ||
|
|
|
|
((pfs->pfs_flags & O_EXCL) && (ap->a_mode & FWRITE)))
|
1994-01-05 10:51:08 +03:00
|
|
|
return (EBUSY);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = process_checkioperm(p1, p2)) != 0)
|
2002-01-12 21:51:56 +03:00
|
|
|
return (error);
|
1997-08-13 02:47:18 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (ap->a_mode & FWRITE)
|
|
|
|
pfs->pfs_flags = ap->a_mode & (FWRITE|O_EXCL);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
return (0);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
return (0);
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* close the pfsnode (vp) after doing i/o.
|
|
|
|
* (vp) is not locked on entry or exit.
|
|
|
|
*
|
|
|
|
* nothing to do for procfs other than undo
|
|
|
|
* any exclusive open flag (see _open above).
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_close(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_close_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_fflag;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct pfsnode *pfs = VTOPFS(ap->a_vp);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
switch (pfs->pfs_type) {
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSmem:
|
1994-06-08 15:33:09 +04:00
|
|
|
if ((ap->a_fflag & FWRITE) && (pfs->pfs_flags & O_EXCL))
|
1994-01-05 10:51:08 +03:00
|
|
|
pfs->pfs_flags &= ~(FWRITE|O_EXCL);
|
|
|
|
break;
|
1997-04-28 07:49:57 +04:00
|
|
|
|
|
|
|
default:
|
1996-02-10 01:39:56 +03:00
|
|
|
break;
|
1994-01-05 10:51:08 +03:00
|
|
|
}
|
1993-08-24 16:59:09 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* _inactive is called when the pfsnode
|
|
|
|
* is vrele'd and the reference count goes
|
|
|
|
* to zero. (vp) will be on the vnode free
|
|
|
|
* list, so to get it back vget() must be
|
|
|
|
* used.
|
|
|
|
*
|
|
|
|
* for procfs, check if the process is still
|
|
|
|
* alive and if it isn't then just throw away
|
|
|
|
* the vnode by calling vgone(). this may
|
|
|
|
* be overkill and a waste of time since the
|
|
|
|
* chances are that the process will still be
|
|
|
|
* there and PFIND is not free.
|
|
|
|
*
|
1999-07-08 05:26:21 +04:00
|
|
|
* (vp) is locked on entry, but must be unlocked on exit.
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_inactive(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2005-04-02 10:15:09 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct pfsnode *pfs = VTOPFS(vp);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2005-04-02 10:15:09 +04:00
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
if (PFIND(pfs->pfs_pid) == NULL && (vp->v_flag & VXLOCK) == 0)
|
|
|
|
vgone(vp);
|
1993-08-26 23:01:00 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
return (0);
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* _reclaim is called when getnewvnode()
|
|
|
|
* wants to make use of an entry on the vnode
|
|
|
|
* free list. at this time the filesystem needs
|
|
|
|
* to free any private data and remove the node
|
|
|
|
* from any private lists.
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_reclaim(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (procfs_freevp(ap->a_vp));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return POSIX pathconf information applicable to special devices.
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_pathconf(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_pathconf_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_name;
|
1994-10-20 07:22:35 +03:00
|
|
|
register_t *a_retval;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*ap->a_retval = LINK_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_MAX_CANON:
|
|
|
|
*ap->a_retval = MAX_CANON;
|
|
|
|
return (0);
|
|
|
|
case _PC_MAX_INPUT:
|
|
|
|
*ap->a_retval = MAX_INPUT;
|
|
|
|
return (0);
|
|
|
|
case _PC_PIPE_BUF:
|
|
|
|
*ap->a_retval = PIPE_BUF;
|
|
|
|
return (0);
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
|
|
|
case _PC_VDISABLE:
|
|
|
|
*ap->a_retval = _POSIX_VDISABLE;
|
|
|
|
return (0);
|
1998-08-03 18:19:57 +04:00
|
|
|
case _PC_SYNC_IO:
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
1994-06-08 15:33:09 +04:00
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* _print is used for debugging.
|
|
|
|
* just print a readable description
|
|
|
|
* of (vp).
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_print(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_print_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct pfsnode *pfs = VTOPFS(ap->a_vp);
|
1993-08-26 23:01:00 +04:00
|
|
|
|
1996-10-13 06:21:25 +04:00
|
|
|
printf("tag VT_PROCFS, type %d, pid %d, mode %x, flags %lx\n",
|
1994-06-08 15:33:09 +04:00
|
|
|
pfs->pfs_type, pfs->pfs_pid, pfs->pfs_mode, pfs->pfs_flags);
|
1996-02-10 01:39:56 +03:00
|
|
|
return 0;
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
int
|
2005-02-27 01:58:54 +03:00
|
|
|
procfs_link(v)
|
1996-02-10 01:39:56 +03:00
|
|
|
void *v;
|
|
|
|
{
|
1996-02-09 17:45:36 +03:00
|
|
|
struct vop_link_args /* {
|
|
|
|
struct vnode *a_dvp;
|
2005-02-27 01:58:54 +03:00
|
|
|
struct vnode *a_vp;
|
1996-02-09 17:45:36 +03:00
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
|
|
|
|
vput(ap->a_dvp);
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
procfs_symlink(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1996-02-09 17:45:36 +03:00
|
|
|
struct vop_symlink_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
char *a_target;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
|
|
|
|
vput(ap->a_dvp);
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
1993-08-24 16:59:09 +04:00
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* Invent attributes for pfsnode (vp) and store
|
|
|
|
* them in (vap).
|
|
|
|
* Directories lengths are returned as zero since
|
|
|
|
* any real length would require the genuine size
|
|
|
|
* to be computed, and nothing cares anyway.
|
|
|
|
*
|
|
|
|
* this is relatively minimal for procfs.
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_getattr(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct pfsnode *pfs = VTOPFS(ap->a_vp);
|
|
|
|
struct vattr *vap = ap->a_vap;
|
1993-08-24 16:59:09 +04:00
|
|
|
struct proc *procp;
|
1994-01-05 10:51:08 +03:00
|
|
|
int error;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/* first check the process still exists */
|
|
|
|
switch (pfs->pfs_type) {
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSroot:
|
|
|
|
case PFScurproc:
|
|
|
|
case PFSself:
|
1994-06-08 15:33:09 +04:00
|
|
|
procp = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
procp = PFIND(pfs->pfs_pid);
|
2003-01-03 16:21:17 +03:00
|
|
|
if (procp == NULL)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (ENOENT);
|
1997-04-28 07:49:57 +04:00
|
|
|
break;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
/* start by zeroing out the attributes */
|
1993-08-24 16:59:09 +04:00
|
|
|
VATTR_NULL(vap);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
/* next do all the common fields */
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_type = ap->a_vp->v_type;
|
1994-01-05 10:51:08 +03:00
|
|
|
vap->va_mode = pfs->pfs_mode;
|
|
|
|
vap->va_fileid = pfs->pfs_fileno;
|
|
|
|
vap->va_flags = 0;
|
1994-04-16 00:49:27 +04:00
|
|
|
vap->va_blocksize = PAGE_SIZE;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
/*
|
2002-08-03 08:52:44 +04:00
|
|
|
* Make all times be current TOD. Avoid microtime(9), it's slow.
|
|
|
|
* We don't guard the read from time(9) with splclock(9) since we
|
2005-02-27 01:58:54 +03:00
|
|
|
* don't actually need to be THAT sure the access is atomic.
|
2002-08-03 08:52:44 +04:00
|
|
|
*
|
1994-01-05 10:51:08 +03:00
|
|
|
* It would be possible to get the process start
|
|
|
|
* time from the p_stat structure, but there's
|
|
|
|
* no "file creation" time stamp anyway, and the
|
|
|
|
* p_stat structure is not addressible if u. gets
|
|
|
|
* swapped out for that process.
|
|
|
|
*/
|
2002-08-03 08:52:44 +04:00
|
|
|
TIMEVAL_TO_TIMESPEC(&time, &vap->va_ctime);
|
1994-01-05 10:51:08 +03:00
|
|
|
vap->va_atime = vap->va_mtime = vap->va_ctime;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
switch (pfs->pfs_type) {
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSmem:
|
|
|
|
case PFSregs:
|
|
|
|
case PFSfpregs:
|
2001-12-05 03:58:05 +03:00
|
|
|
#if defined(__HAVE_PROCFS_MACHDEP) && defined(PROCFS_MACHDEP_PROTECT_CASES)
|
|
|
|
PROCFS_MACHDEP_PROTECT_CASES
|
|
|
|
#endif
|
1997-05-05 11:13:57 +04:00
|
|
|
/*
|
|
|
|
* If the process has exercised some setuid or setgid
|
|
|
|
* privilege, then rip away read/write permission so
|
|
|
|
* that only root can gain access.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (procp->p_flag & P_SUGID)
|
1997-05-05 11:13:57 +04:00
|
|
|
vap->va_mode &= ~(S_IRUSR|S_IWUSR);
|
1997-04-28 07:49:57 +04:00
|
|
|
/* FALLTHROUGH */
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSctl:
|
|
|
|
case PFSstatus:
|
|
|
|
case PFSstat:
|
|
|
|
case PFSnote:
|
|
|
|
case PFSnotepg:
|
|
|
|
case PFSmap:
|
|
|
|
case PFSmaps:
|
|
|
|
case PFScmdline:
|
1994-01-09 22:44:03 +03:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_uid = procp->p_ucred->cr_uid;
|
|
|
|
vap->va_gid = procp->p_ucred->cr_gid;
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSmeminfo:
|
|
|
|
case PFScpuinfo:
|
|
|
|
case PFSuptime:
|
2004-09-20 21:53:08 +04:00
|
|
|
case PFSmounts:
|
2001-01-17 03:09:07 +03:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_uid = vap->va_gid = 0;
|
|
|
|
break;
|
1997-04-28 07:49:57 +04:00
|
|
|
|
|
|
|
default:
|
1996-02-10 01:39:56 +03:00
|
|
|
break;
|
1994-01-09 22:44:03 +03:00
|
|
|
}
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
/*
|
|
|
|
* now do the object specific fields
|
|
|
|
*
|
|
|
|
* The size could be set from struct reg, but it's hardly
|
|
|
|
* worth the trouble, and it puts some (potentially) machine
|
|
|
|
* dependent data into this machine-independent code. If it
|
|
|
|
* becomes important then this function should break out into
|
|
|
|
* a per-file stat function in the corresponding .c file.
|
|
|
|
*/
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
switch (pfs->pfs_type) {
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSroot:
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Set nlink to 1 to tell fts(3) we don't actually know.
|
|
|
|
*/
|
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
1997-04-28 07:49:57 +04:00
|
|
|
vap->va_bytes = vap->va_size = DEV_BSIZE;
|
1994-01-05 10:51:08 +03:00
|
|
|
break;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFScurproc: {
|
2005-05-30 01:55:33 +04:00
|
|
|
char bf[16]; /* should be enough */
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
1997-04-28 07:49:57 +04:00
|
|
|
vap->va_bytes = vap->va_size =
|
2005-05-30 01:55:33 +04:00
|
|
|
snprintf(bf, sizeof(bf), "%ld", (long)curproc->p_pid);
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSself:
|
1999-09-03 03:33:45 +04:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
2004-10-02 08:28:57 +04:00
|
|
|
vap->va_bytes = vap->va_size = sizeof("curproc") - 1;
|
1999-09-03 03:33:45 +04:00
|
|
|
break;
|
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSfd:
|
2003-01-03 16:21:17 +03:00
|
|
|
if (pfs->pfs_fd != -1) {
|
|
|
|
struct file *fp;
|
2003-04-17 23:04:25 +04:00
|
|
|
struct proc *pown;
|
|
|
|
|
|
|
|
if ((error = procfs_getfp(pfs, &pown, &fp)) != 0)
|
2003-01-03 16:21:17 +03:00
|
|
|
return error;
|
2003-04-17 23:04:25 +04:00
|
|
|
FILE_USE(fp);
|
2003-01-03 16:21:17 +03:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_uid = fp->f_cred->cr_uid;
|
|
|
|
vap->va_gid = fp->f_cred->cr_gid;
|
|
|
|
switch (fp->f_type) {
|
|
|
|
case DTYPE_VNODE:
|
|
|
|
vap->va_bytes = vap->va_size =
|
|
|
|
((struct vnode *)fp->f_data)->v_size;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vap->va_bytes = vap->va_size = 0;
|
|
|
|
break;
|
|
|
|
}
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, pown);
|
2003-01-03 16:21:17 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*FALLTHROUGH*/
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSproc:
|
1994-01-05 10:51:08 +03:00
|
|
|
vap->va_nlink = 2;
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_uid = procp->p_ucred->cr_uid;
|
|
|
|
vap->va_gid = procp->p_ucred->cr_gid;
|
1997-04-28 07:49:57 +04:00
|
|
|
vap->va_bytes = vap->va_size = DEV_BSIZE;
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSfile:
|
1994-06-08 15:33:09 +04:00
|
|
|
error = EOPNOTSUPP;
|
1994-01-05 10:51:08 +03:00
|
|
|
break;
|
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSmem:
|
1994-01-05 10:51:08 +03:00
|
|
|
vap->va_bytes = vap->va_size =
|
|
|
|
ctob(procp->p_vmspace->vm_tsize +
|
|
|
|
procp->p_vmspace->vm_dsize +
|
|
|
|
procp->p_vmspace->vm_ssize);
|
|
|
|
break;
|
|
|
|
|
1994-01-28 10:03:16 +03:00
|
|
|
#if defined(PT_GETREGS) || defined(PT_SETREGS)
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSregs:
|
1994-01-06 00:56:02 +03:00
|
|
|
vap->va_bytes = vap->va_size = sizeof(struct reg);
|
1994-01-28 10:03:16 +03:00
|
|
|
break;
|
1994-04-12 06:55:51 +04:00
|
|
|
#endif
|
1994-01-28 10:03:16 +03:00
|
|
|
|
|
|
|
#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSfpregs:
|
1994-01-28 10:03:16 +03:00
|
|
|
vap->va_bytes = vap->va_size = sizeof(struct fpreg);
|
1994-01-09 22:44:03 +03:00
|
|
|
break;
|
1994-04-12 06:55:51 +04:00
|
|
|
#endif
|
1994-01-09 22:44:03 +03:00
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSctl:
|
|
|
|
case PFSstatus:
|
|
|
|
case PFSstat:
|
|
|
|
case PFSnote:
|
|
|
|
case PFSnotepg:
|
|
|
|
case PFScmdline:
|
|
|
|
case PFSmeminfo:
|
|
|
|
case PFScpuinfo:
|
|
|
|
case PFSuptime:
|
2004-09-20 21:53:08 +04:00
|
|
|
case PFSmounts:
|
1997-04-28 07:49:57 +04:00
|
|
|
vap->va_bytes = vap->va_size = 0;
|
1994-01-05 10:51:08 +03:00
|
|
|
break;
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSmap:
|
|
|
|
case PFSmaps:
|
2001-03-30 02:41:52 +04:00
|
|
|
/*
|
|
|
|
* Advise a larger blocksize for the map files, so that
|
|
|
|
* they may be read in one pass.
|
|
|
|
*/
|
2001-03-31 00:25:11 +04:00
|
|
|
vap->va_blocksize = 4 * PAGE_SIZE;
|
2001-08-31 08:56:26 +04:00
|
|
|
vap->va_bytes = vap->va_size = 0;
|
2001-03-30 02:41:52 +04:00
|
|
|
break;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2001-12-05 03:58:05 +03:00
|
|
|
#ifdef __HAVE_PROCFS_MACHDEP
|
|
|
|
PROCFS_MACHDEP_NODETYPE_CASES
|
|
|
|
error = procfs_machdep_getattr(ap->a_vp, vap, procp);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
default:
|
1994-06-08 15:33:09 +04:00
|
|
|
panic("procfs_getattr");
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
return (error);
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
|
|
|
procfs_setattr(v)
|
|
|
|
void *v;
|
1993-08-26 23:01:00 +04:00
|
|
|
{
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* just fake out attribute setting
|
|
|
|
* it's not good to generate an error
|
|
|
|
* return, otherwise things like creat()
|
|
|
|
* will fail when they try to set the
|
|
|
|
* file length to 0. worse, this means
|
|
|
|
* that echo $note > /proc/$pid/note will fail.
|
1993-08-26 23:01:00 +04:00
|
|
|
*/
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
return (0);
|
1993-08-26 23:01:00 +04:00
|
|
|
}
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
/*
|
|
|
|
* implement access checking.
|
|
|
|
*
|
|
|
|
* actually, the check for super-user is slightly
|
|
|
|
* broken since it will allow read access to write-only
|
|
|
|
* objects. this doesn't cause any particular trouble
|
|
|
|
* but does mean that the i/o entry points need to check
|
|
|
|
* that the operation really does make sense.
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_access(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_access_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-12-27 22:05:12 +03:00
|
|
|
struct vattr va;
|
1993-08-24 16:59:09 +04:00
|
|
|
int error;
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = VOP_GETATTR(ap->a_vp, &va, ap->a_cred, ap->a_p)) != 0)
|
1993-08-24 16:59:09 +04:00
|
|
|
return (error);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1997-05-08 20:19:43 +04:00
|
|
|
return (vaccess(va.va_type, va.va_mode,
|
|
|
|
va.va_uid, va.va_gid, ap->a_mode, ap->a_cred));
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-01-05 10:51:08 +03:00
|
|
|
* lookup. this is incredibly complicated in the
|
|
|
|
* general case, however for most pseudo-filesystems
|
|
|
|
* very little needs to be done.
|
|
|
|
*
|
1999-07-08 05:26:21 +04:00
|
|
|
* Locking isn't hard here, just poorly documented.
|
|
|
|
*
|
2005-02-27 01:58:54 +03:00
|
|
|
* If we're looking up ".", just vref the parent & return it.
|
1999-07-08 05:26:21 +04:00
|
|
|
*
|
|
|
|
* If we're looking up "..", unlock the parent, and lock "..". If everything
|
|
|
|
* went ok, and we're on the last component and the caller requested the
|
|
|
|
* parent locked, try to re-lock the parent. We do this to prevent lock
|
|
|
|
* races.
|
|
|
|
*
|
|
|
|
* For anything else, get the needed node. Then unlock the parent if not
|
|
|
|
* the last component or not LOCKPARENT (i.e. if we wouldn't re-lock the
|
|
|
|
* parent in the .. case).
|
|
|
|
*
|
|
|
|
* We try to exit with the parent locked in error cases.
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_lookup(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode * a_dvp;
|
|
|
|
struct vnode ** a_vpp;
|
|
|
|
struct componentname * a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vnode **vpp = ap->a_vpp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
1996-10-26 01:57:58 +04:00
|
|
|
const char *pname = cnp->cn_nameptr;
|
2001-02-22 00:39:52 +03:00
|
|
|
const struct proc_target *pt = NULL;
|
1995-02-03 19:18:46 +03:00
|
|
|
struct vnode *fvp;
|
1993-08-24 16:59:09 +04:00
|
|
|
pid_t pid;
|
1994-01-05 10:51:08 +03:00
|
|
|
struct pfsnode *pfs;
|
2001-01-17 03:09:07 +03:00
|
|
|
struct proc *p = NULL;
|
1999-09-03 03:33:45 +04:00
|
|
|
int i, error, wantpunlock, iscurproc = 0, isself = 0;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
*vpp = NULL;
|
1999-07-08 05:26:21 +04:00
|
|
|
cnp->cn_flags &= ~PDIRUNLOCK;
|
1995-02-03 19:18:46 +03:00
|
|
|
|
|
|
|
if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)
|
|
|
|
return (EROFS);
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (cnp->cn_namelen == 1 && *pname == '.') {
|
|
|
|
*vpp = dvp;
|
1994-01-05 10:51:08 +03:00
|
|
|
VREF(dvp);
|
|
|
|
return (0);
|
|
|
|
}
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1999-07-08 05:26:21 +04:00
|
|
|
wantpunlock = (~cnp->cn_flags & (LOCKPARENT | ISLASTCN));
|
1994-01-05 10:51:08 +03:00
|
|
|
pfs = VTOPFS(dvp);
|
|
|
|
switch (pfs->pfs_type) {
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSroot:
|
1999-07-08 05:26:21 +04:00
|
|
|
/*
|
|
|
|
* Shouldn't get here with .. in the root node.
|
|
|
|
*/
|
2005-02-27 01:58:54 +03:00
|
|
|
if (cnp->cn_flags & ISDOTDOT)
|
1994-01-05 10:51:08 +03:00
|
|
|
return (EIO);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1999-09-03 03:33:45 +04:00
|
|
|
iscurproc = CNEQ(cnp, "curproc", 7);
|
|
|
|
isself = CNEQ(cnp, "self", 4);
|
|
|
|
|
|
|
|
if (iscurproc || isself) {
|
|
|
|
error = procfs_allocvp(dvp->v_mount, vpp, 0,
|
2003-09-27 17:29:02 +04:00
|
|
|
iscurproc ? PFScurproc : PFSself, -1);
|
1999-07-08 05:26:21 +04:00
|
|
|
if ((error == 0) && (wantpunlock)) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
1994-01-09 22:44:03 +03:00
|
|
|
|
2001-01-17 03:09:07 +03:00
|
|
|
for (i = 0; i < nproc_root_targets; i++) {
|
|
|
|
pt = &proc_root_targets[i];
|
|
|
|
if (cnp->cn_namelen == pt->pt_namlen &&
|
|
|
|
memcmp(pt->pt_name, pname, cnp->cn_namelen) == 0 &&
|
|
|
|
(pt->pt_valid == NULL ||
|
2003-06-30 02:28:00 +04:00
|
|
|
(*pt->pt_valid)(p, dvp->v_mount)))
|
2001-01-17 03:09:07 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != nproc_root_targets) {
|
|
|
|
error = procfs_allocvp(dvp->v_mount, vpp, 0,
|
2003-01-03 16:21:17 +03:00
|
|
|
pt->pt_pfstype, -1);
|
2001-01-17 03:09:07 +03:00
|
|
|
if ((error == 0) && (wantpunlock)) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2003-01-03 16:21:17 +03:00
|
|
|
pid = (pid_t)atoi(pname, cnp->cn_namelen);
|
1993-08-24 16:59:09 +04:00
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
p = PFIND(pid);
|
2003-01-03 16:21:17 +03:00
|
|
|
if (p == NULL)
|
1995-02-03 19:18:46 +03:00
|
|
|
break;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
error = procfs_allocvp(dvp->v_mount, vpp, pid, PFSproc, -1);
|
1999-07-08 05:26:21 +04:00
|
|
|
if ((error == 0) && (wantpunlock)) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
|
|
|
return (error);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSproc:
|
1999-07-08 05:26:21 +04:00
|
|
|
/*
|
|
|
|
* do the .. dance. We unlock the directory, and then
|
|
|
|
* get the root dir. That will automatically return ..
|
|
|
|
* locked. Then if the caller wanted dvp locked, we
|
|
|
|
* re-lock.
|
|
|
|
*/
|
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
2003-06-29 22:43:21 +04:00
|
|
|
error = procfs_root(dvp->v_mount, vpp);
|
1999-07-08 05:26:21 +04:00
|
|
|
if ((error == 0) && (wantpunlock == 0) &&
|
|
|
|
((error = vn_lock(dvp, LK_EXCLUSIVE)) == 0))
|
|
|
|
cnp->cn_flags &= ~PDIRUNLOCK;
|
|
|
|
return (error);
|
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
p = PFIND(pfs->pfs_pid);
|
2003-01-03 16:21:17 +03:00
|
|
|
if (p == NULL)
|
1995-02-03 19:18:46 +03:00
|
|
|
break;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
for (pt = proc_targets, i = 0; i < nproc_targets; pt++, i++) {
|
|
|
|
if (cnp->cn_namelen == pt->pt_namlen &&
|
1998-08-10 00:51:08 +04:00
|
|
|
memcmp(pt->pt_name, pname, cnp->cn_namelen) == 0 &&
|
2001-01-17 03:09:07 +03:00
|
|
|
(pt->pt_valid == NULL ||
|
2003-06-30 02:28:00 +04:00
|
|
|
(*pt->pt_valid)(p, dvp->v_mount)))
|
1994-01-05 10:51:08 +03:00
|
|
|
goto found;
|
|
|
|
}
|
1995-02-03 19:18:46 +03:00
|
|
|
break;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
found:
|
2003-09-27 17:29:02 +04:00
|
|
|
if (pt->pt_pfstype == PFSfile) {
|
2000-11-24 21:58:37 +03:00
|
|
|
fvp = p->p_textvp;
|
1994-06-16 10:01:19 +04:00
|
|
|
/* We already checked that it exists. */
|
1995-02-03 19:18:46 +03:00
|
|
|
VREF(fvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY);
|
1999-07-08 05:26:21 +04:00
|
|
|
if (wantpunlock) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
1995-02-03 19:18:46 +03:00
|
|
|
*vpp = fvp;
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
1994-01-05 10:51:08 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1999-07-08 05:26:21 +04:00
|
|
|
error = procfs_allocvp(dvp->v_mount, vpp, pfs->pfs_pid,
|
2003-01-03 16:21:17 +03:00
|
|
|
pt->pt_pfstype, -1);
|
1999-07-08 05:26:21 +04:00
|
|
|
if ((error == 0) && (wantpunlock)) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
|
|
|
return (error);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSfd: {
|
2003-01-03 16:21:17 +03:00
|
|
|
int fd;
|
|
|
|
struct file *fp;
|
|
|
|
/*
|
|
|
|
* do the .. dance. We unlock the directory, and then
|
|
|
|
* get the proc dir. That will automatically return ..
|
|
|
|
* locked. Then if the caller wanted dvp locked, we
|
|
|
|
* re-lock.
|
|
|
|
*/
|
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
error = procfs_allocvp(dvp->v_mount, vpp, pfs->pfs_pid,
|
2003-09-27 17:29:02 +04:00
|
|
|
PFSproc, -1);
|
2003-01-03 16:21:17 +03:00
|
|
|
if ((error == 0) && (wantpunlock == 0) &&
|
|
|
|
((error = vn_lock(dvp, LK_EXCLUSIVE)) == 0))
|
|
|
|
cnp->cn_flags &= ~PDIRUNLOCK;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
fd = atoi(pname, cnp->cn_namelen);
|
|
|
|
p = PFIND(pfs->pfs_pid);
|
2003-04-18 00:19:18 +04:00
|
|
|
if (p == NULL || (fp = fd_getfile(p->p_fd, fd)) == NULL)
|
2003-01-03 16:21:17 +03:00
|
|
|
return ENOENT;
|
2003-04-18 00:19:18 +04:00
|
|
|
FILE_USE(fp);
|
|
|
|
|
2003-01-03 16:21:17 +03:00
|
|
|
switch (fp->f_type) {
|
|
|
|
case DTYPE_VNODE:
|
|
|
|
fvp = (struct vnode *)fp->f_data;
|
2003-04-18 00:50:46 +04:00
|
|
|
|
|
|
|
/* Don't show directories */
|
2003-04-19 01:55:35 +04:00
|
|
|
if (fvp->v_type == VDIR)
|
|
|
|
goto symlink;
|
2003-04-18 00:50:46 +04:00
|
|
|
|
2003-01-03 16:21:17 +03:00
|
|
|
VREF(fvp);
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2005-02-27 01:58:54 +03:00
|
|
|
vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY |
|
2003-01-03 16:54:22 +03:00
|
|
|
(p == curproc ? LK_CANRECURSE : 0));
|
2003-01-03 16:21:17 +03:00
|
|
|
*vpp = fvp;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2003-04-19 01:55:35 +04:00
|
|
|
symlink:
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2003-01-03 16:21:17 +03:00
|
|
|
error = procfs_allocvp(dvp->v_mount, vpp, pfs->pfs_pid,
|
2003-09-27 17:29:02 +04:00
|
|
|
PFSfd, fd);
|
2003-01-03 16:21:17 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((error == 0) && (wantpunlock)) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
default:
|
|
|
|
return (ENOTDIR);
|
|
|
|
}
|
1995-02-03 19:18:46 +03:00
|
|
|
|
|
|
|
return (cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS);
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
1994-04-12 06:55:51 +04:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
procfs_validfile(p, mp)
|
|
|
|
struct proc *p;
|
2001-01-17 03:09:07 +03:00
|
|
|
struct mount *mp;
|
1994-04-12 06:55:51 +04:00
|
|
|
{
|
2003-06-30 02:28:00 +04:00
|
|
|
return (p->p_textvp != NULL);
|
1994-04-12 06:55:51 +04:00
|
|
|
}
|
|
|
|
|
2000-08-10 03:30:49 +04:00
|
|
|
static int
|
2003-06-30 02:28:00 +04:00
|
|
|
procfs_validfile_linux(p, mp)
|
|
|
|
struct proc *p;
|
2001-01-17 03:09:07 +03:00
|
|
|
struct mount *mp;
|
2000-08-10 03:30:49 +04:00
|
|
|
{
|
2001-01-17 03:09:07 +03:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
flags = VFSTOPROC(mp)->pmnt_flags;
|
|
|
|
return ((flags & PROCFSMNT_LINUXCOMPAT) &&
|
2003-06-30 02:28:00 +04:00
|
|
|
(p == NULL || procfs_validfile(p, mp)));
|
2000-08-10 03:30:49 +04:00
|
|
|
}
|
|
|
|
|
2004-10-01 20:32:16 +04:00
|
|
|
struct procfs_root_readdir_ctx {
|
|
|
|
struct uio *uiop;
|
|
|
|
off_t *cookies;
|
|
|
|
int ncookies;
|
2004-10-04 12:40:18 +04:00
|
|
|
off_t off;
|
|
|
|
off_t startoff;
|
2004-10-01 20:32:16 +04:00
|
|
|
int error;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
procfs_root_readdir_callback(struct proc *p, void *arg)
|
|
|
|
{
|
|
|
|
struct procfs_root_readdir_ctx *ctxp = arg;
|
|
|
|
struct dirent d;
|
|
|
|
struct uio *uiop;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
uiop = ctxp->uiop;
|
|
|
|
if (uiop->uio_resid < UIO_MX)
|
|
|
|
return -1; /* no space */
|
|
|
|
|
2004-10-04 12:40:18 +04:00
|
|
|
if (ctxp->off < ctxp->startoff) {
|
|
|
|
ctxp->off++;
|
2004-10-01 20:32:16 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&d, 0, UIO_MX);
|
|
|
|
d.d_reclen = UIO_MX;
|
|
|
|
d.d_fileno = PROCFS_FILENO(p->p_pid, PFSproc, -1);
|
|
|
|
d.d_namlen = snprintf(d.d_name,
|
|
|
|
UIO_MX - offsetof(struct dirent, d_name), "%ld", (long)p->p_pid);
|
|
|
|
d.d_type = DT_DIR;
|
|
|
|
|
|
|
|
proclist_unlock_read();
|
|
|
|
error = uiomove(&d, UIO_MX, uiop);
|
|
|
|
proclist_lock_read();
|
|
|
|
if (error) {
|
|
|
|
ctxp->error = error;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxp->ncookies++;
|
|
|
|
if (ctxp->cookies)
|
2004-10-04 12:40:18 +04:00
|
|
|
*(ctxp->cookies)++ = ctxp->off + 1;
|
|
|
|
ctxp->off++;
|
2004-10-01 20:32:16 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
/*
|
|
|
|
* readdir returns directory entries from pfsnode (vp).
|
|
|
|
*
|
|
|
|
* the strategy here with procfs is to generate a single
|
1995-10-09 14:18:51 +03:00
|
|
|
* directory entry at a time (struct dirent) and then
|
1994-01-05 10:51:08 +03:00
|
|
|
* copy that out to userland using uiomove. a more efficent
|
|
|
|
* though more complex implementation, would try to minimize
|
|
|
|
* the number of calls to uiomove(). for procfs, this is
|
|
|
|
* hardly worth the added code complexity.
|
|
|
|
*
|
|
|
|
* this should just be done through read()
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_readdir(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-16 02:54:38 +04:00
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
int *a_eofflag;
|
1998-03-01 05:20:01 +03:00
|
|
|
off_t **a_cookies;
|
|
|
|
int *a_ncookies;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct uio *uio = ap->a_uio;
|
1995-10-09 14:18:51 +03:00
|
|
|
struct dirent d;
|
1994-01-05 10:51:08 +03:00
|
|
|
struct pfsnode *pfs;
|
1999-08-25 18:42:35 +04:00
|
|
|
off_t i;
|
1995-10-09 14:18:51 +03:00
|
|
|
int error;
|
1998-03-01 05:20:01 +03:00
|
|
|
off_t *cookies = NULL;
|
2004-10-01 20:32:16 +04:00
|
|
|
int ncookies;
|
2001-01-17 03:09:07 +03:00
|
|
|
struct vnode *vp;
|
2001-02-22 00:39:52 +03:00
|
|
|
const struct proc_target *pt;
|
2004-10-01 20:32:16 +04:00
|
|
|
struct procfs_root_readdir_ctx ctx;
|
1994-06-16 02:54:38 +04:00
|
|
|
|
2001-01-17 03:09:07 +03:00
|
|
|
vp = ap->a_vp;
|
|
|
|
pfs = VTOPFS(vp);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
if (uio->uio_resid < UIO_MX)
|
|
|
|
return (EINVAL);
|
1995-10-09 17:03:32 +03:00
|
|
|
if (uio->uio_offset < 0)
|
1993-08-24 16:59:09 +04:00
|
|
|
return (EINVAL);
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
error = 0;
|
1995-10-09 17:03:32 +03:00
|
|
|
i = uio->uio_offset;
|
2004-04-29 20:10:54 +04:00
|
|
|
memset(&d, 0, UIO_MX);
|
1995-10-09 14:18:51 +03:00
|
|
|
d.d_reclen = UIO_MX;
|
1998-03-01 05:20:01 +03:00
|
|
|
ncookies = uio->uio_resid / UIO_MX;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
switch (pfs->pfs_type) {
|
|
|
|
/*
|
|
|
|
* this is for the process-specific sub-directories.
|
|
|
|
* all that is needed to is copy out all the entries
|
|
|
|
* from the procent[] table (top of this file).
|
|
|
|
*/
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSproc: {
|
1995-02-03 19:18:46 +03:00
|
|
|
struct proc *p;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1999-08-14 06:20:19 +04:00
|
|
|
if (i >= nproc_targets)
|
1999-08-25 03:29:08 +04:00
|
|
|
return 0;
|
1999-08-14 06:20:19 +04:00
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
p = PFIND(pfs->pfs_pid);
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (ap->a_ncookies) {
|
|
|
|
ncookies = min(ncookies, (nproc_targets - i));
|
2000-08-03 07:39:52 +04:00
|
|
|
cookies = malloc(ncookies * sizeof (off_t),
|
1998-03-01 05:20:01 +03:00
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
*ap->a_cookies = cookies;
|
|
|
|
}
|
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
for (pt = &proc_targets[i];
|
|
|
|
uio->uio_resid >= UIO_MX && i < nproc_targets; pt++, i++) {
|
2001-01-17 03:09:07 +03:00
|
|
|
if (pt->pt_valid &&
|
2003-06-30 02:28:00 +04:00
|
|
|
(*pt->pt_valid)(p, vp->v_mount) == 0)
|
1994-06-08 15:33:09 +04:00
|
|
|
continue;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2003-01-03 16:21:17 +03:00
|
|
|
d.d_fileno = PROCFS_FILENO(pfs->pfs_pid,
|
|
|
|
pt->pt_pfstype, -1);
|
1995-10-09 14:18:51 +03:00
|
|
|
d.d_namlen = pt->pt_namlen;
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(d.d_name, pt->pt_name, pt->pt_namlen + 1);
|
1995-10-09 14:18:51 +03:00
|
|
|
d.d_type = pt->pt_type;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-04-29 20:10:54 +04:00
|
|
|
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
|
1994-01-05 10:51:08 +03:00
|
|
|
break;
|
1998-03-01 05:20:01 +03:00
|
|
|
if (cookies)
|
1995-10-09 17:03:32 +03:00
|
|
|
*cookies++ = i + 1;
|
1993-09-07 19:40:14 +04:00
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
break;
|
1995-10-09 14:18:51 +03:00
|
|
|
}
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSfd: {
|
2003-01-03 16:21:17 +03:00
|
|
|
struct proc *p;
|
|
|
|
struct filedesc *fdp;
|
2004-02-16 01:18:17 +03:00
|
|
|
struct file *fp;
|
2003-10-30 04:58:17 +03:00
|
|
|
int lim, nc = 0;
|
2003-01-03 16:21:17 +03:00
|
|
|
|
|
|
|
p = PFIND(pfs->pfs_pid);
|
|
|
|
if (p == NULL)
|
|
|
|
return ESRCH;
|
|
|
|
|
|
|
|
fdp = p->p_fd;
|
|
|
|
|
|
|
|
lim = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
|
|
|
|
if (i >= lim)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ap->a_ncookies) {
|
|
|
|
ncookies = min(ncookies, (fdp->fd_nfiles + 2 - i));
|
|
|
|
cookies = malloc(ncookies * sizeof (off_t),
|
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
*ap->a_cookies = cookies;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < 2 && uio->uio_resid >= UIO_MX; i++) {
|
|
|
|
pt = &proc_targets[i];
|
|
|
|
d.d_namlen = pt->pt_namlen;
|
|
|
|
d.d_fileno = PROCFS_FILENO(pfs->pfs_pid,
|
|
|
|
pt->pt_pfstype, -1);
|
|
|
|
(void)memcpy(d.d_name, pt->pt_name, pt->pt_namlen + 1);
|
|
|
|
d.d_type = pt->pt_type;
|
2004-04-29 20:10:54 +04:00
|
|
|
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
|
2003-01-03 16:21:17 +03:00
|
|
|
break;
|
|
|
|
if (cookies)
|
|
|
|
*cookies++ = i + 1;
|
|
|
|
nc++;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
ncookies = nc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (; uio->uio_resid >= UIO_MX && i < fdp->fd_nfiles; i++) {
|
2004-02-16 01:18:17 +03:00
|
|
|
/* check the descriptor exists */
|
|
|
|
if ((fp = fd_getfile(fdp, i - 2)) == NULL)
|
2003-04-18 00:33:17 +04:00
|
|
|
continue;
|
2004-02-16 01:18:17 +03:00
|
|
|
simple_unlock(&fp->f_slock);
|
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
d.d_fileno = PROCFS_FILENO(pfs->pfs_pid, PFSfd, i - 2);
|
2003-01-03 16:21:17 +03:00
|
|
|
d.d_namlen = snprintf(d.d_name, sizeof(d.d_name),
|
2003-01-04 18:42:35 +03:00
|
|
|
"%lld", (long long)(i - 2));
|
2003-01-03 16:21:17 +03:00
|
|
|
d.d_type = VREG;
|
2004-04-29 20:10:54 +04:00
|
|
|
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
|
2003-01-03 16:21:17 +03:00
|
|
|
break;
|
|
|
|
if (cookies)
|
|
|
|
*cookies++ = i + 1;
|
|
|
|
nc++;
|
|
|
|
}
|
|
|
|
ncookies = nc;
|
|
|
|
break;
|
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this is for the root of the procfs filesystem
|
1999-09-03 03:33:45 +04:00
|
|
|
* what is needed are special entries for "curproc"
|
|
|
|
* and "self" followed by an entry for each process
|
2004-10-01 20:32:16 +04:00
|
|
|
* on allproc.
|
1994-01-05 10:51:08 +03:00
|
|
|
*/
|
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
case PFSroot: {
|
2004-10-01 20:32:16 +04:00
|
|
|
int nc = 0;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (ap->a_ncookies) {
|
|
|
|
/*
|
|
|
|
* XXX Potentially allocating too much space here,
|
|
|
|
* but I'm lazy. This loop needs some work.
|
|
|
|
*/
|
2000-08-03 07:39:52 +04:00
|
|
|
cookies = malloc(ncookies * sizeof (off_t),
|
1998-03-01 05:20:01 +03:00
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
*ap->a_cookies = cookies;
|
|
|
|
}
|
2004-10-01 20:32:16 +04:00
|
|
|
error = 0;
|
|
|
|
/* 0 ... 3 are static entries. */
|
|
|
|
for (; i <= 3 && uio->uio_resid >= UIO_MX; i++) {
|
1994-01-05 10:51:08 +03:00
|
|
|
switch (i) {
|
1994-01-09 22:44:03 +03:00
|
|
|
case 0: /* `.' */
|
|
|
|
case 1: /* `..' */
|
2003-09-27 17:29:02 +04:00
|
|
|
d.d_fileno = PROCFS_FILENO(0, PFSroot, -1);
|
1995-10-09 14:18:51 +03:00
|
|
|
d.d_namlen = i + 1;
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(d.d_name, "..", d.d_namlen);
|
1995-10-09 14:18:51 +03:00
|
|
|
d.d_name[i + 1] = '\0';
|
|
|
|
d.d_type = DT_DIR;
|
1994-01-09 22:44:03 +03:00
|
|
|
break;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-01-09 22:44:03 +03:00
|
|
|
case 2:
|
2003-09-27 17:29:02 +04:00
|
|
|
d.d_fileno = PROCFS_FILENO(0, PFScurproc, -1);
|
1999-09-03 03:33:45 +04:00
|
|
|
d.d_namlen = sizeof("curproc") - 1;
|
|
|
|
memcpy(d.d_name, "curproc", sizeof("curproc"));
|
|
|
|
d.d_type = DT_LNK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2003-09-27 17:29:02 +04:00
|
|
|
d.d_fileno = PROCFS_FILENO(0, PFSself, -1);
|
1999-09-03 03:33:45 +04:00
|
|
|
d.d_namlen = sizeof("self") - 1;
|
|
|
|
memcpy(d.d_name, "self", sizeof("self"));
|
1995-10-09 14:18:51 +03:00
|
|
|
d.d_type = DT_LNK;
|
1994-01-05 10:51:08 +03:00
|
|
|
break;
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-04-29 20:10:54 +04:00
|
|
|
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
|
1994-01-05 10:51:08 +03:00
|
|
|
break;
|
1998-03-01 05:20:01 +03:00
|
|
|
nc++;
|
|
|
|
if (cookies)
|
1995-10-09 17:03:32 +03:00
|
|
|
*cookies++ = i + 1;
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
2004-10-01 20:32:16 +04:00
|
|
|
/* 4 ... are process entries. */
|
|
|
|
ctx.uiop = uio;
|
|
|
|
ctx.error = 0;
|
2004-10-04 12:40:18 +04:00
|
|
|
ctx.off = 4;
|
|
|
|
ctx.startoff = i;
|
2004-10-01 20:32:16 +04:00
|
|
|
ctx.cookies = cookies;
|
|
|
|
ctx.ncookies = nc;
|
|
|
|
proclist_foreach_call(&allproc,
|
|
|
|
procfs_root_readdir_callback, &ctx);
|
|
|
|
cookies = ctx.cookies;
|
|
|
|
nc = ctx.ncookies;
|
|
|
|
error = ctx.error;
|
|
|
|
if (error)
|
|
|
|
break;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2004-10-01 20:32:16 +04:00
|
|
|
/* misc entries. */
|
2004-10-04 12:40:18 +04:00
|
|
|
if (i < ctx.off)
|
|
|
|
i = ctx.off;
|
|
|
|
if (i >= ctx.off + nproc_root_targets)
|
2001-01-17 03:09:07 +03:00
|
|
|
break;
|
2004-10-04 12:40:18 +04:00
|
|
|
for (pt = &proc_root_targets[i - ctx.off];
|
2004-10-01 20:32:16 +04:00
|
|
|
uio->uio_resid >= UIO_MX &&
|
|
|
|
pt < &proc_root_targets[nproc_root_targets];
|
|
|
|
pt++, i++) {
|
2001-01-17 03:09:07 +03:00
|
|
|
if (pt->pt_valid &&
|
|
|
|
(*pt->pt_valid)(NULL, vp->v_mount) == 0)
|
|
|
|
continue;
|
2003-01-03 16:21:17 +03:00
|
|
|
d.d_fileno = PROCFS_FILENO(0, pt->pt_pfstype, -1);
|
2001-01-17 03:09:07 +03:00
|
|
|
d.d_namlen = pt->pt_namlen;
|
|
|
|
memcpy(d.d_name, pt->pt_name, pt->pt_namlen + 1);
|
|
|
|
d.d_type = pt->pt_type;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
2004-04-29 20:10:54 +04:00
|
|
|
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
|
2001-01-17 03:09:07 +03:00
|
|
|
break;
|
|
|
|
nc++;
|
|
|
|
if (cookies)
|
|
|
|
*cookies++ = i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ncookies = nc;
|
|
|
|
break;
|
1995-10-09 14:18:51 +03:00
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTDIR;
|
|
|
|
break;
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (ap->a_ncookies) {
|
|
|
|
if (error) {
|
1998-04-21 20:36:37 +04:00
|
|
|
if (cookies)
|
2000-08-03 07:39:52 +04:00
|
|
|
free(*ap->a_cookies, M_TEMP);
|
1998-03-01 05:20:01 +03:00
|
|
|
*ap->a_ncookies = 0;
|
|
|
|
*ap->a_cookies = NULL;
|
|
|
|
} else
|
|
|
|
*ap->a_ncookies = ncookies;
|
|
|
|
}
|
1995-10-09 17:03:32 +03:00
|
|
|
uio->uio_offset = i;
|
1994-01-05 10:51:08 +03:00
|
|
|
return (error);
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
|
|
|
|
1994-01-09 22:44:03 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* readlink reads the link of `curproc'
|
1994-01-09 22:44:03 +03:00
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
procfs_readlink(v)
|
|
|
|
void *v;
|
1994-01-09 22:44:03 +03:00
|
|
|
{
|
1996-02-10 01:39:56 +03:00
|
|
|
struct vop_readlink_args *ap = v;
|
2005-05-30 01:55:33 +04:00
|
|
|
char bf[16]; /* should be enough */
|
|
|
|
char *bp = bf;
|
2003-04-19 01:55:35 +04:00
|
|
|
char *path = NULL;
|
1994-01-09 22:44:03 +03:00
|
|
|
int len;
|
2003-04-19 01:55:35 +04:00
|
|
|
int error = 0;
|
|
|
|
struct pfsnode *pfs = VTOPFS(ap->a_vp);
|
1994-01-09 22:44:03 +03:00
|
|
|
|
2003-09-27 17:29:02 +04:00
|
|
|
if (pfs->pfs_fileno == PROCFS_FILENO(0, PFScurproc, -1))
|
2005-05-30 01:55:33 +04:00
|
|
|
len = snprintf(bf, sizeof(bf), "%ld", (long)curproc->p_pid);
|
2003-09-27 17:29:02 +04:00
|
|
|
else if (pfs->pfs_fileno == PROCFS_FILENO(0, PFSself, -1))
|
2005-05-30 01:55:33 +04:00
|
|
|
len = snprintf(bf, sizeof(bf), "%s", "curproc");
|
2003-04-19 01:55:35 +04:00
|
|
|
else {
|
|
|
|
struct file *fp;
|
|
|
|
struct proc *pown;
|
|
|
|
struct vnode *vxp, *vp;
|
|
|
|
|
|
|
|
if ((error = procfs_getfp(pfs, &pown, &fp)) != 0)
|
|
|
|
return error;
|
|
|
|
FILE_USE(fp);
|
|
|
|
switch (fp->f_type) {
|
|
|
|
case DTYPE_VNODE:
|
|
|
|
vxp = (struct vnode *)fp->f_data;
|
|
|
|
if (vxp->v_type != VDIR) {
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, pown);
|
2003-04-19 01:55:35 +04:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if ((path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK))
|
|
|
|
== NULL) {
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, pown);
|
2003-04-19 01:55:35 +04:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
bp = path + MAXPATHLEN;
|
|
|
|
*--bp = '\0';
|
|
|
|
vp = curproc->p_cwdi->cwdi_rdir;
|
|
|
|
if (vp == NULL)
|
|
|
|
vp = rootvnode;
|
|
|
|
error = getcwd_common(vxp, vp, &bp, path,
|
2003-06-30 02:28:00 +04:00
|
|
|
MAXPATHLEN / 2, 0, curproc);
|
|
|
|
FILE_UNUSE(fp, pown);
|
2003-04-19 01:55:35 +04:00
|
|
|
if (error) {
|
|
|
|
free(path, M_TEMP);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
len = strlen(bp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTYPE_MISC:
|
2005-05-30 01:55:33 +04:00
|
|
|
len = snprintf(bf, sizeof(bf), "%s", "[misc]");
|
2003-04-19 01:55:35 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTYPE_KQUEUE:
|
2005-05-30 01:55:33 +04:00
|
|
|
len = snprintf(bf, sizeof(bf), "%s", "[kqueue]");
|
2003-04-19 01:55:35 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
1994-01-09 22:44:03 +03:00
|
|
|
|
2004-04-29 20:10:54 +04:00
|
|
|
error = uiomove(bp, len, ap->a_uio);
|
2003-04-19 01:55:35 +04:00
|
|
|
if (path)
|
|
|
|
free(path, M_TEMP);
|
|
|
|
return error;
|
1994-01-09 22:44:03 +03:00
|
|
|
}
|
|
|
|
|
1993-08-24 16:59:09 +04:00
|
|
|
/*
|
2003-01-03 16:21:17 +03:00
|
|
|
* convert decimal ascii to int
|
1993-08-24 16:59:09 +04:00
|
|
|
*/
|
2003-01-03 16:21:17 +03:00
|
|
|
static int
|
|
|
|
atoi(b, len)
|
1994-01-05 10:51:08 +03:00
|
|
|
const char *b;
|
2003-01-03 16:21:17 +03:00
|
|
|
size_t len;
|
1993-08-24 16:59:09 +04:00
|
|
|
{
|
2003-01-03 16:21:17 +03:00
|
|
|
int p = 0;
|
1993-08-24 16:59:09 +04:00
|
|
|
|
|
|
|
while (len--) {
|
1994-01-05 10:51:08 +03:00
|
|
|
char c = *b++;
|
1993-08-24 16:59:09 +04:00
|
|
|
if (c < '0' || c > '9')
|
2003-01-03 16:21:17 +03:00
|
|
|
return -1;
|
1994-01-05 10:51:08 +03:00
|
|
|
p = 10 * p + (c - '0');
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2003-01-03 16:21:17 +03:00
|
|
|
return p;
|
1993-08-24 16:59:09 +04:00
|
|
|
}
|