Home | History | Annotate | Download | only in truss
      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, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 2005 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 
     31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
     32 
     33 #define	_SYSCALL32
     34 
     35 #include <stdio.h>
     36 #include <stdlib.h>
     37 #include <unistd.h>
     38 #include <sys/types.h>
     39 #include <sys/stat.h>
     40 #include <sys/signal.h>
     41 #include <sys/fault.h>
     42 #include <sys/syscall.h>
     43 #include <libproc.h>
     44 #include "ramdata.h"
     45 #include "proto.h"
     46 
     47 void	show_stat32(private_t *, long);
     48 #ifdef _LP64
     49 void	show_stat64(private_t *, long);
     50 #endif
     51 
     52 #if defined(i386) && defined(_STAT_VER)
     53 
     54 /*
     55  * Old SVR3 stat structure.
     56  */
     57 struct	o_stat {
     58 	o_dev_t	st_dev;
     59 	o_ino_t	st_ino;
     60 	o_mode_t st_mode;
     61 	o_nlink_t st_nlink;
     62 	o_uid_t st_uid;
     63 	o_gid_t st_gid;
     64 	o_dev_t	st_rdev;
     65 	off32_t	st_size;
     66 	time_t st_atim;
     67 	time_t st_mtim;
     68 	time_t st_ctim;
     69 };
     70 
     71 void
     72 show_o_stat(private_t *pri, long offset)
     73 {
     74 	struct o_stat statb;
     75 	timestruc_t ts;
     76 
     77 	if (offset != NULL &&
     78 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
     79 		(void) printf(
     80 		    "%s    d=0x%.8X i=%-5u m=0%.6o l=%-2u u=%-5u g=%-5u",
     81 		    pri->pname,
     82 		    statb.st_dev & 0xffff,
     83 		    statb.st_ino,
     84 		    statb.st_mode,
     85 		    statb.st_nlink % 0xffff,
     86 		    statb.st_uid,
     87 		    statb.st_gid);
     88 
     89 		switch (statb.st_mode & S_IFMT) {
     90 		case S_IFCHR:
     91 		case S_IFBLK:
     92 			(void) printf(" rdev=0x%.4X\n", statb.st_rdev & 0xffff);
     93 			break;
     94 		default:
     95 			(void) printf(" sz=%u\n", (uint32_t)statb.st_size);
     96 			break;
     97 		}
     98 
     99 		ts.tv_nsec = 0;
    100 		ts.tv_sec = statb.st_atim;
    101 		prtimestruc(pri, "at = ", &ts);
    102 		ts.tv_sec = statb.st_atim;
    103 		prtimestruc(pri, "mt = ", &ts);
    104 		ts.tv_sec = statb.st_atim;
    105 		prtimestruc(pri, "ct = ", &ts);
    106 	}
    107 }
    108 
    109 void
    110 show_stat(private_t *pri, long offset)
    111 {
    112 	show_o_stat(pri, offset);
    113 }
    114 
    115 void
    116 show_xstat(private_t *pri, int version, long offset)
    117 {
    118 	switch (version) {
    119 	case _R3_STAT_VER:
    120 		show_o_stat(pri, offset);
    121 		break;
    122 	case _STAT_VER:
    123 		show_stat32(pri, offset);
    124 		break;
    125 	}
    126 }
    127 
    128 void
    129 show_statat(private_t *pri, long offset)
    130 {
    131 #ifdef _LP64
    132 	if (data_model == PR_MODEL_LP64)
    133 		show_stat64(pri, offset);
    134 	else
    135 		show_stat32(pri, offset);
    136 #else
    137 	show_stat32(pri, offset);
    138 #endif
    139 }
    140 
    141 #else
    142 
    143 void
    144 show_stat(private_t *pri, long offset)
    145 {
    146 #ifdef _LP64
    147 	if (data_model == PR_MODEL_LP64)
    148 		show_stat64(pri, offset);
    149 	else
    150 		show_stat32(pri, offset);
    151 #else
    152 	show_stat32(pri, offset);
    153 #endif
    154 }
    155 
    156 void
    157 show_statat(private_t *pri, long offset)
    158 {
    159 	show_stat(pri, offset);
    160 }
    161 
    162 /* ARGSUSED */
    163 void
    164 show_xstat(private_t *pri, int version, long offset)
    165 {
    166 	show_stat(pri, offset);
    167 }
    168 
    169 #endif
    170 
    171 void
    172 show_stat32(private_t *pri, long offset)
    173 {
    174 	struct stat32 statb;
    175 	timestruc_t ts;
    176 
    177 	if (offset != NULL &&
    178 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
    179 		(void) printf(
    180 		    "%s    d=0x%.8X i=%-5u m=0%.6o l=%-2u u=%-5u g=%-5u",
    181 		    pri->pname,
    182 		    statb.st_dev,
    183 		    statb.st_ino,
    184 		    statb.st_mode,
    185 		    statb.st_nlink,
    186 		    statb.st_uid,
    187 		    statb.st_gid);
    188 
    189 		switch (statb.st_mode & S_IFMT) {
    190 		case S_IFCHR:
    191 		case S_IFBLK:
    192 			(void) printf(" rdev=0x%.8X\n", statb.st_rdev);
    193 			break;
    194 		default:
    195 			(void) printf(" sz=%u\n", statb.st_size);
    196 			break;
    197 		}
    198 
    199 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_atim);
    200 		prtimestruc(pri, "at = ", &ts);
    201 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_mtim);
    202 		prtimestruc(pri, "mt = ", &ts);
    203 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_ctim);
    204 		prtimestruc(pri, "ct = ", &ts);
    205 
    206 		(void) printf(
    207 		    "%s    bsz=%-5d blks=%-5d fs=%.*s\n",
    208 		    pri->pname,
    209 		    statb.st_blksize,
    210 		    statb.st_blocks,
    211 		    _ST_FSTYPSZ,
    212 		    statb.st_fstype);
    213 	}
    214 }
    215 
    216 void
    217 show_stat64_32(private_t *pri, long offset)
    218 {
    219 	struct stat64_32 statb;
    220 	timestruc_t ts;
    221 
    222 	if (offset != NULL &&
    223 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
    224 		(void) printf(
    225 		    "%s    d=0x%.8X i=%-5llu m=0%.6o l=%-2u u=%-5u g=%-5u",
    226 		    pri->pname,
    227 		    statb.st_dev,
    228 		    (u_longlong_t)statb.st_ino,
    229 		    statb.st_mode,
    230 		    statb.st_nlink,
    231 		    statb.st_uid,
    232 		    statb.st_gid);
    233 
    234 		switch (statb.st_mode & S_IFMT) {
    235 		case S_IFCHR:
    236 		case S_IFBLK:
    237 			(void) printf(" rdev=0x%.8X\n", statb.st_rdev);
    238 			break;
    239 		default:
    240 			(void) printf(" sz=%llu\n", (long long)statb.st_size);
    241 			break;
    242 		}
    243 
    244 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_atim);
    245 		prtimestruc(pri, "at = ", &ts);
    246 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_mtim);
    247 		prtimestruc(pri, "mt = ", &ts);
    248 		TIMESPEC32_TO_TIMESPEC(&ts, &statb.st_ctim);
    249 		prtimestruc(pri, "ct = ", &ts);
    250 
    251 		(void) printf("%s    bsz=%-5d blks=%-5lld fs=%.*s\n",
    252 		    pri->pname,
    253 		    statb.st_blksize,
    254 		    (longlong_t)statb.st_blocks,
    255 		    _ST_FSTYPSZ,
    256 		    statb.st_fstype);
    257 	}
    258 }
    259 
    260 #ifdef _LP64
    261 void
    262 show_stat64(private_t *pri, long offset)
    263 {
    264 	struct stat64 statb;
    265 
    266 	if (offset != NULL &&
    267 	    Pread(Proc, &statb, sizeof (statb), offset) == sizeof (statb)) {
    268 		(void) printf(
    269 		    "%s    d=0x%.16lX i=%-5lu m=0%.6o l=%-2u u=%-5u g=%-5u",
    270 		    pri->pname,
    271 		    statb.st_dev,
    272 		    statb.st_ino,
    273 		    statb.st_mode,
    274 		    statb.st_nlink,
    275 		    statb.st_uid,
    276 		    statb.st_gid);
    277 
    278 		switch (statb.st_mode & S_IFMT) {
    279 		case S_IFCHR:
    280 		case S_IFBLK:
    281 			(void) printf(" rdev=0x%.16lX\n", statb.st_rdev);
    282 			break;
    283 		default:
    284 			(void) printf(" sz=%lu\n", statb.st_size);
    285 			break;
    286 		}
    287 
    288 		prtimestruc(pri, "at = ", (timestruc_t *)&statb.st_atim);
    289 		prtimestruc(pri, "mt = ", (timestruc_t *)&statb.st_mtim);
    290 		prtimestruc(pri, "ct = ", (timestruc_t *)&statb.st_ctim);
    291 
    292 		(void) printf(
    293 		    "%s    bsz=%-5d blks=%-5ld fs=%.*s\n",
    294 		    pri->pname,
    295 		    statb.st_blksize,
    296 		    statb.st_blocks,
    297 		    _ST_FSTYPSZ,
    298 		    statb.st_fstype);
    299 	}
    300 }
    301 #endif	/* _LP64 */
    302