1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
* dfile.c - SCO OpenServer file processing functions for lsof
*/
/*
* Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana
* 47907. All rights reserved.
*
* Written by Victor A. Abell
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
*
* 1. Neither the authors nor Purdue University are responsible for any
* consequences of the use of this software.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Credit to the authors and Purdue
* University must appear in documentation and sources.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 4. This notice may not be removed or altered.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright 1995 Purdue Research Foundation.\nAll rights reserved.\n";
static char *rcsid = "$Id: dfile.c,v 1.11 2000/12/04 14:32:49 abe Exp abe $";
#endif
#include "lsof.h"
/*
* get_max_fd() - get maximum file descriptor plus one
*/
int
get_max_fd()
{
#if defined(F_GETHFDO) || defined(_SC_OPEN_MAX)
int nd;
#endif /* defined(F_GETHFDO) || defined(_SC_OPEN_MAX) */
#if defined(F_GETHFDO)
if ((nd = fcntl(-1, F_GETHFDO, 0)) >= 0)
return(nd);
#endif /* defined(F_GETHFDO) */
#if defined(_SC_OPEN_MAX)
if ((nd = sysconf(_SC_OPEN_MAX)) >= 0)
return(nd);
#endif /* defined(_SC_OPEN_MAX) */
return(getdtablesize());
}
/*
* print_dev() - print dev
*/
char *
print_dev(lf, dev)
struct lfile *lf; /* file whose device is to be printed */
dev_t *dev; /* device to be printed */
{
static char buf[128];
(void) snpf(buf, sizeof(buf), "%d,%d",
lf->is_nfs ? ((~(*dev >> 8)) & 0xff) : emajor(*dev),
eminor(*dev));
return(buf);
}
/*
* print_ino() - print inode
*/
char *
print_ino(lf)
struct lfile *lf; /* file whose device is to be printed */
{
static char buf[128];
(void) snpf(buf, sizeof(buf), (lf->inode & 0x80000000) ? "%#x" : "%lu",
lf->inode);
return(buf);
}
/*
* process_file() - process file
*/
void
process_file(fp)
KA_T fp; /* kernel file structure address */
{
struct file f;
int flag;
if (kread(fp, (char *)&f, sizeof(f))) {
(void) snpf(Namech, Namechl, "can't read file struct from %s",
print_kptr(fp, (char *)NULL, 0));
enter_nm(Namech);
return;
}
Lf->off = (SZOFFTYPE)f.f_offset;
if (f.f_count) {
/*
* Construct access code.
*/
if ((flag = (f.f_flag & (FREAD | FWRITE))) == FREAD)
Lf->access = 'r';
else if (flag == FWRITE)
Lf->access = 'w';
else if (flag == (FREAD | FWRITE))
Lf->access = 'u';
/*
* Process structure.
*/
#if defined(HASFSTRUCT)
/*
* Save file structure values.
*/
if (Fsv & FSV_CT) {
Lf->fct = (long)f.f_count;
Lf->fsv |= FSV_CT;
}
if (Fsv & FSV_FA) {
Lf->fsa = fp;
Lf->fsv |= FSV_FA;
}
if (Fsv & FSV_FG) {
Lf->ffg = (long)f.f_flag;
Lf->fsv |= FSV_FG;
}
if (Fsv & FSV_NI) {
Lf->fna = (KA_T)f.f_inode;
Lf->fsv |= FSV_NI;
}
#endif /* defined(HASFSTRUCT) */
process_node((KA_T)f.f_inode);
return;
}
enter_nm("no more information");
}
|