freebsd-skq/usr.bin/fstat/fstat.c

652 lines
16 KiB
C
Raw Permalink Normal View History

1994-05-27 12:33:43 +00:00
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
1994-05-27 12:33:43 +00:00
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
1994-05-27 12:33:43 +00:00
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
2002-06-30 05:25:07 +00:00
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
1994-05-27 12:33:43 +00:00
#include <sys/param.h>
#include <sys/user.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sysctl.h>
1995-04-10 00:38:15 +00:00
#include <sys/queue.h>
#include <sys/un.h>
1994-05-27 12:33:43 +00:00
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
1994-05-27 12:33:43 +00:00
#include <ctype.h>
1997-07-08 11:02:48 +00:00
#include <err.h>
#include <libprocstat.h>
1997-03-11 13:43:33 +00:00
#include <limits.h>
1994-05-27 12:33:43 +00:00
#include <pwd.h>
#include <stdint.h>
1994-05-27 12:33:43 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
1994-05-27 12:33:43 +00:00
#include <string.h>
1997-03-11 13:43:33 +00:00
#include <unistd.h>
#include <netdb.h>
1994-05-27 12:33:43 +00:00
#include "functions.h"
1994-05-27 12:33:43 +00:00
static int fsflg, /* show files on same filesystem as file(s) argument */
pflg, /* show files open by a particular pid */
sflg, /* show socket details */
uflg; /* show files open by a particular (effective) user */
static int checkfile; /* restrict to particular files or filesystems */
static int nflg; /* (numerical) display f.s. and rdev as dev_t */
static int mflg; /* include memory-mapped files */
static int vflg; /* be verbose */
1994-05-27 12:33:43 +00:00
typedef struct devs {
struct devs *next;
uint64_t fsid;
uint64_t ino;
const char *name;
} DEVS;
1994-05-27 12:33:43 +00:00
static DEVS *devs;
static char *memf, *nlistf;
static int getfname(const char *filename);
static void dofiles(struct procstat *procstat, struct kinfo_proc *p);
static void print_access_flags(int flags);
static void print_file_info(struct procstat *procstat,
struct filestat *fst, const char *uname, const char *cmd, int pid);
static void print_pipe_info(struct procstat *procstat,
struct filestat *fst);
static void print_pts_info(struct procstat *procstat,
struct filestat *fst);
static void print_sem_info(struct procstat *procstat,
struct filestat *fst);
static void print_shm_info(struct procstat *procstat,
struct filestat *fst);
static void print_socket_info(struct procstat *procstat,
struct filestat *fst);
static void print_vnode_info(struct procstat *procstat,
struct filestat *fst);
static void usage(void) __dead2;
int
do_fstat(int argc, char **argv)
1994-05-27 12:33:43 +00:00
{
struct kinfo_proc *p;
struct passwd *passwd;
struct procstat *procstat;
1994-05-27 12:33:43 +00:00
int arg, ch, what;
int cnt, i;
1994-05-27 12:33:43 +00:00
arg = 0;
what = KERN_PROC_PROC;
1994-05-27 12:33:43 +00:00
nlistf = memf = NULL;
while ((ch = getopt(argc, argv, "fmnp:su:vN:M:")) != -1)
1994-05-27 12:33:43 +00:00
switch((char)ch) {
case 'f':
fsflg = 1;
break;
case 'M':
memf = optarg;
break;
case 'N':
nlistf = optarg;
break;
case 'm':
mflg = 1;
break;
1994-05-27 12:33:43 +00:00
case 'n':
nflg = 1;
break;
case 'p':
if (pflg++)
usage();
if (!isdigit(*optarg)) {
1997-07-10 06:41:33 +00:00
warnx("-p requires a process id");
1994-05-27 12:33:43 +00:00
usage();
}
what = KERN_PROC_PID;
arg = atoi(optarg);
break;
case 's':
sflg = 1;
break;
1994-05-27 12:33:43 +00:00
case 'u':
if (uflg++)
usage();
1997-07-08 11:02:48 +00:00
if (!(passwd = getpwnam(optarg)))
errx(1, "%s: unknown uid", optarg);
1994-05-27 12:33:43 +00:00
what = KERN_PROC_UID;
arg = passwd->pw_uid;
break;
case 'v':
vflg = 1;
break;
case '?':
default:
usage();
}
if (*(argv += optind)) {
for (; *argv; ++argv) {
if (getfname(*argv))
checkfile = 1;
}
2011-12-30 11:02:40 +00:00
if (!checkfile) /* file(s) specified, but none accessible */
1994-05-27 12:33:43 +00:00
exit(1);
}
1995-05-30 06:41:30 +00:00
if (fsflg && !checkfile) {
1994-05-27 12:33:43 +00:00
/* -f with no files means use wd */
if (getfname(".") == 0)
exit(1);
checkfile = 1;
}
if (memf != NULL)
procstat = procstat_open_kvm(nlistf, memf);
else
procstat = procstat_open_sysctl();
if (procstat == NULL)
errx(1, "procstat_open()");
p = procstat_getprocs(procstat, what, arg, &cnt);
if (p == NULL)
errx(1, "procstat_getprocs()");
/*
* Print header.
*/
if (nflg)
printf("%s",
"USER CMD PID FD DEV INUM MODE SZ|DV R/W");
else
printf("%s",
"USER CMD PID FD MOUNT INUM MODE SZ|DV R/W");
if (checkfile && fsflg == 0)
printf(" NAME\n");
else
putchar('\n');
1994-05-27 12:33:43 +00:00
/*
* Go through the process list.
1994-05-27 12:33:43 +00:00
*/
for (i = 0; i < cnt; i++) {
if (p[i].ki_stat == SZOMB)
1994-05-27 12:33:43 +00:00
continue;
dofiles(procstat, &p[i]);
1994-05-27 12:33:43 +00:00
}
procstat_freeprocs(procstat, p);
procstat_close(procstat);
return (0);
}
static void
dofiles(struct procstat *procstat, struct kinfo_proc *kp)
1994-05-27 12:33:43 +00:00
{
const char *cmd;
const char *uname;
struct filestat *fst;
struct filestat_list *head;
int pid;
uname = user_from_uid(kp->ki_uid, 0);
pid = kp->ki_pid;
cmd = kp->ki_comm;
head = procstat_getfiles(procstat, kp, mflg);
if (head == NULL)
1994-05-27 12:33:43 +00:00
return;
STAILQ_FOREACH(fst, head, next)
print_file_info(procstat, fst, uname, cmd, pid);
procstat_freefiles(procstat, head);
}
static void
print_file_info(struct procstat *procstat, struct filestat *fst,
const char *uname, const char *cmd, int pid)
1994-05-27 12:33:43 +00:00
{
struct vnstat vn;
DEVS *d;
const char *filename;
int error, fsmatch = 0;
char errbuf[_POSIX2_LINE_MAX];
filename = NULL;
if (checkfile != 0) {
if (fst->fs_type != PS_FST_TYPE_VNODE &&
fst->fs_type != PS_FST_TYPE_FIFO)
1994-05-27 12:33:43 +00:00
return;
error = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
if (error != 0)
return;
1994-05-27 12:33:43 +00:00
for (d = devs; d != NULL; d = d->next)
if (d->fsid == vn.vn_fsid) {
fsmatch = 1;
if (d->ino == vn.vn_fileid) {
filename = d->name;
break;
1994-05-27 12:33:43 +00:00
}
}
if (fsmatch == 0 || (filename == NULL && fsflg == 0))
return;
}
/*
* Print entry prefix.
*/
printf("%-8.8s %-10s %5d", uname, cmd, pid);
if (fst->fs_uflags & PS_FST_UFLAG_TEXT)
printf(" text");
else if (fst->fs_uflags & PS_FST_UFLAG_CDIR)
printf(" wd");
else if (fst->fs_uflags & PS_FST_UFLAG_RDIR)
printf(" root");
else if (fst->fs_uflags & PS_FST_UFLAG_TRACE)
printf(" tr");
else if (fst->fs_uflags & PS_FST_UFLAG_MMAP)
printf(" mmap");
else if (fst->fs_uflags & PS_FST_UFLAG_JAIL)
printf(" jail");
else if (fst->fs_uflags & PS_FST_UFLAG_CTTY)
printf(" ctty");
else
printf(" %4d", fst->fs_fd);
/*
* Print type-specific data.
*/
switch (fst->fs_type) {
case PS_FST_TYPE_FIFO:
case PS_FST_TYPE_VNODE:
print_vnode_info(procstat, fst);
1994-05-27 12:33:43 +00:00
break;
case PS_FST_TYPE_SOCKET:
print_socket_info(procstat, fst);
1994-05-27 12:33:43 +00:00
break;
case PS_FST_TYPE_PIPE:
print_pipe_info(procstat, fst);
1994-05-27 12:33:43 +00:00
break;
case PS_FST_TYPE_PTS:
print_pts_info(procstat, fst);
1994-05-27 12:33:43 +00:00
break;
case PS_FST_TYPE_SHM:
print_shm_info(procstat, fst);
break;
case PS_FST_TYPE_SEM:
print_sem_info(procstat, fst);
break;
case PS_FST_TYPE_DEV:
break;
default:
if (vflg)
fprintf(stderr,
"unknown file type %d for file %d of pid %d\n",
fst->fs_type, fst->fs_fd, pid);
}
if (filename && !fsflg)
printf(" %s", filename);
putchar('\n');
}
static char *
addr_to_string(struct sockaddr_storage *ss, char *buffer, int buflen)
{
char buffer2[INET6_ADDRSTRLEN];
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin;
struct sockaddr_un *sun;
switch (ss->ss_family) {
case AF_LOCAL:
sun = (struct sockaddr_un *)ss;
if (strlen(sun->sun_path) == 0)
strlcpy(buffer, "-", buflen);
else
strlcpy(buffer, sun->sun_path, buflen);
break;
case AF_INET:
sin = (struct sockaddr_in *)ss;
if (sin->sin_addr.s_addr == INADDR_ANY)
snprintf(buffer, buflen, "%s:%d", "*",
ntohs(sin->sin_port));
else if (inet_ntop(AF_INET, &sin->sin_addr, buffer2,
sizeof(buffer2)) != NULL)
snprintf(buffer, buflen, "%s:%d", buffer2,
ntohs(sin->sin_port));
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)ss;
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
snprintf(buffer, buflen, "%s.%d", "*",
ntohs(sin6->sin6_port));
else if (inet_ntop(AF_INET6, &sin6->sin6_addr, buffer2,
sizeof(buffer2)) != NULL)
snprintf(buffer, buflen, "%s.%d", buffer2,
ntohs(sin6->sin6_port));
else
strlcpy(buffer, "-", buflen);
break;
default:
strlcpy(buffer, "", buflen);
break;
}
return buffer;
}
static void
print_socket_info(struct procstat *procstat, struct filestat *fst)
1994-05-27 12:33:43 +00:00
{
static const char *stypename[] = {
1994-05-27 12:33:43 +00:00
"unused", /* 0 */
"stream", /* 1 */
1994-05-27 12:33:43 +00:00
"dgram", /* 2 */
"raw", /* 3 */
"rdm", /* 4 */
"seqpak" /* 5 */
};
#define STYPEMAX 5
struct sockstat sock;
struct protoent *pe;
char errbuf[_POSIX2_LINE_MAX];
char src_addr[PATH_MAX], dst_addr[PATH_MAX];
struct sockaddr_un *sun;
int error;
static int isopen;
1994-05-27 12:33:43 +00:00
error = procstat_get_socket_info(procstat, fst, &sock, errbuf);
if (error != 0) {
printf("* error");
return;
1994-05-27 12:33:43 +00:00
}
if (sock.type > STYPEMAX)
printf("* %s ?%d", sock.dname, sock.type);
1994-05-27 12:33:43 +00:00
else
printf("* %s %s", sock.dname, stypename[sock.type]);
1994-05-27 12:33:43 +00:00
1995-05-30 06:41:30 +00:00
/*
1994-05-27 12:33:43 +00:00
* protocol specific formatting
*
* Try to find interesting things to print. For tcp, the interesting
* thing is the address of the tcpcb, for udp and others, just the
* inpcb (socket pcb). For unix domain, its the address of the socket
* pcb and the address of the connected pcb (if connected). Otherwise
* just print the protocol number and address of the socket itself.
* The idea is not to duplicate netstat, but to make available enough
* information for further analysis.
*/
switch (sock.dom_family) {
1994-05-27 12:33:43 +00:00
case AF_INET:
case AF_INET6:
if (!isopen)
setprotoent(++isopen);
if ((pe = getprotobynumber(sock.proto)) != NULL)
printf(" %s", pe->p_name);
else
printf(" %d", sock.proto);
if (sock.proto == IPPROTO_TCP ) {
if (sock.inp_ppcb != 0)
printf(" %lx", (u_long)sock.inp_ppcb);
1994-05-27 12:33:43 +00:00
}
else if (sock.so_pcb != 0)
printf(" %lx", (u_long)sock.so_pcb);
if (!sflg)
break;
printf(" %s <-> %s",
addr_to_string(&sock.sa_local, src_addr, sizeof(src_addr)),
addr_to_string(&sock.sa_peer, dst_addr, sizeof(dst_addr)));
1994-05-27 12:33:43 +00:00
break;
case AF_UNIX:
/* print address of pcb and connected pcb */
if (sock.so_pcb != 0) {
printf(" %lx", (u_long)sock.so_pcb);
if (sock.unp_conn) {
1994-05-27 12:33:43 +00:00
char shoconn[4], *cp;
cp = shoconn;
if (!(sock.so_rcv_sb_state & SBS_CANTRCVMORE))
1994-05-27 12:33:43 +00:00
*cp++ = '<';
*cp++ = '-';
if (!(sock.so_snd_sb_state & SBS_CANTSENDMORE))
1994-05-27 12:33:43 +00:00
*cp++ = '>';
*cp = '\0';
printf(" %s %lx", shoconn,
(u_long)sock.unp_conn);
}
1994-05-27 12:33:43 +00:00
}
if (!sflg)
break;
sun = (struct sockaddr_un *)&sock.sa_local;
/*
* While generally we like to print two addresses,
* local and peer, for sockets, it turns out to be
* more useful to print the first non-null address for
* local sockets, as typically they aren't bound and
* connected, and the path strings can get long.
*/
if (sun->sun_path[0] != 0)
addr_to_string(&sock.sa_local,
src_addr, sizeof(src_addr));
else
addr_to_string(&sock.sa_peer,
src_addr, sizeof(src_addr));
printf(" %s", src_addr);
1994-05-27 12:33:43 +00:00
break;
default:
/* print protocol number and socket address */
printf(" %d %lx", sock.proto, (u_long)sock.so_addr);
1994-05-27 12:33:43 +00:00
}
}
static void
print_pipe_info(struct procstat *procstat, struct filestat *fst)
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
{
struct pipestat ps;
char errbuf[_POSIX2_LINE_MAX];
int error;
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
error = procstat_get_pipe_info(procstat, fst, &ps, errbuf);
if (error != 0) {
printf("* error");
return;
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
}
printf("* pipe %8lx <-> %8lx", (u_long)ps.addr, (u_long)ps.peer);
printf(" %6zd", ps.buffer_cnt);
print_access_flags(fst->fs_fflags);
}
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
static void
print_pts_info(struct procstat *procstat, struct filestat *fst)
{
struct ptsstat pts;
char errbuf[_POSIX2_LINE_MAX];
int error;
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
error = procstat_get_pts_info(procstat, fst, &pts, errbuf);
if (error != 0) {
printf("* error");
return;
}
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
printf("* pseudo-terminal master ");
if (nflg || !*pts.devname) {
printf("%#10jx", (uintmax_t)pts.dev);
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
} else {
printf("%10s", pts.devname);
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
}
print_access_flags(fst->fs_fflags);
Integrate the new MPSAFE TTY layer to the FreeBSD operating system. The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
}
static void
print_sem_info(struct procstat *procstat, struct filestat *fst)
{
struct semstat sem;
char errbuf[_POSIX2_LINE_MAX];
char mode[15];
int error;
error = procstat_get_sem_info(procstat, fst, &sem, errbuf);
if (error != 0) {
printf("* error");
return;
}
if (nflg) {
printf(" ");
(void)snprintf(mode, sizeof(mode), "%o", sem.mode);
} else {
printf(" %-15s", fst->fs_path != NULL ? fst->fs_path : "-");
strmode(sem.mode, mode);
}
printf(" %10s %6u", mode, sem.value);
print_access_flags(fst->fs_fflags);
}
static void
print_shm_info(struct procstat *procstat, struct filestat *fst)
{
struct shmstat shm;
char errbuf[_POSIX2_LINE_MAX];
char mode[15];
int error;
error = procstat_get_shm_info(procstat, fst, &shm, errbuf);
if (error != 0) {
printf("* error");
return;
}
if (nflg) {
printf(" ");
(void)snprintf(mode, sizeof(mode), "%o", shm.mode);
} else {
printf(" %-15s", fst->fs_path != NULL ? fst->fs_path : "-");
strmode(shm.mode, mode);
}
printf(" %10s %6ju", mode, shm.size);
print_access_flags(fst->fs_fflags);
}
static void
print_vnode_info(struct procstat *procstat, struct filestat *fst)
{
struct vnstat vn;
char errbuf[_POSIX2_LINE_MAX];
char mode[15];
const char *badtype;
int error;
badtype = NULL;
error = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
if (error != 0)
badtype = errbuf;
else if (vn.vn_type == PS_FST_VTYPE_VBAD)
badtype = "bad";
else if (vn.vn_type == PS_FST_VTYPE_VNON)
badtype = "none";
if (badtype != NULL) {
printf(" - - %10s -", badtype);
return;
}
if (nflg)
printf(" %#5jx", (uintmax_t)vn.vn_fsid);
else if (vn.vn_mntdir != NULL)
(void)printf(" %-8s", vn.vn_mntdir);
/*
* Print access mode.
*/
if (nflg)
(void)snprintf(mode, sizeof(mode), "%o", vn.vn_mode);
else {
strmode(vn.vn_mode, mode);
}
(void)printf(" %6jd %10s", (intmax_t)vn.vn_fileid, mode);
if (vn.vn_type == PS_FST_VTYPE_VBLK || vn.vn_type == PS_FST_VTYPE_VCHR) {
if (nflg || !*vn.vn_devname)
printf(" %#6jx", (uintmax_t)vn.vn_dev);
else {
printf(" %6s", vn.vn_devname);
}
} else
printf(" %6ju", (uintmax_t)vn.vn_size);
print_access_flags(fst->fs_fflags);
}
static void
print_access_flags(int flags)
1994-05-27 12:33:43 +00:00
{
char rw[3];
rw[0] = '\0';
if (flags & PS_FST_FFLAG_READ)
strcat(rw, "r");
if (flags & PS_FST_FFLAG_WRITE)
strcat(rw, "w");
printf(" %2s", rw);
1994-05-27 12:33:43 +00:00
}
int
getfname(const char *filename)
1994-05-27 12:33:43 +00:00
{
struct stat statbuf;
DEVS *cur;
if (stat(filename, &statbuf)) {
1997-07-08 11:02:48 +00:00
warn("%s", filename);
return (0);
1994-05-27 12:33:43 +00:00
}
1997-07-08 11:02:48 +00:00
if ((cur = malloc(sizeof(DEVS))) == NULL)
err(1, NULL);
1994-05-27 12:33:43 +00:00
cur->next = devs;
devs = cur;
cur->ino = statbuf.st_ino;
cur->fsid = statbuf.st_dev;
1994-05-27 12:33:43 +00:00
cur->name = filename;
return (1);
1994-05-27 12:33:43 +00:00
}
static void
usage(void)
1994-05-27 12:33:43 +00:00
{
(void)fprintf(stderr,
"usage: fstat [-fmnv] [-M core] [-N system] [-p pid] [-u user] [file ...]\n");
1994-05-27 12:33:43 +00:00
exit(1);
}