2 * Copyright 2006-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * Axel Dörfler, axeld@pinc-software.de
29 extern const char *__progname
;
33 open_mode_to_string(int openMode
)
35 switch (openMode
& O_RWMASK
) {
47 print_fds(team_info
&teamInfo
)
49 printf("Team: (%" B_PRId32
") %s\n", teamInfo
.team
, teamInfo
.args
);
54 while (_kern_get_next_fd_info(teamInfo
.team
, &cookie
, &info
, sizeof(fd_info
)) == B_OK
) {
55 printf("%5d %s %" B_PRIdDEV
":%" B_PRIdINO
"\n", info
.number
,
56 open_mode_to_string(info
.open_mode
), info
.device
, info
.node
);
62 filter_device(team_info
&teamInfo
, dev_t device
, bool brief
)
67 while (_kern_get_next_fd_info(teamInfo
.team
, &cookie
, &info
, sizeof(fd_info
)) == B_OK
) {
68 if (info
.device
!= device
)
72 printf("%5" B_PRId32
" %s\n", teamInfo
.team
, teamInfo
.args
);
76 printf("%5" B_PRId32
" %3d %3s %" B_PRIdDEV
":%" B_PRIdINO
" %s\n",
77 teamInfo
.team
, info
.number
, open_mode_to_string(info
.open_mode
),
78 info
.device
, info
.node
, teamInfo
.args
);
84 filter_file(team_info
&teamInfo
, dev_t device
, ino_t node
, bool brief
)
89 while (_kern_get_next_fd_info(teamInfo
.team
, &cookie
, &info
, sizeof(fd_info
)) == B_OK
) {
90 if (info
.device
!= device
|| info
.node
!= node
)
94 printf("%5" B_PRId32
" %s\n", teamInfo
.team
, teamInfo
.args
);
98 printf("%5" B_PRId32
" %3d %3s %s\n", teamInfo
.team
, info
.number
,
99 open_mode_to_string(info
.open_mode
), teamInfo
.args
);
107 printf("Usage: %s <id/pattern> or -[dD] <path-to-device> or -[fF] <file>\n"
108 " Shows info about the used file descriptors in the system.\n\n"
109 " -d\tOnly shows accesses to the given device\n"
110 " -D\tLikewise, but only shows the teams that access it\n"
111 " -f\tOnly shows accesses to the given file\n"
112 " -F\tLikewise, but only shows the teams that access it\n",
115 exit(failure
? 1 : 0);
120 main(int argc
, char **argv
)
122 const char *pattern
= NULL
;
126 info_mode mode
= kList
;
133 if (isdigit(argv
[1][0]))
135 else if (argv
[1][0] == '-')
136 usage(!strcmp(argv
[1], "--help"));
139 } else if (argc
> 2) {
140 if (!strcmp(argv
[1], "-d") || !strcmp(argv
[1], "-D")) {
141 // filter by device usage
142 device
= dev_for_path(argv
[2]);
144 fprintf(stderr
, "%s: could not find device: %s\n", __progname
,
148 mode
= kFilterDevice
;
149 if (argv
[1][1] == 'D')
151 } else if (!strcmp(argv
[1], "-f") || !strcmp(argv
[1], "-F")) {
152 // filter by file usage
154 if (::stat(argv
[2], &stat
) < 0) {
155 fprintf(stderr
, "%s: could not open file: %s\n", __progname
,
159 device
= stat
.st_dev
;
162 if (argv
[1][1] == 'F')
173 while (get_next_team_info(&cookie
, &info
) == B_OK
) {
176 if ((id
!= -1 && id
!= info
.team
)
177 || (pattern
!= NULL
&& !strstr(info
.args
, pattern
)))
183 filter_device(info
, device
, brief
);
186 filter_file(info
, device
, node
, brief
);