From owner-svn-src-projects@FreeBSD.ORG Wed Jun 24 12:08:24 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 31F1A106567F; Wed, 24 Jun 2009 12:08:24 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 03AD68FC12; Wed, 24 Jun 2009 12:08:24 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5OC8N51013762; Wed, 24 Jun 2009 12:08:23 GMT (envelope-from lulf@svn.freebsd.org) Received: (from lulf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5OC8NVc013761; Wed, 24 Jun 2009 12:08:23 GMT (envelope-from lulf@svn.freebsd.org) Message-Id: <200906241208.n5OC8NVc013761@svn.freebsd.org> From: Ulf Lilleengen Date: Wed, 24 Jun 2009 12:08:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194830 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jun 2009 12:08:25 -0000 Author: lulf Date: Wed Jun 24 12:08:23 2009 New Revision: 194830 URL: http://svn.freebsd.org/changeset/base/194830 Log: - Add a version of fstat that uses the sysctls rather than kvm to retrieve information to see what fstat will require of the libprocstat library. Added: projects/libprocstat/usr.bin/fstat/fstat_vnode.c (contents, props changed) Added: projects/libprocstat/usr.bin/fstat/fstat_vnode.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/libprocstat/usr.bin/fstat/fstat_vnode.c Wed Jun 24 12:08:23 2009 (r194830) @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 2009 Ulf Lilleengen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include + +#include +#include +#include + +struct filestat { + long fsid; + long fileid; + mode_t mode; + u_long size; + dev_t rdev; +}; + +int +main(int argc, char **argv) +{ + struct filestat *fs_buf; + struct filestat *fsp; + size_t size, numentries, i; + + if (sysctlbyname("kern.fileinfo", NULL, &size, NULL, 0) == -1) { + fprintf(stderr, "error getting sysctl\n"); + return (0); + } + fs_buf = malloc(size); + if (fs_buf == NULL) { + printf("OOPS\n"); + return (-1); + } + printf("Data size: %d\n", size); + numentries = size / sizeof(struct filestat); + printf("Data entries: %d\n", numentries); + if (sysctlbyname("kern.fileinfo", fs_buf, &size, NULL, 0) == -1) { + fprintf(stderr, "error getting sysctl\n"); + return (0); + } + fsp = fs_buf; + for (i = 0; i < numentries; i++) { + printf("FSID: %ld fileid %ld Size: %lu\n", fsp->fsid, fsp->fileid, fsp->size); + + fsp++; + } +}