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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_ks.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/door.h>
#include <sys/file.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/procfs.h>
#include <sys/proc/prdata.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/vnode.h>
#include <sys/fs/snode.h>
#include <sys/fs/fifonode.h>
#include <sys/fs/namenode.h>
#include <sys/socket.h>
#include <sys/stropts.h>
#include <sys/socketvar.h>
#include <sys/strsubr.h>
#include <sys/un.h>
int
vfs_walk_init(mdb_walk_state_t *wsp)
{
if (wsp->walk_addr == NULL &&
mdb_readvar(&wsp->walk_addr, "rootvfs") == -1) {
mdb_warn("failed to read 'rootvfs'");
return (WALK_ERR);
}
wsp->walk_data = (void *)wsp->walk_addr;
return (WALK_NEXT);
}
int
vfs_walk_step(mdb_walk_state_t *wsp)
{
vfs_t vfs;
int status;
if (mdb_vread(&vfs, sizeof (vfs), wsp->walk_addr) == -1) {
mdb_warn("failed to read vfs_t at %p", wsp->walk_addr);
return (WALK_DONE);
}
status = wsp->walk_callback(wsp->walk_addr, &vfs, wsp->walk_cbdata);
if (vfs.vfs_next == wsp->walk_data)
return (WALK_DONE);
wsp->walk_addr = (uintptr_t)vfs.vfs_next;
return (status);
}
/*
* Utility routine to read in a filesystem name given a vfs pointer. If
* no vfssw entry for the vfs is available (as is the case with some pseudo-
* filesystems), we check against some known problem fs's: doorfs and
* portfs. If that fails, we try to guess the filesystem name using
* symbol names. fsname should be a buffer of size _ST_FSTYPSZ.
*/
static int
read_fsname(uintptr_t vfsp, char *fsname)
{
vfs_t vfs;
struct vfssw vfssw_entry;
GElf_Sym vfssw_sym, test_sym;
char testname[MDB_SYM_NAMLEN];
if (mdb_vread(&vfs, sizeof (vfs), vfsp) == -1) {
mdb_warn("failed to read vfs %p", vfsp);
return (-1);
}
if (mdb_lookup_by_name("vfssw", &vfssw_sym) == -1) {
mdb_warn("failed to find vfssw");
return (-1);
}
/*
* vfssw is an array; we need vfssw[vfs.vfs_fstype].
*/
if (mdb_vread(&vfssw_entry, sizeof (vfssw_entry),
vfssw_sym.st_value + (sizeof (struct vfssw) * vfs.vfs_fstype))
== -1) {
mdb_warn("failed to read vfssw index %d", vfs.vfs_fstype);
return (-1);
}
if (vfs.vfs_fstype != 0) {
if (mdb_readstr(fsname, _ST_FSTYPSZ,
(uintptr_t)vfssw_entry.vsw_name) == -1) {
mdb_warn("failed to find fs name %p",
vfssw_entry.vsw_name);
return (-1);
}
return (0);
}
/*
* Do precise detection for certain filesystem types that we
* know do not appear in vfssw[], and that we depend upon in other
* parts of the code: doorfs and portfs.
*/
if (mdb_lookup_by_name("door_vfs", &test_sym) != -1) {
if (test_sym.st_value == vfsp) {
strcpy(fsname, "doorfs");
return (0);
}
}
if (mdb_lookup_by_name("port_vfs", &test_sym) != -1) {
if (test_sym.st_value == vfsp) {
strcpy(fsname, "portfs");
return (0);
}
}
/*
* Heuristic detection for other filesystems that don't have a
* vfssw[] entry. These tend to be named <fsname>_vfs, so we do a
* lookup_by_addr and see if we find a symbol of that name.
*/
if (mdb_lookup_by_addr(vfsp, MDB_SYM_EXACT, testname, sizeof (testname),
&test_sym) != -1) {
if ((strlen(testname) > 4) &&
(strcmp(testname + strlen(testname) - 4, "_vfs") == 0)) {
testname[strlen(testname) - 4] = '\0';
strncpy(fsname, testname, _ST_FSTYPSZ);
return (0);
}
}
mdb_warn("unknown filesystem type for vfs %p", vfsp);
return (-1);
}
/*
* Column widths for mount point display in ::fsinfo output.
*/
#ifdef _LP64
#define FSINFO_MNTLEN 48
#else
#define FSINFO_MNTLEN 56
#endif
/*ARGSUSED*/
int
fsinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
vfs_t vfs;
int len;
int opt_v = 0;
char buf[MAXPATHLEN];
char fsname[_ST_FSTYPSZ];
mntopt_t *mntopts;
size_t size;
int i;
int first = 1;
char opt[MAX_MNTOPT_STR];
uintptr_t global_zone;
if (!(flags & DCMD_ADDRSPEC)) {
if (mdb_walk_dcmd("vfs", "fsinfo", argc, argv) == -1) {
mdb_warn("failed to walk file system list");
return (DCMD_ERR);
}
return (DCMD_OK);
}
if (mdb_getopts(argc, argv,
'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL) != argc)
return (DCMD_USAGE);
if (DCMD_HDRSPEC(flags))
mdb_printf("%<u>%?s %-15s %s%</u>\n",
"VFSP", "FS", "MOUNT");
if (mdb_vread(&vfs, sizeof (vfs), addr) == -1) {
mdb_warn("failed to read vfs_t %p", addr);
return (DCMD_ERR);
}
if ((len = mdb_read_refstr((uintptr_t)vfs.vfs_mntpt, buf,
sizeof (buf))) <= 0)
strcpy(buf, "??");
else if (!opt_v && (len >= FSINFO_MNTLEN))
/*
* In normal mode, we truncate the path to keep the output
* clean. In -v mode, we just print the full path.
*/
strcpy(&buf[FSINFO_MNTLEN - 4], "...");
if (read_fsname(addr, fsname) == -1)
return (DCMD_ERR);
mdb_printf("%0?p %-15s %s\n", addr, fsname, buf);
if (!opt_v)
return (DCMD_OK);
/*
* Print 'resource' string; this shows what we're mounted upon.
*/
if (mdb_read_refstr((uintptr_t)vfs.vfs_resource, buf,
MAXPATHLEN) <= 0)
strcpy(buf, "??");
mdb_printf("%?s %s\n", "R:", buf);
/*
* Print mount options array; it sucks to be a mimic, but we copy
* the same logic as in mntvnops.c for adding zone= tags, and we
* don't bother with the obsolete dev= option.
*/
size = vfs.vfs_mntopts.mo_count * sizeof (mntopt_t);
mntopts = mdb_alloc(size, UM_SLEEP | UM_GC);
if (mdb_vread(mntopts, size,
(uintptr_t)vfs.vfs_mntopts.mo_list) == -1) {
mdb_warn("failed to read mntopts %p", vfs.vfs_mntopts.mo_list);
return (DCMD_ERR);
}
for (i = 0; i < vfs.vfs_mntopts.mo_count; i++) {
if (mntopts[i].mo_flags & MO_SET) {
if (mdb_readstr(opt, sizeof (opt),
(uintptr_t)mntopts[i].mo_name) == -1) {
mdb_warn("failed to read mntopt name %p",
mntopts[i].mo_name);
return (DCMD_ERR);
}
if (first) {
mdb_printf("%?s ", "O:");
first = 0;
} else {
mdb_printf(",");
}
mdb_printf("%s", opt);
if (mntopts[i].mo_flags & MO_HASVALUE) {
if (mdb_readstr(opt, sizeof (opt),
(uintptr_t)mntopts[i].mo_arg) == -1) {
mdb_warn("failed to read mntopt "
"value %p", mntopts[i].mo_arg);
return (DCMD_ERR);
}
mdb_printf("=%s", opt);
}
}
}
if (mdb_readvar(&global_zone, "global_zone") == -1) {
mdb_warn("failed to locate global_zone");
return (DCMD_ERR);
}
if ((vfs.vfs_zone != NULL) &&
((uintptr_t)vfs.vfs_zone != global_zone)) {
zone_t z;
if (mdb_vread(&z, sizeof (z), (uintptr_t)vfs.vfs_zone) == -1) {
mdb_warn("failed to read zone");
return (DCMD_ERR);
}
/*
* zone names are much shorter than MAX_MNTOPT_STR
*/
if (mdb_readstr(opt, sizeof (opt),
(uintptr_t)z.zone_name) == -1) {
mdb_warn("failed to read zone name");
return (DCMD_ERR);
}
if (first) {
mdb_printf("%?s ", "O:");
} else {
mdb_printf(",");
}
mdb_printf("zone=%s", opt);
}
return (DCMD_OK);
}
#define REALVP_DONE 0
#define REALVP_ERR 1
#define REALVP_CONTINUE 2
static int
next_realvp(uintptr_t invp, struct vnode *outvn, uintptr_t *outvp)
{
char fsname[_ST_FSTYPSZ];
*outvp = invp;
if (mdb_vread(outvn, sizeof (struct vnode), invp) == -1) {
mdb_warn("failed to read vnode at %p", invp);
return (REALVP_ERR);
}
if (read_fsname((uintptr_t)outvn->v_vfsp, fsname) == -1)
return (REALVP_ERR);
/*
* We know how to do 'realvp' for as many filesystems as possible;
* for all other filesystems, we assume that the vp we are given
* is the realvp. In the kernel, a realvp operation will sometimes
* dig through multiple layers. Here, we only fetch the pointer
* to the next layer down. This allows dcmds to print out the
* various layers.
*/
if (strcmp(fsname, "fifofs") == 0) {
fifonode_t fn;
if (mdb_vread(&fn, sizeof (fn),
(uintptr_t)outvn->v_data) == -1) {
mdb_warn("failed to read fifonode");
return (REALVP_ERR);
}
*outvp = (uintptr_t)fn.fn_realvp;
} else if (strcmp(fsname, "namefs") == 0) {
struct namenode nn;
if (mdb_vread(&nn, sizeof (nn),
(uintptr_t)outvn->v_data) == -1) {
mdb_warn("failed to read namenode");
return (REALVP_ERR);
}
*outvp = (uintptr_t)nn.nm_filevp;
} else if (outvn->v_type == VSOCK && outvn->v_stream != NULL) {
struct stdata stream;
/*
* Sockets have a strange and different layering scheme; we
* hop over into the sockfs vnode (accessible via the stream
* head) if possible.
*/
if (mdb_vread(&stream, sizeof (stream),
(uintptr_t)outvn->v_stream) == -1) {
mdb_warn("failed to read stream data");
return (REALVP_ERR);
}
*outvp = (uintptr_t)stream.sd_vnode;
}
if (*outvp == invp || *outvp == NULL)
return (REALVP_DONE);
return (REALVP_CONTINUE);
}
static void
pfiles_print_addr(struct sockaddr *addr)
{
struct sockaddr_in *s_in;
struct sockaddr_un *s_un;
struct sockaddr_in6 *s_in6;
in_port_t port;
switch (addr->sa_family) {
case AF_INET:
/*LINTED: alignment*/
s_in = (struct sockaddr_in *)addr;
mdb_nhconvert(&port, &s_in->sin_port, sizeof (port));
mdb_printf("AF_INET %I %d ", s_in->sin_addr.s_addr, port);
break;
case AF_INET6:
/*LINTED: alignment*/
s_in6 = (struct sockaddr_in6 *)addr;
mdb_nhconvert(&port, &s_in6->sin6_port, sizeof (port));
mdb_printf("AF_INET6 %N %d ", &(s_in6->sin6_addr), port);
break;
case AF_UNIX:
s_un = (struct sockaddr_un *)addr;
mdb_printf("AF_UNIX %s ", s_un->sun_path);
break;
default:
mdb_printf("AF_?? (%d) ", addr->sa_family);
break;
}
}
static int
pfiles_get_sonode(uintptr_t vp, struct sonode *sonode)
{
vnode_t v;
struct stdata stream;
if (mdb_vread(&v, sizeof (v), vp) == -1) {
mdb_warn("failed to read socket vnode");
return (-1);
}
if (mdb_vread(&stream, sizeof (stream), (uintptr_t)v.v_stream) == -1) {
mdb_warn("failed to read stream data");
return (-1);
}
if (mdb_vread(&v, sizeof (v), (uintptr_t)stream.sd_vnode) == -1) {
mdb_warn("failed to read stream vnode");
return (-1);
}
if (mdb_vread(sonode, sizeof (struct sonode),
(uintptr_t)v.v_data) == -1) {
mdb_warn("failed to read sonode");
return (-1);
}
return (0);
}
/*
* Do some digging to get a reasonable pathname for this vnode. 'path'
* should point at a buffer of MAXPATHLEN in size.
*/
static int
pfiles_dig_pathname(uintptr_t vp, char *path)
{
vnode_t v;
bzero(path, MAXPATHLEN);
if (mdb_vread(&v, sizeof (v), vp) == -1) {
mdb_warn("failed to read vnode");
return (-1);
}
if (v.v_path == NULL) {
/*
* fifo's and doors are special. Some have pathnames, and
* some do not. And for these, it is pointless to go off to
* mdb_vnode2path, which is very slow.
*
* Event ports never have a pathname.
*/
if (v.v_type == VFIFO || v.v_type == VDOOR || v.v_type == VPORT)
return (0);
/*
* For sockets, we won't find a path unless we print the path
* associated with the accessvp.
*/
if (v.v_type == VSOCK) {
struct sonode sonode;
if (pfiles_get_sonode(vp, &sonode) == -1) {
return (-1);
}
vp = (uintptr_t)sonode.so_accessvp;
}
}
/*
* mdb_vnode2path will print an error for us as needed, but not
* finding a pathname is not really an error, so we plow on.
*/
(void) mdb_vnode2path(vp, path, MAXPATHLEN);
/*
* A common problem is that device pathnames are prefixed with
* /dev/../devices/. We just clean those up slightly:
* /dev/../devices/<mumble> --> /devices/<mumble>
* /dev/pts/../../devices/<mumble> --> /devices/<mumble>
*/
if (strncmp("/dev/../devices/", path, strlen("/dev/../devices/")) == 0)
strcpy(path, path + 7);
if (strncmp("/dev/pts/../../devices/", path,
strlen("/dev/pts/../../devices/")) == 0)
strcpy(path, path + 14);
return (0);
}
const struct fs_type {
int type;
const char *name;
} fs_types[] = {
{ VNON, "NON" },
{ VREG, "REG" },
{ VDIR, "DIR" },
{ VBLK, "BLK" },
{ VCHR, "CHR" },
{ VLNK, "LNK" },
{ VFIFO, "FIFO" },
{ VDOOR, "DOOR" },
{ VPROC, "PROC" },
{ VSOCK, "SOCK" },
{ VPORT, "PORT" },
{ VBAD, "BAD" }
};
#define NUM_FS_TYPES (sizeof (fs_types) / sizeof (struct fs_type))
struct pfiles_cbdata {
int opt_p;
int fd;
};
static int
pfile_callback(uintptr_t addr, const struct file *f, struct pfiles_cbdata *cb)
{
vnode_t v, layer_vn;
int myfd = cb->fd;
const char *type;
char path[MAXPATHLEN];
uintptr_t top_vnodep, realvpp;
char fsname[_ST_FSTYPSZ];
int err, i;
cb->fd++;
if (addr == NULL) {
return (WALK_NEXT);
}
top_vnodep = realvpp = (uintptr_t)f->f_vnode;
if (mdb_vread(&v, sizeof (v), realvpp) == -1) {
mdb_warn("failed to read vnode");
return (DCMD_ERR);
}
type = "?";
for (i = 0; i <= NUM_FS_TYPES; i++) {
if (fs_types[i].type == v.v_type)
type = fs_types[i].name;
}
do {
uintptr_t next_realvpp;
err = next_realvp(realvpp, &layer_vn, &next_realvpp);
if (next_realvpp != NULL)
realvpp = next_realvpp;
} while (err == REALVP_CONTINUE);
if (err == REALVP_ERR) {
mdb_warn("failed to do realvp() for %p", realvpp);
return (DCMD_ERR);
}
if (read_fsname((uintptr_t)layer_vn.v_vfsp, fsname) == -1)
return (DCMD_ERR);
mdb_printf("%4d %4s %?0p ", myfd, type, top_vnodep);
if (cb->opt_p) {
if (pfiles_dig_pathname(top_vnodep, path) == -1)
return (DCMD_ERR);
mdb_printf("%s\n", path);
return (DCMD_OK);
}
/*
* Sockets generally don't have interesting pathnames; we only
* show those in the '-p' view.
*/
path[0] = '\0';
if (v.v_type != VSOCK) {
if (pfiles_dig_pathname(top_vnodep, path) == -1)
return (DCMD_ERR);
}
mdb_printf("%s%s", path, path[0] == '\0' ? "" : " ");
switch (v.v_type) {
case VDOOR:
{
door_node_t doornode;
proc_t pr;
if (mdb_vread(&doornode, sizeof (doornode),
(uintptr_t)layer_vn.v_data) == -1) {
mdb_warn("failed to read door_node");
return (DCMD_ERR);
}
if (mdb_vread(&pr, sizeof (pr),
(uintptr_t)doornode.door_target) == -1) {
mdb_warn("failed to read door server process %p",
doornode.door_target);
return (DCMD_ERR);
}
mdb_printf("[door to '%s' (proc=%p)]", pr.p_user.u_comm,
doornode.door_target);
break;
}
case VSOCK:
{
struct sonode sonode;
if (pfiles_get_sonode(realvpp, &sonode) == -1)
return (DCMD_ERR);
/*
* If the address is cached in the sonode, use it; otherwise,
* we print nothing.
*/
if (sonode.so_state & SS_LADDR_VALID) {
struct sockaddr *laddr =
mdb_alloc(sonode.so_laddr_len, UM_SLEEP);
if (mdb_vread(laddr, sonode.so_laddr_len,
(uintptr_t)sonode.so_laddr_sa) == -1) {
mdb_warn("failed to read sonode socket addr");
return (DCMD_ERR);
}
mdb_printf("socket: ");
pfiles_print_addr(laddr);
}
if (sonode.so_state & SS_FADDR_VALID) {
struct sockaddr *faddr =
mdb_alloc(sonode.so_faddr_len, UM_SLEEP);
if (mdb_vread(faddr, sonode.so_faddr_len,
(uintptr_t)sonode.so_faddr_sa) == -1) {
mdb_warn("failed to read sonode remote addr");
return (DCMD_ERR);
}
mdb_printf("remote: ");
pfiles_print_addr(faddr);
}
break;
}
case VPORT:
mdb_printf("[event port (port=%p)]", v.v_data);
break;
case VPROC:
{
prnode_t prnode;
prcommon_t prcommon;
if (mdb_vread(&prnode, sizeof (prnode),
(uintptr_t)layer_vn.v_data) == -1) {
mdb_warn("failed to read prnode");
return (DCMD_ERR);
}
if (mdb_vread(&prcommon, sizeof (prcommon),
(uintptr_t)prnode.pr_common) == -1) {
mdb_warn("failed to read prcommon %p",
prnode.pr_common);
return (DCMD_ERR);
}
mdb_printf("(proc=%p)", prcommon.prc_proc);
break;
}
default:
break;
}
mdb_printf("\n");
return (WALK_NEXT);
}
static int
file_t_callback(uintptr_t addr, const struct file *f, struct pfiles_cbdata *cb)
{
int myfd = cb->fd;
cb->fd++;
if (addr == NULL) {
return (WALK_NEXT);
}
/*
* We really need 20 digits to print a 64-bit offset_t, but this
* is exceedingly rare, so we cheat and assume a column width of 10
* digits, in order to fit everything cleanly into 80 columns.
*/
mdb_printf("%?0p %4d %8x %?0p %10lld %?0p %4d\n",
addr, myfd, f->f_flag, f->f_vnode, f->f_offset, f->f_cred,
f->f_count);
return (WALK_NEXT);
}
int
pfiles(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
int opt_f = 0;
struct pfiles_cbdata cb;
bzero(&cb, sizeof (cb));
if (!(flags & DCMD_ADDRSPEC))
return (DCMD_USAGE);
if (mdb_getopts(argc, argv,
'p', MDB_OPT_SETBITS, TRUE, &cb.opt_p,
'f', MDB_OPT_SETBITS, TRUE, &opt_f, NULL) != argc)
return (DCMD_USAGE);
if (opt_f) {
mdb_printf("%<u>%?s %4s %8s %?s %10s %?s %4s%</u>\n", "FILE",
"FD", "FLAG", "VNODE", "OFFSET", "CRED", "CNT");
if (mdb_pwalk("allfile", (mdb_walk_cb_t)file_t_callback, &cb,
addr) == -1) {
mdb_warn("failed to walk 'allfile'");
return (DCMD_ERR);
}
} else {
mdb_printf("%<u>%-4s %4s %?s ", "FD", "TYPE", "VNODE");
if (cb.opt_p)
mdb_printf("PATH");
else
mdb_printf("INFO");
mdb_printf("%</u>\n");
if (mdb_pwalk("allfile", (mdb_walk_cb_t)pfile_callback, &cb,
addr) == -1) {
mdb_warn("failed to walk 'allfile'");
return (DCMD_ERR);
}
}
return (DCMD_OK);
}
void
pfiles_help(void)
{
mdb_printf(
"Given the address of a process, print information about files\n"
"which the process has open. By default, this includes decoded\n"
"information about the file depending on file and filesystem type\n"
"\n"
"\t-p\tPathnames; omit decoded information. Only display "
"pathnames\n"
"\t-f\tfile_t view; show the file_t structure corresponding to "
"the fd\n");
}
|