file.c revision b8c9f77c6d2d9350d26705ff6b200e54d1ca66cc
1/* 2#ifdef linux 3 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> 4 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> 5 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> 6 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * $Id$ 32 */ 33 34#include "defs.h" 35 36#include <dirent.h> 37#ifdef linux 38#define dirent kernel_dirent 39#define dirent64 kernel_dirent64 40#include <linux/types.h> 41#include <linux/dirent.h> 42#undef dirent 43#else 44#define kernel_dirent dirent 45#endif 46 47#ifdef linux 48# ifdef LINUXSPARC 49struct stat { 50 unsigned short st_dev; 51 unsigned int st_ino; 52 unsigned short st_mode; 53 short st_nlink; 54 unsigned short st_uid; 55 unsigned short st_gid; 56 unsigned short st_rdev; 57 unsigned int st_size; 58 int st_atime; 59 unsigned int __unused1; 60 int st_mtime; 61 unsigned int __unused2; 62 int st_ctime; 63 unsigned int __unused3; 64 int st_blksize; 65 int st_blocks; 66 unsigned int __unused4[2]; 67}; 68# define stat kernel_stat 69# include <asm/stat.h> 70# undef stat 71# else 72# undef dev_t 73# undef ino_t 74# undef mode_t 75# undef nlink_t 76# undef uid_t 77# undef gid_t 78# undef off_t 79# undef loff_t 80 81# define dev_t __kernel_dev_t 82# define ino_t __kernel_ino_t 83# define mode_t __kernel_mode_t 84# define nlink_t __kernel_nlink_t 85# define uid_t __kernel_uid_t 86# define gid_t __kernel_gid_t 87# define off_t __kernel_off_t 88# define loff_t __kernel_loff_t 89 90# include <asm/stat.h> 91 92# undef dev_t 93# undef ino_t 94# undef mode_t 95# undef nlink_t 96# undef uid_t 97# undef gid_t 98# undef off_t 99# undef loff_t 100 101# define dev_t dev_t 102# define ino_t ino_t 103# define mode_t mode_t 104# define nlink_t nlink_t 105# define uid_t uid_t 106# define gid_t gid_t 107# define off_t off_t 108# define loff_t loff_t 109# endif 110# define stat libc_stat 111# define stat64 libc_stat64 112# include <sys/stat.h> 113# undef stat 114# undef stat64 115#else 116# include <sys/stat.h> 117#endif 118 119#include <fcntl.h> 120 121#ifdef SVR4 122# include <sys/cred.h> 123#endif /* SVR4 */ 124 125#ifdef HAVE_SYS_VFS_H 126#include <sys/vfs.h> 127#endif 128 129#ifdef FREEBSD 130#include <sys/param.h> 131#include <sys/mount.h> 132#include <sys/stat.h> 133 134#define stat64 stat 135#define HAVE_STAT64 1 /* Ugly hack */ 136#endif 137 138#ifdef MAJOR_IN_SYSMACROS 139#include <sys/sysmacros.h> 140#endif 141 142#ifdef MAJOR_IN_MKDEV 143#include <sys/mkdev.h> 144#endif 145 146#ifdef HAVE_SYS_ASYNCH_H 147#include <sys/asynch.h> 148#endif 149 150#ifdef SUNOS4 151#include <ustat.h> 152#endif 153 154/* 155 * This is a really dirty trick but it should always work. Traditional 156 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by 157 * adding 1. Just remember to add 1 to any arg decoded with openmodes. 158 */ 159struct xlat openmodes[] = { 160 { O_RDWR+1, "O_RDWR" }, 161 { O_RDONLY+1, "O_RDONLY" }, 162 { O_WRONLY+1, "O_WRONLY" }, 163 { O_NONBLOCK, "O_NONBLOCK" }, 164 { O_APPEND, "O_APPEND" }, 165 { O_CREAT, "O_CREAT" }, 166 { O_TRUNC, "O_TRUNC" }, 167 { O_EXCL, "O_EXCL" }, 168 { O_NOCTTY, "O_NOCTTY" }, 169#ifdef O_SYNC 170 { O_SYNC, "O_SYNC" }, 171#endif 172#ifdef O_ASYNC 173 { O_ASYNC, "O_ASYNC" }, 174#endif 175#ifdef O_DSYNC 176 { O_DSYNC, "O_DSYNC" }, 177#endif 178#ifdef O_RSYNC 179 { O_RSYNC, "O_RSYNC" }, 180#endif 181#ifdef O_NDELAY 182 { O_NDELAY, "O_NDELAY" }, 183#endif 184#ifdef O_PRIV 185 { O_PRIV, "O_PRIV" }, 186#endif 187#ifdef O_DIRECT 188 { O_DIRECT, "O_DIRECT" }, 189#endif 190#ifdef O_LARGEFILE 191 { O_LARGEFILE, "O_LARGEFILE" }, 192#endif 193#ifdef O_DIRECTORY 194 { O_DIRECTORY, "O_DIRECTORY" }, 195#endif 196#ifdef O_NOFOLLOW 197 { O_NOFOLLOW, "O_NOFOLLOW" }, 198#endif 199 200#ifdef FNDELAY 201 { FNDELAY, "FNDELAY" }, 202#endif 203#ifdef FAPPEND 204 { FAPPEND, "FAPPEND" }, 205#endif 206#ifdef FMARK 207 { FMARK, "FMARK" }, 208#endif 209#ifdef FDEFER 210 { FDEFER, "FDEFER" }, 211#endif 212#ifdef FASYNC 213 { FASYNC, "FASYNC" }, 214#endif 215#ifdef FSHLOCK 216 { FSHLOCK, "FSHLOCK" }, 217#endif 218#ifdef FEXLOCK 219 { FEXLOCK, "FEXLOCK" }, 220#endif 221#ifdef FCREAT 222 { FCREAT, "FCREAT" }, 223#endif 224#ifdef FTRUNC 225 { FTRUNC, "FTRUNC" }, 226#endif 227#ifdef FEXCL 228 { FEXCL, "FEXCL" }, 229#endif 230#ifdef FNBIO 231 { FNBIO, "FNBIO" }, 232#endif 233#ifdef FSYNC 234 { FSYNC, "FSYNC" }, 235#endif 236#ifdef FNOCTTY 237 { FNOCTTY, "FNOCTTY" }, 238#endif 239#ifdef O_SHLOCK 240 { O_SHLOCK, "O_SHLOCK" }, 241#endif 242#ifdef O_EXLOCK 243 { O_EXLOCK, "O_EXLOCK" }, 244#endif 245 { 0, NULL }, 246}; 247 248int 249sys_open(tcp) 250struct tcb *tcp; 251{ 252 if (entering(tcp)) { 253 printpath(tcp, tcp->u_arg[0]); 254 tprintf(", "); 255 /* flags */ 256 printflags(openmodes, tcp->u_arg[1] + 1); 257 if (tcp->u_arg[1] & O_CREAT) { 258 /* mode */ 259 tprintf(", %#lo", tcp->u_arg[2]); 260 } 261 } 262 return 0; 263} 264 265#ifdef LINUXSPARC 266struct xlat openmodessol[] = { 267 { 0, "O_RDWR" }, 268 { 1, "O_RDONLY" }, 269 { 2, "O_WRONLY" }, 270 { 0x80, "O_NONBLOCK" }, 271 { 8, "O_APPEND" }, 272 { 0x100, "O_CREAT" }, 273 { 0x200, "O_TRUNC" }, 274 { 0x400, "O_EXCL" }, 275 { 0x800, "O_NOCTTY" }, 276 { 0x10, "O_SYNC" }, 277 { 0x40, "O_DSYNC" }, 278 { 0x8000, "O_RSYNC" }, 279 { 4, "O_NDELAY" }, 280 { 0x1000, "O_PRIV" }, 281 { 0, NULL }, 282}; 283 284int 285solaris_open(tcp) 286struct tcb *tcp; 287{ 288 if (entering(tcp)) { 289 printpath(tcp, tcp->u_arg[0]); 290 tprintf(", "); 291 /* flags */ 292 printflags(openmodessol, tcp->u_arg[1] + 1); 293 if (tcp->u_arg[1] & 0x100) { 294 /* mode */ 295 tprintf(", %#lo", tcp->u_arg[2]); 296 } 297 } 298 return 0; 299} 300 301#endif 302 303int 304sys_creat(tcp) 305struct tcb *tcp; 306{ 307 if (entering(tcp)) { 308 printpath(tcp, tcp->u_arg[0]); 309 tprintf(", %#lo", tcp->u_arg[1]); 310 } 311 return 0; 312} 313 314static struct xlat access_flags[] = { 315 { F_OK, "F_OK", }, 316 { R_OK, "R_OK" }, 317 { W_OK, "W_OK" }, 318 { X_OK, "X_OK" }, 319#ifdef EFF_ONLY_OK 320 { EFF_ONLY_OK, "EFF_ONLY_OK" }, 321#endif 322#ifdef EX_OK 323 { EX_OK, "EX_OK" }, 324#endif 325 { 0, NULL }, 326}; 327 328int 329sys_access(tcp) 330struct tcb *tcp; 331{ 332 if (entering(tcp)) { 333 printpath(tcp, tcp->u_arg[0]); 334 tprintf(", "); 335 printflags(access_flags, tcp->u_arg[1]); 336 } 337 return 0; 338} 339 340int 341sys_umask(tcp) 342struct tcb *tcp; 343{ 344 if (entering(tcp)) { 345 tprintf("%#lo", tcp->u_arg[0]); 346 } 347 return RVAL_OCTAL; 348} 349 350static struct xlat whence[] = { 351 { SEEK_SET, "SEEK_SET" }, 352 { SEEK_CUR, "SEEK_CUR" }, 353 { SEEK_END, "SEEK_END" }, 354 { 0, NULL }, 355}; 356 357#ifndef FREEBSD 358int 359sys_lseek(tcp) 360struct tcb *tcp; 361{ 362 off_t offset; 363 int _whence; 364 365 if (entering(tcp)) { 366 tprintf("%ld, ", tcp->u_arg[0]); 367 offset = tcp->u_arg[1]; 368 _whence = tcp->u_arg[2]; 369 if (_whence == SEEK_SET) 370 tprintf("%lu, ", offset); 371 else 372 tprintf("%ld, ", offset); 373 printxval(whence, _whence, "SEEK_???"); 374 } 375 return RVAL_UDECIMAL; 376} 377#endif 378 379#ifdef linux 380int 381sys_llseek (tcp) 382struct tcb *tcp; 383{ 384 if (entering(tcp)) { 385 if (tcp->u_arg[4] == SEEK_SET) 386 tprintf("%ld, %llu, ", tcp->u_arg[0], 387 (((long long int) tcp->u_arg[1]) << 32 388 | (unsigned long long) tcp->u_arg[2])); 389 else 390 tprintf("%ld, %lld, ", tcp->u_arg[0], 391 (((long long int) tcp->u_arg[1]) << 32 392 | (unsigned long long) tcp->u_arg[2])); 393 } 394 else { 395 long long int off; 396 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0) 397 tprintf("%#lx, ", tcp->u_arg[3]); 398 else 399 tprintf("[%llu], ", off); 400 printxval(whence, tcp->u_arg[4], "SEEK_???"); 401 } 402 return 0; 403} 404#endif 405 406#if _LFS64_LARGEFILE || FREEBSD 407int 408sys_lseek64 (tcp) 409struct tcb *tcp; 410{ 411 if (entering(tcp)) { 412 long long offset; 413 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */ 414 offset = get64(tcp->u_arg [1], tcp->u_arg[2]); 415 if (tcp->u_arg[3] == SEEK_SET) 416 tprintf("%ld, %llu, ", tcp->u_arg[0], offset); 417 else 418 tprintf("%ld, %lld, ", tcp->u_arg[0], offset); 419 printxval(whence, tcp->u_arg[3], "SEEK_???"); 420 } 421 return RVAL_LUDECIMAL; 422} 423#endif 424 425#ifndef FREEBSD 426int 427sys_truncate(tcp) 428struct tcb *tcp; 429{ 430 if (entering(tcp)) { 431 printpath(tcp, tcp->u_arg[0]); 432 tprintf(", %lu", tcp->u_arg[1]); 433 } 434 return 0; 435} 436#endif 437 438#if _LFS64_LARGEFILE || FREEBSD 439int 440sys_truncate64(tcp) 441struct tcb *tcp; 442{ 443 if (entering(tcp)) { 444 ALIGN64 (tcp, 1); 445 printpath(tcp, tcp->u_arg[0]); 446 tprintf(", %llu", get64(tcp->u_arg[1],tcp->u_arg[2])); 447 } 448 return 0; 449} 450#endif 451 452#ifndef FREEBSD 453int 454sys_ftruncate(tcp) 455struct tcb *tcp; 456{ 457 if (entering(tcp)) { 458 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]); 459 } 460 return 0; 461} 462#endif 463 464#if _LFS64_LARGEFILE || FREEBSD 465int 466sys_ftruncate64(tcp) 467struct tcb *tcp; 468{ 469 if (entering(tcp)) { 470 ALIGN64 (tcp, 1); 471 tprintf("%ld, %llu", tcp->u_arg[0], 472 get64(tcp->u_arg[1] ,tcp->u_arg[2])); 473 } 474 return 0; 475} 476#endif 477 478/* several stats */ 479 480static struct xlat modetypes[] = { 481 { S_IFREG, "S_IFREG" }, 482 { S_IFSOCK, "S_IFSOCK" }, 483 { S_IFIFO, "S_IFIFO" }, 484 { S_IFLNK, "S_IFLNK" }, 485 { S_IFDIR, "S_IFDIR" }, 486 { S_IFBLK, "S_IFBLK" }, 487 { S_IFCHR, "S_IFCHR" }, 488 { 0, NULL }, 489}; 490 491static char * 492sprintmode(mode) 493int mode; 494{ 495 static char buf[64]; 496 char *s; 497 498 if ((mode & S_IFMT) == 0) 499 s = ""; 500 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) { 501 sprintf(buf, "%#o", mode); 502 return buf; 503 } 504 sprintf(buf, "%s%s%s%s", s, 505 (mode & S_ISUID) ? "|S_ISUID" : "", 506 (mode & S_ISGID) ? "|S_ISGID" : "", 507 (mode & S_ISVTX) ? "|S_ISVTX" : ""); 508 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX); 509 if (mode) 510 sprintf(buf + strlen(buf), "|%#o", mode); 511 s = (*buf == '|') ? buf + 1 : buf; 512 return *s ? s : "0"; 513} 514 515static char * 516sprinttime(t) 517time_t t; 518{ 519 struct tm *tmp; 520 static char buf[32]; 521 522 if (t == 0) { 523 sprintf(buf, "0"); 524 return buf; 525 } 526 tmp = localtime(&t); 527 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d", 528 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 529 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 530 return buf; 531} 532 533#ifdef LINUXSPARC 534typedef struct { 535 int tv_sec; 536 int tv_nsec; 537} timestruct_t; 538 539struct solstat { 540 unsigned st_dev; 541 int st_pad1[3]; /* network id */ 542 unsigned st_ino; 543 unsigned st_mode; 544 unsigned st_nlink; 545 unsigned st_uid; 546 unsigned st_gid; 547 unsigned st_rdev; 548 int st_pad2[2]; 549 int st_size; 550 int st_pad3; /* st_size, off_t expansion */ 551 timestruct_t st_atime; 552 timestruct_t st_mtime; 553 timestruct_t st_ctime; 554 int st_blksize; 555 int st_blocks; 556 char st_fstype[16]; 557 int st_pad4[8]; /* expansion area */ 558}; 559 560static void 561printstatsol(tcp, addr) 562struct tcb *tcp; 563long addr; 564{ 565 struct solstat statbuf; 566 567 if (!addr) { 568 tprintf("NULL"); 569 return; 570 } 571 if (syserror(tcp) || !verbose(tcp)) { 572 tprintf("%#lx", addr); 573 return; 574 } 575 if (umove(tcp, addr, &statbuf) < 0) { 576 tprintf("{...}"); 577 return; 578 } 579 if (!abbrev(tcp)) { 580 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", 581 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff), 582 (unsigned long) (statbuf.st_dev & 0x3ffff), 583 (unsigned long) statbuf.st_ino, 584 sprintmode(statbuf.st_mode)); 585 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", 586 (unsigned long) statbuf.st_nlink, 587 (unsigned long) statbuf.st_uid, 588 (unsigned long) statbuf.st_gid); 589 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize); 590 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks); 591 } 592 else 593 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); 594 switch (statbuf.st_mode & S_IFMT) { 595 case S_IFCHR: case S_IFBLK: 596 tprintf("st_rdev=makedev(%lu, %lu), ", 597 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff), 598 (unsigned long) (statbuf.st_rdev & 0x3ffff)); 599 break; 600 default: 601 tprintf("st_size=%u, ", statbuf.st_size); 602 break; 603 } 604 if (!abbrev(tcp)) { 605 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); 606 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); 607 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime)); 608 } 609 else 610 tprintf("...}"); 611} 612#endif /* LINUXSPARC */ 613 614#ifdef FREEBSD 615static struct xlat fileflags[] = { 616 { UF_NODUMP, "UF_NODUMP" }, 617 { UF_IMMUTABLE, "UF_IMMUTABLE" }, 618 { UF_APPEND, "UF_APPEND" }, 619 { UF_OPAQUE, "UF_OPAQUE" }, 620 { UF_NOUNLINK, "UF_NOUNLINK" }, 621 { SF_ARCHIVED, "SF_ARCHIVED" }, 622 { SF_IMMUTABLE, "SF_IMMUTABLE" }, 623 { SF_APPEND, "SF_APPEND" }, 624 { SF_NOUNLINK, "SF_NOUNLINK" }, 625 { 0, NULL }, 626}; 627 628int 629sys_chflags(tcp) 630struct tcb *tcp; 631{ 632 if (entering(tcp)) { 633 printpath(tcp, tcp->u_arg[0]); 634 tprintf(", "); 635 if (tcp->u_arg[1]) 636 printflags(fileflags, tcp->u_arg[1]); 637 else 638 tprintf("0"); 639 } 640 return 0; 641} 642 643int 644sys_fchflags(tcp) 645struct tcb *tcp; 646{ 647 if (entering(tcp)) { 648 tprintf("%ld, ", tcp->u_arg[0]); 649 if (tcp->u_arg[1]) 650 printflags(fileflags, tcp->u_arg[1]); 651 else 652 tprintf("0"); 653 } 654 return 0; 655} 656#endif 657 658#ifndef FREEBSD 659static void 660realprintstat(tcp, statbuf) 661struct tcb *tcp; 662struct stat *statbuf; 663{ 664 if (!abbrev(tcp)) { 665 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", 666 (unsigned long) major(statbuf->st_dev), 667 (unsigned long) minor(statbuf->st_dev), 668 (unsigned long) statbuf->st_ino, 669 sprintmode(statbuf->st_mode)); 670 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", 671 (unsigned long) statbuf->st_nlink, 672 (unsigned long) statbuf->st_uid, 673 (unsigned long) statbuf->st_gid); 674#ifdef HAVE_ST_BLKSIZE 675 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize); 676#endif /* HAVE_ST_BLKSIZE */ 677#ifdef HAVE_ST_BLOCKS 678 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks); 679#endif /* HAVE_ST_BLOCKS */ 680 } 681 else 682 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode)); 683 switch (statbuf->st_mode & S_IFMT) { 684 case S_IFCHR: case S_IFBLK: 685#ifdef HAVE_ST_RDEV 686 tprintf("st_rdev=makedev(%lu, %lu), ", 687 (unsigned long) major(statbuf->st_rdev), 688 (unsigned long) minor(statbuf->st_rdev)); 689#else /* !HAVE_ST_RDEV */ 690 tprintf("st_size=makedev(%lu, %lu), ", 691 (unsigned long) major(statbuf->st_size), 692 (unsigned long) minor(statbuf->st_size)); 693#endif /* !HAVE_ST_RDEV */ 694 break; 695 default: 696 tprintf("st_size=%lu, ", statbuf->st_size); 697 break; 698 } 699 if (!abbrev(tcp)) { 700 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime)); 701 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime)); 702 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime)); 703 } 704 else 705 tprintf("...}"); 706} 707 708 709static void 710printstat(tcp, addr) 711struct tcb *tcp; 712long addr; 713{ 714 struct stat statbuf; 715 716#ifdef LINUXSPARC 717 if (current_personality == 1) { 718 printstatsol(tcp, addr); 719 return; 720 } 721#endif /* LINUXSPARC */ 722 723 if (!addr) { 724 tprintf("NULL"); 725 return; 726 } 727 if (syserror(tcp) || !verbose(tcp)) { 728 tprintf("%#lx", addr); 729 return; 730 } 731 if (umove(tcp, addr, &statbuf) < 0) { 732 tprintf("{...}"); 733 return; 734 } 735 736 realprintstat(tcp, &statbuf); 737} 738#endif /* !FREEBSD */ 739 740#ifdef HAVE_STAT64 741static void 742printstat64(tcp, addr) 743struct tcb *tcp; 744long addr; 745{ 746 struct stat64 statbuf; 747 748#ifdef LINUXSPARC 749 if (current_personality == 1) { 750 printstatsol(tcp, addr); 751 return; 752 } 753#endif /* LINUXSPARC */ 754 755 if (!addr) { 756 tprintf("NULL"); 757 return; 758 } 759 if (syserror(tcp) || !verbose(tcp)) { 760 tprintf("%#lx", addr); 761 return; 762 } 763 if (umove(tcp, addr, &statbuf) < 0) { 764 tprintf("{...}"); 765 return; 766 } 767 768 if (!abbrev(tcp)) { 769#ifdef HAVE_LONG_LONG 770 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ", 771#else 772 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", 773#endif 774 (unsigned long) major(statbuf.st_dev), 775 (unsigned long) minor(statbuf.st_dev), 776#ifdef HAVE_LONG_LONG 777 (unsigned long long) statbuf.st_ino, 778#else 779 (unsigned long) statbuf.st_ino, 780#endif 781 sprintmode(statbuf.st_mode)); 782 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", 783 (unsigned long) statbuf.st_nlink, 784 (unsigned long) statbuf.st_uid, 785 (unsigned long) statbuf.st_gid); 786#ifdef HAVE_ST_BLKSIZE 787 tprintf("st_blksize=%lu, ", 788 (unsigned long) statbuf.st_blksize); 789#endif /* HAVE_ST_BLKSIZE */ 790#ifdef HAVE_ST_BLOCKS 791 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks); 792#endif /* HAVE_ST_BLOCKS */ 793 } 794 else 795 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); 796 switch (statbuf.st_mode & S_IFMT) { 797 case S_IFCHR: case S_IFBLK: 798#ifdef HAVE_ST_RDEV 799 tprintf("st_rdev=makedev(%lu, %lu), ", 800 (unsigned long) major(statbuf.st_rdev), 801 (unsigned long) minor(statbuf.st_rdev)); 802#else /* !HAVE_ST_RDEV */ 803 tprintf("st_size=makedev(%lu, %lu), ", 804 (unsigned long) major(statbuf.st_size), 805 (unsigned long) minor(statbuf.st_size)); 806#endif /* !HAVE_ST_RDEV */ 807 break; 808 default: 809 tprintf("st_size=%llu, ", statbuf.st_size); 810 break; 811 } 812 if (!abbrev(tcp)) { 813 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); 814 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); 815#ifndef FREEBSD 816 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime)); 817#else /* FREEBSD */ 818 tprintf("st_ctime=%s, ", sprinttime(statbuf.st_ctime)); 819 tprintf("st_flags="); 820 if (statbuf.st_flags) { 821 printflags(fileflags, statbuf.st_flags); 822 } else 823 tprintf("0"); 824 tprintf(", st_gen=%u}", statbuf.st_gen); 825#endif /* FREEBSD */ 826 } 827 else 828 tprintf("...}"); 829} 830#endif /* HAVE_STAT64 */ 831 832#if defined(linux) && !defined(IA64) 833static void 834convertoldstat(oldbuf, newbuf) 835const struct __old_kernel_stat *oldbuf; 836struct stat *newbuf; 837{ 838 newbuf->st_dev=oldbuf->st_dev; 839 newbuf->st_ino=oldbuf->st_ino; 840 newbuf->st_mode=oldbuf->st_mode; 841 newbuf->st_nlink=oldbuf->st_nlink; 842 newbuf->st_uid=oldbuf->st_uid; 843 newbuf->st_gid=oldbuf->st_gid; 844 newbuf->st_rdev=oldbuf->st_rdev; 845 newbuf->st_size=oldbuf->st_size; 846 newbuf->st_atime=oldbuf->st_atime; 847 newbuf->st_mtime=oldbuf->st_mtime; 848 newbuf->st_ctime=oldbuf->st_ctime; 849 newbuf->st_blksize=0; /* not supported in old_stat */ 850 newbuf->st_blocks=0; /* not supported in old_stat */ 851} 852 853 854static void 855printoldstat(tcp, addr) 856struct tcb *tcp; 857long addr; 858{ 859 struct __old_kernel_stat statbuf; 860 struct stat newstatbuf; 861 862#ifdef LINUXSPARC 863 if (current_personality == 1) { 864 printstatsol(tcp, addr); 865 return; 866 } 867#endif /* LINUXSPARC */ 868 869 if (!addr) { 870 tprintf("NULL"); 871 return; 872 } 873 if (syserror(tcp) || !verbose(tcp)) { 874 tprintf("%#lx", addr); 875 return; 876 } 877 if (umove(tcp, addr, &statbuf) < 0) { 878 tprintf("{...}"); 879 return; 880 } 881 882 convertoldstat(&statbuf, &newstatbuf); 883 realprintstat(tcp, &newstatbuf); 884} 885#endif /* linux && !IA64 */ 886 887#ifndef FREEBSD 888int 889sys_stat(tcp) 890struct tcb *tcp; 891{ 892 if (entering(tcp)) { 893 printpath(tcp, tcp->u_arg[0]); 894 tprintf(", "); 895 } else { 896 printstat(tcp, tcp->u_arg[1]); 897 } 898 return 0; 899} 900#endif 901 902int 903sys_stat64(tcp) 904struct tcb *tcp; 905{ 906#ifdef HAVE_STAT64 907 if (entering(tcp)) { 908 printpath(tcp, tcp->u_arg[0]); 909 tprintf(", "); 910 } else { 911 printstat64(tcp, tcp->u_arg[1]); 912 } 913 return 0; 914#else 915 return printargs(tcp); 916#endif 917} 918 919#ifdef linux 920# if !defined(IA64) 921int 922sys_oldstat(tcp) 923struct tcb *tcp; 924{ 925 if (entering(tcp)) { 926 printpath(tcp, tcp->u_arg[0]); 927 tprintf(", "); 928 } else { 929 printoldstat(tcp, tcp->u_arg[1]); 930 } 931 return 0; 932} 933# endif /* !IA64 */ 934#endif /* linux */ 935 936#ifndef FREEBSD 937int 938sys_fstat(tcp) 939struct tcb *tcp; 940{ 941 if (entering(tcp)) 942 tprintf("%ld, ", tcp->u_arg[0]); 943 else { 944 printstat(tcp, tcp->u_arg[1]); 945 } 946 return 0; 947} 948#endif 949 950int 951sys_fstat64(tcp) 952struct tcb *tcp; 953{ 954#ifdef HAVE_STAT64 955 if (entering(tcp)) 956 tprintf("%ld, ", tcp->u_arg[0]); 957 else { 958 printstat64(tcp, tcp->u_arg[1]); 959 } 960 return 0; 961#else 962 return printargs(tcp); 963#endif 964} 965 966#ifdef linux 967# if !defined(IA64) 968int 969sys_oldfstat(tcp) 970struct tcb *tcp; 971{ 972 if (entering(tcp)) 973 tprintf("%ld, ", tcp->u_arg[0]); 974 else { 975 printoldstat(tcp, tcp->u_arg[1]); 976 } 977 return 0; 978} 979# endif /* !IA64 */ 980#endif 981 982#ifndef FREEBSD 983int 984sys_lstat(tcp) 985struct tcb *tcp; 986{ 987 if (entering(tcp)) { 988 printpath(tcp, tcp->u_arg[0]); 989 tprintf(", "); 990 } else { 991 printstat(tcp, tcp->u_arg[1]); 992 } 993 return 0; 994} 995#endif 996 997int 998sys_lstat64(tcp) 999struct tcb *tcp; 1000{ 1001#ifdef HAVE_STAT64 1002 if (entering(tcp)) { 1003 printpath(tcp, tcp->u_arg[0]); 1004 tprintf(", "); 1005 } else { 1006 printstat64(tcp, tcp->u_arg[1]); 1007 } 1008 return 0; 1009#else 1010 return printargs(tcp); 1011#endif 1012} 1013 1014#ifdef linux 1015# if !defined(IA64) 1016int 1017sys_oldlstat(tcp) 1018struct tcb *tcp; 1019{ 1020 if (entering(tcp)) { 1021 printpath(tcp, tcp->u_arg[0]); 1022 tprintf(", "); 1023 } else { 1024 printoldstat(tcp, tcp->u_arg[1]); 1025 } 1026 return 0; 1027} 1028# endif /* !IA64 */ 1029#endif 1030 1031 1032#if defined(SVR4) || defined(LINUXSPARC) 1033 1034int 1035sys_xstat(tcp) 1036struct tcb *tcp; 1037{ 1038 if (entering(tcp)) { 1039 tprintf("%ld, ", tcp->u_arg[0]); 1040 printpath(tcp, tcp->u_arg[1]); 1041 tprintf(", "); 1042 } else { 1043#ifdef _STAT64_VER 1044 if (tcp->u_arg[0] == _STAT64_VER) 1045 printstat64 (tcp, tcp->u_arg[2]); 1046 else 1047#endif 1048 printstat(tcp, tcp->u_arg[2]); 1049 } 1050 return 0; 1051} 1052 1053int 1054sys_fxstat(tcp) 1055struct tcb *tcp; 1056{ 1057 if (entering(tcp)) 1058 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); 1059 else { 1060#ifdef _STAT64_VER 1061 if (tcp->u_arg[0] == _STAT64_VER) 1062 printstat64 (tcp, tcp->u_arg[2]); 1063 else 1064#endif 1065 printstat(tcp, tcp->u_arg[2]); 1066 } 1067 return 0; 1068} 1069 1070int 1071sys_lxstat(tcp) 1072struct tcb *tcp; 1073{ 1074 if (entering(tcp)) { 1075 tprintf("%ld, ", tcp->u_arg[0]); 1076 printpath(tcp, tcp->u_arg[1]); 1077 tprintf(", "); 1078 } else { 1079#ifdef _STAT64_VER 1080 if (tcp->u_arg[0] == _STAT64_VER) 1081 printstat64 (tcp, tcp->u_arg[2]); 1082 else 1083#endif 1084 printstat(tcp, tcp->u_arg[2]); 1085 } 1086 return 0; 1087} 1088 1089int 1090sys_xmknod(tcp) 1091struct tcb *tcp; 1092{ 1093 int mode = tcp->u_arg[2]; 1094 1095 if (entering(tcp)) { 1096 tprintf("%ld, ", tcp->u_arg[0]); 1097 printpath(tcp, tcp->u_arg[1]); 1098 tprintf(", %s", sprintmode(mode)); 1099 switch (mode & S_IFMT) { 1100 case S_IFCHR: case S_IFBLK: 1101#ifdef LINUXSPARC 1102 tprintf(", makedev(%lu, %lu)", 1103 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff), 1104 (unsigned long) (tcp->u_arg[3] & 0x3ffff)); 1105#else 1106 tprintf(", makedev(%lu, %lu)", 1107 (unsigned long) major(tcp->u_arg[3]), 1108 (unsigned long) minor(tcp->u_arg[3])); 1109#endif 1110 break; 1111 default: 1112 break; 1113 } 1114 } 1115 return 0; 1116} 1117 1118#ifdef HAVE_SYS_ACL_H 1119 1120#include <sys/acl.h> 1121 1122struct xlat aclcmds[] = { 1123#ifdef SETACL 1124 { SETACL, "SETACL" }, 1125#endif 1126#ifdef GETACL 1127 { GETACL, "GETACL" }, 1128#endif 1129#ifdef GETACLCNT 1130 { GETACLCNT, "GETACLCNT" }, 1131#endif 1132#ifdef ACL_GET 1133 { ACL_GET, "ACL_GET" }, 1134#endif 1135#ifdef ACL_SET 1136 { ACL_SET, "ACL_SET" }, 1137#endif 1138#ifdef ACL_CNT 1139 { ACL_CNT, "ACL_CNT" }, 1140#endif 1141 { 0, NULL }, 1142}; 1143 1144int 1145sys_acl(tcp) 1146struct tcb *tcp; 1147{ 1148 if (entering(tcp)) { 1149 printpath(tcp, tcp->u_arg[0]); 1150 tprintf(", "); 1151 printxval(aclcmds, tcp->u_arg[1], "???ACL???"); 1152 tprintf(", %ld", tcp->u_arg[2]); 1153 /* 1154 * FIXME - dump out the list of aclent_t's pointed to 1155 * by "tcp->u_arg[3]" if it's not NULL. 1156 */ 1157 if (tcp->u_arg[3]) 1158 tprintf(", %#lx", tcp->u_arg[3]); 1159 else 1160 tprintf(", NULL"); 1161 } 1162 return 0; 1163} 1164 1165 1166int 1167sys_facl(tcp) 1168struct tcb *tcp; 1169{ 1170 if (entering(tcp)) { 1171 tprintf("%ld, ", tcp->u_arg[0]); 1172 printxval(aclcmds, tcp->u_arg[1], "???ACL???"); 1173 tprintf(", %ld", tcp->u_arg[2]); 1174 /* 1175 * FIXME - dump out the list of aclent_t's pointed to 1176 * by "tcp->u_arg[3]" if it's not NULL. 1177 */ 1178 if (tcp->u_arg[3]) 1179 tprintf(", %#lx", tcp->u_arg[3]); 1180 else 1181 tprintf(", NULL"); 1182 } 1183 return 0; 1184} 1185 1186 1187struct xlat aclipc[] = { 1188#ifdef IPC_SHM 1189 { IPC_SHM, "IPC_SHM" }, 1190#endif 1191#ifdef IPC_SEM 1192 { IPC_SEM, "IPC_SEM" }, 1193#endif 1194#ifdef IPC_MSG 1195 { IPC_MSG, "IPC_MSG" }, 1196#endif 1197 { 0, NULL }, 1198}; 1199 1200 1201int 1202sys_aclipc(tcp) 1203struct tcb *tcp; 1204{ 1205 if (entering(tcp)) { 1206 printxval(aclipc, tcp->u_arg[0], "???IPC???"); 1207 tprintf(", %#lx, ", tcp->u_arg[1]); 1208 printxval(aclcmds, tcp->u_arg[2], "???ACL???"); 1209 tprintf(", %ld", tcp->u_arg[3]); 1210 /* 1211 * FIXME - dump out the list of aclent_t's pointed to 1212 * by "tcp->u_arg[4]" if it's not NULL. 1213 */ 1214 if (tcp->u_arg[4]) 1215 tprintf(", %#lx", tcp->u_arg[4]); 1216 else 1217 tprintf(", NULL"); 1218 } 1219 return 0; 1220} 1221 1222 1223 1224#endif /* HAVE_SYS_ACL_H */ 1225 1226#endif /* SVR4 || LINUXSPARC */ 1227 1228#ifdef linux 1229 1230static struct xlat fsmagic[] = { 1231 { 0x73757245, "CODA_SUPER_MAGIC" }, 1232 { 0x012ff7b7, "COH_SUPER_MAGIC" }, 1233 { 0x1373, "DEVFS_SUPER_MAGIC" }, 1234 { 0x1cd1, "DEVPTS_SUPER_MAGIC" }, 1235 { 0x414A53, "EFS_SUPER_MAGIC" }, 1236 { 0xef51, "EXT2_OLD_SUPER_MAGIC" }, 1237 { 0xef53, "EXT2_SUPER_MAGIC" }, 1238 { 0x137d, "EXT_SUPER_MAGIC" }, 1239 { 0xf995e849, "HPFS_SUPER_MAGIC" }, 1240 { 0x9660, "ISOFS_SUPER_MAGIC" }, 1241 { 0x137f, "MINIX_SUPER_MAGIC" }, 1242 { 0x138f, "MINIX_SUPER_MAGIC2" }, 1243 { 0x2468, "MINIX2_SUPER_MAGIC" }, 1244 { 0x2478, "MINIX2_SUPER_MAGIC2" }, 1245 { 0x4d44, "MSDOS_SUPER_MAGIC" }, 1246 { 0x564c, "NCP_SUPER_MAGIC" }, 1247 { 0x6969, "NFS_SUPER_MAGIC" }, 1248 { 0x9fa0, "PROC_SUPER_MAGIC" }, 1249 { 0x002f, "QNX4_SUPER_MAGIC" }, 1250 { 0x52654973, "REISERFS_SUPER_MAGIC" }, 1251 { 0x02011994, "SHMFS_SUPER_MAGIC" }, 1252 { 0x517b, "SMB_SUPER_MAGIC" }, 1253 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" }, 1254 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" }, 1255 { 0x00011954, "UFS_MAGIC" }, 1256 { 0x54190100, "UFS_CIGAM" }, 1257 { 0x012ff7b4, "XENIX_SUPER_MAGIC" }, 1258 { 0x012fd16d, "XIAFS_SUPER_MAGIC" }, 1259 { 0, NULL }, 1260}; 1261 1262#endif /* linux */ 1263 1264#ifndef SVR4 1265 1266static char * 1267sprintfstype(magic) 1268int magic; 1269{ 1270 static char buf[32]; 1271#ifdef linux 1272 char *s; 1273 1274 s = xlookup(fsmagic, magic); 1275 if (s) { 1276 sprintf(buf, "\"%s\"", s); 1277 return buf; 1278 } 1279#endif /* linux */ 1280 sprintf(buf, "%#x", magic); 1281 return buf; 1282} 1283 1284static void 1285printstatfs(tcp, addr) 1286struct tcb *tcp; 1287long addr; 1288{ 1289 struct statfs statbuf; 1290 1291 if (syserror(tcp) || !verbose(tcp)) { 1292 tprintf("%#lx", addr); 1293 return; 1294 } 1295 if (umove(tcp, addr, &statbuf) < 0) { 1296 tprintf("{...}"); 1297 return; 1298 } 1299#ifdef ALPHA 1300 1301 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ", 1302 sprintfstype(statbuf.f_type), 1303 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree); 1304 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u", 1305 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen); 1306#else /* !ALPHA */ 1307 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ", 1308 sprintfstype(statbuf.f_type), 1309 (unsigned long)statbuf.f_bsize, 1310 (unsigned long)statbuf.f_blocks, 1311 (unsigned long)statbuf.f_bfree); 1312 tprintf("f_files=%lu, f_ffree=%lu", 1313 (unsigned long)statbuf.f_files, 1314 (unsigned long)statbuf.f_ffree); 1315#ifdef linux 1316 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); 1317#endif /* linux */ 1318#endif /* !ALPHA */ 1319 tprintf("}"); 1320} 1321 1322int 1323sys_statfs(tcp) 1324struct tcb *tcp; 1325{ 1326 if (entering(tcp)) { 1327 printpath(tcp, tcp->u_arg[0]); 1328 tprintf(", "); 1329 } else { 1330 printstatfs(tcp, tcp->u_arg[1]); 1331 } 1332 return 0; 1333} 1334 1335int 1336sys_fstatfs(tcp) 1337struct tcb *tcp; 1338{ 1339 if (entering(tcp)) { 1340 tprintf("%lu, ", tcp->u_arg[0]); 1341 } else { 1342 printstatfs(tcp, tcp->u_arg[1]); 1343 } 1344 return 0; 1345} 1346 1347#if defined(linux) && defined(__alpha) 1348 1349int 1350osf_statfs(tcp) 1351struct tcb *tcp; 1352{ 1353 if (entering(tcp)) { 1354 printpath(tcp, tcp->u_arg[0]); 1355 tprintf(", "); 1356 } else { 1357 printstatfs(tcp, tcp->u_arg[1]); 1358 tprintf(", %lu", tcp->u_arg[2]); 1359 } 1360 return 0; 1361} 1362 1363int 1364osf_fstatfs(tcp) 1365struct tcb *tcp; 1366{ 1367 if (entering(tcp)) { 1368 tprintf("%lu, ", tcp->u_arg[0]); 1369 } else { 1370 printstatfs(tcp, tcp->u_arg[1]); 1371 tprintf(", %lu", tcp->u_arg[2]); 1372 } 1373 return 0; 1374} 1375#endif /* linux && __alpha */ 1376 1377#endif /* !SVR4 */ 1378 1379#ifdef SUNOS4 1380 1381int 1382sys_ustat(tcp) 1383struct tcb *tcp; 1384{ 1385 struct ustat statbuf; 1386 1387 if (entering(tcp)) { 1388 tprintf("makedev(%lu, %lu), ", 1389 (long) major(tcp->u_arg[0]), 1390 (long) minor(tcp->u_arg[0])); 1391 } 1392 else { 1393 if (syserror(tcp) || !verbose(tcp)) 1394 tprintf("%#lx", tcp->u_arg[1]); 1395 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0) 1396 tprintf("{...}"); 1397 else { 1398 tprintf("{f_tfree=%lu, f_tinode=%lu, ", 1399 statbuf.f_tfree, statbuf.f_tinode); 1400 tprintf("f_fname=\"%.*s\", ", 1401 (int) sizeof(statbuf.f_fname), 1402 statbuf.f_fname); 1403 tprintf("f_fpack=\"%.*s\"}", 1404 (int) sizeof(statbuf.f_fpack), 1405 statbuf.f_fpack); 1406 } 1407 } 1408 return 0; 1409} 1410 1411#endif /* SUNOS4 */ 1412 1413int 1414sys_pivotroot(tcp) 1415struct tcb *tcp; 1416{ 1417 if (entering(tcp)) { 1418 printpath(tcp, tcp->u_arg[0]); 1419 tprintf(", "); 1420 printpath(tcp, tcp->u_arg[1]); 1421 } 1422 return 0; 1423} 1424 1425 1426/* directory */ 1427int 1428sys_chdir(tcp) 1429struct tcb *tcp; 1430{ 1431 if (entering(tcp)) { 1432 printpath(tcp, tcp->u_arg[0]); 1433 } 1434 return 0; 1435} 1436 1437int 1438sys_mkdir(tcp) 1439struct tcb *tcp; 1440{ 1441 if (entering(tcp)) { 1442 printpath(tcp, tcp->u_arg[0]); 1443 tprintf(", %#lo", tcp->u_arg[1]); 1444 } 1445 return 0; 1446} 1447 1448int 1449sys_rmdir(tcp) 1450struct tcb *tcp; 1451{ 1452 if (entering(tcp)) { 1453 printpath(tcp, tcp->u_arg[0]); 1454 } 1455 return 0; 1456} 1457 1458int 1459sys_fchdir(tcp) 1460struct tcb *tcp; 1461{ 1462 if (entering(tcp)) { 1463 tprintf("%ld", tcp->u_arg[0]); 1464 } 1465 return 0; 1466} 1467 1468int 1469sys_chroot(tcp) 1470struct tcb *tcp; 1471{ 1472 if (entering(tcp)) { 1473 printpath(tcp, tcp->u_arg[0]); 1474 } 1475 return 0; 1476} 1477 1478int 1479sys_fchroot(tcp) 1480struct tcb *tcp; 1481{ 1482 if (entering(tcp)) { 1483 tprintf("%ld", tcp->u_arg[0]); 1484 } 1485 return 0; 1486} 1487 1488int 1489sys_link(tcp) 1490struct tcb *tcp; 1491{ 1492 if (entering(tcp)) { 1493 printpath(tcp, tcp->u_arg[0]); 1494 tprintf(", "); 1495 printpath(tcp, tcp->u_arg[1]); 1496 } 1497 return 0; 1498} 1499 1500int 1501sys_unlink(tcp) 1502struct tcb *tcp; 1503{ 1504 if (entering(tcp)) { 1505 printpath(tcp, tcp->u_arg[0]); 1506 } 1507 return 0; 1508} 1509 1510int 1511sys_symlink(tcp) 1512struct tcb *tcp; 1513{ 1514 if (entering(tcp)) { 1515 printpath(tcp, tcp->u_arg[0]); 1516 tprintf(", "); 1517 printpath(tcp, tcp->u_arg[1]); 1518 } 1519 return 0; 1520} 1521 1522int 1523sys_readlink(tcp) 1524struct tcb *tcp; 1525{ 1526 if (entering(tcp)) { 1527 printpath(tcp, tcp->u_arg[0]); 1528 tprintf(", "); 1529 } else { 1530 if (syserror(tcp)) 1531 tprintf("%#lx", tcp->u_arg[1]); 1532 else 1533 printpathn(tcp, tcp->u_arg[1], tcp->u_rval); 1534 tprintf(", %lu", tcp->u_arg[2]); 1535 } 1536 return 0; 1537} 1538 1539int 1540sys_rename(tcp) 1541struct tcb *tcp; 1542{ 1543 if (entering(tcp)) { 1544 printpath(tcp, tcp->u_arg[0]); 1545 tprintf(", "); 1546 printpath(tcp, tcp->u_arg[1]); 1547 } 1548 return 0; 1549} 1550 1551int 1552sys_chown(tcp) 1553struct tcb *tcp; 1554{ 1555 if (entering(tcp)) { 1556 printpath(tcp, tcp->u_arg[0]); 1557 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]); 1558 } 1559 return 0; 1560} 1561 1562int 1563sys_fchown(tcp) 1564struct tcb *tcp; 1565{ 1566 if (entering(tcp)) { 1567 tprintf("%ld, %lu, %lu", 1568 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); 1569 } 1570 return 0; 1571} 1572 1573int 1574sys_chmod(tcp) 1575struct tcb *tcp; 1576{ 1577 if (entering(tcp)) { 1578 printpath(tcp, tcp->u_arg[0]); 1579 tprintf(", %#lo", tcp->u_arg[1]); 1580 } 1581 return 0; 1582} 1583 1584int 1585sys_fchmod(tcp) 1586struct tcb *tcp; 1587{ 1588 if (entering(tcp)) { 1589 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]); 1590 } 1591 return 0; 1592} 1593 1594#ifdef ALPHA 1595int 1596sys_osf_utimes(tcp) 1597struct tcb *tcp; 1598{ 1599 if (entering(tcp)) { 1600 printpath(tcp, tcp->u_arg[0]); 1601 tprintf(", "); 1602 printtv32(tcp, tcp->u_arg[1]); 1603 } 1604 return 0; 1605} 1606#endif 1607 1608int 1609sys_utimes(tcp) 1610struct tcb *tcp; 1611{ 1612 if (entering(tcp)) { 1613 printpath(tcp, tcp->u_arg[0]); 1614 tprintf(", "); 1615 printtv(tcp, tcp->u_arg[1]); 1616 } 1617 return 0; 1618} 1619 1620int 1621sys_utime(tcp) 1622struct tcb *tcp; 1623{ 1624 long ut[2]; 1625 1626 if (entering(tcp)) { 1627 printpath(tcp, tcp->u_arg[0]); 1628 tprintf(", "); 1629 if (!tcp->u_arg[1]) 1630 tprintf("NULL"); 1631 else if (!verbose(tcp)) 1632 tprintf("%#lx", tcp->u_arg[1]); 1633 else if (umoven(tcp, tcp->u_arg[1], sizeof ut, 1634 (char *) ut) < 0) 1635 tprintf("[?, ?]"); 1636 else { 1637 tprintf("[%s,", sprinttime(ut[0])); 1638 tprintf(" %s]", sprinttime(ut[1])); 1639 } 1640 } 1641 return 0; 1642} 1643 1644int 1645sys_mknod(tcp) 1646struct tcb *tcp; 1647{ 1648 int mode = tcp->u_arg[1]; 1649 1650 if (entering(tcp)) { 1651 printpath(tcp, tcp->u_arg[0]); 1652 tprintf(", %s", sprintmode(mode)); 1653 switch (mode & S_IFMT) { 1654 case S_IFCHR: case S_IFBLK: 1655#ifdef LINUXSPARC 1656 if (current_personality == 1) 1657 tprintf(", makedev(%lu, %lu)", 1658 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff), 1659 (unsigned long) (tcp->u_arg[2] & 0x3ffff)); 1660 else 1661#endif 1662 tprintf(", makedev(%lu, %lu)", 1663 (unsigned long) major(tcp->u_arg[2]), 1664 (unsigned long) minor(tcp->u_arg[2])); 1665 break; 1666 default: 1667 break; 1668 } 1669 } 1670 return 0; 1671} 1672 1673int 1674sys_mkfifo(tcp) 1675struct tcb *tcp; 1676{ 1677 if (entering(tcp)) { 1678 printpath(tcp, tcp->u_arg[0]); 1679 tprintf(", %#lo", tcp->u_arg[1]); 1680 } 1681 return 0; 1682} 1683 1684int 1685sys_fsync(tcp) 1686struct tcb *tcp; 1687{ 1688 if (entering(tcp)) { 1689 tprintf("%ld", tcp->u_arg[0]); 1690 } 1691 return 0; 1692} 1693 1694#ifdef linux 1695 1696static void 1697printdir(tcp, addr) 1698struct tcb *tcp; 1699long addr; 1700{ 1701 struct dirent d; 1702 1703 if (!verbose(tcp)) { 1704 tprintf("%#lx", addr); 1705 return; 1706 } 1707 if (umove(tcp, addr, &d) < 0) { 1708 tprintf("{...}"); 1709 return; 1710 } 1711 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino); 1712 tprintf("d_name="); 1713 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen); 1714 tprintf("}"); 1715} 1716 1717int 1718sys_readdir(tcp) 1719struct tcb *tcp; 1720{ 1721 if (entering(tcp)) { 1722 tprintf("%lu, ", tcp->u_arg[0]); 1723 } else { 1724 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp)) 1725 tprintf("%#lx", tcp->u_arg[1]); 1726 else 1727 printdir(tcp, tcp->u_arg[1]); 1728 /* Not much point in printing this out, it is always 1. */ 1729 if (tcp->u_arg[2] != 1) 1730 tprintf(", %lu", tcp->u_arg[2]); 1731 } 1732 return 0; 1733} 1734 1735#endif /* linux */ 1736 1737#ifdef FREEBSD 1738struct xlat direnttypes[] = { 1739 { DT_FIFO, "DT_FIFO" }, 1740 { DT_CHR, "DT_CHR" }, 1741 { DT_DIR, "DT_DIR" }, 1742 { DT_BLK, "DT_BLK" }, 1743 { DT_REG, "DT_REG" }, 1744 { DT_LNK, "DT_LNK" }, 1745 { DT_SOCK, "DT_SOCK" }, 1746 { DT_WHT, "DT_WHT" }, 1747 { 0, NULL }, 1748}; 1749 1750#endif 1751 1752int 1753sys_getdents(tcp) 1754struct tcb *tcp; 1755{ 1756 int i, len, dents = 0; 1757 char *buf; 1758 1759 if (entering(tcp)) { 1760 tprintf("%lu, ", tcp->u_arg[0]); 1761 return 0; 1762 } 1763 if (syserror(tcp) || !verbose(tcp)) { 1764 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]); 1765 return 0; 1766 } 1767 len = tcp->u_rval; 1768 if ((buf = malloc(len)) == NULL) { 1769 tprintf("out of memory\n"); 1770 return 0; 1771 } 1772 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) { 1773 tprintf("{...}, %lu", tcp->u_arg[2]); 1774 free(buf); 1775 return 0; 1776 } 1777 if (!abbrev(tcp)) 1778 tprintf("{"); 1779 for (i = 0; i < len;) { 1780 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i]; 1781#ifdef linux 1782 if (!abbrev(tcp)) { 1783 tprintf("%s{d_ino=%lu, d_off=%lu, ", 1784 i ? " " : "", d->d_ino, d->d_off); 1785 tprintf("d_reclen=%u, d_name=\"%s\"}", 1786 d->d_reclen, d->d_name); 1787 } 1788#endif /* linux */ 1789#ifdef SVR4 1790 if (!abbrev(tcp)) { 1791 tprintf("%s{d_ino=%lu, d_off=%lu, ", 1792 i ? " " : "", d->d_ino, d->d_off); 1793 tprintf("d_reclen=%u, d_name=\"%s\"}", 1794 d->d_reclen, d->d_name); 1795 } 1796#endif /* SVR4 */ 1797#ifdef SUNOS4 1798 if (!abbrev(tcp)) { 1799 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ", 1800 i ? " " : "", d->d_off, d->d_fileno, 1801 d->d_reclen); 1802 tprintf("d_namlen=%u, d_name=\"%.*s\"}", 1803 d->d_namlen, d->d_namlen, d->d_name); 1804 } 1805#endif /* SUNOS4 */ 1806#ifdef FREEBSD 1807 if (!abbrev(tcp)) { 1808 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=", 1809 i ? " " : "", d->d_fileno, d->d_reclen); 1810 printxval(direnttypes, d->d_type, "DT_???"); 1811 tprintf(", d_namlen=%u, d_name=\"%.*s\"}", 1812 d->d_namlen, d->d_namlen, d->d_name); 1813 } 1814#endif /* FREEBSD */ 1815 if (!d->d_reclen) { 1816 tprintf("/* d_reclen == 0, problem here */"); 1817 break; 1818 } 1819 i += d->d_reclen; 1820 dents++; 1821 } 1822 if (!abbrev(tcp)) 1823 tprintf("}"); 1824 else 1825 tprintf("/* %u entries */", dents); 1826 tprintf(", %lu", tcp->u_arg[2]); 1827 free(buf); 1828 return 0; 1829} 1830 1831 1832#if _LFS64_LARGEFILE 1833int 1834sys_getdents64(tcp) 1835struct tcb *tcp; 1836{ 1837 int i, len, dents = 0; 1838 char *buf; 1839 1840 if (entering(tcp)) { 1841 tprintf("%lu, ", tcp->u_arg[0]); 1842 return 0; 1843 } 1844 if (syserror(tcp) || !verbose(tcp)) { 1845 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]); 1846 return 0; 1847 } 1848 len = tcp->u_rval; 1849 if ((buf = malloc(len)) == NULL) { 1850 tprintf("out of memory\n"); 1851 return 0; 1852 } 1853 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) { 1854 tprintf("{...}, %lu", tcp->u_arg[2]); 1855 free(buf); 1856 return 0; 1857 } 1858 if (!abbrev(tcp)) 1859 tprintf("{"); 1860 for (i = 0; i < len;) { 1861 struct dirent64 *d = (struct dirent64 *) &buf[i]; 1862#ifdef linux 1863 if (!abbrev(tcp)) { 1864 tprintf("%s{d_ino=%lu, d_off=%lu, ", 1865 i ? " " : "", d->d_ino, d->d_off); 1866 tprintf("d_reclen=%u, d_name=\"%s\"}", 1867 d->d_reclen, d->d_name); 1868 } 1869#endif /* linux */ 1870#ifdef SVR4 1871 if (!abbrev(tcp)) { 1872 tprintf("%s{d_ino=%llu, d_off=%llu, ", 1873 i ? " " : "", d->d_ino, d->d_off); 1874 tprintf("d_reclen=%u, d_name=\"%s\"}", 1875 d->d_reclen, d->d_name); 1876 } 1877#endif /* SVR4 */ 1878#ifdef SUNOS4 1879 if (!abbrev(tcp)) { 1880 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ", 1881 i ? " " : "", d->d_off, d->d_fileno, 1882 d->d_reclen); 1883 tprintf("d_namlen=%u, d_name=\"%.*s\"}", 1884 d->d_namlen, d->d_namlen, d->d_name); 1885 } 1886#endif /* SUNOS4 */ 1887 i += d->d_reclen; 1888 dents++; 1889 } 1890 if (!abbrev(tcp)) 1891 tprintf("}"); 1892 else 1893 tprintf("/* %u entries */", dents); 1894 tprintf(", %lu", tcp->u_arg[2]); 1895 free(buf); 1896 return 0; 1897} 1898#endif 1899 1900#ifdef FREEBSD 1901int 1902sys_getdirentries(tcp) 1903struct tcb * tcp; 1904{ 1905 int i, len, dents = 0; 1906 long basep; 1907 char *buf; 1908 1909 if (entering(tcp)) { 1910 tprintf("%lu, ", tcp->u_arg[0]); 1911 return 0; 1912 } 1913 if (syserror(tcp) || !verbose(tcp)) { 1914 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]); 1915 return 0; 1916 } 1917 len = tcp->u_rval; 1918 if ((buf = malloc(len)) == NULL) { 1919 tprintf("out of memory\n"); 1920 return 0; 1921 } 1922 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) { 1923 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]); 1924 free(buf); 1925 return 0; 1926 } 1927 if (!abbrev(tcp)) 1928 tprintf("{"); 1929 for (i = 0; i < len;) { 1930 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i]; 1931 if (!abbrev(tcp)) { 1932 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=", 1933 i ? " " : "", d->d_fileno, d->d_reclen); 1934 printxval(direnttypes, d->d_type, "DT_???"); 1935 tprintf(", d_namlen=%u, d_name=\"%.*s\"}", 1936 d->d_namlen, d->d_namlen, d->d_name); 1937 } 1938 i += d->d_reclen; 1939 dents++; 1940 } 1941 if (!abbrev(tcp)) 1942 tprintf("}"); 1943 else 1944 tprintf("/* %u entries */", dents); 1945 free(buf); 1946 tprintf(", %lu", tcp->u_arg[2]); 1947 if (umove(tcp, tcp->u_arg[3], &basep) < 0) 1948 tprintf(", %#lx", tcp->u_arg[3]); 1949 else 1950 tprintf(", [%lu]", basep); 1951 return 0; 1952} 1953#endif 1954 1955#ifdef linux 1956int 1957sys_getcwd(tcp) 1958struct tcb *tcp; 1959{ 1960 if (exiting(tcp)) { 1961 if (syserror(tcp)) 1962 tprintf("%#lx", tcp->u_arg[0]); 1963 else 1964 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1); 1965 tprintf(", %lu", tcp->u_arg[1]); 1966 } 1967 return 0; 1968} 1969#endif /* linux */ 1970 1971#ifdef FREEBSD 1972int 1973sys___getcwd(tcp) 1974struct tcb *tcp; 1975{ 1976 if (exiting(tcp)) { 1977 if (syserror(tcp)) 1978 tprintf("%#lx", tcp->u_arg[0]); 1979 else 1980 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]); 1981 tprintf(", %lu", tcp->u_arg[1]); 1982 } 1983 return 0; 1984} 1985#endif 1986 1987#ifdef HAVE_SYS_ASYNCH_H 1988 1989int 1990sys_aioread(tcp) 1991struct tcb *tcp; 1992{ 1993 struct aio_result_t res; 1994 1995 if (entering(tcp)) { 1996 tprintf("%lu, ", tcp->u_arg[0]); 1997 } else { 1998 if (syserror(tcp)) 1999 tprintf("%#lx", tcp->u_arg[1]); 2000 else 2001 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); 2002 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]); 2003 printxval(whence, tcp->u_arg[4], "L_???"); 2004 if (syserror(tcp) || tcp->u_arg[5] == 0 2005 || umove(tcp, tcp->u_arg[5], &res) < 0) 2006 tprintf(", %#lx", tcp->u_arg[5]); 2007 else 2008 tprintf(", {aio_return %d aio_errno %d}", 2009 res.aio_return, res.aio_errno); 2010 } 2011 return 0; 2012} 2013 2014int 2015sys_aiowrite(tcp) 2016struct tcb *tcp; 2017{ 2018 struct aio_result_t res; 2019 2020 if (entering(tcp)) { 2021 tprintf("%lu, ", tcp->u_arg[0]); 2022 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); 2023 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]); 2024 printxval(whence, tcp->u_arg[4], "L_???"); 2025 } 2026 else { 2027 if (tcp->u_arg[5] == 0) 2028 tprintf(", NULL"); 2029 else if (syserror(tcp) 2030 || umove(tcp, tcp->u_arg[5], &res) < 0) 2031 tprintf(", %#lx", tcp->u_arg[5]); 2032 else 2033 tprintf(", {aio_return %d aio_errno %d}", 2034 res.aio_return, res.aio_errno); 2035 } 2036 return 0; 2037} 2038 2039int 2040sys_aiowait(tcp) 2041struct tcb *tcp; 2042{ 2043 if (entering(tcp)) 2044 printtv(tcp, tcp->u_arg[0]); 2045 return 0; 2046} 2047 2048int 2049sys_aiocancel(tcp) 2050struct tcb *tcp; 2051{ 2052 struct aio_result_t res; 2053 2054 if (exiting(tcp)) { 2055 if (tcp->u_arg[0] == 0) 2056 tprintf("NULL"); 2057 else if (syserror(tcp) 2058 || umove(tcp, tcp->u_arg[0], &res) < 0) 2059 tprintf("%#lx", tcp->u_arg[0]); 2060 else 2061 tprintf("{aio_return %d aio_errno %d}", 2062 res.aio_return, res.aio_errno); 2063 } 2064 return 0; 2065} 2066 2067#endif /* HAVE_SYS_ASYNCH_H */ 2068