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 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #if HAVE_LONG_LONG_OFF_T
40 * Hacks for systems that have a long long off_t
42 #define flock64 flock /* Horrid hack */
43 #define printflock printflock64 /* Horrider hack */
47 static const struct xlat fcntlcmds[] = {
48 { F_DUPFD, "F_DUPFD" },
49 { F_GETFD, "F_GETFD" },
50 { F_SETFD, "F_SETFD" },
51 { F_GETFL, "F_GETFL" },
52 { F_SETFL, "F_SETFL" },
53 { F_GETLK, "F_GETLK" },
54 { F_SETLK, "F_SETLK" },
55 { F_SETLKW, "F_SETLKW" },
56 { F_GETOWN, "F_GETOWN" },
57 { F_SETOWN, "F_SETOWN" },
59 { F_RSETLK, "F_RSETLK" },
62 { F_RSETLKW, "F_RSETLKW" },
65 { F_RGETLK, "F_RGETLK" },
71 { F_SETSIG, "F_SETSIG" },
74 { F_GETSIG, "F_GETSIG" },
77 { F_CHKFL, "F_CHKFL" },
80 { F_DUP2FD, "F_DUP2FD" },
83 { F_ALLOCSP, "F_ALLOCSP" },
86 { F_ISSTREAM, "F_ISSTREAM" },
92 { F_NPRIV, "F_NPRIV" },
95 { F_QUOTACL, "F_QUOTACL" },
98 { F_BLOCKS, "F_BLOCKS" },
101 { F_BLKSIZE, "F_BLKSIZE" },
104 { F_GETOWN, "F_GETOWN" },
107 { F_SETOWN, "F_SETOWN" },
110 { F_REVOKE, "F_REVOKE" },
113 { F_SETLK, "F_SETLK" },
116 { F_SETLKW, "F_SETLKW" },
119 { F_FREESP, "F_FREESP" },
122 { F_GETLK, "F_GETLK" },
125 { F_SETLK64, "F_SETLK64" },
128 { F_SETLKW64, "F_SETLKW64" },
131 { F_FREESP64, "F_FREESP64" },
134 { F_GETLK64, "F_GETLK64" },
137 { F_SHARE, "F_SHARE" },
140 { F_UNSHARE, "F_UNSHARE" },
145 static const struct xlat fdflags[] = {
147 { FD_CLOEXEC, "FD_CLOEXEC" },
154 static const struct xlat flockcmds[] = {
155 { LOCK_SH, "LOCK_SH" },
156 { LOCK_EX, "LOCK_EX" },
157 { LOCK_NB, "LOCK_NB" },
158 { LOCK_UN, "LOCK_UN" },
164 static const struct xlat lockfcmds[] = {
165 { F_RDLCK, "F_RDLCK" },
166 { F_WRLCK, "F_WRLCK" },
167 { F_UNLCK, "F_UNLCK" },
169 { F_EXLCK, "F_EXLCK" },
172 { F_SHLCK, "F_SHLCK" },
177 static const struct xlat whence[] = {
178 { SEEK_SET, "SEEK_SET" },
179 { SEEK_CUR, "SEEK_CUR" },
180 { SEEK_END, "SEEK_END" },
184 #ifndef HAVE_LONG_LONG_OFF_T
187 printflock(tcp, addr, getlk)
194 if (umove(tcp, addr, &fl) < 0) {
199 printxval(lockfcmds, fl.l_type, "F_???");
200 tprintf(", whence=");
201 printxval(whence, fl.l_whence, "SEEK_???");
202 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
204 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
210 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
213 printflock64(tcp, addr, getlk)
220 if (umove(tcp, addr, &fl) < 0) {
225 printxval(lockfcmds, fl.l_type, "F_???");
226 tprintf(", whence=");
227 printxval(whence, fl.l_whence, "SEEK_???");
228 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
230 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
237 sprintflags(xlat, flags)
238 const struct xlat *xlat;
241 static char outstr[1024];
244 strcpy(outstr, "flags ");
246 for (; xlat->str; xlat++) {
247 if ((flags & xlat->val) == xlat->val) {
248 sprintf(outstr + strlen(outstr),
249 "%s%s", sep, xlat->str);
255 sprintf(outstr + strlen(outstr),
256 "%s%#x", sep, flags);
264 extern const struct xlat openmodes[];
267 tprintf("%ld, ", tcp->u_arg[0]);
268 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
269 switch (tcp->u_arg[1]) {
272 if (printflags(fdflags, tcp->u_arg[2]) == 0)
275 case F_SETOWN: case F_DUPFD:
276 tprintf(", %ld", tcp->u_arg[2]);
280 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
283 case F_SETLK: case F_SETLKW:
288 printflock(tcp, tcp->u_arg[2], 0);
294 /* Linux glibc defines SETLK64 as SETLK,
295 even though the kernel has different values - as does Solaris. */
296 #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
299 #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
303 printflock64(tcp, tcp->u_arg[2], 0);
309 switch (tcp->u_arg[1]) {
311 case F_SETFD: case F_SETFL:
312 case F_SETLK: case F_SETLKW:
313 case F_SETOWN: case F_GETOWN:
316 if (tcp->u_rval == 0)
318 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
319 return RVAL_HEX|RVAL_STR;
321 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
322 return RVAL_HEX|RVAL_STR;
325 printflock(tcp, tcp->u_arg[2], 1);
328 #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
332 printflock64(tcp, tcp->u_arg[2], 1);
336 tprintf(", %#lx", tcp->u_arg[2]);
350 tprintf("%ld, ", tcp->u_arg[0]);
351 if (!printflags(flockcmds, tcp->u_arg[1]))
363 tprintf("%ld", tcp->u_arg[0]);
373 tprintf("%ld", tcp->u_arg[0]);
383 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
389 sys_getdtablesize(tcp)
396 decode_select(tcp, args, bitness)
410 static char outstr[1024];
417 for (i = 0; i < 3; i++) {
424 tprintf(", %#lx", arg);
427 if (umove(tcp, arg, &fds) < 0) {
432 for (j = 0, sep = ""; j < nfds; j++) {
433 if (FD_ISSET(j, &fds)) {
434 tprintf("%s%u", sep, j);
442 else if (!verbose(tcp))
443 tprintf(", %#lx", args[4]);
444 else if (umove(tcp, args[4], &tv) < 0)
449 tv32=(struct timeval32*)&tv;
450 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
453 tprintf(", {%lu, %lu}",
454 (long) tv.tv_sec, (long) tv.tv_usec);
459 unsigned int cumlen = 0;
465 if ((nfds = tcp->u_rval) == 0) {
466 tcp->auxstr = "Timeout";
470 for (i = 0; i < 3; i++) {
474 tcp->auxstr = outstr;
476 if (!arg || umove(tcp, arg, &fds) < 0)
478 for (j = 0; j < args[0]; j++) {
479 if (FD_ISSET(j, &fds)) {
481 sprintf(str, "%s%s [%u", sep,
489 sprintf(str, " %u", j);
490 cumlen += strlen(str);
491 if (cumlen < sizeof(outstr))
502 /* This contains no useful information on SunOS. */
506 if (umove(tcp, args[4], &tv) >= 0) {
509 tv32=(struct timeval32*)&tv;
510 sprintf(str, "%sleft {%u, %u}", sep,
511 tv32->tv_sec, tv32->tv_usec);
514 sprintf(str, "%sleft {%lu, %lu}", sep,
515 (long) tv.tv_sec, (long) tv.tv_usec);
517 if ((cumlen += strlen(str)) < sizeof(outstr))
535 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
539 return decode_select(tcp, args, 0);
547 long *args = tcp->u_arg;
548 return decode_select(tcp, args, 1);
558 long *args = tcp->u_arg;
559 return decode_select(tcp, args, 0);