1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _LXPROC_H 27 #define _LXPROC_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /* 34 * lxproc.h: declarations, data structures and macros for lxprocfs 35 */ 36 37 38 #include <sys/types.h> 39 #include <sys/param.h> 40 #include <sys/policy.h> 41 #include <sys/debug.h> 42 #include <sys/dirent.h> 43 #include <sys/errno.h> 44 #include <sys/file.h> 45 #include <sys/kmem.h> 46 #include <sys/pathname.h> 47 #include <sys/proc.h> 48 #include <sys/systm.h> 49 #include <sys/var.h> 50 #include <sys/user.h> 51 #include <sys/t_lock.h> 52 #include <sys/sysmacros.h> 53 #include <sys/cred.h> 54 #include <sys/priv.h> 55 #include <sys/vnode.h> 56 #include <sys/vfs.h> 57 #include <sys/statvfs.h> 58 #include <sys/cmn_err.h> 59 #include <sys/zone.h> 60 #include <sys/uio.h> 61 #include <sys/utsname.h> 62 #include <sys/dnlc.h> 63 #include <sys/atomic.h> 64 #include <sys/sunddi.h> 65 #include <sys/sunldi.h> 66 #include <vm/as.h> 67 #include <vm/anon.h> 68 69 /* 70 * Convert a vnode into an lxpr_mnt_t 71 */ 72 #define VTOLXPM(vp) ((lxpr_mnt_t *)(vp)->v_vfsp->vfs_data) 73 74 /* 75 * convert a vnode into an lxpr_node 76 */ 77 #define VTOLXP(vp) ((lxpr_node_t *)(vp)->v_data) 78 79 /* 80 * convert a lxprnode into a vnode 81 */ 82 #define LXPTOV(lxpnp) ((lxpnp)->lxpr_vnode) 83 84 /* 85 * convert a lxpr_node into zone for fs 86 */ 87 #define LXPTOZ(lxpnp) \ 88 (((lxpr_mnt_t *)(lxpnp)->lxpr_vnode->v_vfsp->vfs_data)->lxprm_zone) 89 90 #define LXPNSIZ 256 /* max size of lx /proc file name entries */ 91 92 /* 93 * Pretend that a directory entry takes 16 bytes 94 */ 95 #define LXPR_SDSIZE 16 96 97 /* 98 * Node/file types for lx /proc files 99 * (directories and files contained therein). 100 */ 101 typedef enum lxpr_nodetype { 102 LXPR_PROCDIR, /* /proc */ 103 LXPR_PIDDIR, /* /proc/<pid> */ 104 LXPR_PID_CMDLINE, /* /proc/<pid>/cmdline */ 105 LXPR_PID_CPU, /* /proc/<pid>/cpu */ 106 LXPR_PID_CURDIR, /* /proc/<pid>/cwd */ 107 LXPR_PID_ENV, /* /proc/<pid>/environ */ 108 LXPR_PID_EXE, /* /proc/<pid>/exe */ 109 LXPR_PID_MAPS, /* /proc/<pid>/maps */ 110 LXPR_PID_MEM, /* /proc/<pid>/mem */ 111 LXPR_PID_ROOTDIR, /* /proc/<pid>/root */ 112 LXPR_PID_STAT, /* /proc/<pid>/stat */ 113 LXPR_PID_STATM, /* /proc/<pid>/statm */ 114 LXPR_PID_STATUS, /* /proc/<pid>/status */ 115 LXPR_PID_FDDIR, /* /proc/<pid>/fd */ 116 LXPR_PID_FD_FD, /* /proc/<pid>/fd/nn */ 117 LXPR_CMDLINE, /* /proc/cmdline */ 118 LXPR_CPUINFO, /* /proc/cpuinfo */ 119 LXPR_DEVICES, /* /proc/devices */ 120 LXPR_DMA, /* /proc/dma */ 121 LXPR_FILESYSTEMS, /* /proc/filesystems */ 122 LXPR_INTERRUPTS, /* /proc/interrupts */ 123 LXPR_IOPORTS, /* /proc/ioports */ 124 LXPR_KCORE, /* /proc/kcore */ 125 LXPR_KMSG, /* /proc/kmsg */ 126 LXPR_LOADAVG, /* /proc/loadavg */ 127 LXPR_MEMINFO, /* /proc/meminfo */ 128 LXPR_MOUNTS, /* /proc/mounts */ 129 LXPR_NETDIR, /* /proc/net */ 130 LXPR_NET_ARP, /* /proc/net/arp */ 131 LXPR_NET_DEV, /* /proc/net/dev */ 132 LXPR_NET_DEV_MCAST, /* /proc/net/dev_mcast */ 133 LXPR_NET_IGMP, /* /proc/net/igmp */ 134 LXPR_NET_IP_MR_CACHE, /* /proc/net/ip_mr_cache */ 135 LXPR_NET_IP_MR_VIF, /* /proc/net/ip_mr_vif */ 136 LXPR_NET_MCFILTER, /* /proc/net/mcfilter */ 137 LXPR_NET_NETSTAT, /* /proc/net/netstat */ 138 LXPR_NET_RAW, /* /proc/net/raw */ 139 LXPR_NET_ROUTE, /* /proc/net/route */ 140 LXPR_NET_RPC, /* /proc/net/rpc */ 141 LXPR_NET_RT_CACHE, /* /proc/net/rt_cache */ 142 LXPR_NET_SOCKSTAT, /* /proc/net/sockstat */ 143 LXPR_NET_SNMP, /* /proc/net/snmp */ 144 LXPR_NET_STAT, /* /proc/net/stat */ 145 LXPR_NET_TCP, /* /proc/net/tcp */ 146 LXPR_NET_UDP, /* /proc/net/udp */ 147 LXPR_NET_UNIX, /* /proc/net/unix */ 148 LXPR_PARTITIONS, /* /proc/partitions */ 149 LXPR_SELF, /* /proc/self */ 150 LXPR_STAT, /* /proc/stat */ 151 LXPR_UPTIME, /* /proc/uptime */ 152 LXPR_VERSION, /* /proc/version */ 153 LXPR_NFILES /* number of lx /proc file types */ 154 } lxpr_nodetype_t; 155 156 157 /* 158 * Number of fds allowed for in the inode number calculation 159 * per process (if a process has more fds then inode numbers 160 * may be duplicated) 161 */ 162 #define LXPR_FD_PERPROC 2000 163 164 /* 165 * external dirent characteristics 166 */ 167 #define LXPRMAXNAMELEN 14 168 typedef struct { 169 lxpr_nodetype_t d_type; 170 char d_name[LXPRMAXNAMELEN]; 171 } lxpr_dirent_t; 172 173 /* 174 * This is the lxprocfs private data object 175 * which is attached to v_data in the vnode structure 176 */ 177 typedef struct lxpr_node { 178 lxpr_nodetype_t lxpr_type; /* type of this node */ 179 vnode_t *lxpr_vnode; /* vnode for the node */ 180 vnode_t *lxpr_parent; /* parent directory */ 181 vnode_t *lxpr_realvp; /* real vnode, file in dirs */ 182 timestruc_t lxpr_time; /* creation etc time for file */ 183 mode_t lxpr_mode; /* file mode bits */ 184 uid_t lxpr_uid; /* file owner */ 185 gid_t lxpr_gid; /* file group owner */ 186 pid_t lxpr_pid; /* pid of proc referred to */ 187 ino_t lxpr_ino; /* node id */ 188 ldi_handle_t lxpr_cons_ldih; /* ldi handle for console device */ 189 } lxpr_node_t; 190 191 struct zone; /* forward declaration */ 192 193 /* 194 * This is the lxprocfs private data object 195 * which is attached to vfs_data in the vfs structure 196 */ 197 typedef struct lxpr_mnt { 198 lxpr_node_t *lxprm_node; /* node at root of proc mount */ 199 struct zone *lxprm_zone; /* zone for this mount */ 200 ldi_ident_t lxprm_li; /* ident for ldi */ 201 } lxpr_mnt_t; 202 203 extern vnodeops_t *lxpr_vnodeops; 204 extern int nproc_highbit; /* highbit(v.v_nproc) */ 205 206 typedef struct mounta mounta_t; 207 208 extern void lxpr_initnodecache(); 209 extern void lxpr_fininodecache(); 210 extern void lxpr_initrootnode(lxpr_node_t **, vfs_t *); 211 extern ino_t lxpr_inode(lxpr_nodetype_t, pid_t, int); 212 extern ino_t lxpr_parentinode(lxpr_node_t *); 213 extern lxpr_node_t *lxpr_getnode(vnode_t *, lxpr_nodetype_t, proc_t *, int); 214 extern void lxpr_freenode(lxpr_node_t *); 215 216 typedef struct lxpr_uiobuf lxpr_uiobuf_t; 217 extern lxpr_uiobuf_t *lxpr_uiobuf_new(uio_t *); 218 extern void lxpr_uiobuf_free(lxpr_uiobuf_t *); 219 extern int lxpr_uiobuf_flush(lxpr_uiobuf_t *); 220 extern void lxpr_uiobuf_seek(lxpr_uiobuf_t *, offset_t); 221 extern void lxpr_uiobuf_write(lxpr_uiobuf_t *, const char *, size_t); 222 extern void lxpr_uiobuf_printf(lxpr_uiobuf_t *, const char *, ...); 223 extern void lxpr_uiobuf_seterr(lxpr_uiobuf_t *, int); 224 225 proc_t *lxpr_lock(pid_t); 226 void lxpr_unlock(proc_t *); 227 228 #ifdef __cplusplus 229 } 230 #endif 231 232 #endif /* _LXPROC_H */