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