1/*
2 * machine.h - Darwin definitions for /dev/kmem-based lsof
3 */
4
5
6/*
7 * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana
8 * 47907.  All rights reserved.
9 *
10 * Written by Victor A. Abell
11 *
12 * This software is not subject to any license of the American Telephone
13 * and Telegraph Company or the Regents of the University of California.
14 *
15 * Permission is granted to anyone to use this software for any purpose on
16 * any computer system, and to alter it and redistribute it freely, subject
17 * to the following restrictions:
18 *
19 * 1. Neither the authors nor Purdue University are responsible for any
20 *    consequences of the use of this software.
21 *
22 * 2. The origin of this software must not be misrepresented, either by
23 *    explicit claim or by omission.  Credit to the authors and Purdue
24 *    University must appear in documentation and sources.
25 *
26 * 3. Altered versions must be plainly marked as such, and must not be
27 *    misrepresented as being the original software.
28 *
29 * 4. This notice may not be removed or altered.
30 */
31
32
33/*
34 * $Id: machine.h,v 1.16 2010/07/29 16:03:04 abe Exp $
35 */
36
37
38#if	!defined(LSOF_MACHINE_H)
39#define	LSOF_MACHINE_H	1
40
41
42#include <sys/types.h>
43#include <sys/param.h>
44
45# if	DARWINV>=800
46#include <string.h>
47# endif	/* DARWINV>=800 */
48
49
50/*
51 * CAN_USE_CLNT_CREATE is defined for those dialects where RPC clnt_create()
52 * can be used to obtain a CLIENT handle in lieu of clnttcp_create().
53 */
54
55#define	CAN_USE_CLNT_CREATE	1
56
57
58/*
59 * DEVDEV_PATH defines the path to the directory that contains device
60 * nodes.
61 */
62
63#define	DEVDEV_PATH	"/dev"
64
65
66/*
67 * GET_MAX_FD is defined for those dialects that provide a function other than
68 * getdtablesize() to obtain the maximum file descriptor number plus one.
69 */
70
71/* #define	GET_MAX_FD	?	*/
72
73
74/*
75 * HASAOPT is defined for those dialects that have AFS support; it specifies
76 * that the default path to an alternate AFS kernel name list file may be
77 * supplied with the -A <path> option.
78 */
79
80/* #define	HASAOPT		1 */
81
82
83/*
84 * HASBLKDEV is defined for those dialects that want block device information
85 * recorded in BDevtp[].
86 */
87
88#define	HASBLKDEV	1
89
90
91/*
92 * HASDCACHE is defined for those dialects that support a device cache
93 * file.
94 *
95 * HASENVDC defined the name of an environment variable that contains the
96 * device cache file path.  The HASENVDC environment variable is ignored when
97 * the lsof process is setuid(root) or its real UID is 0.
98 *
99 * HASPERSDC defines the format for the last component of a personal device
100 * cache file path.  The first will be the home directory of the real UID that
101 * executes lsof.
102 *
103 * HASPERSDCPATH defines the environment variable whose value is the middle
104 * component of the personal device cache file path.  The middle component
105 * follows the home directory and precedes the results of applying HASPERSDC.
106 * The HASPERSDCPATH environment variable is ignored when the lsof process is
107 * setuid(root) or its real UID is 0.
108 *
109 * HASSYSDC defines a public device cache file path.  When it's defined, it's
110 * used as the path from which to read the device cache.
111 *
112 * Consult the 00DCACHE and 00FAQ files of the lsof distribution for more
113 * information on device cache file path construction.
114 */
115
116/* #define	HASDCACHE	1	*/
117/* #define	HASENVDC	"LSOFDEVCACHE"	*/
118/* #define	HASPERSDC	"%h/%p.lsof_%L"	*/
119/* #define	HASPERSDCPATH	"LSOFPERSDCPATH"	*/
120/* #define	HASSYSDC	"/your/choice/of/path" */
121
122
123/*
124 * HASCDRNODE is defined for those dialects that have CD-ROM nodes.
125 */
126
127/* #define	HASCDRNODE	1 */
128
129
130/*
131 * HASFIFONODE is defined for those dialects that have FIFO nodes.
132 */
133
134/* #define	HASFIFONODE	1 */
135
136
137/*
138 * HASFSINO is defined for those dialects that have the file system
139 * inode element, fs_ino, in the lfile structure definition in lsof.h.
140 */
141
142/* #define	HASFSINO	1 */
143
144
145/*
146 * HASFSTRUCT is defined if the dialect has a file structure.
147 *
148 * FSV_DEFAULT defines the default set of file structure values to list.
149 * It defaults to zero (0), but may be made up of a combination of the
150 * FSV_* symbols from lsof.h.
151 *
152 *   HASNOFSADDR  -- has no file structure address
153 *   HASNOFSFLAGS -- has no file structure flags
154 *   HASNOFSCOUNT -- has no file structure count
155 *   HASNOFSNADDR -- has no file structure node address
156 */
157
158#define	HASFSTRUCT	1
159/* #define	FSV_DEFAULT	FSV_? | FSV_? | FSV_? */
160/* #define	HASNOFSADDR	1	has no file structure address */
161/* #define	HASNOFSFLAGS	1	has no file structure flags */
162/* #define	HASNOFSCOUNT	1	has no file structure count */
163/* #define	HASNOFSNADDR	1	has no file structure node address */
164
165
166/*
167 * HASGNODE is defined for those dialects that have gnodes.
168 */
169
170/* #define	HASGNODE	1 */
171
172
173/*
174 * HASHSNODE is defined for those dialects that have High Sierra nodes.
175 */
176
177/* #define	HASHSNODE	1 */
178
179
180/*
181 * HASINODE is defined for those dialects that have inodes and wish to
182 * use readinode() from node.c.
183 */
184
185# if	DARWINV<800
186#define	HASINODE	1
187# endif	/* DARWINV<800 */
188
189
190/*
191 * HASINTSIGNAL is defined for those dialects whose signal function returns
192 * an int.
193 */
194
195/* #define	HASINTSIGNAL	1 */
196
197
198/*
199 * HASKERNIDCK is defined for those dialects that support the comparison of
200 * the build to running kernel identity.
201 */
202
203#define	HASKERNIDCK	1
204
205
206/*
207 * HASKOPT is defined for those dialects that support the -k option of
208 * reading the kernel's name list from an optional file.
209 */
210
211#define	HASKOPT	1
212
213
214/*
215 * HASLFILEADD is defined for those dialects that need additional elements
216 * in struct lfile.  The HASLFILEADD definition is a macro that defines
217 * them.  If any of the additional elements need to be preset in the
218 * alloc_lfile() function of proc.c, the SETLFILEADD macro may be defined
219 * to do that.
220 *
221 * If any additional elements need to be cleared in alloc_lfile() or in the
222 * free_proc() function of proc.c, the CLRLFILEADD macro may be defined to
223 * do that.  Note that CLRLFILEADD takes one argument, the pointer to the
224 * lfile struct.  The CLRLFILEADD macro is expected to expand to statements
225 * that are complete -- i.e., have terminating semi-colons -- so the macro is
226 * called without a terminating semicolon by proc.c.
227 *
228 * The HASXOPT definition may be used to select the conditions under which
229 * private lfile elements are used.
230 */
231
232# if	DARWINV>=800
233#define	HASLFILEADD char *V_path;
234#define CLRLFILEADD(lf)	if (lf->V_path) { \
235			    (void) free((FREE_P *)lf->V_path); \
236			    lf->V_path = (char *)NULL; \
237			}
238#define SETLFILEADD Lf->V_path = (char *)NULL;
239# endif	/* DARWINV>=800 */
240
241
242/*
243 * HASMNTSTAT indicates the dialect supports the mount stat(2) result option
244 * in its l_vfs and mounts structures.
245 */
246
247/* #define	HASMNTSTAT	1	*/
248
249
250/*
251 * HASMNTSUP is defined for those dialects that support the mount supplement
252 * option.
253 */
254
255/* #define	HASMNTSUP	1	*/
256
257
258/*
259 * HASMOPT is defined for those dialects that support the reading of
260 * kernel memory from an alternate file.
261 */
262
263#define	HASMOPT	1
264
265
266/*
267 * HASNCACHE is defined for those dialects that have a kernel name cache
268 * that lsof can search.  A value of 1 directs printname() to prefix the
269 * cache value with the file system directory name; 2, avoid the prefix.
270 *
271 * NCACHELDPFX is a set of C commands to execute before calling ncache_load().
272 *
273 * NCACHELDSFX is a set of C commands to execute after calling ncache_load().
274 */
275
276# if	DARWINV<800
277#define	HASNCACHE	1
278/* #define	NCACHELDPFX	??? */
279/* #define	NCACHELDSFX	??? */
280# else	/* DARWINV>=800 */
281/* #define	HASNCACHE	1   */
282/* #define	NCACHELDPFX	??? */
283/* #define	NCACHELDSFX	??? */
284# endif	/* DARWINV<800 */
285
286
287/*
288 * HASNLIST is defined for those dialects that use nlist() to acccess
289 * kernel symbols.
290 */
291
292#define	HASNLIST	1
293
294
295/*
296 * HASPIPEFN is defined for those dialects that have a special function to
297 * process DTYPE_PIPE file structure entries.  Its value is the name of the
298 * function.
299 *
300 * NOTE: don't forget to define a prototype for this function in dproto.h.
301 */
302
303# if	DARWINV<800
304/* #define	HASPIPEFN	process_pipe? */
305# else	/* DARWINV>=800 */
306#define	HASPIPEFN	process_pipe
307# endif	/* DARWINV<800 */
308
309
310/*
311 * HASPIPENODE is defined for those dialects that have pipe nodes.
312 */
313
314/* #define	HASPIPENODE	1 */
315
316
317/*
318 * HASPMAPENABLED is defined when the reporting of portmapper registration
319 * info is enabled by default.
320 */
321
322/* #define	HASPMAPENABLED	1 */
323
324
325/*
326 * HASPPID is defined for those dialects that support identification of
327 * the parent process IDentifier (PPID) of a process.
328 */
329#define	HASPPID		1
330
331
332/*
333 * HASPRINTDEV, HASPRINTINO, HASPRINTNM, HASPRINTOFF, and HASPRINTSZ
334 * define private dialect-specific functions for printing DEVice numbers,
335 * INOde numbers, NaMes, file OFFsets, and file SiZes.  The functions are
336 * called from print_file().
337 */
338
339/* #define	HASPRINTDEV	print_dev?	*/
340/* #define	HASPRINTINO	print_ino?	*/
341/* #define	HASPRINTNM	print_nm?	*/
342/* #define	HASPRINTOFF	print_off?	*/
343/* #define	HASPRINTSZ	print_sz?	*/
344
345
346/*
347 * HASPRIVFILETYPE and PRIVFILETYPE are defined for dialects that have a
348 * file structure type that isn't defined by a DTYPE_* symbol.  They are
349 * used in lib/prfp.c to select the type's processing.
350 *
351 * PRIVFILETYPE is the definition of the f_type value in the file struct.
352 *
353 * HASPRIVFILETYPE is the name of the processing function.
354 */
355
356/* #define	HASPRIVFILETYPE	process_shmf?	*/
357/* #define	PRIVFILETYPE	??	*/
358
359
360/*
361 * HASPRIVNMCACHE is defined for dialects that have a private method for
362 * printing cached NAME column values for some files.  HASPRIVNAMECACHE
363 * is defined to be the name of the function.
364 *
365 * The function takes one argument, a struct lfile pointer to the file, and
366 * returns non-zero if it prints a name to stdout.
367 */
368
369# if	DARWINV<800
370/* #define	HASPRIVNMCACHE	<function name>	*/
371# else	/* DARWINV>=800 */
372#define	HASPRIVNMCACHE	print_v_path
373# endif	/* DARWINV<800 */
374
375
376/*
377 * HASPRIVPRIPP is defined for dialects that have a private function for
378 * printing IP protocol names.  When HASPRIVPRIPP isn't defined, the
379 * IP protocol name printing function defaults to printiprto().
380 */
381
382/* #define	HASPRIVPRIPP	1	*/
383
384
385/*
386 * HASPROCFS is defined for those dialects that have a proc file system --
387 * usually /proc and usually in SYSV4 derivatives.
388 *
389 * HASFSTYPE is defined as 1 for those systems that have a file system type
390 * string, st_fstype, in the stat() buffer; 2, for those systems that have a
391 * file system type integer in the stat() buffer, named MOUNTS_STAT_FSTYPE;
392 * 0, for systems whose stat(2) structure has no file system type member.  The
393 * additional symbols MOUNTS_FSTYPE, RMNT_FSTYPE, and RMNT_STAT_FSTYPE may be
394 * defined in dlsof.h to direct how the readmnt() function in lib/rmnt.c
395 * preserves these stat(2) and getmntent(3) buffer values in the local mounts
396 * structure.
397 *
398 * The defined value is the string that names the file system type.
399 *
400 * The HASPROCFS definition usually must be accompanied by the HASFSTYPE
401 * definition and the providing of an fstype element in the local mounts
402 * structure (defined in dlsof.h).
403 *
404 * The HASPROCFS definition may be accompanied by the HASPINODEN definition.
405 * HASPINODEN specifies that searching for files in HASPROCFS is to be done
406 * by inode number.
407 */
408
409# if	defined(HASPROCFS)
410#undef	HASPROCFS
411#define	HASPROCFS	"proc"
412# endif	/* defined(HASPROCFS) */
413
414/* #define		HASPROCFS	"proc?" */
415/* #define		HASFSTYPE	1 */
416
417#define	HASPINODEN	1
418
419
420/*
421 * HASRNODE is defined for those dialects that have rnodes.
422 */
423
424/* #define	HASRNODE	1 */
425
426
427/*
428 * Define HASSECURITY to restrict the listing of all open files to the
429 * root user.  When HASSECURITY is defined, the non-root user may list
430 * only files whose processes have the same user ID as the real user ID
431 * (the one that its user logged on with) of the lsof process.
432 */
433
434/* #define	HASSECURITY	1 */
435
436
437/*
438 * If HASSECURITY is defined, define HASNOSOCKSECURITY to allow users
439 * restricted by HASSECURITY to list any open socket files, provide their
440 * listing is selected by the "-i" option.
441 */
442
443/* #define	HASNOSOCKSECURITY	1	*/
444
445
446/*
447 * HASSETLOCALE is defined for those dialects that have <locale.h> and
448 * setlocale().
449 *
450 * If the dialect also has wide character support for language locales,
451 * HASWIDECHAR activates lsof's wide character support and WIDECHARINCL
452 * defines the header file (if any) that must be #include'd to use the
453 * mblen() and mbtowc() functions.
454 */
455
456#define	HASSETLOCALE	1
457
458# if	DARWINV>=700
459#define	HASWIDECHAR	1
460# endif	/* DARWINV>=700 */
461
462/* #define	WIDECHARINCL	<wchar.h>	*/
463
464
465/*
466 * HASSNODE is defined for those dialects that have snodes.
467 */
468
469/* #define	HASSNODE	1 */
470
471
472/*
473 * HASTASKS is defined for those dialects that have task reporting support.
474 */
475
476/* #define	HASTASKS	1 */
477
478
479/*
480 * HASSOOPT, HASSOSTATE and HASTCPOPT define the availability of information
481 * on socket options (SO_* symbols), socket states (SS_* symbols) and TCP
482 * options.
483 */
484
485#define	HASSOOPT	1	/* has socket option information */
486#define	HASSOSTATE	1	/* has socket state information */
487#define	HASTCPOPT	1	/* has TCP options or flags */
488
489
490/*
491 * Define HASSPECDEVD to be the name of a function that handles the results
492 * of a successful stat(2) of a file name argument.
493 *
494 * For example, HASSPECDEVD() for Darwin makes sure that st_dev is set to
495 * what stat("/dev") returns -- i.e., what's in DevDev.
496 *
497 * The function takes two arguments:
498 *
499 *	1: pointer to the full path name of file
500 *	2: pointer to the stat(2) result
501 *
502 * The function returns void.
503 */
504
505#define	HASSPECDEVD	process_dev_stat
506
507
508/*
509 * HASSTREAMS is defined for those dialects that support streams.
510 */
511
512/* #define	HASSTREAMS	1 */
513
514
515/*
516 * HASTCPTPIQ is defined for dialects where it is possible to report the
517 * TCP/TPI Recv-Q and Send-Q values produced by netstat.
518 */
519
520#define	HASTCPTPIQ	1
521
522
523/*
524 * HASTCPTPIW is defined for dialects where it is possible to report the
525 * TCP/TPI send and receive window sizes produced by netstat.
526 */
527
528/* #define	HASTCPTPIW	1 */
529
530
531/*
532 * HASTMPNODE is defined for those dialects that have tmpnodes.
533 */
534
535/* #define	HASTMPNODE	1 */
536
537
538/*
539 * HASVNODE is defined for those dialects that use the Sun virtual file system
540 * node, the vnode.  BSD derivatives usually do; System V derivatives prior
541 * to R4 usually don't.
542 * doesn't.
543 */
544
545#define	HASVNODE	1
546
547
548/*
549 * HASXOPT is defined for those dialects that have an X option.  It
550 * defines the text for the usage display.  HASXOPT_VALUE defines the
551 * option's default binary value -- 0 or 1.
552 */
553
554/* #define	HASXOPT		"help text for X option" */
555/* #define	HASXOPT_VALUE	1 */
556
557
558/*
559 * INODETYPE and INODEPSPEC define the internal node number type and its
560 * printf specification modifier.  These need not be defined and lsof.h
561 * can be allowed to define defaults.
562 *
563 * These are defined here, because they must be used in dlsof.h.
564 */
565
566# if	DARWINV>=800
567#define	INODETYPE	unsigned long long
568					/* inode number internal storage type */
569#define	INODEPSPEC	"ll"		 /* INODETYPE printf specification
570					 * modifier */
571# endif	/* DARWINV>=800 */
572
573
574/*
575 * UID_ARG defines the size of a User ID number when it is passed
576 * as a function argument.
577 */
578
579#define	UID_ARG	int
580
581
582/*
583 * Each USE_LIB_<function_name> is defined for dialects that use the
584 * <function_name> in the lsof library.
585 *
586 * Note: other definitions and operations may be required to condition the
587 * library function source code.  They may be found in the dialect dlsof.h
588 * header files.
589 */
590
591#define	USE_LIB_CKKV				1	/* ckkv.c */
592/* #define	USE_LIB_COMPLETEVFS		1	   cvfs.c */
593#define	USE_LIB_FIND_CH_INO			1	/* fino.c */
594#define	USE_LIB_IS_FILE_NAMED			1	/* isfn.c */
595#define	USE_LIB_LKUPDEV				1	/* lkud.c */
596#define	USE_LIB_PRINTDEVNAME			1	/* pdvn.c */
597/* #define	USE_LIB_PROCESS_FILE		1	   prfp.c */
598#define	USE_LIB_PRINT_TCPTPI			1	/* ptti.c */
599/* #define	USE_LIB_READDEV			1	   rdev.c */
600/* #define	USE_LIB_READMNT			1	   rmnt.c */
601/* #define	USE_LIB_REGEX			1	   regex.c */
602/* #define	USE_LIB_RNAM			1	   rnam.c */
603
604#if	DARWINV<800
605#define	USE_LIB_RNMH				1	/* rnmh.c */
606#else	/* DARWINV>800 */
607/* #define	USE_LIB_RNMH			1	   rnmh.c */
608#endif	/* DARWINV<800 */
609
610/* #define	USE_LIB_RNCH			1	   rnch.c */
611/* #define	USE_LIB_SNPF			1	   snpf.c */
612#define	snpf	snprintf	/* use the system's snprintf() */
613
614
615/*
616 * WARNDEVACCESS is defined for those dialects that should issue a warning
617 * when lsof can't access /dev (or /device) or one of its sub-directories.
618 * The warning can be inhibited by the lsof caller with the -w option.
619 */
620
621#define	WARNDEVACCESS	1
622
623
624/*
625 * WARNINGSTATE is defined for those dialects that want to suppress all lsof
626 * warning messages.
627 */
628
629/* #define	WARNINGSTATE	1	warnings are enabled by default */
630
631
632/*
633 * WILLDROPGID is defined for those dialects whose lsof executable runs
634 * setgid(not_real_GID) and whose setgid power can be relinquished after
635 * the dialect's initialize() function has been executed.
636 */
637
638#define	WILLDROPGID	1
639
640
641/*
642 * zeromem is a macro that uses bzero or memset.
643 */
644
645#define	zeromem(a, l)	memset(a, 0, l)
646
647#endif	/* !defined(LSOF_MACHINE_H) */
648