Debian Codegraph @

00PORTING

raw
1
2 Guide to Porting lsof 4 to Unix OS Dialects
3
4 **********************************************************************
5 | The latest release of lsof is always available via anonymous ftp |
6 | from lsof.itap.purdue.edu. Look in pub/lsof.README for its |
7 | location. |
8 **********************************************************************
9
10 Contents
11
12 How Lsof Works
13 /proc-based Linux Lsof -- a Different Approach
14 General Guidelines
15 Organization
16 Source File Naming Conventions
17 Coding Philosophies
18 Data Requirements
19 Dlsof.h and #include's
20 Definitions That Affect Compilation
21 Options: Common and Special
22 Defining Dialect-Specific Symbols and Global Storage
23 Coding Dialect-specific Functions
24 Function Prototype Definitions and the _PROTOTYPE Macro
25 The Makefile
26 The Mksrc Shell Script
27 The MkKernOpts Shell Script
28 Testing and the lsof Test Suite
29 Where Next?
30
31
32 How Lsof Works
33 --------------
34
35 Before getting on with porting guidelines, just a word or two about
36 how lsof works.
37
38 Lsof obtains data about open UNIX dialect files by reading the
39 kernel's proc structure information, following it to the related
40 user structure, then reading the open file structures stored
41 (usually) in the user structure. Typically lsof uses the kernel
42 memory devices, /dev/kmem, /dev/mem, etc. to read kernel data.
43
44 Lsof stores information from the proc and user structures in an
45 internal, local proc structure table. It then processes the open
46 file structures by reading the file system nodes that lie behind
47 them, extracting and storing relevant data in internal local file
48 structures that are linked to the internal local process structure.
49
50 Once all data has been gathered, lsof reports it from its internal,
51 local tables.
52
53 There are a few variants on this subject. Some systems don't have
54 just proc structures, but have task structures, too, (e.g., NeXTSTEP
55 and OSF/1 derivatives). For some dialects lsof gets proc structures
56 or process information (See "/proc-based Linux Lsof -- a Different
57 Approach) from files of the /proc file system. It's not necessary
58 for lsof to read user structures on some systems (recent versions
59 of HP-UX), because the data lsof needs can be found in the task or
60 proc structures. In the end lsof gathers the same data, just from
61 slightly different sources.
62
63
64 /proc-based Linux Lsof -- a Different Approach
65 ==============================================
66
67 For a completely different approach to lsof construction, take a
68 look at the /proc-based Linux sources in .../dialects/linux/proc.
69 (The sources in .../dialects/linux/kmem are for a traditional lsof
70 that uses /dev/kmem to read information from kernel structures.)
71
72 The /proc-based lsof obtains all its information from the Linux
73 /proc file system. Consequently, it is relatively immune to changes
74 in Linux kernel structures and doesn't need to be re-compiled each
75 time the Linux kernel version changes.
76
77 There are some down-sides to the Linux /proc-based lsof:
78
79 * It must run setuid-root in order to be able to read the
80 /proc file system branches for all processes. In contrast,
81 the /dev/kmem-based Linux lsof usually needs only setgid
82 permission.
83
84 * It depends on the exact character format of /proc files, so
85 it is sensitive to changes in /proc file composition.
86
87 * It is limited to the information a /proc file system
88 implementor decides to provide. For example, if a
89 /proc/net/<protocol> file lacks an inode number, the
90 /proc-based lsof can't connect open socket files to that
91 protocol. Another deficiency is that the /proc-based may
92 not be able to report file offset (position) information,
93 when it isn't available in the /proc/<PID>/fd/ entry for a
94 file.
95
96 In contrast the /dev/kmem-based lsof has full access to
97 kernel structures and "sees" new data as soon as it appears.
98 Of course, that new data requires that lsof be recompiled
99 and usually also requires changes to lsof.
100
101 Overall the switch from a /dev/kmem base to a /proc one is an
102 advantage to Linux lsof. The switch was made at lsof revision 4.23
103 for Linux kernel versions 2.1.72 (approximately) and higher. The
104 reason I'm not certain at which Linux kernel version a /proc-based
105 lsof becomes possible is that the /proc additions needed to implement
106 it have been added gradually to Linux 2.1.x in ways that I cannot
107 measure.
108
109 /proc-based lsof functions in many ways the same as /dev/kmem-based
110 lsof. It scans the /proc directory, looking for <PID>/ subdirectories.
111 Inside each one it collects process-related data from the cwd, exe,
112 maps, root, and stat information files.
113
114 It collects open file information from the fd/ subdirectory of each
115 <PID>/ subdirectory. The lstat(2), readlink(2), and stat(2) system
116 calls gather information about the files from the kernel.
117
118 Lock information comes from /proc/locks. It is matched to open
119 files by inode number. Mount information comes from /proc/mounts.
120 Per domain protocol information comes from the files of /proc/net;
121 it's matched to open socket files by inode number.
122
123 The Linux /proc file system implementors have done an amazing job
124 of providing the information lsof needs. The /proc-based lsof
125 project has so far generated only two kernel modification:
126
127 * A modification to /usr/src/linux/net/ipx/af_ipx.c adds the
128 inode number to the entries of /proc/net/ipx.
129
130 Jonathan Sergent did this kernel modification.
131
132 It may be found in the .../dialects/linux/proc/patches
133 subdirectory of the lsof distribution.
134
135 * An experimental modification to /usr/src/linux/fs/stat.c
136 allows lstat(2) to return file position information for
137 /proc/<PID>/fd/<FD> files.
138
139 Contact me for this modification.
140
141
142 One final note about the /proc-based Linux lsof: it doesn't need
143 any functions from the lsof library in the lib/ subdirectory.
144
145 FreeBSD is now also using a similar approach. Sysctls are used
146 to retrieve processes, files, socket PCBs etc. Access to kernel
147 memory is optional and only used as a last resort when data is
148 not provided by the kernel.
149
150
151 General Guidelines
152 ------------------
153
154 These are the general guidelines for porting lsof 4 to a new Unix
155 dialect:
156
157 * Understand the organization of the lsof sources and the
158 philosophies that guide their coding.
159
160 * Understand the data requirements and determine the methods
161 of locating the necessary data in the new dialect's kernel.
162
163 * Pick a name for the subdirectory in lsof4/dialects for your
164 dialect. Generally I use a vendor operating system name
165 abbreviation.
166
167 * Locate the necessary header files and #include them in the
168 dialect's dlsof.h file. (You may not be able to complete
169 this step until you have coded all dialect-specific functions.)
170
171 * Determine the optional library functions of lsof to be used
172 and set their definitions in the dialect's machine.h file.
173
174 * Define the dialect's specific symbols and global storage
175 in the dialect's dlsof.h and dstore.c files.
176
177 * Code the dialect-specific functions in the appropriate
178 source files of the dialect's subdirectory.
179
180 Include the necessary prototype definitions of the dialect-
181 specific functions in the dproto.h file in the dialect's
182 subdirectory.
183
184 * Define the dialect's Makefile and source construction shell
185 script, Mksrc.
186
187 * If there are #define's that affect how kernel structures
188 are organized, and those #define's are needed when compiling
189 lsof, build a MkKernOpts shell script to locate the #define's
190 and supply them to the Configure shell script.
191
192
193 Organization
194 ------------
195
196 The code in a dialect-specific version of lsof comes from three
197 sources:
198
199 1) functions common to all versions, located in the top level
200 directory, lsof4;
201
202 2) functions specific to the dialect, located in the dialect's
203 subdirectory -- e.g., lsof4/dialects/sun;
204
205 3) functions that are common to several dialects, although
206 not to all, organized in a library, liblsof.a. The functions
207 in the library source can be selected and customized with
208 definitions in the dialect machine.h header files.
209
210 The tree looks like this:
211
212 lsof4 ----------------------+ 3) library --
213 | \ lsof4/lib
214 1) fully common functions + \
215 e.g., lsof4/main.c + lsof4/dialects/
216 / / / / \
217 + + + + +
218 2) dialect-specific subdirectories -- e.g., lsof4/dialects/sun
219
220 The code for a dialect-specific version is constructed from these
221 three sources by the Configure shell script in the top level lsof4
222 directory and definitions in the dialect machine.h header files.
223 Configure uses the Mksrc shell script in each dialect's subdirectory,
224 and may use an optional MkKernOpts shell script in selected dialect
225 subdirectories.
226
227 Configure calls the Mksrc shell script in each dialect's subdirectory
228 to assemble the dialect-specific sources in the main lsof directory.
229 Configure may call MkKernOpts to determine kernel compile-time
230 options that are needed for compiling kernel structures correctly
231 for use by lsof. Configure puts the options in a dialect-specific
232 Makefile it build, using a template in the dialect subdirectory.
233
234 The assembly of dialect-specific sources in the main lsof directory
235 is usually done by creating symbolic links from the top level to
236 the dialect's subdirectory. The LSOF_MKC environment variable may
237 be defined prior to using Configure to change the technique used
238 to assemble the sources -- most commonly to use cp instead of ln -s.
239
240 The Configure script completes the dialect's Makefile by adding
241 string definitions, including the necessary kernel compile-time
242 options, to a dialect skeleton Makefile while copying it from the
243 dialect subdirectory to the top level lsof4 directory. Optionally
244 Makefile may call the dialect's MkKernOpts script to add string
245 definitions.
246
247 When the lsof library, lsof4/lib/liblsof.a, is compiled its
248 functions are selected and customized by #define's in the dialect
249 machine.h header file.
250
251
252 Source File Naming Conventions
253 ------------------------------
254
255 With one exception, dialect-specific source files begin with a
256 lower case `d' character -- ddev.c, dfile.c, dlsof.h. The one
257 exception is the header file that contains dialect-specific
258 definitions for the optional features of the common functions.
259 It's called machine.h for historical reasons.
260
261 Currently all dialects use almost the same source file names. One
262 exception to the rule happens in dialects where there must be
263 different source files -- e.g., dnode[123].c -- to eliminate node
264 header file structure element name conflicts. The source modules
265 in a few subdirectories are organized that way.
266
267 These are common files in lsof4/:
268
269 Configure the configuration script
270
271 Customize does some customization of the selected lsof
272 dialect
273
274 Inventory takes an inventory of the files in an lsof
275 distribution
276
277 version the version number
278
279 dialects/ the dialects subdirectory
280
281 These are the common function source files in lsof4/:
282
283 arg.c common argument processing functions
284
285 common.h common header file that #include's the dialect-specific
286 header files
287
288 main.c common main function for lsof 4
289
290 misc.c common miscellaneous functions -- e.g., special versions
291 of stat() and readlink()
292
293 node.c common node reading functions -- readinode(), readvnode()
294
295 print.c common print support functions
296
297 proc.c common process and file structure functions
298
299 proto.h common prototype definitions, including the definition of
300 the _PROTOTYPE() macro
301
302 store.c common global storage version.h the current lsof version
303 number, derived from the file version by the Makefile
304
305 usage.c functions to display lsof usage panel
306
307 These are the dialect-specific files:
308
309 Makefile the Makefile skeleton
310
311 Mksrc a shell script that assists the Configure script
312 in configuring dialect sources
313
314 MkKernOpts an optional shell script that identifies kernel
315 compile-time options for selected dialects -- e.g.,
316 Pyramid DC/OSx and Reliant UNIX
317
318 ddev.c device support functions -- readdev() -- may be
319 eliminated by functions from lsof4/lib/
320
321 dfile.c file processing functions -- may be eliminated by
322 functions from lsof4/lib/
323
324 dlsof.h dialect-specific header file -- contains #include's
325 for system header files and dialect-specific global
326 storage declarations
327
328 dmnt.c mount support functions -- may be eliminated by
329 functions from lsof4/lib/
330
331 dnode.c node processing functions -- e.g., for gnode or vnode
332
333 dnode?.c additional node processing functions, used when node
334 header files have duplicate and conflicting element
335 names.
336
337 dproc.c functions to access, read, examine and cache data about
338 dialect-specific process structures -- this file contains
339 the dialect-specific "main" function, gather_proc_info()
340
341 dproto.h dialect-specific prototype declarations
342
343 dsock.c dialect-specific socket processing functions
344
345 dstore.c dialect-specific global storage -- e.g., the nlist()
346 structure
347
348 machine.h dialect specific definitions of common function options --
349 e.g., a HASINODE definition to activate the readinode()
350 function in lsof4/node.c
351
352 The machine.h header file also selects and customizes
353 the functions of lsof4/lib/.
354
355 These are the lib/ files. Definitions in the dialect machine.h
356 header files select and customize the contained functions that are
357 to be compiled and archived to liblsof.a.
358
359 Makefile.skel is a skeleton Makefile, used by Configure
360 to construct the Makefile for the lsof
361 library.
362
363 cvfs.c completevfs() function
364
365 USE_LIB_COMPLETEVFS selects it.
366
367 CVFS_DEVSAVE, CVFS_NLKSAVE, CVFS_SZSAVE,
368 and HASFSINO customize it.
369
370 dvch.c device cache functions
371
372 HASDCACHE selects them.
373
374 DCACHE_CLONE, DCACHE_CLR, DCACHE_PSEUDO,
375 DVCH_CHOWN, DVCH_DEVPATH, DVCH_EXPDEV,
376 HASBLKDEV, HASENVDC, HASSYSDC, HASPERSDC,
377 HASPERSDCPATH, and NOWARNBLKDEV customize
378 them.
379
380 fino.c find block and character device inode functions
381
382 HASBLKDEV and USE_LIB_FIND_CH_INO select them.
383
384 isfn.c hashSfile() and is_file_named() functions
385
386 USE_LIB_IS_FILE_NAMED selects it.
387
388 lkud.c device lookup functions
389
390 HASBLKDEV and USE_LIB_LKUPDEV select them.
391
392 pdvn.c print device name functions
393
394 HASBLKDEV and USE_LIB_PRINTDEVNAME select them.
395
396 prfp.c process_file() function
397
398 USE_LIB_PROCESS_FILE selects it.
399
400 FILEPTR, DTYPE_PIPE, HASPIPEFN, DTYPE_GNODE,
401 DTYPE_INODE, DTYPE_PORT, DTYPE_VNODE, DTYPE_PTS,
402 HASF_VNODE, HASKQUEUE, HASPRIVFILETYPE,
403 HASPSXSHM, HASPSXSEM and HASPTSFN customize it.
404
405 ptti.c print_tcptpi() function
406
407 USE_LIB_PRINT_TCPTPI selects it.
408
409 HASSOOPT, HASSBSTATE, HASSOSTATE, AHSTCPOPT,
410 HASTCPTPIQ and HASTCPTPIW customize it.
411
412 rdev.c readdev() function
413
414 USE_LIB_READDEV selects it.
415
416 DIRTYPE, HASBLKDEV, HASDCACHE, HASDNAMLEN,
417 RDEV_EXPDEV, RDEV_STATFN, USE_STAT, and
418 WARNDEVACCESS customize it.
419
420 rmnt.c readmnt() function
421
422 USE_LIB_READMNT selects it.
423
424 HASFSTYPE, MNTSKIP, RMNT_EXPDEV, RMNT_FSTYPE,
425 and MOUNTS_FSTYPE customize it.
426
427 rnam.c BSD format name cache functions
428
429 HASNCACHE and USE_LIB_RNAM select them.
430
431 HASFSINO, NCACHE, NCACHE_NC_CAST, NCACHE_NM,
432 NCACHE_NMLEN, NCACHE_NODEADDR, NCACHE_NODEID,
433 NCACHE_NO_ROOT, NCACHE_NXT, NCACHE_PARADDR,
434 NCACHE_PARID, NCACHE_SZ_CAST, NCHNAMLEN,
435 X_NCACHE, and X_NCSIZE, customize them.
436
437 rnch.c Sun format name cache functions
438
439 HASNCACHE and USE_LIB_RNCH select them.
440
441 ADDR_NCACHE, HASDNLCPTR, HASFSINO, NCACHE_DP,
442 NCACHE_NAME, NCACHE_NAMLEN, NCACHE_NEGVN,
443 NCACHE_NODEID, NCACHE_NXT, NCACHE_PARID,
444 NCACHE_VP, X_NCACHE, and X_NCSIZE, customize
445 them.
446
447
448 The comments and the source code in these library files give more
449 information on customization.
450
451
452 Coding Philosophies
453 -------------------
454
455 A few basic philosophies govern the coding of lsof 4 functions:
456
457 * Use as few #if/#else/#endif constructs as possible, even at
458 the cost of nearly-duplicate code.
459
460 When #if/#else/#endif constructs are necessary:
461
462 o Use the form
463
464 #if defined(s<symbol>)
465
466 in preference to
467
468 #ifdef <symbol>
469
470 to allow easier addition of tests to the #if.
471
472 o Indent them to signify their level -- e.g.,
473
474 #if /* level one */
475 # if /* level two */
476 # endif /* level two */
477 #else /* level one */
478 #endif /* level one */
479
480 o Use ANSI standard comments on #else and #endif statements.
481
482 * Document copiously.
483
484 * Aim for ANSI-C compatibility:
485
486 o Use function prototypes for all functions, hiding them
487 from compilers that cannot handle them with the _PROTOTYPE()
488 macro.
489
490 o Use the compiler's ANSI conformance checking wherever
491 possible -- e.g., gcc's -ansi option.
492
493
494 Data Requirements
495 -----------------
496
497 Lsof's strategy in obtaining open file information is to access
498 the process table via its proc structures, then obtain the associated
499 user area and open file structures. The open file structures then
500 lead lsof to file type specific structures -- cdrnodes, fifonodes,
501 inodes, gnodes, hsfsnodes, pipenodes, pcnodes, rnodes, snodes,
502 sockets, tmpnodes, and vnodes.
503
504 The specific node structures must yield data about the open files. The
505 most important items and device number (raw and cooked) and node
506 number. (Lsof uses them to identify files and file systems named as
507 arguments.) Link counts and file sizes are important, too, as are the
508 special characteristics of sockets, pipes, FIFOs, etc.
509
510 This means that to begin an lsof port to a new Unix dialect you
511 must understand how to obtain these structures from the dialect's
512 kernel. Look for kernel access functions -- e.g., the AIX readx()
513 function, Sun and Sun-like kvm_*() functions, or SGI's syssgi()
514 function. Look for clues in header files -- e.g. external declarations
515 and macros.
516
517 If you have access to them, look at sources to programs like ps(1),
518 or the freely available monitor and top programs. They may give
519 you important clues on reading proc and user area structures. An
520 appeal to readers of dialect-specific news groups may uncover
521 correspondents who can help.
522
523 Careful reading of system header files -- e.g., <sys/proc.h> --
524 may give hints about how kernel storage is organized. Look for
525 global variables declared under a KERNEL or _KERNEL #if. Run nm(1)
526 across the kernel image (/vmunix, /unix, etc.) and look for references
527 to structures of interest.
528
529 Even if there are support functions for reading structures, like the
530 kvm_*() functions, you must still understand how to read data from
531 kernel memory. Typically this requires an understanding of the
532 nlist() function, and how to use /dev/kmem, /dev/mem, and /dev/swap.
533
534 Don't overlook the possibility that you may have to use the process
535 file system -- e.g., /proc. I try to avoid using /proc when I can,
536 since it usually requires that lsof have setuid(root) permission
537 to read the individual /proc "files".
538
539 Once you can access kernel structures, you must understand how
540 they're connected. You must answer questions like:
541
542 * How big are kernel addresses? How are they type cast?
543
544 * How are kernel variable names converted to addresses?
545 Nlist()?
546
547 * How are the proc structures organized? Is it a static
548 table? Are the proc structures linked? Is there a
549 kernel pointer to the first proc structure? Is there a
550 proc structure count?
551
552 * How does one obtain copies of the proc structures? Via
553 /dev/kmem? Via a vendor API?
554
555 * If this is a Mach derivative, is it necessary to obtain the
556 task and thread structures? How?
557
558 * How does one obtain the user area (or the utask area in Mach
559 systems) that corresponds to a process?
560
561 * Where are the file structures located for open file
562 descriptors and how are they located? Are all file
563 structures in the user area? Is the file structure space
564 extensible?
565
566 * Where do the private data pointers in file structures lead?
567 To gnodes? To inodes? To sockets? To vnodes? Hint: look
568 in <sys/file.h> for DTYPE_* instances and further pointers.
569
570 * How are the nodes organized? To what other nodes do they
571 lead and how? Where are the common bits of information in
572 nodes -- device, node number, size -- stored? Hint: look
573 in the header files for nodes for macros that may be used
574 to obtain the address of one node from another -- e.g., the
575 VTOI() macro that leads from a vnode to an inode.
576
577 * Are text reference nodes identified and how? Is it
578 necessary to examine the virtual memory map of a process or
579 a task to locate text references? Some kernels have text
580 node pointers in the proc structures; some, in the user
581 area; Mach kernels may have text information in the task
582 structure, reached in various ways from the proc, user area,
583 or user task structure.
584
585 * How is the device table -- e.g., /dev or /devices --
586 organized? How is it read? Using direct or dirent structures?
587
588 How are major/minor device numbers represented? How are
589 device numbers assembled and disassembled?
590
591 Are there clone devices? How are they identified?
592
593 * How is mount information obtained? Getmntinfo()? Getmntent()?
594 Some special kernel call?
595
596 * How are sockets identified and organized? BSD-style? As
597 streams? Are there streams?
598
599 * Are there special nodes -- CD-ROM nodes, FIFO nodes, etc.?
600
601 * How is the kernel's name cache organized? Can lsof access
602 it to get partial name components?
603
604
605 Dlsof.h and #include's
606 ----------------------
607
608 Once you have identified the kernel's data organization and know
609 what structures it provides, you must add #include's to dlsof.h to
610 access their definitions. Sometimes it is difficult to locate the
611 header files -- you may need to introduce -I specifications in the
612 Makefile via the DINC shell variable in the Configure script.
613
614 Sometimes it is necessary to define special symbols -- e.g., KERNEL,
615 _KERNEL, _KMEMUSER -- to induce system header files to yield kernel
616 structure definitions. Sometimes making those symbol definitions
617 cause other header file and definition conflicts. There's no good
618 general rule on how to proceed when conflicts occur.
619
620 Rarely it may be necessary to extract structure definitions from
621 system header files and move them to dlsof.h, create special versions
622 of system header files, or obtain special copies of system header
623 files from "friendly" (e.g., vendor) sources. The dlsof.h header
624 file in lsof4/dialects/sun shows examples of the first case; the
625 second, no examples; the third, the irix5hdr subdirectory in
626 lsof4/dialects/irix (a mixture of the first and third).
627
628 Building up the necessary #includes in dlsof.h is an iterative
629 process that requires attention as you build the dialect-specific
630 functions that references kernel structures. Be prepared to revisit
631 dlsof.h frequently.
632
633
634 Definitions That Affect Compilation
635 -----------------------------------
636
637 The source files at the top level and in the lib/ subdirectory
638 contain optional functions that may be activated with definitions
639 in a dialect's machine.h header file. Some are functions for
640 reading node structures that may not apply to all dialects -- e.g.
641 CD-ROM nodes (cdrnode), or `G' nodes (gnode) -- and others are
642 common functions that may occasionally be replaced by dialect-specific
643 ones. Once you understand your kernel's data organization, you'll
644 be able to decide the optional common node functions to activate.
645
646 Definitions in machine.h and dlsof.h also enable or disable other
647 optional common features. The following is an attempt to list all
648 the definitions that affect lsof code, but CAUTION, it is only
649 attempt and may be incomplete. Always check lsof4 source code in
650 lib/ and dialects/, and dialect machine.h header files for other
651 possibilities
652
653 AFS_VICE See 00XCONFIG.
654
655 AIX_KERNBITS specifies the kernel bit size, 32 or 64, of the Power
656 architecture AIX 5.x kernel for which lsof was built.
657
658 CAN_USE_CLNT_CREATE is defined for dialects where the more modern
659 RPC function clnt_create() can be used in
660 place of the deprecated clnttcp_create().
661
662 CLONEMAJ defines the name of the variable that
663 contains the clone major device number.
664 (Also see HAS_STD_CLONE and HAVECLONEMAJ.)
665
666 DEVDEV_PATH defines the path to the directory where device
667 nodes are stored, usually /dev. Solaris 10
668 uses /devices.
669
670 DIALECT_WARNING may be defined by a dialect to provide a
671 warning message that will be displayed with
672 help (-h) and version (-v) output.
673
674 FSV_DEFAULT defines the default file structure values to
675 list. It may be composed of or'd FSV_*
676 (See common.h) values. The default is none (0).
677
678 GET_MAJ_DEV is a macro to get major portion from device
679 number instead of via the standard major()
680 macro.
681
682 GET_MIN_DEV is a macro to get minor portion from device
683 number instead of via the standard minor()
684 macro.
685
686 GET_MAX_FD the name of the function that returns an
687 int for the maximum open file descriptor
688 plus one. If not defined, defaults to
689 getdtablesize.
690
691 HAS9660FS enables CD9660 file system support in a
692 BSD dialect.
693
694 HAS_ADVLOCK_ARGS is defined for NetBSD and OpenBSD dialects
695 whose <sys/lockf.h> references vop_advlock_args.
696
697 HAS_AFS enables AFS support code for the dialect.
698
699 HAS_AIO_REQ_STRUCT is defined for Solaris 10 and above systems that
700 have the aio_req structure definition.
701
702 HASAOPT indicates the dialect supports the AFS -A
703 option when HAS_AFS is also defined.
704
705 HASBLKDEV indicates the dialect has block device support.
706
707 HASBUFQ_H indicates the *NSD dialect has the <sys/bufq.h>
708 header file.
709
710 HASCACHEFS enables cache file system support for the
711 dialect.
712
713 HASCDRNODE enables/disables readcdrnode() in node.c.
714
715 HAS_CLOSEFROM is defined when the FreeBSD C library contains the
716 closefrom() function.
717
718 HAS_CONN_NEW indicates the Solaris version has the new form
719 of the conn_s structure, introduced in b134 of
720 Solaris 11. This will always accompany the
721 HAS_IPCLASSIFIER_H definition.
722
723 HAS_CONST indicates that the compiler supports the
724 const keyword.
725
726 HASCPUMASK_T indicates the FreeBSD 5.2 or higher dialect
727 has cpumask_t typedef's.
728
729 HAS_CRED_IMPL_H indicates the Solaris 10 dialect has the
730 <sys/cred_impl.h> header file available.
731
732 HASCWDINFO indicates the cwdinfo structure is defined
733 in the NetBSD <sys/filedesc.h>.
734
735 HASDCACHE enables device file cache file support.
736 The device cache file contains information
737 about the names, device numbers and inode
738 numbers of entries in the /dev (or /device)
739 node subtree that lsof saves from call to
740 call. See the 00DCACHE file of the lsof
741 distribution for more information on this
742 feature.
743
744 HAS_DINODE_U indicates the OpenBSD version has a dinode_u
745 union in its inode structure.
746
747 HASDNLCPTR is defined when the name cache entry of
748 <sys/dnlc.h> has a name character pointer
749 rather than a name character array.
750
751 HAS_DUP2 is defined when the FreeBSD C library contains the
752 dup2() function.
753
754 HASEFFNLINK indicates the *BSD system has the i_effnlink
755 member in the inode structure.
756
757 HASENVDC enables the use of an environment-defined
758 device cache file path and defines the name
759 of the environment variable from which lsof
760 may take it. (See the 00DCACHE file of
761 the lsof distribution for information on
762 when HASENVDC is used or ignored.)
763
764 HASEOPT indicates the dialect supports the -e option to
765 eliminate kernel blocks on a named file system.
766
767 HASEPTOPTS indicates the dialect supports the +|-E end point
768 options.
769
770 HASEXT2FS is defined for BSD dialects for which ext2fs
771 file system support can be provided. A value
772 of 1 indicates that the i_e2din member does not
773 exist; 2, it exists.
774
775 HASF_VNODE indicates the dialect's file structure has an
776 f_vnode member in it.
777
778 HAS_FILEDESCENT indicates the FreeBSD system has the filedescent
779 definition in the <sys/filedesc.h> header file.
780
781 HASFDESCFS enables file descriptor file system support
782 for the dialect. A value of 1 indicates
783 <miscfs/fdesc.h> has a Fctty definition; 2,
784 it does not.
785
786 HASFDLINK indicates the file descriptor file system
787 node has the fd_link member.
788
789 HASFIFONODE enables/disables readfifonode() in node.c.
790
791 HAS_F_OPEN indicates the UnixWare 7.x dialect has the
792 f_open member in its file struct.
793
794 HASFSINO enables the inclusion of the fs_ino element
795 in the lfile structure definition in common.h.
796 This contains the file system's inode number
797 and may be needed when searching the kernel
798 name cache. See dialects/osr/dproc.c for
799 an example.
800
801 HASFSTRUCT indicates the dialect has a file structure
802 the listing of whose element values can be
803 enabled with +f[cfn]. FSV_DEFAULT defines
804 the default listing values.
805
806 HASFSTYPE enables/disables the use of the file system's
807 stat(2) st_fstype member.
808
809 If the HASFSTYPE value is 1, st_fstype is
810 treated as a character array; 2, it is
811 treated as an integer.
812
813 See also the RMNT_EXPDEV and RMNT_FSTYPE
814 documentation in lib/rmnt.c
815
816 HASGETBOOTFILE indicates the NetBSD or OpenBSD dialect has
817 a getbootfile() function.
818
819 HASGNODE enables/disables readgnode() in node.c.
820
821 HASHSNODE enables/disables readhsnode() in node.c.
822
823 HASI_E2FS_PTR indicates the BSD dialect has a pointer in
824 its inode to the EXTFS dinode.
825
826 HASI_FFS indicates the BSD dialect has i_ffs_size
827 in <ufs/ufs/inode.h>.
828
829 HASI_FFS1 indicates the BSD dialect supports the fast
830 UFS1 and UFS2 file systems.
831
832 HAS_INKERNEL indicates the SCO OSR 6.0.0 or higher, or
833 UnixWare 7.1.4 or higher system uses the
834 INKERNEL symbol in <netinet/in_pcb.h> or
835 <netinet/tcp_var.h>.
836
837 HASINODE enables/disables readinode() in node.c.
838
839 HASINRIAIPv6 is defined if the dialect has the INRIA IPv6
840 support. (HASIPv6 will also be defined.)
841
842 HASINT16TYPE is defined when the dialect has a typedef
843 for int16 that may conflict with some other
844 header file's redefinition (e.g., <afs/std.h>).
845
846 HASINT32TYPE is defined when the dialect has a typedef
847 for int32 that may conflict with some other
848 header file's redefinition (e.g., <afs/std.h>).
849
850 HASINTSIGNAL is defined when signal() returns an int.
851
852 HAS_IPCLASSIFIER_H is defined for Solaris dialects that have the
853 <inet/ipclassifier.h> header file.
854
855 HAS_IPC_S_PATCH is defined when the HP-UX 11 dialect has the
856 ipc_s patch installed. It has a value of
857 1 if the ipc_s structure has an ipc_ipis
858 member, but the ipis_s structure lacks the
859 ipis_msgsqueued member; 2, if ipc_s has
860 ipc_ipis, but ipis_s lacks ipis_msgsqueued.
861
862 HASIPv6 indicates the dialect supports the IPv6
863 Internet address family.
864
865 HAS_JFS2 The AIX >= 5.0 dialect has jfs2 support.
866
867 HASKERNFS is defined for BSD dialects for which
868 /kern file system support can be provided.
869
870 HASKERNFS_KFS_KT indicates *kfs_kt is in the BSD dialect's
871 <miscfs/kernfs/kernfs.h>.
872
873 HASKOPT enables/disables the ability to read the
874 kernel's name list from a file -- e.g., from
875 a crash dump file.
876
877 HASKQUEUE indicates the dialect supports the kqueue
878 file type.
879
880 HASKVMGETPROC2 The *BSD dialect has the kvm_gettproc2()
881 function.
882
883 HAS_KVM_VNODE indicates the FreeBSD 5.3 or higher dialect has
884 "defined(_KVM_VNODE)" in <sys/vnode.h>.
885
886 HASLFILEADD defines additional, dialect-specific elements
887
888 SETLFILEADD in the lfile structure (defined in common.h).
889 HASLFILEADD is a macro. The accompanying SETFILEADD
890 macro is used in the alloc_lfile() function of
891 proc.c to preset the additional elements.
892
893 HAS_LF_LWP is defined for BSD dialects where the lockf
894 structure has an lf_lwp member.
895
896 HASLFS indicates the *BSD dialect has log-structured
897 file system support.
898
899 HAS_LGRP_ROOT_CONFLICT
900 indicates the Solaris 9 or Solaris 10 system has
901 a conflict over the lgrp_root symbol in the
902 <sys/lgrp.h> and <sys/lgrp_user.h> header files.
903
904 HAS_LIBCTF indicates the Solaris 10 and above system has
905 the CTF library.
906
907 HAS_LOCKF_ENTRY indicates the FreeBSD version has a lockf_entry
908 structure in its <sys/lockf.h> header file.
909
910 HAS_LWP_H is defined for BSD dialects that have the
911 <sys/lwp.h> header file.
912
913 HASMOPT enables/disables the ability to read kernel
914 memory from a file -- e.g., from a crash
915 dump file.
916
917 HASMSDOSFS enables MS-DOS file system support in a
918 BSD dialect.
919
920 HASMNTSTAT indicates the dialect has a stat(2) status
921 element in its mounts structure.
922
923 HASMNTSUP indicates the dialect supports the mount supplement
924 option.
925
926 HASNAMECACHE indicates the FreeBSD dialect has a namecache
927 structure definition in <sys/namei.h>.
928
929 HASNCACHE enables the probing of the kernel's name cache
930 to obtain path name components. A value
931 of 1 directs printname() to prefix the
932 cache value with the file system directory
933 name; 2, avoid the prefix.
934
935 HASNCVPID The *BSD dialect namecache struct has an
936 nc_vpid member.
937
938 HAS_NFS enables NFS support for the dialect.
939
940 HASNFSPROTO indicates the NetBSD or OpenBSD version
941 has the nfsproto.h header file.
942
943 HASNFSVATTRP indicates the n_vattr member of the nfsnode of
944 the *BSD dialect is a pointer.
945
946 HASNLIST enables/disables nlist() function support.
947 (See NLIST_TYPE.)
948
949 HASNOFSADDR is defined if the dialect has no file structure
950 addresses. (HASFSTRUCT must be defined.)
951
952 HASNOFSCOUNT is defined if the dialect has no file structure counts.
953 (HASFSTRUCT must be defined.)
954
955 HASNOFSFLAGS is defined if the dialect has no file structure flags.
956 (HASFSTRUCT must be defined.)
957
958 HASNOFSNADDR is defined if the dialect has no file structure node
959 addresses. (HASFSTRUCT must be defined.)
960
961 HAS_NO_6PORT is defined if the FreeBSD in_pcb.h has no in6p_.port
962 definitions.
963
964 HAS_NO_6PPCB is defined if the FreeBSD in_pcb.h has no in6p_ppcb
965 definition.
966
967 HAS_NO_LONG_LONG indicates the dialect has no support for the C
968 long long type. This definition is used by
969 the built-in snprintf() support of lib/snpf.c.
970
971 HASNORPC_H indicates the dialect has no /usr/include/rpc/rpc.h
972 header file.
973
974 HASNOSOCKSECURITY enables the listing of open socket files,
975 even when HASSECURITY restricts listing of
976 open files to the UID of the user who is
977 running lsof, provided socket file listing
978 is selected with the "-i" option. This
979 definition is only effective when HASSECURITY
980 is also defined.
981
982 HASNULLFS indicates the dialect (usually *BSD) has a
983 null file system.
984
985 HASOBJFS indicates the Pyramid version has OBJFS
986 support.
987
988 HASONLINEJFS indicates the HP-UX 11 dialect has the optional
989 OnlineJFS package installed.
990
991 HAS_PC_DIRENTPERSEC
992 indicates the Solaris 10 system's <sys/fs/pc_node.h>
993 header file has the pc_direntpersec() macro.
994
995 HAS_PAD_MUTEX indicates the Solaris 11 system has the pad_mutex_t
996 typedef in its <sys/mutex.h> header file.
997
998 HASPERSDC enables the use of a personal device cache
999 file path and specifies a format by which
1000 it is constructed. See the 00DCACHE file
1001 of the lsof distribution for more information
1002 on the format.
1003
1004 HASPERSDCPATH enables the use of a modified personal
1005 device cache file path and specifies the
1006 name of the environment variable from which
1007 its component may be taken. See the 00DCACHE
1008 file of the lsof distribution for more
1009 information on the modified personal device
1010 cache file path.
1011
1012 HASPINODEN declares that the inode number of a /proc file
1013 should be stored in its procfsid structure.
1014
1015 HASPIPEFN defines the function that processes DTYPE_PIPE
1016 file structures. It's used in the prfp.c
1017 library source file. See the FreeBSD
1018 dialect source for an example.
1019
1020 HASPIPENODE enables/disables readpipenode() in node.c.
1021
1022 HASPMAPENABLED enables the automatic reporting of portmapper
1023 registration information for TCP and UDP
1024 ports that have been registered.
1025
1026 HASPPID indicates the dialect has parent PID support.
1027
1028 HASPR_LDT indicates the Solaris dialect has a pr_ldt
1029 member in the pronodetype enum.
1030
1031 HASPR_GWINDOWS indicates the Solaris dialect has a pr_windows
1032 member in the pronodetype enum.
1033
1034 HASPRINTDEV this value defines a private function for
1035 printing the dialect's device number. Used
1036 by print.c/print_file(). Takes one argument:
1037
1038 char *HASPRINTDEV(struct lfile *)
1039
1040 HASPRINTINO this value names a private function for
1041 printing the dialect's inode number. Used
1042 by print.c/print_file(). Takes one argument:
1043
1044 char *HASPRINTINO(struct lfile *)
1045
1046 HASPRINTNM this value names a private function for
1047 printing the dialect's file name. Used by
1048 print.c/print_file(). Takes one argument:
1049
1050 void HASPRINTNM(struct lfile *)
1051
1052 HASPRIVFILETYPE enables processing of the private file
1053 type, whose number (from f_type of the file
1054 struct) is defined by PRIVFILETYPE.
1055 HASPRIVFILETYPE defines the function that
1056 processes the file struct's f_data member.
1057 Processing is initiated from the process_file()
1058 function of the prfp.c library source file
1059 or from the dialect's own process_file()
1060 function.
1061
1062 HASPRIVNMCACHE enables printing of a file path from a
1063 private name cache. HASPRIVNMCACHE defines
1064 the name of the printing function. The
1065 function takes one argument, a struct lfile
1066 pointer to the file, and returns non-zero
1067 if it prints a cached name to stdout.
1068
1069 HASPRIVPRIPP is defined for dialects that have a private
1070 function for printing the IP protocol name.
1071 When this is not defined, the function to
1072 do that defaults to printiproto().
1073
1074 HASPROCFS defines the name (if any) of the process file
1075 system -- e.g., /proc.
1076
1077 HASPROCFS_PFSROOT indicates PFSroot is in the BSD dialect's
1078 <miscfs/procfs/procfs.h>.
1079
1080 HASPSEUDOFS indicates the FreeBSD dialect has pseudofs
1081 file system support.
1082
1083 HASPSXSEM indicates the dialect has support for the POSIX
1084 semaphore file type.
1085
1086 HASPSXSHM indicates the dialect has support for the POSIX
1087 shared memory file type.
1088
1089 HASPTSFN indicates the dialect has a DNODE_PTS file descriptor
1090 type and defines the function that processes it.
1091
1092 HASPTYEPT indicates the Linux dialect has support for the
1093 pseudoterminal endpoint option.
1094
1095 HASPTYFS indicates the *BSD dialect has a ptyfs file system.
1096
1097 HASRNODE enables/disables readrnode() in node.c.
1098
1099 HASRNODE3 indicates the HPUX 10.20 or lower dialect has NFS3
1100 support with a modified rnode structure.
1101
1102 HASRPCV2H The FreeBSD dialect has <nfs/rpcv2.h>.
1103
1104 HAS_SANFS indicates the AIX system has SANFS file system
1105 support.
1106
1107 HAS_SB_CC indicates the FreeBSD system's sockbuf structure has
1108 the sb_ccc member, rather than the sb_cc member.
1109
1110 HASSBSTATE indicates the dialect has socket buffer state
1111 information (e.g., SBS_* symbols) available.
1112
1113 HASSECURITY enables/disables restricting open file
1114 information access. (Also see HASNOSOCKSECURITY.)
1115
1116 HASSELINUX indicates the Linux dialect has SELinux security
1117 context support available.
1118
1119 HASSETLOCALE is defined if the dialect has <locale.h> and
1120 setlocale().
1121
1122 HAS_SI_PRIV indicates the FreeBSD 6.0 and higher cdev
1123 structure has an si_priv member.
1124
1125 HAS_SOCKET_PROTO_H indicates the Solaris 10 system has the header file
1126 <sys/socket_proto.h>.
1127
1128 HASSOUXSOUA indicates that the Solaris <sys/socketvar.h> has
1129 soua_* members in its so_ux_addr structure.
1130
1131 HASSPECDEVD indicates the dialect has a special device
1132 directory and defines the name of a function
1133 that processes the results of a successful
1134 stat(2) of a file in that directory.
1135
1136 HASSNODE indicates the dialect has snode support.
1137
1138 HASSOOPT indicates the dialect has socket option
1139 information (e.g., SO_* symbols) available.
1140
1141 HASSOSTATE indicates the dialect has socket state
1142 information (e.g., SS_* symbols) available.
1143
1144 HASSTATVFS indicates the NetBSD dialect has a statvfs
1145 struct definition.
1146
1147 HASSTAT64 indicates the dialect's <sys/stat.h> contains
1148 stat64.
1149
1150 HAS_STD_CLONE indicates the dialect uses a standard clone
1151 device structure that can be used in common
1152 library function clone processing. If the
1153 value is 1, the clone table will be built
1154 by readdev() and cached when HASDCACHE is
1155 defined; if the value is 2, it is assumed
1156 the clone table is built independently.
1157 (Also see CLONEMAJ and HAVECLONEMAJ.)
1158
1159 HASSTREAMS enables/disables streams. CAUTION, requires
1160 specific support code in the dialect sources.
1161
1162 HAS_STRFTIME indicates the dialect has the gmtime() and
1163 strftime() C library functions that support
1164 the -r marker format option. Configure tests
1165 for the functions and defines this symbol.
1166
1167 HASSYSDC enables the use of a system-wide device
1168 cache file and defines its path. See the
1169 00DCACHE file of the lsof distribution for
1170 more information on the system-wide device
1171 cache file path option.
1172
1173 HAS_SYS_PIPEH indicates the dialect has a <sys/pipe.h>
1174 header file.
1175
1176 HAS_SYS_SX_H indicates the FreeBSD 7.0 and higher system has
1177 a <sys/sx.h> header file.
1178
1179 HAS_TMPFS indicates the FreeBSD system has the <fs/tmpfs.h>
1180 header file.
1181
1182 HASTMPNODE enables/disables readtnode() in node.c.
1183
1184 HASTCPOPT indicates the dialect has TCP option
1185 information (i.e., from TF_* symbols)
1186 available.
1187
1188 HASTCPTPIQ is defined when the dialect can duplicate
1189 the receive and send queue sizes reported
1190 by netstat.
1191
1192 HASTCPTPIW is defined when the dialect can duplicate
1193 the receive and send window sizes reported
1194 by netstat.
1195
1196 HASTCPUDPSTATE is defined when the dialect has support for
1197 TCP and UDP state, including the "-s p:s"
1198 option and associated speed enhancements.
1199
1200 HASTFS indicates that the Pyramid dialect has TFS
1201 file system support.
1202
1203 HAS_UFS1_2 indicates the FreeBSD 6 and higher system has
1204 UFS1 and UFS2 members in its inode structure.
1205
1206 HAS_UM_UFS indicates the OpenBSD version has UM_UFS[12]
1207 definitions.
1208
1209 HASUINT16TYPE is defined when the dialect has a typedef
1210 for u_int16 that may conflict with some other
1211 header file's redefinition (e.g., <afs/std.h>).
1212
1213 HASUXSOCKEPT indicates the Linux version has support for the
1214 UNIX socket endpoint option.
1215
1216 HASUTMPX indicates the dialect has a <utmpx.h> header
1217 file.
1218
1219 HAS_UVM_INCL indicates the NetBSD or OpenBSD dialect has
1220 a <uvm> include directory.
1221
1222 HAS_UW_CFS indicates the UnixWare 7.1.1 or above dialect
1223 has CFS file system support.
1224
1225 HAS_UW_NSC indicates the UnixWare 7.1.1 or above dialect
1226 has a NonStop Cluster (NSC) kernel.
1227
1228 HAS_V_LOCKF indicates the FreeBSD version has a v_lockf
1229 member in the vode structure, defined in
1230 <sys/vnode.h>.
1231
1232 HAS_VM_MEMATTR_T indicates the FreeBSD <sys/conf.h> uses the
1233 vm_memattr_t typedef.
1234
1235 HASVMLOCKH indicates the FreeBSD dialect has <vm/lock.h>.
1236
1237 HASVNODE enables/disables readvnode() function in node.c.
1238
1239 HAS_V_PATH indicates the dialect's vnode structure has a
1240 v_path member.
1241
1242 HAS_VSOCK indicates that the Solaris version has a VSOCK
1243 member in the vtype enum
1244
1245 HASVXFS enables Veritas VxFS file system support for
1246 the dialect. CAUTION, the dialect sources
1247 must have the necessary support code.
1248
1249 HASVXFSDNLC indicates the VxFS file system has its own
1250 name cache.
1251
1252 HASVXFS_FS_H indicates <sys/fs/vx_fs.h> exists.
1253
1254 HASVXFS_MACHDEP_H indicates <sys/fs/vx_machdep.h> exists.
1255
1256 HASVXFS_OFF64_T indicates <sys/fs/vx_solaris.h> exists and
1257 has an off64_t typedef.
1258
1259 HASXVFSRNL indicates the dialect has VxFS Reverse Name
1260 Lookup (RNL) support.
1261
1262 HASVXFS_SOL_H indicates <sys/fs/vx_sol.h> exists.
1263
1264 HASVXFS_SOLARIS_H indicates <sys/fs/vx_solaris.h> exists.
1265
1266 HASVXFS_U64_T if HASVXFS_SOLARIS_H is defined, this
1267 variable indicates that <sys/fs/vx_solaris.h>
1268 has a vx_u64_t typedef.
1269
1270 HASVXFSUTIL indicates the Solaris dialect has VxFS 3.4
1271 or higher and has the utility libraries,
1272 libvxfsutil.a (32 bit) and libvxfsutil64.a
1273 (64 bit).
1274
1275 HASVXFS_VX_INODE indicates that <sys/fs/vx_inode.h> contains
1276 a vx_inode structure.
1277
1278 HASWCTYPE_H indicates the FreeBSD version has wide-character
1279 support and the <wctype.h> header file. Note:
1280 the HASWIDECHAR #define will also be set.
1281
1282 HASWIDECHAR indicates the dialect has the wide-character
1283 support functions iswprint(), mblen() and mbtowc().
1284
1285 HASXNAMNODE indicates the OSR dialect has <sys/fs/xnamnode.h>.
1286
1287 HASXOPT defines help text for dialect-specific X option
1288 and enables X option processing in usage.c and
1289 main.c.
1290
1291 HASXOPT_ROOT when defined, restricts the dialect-specific
1292 X option to processes whose real user ID
1293 is root.
1294
1295 HASXOPT_VALUE defines the default binary value for the X option
1296 in store.c.
1297
1298 HAS_XTCPCB_TMAXSEG indicates that <netinet/tcp_var.h> in this FreeBSD
1299 version exists and its struct xtcpcb has a
1300 t_magseg field.
1301
1302 HAS_ZFS indicates the dialect has support for the ZFS file
1303 system.
1304
1305 HASZONES the Solaris dialect has zones.
1306
1307 HAVECLONEMAJ defines the name of the status variable
1308 that indicates a clone major device number
1309 is available in CLONEMAJ. (Also see CLONEMAJ
1310 and HAS_STD_CLONE.)
1311
1312 HPUX_KERNBITS defines the number of bits in the HP-UX 10.30
1313 and above kernel "basic" word: 32 or 64.
1314
1315 KA_T defines the type cast required to assign
1316 space to kernel pointers. When not defined
1317 by a dialect header file, KA_T defaults to
1318 unsigned long.
1319
1320 KA_T_FMT_X defines the printf format for printing a
1321 KA_T -- the default is "%#lx" for the
1322 default unsigned long KA_T cast.
1323
1324 LSOF_ARCH See 00XCONFIG.
1325
1326 LSOF_BLDCMT See 00XCONFIG.
1327
1328 LSOF_CC See 00XCONFIG.
1329
1330 LSOF_CCV See 00XCONFIG.
1331
1332 LSOF_HOST See 00XCONFIG.
1333
1334 LSOF_INCLUDE See 00XCONFIG.
1335
1336 LSOF_LOGNAME See 00XCONFIG.
1337
1338 LSOF_MKC See the "The Mksrc Shell Script" section of
1339 this file.
1340
1341 LSOF_SYSINFO See 00XCONFIG.
1342
1343 LSOF_USER See 00XCONFIG.
1344
1345 LSOF_VERS See 00XCONFIG.
1346
1347 LSOF_VSTR See 00XCONFIG.
1348
1349 MACH defines a MACH system.
1350
1351 N_UNIXV defines an alternate value for the N_UNIV symbol.
1352
1353 NCACHELDPFX defines C code to be executed before calling
1354 ncache_load().
1355
1356 NCACHELDSFX defines C code to be executed after calling
1357 ncache_load().
1358
1359 NEEDS_BOOL_TYPEDEF indicates the FreeBSD 10 system, being built on an
1360 i386 architecture systemn, needs typdef bool.
1361
1362 NEEDS_BOOLEAN_T indicates the FreeBSD 9 and above system needs a
1363 boolean_t definition for <sys/conf.h>.
1364
1365 NEEDS_DEVICE_T indicates the FreeBSD <sys/eventhandler.h> header file
1366 needs the device_t typedef.
1367
1368 NEEDS_MACH_PORT_T is defined for Darwin versions that need the inclusion
1369 of the header file <device/device_types.h>.
1370
1371 NEEDS_NETINET_TCPH is defined when the Linux version needs to #include
1372 <netinet/tcp.h> in place of <linux/tcp.h> in order to
1373 have access to the TCP_* definitions.
1374
1375 NEVER_HASDCACHE keeps the Customize script from offering to
1376 change HASDCACHE by its presence anywhere
1377 in a dialect's machine.h header file --
1378 e.g., in a comment. See the Customize
1379 script or machine.h in dialects/linux/proc.
1380
1381 NEVER_WARNDEVACCESS keeps the Customize script from offering to
1382 change WARNDEVACCESS by its presence anywhere
1383 in a dialect's machine.h header file --
1384 including in a comment. See the Customize
1385 script or machine.h in dialects/linux/proc.
1386
1387 NLIST_TYPE is the type of the nlist table, Nl[], if it is
1388 not nlist. HASNLIST must be set for this
1389 definition to be effective.
1390
1391 NOWARNBLKDEV specifies that no warning is to be issued
1392 when no block devices are found. This
1393 definition is used only when HASBLKDEV is
1394 also defined.
1395
1396 OFFDECDIG specifies how many decimal digits will be
1397 printed for the file offset in a 0t form
1398 before switching to a 0x form. The count
1399 includes the "0t". A count of zero means
1400 the size is unlimited.
1401
1402 PRIVFILETYPE is the number of a private file type, found
1403 in the f_type member of the file struct, to
1404 be processed by the HASPRIVFILETYPE function.
1405 See the AIX dialect sources for an example.
1406
1407 _PSTAT_STREAM_GET_XPORT
1408 indicates the HP-UX PSTAT header files require
1409 this symbol to be defined for proper handling of
1410 stream export data.
1411
1412 SAVE_MP_IN_SFILE indicates the dialect needs to have the mounts
1413 structure pointer for a file system search argument
1414 recorded in the dialect's sfile structure. This
1415 definition is made in the dialect's dlsof.h header
1416 file within the sfile structure.
1417
1418 TIMEVAL_LSOF defines the name of the timeval structure.
1419 The default is timeval. /dev/kmem-based
1420 Linux lsof redefines timeval with this
1421 symbol to avoid conflicts between glibc
1422 and kernel definitions.
1423
1424 TYPELOGSECSHIFT defines the type of the cdfs_LogSecShift
1425 member of the cdfs structure for UnixWare
1426 7 and higher.
1427
1428 UID_ARG_T defines the cast on a User ID when passed
1429 as a function argument.
1430
1431 USE_LIB_COMPLETEVFS
1432 selects the use of the completevfs() function
1433 in lsof4/lib/cvfs.c.
1434
1435 USE_LIB_FIND_CH_INO
1436 selects the use of the find_ch_ino() inode
1437 function in lsof4/lib/fino.c.
1438
1439 Note: HASBLKDEV selects the has_bl_ino()
1440 function.
1441
1442 USE_LIB_IS_FILE_NAMED
1443 selects the use of the is_file_named() function
1444 in lsof4/lib/isfn.c.
1445
1446 USE_LIB_LKUPDEV selects the use of the lkupdev() function
1447 in lsof4/lib/lkud.c.
1448
1449 Note: HASBLKDEV selects the lkupbdev() function.
1450
1451 USE_LIB_PRINTDEVNAME
1452 selects the use of the printdevname() function
1453 in lsof4/lib/pdvn.c.
1454
1455 Note: HASBLKDEV selects the printbdevname()
1456 function.
1457
1458 USE_LIB_PRINT_TCPTPI
1459 selects the use of the print_tcptpi() function
1460 in lsof4/lib/ptti.c.
1461
1462 USE_LIB_PROCESS_FILE
1463 selects the use of the process_file() function
1464 in lsof4/lib/prfp.c.
1465
1466 USE_LIB_READDEV selects the use of the readdev() and stkdir()
1467 functions in lsof4/lib/rdev.c.
1468
1469 USE_LIB_READMNT selects the use of the readmnt() function
1470 in lsof4/lib/rmnt.c.
1471
1472 USE_LIB_RNAM selects the use of the device cache functions
1473 in lsof4/lib/rnam.c.
1474
1475 Note: HASNCACHE must also be defined.
1476
1477 USE_LIB_RNCH selects the use of the device cache functions
1478 in lsof4/lib/rnch.c.
1479
1480 Note: HASNCACHE must also be defined.
1481
1482 USE_STAT is defined for those dialects that must
1483 use the stat(2) function instead of lstat(2)
1484 to scan /dev -- i.e., in the readdev()
1485 function.
1486
1487 VNODE_VFLAG is an alternate name for the vnode structure's
1488 v_flag member.
1489
1490 WARNDEVACCESS enables the issuing of a warning message when
1491 lsof is unable to access /dev (or /device)
1492 or one of its subdirectories, or stat(2)
1493 a file in them. Some dialects (e.g., HP-UX)
1494 have many inaccessible subdirectories and
1495 it is appropriate to inhibit the warning
1496 for them with WARNDEVACCESS. The -w option
1497 will also inhibit these warnings.
1498
1499 WARNINGSTATE when defined, disables the default issuing
1500 of warning messages. WARNINGSTATE is
1501 undefined by default for all dialects in
1502 the lsof distribution.
1503
1504 WIDECHARINCL defines the header file to be included (if any)
1505 when wide-character support is enabled with
1506 HASWIDECHAR.
1507
1508 zeromem() defines a macro to zero memory -- e.g., using
1509 bzero() or memset().
1510
1511 Any dialect's machine.h file and Configure stanza can serve as a
1512 template for building your own. All machine.h files usually have
1513 all definitions, disabling some (with comment prefix and suffix)
1514 and enabling others.
1515
1516
1517 Options: Common and Special
1518 ---------------------------
1519
1520 All but one lsof option is common; the specific option is ``-X''.
1521 If a dialect does not support a common option, the related #define
1522 in machine.h -- e.g., HASCOPT -- should be deselected.
1523
1524 The specific option, ``-X'', may be used by any dialect for its
1525 own purpose. Right now (May 30, 1995) the ``-X'' option is binary
1526 (i.e., it's not allowed arguments of its own, and its value must
1527 be 0 or 1) but that could be changed should the need arise. The
1528 option is enabled with the HASXOPT definition in machine.h; its
1529 default value is defined by HASXOPT_VALUE.
1530
1531 The value of HASXOPT should be the text displayed for ``-X'' by
1532 the usage() function in usage.c. HASXOPT_VALUE should be the
1533 default value, 0 or 1.
1534
1535 AIX for the IBM RICS System/6000 defines the ``-X'' option to
1536 control readx() usage, since there is a bug in AIX kernels that
1537 readx() can expose for other processes.
1538
1539
1540 Defining Dialect-Specific Symbols and Global Storage
1541 ----------------------------------------------------
1542
1543 A dialect's dlsof.h and dstore.c files contain dialect-specific
1544 symbol and global storage definitions. There are symbol definitions,
1545 for example, for function and data casts, and for file paths.
1546 Dslof.h defines lookup names the nlist() table -- X_* symbols --
1547 when nlist() is being used.
1548
1549 Global storage definitions include such things as structures for
1550 local Virtual File System (vfs) information; mount information;
1551 search file information; and kernel memory file descriptors --
1552 e.g., Kmem for /dev/kmem, Mem for /dev/mem, Swap for /dev/drum.
1553
1554
1555 Coding Dialect-specific Functions
1556 ---------------------------------
1557
1558 Each supported dialect must have some basic functions that the
1559 common functions of the top level may call. Some of them may be
1560 obtained from the library in lsof4/lib, selected and customized by
1561 #define's in the dialect machine.h header file. Others may have
1562 to be coded specifically for the dialect.
1563
1564 Each supported dialect usually has private functions, too. Those
1565 are wholly determined by the needs of the dialect's data organization
1566 and access.
1567
1568 These are some of the basic functions that each dialect must supply
1569 -- they're all defined in proto.h:
1570
1571 initialize() function to initialize the dialect
1572
1573 is_file_named() function to check if a file was named
1574 by an optional file name argument
1575 (lsof4/lib/isfn.c)
1576
1577 gather_proc_info() function to gather process table
1578 and related information and cache it
1579
1580 printchdevname() function to locate and optionally
1581 print the name of a character device
1582 (lsof4/lib/pdvn.c)
1583
1584 print_tcptpistate() function to print the TCP or TPI
1585 state for a TCP or UDP socket file,
1586 if the one in lib/ptti.c isn't
1587 suitable (define USE_LIB_PRINT_TCPTPI
1588 to activate lib/ptti.c)
1589
1590 process_file() function to process an open file
1591 structure (lsof4/lib/prfp.c)
1592
1593 process_node() function to process a primary node
1594
1595 process_socket() function to process a socket
1596
1597 readdev() and stkdir() functions to read and cache device
1598 information (lsof4/lib/rdev.c)
1599
1600 readmnt() function to read mount table information
1601 (lsof4/lib/rmnt.c)
1602
1603 Other common functions may be needed, and might be obtained from
1604 lsof4/lib, depending on the needs of the dialect's node and socket
1605 file processing functions.
1606
1607 Check the functions in lsof4/lib and specific lsof4/dialects/*
1608 files for examples.
1609
1610 As you build these functions you will probably have to add #include's
1611 to dlsof.h.
1612
1613
1614 Function Prototype Definitions and the _PROTOTYPE Macro
1615 -------------------------------------------------------
1616
1617 Once you've defined your dialect-specific definitions, you should
1618 define their prototypes in dproto.h or locally in the file where
1619 they occur and are used. Do this even if your compiler is not ANSI
1620 compliant -- the _PROTOTYPE macro knows how to cope with that and
1621 will avoid creating prototypes that will confuse your compiler.
1622
1623
1624 The Makefile
1625 ------------
1626
1627 Here are some general rules for constructing the dialect Makefile.
1628
1629 * Use an existing dialect's Makefile as a template.
1630
1631 * Make sure the echo actions of the install rule are appropriate.
1632
1633 * Use the DEBUG string to set debugging options, like ``-g''.
1634 You may also need to use the -O option when forking and
1635 SIGCHLD signals defeat your debugger.
1636
1637 * Don't put ``\"'' in a compiler flags -D<symbol>=<string>
1638 clause in your Makefile. Leave off the ``\"'' even though
1639 you want <string> to be a string literal and instead adapt
1640 the N_UNIX* macros you'll find in Makefiles for FreeBSD
1641 and Linux. That will allow the Makefile's version.h rule
1642 to put CFLAGS into version.h without having to worry about
1643 the ``\"'' sequences.
1644
1645 * Finally, remember that strings can be passed from the top
1646 level's Configure shell script. That's an appropriate way
1647 to handle options, especially if there are multiple versions
1648 of the Unix dialect to which you are porting lsof 4.
1649
1650
1651 The Mksrc Shell Script
1652 ----------------------
1653
1654 Pattern your Mksrc shell script after an existing one from another
1655 dialect. Change the D shell variable to the name of your dialect's
1656 subdirectory in lsof4/dialects. Adjust any other shell variable
1657 to your local conditions. (Probably that won't be necessary.)
1658
1659 Note that, if using symbolic links from the top level to your
1660 dialect subdirectory is impossible or impractical, you can set the
1661 LSOF_MKC shell variable in Configure to something other than
1662 "ln -s" -- e.g., "cp," and Configure will pass it to the Mksrc
1663 shell script in the M environment variable.
1664
1665
1666 The MkKernOpts Shell Script
1667 ---------------------------
1668
1669 The MkKernOptrs shell script is used by some dialects -- e.g.,
1670 Pyramid DC/OSx and Reliant UNIX -- to determine the compile-time
1671 options used to build the current kernel that affect kernel structure
1672 definitions, so those same options can be used to build lsof.
1673 Configure calls MkKernOpts for the selected dialects.
1674
1675 If your kernel is built with options that affect structure definitions.
1676 -- most commonly affected are the proc structure from <sys/proc.h>
1677 and the user structure from <sys/user.h> -- check the MkKernOpts
1678 in lsof4/dialects/irix for a comprehensive example.
1679
1680
1681 Testing and the Lsof Test Suite
1682 -------------------------------
1683
1684 Once you have managed to create a port, here are some tips for
1685 testing it.
1686
1687 * First look at the test suite in the tests/ sub-directory of the
1688 lsof distribution. While it will need to be customized to be
1689 usable with a new port, it should provide ideas on things to
1690 test. Look for more information about the test suite in the
1691 00TEST file.
1692
1693 * Pick a simple process whose open files you are likely to
1694 know and see if the lsof output agrees with what you know.
1695 (Hint: select the process with `lsof -p <process_PID>`.)
1696
1697 Are the device numbers and device names correct?
1698
1699 Are the file system names and mount points correct?
1700
1701 Are inode numbers and sizes correct?
1702
1703 Are command names, file descriptor numbers, UIDs, PIDs, PGIDs,
1704 and PPIDs correct?
1705
1706 A simple tool that does a stat(2) of the files being examined
1707 and reports the stat struct contents can provide a reference for
1708 some values; so can `ls -l /dev/<device>`.
1709
1710 * Let lsof list information about all open files and ask the
1711 same questions. Look also for error messages about not being
1712 able to read a node or structure.
1713
1714 * Pick a file that you know is open -- open it and hold it
1715 that way with a C program (not vi), if you must. Ask lsof to
1716 find the file's open instance by specifying its path to lsof.
1717
1718 * Create a C program that opens a large number of files and holds
1719 them open. Background the test process and ask lsof to list
1720 its files.
1721
1722 * Generate some locks -- you may need to write a C program to
1723 do this, hold the locked file open, and see if lsof can identify
1724 the lock properly. You may need to write several C programs
1725 if your dialect supports different lock functions -- fnctl(),
1726 flock(), lockf(), locking().
1727
1728 * Identify a process with known Internet file usage -- inetd
1729 is a good one -- and ask lsof to list its open files. See if
1730 protocols and service names are listed properly.
1731
1732 See if your lsof identifies Internet socket files properly for
1733 rlogind or telnetd processes.
1734
1735 * Create a UNIX domain socket file, if your dialect allows it,
1736 hold it open by backgrounding the process, and see if lsof can
1737 identify the open UNIX domain socket file properly.
1738
1739 * Create a FIFO file and see what lsof says about it.
1740
1741 * Watch an open pipe -- `lsof -u <your_login> | less` is a
1742 good way to do this.
1743
1744 * See if lsof can identify NFS files and their devices properly.
1745 Open and hold open an NFS file and see if lsof can find the open
1746 instance by path.
1747
1748 * If your test system has CD-ROM and floppy disk devices, open
1749 files on them and see if lsof reports their information correctly.
1750 Such devices often have special kernel structures associated
1751 with them and need special attention from lsof for their
1752 identification. Pay particular attention to the inode numbers
1753 lsof reports for CD-ROM and floppy disk files -- often they are
1754 calculated dynamically, rather than stored in a kernel node
1755 structure.
1756
1757 * If your implementation can probe the kernel name cache, look
1758 at some processes with open files whose paths you know to see
1759 if lsof identifies any name components. If it doesn't, make
1760 sure the name components are in the name cache by accessing
1761 the files yourself with ls or a similar tool.
1762
1763 * If your dialect supports the /proc file system, use a C program
1764 to open files there, background a test process, and ask lsof to
1765 report its open files.
1766
1767 * If your dialect supports fattach(), create a small test program
1768 to use it, background a test process, and ask lsof to report
1769 its open files.
1770
1771 I can supply some quick-and-dirty tools for reporting stat buffer
1772 contents, holding files open, creating UNIX domain files, creating
1773 FIFOs, etc., if you need them.
1774
1775
1776 Where Next?
1777 -----------
1778
1779 Is this document complete? Certainly not! One might wish that it
1780 were accompanied by man pages for all lsof functions, by free beer
1781 or chocolates, by ... (You get the idea.)
1782
1783 But those things are not likely to happen as long as lsof is a
1784 privately supported, one man operation.
1785
1786 So, if you need more information on how lsof is constructed or
1787 works in order to do a port of your own, you'll have to read the
1788 lsof source code. You can also ask me questions via email, but
1789 keep in mind the private, one-man nature of current lsof support.
1790
1791
1792 Vic Abell <[email protected]>
1793 July 14, 2018