Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * $Id$ |
| 30 | */ |
| 31 | |
| 32 | #include "defs.h" |
| 33 | |
| 34 | #include <dirent.h> |
| 35 | |
Wichert Akkerman | 8bc6cfd | 1999-04-21 15:57:38 +0000 | [diff] [blame] | 36 | #ifdef linux |
Wichert Akkerman | d4d8e92 | 1999-04-18 23:30:29 +0000 | [diff] [blame] | 37 | # include <asm/stat.h> |
| 38 | # define stat libc_stat |
| 39 | # include <sys/stat.h> |
| 40 | # undef stat |
Wichert Akkerman | d4d8e92 | 1999-04-18 23:30:29 +0000 | [diff] [blame] | 41 | #else |
| 42 | # include <sys/stat.h> |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 43 | #endif |
Wichert Akkerman | d4d8e92 | 1999-04-18 23:30:29 +0000 | [diff] [blame] | 44 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 45 | #include <fcntl.h> |
| 46 | |
| 47 | #ifdef SVR4 |
| 48 | # include <sys/cred.h> |
| 49 | #endif /* SVR4 */ |
| 50 | |
| 51 | #include <sys/vfs.h> |
| 52 | |
| 53 | #ifdef MAJOR_IN_SYSMACROS |
| 54 | #include <sys/sysmacros.h> |
| 55 | #endif |
| 56 | |
| 57 | #ifdef MAJOR_IN_MKDEV |
| 58 | #include <sys/mkdev.h> |
| 59 | #endif |
| 60 | |
| 61 | #ifdef HAVE_SYS_ASYNCH_H |
| 62 | #include <sys/asynch.h> |
| 63 | #endif |
| 64 | |
| 65 | #ifdef SUNOS4 |
| 66 | #include <ustat.h> |
| 67 | #endif |
| 68 | |
| 69 | /* |
| 70 | * This is a really dirty trick but it should always work. Traditional |
| 71 | * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by |
| 72 | * adding 1. Just remember to add 1 to any arg decoded with openmodes. |
| 73 | */ |
| 74 | struct xlat openmodes[] = { |
| 75 | { O_RDWR+1, "O_RDWR" }, |
| 76 | { O_RDONLY+1, "O_RDONLY" }, |
| 77 | { O_WRONLY+1, "O_WRONLY" }, |
| 78 | { O_NONBLOCK, "O_NONBLOCK" }, |
| 79 | { O_APPEND, "O_APPEND" }, |
| 80 | { O_CREAT, "O_CREAT" }, |
| 81 | { O_TRUNC, "O_TRUNC" }, |
| 82 | { O_EXCL, "O_EXCL" }, |
| 83 | { O_NOCTTY, "O_NOCTTY" }, |
| 84 | #ifdef O_SYNC |
| 85 | { O_SYNC, "O_SYNC" }, |
| 86 | #endif |
| 87 | #ifdef O_ASYNC |
| 88 | { O_ASYNC, "O_ASYNC" }, |
| 89 | #endif |
| 90 | #ifdef O_DSYNC |
| 91 | { O_DSYNC, "O_DSYNC" }, |
| 92 | #endif |
| 93 | #ifdef O_RSYNC |
| 94 | { O_RSYNC, "O_RSYNC" }, |
| 95 | #endif |
| 96 | #ifdef O_NDELAY |
| 97 | { O_NDELAY, "O_NDELAY" }, |
| 98 | #endif |
| 99 | #ifdef O_PRIV |
| 100 | { O_PRIV, "O_PRIV" }, |
| 101 | #endif |
| 102 | #ifdef O_DIRECT |
| 103 | { O_DIRECT, "O_DIRECT" }, |
| 104 | #endif |
| 105 | #ifdef O_LARGEFILE |
| 106 | { O_LARGEFILE, "O_LARGEFILE" }, |
| 107 | #endif |
| 108 | #ifdef O_DIRECTORY |
| 109 | { O_DIRECTORY, "O_DIRECTORY" }, |
| 110 | #endif |
| 111 | |
| 112 | #ifdef FNDELAY |
| 113 | { FNDELAY, "FNDELAY" }, |
| 114 | #endif |
| 115 | #ifdef FAPPEND |
| 116 | { FAPPEND, "FAPPEND" }, |
| 117 | #endif |
| 118 | #ifdef FMARK |
| 119 | { FMARK, "FMARK" }, |
| 120 | #endif |
| 121 | #ifdef FDEFER |
| 122 | { FDEFER, "FDEFER" }, |
| 123 | #endif |
| 124 | #ifdef FASYNC |
| 125 | { FASYNC, "FASYNC" }, |
| 126 | #endif |
| 127 | #ifdef FSHLOCK |
| 128 | { FSHLOCK, "FSHLOCK" }, |
| 129 | #endif |
| 130 | #ifdef FEXLOCK |
| 131 | { FEXLOCK, "FEXLOCK" }, |
| 132 | #endif |
| 133 | #ifdef FCREAT |
| 134 | { FCREAT, "FCREAT" }, |
| 135 | #endif |
| 136 | #ifdef FTRUNC |
| 137 | { FTRUNC, "FTRUNC" }, |
| 138 | #endif |
| 139 | #ifdef FEXCL |
| 140 | { FEXCL, "FEXCL" }, |
| 141 | #endif |
| 142 | #ifdef FNBIO |
| 143 | { FNBIO, "FNBIO" }, |
| 144 | #endif |
| 145 | #ifdef FSYNC |
| 146 | { FSYNC, "FSYNC" }, |
| 147 | #endif |
| 148 | #ifdef FNOCTTY |
| 149 | { FNOCTTY, "FNOCTTY" }, |
| 150 | #endif |
| 151 | { 0, NULL }, |
| 152 | }; |
| 153 | |
| 154 | int |
| 155 | sys_open(tcp) |
| 156 | struct tcb *tcp; |
| 157 | { |
| 158 | if (entering(tcp)) { |
| 159 | printpath(tcp, tcp->u_arg[0]); |
| 160 | tprintf(", "); |
| 161 | /* flags */ |
| 162 | printflags(openmodes, tcp->u_arg[1] + 1); |
| 163 | if (tcp->u_arg[1] & O_CREAT) { |
| 164 | /* mode */ |
| 165 | tprintf(", %#lo", tcp->u_arg[2]); |
| 166 | } |
| 167 | } |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | #ifdef LINUXSPARC |
| 172 | struct xlat openmodessol[] = { |
| 173 | { 0, "O_RDWR" }, |
| 174 | { 1, "O_RDONLY" }, |
| 175 | { 2, "O_WRONLY" }, |
| 176 | { 0x80, "O_NONBLOCK" }, |
| 177 | { 8, "O_APPEND" }, |
| 178 | { 0x100, "O_CREAT" }, |
| 179 | { 0x200, "O_TRUNC" }, |
| 180 | { 0x400, "O_EXCL" }, |
| 181 | { 0x800, "O_NOCTTY" }, |
| 182 | { 0x10, "O_SYNC" }, |
| 183 | { 0x40, "O_DSYNC" }, |
| 184 | { 0x8000, "O_RSYNC" }, |
| 185 | { 4, "O_NDELAY" }, |
| 186 | { 0x1000, "O_PRIV" }, |
| 187 | { 0, NULL }, |
| 188 | }; |
| 189 | |
| 190 | int |
| 191 | solaris_open(tcp) |
| 192 | struct tcb *tcp; |
| 193 | { |
| 194 | if (entering(tcp)) { |
| 195 | printpath(tcp, tcp->u_arg[0]); |
| 196 | tprintf(", "); |
| 197 | /* flags */ |
| 198 | printflags(openmodessol, tcp->u_arg[1] + 1); |
| 199 | if (tcp->u_arg[1] & 0x100) { |
| 200 | /* mode */ |
| 201 | tprintf(", %#lo", tcp->u_arg[2]); |
| 202 | } |
| 203 | } |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | #endif |
| 208 | |
| 209 | int |
| 210 | sys_creat(tcp) |
| 211 | struct tcb *tcp; |
| 212 | { |
| 213 | if (entering(tcp)) { |
| 214 | printpath(tcp, tcp->u_arg[0]); |
| 215 | tprintf(", %#lo", tcp->u_arg[1]); |
| 216 | } |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static struct xlat access_flags[] = { |
| 221 | { F_OK, "F_OK", }, |
| 222 | { R_OK, "R_OK" }, |
| 223 | { W_OK, "W_OK" }, |
| 224 | { X_OK, "X_OK" }, |
| 225 | #ifdef EFF_ONLY_OK |
| 226 | { EFF_ONLY_OK, "EFF_ONLY_OK" }, |
| 227 | #endif |
| 228 | #ifdef EX_OK |
| 229 | { EX_OK, "EX_OK" }, |
| 230 | #endif |
| 231 | { 0, NULL }, |
| 232 | }; |
| 233 | |
| 234 | int |
| 235 | sys_access(tcp) |
| 236 | struct tcb *tcp; |
| 237 | { |
| 238 | if (entering(tcp)) { |
| 239 | printpath(tcp, tcp->u_arg[0]); |
| 240 | tprintf(", "); |
| 241 | printflags(access_flags, tcp->u_arg[1]); |
| 242 | } |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | int |
| 247 | sys_umask(tcp) |
| 248 | struct tcb *tcp; |
| 249 | { |
| 250 | if (entering(tcp)) { |
| 251 | tprintf("%#lo", tcp->u_arg[0]); |
| 252 | } |
| 253 | return RVAL_OCTAL; |
| 254 | } |
| 255 | |
| 256 | static struct xlat whence[] = { |
| 257 | { SEEK_SET, "SEEK_SET" }, |
| 258 | { SEEK_CUR, "SEEK_CUR" }, |
| 259 | { SEEK_END, "SEEK_END" }, |
| 260 | { 0, NULL }, |
| 261 | }; |
| 262 | |
| 263 | int |
| 264 | sys_lseek(tcp) |
| 265 | struct tcb *tcp; |
| 266 | { |
| 267 | if (entering(tcp)) { |
| 268 | tprintf("%ld, ", tcp->u_arg[0]); |
| 269 | if (tcp->u_arg[2] == SEEK_SET) |
| 270 | tprintf("%lu, ", tcp->u_arg[1]); |
| 271 | else |
| 272 | tprintf("%ld, ", tcp->u_arg[1]); |
| 273 | printxval(whence, tcp->u_arg[2], "SEEK_???"); |
| 274 | } |
| 275 | return RVAL_UDECIMAL; |
| 276 | } |
| 277 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 278 | #ifdef linux |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 279 | int |
| 280 | sys_llseek (tcp) |
| 281 | struct tcb *tcp; |
| 282 | { |
| 283 | if (entering(tcp)) { |
| 284 | if (tcp->u_arg[4] == SEEK_SET) |
| 285 | tprintf("%ld, %llu, ", tcp->u_arg[0], |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 286 | (((long long int) tcp->u_arg[1]) << 32 |
| 287 | | (unsigned long long) tcp->u_arg[2])); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 288 | else |
| 289 | tprintf("%ld, %lld, ", tcp->u_arg[0], |
| 290 | (((long long int) tcp->u_arg[1]) << 32 |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 291 | | (unsigned long long) tcp->u_arg[2])); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 292 | } |
| 293 | else { |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 294 | long long int off; |
| 295 | if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 296 | tprintf("%#lx, ", tcp->u_arg[3]); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 297 | else |
| 298 | tprintf("[%llu], ", off); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 299 | printxval(whence, tcp->u_arg[4], "SEEK_???"); |
| 300 | } |
| 301 | return 0; |
| 302 | } |
| 303 | #endif |
| 304 | |
| 305 | int |
| 306 | sys_truncate(tcp) |
| 307 | struct tcb *tcp; |
| 308 | { |
| 309 | if (entering(tcp)) { |
| 310 | printpath(tcp, tcp->u_arg[0]); |
| 311 | tprintf(", %lu", tcp->u_arg[1]); |
| 312 | } |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | int |
| 317 | sys_ftruncate(tcp) |
| 318 | struct tcb *tcp; |
| 319 | { |
| 320 | if (entering(tcp)) { |
| 321 | tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]); |
| 322 | } |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /* several stats */ |
| 327 | |
| 328 | static struct xlat modetypes[] = { |
| 329 | { S_IFREG, "S_IFREG" }, |
| 330 | { S_IFSOCK, "S_IFSOCK" }, |
| 331 | { S_IFIFO, "S_IFIFO" }, |
| 332 | { S_IFLNK, "S_IFLNK" }, |
| 333 | { S_IFDIR, "S_IFDIR" }, |
| 334 | { S_IFBLK, "S_IFBLK" }, |
| 335 | { S_IFCHR, "S_IFCHR" }, |
| 336 | { 0, NULL }, |
| 337 | }; |
| 338 | |
| 339 | static char * |
| 340 | sprintmode(mode) |
| 341 | int mode; |
| 342 | { |
| 343 | static char buf[64]; |
| 344 | char *s; |
| 345 | |
| 346 | if ((mode & S_IFMT) == 0) |
| 347 | s = ""; |
| 348 | else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) { |
| 349 | sprintf(buf, "%#o", mode); |
| 350 | return buf; |
| 351 | } |
| 352 | sprintf(buf, "%s%s%s%s", s, |
| 353 | (mode & S_ISUID) ? "|S_ISUID" : "", |
| 354 | (mode & S_ISGID) ? "|S_ISGID" : "", |
| 355 | (mode & S_ISVTX) ? "|S_ISVTX" : ""); |
| 356 | mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX); |
| 357 | if (mode) |
| 358 | sprintf(buf + strlen(buf), "|%#o", mode); |
| 359 | s = (*buf == '|') ? buf + 1 : buf; |
| 360 | return *s ? s : "0"; |
| 361 | } |
| 362 | |
| 363 | static char * |
| 364 | sprinttime(t) |
| 365 | time_t t; |
| 366 | { |
| 367 | struct tm *tmp; |
| 368 | static char buf[32]; |
| 369 | |
| 370 | if (t == 0) { |
| 371 | sprintf(buf, "0"); |
| 372 | return buf; |
| 373 | } |
| 374 | tmp = localtime(&t); |
| 375 | sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d", |
| 376 | tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday, |
| 377 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); |
| 378 | return buf; |
| 379 | } |
| 380 | |
| 381 | #ifdef LINUXSPARC |
| 382 | typedef struct { |
| 383 | int tv_sec; |
| 384 | int tv_nsec; |
| 385 | } timestruct_t; |
| 386 | |
| 387 | struct solstat { |
| 388 | unsigned st_dev; |
| 389 | int st_pad1[3]; /* network id */ |
| 390 | unsigned st_ino; |
| 391 | unsigned st_mode; |
| 392 | unsigned st_nlink; |
| 393 | unsigned st_uid; |
| 394 | unsigned st_gid; |
| 395 | unsigned st_rdev; |
| 396 | int st_pad2[2]; |
| 397 | int st_size; |
| 398 | int st_pad3; /* st_size, off_t expansion */ |
| 399 | timestruct_t st_atime; |
| 400 | timestruct_t st_mtime; |
| 401 | timestruct_t st_ctime; |
| 402 | int st_blksize; |
| 403 | int st_blocks; |
| 404 | char st_fstype[16]; |
| 405 | int st_pad4[8]; /* expansion area */ |
| 406 | }; |
| 407 | |
| 408 | static void |
| 409 | printstatsol(tcp, addr) |
| 410 | struct tcb *tcp; |
| 411 | int addr; |
| 412 | { |
| 413 | struct solstat statbuf; |
| 414 | |
| 415 | if (!addr) { |
| 416 | tprintf("NULL"); |
| 417 | return; |
| 418 | } |
| 419 | if (syserror(tcp) || !verbose(tcp)) { |
| 420 | tprintf("%#x", addr); |
| 421 | return; |
| 422 | } |
| 423 | if (umove(tcp, addr, &statbuf) < 0) { |
| 424 | tprintf("{...}"); |
| 425 | return; |
| 426 | } |
| 427 | if (!abbrev(tcp)) { |
| 428 | tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", |
| 429 | (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff), |
| 430 | (unsigned long) (statbuf.st_dev & 0x3ffff), |
| 431 | (unsigned long) statbuf.st_ino, |
| 432 | sprintmode(statbuf.st_mode)); |
| 433 | tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", |
| 434 | (unsigned long) statbuf.st_nlink, |
| 435 | (unsigned long) statbuf.st_uid, |
| 436 | (unsigned long) statbuf.st_gid); |
| 437 | tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize); |
| 438 | tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks); |
| 439 | } |
| 440 | else |
| 441 | tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); |
| 442 | switch (statbuf.st_mode & S_IFMT) { |
| 443 | case S_IFCHR: case S_IFBLK: |
| 444 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 445 | (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff), |
| 446 | (unsigned long) (statbuf.st_rdev & 0x3ffff)); |
| 447 | break; |
| 448 | default: |
| 449 | tprintf("st_size=%u, ", statbuf.st_size); |
| 450 | break; |
| 451 | } |
| 452 | if (!abbrev(tcp)) { |
| 453 | tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); |
| 454 | tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); |
| 455 | tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime)); |
| 456 | } |
| 457 | else |
| 458 | tprintf("...}"); |
| 459 | } |
Wichert Akkerman | b859bea | 1999-04-18 22:50:50 +0000 | [diff] [blame] | 460 | #endif /* LINUXSPARC */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 461 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 462 | static void |
| 463 | realprintstat(tcp, statbuf) |
| 464 | struct tcb *tcp; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 465 | struct stat *statbuf; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 466 | { |
| 467 | if (!abbrev(tcp)) { |
| 468 | tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", |
| 469 | (unsigned long) major(statbuf->st_dev), |
| 470 | (unsigned long) minor(statbuf->st_dev), |
| 471 | (unsigned long) statbuf->st_ino, |
| 472 | sprintmode(statbuf->st_mode)); |
| 473 | tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", |
| 474 | (unsigned long) statbuf->st_nlink, |
| 475 | (unsigned long) statbuf->st_uid, |
| 476 | (unsigned long) statbuf->st_gid); |
| 477 | #ifdef HAVE_ST_BLKSIZE |
| 478 | tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize); |
| 479 | #endif /* HAVE_ST_BLKSIZE */ |
| 480 | #ifdef HAVE_ST_BLOCKS |
| 481 | tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks); |
| 482 | #endif /* HAVE_ST_BLOCKS */ |
| 483 | } |
| 484 | else |
| 485 | tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode)); |
| 486 | switch (statbuf->st_mode & S_IFMT) { |
| 487 | case S_IFCHR: case S_IFBLK: |
| 488 | #ifdef HAVE_ST_RDEV |
| 489 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 490 | (unsigned long) major(statbuf->st_rdev), |
| 491 | (unsigned long) minor(statbuf->st_rdev)); |
| 492 | #else /* !HAVE_ST_RDEV */ |
| 493 | tprintf("st_size=makedev(%lu, %lu), ", |
| 494 | (unsigned long) major(statbuf->st_size), |
| 495 | (unsigned long) minor(statbuf->st_size)); |
| 496 | #endif /* !HAVE_ST_RDEV */ |
| 497 | break; |
| 498 | default: |
| 499 | tprintf("st_size=%lu, ", statbuf->st_size); |
| 500 | break; |
| 501 | } |
| 502 | if (!abbrev(tcp)) { |
| 503 | tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime)); |
| 504 | tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime)); |
| 505 | tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime)); |
| 506 | } |
| 507 | else |
| 508 | tprintf("...}"); |
| 509 | } |
| 510 | |
Nate Sammons | 771a6ff | 1999-04-05 22:39:31 +0000 | [diff] [blame] | 511 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 512 | static void |
| 513 | printstat(tcp, addr) |
| 514 | struct tcb *tcp; |
| 515 | int addr; |
| 516 | { |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 517 | struct stat statbuf; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 518 | |
| 519 | #ifdef LINUXSPARC |
| 520 | if (current_personality == 1) { |
| 521 | printstatsol(tcp, addr); |
| 522 | return; |
| 523 | } |
| 524 | #endif /* LINUXSPARC */ |
| 525 | |
| 526 | if (!addr) { |
| 527 | tprintf("NULL"); |
| 528 | return; |
| 529 | } |
| 530 | if (syserror(tcp) || !verbose(tcp)) { |
| 531 | tprintf("%#x", addr); |
| 532 | return; |
| 533 | } |
| 534 | if (umove(tcp, addr, &statbuf) < 0) { |
| 535 | tprintf("{...}"); |
| 536 | return; |
| 537 | } |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 538 | |
| 539 | realprintstat(tcp, &statbuf); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 542 | #ifdef linux |
| 543 | static void |
| 544 | convertoldstat(oldbuf, newbuf) |
Wichert Akkerman | 25d0c4f | 1999-04-18 19:35:42 +0000 | [diff] [blame] | 545 | const struct __old_kernel_stat *oldbuf; |
| 546 | struct stat *newbuf; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 547 | { |
| 548 | newbuf->st_dev=oldbuf->st_dev; |
| 549 | newbuf->st_ino=oldbuf->st_ino; |
| 550 | newbuf->st_mode=oldbuf->st_mode; |
| 551 | newbuf->st_nlink=oldbuf->st_nlink; |
| 552 | newbuf->st_uid=oldbuf->st_uid; |
| 553 | newbuf->st_gid=oldbuf->st_gid; |
| 554 | newbuf->st_rdev=oldbuf->st_rdev; |
| 555 | newbuf->st_size=oldbuf->st_size; |
| 556 | newbuf->st_atime=oldbuf->st_atime; |
| 557 | newbuf->st_mtime=oldbuf->st_mtime; |
| 558 | newbuf->st_ctime=oldbuf->st_ctime; |
| 559 | newbuf->st_blksize=0; /* not supported in old_stat */ |
| 560 | newbuf->st_blocks=0; /* not supported in old_stat */ |
| 561 | } |
| 562 | #endif |
| 563 | |
| 564 | |
| 565 | #ifdef linux |
| 566 | static void |
| 567 | printoldstat(tcp, addr) |
| 568 | struct tcb *tcp; |
| 569 | int addr; |
| 570 | { |
Wichert Akkerman | 25d0c4f | 1999-04-18 19:35:42 +0000 | [diff] [blame] | 571 | struct __old_kernel_stat statbuf; |
| 572 | struct stat newstatbuf; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 573 | |
| 574 | #ifdef LINUXSPARC |
| 575 | if (current_personality == 1) { |
| 576 | printstatsol(tcp, addr); |
| 577 | return; |
| 578 | } |
| 579 | #endif /* LINUXSPARC */ |
| 580 | |
| 581 | if (!addr) { |
| 582 | tprintf("NULL"); |
| 583 | return; |
| 584 | } |
| 585 | if (syserror(tcp) || !verbose(tcp)) { |
| 586 | tprintf("%#x", addr); |
| 587 | return; |
| 588 | } |
| 589 | if (umove(tcp, addr, &statbuf) < 0) { |
| 590 | tprintf("{...}"); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | convertoldstat(&statbuf, &newstatbuf); |
| 595 | realprintstat(tcp, &newstatbuf); |
| 596 | } |
| 597 | #endif |
| 598 | |
| 599 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 600 | int |
| 601 | sys_stat(tcp) |
| 602 | struct tcb *tcp; |
| 603 | { |
| 604 | if (entering(tcp)) { |
| 605 | printpath(tcp, tcp->u_arg[0]); |
| 606 | tprintf(", "); |
| 607 | } else { |
| 608 | printstat(tcp, tcp->u_arg[1]); |
| 609 | } |
| 610 | return 0; |
| 611 | } |
| 612 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 613 | #ifdef linux |
| 614 | int |
| 615 | sys_oldstat(tcp) |
| 616 | struct tcb *tcp; |
| 617 | { |
| 618 | if (entering(tcp)) { |
| 619 | printpath(tcp, tcp->u_arg[0]); |
| 620 | tprintf(", "); |
| 621 | } else { |
| 622 | printoldstat(tcp, tcp->u_arg[1]); |
| 623 | } |
| 624 | return 0; |
| 625 | } |
| 626 | #endif |
| 627 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 628 | int |
| 629 | sys_fstat(tcp) |
| 630 | struct tcb *tcp; |
| 631 | { |
| 632 | if (entering(tcp)) |
| 633 | tprintf("%ld, ", tcp->u_arg[0]); |
| 634 | else { |
| 635 | printstat(tcp, tcp->u_arg[1]); |
| 636 | } |
| 637 | return 0; |
| 638 | } |
| 639 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 640 | #ifdef linux |
| 641 | int |
| 642 | sys_oldfstat(tcp) |
| 643 | struct tcb *tcp; |
| 644 | { |
| 645 | if (entering(tcp)) |
| 646 | tprintf("%ld, ", tcp->u_arg[0]); |
| 647 | else { |
| 648 | printoldstat(tcp, tcp->u_arg[1]); |
| 649 | } |
| 650 | return 0; |
| 651 | } |
| 652 | #endif |
| 653 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 654 | int |
| 655 | sys_lstat(tcp) |
| 656 | struct tcb *tcp; |
| 657 | { |
| 658 | if (entering(tcp)) { |
| 659 | printpath(tcp, tcp->u_arg[0]); |
| 660 | tprintf(", "); |
| 661 | } else { |
| 662 | printstat(tcp, tcp->u_arg[1]); |
| 663 | } |
| 664 | return 0; |
| 665 | } |
| 666 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 667 | #ifdef linux |
| 668 | int |
| 669 | sys_oldlstat(tcp) |
| 670 | struct tcb *tcp; |
| 671 | { |
| 672 | if (entering(tcp)) { |
| 673 | printpath(tcp, tcp->u_arg[0]); |
| 674 | tprintf(", "); |
| 675 | } else { |
| 676 | printoldstat(tcp, tcp->u_arg[1]); |
| 677 | } |
| 678 | return 0; |
| 679 | } |
| 680 | #endif |
| 681 | |
| 682 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 683 | #if defined(SVR4) || defined(LINUXSPARC) |
| 684 | |
| 685 | int |
| 686 | sys_xstat(tcp) |
| 687 | struct tcb *tcp; |
| 688 | { |
| 689 | if (entering(tcp)) { |
| 690 | tprintf("%ld, ", tcp->u_arg[0]); |
| 691 | printpath(tcp, tcp->u_arg[1]); |
| 692 | tprintf(", "); |
| 693 | } else { |
| 694 | printstat(tcp, tcp->u_arg[2]); |
| 695 | } |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | int |
| 700 | sys_fxstat(tcp) |
| 701 | struct tcb *tcp; |
| 702 | { |
| 703 | if (entering(tcp)) |
| 704 | tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 705 | else { |
| 706 | printstat(tcp, tcp->u_arg[2]); |
| 707 | } |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | int |
| 712 | sys_lxstat(tcp) |
| 713 | struct tcb *tcp; |
| 714 | { |
| 715 | if (entering(tcp)) { |
| 716 | tprintf("%ld, ", tcp->u_arg[0]); |
| 717 | printpath(tcp, tcp->u_arg[1]); |
| 718 | tprintf(", "); |
| 719 | } else { |
| 720 | printstat(tcp, tcp->u_arg[2]); |
| 721 | } |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | int |
| 726 | sys_xmknod(tcp) |
| 727 | struct tcb *tcp; |
| 728 | { |
| 729 | int mode = tcp->u_arg[2]; |
| 730 | |
| 731 | if (entering(tcp)) { |
| 732 | tprintf("%ld, ", tcp->u_arg[0]); |
| 733 | printpath(tcp, tcp->u_arg[1]); |
| 734 | tprintf(", %s", sprintmode(mode)); |
| 735 | switch (mode & S_IFMT) { |
| 736 | case S_IFCHR: case S_IFBLK: |
| 737 | #ifdef LINUXSPARC |
| 738 | tprintf(", makedev(%lu, %lu)", |
| 739 | (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff), |
| 740 | (unsigned long) (tcp->u_arg[3] & 0x3ffff)); |
| 741 | #else |
| 742 | tprintf(", makedev(%lu, %lu)", |
| 743 | (unsigned long) major(tcp->u_arg[3]), |
| 744 | (unsigned long) minor(tcp->u_arg[3])); |
| 745 | #endif |
| 746 | break; |
| 747 | default: |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | #endif /* SVR4 || LINUXSPARC */ |
| 755 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 756 | #ifdef linux |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 757 | |
| 758 | static struct xlat fsmagic[] = { |
| 759 | { 0xef51, "EXT2_OLD_SUPER_MAGIC" }, |
| 760 | { 0xef53, "EXT2_SUPER_MAGIC" }, |
| 761 | { 0x137d, "EXT_SUPER_MAGIC" }, |
| 762 | { 0x9660, "ISOFS_SUPER_MAGIC" }, |
| 763 | { 0x137f, "MINIX_SUPER_MAGIC" }, |
| 764 | { 0x138f, "MINIX_SUPER_MAGIC2" }, |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 765 | { 0x2468, "MINIX2_SUPER_MAGIC" }, |
| 766 | { 0x2478, "MINIX2_SUPER_MAGIC2" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 767 | { 0x4d44, "MSDOS_SUPER_MAGIC" }, |
| 768 | { 0x6969, "NFS_SUPER_MAGIC" }, |
| 769 | { 0x9fa0, "PROC_SUPER_MAGIC" }, |
| 770 | { 0x012fd16d, "XIAFS_SUPER_MAGIC" }, |
| 771 | { 0, NULL }, |
| 772 | }; |
| 773 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 774 | #endif /* linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 775 | |
| 776 | #ifndef SVR4 |
| 777 | |
| 778 | static char * |
| 779 | sprintfstype(magic) |
| 780 | int magic; |
| 781 | { |
| 782 | static char buf[32]; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 783 | #ifdef linux |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 784 | char *s; |
| 785 | |
| 786 | s = xlookup(fsmagic, magic); |
| 787 | if (s) { |
| 788 | sprintf(buf, "\"%s\"", s); |
| 789 | return buf; |
| 790 | } |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 791 | #endif /* linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 792 | sprintf(buf, "%#x", magic); |
| 793 | return buf; |
| 794 | } |
| 795 | |
| 796 | static void |
| 797 | printstatfs(tcp, addr) |
| 798 | struct tcb *tcp; |
| 799 | long addr; |
| 800 | { |
| 801 | struct statfs statbuf; |
| 802 | |
| 803 | if (syserror(tcp) || !verbose(tcp)) { |
| 804 | tprintf("%#lx", addr); |
| 805 | return; |
| 806 | } |
| 807 | if (umove(tcp, addr, &statbuf) < 0) { |
| 808 | tprintf("{...}"); |
| 809 | return; |
| 810 | } |
| 811 | #ifdef ALPHA |
| 812 | |
| 813 | tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ", |
| 814 | sprintfstype(statbuf.f_type), |
| 815 | statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 816 | tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u", |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 817 | statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen); |
| 818 | #else /* !ALPHA */ |
| 819 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ", |
| 820 | sprintfstype(statbuf.f_type), |
Nate Sammons | 5c74d20 | 1999-04-06 01:37:51 +0000 | [diff] [blame] | 821 | (unsigned long)statbuf.f_bsize, |
| 822 | (unsigned long)statbuf.f_blocks, |
| 823 | (unsigned long)statbuf.f_bfree); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 824 | tprintf("f_files=%lu, f_ffree=%lu", |
Nate Sammons | 5c74d20 | 1999-04-06 01:37:51 +0000 | [diff] [blame] | 825 | (unsigned long)statbuf.f_files, |
| 826 | (unsigned long)statbuf.f_ffree); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 827 | #ifdef linux |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 828 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 829 | #endif /* linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 830 | #endif /* !ALPHA */ |
| 831 | tprintf("}"); |
| 832 | } |
| 833 | |
| 834 | int |
| 835 | sys_statfs(tcp) |
| 836 | struct tcb *tcp; |
| 837 | { |
| 838 | if (entering(tcp)) { |
| 839 | printpath(tcp, tcp->u_arg[0]); |
| 840 | tprintf(", "); |
| 841 | } else { |
| 842 | printstatfs(tcp, tcp->u_arg[1]); |
| 843 | } |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | int |
| 848 | sys_fstatfs(tcp) |
| 849 | struct tcb *tcp; |
| 850 | { |
| 851 | if (entering(tcp)) { |
| 852 | tprintf("%lu, ", tcp->u_arg[0]); |
| 853 | } else { |
| 854 | printstatfs(tcp, tcp->u_arg[1]); |
| 855 | } |
| 856 | return 0; |
| 857 | } |
| 858 | |
Wichert Akkerman | a0f36c6 | 1999-04-16 14:01:34 +0000 | [diff] [blame] | 859 | #if defined(linux) && defined(__alpha) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 860 | |
| 861 | int |
| 862 | osf_statfs(tcp) |
| 863 | struct tcb *tcp; |
| 864 | { |
| 865 | if (entering(tcp)) { |
| 866 | printpath(tcp, tcp->u_arg[0]); |
| 867 | tprintf(", "); |
| 868 | } else { |
| 869 | printstatfs(tcp, tcp->u_arg[1]); |
| 870 | tprintf(", %lu", tcp->u_arg[2]); |
| 871 | } |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | int |
| 876 | osf_fstatfs(tcp) |
| 877 | struct tcb *tcp; |
| 878 | { |
| 879 | if (entering(tcp)) { |
| 880 | tprintf("%lu, ", tcp->u_arg[0]); |
| 881 | } else { |
| 882 | printstatfs(tcp, tcp->u_arg[1]); |
| 883 | tprintf(", %lu", tcp->u_arg[2]); |
| 884 | } |
| 885 | return 0; |
| 886 | } |
Wichert Akkerman | a0f36c6 | 1999-04-16 14:01:34 +0000 | [diff] [blame] | 887 | #endif /* linux && __alpha */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 888 | |
| 889 | #endif /* !SVR4 */ |
| 890 | |
| 891 | #ifdef SUNOS4 |
| 892 | |
| 893 | int |
| 894 | sys_ustat(tcp) |
| 895 | struct tcb *tcp; |
| 896 | { |
| 897 | struct ustat statbuf; |
| 898 | |
| 899 | if (entering(tcp)) { |
| 900 | tprintf("makedev(%lu, %lu), ", |
| 901 | (long) major(tcp->u_arg[0]), |
| 902 | (long) minor(tcp->u_arg[0])); |
| 903 | } |
| 904 | else { |
| 905 | if (syserror(tcp) || !verbose(tcp)) |
| 906 | tprintf("%#lx", tcp->u_arg[1]); |
| 907 | else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0) |
| 908 | tprintf("{...}"); |
| 909 | else { |
| 910 | tprintf("{f_tfree=%lu, f_tinode=%lu, ", |
| 911 | statbuf.f_tfree, statbuf.f_tinode); |
| 912 | tprintf("f_fname=\"%.*s\", ", |
| 913 | (int) sizeof(statbuf.f_fname), |
| 914 | statbuf.f_fname); |
| 915 | tprintf("f_fpack=\"%.*s\"}", |
| 916 | (int) sizeof(statbuf.f_fpack), |
| 917 | statbuf.f_fpack); |
| 918 | } |
| 919 | } |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | #endif /* SUNOS4 */ |
| 924 | |
| 925 | /* directory */ |
| 926 | int |
| 927 | sys_chdir(tcp) |
| 928 | struct tcb *tcp; |
| 929 | { |
| 930 | if (entering(tcp)) { |
| 931 | printpath(tcp, tcp->u_arg[0]); |
| 932 | } |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | int |
| 937 | sys_mkdir(tcp) |
| 938 | struct tcb *tcp; |
| 939 | { |
| 940 | if (entering(tcp)) { |
| 941 | printpath(tcp, tcp->u_arg[0]); |
| 942 | tprintf(", %#lo", tcp->u_arg[1]); |
| 943 | } |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | int |
| 948 | sys_rmdir(tcp) |
| 949 | struct tcb *tcp; |
| 950 | { |
| 951 | if (entering(tcp)) { |
| 952 | printpath(tcp, tcp->u_arg[0]); |
| 953 | } |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | int |
| 958 | sys_fchdir(tcp) |
| 959 | struct tcb *tcp; |
| 960 | { |
| 961 | if (entering(tcp)) { |
| 962 | tprintf("%ld", tcp->u_arg[0]); |
| 963 | } |
| 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | int |
| 968 | sys_chroot(tcp) |
| 969 | struct tcb *tcp; |
| 970 | { |
| 971 | if (entering(tcp)) { |
| 972 | printpath(tcp, tcp->u_arg[0]); |
| 973 | } |
| 974 | return 0; |
| 975 | } |
| 976 | |
| 977 | int |
| 978 | sys_fchroot(tcp) |
| 979 | struct tcb *tcp; |
| 980 | { |
| 981 | if (entering(tcp)) { |
| 982 | tprintf("%ld", tcp->u_arg[0]); |
| 983 | } |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | int |
| 988 | sys_link(tcp) |
| 989 | struct tcb *tcp; |
| 990 | { |
| 991 | if (entering(tcp)) { |
| 992 | printpath(tcp, tcp->u_arg[0]); |
| 993 | tprintf(", "); |
| 994 | printpath(tcp, tcp->u_arg[1]); |
| 995 | } |
| 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | int |
| 1000 | sys_unlink(tcp) |
| 1001 | struct tcb *tcp; |
| 1002 | { |
| 1003 | if (entering(tcp)) { |
| 1004 | printpath(tcp, tcp->u_arg[0]); |
| 1005 | } |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | int |
| 1010 | sys_symlink(tcp) |
| 1011 | struct tcb *tcp; |
| 1012 | { |
| 1013 | if (entering(tcp)) { |
| 1014 | printpath(tcp, tcp->u_arg[0]); |
| 1015 | tprintf(", "); |
| 1016 | printpath(tcp, tcp->u_arg[1]); |
| 1017 | } |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
| 1021 | int |
| 1022 | sys_readlink(tcp) |
| 1023 | struct tcb *tcp; |
| 1024 | { |
| 1025 | if (entering(tcp)) { |
| 1026 | printpath(tcp, tcp->u_arg[0]); |
| 1027 | tprintf(", "); |
| 1028 | } else { |
| 1029 | if (syserror(tcp)) |
| 1030 | tprintf("%#lx", tcp->u_arg[1]); |
| 1031 | else |
| 1032 | printpathn(tcp, tcp->u_arg[1], tcp->u_rval); |
| 1033 | tprintf(", %lu", tcp->u_arg[2]); |
| 1034 | } |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | int |
| 1039 | sys_rename(tcp) |
| 1040 | struct tcb *tcp; |
| 1041 | { |
| 1042 | if (entering(tcp)) { |
| 1043 | printpath(tcp, tcp->u_arg[0]); |
| 1044 | tprintf(", "); |
| 1045 | printpath(tcp, tcp->u_arg[1]); |
| 1046 | } |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | int |
| 1051 | sys_chown(tcp) |
| 1052 | struct tcb *tcp; |
| 1053 | { |
| 1054 | if (entering(tcp)) { |
| 1055 | printpath(tcp, tcp->u_arg[0]); |
| 1056 | tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]); |
| 1057 | } |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | int |
| 1062 | sys_fchown(tcp) |
| 1063 | struct tcb *tcp; |
| 1064 | { |
| 1065 | if (entering(tcp)) { |
| 1066 | tprintf("%ld, %lu, %lu", |
| 1067 | tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
| 1068 | } |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | int |
| 1073 | sys_chmod(tcp) |
| 1074 | struct tcb *tcp; |
| 1075 | { |
| 1076 | if (entering(tcp)) { |
| 1077 | printpath(tcp, tcp->u_arg[0]); |
| 1078 | tprintf(", %#lo", tcp->u_arg[1]); |
| 1079 | } |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | int |
| 1084 | sys_fchmod(tcp) |
| 1085 | struct tcb *tcp; |
| 1086 | { |
| 1087 | if (entering(tcp)) { |
| 1088 | tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]); |
| 1089 | } |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | int |
| 1094 | sys_utimes(tcp) |
| 1095 | struct tcb *tcp; |
| 1096 | { |
| 1097 | if (entering(tcp)) { |
| 1098 | printpath(tcp, tcp->u_arg[0]); |
| 1099 | tprintf(", "); |
| 1100 | printtv(tcp, tcp->u_arg[1]); |
| 1101 | } |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
| 1105 | int |
| 1106 | sys_utime(tcp) |
| 1107 | struct tcb *tcp; |
| 1108 | { |
| 1109 | long ut[2]; |
| 1110 | |
| 1111 | if (entering(tcp)) { |
| 1112 | printpath(tcp, tcp->u_arg[0]); |
| 1113 | tprintf(", "); |
| 1114 | if (!tcp->u_arg[1]) |
| 1115 | tprintf("NULL"); |
| 1116 | else if (!verbose(tcp)) |
| 1117 | tprintf("%#lx", tcp->u_arg[1]); |
| 1118 | else if (umoven(tcp, tcp->u_arg[1], sizeof ut, |
| 1119 | (char *) ut) < 0) |
| 1120 | tprintf("[?, ?]"); |
| 1121 | else { |
| 1122 | tprintf("[%s,", sprinttime(ut[0])); |
| 1123 | tprintf(" %s]", sprinttime(ut[1])); |
| 1124 | } |
| 1125 | } |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | int |
| 1130 | sys_mknod(tcp) |
| 1131 | struct tcb *tcp; |
| 1132 | { |
| 1133 | int mode = tcp->u_arg[1]; |
| 1134 | |
| 1135 | if (entering(tcp)) { |
| 1136 | printpath(tcp, tcp->u_arg[0]); |
| 1137 | tprintf(", %s", sprintmode(mode)); |
| 1138 | switch (mode & S_IFMT) { |
| 1139 | case S_IFCHR: case S_IFBLK: |
| 1140 | #ifdef LINUXSPARC |
| 1141 | if (current_personality == 1) |
| 1142 | tprintf(", makedev(%lu, %lu)", |
| 1143 | (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff), |
| 1144 | (unsigned long) (tcp->u_arg[2] & 0x3ffff)); |
| 1145 | else |
| 1146 | #endif |
| 1147 | tprintf(", makedev(%lu, %lu)", |
| 1148 | (unsigned long) major(tcp->u_arg[2]), |
| 1149 | (unsigned long) minor(tcp->u_arg[2])); |
| 1150 | break; |
| 1151 | default: |
| 1152 | break; |
| 1153 | } |
| 1154 | } |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | int |
| 1159 | sys_mkfifo(tcp) |
| 1160 | struct tcb *tcp; |
| 1161 | { |
| 1162 | if (entering(tcp)) { |
| 1163 | printpath(tcp, tcp->u_arg[0]); |
| 1164 | tprintf(", %#lo", tcp->u_arg[1]); |
| 1165 | } |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | int |
| 1170 | sys_fsync(tcp) |
| 1171 | struct tcb *tcp; |
| 1172 | { |
| 1173 | if (entering(tcp)) { |
| 1174 | tprintf("%ld", tcp->u_arg[0]); |
| 1175 | } |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 1179 | #ifdef linux |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1180 | |
| 1181 | static void |
| 1182 | printdir(tcp, addr) |
| 1183 | struct tcb *tcp; |
| 1184 | long addr; |
| 1185 | { |
| 1186 | struct dirent d; |
| 1187 | |
| 1188 | if (!verbose(tcp)) { |
| 1189 | tprintf("%#lx", addr); |
| 1190 | return; |
| 1191 | } |
| 1192 | if (umove(tcp, addr, &d) < 0) { |
| 1193 | tprintf("{...}"); |
| 1194 | return; |
| 1195 | } |
| 1196 | tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1197 | tprintf("d_name="); |
| 1198 | printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen); |
| 1199 | tprintf("}"); |
| 1200 | } |
| 1201 | |
| 1202 | int |
| 1203 | sys_readdir(tcp) |
| 1204 | struct tcb *tcp; |
| 1205 | { |
| 1206 | if (entering(tcp)) { |
| 1207 | tprintf("%lu, ", tcp->u_arg[0]); |
| 1208 | } else { |
| 1209 | if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp)) |
| 1210 | tprintf("%#lx", tcp->u_arg[1]); |
| 1211 | else |
| 1212 | printdir(tcp, tcp->u_arg[1]); |
| 1213 | /* Not much point in printing this out, it is always 1. */ |
| 1214 | if (tcp->u_arg[2] != 1) |
| 1215 | tprintf(", %lu", tcp->u_arg[2]); |
| 1216 | } |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 1220 | #endif /* linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1221 | |
| 1222 | int |
| 1223 | sys_getdents(tcp) |
| 1224 | struct tcb *tcp; |
| 1225 | { |
| 1226 | int i, len, dents = 0; |
| 1227 | char *buf; |
| 1228 | |
| 1229 | if (entering(tcp)) { |
| 1230 | tprintf("%lu, ", tcp->u_arg[0]); |
| 1231 | return 0; |
| 1232 | } |
| 1233 | if (syserror(tcp) || !verbose(tcp)) { |
| 1234 | tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]); |
| 1235 | return 0; |
| 1236 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1237 | len = tcp->u_rval; |
| 1238 | if ((buf = malloc(len)) == NULL) { |
| 1239 | tprintf("out of memory\n"); |
| 1240 | return 0; |
| 1241 | } |
| 1242 | if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) { |
| 1243 | tprintf("{...}, %lu", tcp->u_arg[2]); |
| 1244 | free(buf); |
| 1245 | return 0; |
| 1246 | } |
| 1247 | if (!abbrev(tcp)) |
| 1248 | tprintf("{"); |
| 1249 | for (i = 0; i < len;) { |
| 1250 | struct dirent *d = (struct dirent *) &buf[i]; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 1251 | #ifdef linux |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1252 | if (!abbrev(tcp)) { |
| 1253 | tprintf("%s{d_ino=%lu, d_off=%lu, ", |
| 1254 | i ? " " : "", d->d_ino, d->d_off); |
| 1255 | tprintf("d_reclen=%u, d_name=\"%s\"}", |
| 1256 | d->d_reclen, d->d_name); |
| 1257 | } |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 1258 | #endif /* linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1259 | #ifdef SVR4 |
| 1260 | if (!abbrev(tcp)) { |
| 1261 | tprintf("%s{d_ino=%lu, d_off=%lu, ", |
| 1262 | i ? " " : "", d->d_ino, d->d_off); |
| 1263 | tprintf("d_reclen=%u, d_name=\"%s\"}", |
| 1264 | d->d_reclen, d->d_name); |
| 1265 | } |
| 1266 | #endif /* SVR4 */ |
| 1267 | #ifdef SUNOS4 |
| 1268 | if (!abbrev(tcp)) { |
| 1269 | tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ", |
| 1270 | i ? " " : "", d->d_off, d->d_fileno, |
| 1271 | d->d_reclen); |
| 1272 | tprintf("d_namlen=%u, d_name=\"%.*s\"}", |
| 1273 | d->d_namlen, d->d_namlen, d->d_name); |
| 1274 | } |
| 1275 | #endif /* SUNOS4 */ |
| 1276 | i += d->d_reclen; |
| 1277 | dents++; |
| 1278 | } |
| 1279 | if (!abbrev(tcp)) |
| 1280 | tprintf("}"); |
| 1281 | else |
| 1282 | tprintf("/* %u entries */", dents); |
| 1283 | tprintf(", %lu", tcp->u_arg[2]); |
| 1284 | free(buf); |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 1288 | #ifdef linux |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1289 | |
| 1290 | int |
| 1291 | sys_getcwd(tcp) |
| 1292 | struct tcb *tcp; |
| 1293 | { |
| 1294 | if (exiting(tcp)) { |
| 1295 | if (syserror(tcp)) |
| 1296 | tprintf("%#lx", tcp->u_arg[0]); |
| 1297 | else |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 1298 | printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1299 | tprintf(", %lu", tcp->u_arg[1]); |
| 1300 | } |
| 1301 | return 0; |
| 1302 | } |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 1303 | #endif /* linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1304 | |
| 1305 | #ifdef HAVE_SYS_ASYNCH_H |
| 1306 | |
| 1307 | int |
| 1308 | sys_aioread(tcp) |
| 1309 | struct tcb *tcp; |
| 1310 | { |
| 1311 | struct aio_result_t res; |
| 1312 | |
| 1313 | if (entering(tcp)) { |
| 1314 | tprintf("%lu, ", tcp->u_arg[0]); |
| 1315 | } else { |
| 1316 | if (syserror(tcp)) |
| 1317 | tprintf("%#lx", tcp->u_arg[1]); |
| 1318 | else |
| 1319 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 1320 | tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]); |
| 1321 | printxval(whence, tcp->u_arg[4], "L_???"); |
| 1322 | if (syserror(tcp) || tcp->u_arg[5] == 0 |
| 1323 | || umove(tcp, tcp->u_arg[5], &res) < 0) |
| 1324 | tprintf(", %#lx", tcp->u_arg[5]); |
| 1325 | else |
| 1326 | tprintf(", {aio_return %d aio_errno %d}", |
| 1327 | res.aio_return, res.aio_errno); |
| 1328 | } |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
| 1332 | int |
| 1333 | sys_aiowrite(tcp) |
| 1334 | struct tcb *tcp; |
| 1335 | { |
| 1336 | struct aio_result_t res; |
| 1337 | |
| 1338 | if (entering(tcp)) { |
| 1339 | tprintf("%lu, ", tcp->u_arg[0]); |
| 1340 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 1341 | tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]); |
| 1342 | printxval(whence, tcp->u_arg[4], "L_???"); |
| 1343 | } |
| 1344 | else { |
| 1345 | if (tcp->u_arg[5] == 0) |
| 1346 | tprintf(", NULL"); |
| 1347 | else if (syserror(tcp) |
| 1348 | || umove(tcp, tcp->u_arg[5], &res) < 0) |
| 1349 | tprintf(", %#lx", tcp->u_arg[5]); |
| 1350 | else |
| 1351 | tprintf(", {aio_return %d aio_errno %d}", |
| 1352 | res.aio_return, res.aio_errno); |
| 1353 | } |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
| 1357 | int |
| 1358 | sys_aiowait(tcp) |
| 1359 | struct tcb *tcp; |
| 1360 | { |
| 1361 | if (entering(tcp)) |
| 1362 | printtv(tcp, tcp->u_arg[0]); |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | int |
| 1367 | sys_aiocancel(tcp) |
| 1368 | struct tcb *tcp; |
| 1369 | { |
| 1370 | struct aio_result_t res; |
| 1371 | |
| 1372 | if (exiting(tcp)) { |
| 1373 | if (tcp->u_arg[0] == 0) |
| 1374 | tprintf("NULL"); |
| 1375 | else if (syserror(tcp) |
| 1376 | || umove(tcp, tcp->u_arg[0], &res) < 0) |
| 1377 | tprintf("%#lx", tcp->u_arg[0]); |
| 1378 | else |
| 1379 | tprintf("{aio_return %d aio_errno %d}", |
| 1380 | res.aio_return, res.aio_errno); |
| 1381 | } |
| 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | #endif /* HAVE_SYS_ASYNCH_H */ |