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