machine.c revision 1.23
1/* $OpenBSD: machine.c,v 1.23 2001/02/22 03:10:24 deraadt Exp $ */ 2 3/* 4 * top - a top users display for Unix 5 * 6 * SYNOPSIS: For an OpenBSD system 7 * 8 * DESCRIPTION: 9 * This is the machine-dependent module for OpenBSD 10 * Tested on: 11 * i386 12 * 13 * TERMCAP: -ltermlib 14 * 15 * CFLAGS: -DHAVE_GETOPT -DORDER 16 * 17 * AUTHOR: Thorsten Lockert <tholo@sigmasoft.com> 18 * Adapted from BSD4.4 by Christos Zoulas <christos@ee.cornell.edu> 19 * Patch for process wait display by Jarl F. Greipsland <jarle@idt.unit.no> 20 * Patch for -DORDER by Kenneth Stailey <kstailey@disclosure.com> 21 * Patch for new swapctl(2) by Tobias Weingartner <weingart@openbsd.org> 22 */ 23 24#include <sys/types.h> 25#include <sys/signal.h> 26#include <sys/param.h> 27 28#define DOSWAP 29 30#include <stdio.h> 31#include <stdlib.h> 32#include <string.h> 33#include <limits.h> 34#include <err.h> 35#include <math.h> 36#include <unistd.h> 37#include <sys/errno.h> 38#include <sys/sysctl.h> 39#include <sys/dir.h> 40#include <sys/dkstat.h> 41#include <sys/file.h> 42#include <sys/time.h> 43#include <sys/resource.h> 44 45#ifdef DOSWAP 46#include <sys/swap.h> 47#include <err.h> 48#endif 49 50static int getkval __P((unsigned long, int *, int, char *)); 51static int swapmode __P((int *, int *)); 52 53#include "top.h" 54#include "display.h" 55#include "machine.h" 56#include "utils.h" 57 58/* get_process_info passes back a handle. This is what it looks like: */ 59 60struct handle { 61 struct kinfo_proc **next_proc; /* points to next valid proc pointer */ 62 int remaining; /* number of pointers remaining */ 63}; 64 65/* declarations for load_avg */ 66#include "loadavg.h" 67 68#define PP(pp, field) ((pp)->kp_proc . field) 69#define EP(pp, field) ((pp)->kp_eproc . field) 70#define VP(pp, field) ((pp)->kp_eproc.e_vm . field) 71 72/* what we consider to be process size: */ 73#define PROCSIZE(pp) (VP((pp), vm_tsize) + VP((pp), vm_dsize) + VP((pp), vm_ssize)) 74 75/* 76 * These definitions control the format of the per-process area 77 */ 78static char header[] = 79" PID X PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND"; 80/* 0123456 -- field to fill in starts at header+6 */ 81#define UNAME_START 6 82 83#define Proc_format \ 84 "%5d %-8.8s %3d %4d %5s %5s %-5s %-6.6s %6s %5.2f%% %.14s" 85 86 87/* process state names for the "STATE" column of the display */ 88/* the extra nulls in the string "run" are for adding a slash and 89 the processor number when needed */ 90 91char *state_abbrev[] = { 92 "", "start", "run\0\0\0", "sleep", "stop", "zomb", 93}; 94 95 96static int stathz; 97 98/* these are offsets obtained via nlist and used in the get_ functions */ 99 100static unsigned long cp_time_offset; 101 102/* these are for calculating cpu state percentages */ 103static long cp_time[CPUSTATES]; 104static long cp_old[CPUSTATES]; 105static long cp_diff[CPUSTATES]; 106 107/* these are for detailing the process states */ 108int process_states[7]; 109char *procstatenames[] = { 110 "", " starting, ", " running, ", " idle, ", " stopped, ", " zombie, ", 111 NULL 112}; 113 114/* these are for detailing the cpu states */ 115int cpu_states[CPUSTATES]; 116char *cpustatenames[] = { 117 "user", "nice", "system", "interrupt", "idle", NULL 118}; 119 120/* these are for detailing the memory statistics */ 121int memory_stats[8]; 122char *memorynames[] = { 123 "Real: ", "K/", "K act/tot ", "Free: ", "K ", 124#ifdef DOSWAP 125 "Swap: ", "K/", "K used/tot", 126#endif 127 NULL 128}; 129 130#ifdef ORDER 131/* these are names given to allowed sorting orders -- first is default */ 132char *ordernames[] = {"cpu", "size", "res", "time", "pri", NULL}; 133#endif 134 135/* these are for keeping track of the proc array */ 136static int nproc; 137static int onproc = -1; 138static int pref_len; 139static struct kinfo_proc *pbase; 140static struct kinfo_proc **pref; 141 142/* these are for getting the memory statistics */ 143static int pageshift; /* log base 2 of the pagesize */ 144 145/* define pagetok in terms of pageshift */ 146#define pagetok(size) ((size) << pageshift) 147 148int 149getstathz() 150{ 151 struct clockinfo cinf; 152 size_t size = sizeof(cinf); 153 int mib[2]; 154 155 mib[0] = CTL_KERN; 156 mib[1] = KERN_CLOCKRATE; 157 if (sysctl(mib, 2, &cinf, &size, NULL, 0) == -1) 158 return (-1); 159 return (cinf.stathz); 160} 161 162int 163machine_init(statics) 164 struct statics *statics; 165{ 166 char errbuf[_POSIX2_LINE_MAX]; 167 int pagesize, i = 0; 168 169 stathz = getstathz(); 170 if (stathz == -1) 171 return (-1); 172 173 pbase = NULL; 174 pref = NULL; 175 onproc = -1; 176 nproc = 0; 177 178 /* get the page size with "getpagesize" and calculate pageshift from 179 * it */ 180 pagesize = getpagesize(); 181 pageshift = 0; 182 while (pagesize > 1) { 183 pageshift++; 184 pagesize >>= 1; 185 } 186 187 /* we only need the amount of log(2)1024 for our conversion */ 188 pageshift -= LOG1024; 189 190 /* fill in the statics information */ 191 statics->procstate_names = procstatenames; 192 statics->cpustate_names = cpustatenames; 193 statics->memory_names = memorynames; 194#ifdef ORDER 195 statics->order_names = ordernames; 196#endif 197 return (0); 198} 199 200char * 201format_header(uname_field) 202 char *uname_field; 203{ 204 char *ptr; 205 206 ptr = header + UNAME_START; 207 while (*uname_field != '\0') { 208 *ptr++ = *uname_field++; 209 } 210 return (header); 211} 212 213void 214get_system_info(si) 215 struct system_info *si; 216{ 217 static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; 218 static int vmtotal_mib[] = {CTL_VM, VM_METER}; 219 static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; 220 struct loadavg sysload; 221 struct vmtotal vmtotal; 222 double *infoloadp; 223 int total, i; 224 size_t size; 225 226 size = sizeof(cp_time); 227 if (sysctl(cp_time_mib, 2, &cp_time, &size, NULL, 0) < 0) { 228 warn("sysctl kern.cp_time failed"); 229 total = 0; 230 } 231 232 size = sizeof(sysload); 233 if (sysctl(sysload_mib, 2, &sysload, &size, NULL, 0) < 0) { 234 warn("sysctl failed"); 235 total = 0; 236 } 237 infoloadp = si->load_avg; 238 for (i = 0; i < 3; i++) 239 *infoloadp++ = ((double) sysload.ldavg[i]) / sysload.fscale; 240 241 /* convert cp_time counts to percentages */ 242 total = percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff); 243 244 /* get total -- systemwide main memory usage structure */ 245 size = sizeof(vmtotal); 246 if (sysctl(vmtotal_mib, 2, &vmtotal, &size, NULL, 0) < 0) { 247 warn("sysctl failed"); 248 bzero(&vmtotal, sizeof(vmtotal)); 249 } 250 /* convert memory stats to Kbytes */ 251 memory_stats[0] = -1; 252 memory_stats[1] = pagetok(vmtotal.t_arm); 253 memory_stats[2] = pagetok(vmtotal.t_rm); 254 memory_stats[3] = -1; 255 memory_stats[4] = pagetok(vmtotal.t_free); 256 memory_stats[5] = -1; 257#ifdef DOSWAP 258 if (!swapmode(&memory_stats[6], &memory_stats[7])) { 259 memory_stats[6] = 0; 260 memory_stats[7] = 0; 261 } 262#endif 263 264 /* set arrays and strings */ 265 si->cpustates = cpu_states; 266 si->memory = memory_stats; 267 si->last_pid = -1; 268} 269 270static struct handle handle; 271 272struct kinfo_proc * 273getprocs(op, arg, cnt) 274 int op, arg; 275 int *cnt; 276{ 277 size_t size = 0; 278 int mib[4] = {CTL_KERN, KERN_PROC, op, arg}; 279 int st, nprocs; 280 static struct kinfo_proc *procbase; 281 282 st = sysctl(mib, 4, NULL, &size, NULL, 0); 283 if (st == -1) { 284 /* _kvm_syserr(kd, kd->program, "kvm_getprocs"); */ 285 return (0); 286 } 287 if (procbase) 288 free(procbase); 289 procbase = (struct kinfo_proc *)malloc(size); 290 if (procbase == NULL) 291 return (0); 292 st = sysctl(mib, 4, procbase, &size, NULL, 0); 293 if (st == -1) { 294 /* _kvm_syserr(kd, kd->program, "kvm_getprocs"); */ 295 return (0); 296 } 297 if (size % sizeof(struct kinfo_proc) != 0) { 298 /* _kvm_err(kd, kd->program, 299 "proc size mismatch (%d total, %d chunks)", 300 size, sizeof(struct kinfo_proc)); */ 301 return (0); 302 } 303 *cnt = size / sizeof(struct kinfo_proc); 304 return (procbase); 305} 306 307caddr_t 308get_process_info(si, sel, compare) 309 struct system_info *si; 310 struct process_select *sel; 311 int (*compare) __P((const void *, const void *)); 312 313{ 314 int show_idle, show_system, show_uid, show_command; 315 int total_procs, active_procs, i; 316 struct kinfo_proc **prefp, *pp; 317 318 if ((pbase = getprocs(KERN_PROC_KTHREAD, 0, &nproc)) == NULL) { 319 /* warnx("%s", kvm_geterr(kd)); */ 320 quit(23); 321 } 322 if (nproc > onproc) 323 pref = (struct kinfo_proc **) realloc(pref, sizeof(struct kinfo_proc *) 324 * (onproc = nproc)); 325 if (pref == NULL) { 326 warnx("Out of memory."); 327 quit(23); 328 } 329 /* get a pointer to the states summary array */ 330 si->procstates = process_states; 331 332 /* set up flags which define what we are going to select */ 333 show_idle = sel->idle; 334 show_system = sel->system; 335 show_uid = sel->uid != -1; 336 show_command = sel->command != NULL; 337 338 /* count up process states and get pointers to interesting procs */ 339 total_procs = 0; 340 active_procs = 0; 341 memset((char *) process_states, 0, sizeof(process_states)); 342 prefp = pref; 343 for (pp = pbase, i = 0; i < nproc; pp++, i++) { 344 /* 345 * Place pointers to each valid proc structure in pref[]. 346 * Process slots that are actually in use have a non-zero 347 * status field. Processes with SSYS set are system 348 * processes---these get ignored unless show_sysprocs is set. 349 */ 350 if (PP(pp, p_stat) != 0 && 351 (show_system || ((PP(pp, p_flag) & P_SYSTEM) == 0))) { 352 total_procs++; 353 process_states[(unsigned char) PP(pp, p_stat)]++; 354 if ((PP(pp, p_stat) != SZOMB) && 355 (show_idle || (PP(pp, p_pctcpu) != 0) || 356 (PP(pp, p_stat) == SRUN)) && 357 (!show_uid || EP(pp, e_pcred.p_ruid) == (uid_t) sel->uid)) { 358 *prefp++ = pp; 359 active_procs++; 360 } 361 } 362 } 363 364 /* if requested, sort the "interesting" processes */ 365 if (compare != NULL) { 366 qsort((char *) pref, active_procs, sizeof(struct kinfo_proc *), compare); 367 } 368 /* remember active and total counts */ 369 si->p_total = total_procs; 370 si->p_active = pref_len = active_procs; 371 372 /* pass back a handle */ 373 handle.next_proc = pref; 374 handle.remaining = active_procs; 375 return ((caddr_t) & handle); 376} 377 378char fmt[MAX_COLS]; /* static area where result is built */ 379 380char * 381format_next_process(handle, get_userid) 382 caddr_t handle; 383 char *(*get_userid)(); 384 385{ 386 char waddr[sizeof(void *) * 2 + 3]; /* Hexify void pointer */ 387 struct kinfo_proc *pp; 388 struct handle *hp; 389 char *p_wait; 390 int cputime; 391 double pct; 392 393 /* find and remember the next proc structure */ 394 hp = (struct handle *) handle; 395 pp = *(hp->next_proc++); 396 hp->remaining--; 397 398 /* get the process's user struct and set cputime */ 399 if ((PP(pp, p_flag) & P_INMEM) == 0) { 400 /* 401 * Print swapped processes as <pname> 402 */ 403 char *comm = PP(pp, p_comm); 404#define COMSIZ sizeof(PP(pp, p_comm)) 405 char buf[COMSIZ]; 406 (void) strncpy(buf, comm, COMSIZ); 407 comm[0] = '<'; 408 (void) strncpy(&comm[1], buf, COMSIZ - 2); 409 comm[COMSIZ - 2] = '\0'; 410 (void) strncat(comm, ">", COMSIZ - 1); 411 comm[COMSIZ - 1] = '\0'; 412 } 413 cputime = (PP(pp, p_uticks) + PP(pp, p_sticks) + PP(pp, p_iticks)) / stathz; 414 415 /* calculate the base for cpu percentages */ 416 pct = pctdouble(PP(pp, p_pctcpu)); 417 418 if (PP(pp, p_wchan)) 419 if (PP(pp, p_wmesg)) 420 p_wait = EP(pp, e_wmesg); 421 else { 422 snprintf(waddr, sizeof(waddr), "%lx", 423 (unsigned long) (PP(pp, p_wchan)) & ~KERNBASE); 424 p_wait = waddr; 425 } 426 else 427 p_wait = "-"; 428 429 /* format this entry */ 430 snprintf(fmt, MAX_COLS, 431 Proc_format, 432 PP(pp, p_pid), 433 (*get_userid) (EP(pp, e_pcred.p_ruid)), 434 PP(pp, p_priority) - PZERO, 435 PP(pp, p_nice) - NZERO, 436 format_k(pagetok(PROCSIZE(pp))), 437 format_k(pagetok(VP(pp, vm_rssize))), 438 (PP(pp, p_stat) == SSLEEP && PP(pp, p_slptime) > MAXSLP) 439 ? "idle" : state_abbrev[(unsigned char) PP(pp, p_stat)], 440 p_wait, 441 format_time(cputime), 442 100.0 * pct, 443 printable(PP(pp, p_comm))); 444 445 /* return the result */ 446 return (fmt); 447} 448 449/* comparison routine for qsort */ 450static unsigned char sorted_state[] = 451{ 452 0, /* not used */ 453 4, /* start */ 454 5, /* run */ 455 2, /* sleep */ 456 3, /* stop */ 457 1 /* zombie */ 458}; 459#ifdef ORDER 460 461/* 462 * proc_compares - comparison functions for "qsort" 463 */ 464 465/* 466 * First, the possible comparison keys. These are defined in such a way 467 * that they can be merely listed in the source code to define the actual 468 * desired ordering. 469 */ 470 471 472#define ORDERKEY_PCTCPU \ 473 if (lresult = (pctcpu)PP(p2, p_pctcpu) - (pctcpu)PP(p1, p_pctcpu), \ 474 (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0) 475#define ORDERKEY_CPUTIME \ 476 if ((result = PP(p2, p_rtime.tv_sec) - PP(p1, p_rtime.tv_sec)) == 0) \ 477 if ((result = PP(p2, p_rtime.tv_usec) - \ 478 PP(p1, p_rtime.tv_usec)) == 0) 479#define ORDERKEY_STATE \ 480 if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - \ 481 sorted_state[(unsigned char) PP(p1, p_stat)]) == 0) 482#define ORDERKEY_PRIO \ 483 if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0) 484#define ORDERKEY_RSSIZE \ 485 if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0) 486#define ORDERKEY_MEM \ 487 if ((result = PROCSIZE(p2) - PROCSIZE(p1)) == 0) 488 489 490/* compare_cpu - the comparison function for sorting by cpu percentage */ 491int 492compare_cpu(v1, v2) 493 const void *v1, *v2; 494{ 495 struct proc **pp1 = (struct proc **) v1; 496 struct proc **pp2 = (struct proc **) v2; 497 struct kinfo_proc *p1; 498 struct kinfo_proc *p2; 499 int result; 500 pctcpu lresult; 501 502 /* remove one level of indirection */ 503 p1 = *(struct kinfo_proc **) pp1; 504 p2 = *(struct kinfo_proc **) pp2; 505 506 ORDERKEY_PCTCPU 507 ORDERKEY_CPUTIME 508 ORDERKEY_STATE 509 ORDERKEY_PRIO 510 ORDERKEY_RSSIZE 511 ORDERKEY_MEM 512 ; 513 return (result); 514} 515 516/* compare_size - the comparison function for sorting by total memory usage */ 517int 518compare_size(v1, v2) 519 const void *v1, *v2; 520{ 521 struct proc **pp1 = (struct proc **) v1; 522 struct proc **pp2 = (struct proc **) v2; 523 struct kinfo_proc *p1; 524 struct kinfo_proc *p2; 525 int result; 526 pctcpu lresult; 527 528 /* remove one level of indirection */ 529 p1 = *(struct kinfo_proc **) pp1; 530 p2 = *(struct kinfo_proc **) pp2; 531 532 ORDERKEY_MEM 533 ORDERKEY_RSSIZE 534 ORDERKEY_PCTCPU 535 ORDERKEY_CPUTIME 536 ORDERKEY_STATE 537 ORDERKEY_PRIO 538 ; 539 return (result); 540} 541 542/* compare_res - the comparison function for sorting by resident set size */ 543int 544compare_res(v1, v2) 545 const void *v1, *v2; 546{ 547 struct proc **pp1 = (struct proc **) v1; 548 struct proc **pp2 = (struct proc **) v2; 549 struct kinfo_proc *p1; 550 struct kinfo_proc *p2; 551 int result; 552 pctcpu lresult; 553 554 /* remove one level of indirection */ 555 p1 = *(struct kinfo_proc **) pp1; 556 p2 = *(struct kinfo_proc **) pp2; 557 558 ORDERKEY_RSSIZE 559 ORDERKEY_MEM 560 ORDERKEY_PCTCPU 561 ORDERKEY_CPUTIME 562 ORDERKEY_STATE 563 ORDERKEY_PRIO 564 ; 565 return (result); 566} 567 568/* compare_time - the comparison function for sorting by CPU time */ 569int 570compare_time(v1, v2) 571 const void *v1, *v2; 572{ 573 struct proc **pp1 = (struct proc **) v1; 574 struct proc **pp2 = (struct proc **) v2; 575 struct kinfo_proc *p1; 576 struct kinfo_proc *p2; 577 int result; 578 pctcpu lresult; 579 580 /* remove one level of indirection */ 581 p1 = *(struct kinfo_proc **) pp1; 582 p2 = *(struct kinfo_proc **) pp2; 583 584 ORDERKEY_CPUTIME 585 ORDERKEY_PCTCPU 586 ORDERKEY_STATE 587 ORDERKEY_PRIO 588 ORDERKEY_MEM 589 ORDERKEY_RSSIZE 590 ; 591 return (result); 592} 593 594/* compare_prio - the comparison function for sorting by CPU time */ 595int 596compare_prio(v1, v2) 597 const void *v1, *v2; 598{ 599 struct proc **pp1 = (struct proc **) v1; 600 struct proc **pp2 = (struct proc **) v2; 601 struct kinfo_proc *p1; 602 struct kinfo_proc *p2; 603 int result; 604 pctcpu lresult; 605 606 /* remove one level of indirection */ 607 p1 = *(struct kinfo_proc **) pp1; 608 p2 = *(struct kinfo_proc **) pp2; 609 610 ORDERKEY_PRIO 611 ORDERKEY_PCTCPU 612 ORDERKEY_CPUTIME 613 ORDERKEY_STATE 614 ORDERKEY_RSSIZE 615 ORDERKEY_MEM 616 ; 617 return (result); 618} 619 620int (*proc_compares[]) () = { 621 compare_cpu, 622 compare_size, 623 compare_res, 624 compare_time, 625 compare_prio, 626 NULL 627}; 628#else 629/* 630 * proc_compare - comparison function for "qsort" 631 * Compares the resource consumption of two processes using five 632 * distinct keys. The keys (in descending order of importance) are: 633 * percent cpu, cpu ticks, state, resident set size, total virtual 634 * memory usage. The process states are ordered as follows (from least 635 * to most important): zombie, sleep, stop, start, run. The array 636 * declaration below maps a process state index into a number that 637 * reflects this ordering. 638 */ 639int 640proc_compare(v1, v2) 641 const void *v1, *v2; 642{ 643 struct proc **pp1 = (struct proc **) v1; 644 struct proc **pp2 = (struct proc **) v2; 645 struct kinfo_proc *p1; 646 struct kinfo_proc *p2; 647 int result; 648 pctcpu lresult; 649 650 /* remove one level of indirection */ 651 p1 = *(struct kinfo_proc **) pp1; 652 p2 = *(struct kinfo_proc **) pp2; 653 654 /* compare percent cpu (pctcpu) */ 655 if ((lresult = PP(p2, p_pctcpu) - PP(p1, p_pctcpu)) == 0) { 656 /* use CPU usage to break the tie */ 657 if ((result = PP(p2, p_rtime).tv_sec - PP(p1, p_rtime).tv_sec) == 0) { 658 /* use process state to break the tie */ 659 if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - 660 sorted_state[(unsigned char) PP(p1, p_stat)]) == 0) { 661 /* use priority to break the tie */ 662 if ((result = PP(p2, p_priority) - 663 PP(p1, p_priority)) == 0) { 664 /* use resident set size (rssize) to 665 * break the tie */ 666 if ((result = VP(p2, vm_rssize) - 667 VP(p1, vm_rssize)) == 0) { 668 /* use total memory to break 669 * the tie */ 670 result = PROCSIZE(p2) - PROCSIZE(p1); 671 } 672 } 673 } 674 } 675 } else { 676 result = lresult < 0 ? -1 : 1; 677 } 678 return (result); 679} 680#endif 681 682/* 683 * proc_owner(pid) - returns the uid that owns process "pid", or -1 if 684 * the process does not exist. 685 * It is EXTREMLY IMPORTANT that this function work correctly. 686 * If top runs setuid root (as in SVR4), then this function 687 * is the only thing that stands in the way of a serious 688 * security problem. It validates requests for the "kill" 689 * and "renice" commands. 690 */ 691int 692proc_owner(pid) 693 pid_t pid; 694{ 695 struct kinfo_proc **prefp, *pp; 696 int cnt; 697 698 prefp = pref; 699 cnt = pref_len; 700 while (--cnt >= 0) { 701 pp = *prefp++; 702 if (PP(pp, p_pid) == pid) { 703 return ((int) EP(pp, e_pcred.p_ruid)); 704 } 705 } 706 return (-1); 707} 708#ifdef DOSWAP 709/* 710 * swapmode is rewritten by Tobias Weingartner <weingart@openbsd.org> 711 * to be based on the new swapctl(2) system call. 712 */ 713static int 714swapmode(used, total) 715 int *used; 716 int *total; 717{ 718 int nswap, rnswap, i; 719 struct swapent *swdev; 720 721 nswap = swapctl(SWAP_NSWAP, 0, 0); 722 if (nswap == 0) 723 return 0; 724 725 swdev = malloc(nswap * sizeof(*swdev)); 726 if (swdev == NULL) 727 return 0; 728 729 rnswap = swapctl(SWAP_STATS, swdev, nswap); 730 if (rnswap == -1) 731 return 0; 732 733 /* if rnswap != nswap, then what? */ 734 735 /* Total things up */ 736 *total = *used = 0; 737 for (i = 0; i < nswap; i++) { 738 if (swdev[i].se_flags & SWF_ENABLE) { 739 *used += (swdev[i].se_inuse / (1024 / DEV_BSIZE)); 740 *total += (swdev[i].se_nblks / (1024 / DEV_BSIZE)); 741 } 742 } 743 744 free(swdev); 745 return 1; 746} 747#endif 748