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.
35 #include <sys/resource.h>
37 #include <sys/times.h>
38 #include <linux/kernel.h>
39 #include <sys/quota.h>
42 #include <ufs/quota.h>
44 #if defined(SVR4) || defined(FREEBSD)
45 #include <sys/times.h>
49 #if HAVE_LONG_LONG_RLIM_T
51 * Hacks for systems that have a long long rlim_t
54 #define rlimit64 rlimit /* Ugly hack */
55 #define rlim64_t rlim_t /* Ugly hack */
56 #define RLIM64_INFINITY RLIM_INFINITY /* You guessed it */
58 #define sys_getrlimit64 sys_getrlimit
59 #define sys_setrlimit64 sys_setrlimit
62 static const struct xlat resources[] = {
64 { RLIMIT_CPU, "RLIMIT_CPU" },
67 { RLIMIT_FSIZE, "RLIMIT_FSIZE" },
70 { RLIMIT_DATA, "RLIMIT_DATA" },
73 { RLIMIT_STACK, "RLIMIT_STACK" },
76 { RLIMIT_CORE, "RLIMIT_CORE" },
79 { RLIMIT_RSS, "RLIMIT_RSS" },
82 { RLIMIT_NPROC,"RLIMIT_NPROC" },
85 { RLIMIT_NOFILE,"RLIMIT_NOFILE" },
88 { RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK" },
91 { RLIMIT_VMEM, "RLIMIT_VMEM" },
94 { RLIMIT_AS, "RLIMIT_AS" },
97 { RLIMIT_LOCKS, "RLIMIT_LOCKS" },
99 #ifdef RLIMIT_SIGPENDING
100 { RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING" },
102 #ifdef RLIMIT_MSGQUEUE
103 { RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE" },
108 #if !HAVE_LONG_LONG_RLIM_T
115 if (lim == RLIM_INFINITY)
116 sprintf(buf, "RLIM_INFINITY");
117 else if (lim > 1024 && lim%1024 == 0)
118 sprintf(buf, "%ld*1024", lim/1024);
120 sprintf(buf, "%ld", lim);
131 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
135 if (syserror(tcp) || !verbose(tcp))
136 tprintf("%#lx", tcp->u_arg[1]);
137 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
140 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
141 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
154 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
157 tprintf("%#lx", tcp->u_arg[1]);
158 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
161 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
162 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
167 #endif /* !HAVE_LONG_LONG_RLIM_T */
169 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T
176 if (lim == RLIM64_INFINITY)
177 sprintf(buf, "RLIM64_INFINITY");
178 else if (lim > 1024 && lim%1024 == 0)
179 sprintf(buf, "%lld*1024", (long long) lim/1024);
181 sprintf(buf, "%lld", (long long) lim);
189 struct rlimit64 rlim;
192 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
196 if (syserror(tcp) || !verbose(tcp))
197 tprintf("%#lx", tcp->u_arg[1]);
198 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
201 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
202 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
212 struct rlimit64 rlim;
215 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
218 tprintf("%#lx", tcp->u_arg[1]);
219 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
222 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
223 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
228 #endif /* _LFS64_LARGEFILES || HAVE_LONG_LONG_RLIM_T */
232 static const struct xlat usagewho[] = {
233 { RUSAGE_SELF, "RUSAGE_SELF" },
234 { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" },
236 { RUSAGE_BOTH, "RUSAGE_BOTH" },
243 printrusage32(tcp, addr)
254 struct timeval32 ru_utime; /* user time used */
255 struct timeval32 ru_stime; /* system time used */
256 long ru_maxrss; /* maximum resident set size */
257 long ru_ixrss; /* integral shared memory size */
258 long ru_idrss; /* integral unshared data size */
259 long ru_isrss; /* integral unshared stack size */
260 long ru_minflt; /* page reclaims */
261 long ru_majflt; /* page faults */
262 long ru_nswap; /* swaps */
263 long ru_inblock; /* block input operations */
264 long ru_oublock; /* block output operations */
265 long ru_msgsnd; /* messages sent */
266 long ru_msgrcv; /* messages received */
267 long ru_nsignals; /* signals received */
268 long ru_nvcsw; /* voluntary context switches */
269 long ru_nivcsw; /* involuntary " */
274 else if (syserror(tcp) || !verbose(tcp))
275 tprintf("%#lx", addr);
276 else if (umove(tcp, addr, &ru) < 0)
278 else if (!abbrev(tcp)) {
279 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
280 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
281 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
282 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
283 ru.ru_maxrss, ru.ru_ixrss);
284 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
285 ru.ru_idrss, ru.ru_isrss);
286 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
287 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
288 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
289 ru.ru_inblock, ru.ru_oublock);
290 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
291 ru.ru_msgsnd, ru.ru_msgrcv);
292 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
293 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
296 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
297 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
298 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
304 printrusage(tcp, addr)
312 else if (syserror(tcp) || !verbose(tcp))
313 tprintf("%#lx", addr);
314 else if (umove(tcp, addr, &ru) < 0)
316 else if (!abbrev(tcp)) {
317 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
318 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
319 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
320 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
321 ru.ru_maxrss, ru.ru_ixrss);
322 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
323 ru.ru_idrss, ru.ru_isrss);
324 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
325 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
326 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
327 ru.ru_inblock, ru.ru_oublock);
328 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
329 ru.ru_msgsnd, ru.ru_msgrcv);
330 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
331 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
334 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
335 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
336 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
345 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
349 printrusage(tcp, tcp->u_arg[1]);
355 sys_osf_getrusage(tcp)
359 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
363 printrusage32(tcp, tcp->u_arg[1]);
379 if (syserror(tcp) || !verbose(tcp))
380 tprintf("%#lx", tcp->u_arg[0]);
381 else if (umove(tcp, tcp->u_arg[0], &si) < 0)
384 tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ",
385 si.uptime, si.loads[0], si.loads[1],
387 tprintf("totalram=%lu, freeram=%lu, ",
388 si.totalram, si.freeram);
389 tprintf("sharedram=%lu, bufferram=%lu} ",
390 si.sharedram, si.bufferram);
391 tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}",
392 si.totalswap, si.freeswap, si.procs);
400 static const struct xlat priorities[] = {
401 { PRIO_PROCESS, "PRIO_PROCESS" },
402 { PRIO_PGRP, "PRIO_PGRP" },
403 { PRIO_USER, "PRIO_USER" },
412 printxval(priorities, tcp->u_arg[0], "PRIO_???");
413 tprintf(", %lu", tcp->u_arg[1]);
423 printxval(priorities, tcp->u_arg[0], "PRIO_???");
424 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
434 tprintf("%ld", tcp->u_arg[0]);
447 if (tcp->u_arg[0] == 0)
449 else if (syserror(tcp))
450 tprintf("%#lx", tcp->u_arg[0]);
451 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
454 tprintf("{tms_utime=%lu, tms_stime=%lu, ",
455 tbuf.tms_utime, tbuf.tms_stime);
456 tprintf("tms_cutime=%lu, tms_cstime=%lu}",
457 tbuf.tms_cutime, tbuf.tms_cstime);
467 #define OLD_CMD(c) ((c)<<8)
468 #define NEW_CMD(c) ((0x80<<16)+(c))
469 #define XQM_CMD(c) (('X'<<8)+(c))
470 #define NEW_COMMAND(c) (( ((c) >> SUBCMDSHIFT) & (0x80 << 16)))
471 #define XQM_COMMAND(c) (( ((c) >> SUBCMDSHIFT) & ('X' << 8)) == ('X' << 8))
472 #define OLD_COMMAND(c) (!NEW_COMMAND(c) && !XQM_COMMAND(c))
474 static const struct xlat quotacmds[] = {
475 { OLD_CMD(0x1), "Q_QUOTAON" },
476 { OLD_CMD(0x2), "Q_QUOTAOFF" },
477 { OLD_CMD(0x3), "Q_GETQUOTA" },
478 { OLD_CMD(0x4), "Q_SETQUOTA" },
479 { OLD_CMD(0x5), "Q_SETUSE" },
480 { OLD_CMD(0x6), "Q_SYNC" },
481 { OLD_CMD(0x7), "Q_SETQLIM" },
482 { OLD_CMD(0x8), "Q_GETSTATS" },
483 { OLD_CMD(0x10),"Q_RSQUASH" },
484 { NEW_CMD(0x1), "Q_SYNC" },
485 { NEW_CMD(0x2), "Q_QUOTAON" },
486 { NEW_CMD(0x3), "Q_QUOTAOFF" },
487 { NEW_CMD(0x4), "Q_GETFMT" },
488 { NEW_CMD(0x5), "Q_GETINFO" },
489 { NEW_CMD(0x6), "Q_SETINFO" },
490 { NEW_CMD(0x7), "Q_GETQUOTA" },
491 { NEW_CMD(0x8), "Q_SETQUOTA" },
492 { XQM_CMD(0x1), "Q_XQUOTAON" },
493 { XQM_CMD(0x2), "Q_XQUOTAOFF" },
494 { XQM_CMD(0x3), "Q_XGETQUOTA" },
495 { XQM_CMD(0x4), "Q_XSETQLIM" },
496 { XQM_CMD(0x5), "Q_XGETQSTAT" },
497 { XQM_CMD(0x6), "Q_XQUOTARM" },
501 static const struct xlat quotatypes[] = {
502 { USRQUOTA, "USRQUOTA" },
503 { GRPQUOTA, "GRPQUOTA" },
512 * The Linux kernel only looks at the low 32 bits of the command
513 * argument, but on some 64-bit architectures (s390x) this word
514 * will have been sign-extended when we see it. The high 1 bits
515 * don't mean anything, so don't confuse the output with them.
517 unsigned int cmd = tcp->u_arg[0];
520 printxval(quotacmds, cmd >> SUBCMDSHIFT, "Q_???");
522 printxval(quotatypes, cmd & SUBCMDMASK, "???QUOTA");
524 printstr(tcp, tcp->u_arg[1], -1);
525 tprintf(", %lu, ", tcp->u_arg[2]);
532 else if (!verbose(tcp) ||
533 #ifdef HAVE_STRUCT_DQBLK_DQB_CURBLOCKS
537 tprintf("%#lx", tcp->u_arg[3]);
538 else if (umoven(tcp, tcp->u_arg[3], sizeof(struct dqblk),
543 tprintf("%llu, ", (unsigned long long) dq.dqb_bhardlimit);
544 tprintf("%llu, ", (unsigned long long) dq.dqb_bsoftlimit);
545 #ifdef HAVE_STRUCT_DQBLK_DQB_CURBLOCKS
546 tprintf("%llu, ", (unsigned long long) dq.dqb_curblocks);
548 tprintf("%llu, ", (unsigned long long) dq.dqb_curspace);
550 tprintf("%llu, ", (unsigned long long) dq.dqb_ihardlimit);
551 tprintf("%llu, ", (unsigned long long) dq.dqb_isoftlimit);
552 tprintf("%llu, ", (unsigned long long) dq.dqb_curinodes);
553 tprintf("%llu, ", (unsigned long long) dq.dqb_btime);
554 tprintf("%llu", (unsigned long long) dq.dqb_itime);
564 #if defined(SUNOS4) || defined(FREEBSD)
567 #include <ufs/ufs/quota.h>
570 static const struct xlat quotacmds[] = {
571 { Q_QUOTAON, "Q_QUOTAON" },
572 { Q_QUOTAOFF, "Q_QUOTAOFF" },
573 { Q_GETQUOTA, "Q_GETQUOTA" },
574 { Q_SETQUOTA, "Q_SETQUOTA" },
576 { Q_SETQLIM, "Q_SETQLIM" },
579 { Q_SETUSE, "Q_SETUSE" },
581 { Q_SYNC, "Q_SYNC" },
589 /* fourth arg (addr) not interpreted here */
592 printxval(quotacmds, tcp->u_arg[0], "Q_???");
594 printstr(tcp, tcp->u_arg[1], -1);
597 printpath(tcp, tcp->u_arg[0]);
599 printxval(quotacmds, tcp->u_arg[1], "Q_???");
601 tprintf(", %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
606 #endif /* SUNOS4 || FREEBSD */