2 * machine.h -- Darwin definitions for libproc-based lsof
7 * Portions Copyright 2005 Apple Computer, Inc. All rights reserved.
9 * Copyright 2005 Purdue Research Foundation, West Lafayette, Indiana
10 * 47907. All rights reserved.
12 * Written by Allan Nathanson, Apple Computer, Inc., and Victor A.
13 * Abell, Purdue University.
15 * This software is not subject to any license of the American Telephone
16 * and Telegraph Company or the Regents of the University of California.
18 * Permission is granted to anyone to use this software for any purpose on
19 * any computer system, and to alter it and redistribute it freely, subject
20 * to the following restrictions:
22 * 1. Neither the authors, nor Apple Computer, Inc. nor Purdue University
23 * are responsible for any consequences of the use of this software.
25 * 2. The origin of this software must not be misrepresented, either
26 * by explicit claim or by omission. Credit to the authors, Apple
27 * Computer, Inc. and Purdue University must appear in documentation
30 * 3. Altered versions must be plainly marked as such, and must not be
31 * misrepresented as being the original software.
33 * 4. This notice may not be removed or altered.
38 * $Id: machine.h,v 1.10 2013/01/02 17:03:05 abe Exp abe $
42 #if !defined(LSOF_MACHINE_H)
43 #define LSOF_MACHINE_H 1
46 #include <sys/types.h>
47 #include <sys/param.h>
49 # if defined(NEEDS_MACH_PORT_T)
50 # include <device/device_types.h>
51 # endif /* NEED_MACH_PORT_T */
53 #include "/usr/include/string.h"
57 * CAN_USE_CLNT_CREATE is defined for those dialects where RPC clnt_create()
58 * can be used to obtain a CLIENT handle in lieu of clnttcp_create().
61 #define CAN_USE_CLNT_CREATE 1
65 * DEVDEV_PATH defines the path to the directory that contains device
69 #define DEVDEV_PATH "/dev"
73 * GET_MAX_FD is defined for those dialects that provide a function other than
74 * getdtablesize() to obtain the maximum file descriptor number plus one.
77 /* #define GET_MAX_FD ? */
81 * HASAOPT is defined for those dialects that have AFS support; it specifies
82 * that the default path to an alternate AFS kernel name list file may be
83 * supplied with the -A <path> option.
86 /* #define HASAOPT 1 */
90 * HASBLKDEV is defined for those dialects that want block device information
91 * recorded in BDevtp[].
98 * HASDCACHE is defined for those dialects that support a device cache
101 * HASENVDC defined the name of an environment variable that contains the
102 * device cache file path. The HASENVDC environment variable is ignored when
103 * the lsof process is setuid(root) or its real UID is 0.
105 * HASPERSDC defines the format for the last component of a personal device
106 * cache file path. The first will be the home directory of the real UID that
109 * HASPERSDCPATH defines the environment variable whose value is the middle
110 * component of the personal device cache file path. The middle component
111 * follows the home directory and precedes the results of applying HASPERSDC.
112 * The HASPERSDCPATH environment variable is ignored when the lsof process is
113 * setuid(root) or its real UID is 0.
115 * HASSYSDC defines a public device cache file path. When it's defined, it's
116 * used as the path from which to read the device cache.
118 * Consult the 00DCACHE and 00FAQ files of the lsof distribution for more
119 * information on device cache file path construction.
122 /* #define HASDCACHE 1 */
123 /* #define HASENVDC "LSOFDEVCACHE" */
124 /* #define HASPERSDC "%h/%p.lsof_%L" */
125 /* #define HASPERSDCPATH "LSOFPERSDCPATH" */
126 /* #define HASSYSDC "/your/choice/of/path" */
130 * HASCDRNODE is defined for those dialects that have CD-ROM nodes.
133 /* #define HASCDRNODE 1 */
137 * HASFIFONODE is defined for those dialects that have FIFO nodes.
140 /* #define HASFIFONODE 1 */
144 * HASFSINO is defined for those dialects that have the file system
145 * inode element, fs_ino, in the lfile structure definition in lsof.h.
152 * HASFSTRUCT is defined if the dialect has a file structure.
154 * FSV_DEFAULT defines the default set of file structure values to list.
155 * It defaults to zero (0), but may be made up of a combination of the
156 * FSV_* symbols from lsof.h.
158 * HASNOFSADDR -- has no file structure address
159 * HASNOFSFLAGS -- has no file structure flags
160 * HASNOFSCOUNT -- has no file structure count
161 * HASNOFSNADDR -- has no file structure node address
165 /* #define FSV_DEFAULT FSV_? | FSV_? | FSV_? */
166 #define HASNOFSADDR 1 /* has no file structure address */
167 /* #define HASNOFSFLAGS 1 has no file structure flags */
168 /* #define HASNOFSCOUNT 1 has no file structure count */
169 #define HASNOFSNADDR 1 /* has no file structure node address */
173 * HASGNODE is defined for those dialects that have gnodes.
176 /* #define HASGNODE 1 */
180 * HASHSNODE is defined for those dialects that have High Sierra nodes.
183 /* #define HASHSNODE 1 */
187 * HASINODE is defined for those dialects that have inodes and wish to
188 * use readinode() from node.c.
191 /* #define HASINODE 1 */
195 * HASINTSIGNAL is defined for those dialects whose signal function returns
199 /* #define HASINTSIGNAL 1 */
203 * HASKERNIDCK is defined for those dialects that support the comparison of
204 * the build to running kernel identity.
207 #define HASKERNIDCK 1
211 * HASKOPT is defined for those dialects that support the -k option of
212 * reading the kernel's name list from an optional file.
215 /* #define HASKOPT 1 */
219 * HASLFILEADD is defined for those dialects that need additional elements
220 * in struct lfile. The HASLFILEADD definition is a macro that defines
221 * them. If any of the additional elements need to be preset in the
222 * alloc_lfile() function of proc.c, the SETLFILEADD macro may be defined
225 * If any additional elements need to be cleared in alloc_lfile() or in the
226 * free_proc() function of proc.c, the CLRLFILEADD macro may be defined to
227 * do that. Note that CLRLFILEADD takes one argument, the pointer to the
228 * lfile struct. The CLRLFILEADD macro is expected to expand to statements
229 * that are complete -- i.e., have terminating semi-colons -- so the macro is
230 * called without a terminating semicolon by proc.c.
232 * The HASXOPT definition may be used to select the conditions under which
233 * private lfile elements are used.
236 #define HASLFILEADD char *V_path; \
237 mach_port_t fileport; \
239 #define CLRLFILEADD(lf) if (lf->V_path) { \
240 (void) free((FREE_P *)lf->V_path); \
241 lf->V_path = (char *)NULL; \
243 lf->fileport = MACH_PORT_NULL; \
245 #define SETLFILEADD Lf->V_path = (char *)NULL; \
246 Lf->fileport = MACH_PORT_NULL; \
251 * HASMNTSTAT indicates the dialect supports the mount stat(2) result option
252 * in its l_vfs and mounts structures.
255 /* #define HASMNTSTAT 1 */
259 * HASMNTSUP is defined for those dialects that support the mount supplement
263 /* #define HASMNTSUP 1 */
267 * HASMOPT is defined for those dialects that support the reading of
268 * kernel memory from an alternate file.
271 /* #define HASMOPT 1 */
275 * HASNCACHE is defined for those dialects that have a kernel name cache
276 * that lsof can search. A value of 1 directs printname() to prefix the
277 * cache value with the file system directory name; 2, avoid the prefix.
279 * NCACHELDPFX is a set of C commands to execute before calling ncache_load().
281 * NCACHELDSFX is a set of C commands to execute after calling ncache_load().
284 /* #define HASNCACHE 1 */
285 /* #define NCACHELDPFX ??? */
286 /* #define NCACHELDSFX ??? */
290 * HASNLIST is defined for those dialects that use nlist() to acccess
294 /* #define HASNLIST 1 */
298 * HASPIPEFN is defined for those dialects that have a special function to
299 * process DTYPE_PIPE file structure entries. Its value is the name of the
302 * NOTE: don't forget to define a prototype for this function in dproto.h.
305 /* #define HASPIPEFN process_pipe? */
309 * HASPIPENODE is defined for those dialects that have pipe nodes.
312 /* #define HASPIPENODE 1 */
316 * HASPMAPENABLED is defined when the reporting of portmapper registration
317 * info is enabled by default.
320 /* #define HASPMAPENABLED 1 */
324 * HASPPID is defined for those dialects that support identification of
325 * the parent process IDentifier (PPID) of a process.
332 * HASPRINTDEV, HASPRINTINO, HASPRINTNM, HASPRINTOFF, and HASPRINTSZ
333 * define private dialect-specific functions for printing DEVice numbers,
334 * INOde numbers, NaMes, file OFFsets, and file SiZes. The functions are
335 * called from print_file().
338 /* #define HASPRINTDEV print_dev */
339 /* #define HASPRINTINO print_ino? */
340 #define HASPRINTNM print_nm
341 /* #define HASPRINTOFF print_off? */
342 /* #define HASPRINTSZ print_sz? */
346 * HASPRIVFILETYPE and PRIVFILETYPE are defined for dialects that have a
347 * file structure type that isn't defined by a DTYPE_* symbol. They are
348 * used in lib/prfp.c to select the type's processing.
350 * PRIVFILETYPE is the definition of the f_type value in the file struct.
352 * HASPRIVFILETYPE is the name of the processing function.
355 /* #define HASPRIVFILETYPE process_shmf? */
356 /* #define PRIVFILETYPE ?? */
360 * HASPRIVNMCACHE is defined for dialects that have a private method for
361 * printing cached NAME column values for some files. HASPRIVNAMECACHE
362 * is defined to be the name of the function.
364 * The function takes one argument, a struct lfile pointer to the file, and
365 * returns non-zero if it prints a name to stdout.
368 #define HASPRIVNMCACHE print_v_path
372 * HASPRIVPRIPP is defined for dialects that have a private function for
373 * printing IP protocol names. When HASPRIVPRIPP isn't defined, the
374 * IP protocol name printing function defaults to printiprto().
377 /* #define HASPRIVPRIPP 1 */
381 * HASPROCFS is defined for those dialects that have a proc file system --
382 * usually /proc and usually in SYSV4 derivatives.
384 * HASFSTYPE is defined as 1 for those systems that have a file system type
385 * string, st_fstype, in the stat() buffer; 2, for those systems that have a
386 * file system type integer in the stat() buffer, named MOUNTS_STAT_FSTYPE;
387 * 0, for systems whose stat(2) structure has no file system type member. The
388 * additional symbols MOUNTS_FSTYPE, RMNT_FSTYPE, and RMNT_STAT_FSTYPE may be
389 * defined in dlsof.h to direct how the readmnt() function in lib/rmnt.c
390 * preserves these stat(2) and getmntent(3) buffer values in the local mounts
393 * The defined value is the string that names the file system type.
395 * The HASPROCFS definition usually must be accompanied by the HASFSTYPE
396 * definition and the providing of an fstype element in the local mounts
397 * structure (defined in dlsof.h).
399 * The HASPROCFS definition may be accompanied by the HASPINODEN definition.
400 * HASPINODEN specifies that searching for files in HASPROCFS is to be done
404 /* #define HASPROCFS "proc?" */
405 /* #define HASFSTYPE 1 */
406 /* #define HASPINODEN 1 */
410 * HASRNODE is defined for those dialects that have rnodes.
413 /* #define HASRNODE 1 */
417 * Define HASSECURITY to restrict the listing of all open files to the
418 * root user. When HASSECURITY is defined, the non-root user may list
419 * only files whose processes have the same user ID as the real user ID
420 * (the one that its user logged on with) of the lsof process.
423 /* #define HASSECURITY 1 */
427 * If HASSECURITY is defined, define HASNOSOCKSECURITY to allow users
428 * restricted by HASSECURITY to list any open socket files, provide their
429 * listing is selected by the "-i" option.
432 /* #define HASNOSOCKSECURITY 1 */
436 * HASSETLOCALE is defined for those dialects that have <locale.h> and
439 * If the dialect also has wide character support for language locales,
440 * HASWIDECHAR activates lsof's wide character support and WIDECHARINCL
441 * defines the header file (if any) that must be #include'd to use the
442 * mblen() and mbtowc() functions.
445 #define HASSETLOCALE 1
446 #define HASWIDECHAR 1
447 /* #define WIDECHARINCL <wchar.h> */
451 * HASSNODE is defined for those dialects that have snodes.
454 /* #define HASSNODE 1 */
458 * HASTASKS is defined for those dialects that have task reporting support.
461 /* #define HASTASKS 1 */
465 * HASSOOPT, HASSOSTATE and HASTCPOPT define the availability of information
466 * on socket options (SO_* symbols), socket states (SS_* symbols) and TCP
470 #define HASSOOPT 1 /* has socket option information */
471 #define HASSOSTATE 1 /* has socket state information */
472 #define HASTCPOPT 1 /* has TCP options or flags */
476 * Define HASSPECDEVD to be the name of a function that handles the results
477 * of a successful stat(2) of a file name argument.
479 * For example, HASSPECDEVD() for Darwin makes sure that st_dev is set to
480 * what stat("/dev") returns -- i.e., what's in DevDev.
482 * The function takes two arguments:
484 * 1: pointer to the full path name of file
485 * 2: pointer to the stat(2) result
487 * The function returns void.
490 #define HASSPECDEVD process_dev_stat
494 * HASSTREAMS is defined for those dialects that support streams.
497 /* #define HASSTREAMS 1 */
501 * HASTCPTPIQ is defined for dialects where it is possible to report the
502 * TCP/TPI Recv-Q and Send-Q values produced by netstat.
509 * HASTCPTPIW is defined for dialects where it is possible to report the
510 * TCP/TPI send and receive window sizes produced by netstat.
513 /* #define HASTCPTPIW 1 */
517 * HASTCPUDPSTATE is defined for dialects that have TCP and UDP state
518 * support -- i.e., for the "-stcp|udp:state" option and its associated
519 * speed improvements.
522 #define HASTCPUDPSTATE 1
526 * HASTMPNODE is defined for those dialects that have tmpnodes.
529 /* #define HASTMPNODE 1 */
533 * HASVNODE is defined for those dialects that use the Sun virtual file system
534 * node, the vnode. BSD derivatives usually do; System V derivatives prior to
538 /* #define HASVNODE 1 */
542 * HASXOPT is defined for those dialects that have an X option. It
543 * defines the text for the usage display. HASXOPT_VALUE defines the
544 * option's default binary value -- 0 or 1.
547 /* #define HASXOPT "help text for X option" */
548 /* #define HASXOPT_VALUE 1 */
552 * INODETYPE and INODEPSPEC define the internal node number type and its
553 * printf specification modifier. These need not be defined and lsof.h
554 * can be allowed to define defaults.
556 * These are defined here, because they must be used in dlsof.h.
559 #define INODETYPE unsigned long long
560 /* inode number internal storage type */
561 #define INODEPSPEC "ll" /* INODETYPE printf specification
566 * UID_ARG defines the size of a User ID number when it is passed
567 * as a function argument.
574 * Each USE_LIB_<function_name> is defined for dialects that use the
575 * <function_name> in the lsof library.
577 * Note: other definitions and operations may be required to condition the
578 * library function source code. They may be found in the dialect dlsof.h
582 #define USE_LIB_CKKV 1 /* ckkv.c */
583 /* #define USE_LIB_COMPLETEVFS 1 cvfs.c */
584 #define USE_LIB_FIND_CH_INO 1 /* fino.c */
585 #define USE_LIB_IS_FILE_NAMED 1 /* isfn.c */
586 #define USE_LIB_LKUPDEV 1 /* lkud.c */
587 /* #define USE_LIB_PRINTDEVNAME 1 pdvn.c */
588 /* #define USE_LIB_PROCESS_FILE 1 prfp.c */
589 #define USE_LIB_PRINT_TCPTPI 1 /* ptti.c */
590 /* #define USE_LIB_READDEV 1 rdev.c */
591 /* #define USE_LIB_READMNT 1 rmnt.c */
592 /* #define USE_LIB_REGEX 1 regex.c */
593 /* #define USE_LIB_RNAM 1 rnam.c */
594 /* #define USE_LIB_RNCH 1 rnch.c */
595 /* #define USE_LIB_RNMH 1 rnmh.c */
596 /* #define USE_LIB_SNPF 1 snpf.c */
597 #define snpf snprintf /* use the system's snprintf() */
601 * WARNDEVACCESS is defined for those dialects that should issue a warning
602 * when lsof can't access /dev (or /device) or one of its sub-directories.
603 * The warning can be inhibited by the lsof caller with the -w option.
606 /* #define WARNDEVACCESS 1 */
610 * WARNINGSTATE is defined for those dialects that want to suppress all lsof
614 /* #define WARNINGSTATE 1 warnings are enabled by default */
618 * WILLDROPGID is defined for those dialects whose lsof executable runs
619 * setgid(not_real_GID) and whose setgid power can be relinquished after
620 * the dialect's initialize() function has been executed.
623 #define WILLDROPGID 1
627 * zeromem is a macro that uses bzero or memset.
630 #define zeromem(a, l) memset(a, 0, l)
632 #endif /* !defined(LSOF_MACHINE_H) */