[BACK]Return to procfs_linux.c CVS log [TXT][DIR] Up to [local] / sys / miscfs / procfs

Annotation of sys/miscfs/procfs/procfs_linux.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: procfs_linux.c,v 1.8 2007/06/18 08:30:07 jasper Exp $ */
                      2: /*      $NetBSD: procfs_linux.c,v 1.2.4.1 2001/03/30 21:48:11 he Exp $      */
                      3:
                      4: /*
                      5:  * Copyright (c) 2001 Wasabi Systems, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Written by Frank van der Linden for Wasabi Systems, Inc.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *      This product includes software developed for the NetBSD Project by
                     21:  *      Wasabi Systems, Inc.
                     22:  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
                     23:  *    or promote products derived from this software without specific prior
                     24:  *    written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39: #include <sys/param.h>
                     40: #include <sys/systm.h>
                     41: #include <sys/time.h>
                     42: #include <sys/kernel.h>
                     43: #include <sys/proc.h>
                     44: #include <sys/vnode.h>
                     45:
                     46: #include <miscfs/procfs/procfs.h>
                     47:
                     48: #include <uvm/uvm_extern.h>
                     49:
                     50: #define PGTOB(p)       ((unsigned long)(p) << PAGE_SHIFT)
                     51: #define PGTOKB(p)      ((unsigned long)(p) << (PAGE_SHIFT - 10))
                     52:
                     53: /*
                     54:  * Linux compatible /proc/meminfo. Only active when the -o linux
                     55:  * mountflag is used.
                     56:  */
                     57: int
                     58: procfs_domeminfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
                     59:                 struct uio *uio)
                     60: {
                     61:        char buf[512], *cp;
                     62:        int len, error;
                     63:
                     64:        len = snprintf(buf, sizeof buf,
                     65:                "        total:    used:    free:  shared: buffers: cached:\n"
                     66:                "Mem:  %8lu %8lu %8lu %8lu %8lu %8lu\n"
                     67:                "Swap: %8lu %8lu %8lu\n"
                     68:                "MemTotal:  %8lu kB\n"
                     69:                "MemFree:   %8lu kB\n"
                     70:                "MemShared: %8lu kB\n"
                     71:                "Buffers:   %8lu kB\n"
                     72:                "Cached:    %8lu kB\n"
                     73:                "SwapTotal: %8lu kB\n"
                     74:                "SwapFree:  %8lu kB\n",
                     75:                PGTOB(uvmexp.npages),
                     76:                PGTOB(uvmexp.npages - uvmexp.free),
                     77:                PGTOB(uvmexp.free),
                     78:                0L,
                     79:                0L,
                     80:                0L,
                     81:                PGTOB(uvmexp.swpages),
                     82:                PGTOB(uvmexp.swpginuse),
                     83:                PGTOB(uvmexp.swpages - uvmexp.swpginuse),
                     84:                PGTOKB(uvmexp.npages),
                     85:                PGTOKB(uvmexp.free),
                     86:                0L,
                     87:                0L,
                     88:                0L,
                     89:                PGTOKB(uvmexp.swpages),
                     90:                PGTOKB(uvmexp.swpages - uvmexp.swpginuse));
                     91:
                     92:        if (len <= 0 || len >= sizeof buf ||
                     93:            len < uio->uio_offset || uio->uio_resid == 0)
                     94:                return EINVAL;
                     95:
                     96:        len -= uio->uio_offset;
                     97:        cp = buf + uio->uio_offset;
                     98:        len = imin(len, uio->uio_resid);
                     99:        error = uiomove(cp, len, uio);
                    100:        return error;
                    101: }
                    102:
                    103: int
                    104: procfs_docpuinfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
                    105:                 struct uio *uio)
                    106: {
                    107:        char buf[512], *cp;
                    108:        int len, error;
                    109:
                    110:        len = sizeof buf;
                    111:        if (procfs_getcpuinfstr(buf, &len) < 0)
                    112:                return EIO;
                    113:
                    114:        if (len == 0 || uio->uio_offset > sizeof(buf))
                    115:                return 0;
                    116:
                    117:        len -= uio->uio_offset;
                    118:        cp = buf + uio->uio_offset;
                    119:        len = imin(len, uio->uio_resid);
                    120:        if (len <= 0)
                    121:                error = 0;
                    122:        else
                    123:                error = uiomove(cp, len, uio);
                    124:        return error;
                    125: }
                    126:
                    127: #ifndef __i386__
                    128: int
                    129: procfs_getcpuinfstr(char *buf, int *len)
                    130: {
                    131:        *len = 0;
                    132:
                    133:        return 0;
                    134: }
                    135: #endif

CVSweb