xref: /illumos-gate/usr/src/cmd/truss/stat.c (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 #define	_SYSCALL32
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/signal.h>
38 #include <sys/fault.h>
39 #include <sys/syscall.h>
40 #include <libproc.h>
41 #include "ramdata.h"
42 #include "proto.h"
43 
44 void	show_stat32(private_t *, long);
45 void	show_stat64(private_t *, long);
46 
47 void
48 show_stat(private_t *pri, long offset)
49 {
50 	if (data_model == PR_MODEL_LP64)
51 		show_stat64(pri, offset);
52 	else
53 		show_stat32(pri, offset);
54 }
55 
56 void
57 show_stat32(private_t *pri, long offset)
58 {
59 	struct stat32 statb;
60 	timestruc_t ts;
61 
62 	if (offset != 0 &&
63 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
64 		(void) printf(
65 		    "%s    d=0x%.8X i=%-5u m=0%.6o l=%-2u u=%-5u g=%-5u",
66 		    pri->pname,
67 		    statb.st_dev,
68 		    statb.st_ino,
69 		    statb.st_mode,
70 		    statb.st_nlink,
71 		    statb.st_uid,
72 		    statb.st_gid);
73 
74 		switch (statb.st_mode & S_IFMT) {
75 		case S_IFCHR:
76 		case S_IFBLK:
77 			(void) printf(" rdev=0x%.8X\n", statb.st_rdev);
78 			break;
79 		default:
80 			(void) printf(" sz=%u\n", statb.st_size);
81 			break;
82 		}
83 
84 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_atim);
85 		prtimestruc(pri, "at = ", &ts);
86 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_mtim);
87 		prtimestruc(pri, "mt = ", &ts);
88 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_ctim);
89 		prtimestruc(pri, "ct = ", &ts);
90 
91 		(void) printf(
92 		    "%s    bsz=%-5d blks=%-5d fs=%.*s\n",
93 		    pri->pname,
94 		    statb.st_blksize,
95 		    statb.st_blocks,
96 		    _ST_FSTYPSZ,
97 		    statb.st_fstype);
98 	}
99 }
100 
101 void
102 show_stat64_32(private_t *pri, long offset)
103 {
104 	struct stat64_32 statb;
105 	timestruc_t ts;
106 
107 	if (offset != 0 &&
108 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
109 		(void) printf(
110 		    "%s    d=0x%.8X i=%-5llu m=0%.6o l=%-2u u=%-5u g=%-5u",
111 		    pri->pname,
112 		    statb.st_dev,
113 		    (u_longlong_t)statb.st_ino,
114 		    statb.st_mode,
115 		    statb.st_nlink,
116 		    statb.st_uid,
117 		    statb.st_gid);
118 
119 		switch (statb.st_mode & S_IFMT) {
120 		case S_IFCHR:
121 		case S_IFBLK:
122 			(void) printf(" rdev=0x%.8X\n", statb.st_rdev);
123 			break;
124 		default:
125 			(void) printf(" sz=%llu\n", (long long)statb.st_size);
126 			break;
127 		}
128 
129 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_atim);
130 		prtimestruc(pri, "at = ", &ts);
131 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_mtim);
132 		prtimestruc(pri, "mt = ", &ts);
133 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_ctim);
134 		prtimestruc(pri, "ct = ", &ts);
135 
136 		(void) printf("%s    bsz=%-5d blks=%-5lld fs=%.*s\n",
137 		    pri->pname,
138 		    statb.st_blksize,
139 		    (longlong_t)statb.st_blocks,
140 		    _ST_FSTYPSZ,
141 		    statb.st_fstype);
142 	}
143 }
144 
145 void
146 show_stat64(private_t *pri, long offset)
147 {
148 	struct stat64 statb;
149 
150 	if (offset != 0 &&
151 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
152 		(void) printf(
153 		    "%s    d=0x%.16lX i=%-5lu m=0%.6o l=%-2u u=%-5u g=%-5u",
154 		    pri->pname,
155 		    statb.st_dev,
156 		    statb.st_ino,
157 		    statb.st_mode,
158 		    statb.st_nlink,
159 		    statb.st_uid,
160 		    statb.st_gid);
161 
162 		switch (statb.st_mode & S_IFMT) {
163 		case S_IFCHR:
164 		case S_IFBLK:
165 			(void) printf(" rdev=0x%.16lX\n", statb.st_rdev);
166 			break;
167 		default:
168 			(void) printf(" sz=%lu\n", statb.st_size);
169 			break;
170 		}
171 
172 		prtimestruc(pri, "at = ", (timestruc_t *)&statb.st_atim);
173 		prtimestruc(pri, "mt = ", (timestruc_t *)&statb.st_mtim);
174 		prtimestruc(pri, "ct = ", (timestruc_t *)&statb.st_ctim);
175 
176 		(void) printf(
177 		    "%s    bsz=%-5d blks=%-5ld fs=%.*s\n",
178 		    pri->pname,
179 		    statb.st_blksize,
180 		    statb.st_blocks,
181 		    _ST_FSTYPSZ,
182 		    statb.st_fstype);
183 	}
184 }
185