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