From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 16:48:57 2011 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 6DAF5106564A; Tue, 4 Oct 2011 16:48:57 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5C3928FC0A; Tue, 4 Oct 2011 16:48:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94Gmvun066236; Tue, 4 Oct 2011 16:48:57 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94Gmvq9066231; Tue, 4 Oct 2011 16:48:57 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041648.p94Gmvq9066231@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 16:48:57 +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: r225985 - in projects/geom-events/usr.sbin: . ggetmode 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: Tue, 04 Oct 2011 16:48:57 -0000 Author: lev (ports committer) Date: Tue Oct 4 16:48:57 2011 New Revision: 225985 URL: http://svn.freebsd.org/changeset/base/225985 Log: Add ggetmode(8) - utility to check open mode of geom provider. Added: projects/geom-events/usr.sbin/ggetmode/ projects/geom-events/usr.sbin/ggetmode/Makefile projects/geom-events/usr.sbin/ggetmode/ggetmode.8 projects/geom-events/usr.sbin/ggetmode/ggetmode.c Modified: projects/geom-events/usr.sbin/Makefile Modified: projects/geom-events/usr.sbin/Makefile ============================================================================== --- projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:47:18 2011 (r225984) +++ projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:48:57 2011 (r225985) @@ -28,6 +28,7 @@ SUBDIR= adduser \ fwcontrol \ getfmac \ getpmac \ + ggetmode \ gstat \ i2c \ ifmcstat \ Added: projects/geom-events/usr.sbin/ggetmode/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/ggetmode/Makefile Tue Oct 4 16:48:57 2011 (r225985) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG= ggetmode +MAN= ggetmode.8 +DPADD= ${LIBGEOM} +LDADD= -lgeom + +.include Added: projects/geom-events/usr.sbin/ggetmode/ggetmode.8 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/ggetmode/ggetmode.8 Tue Oct 4 16:48:57 2011 (r225985) @@ -0,0 +1,57 @@ +.\" Copyright (c) 2011 Lev Serebryakov +.\" 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$ +.\" +.Dd September 14, 2011 +.Dt GGETMODE 8 +.Os +.Sh NAME +.Nm ggetmode +.Nd prints open mode of the given geom provider represented as the device node. +.Sh SYNOPSIS +.Nm ggetmode +.Ar device_name +.Sh DESCRIPTION +.Nm +utility prints open mode of the given device in standard +.Xr geom 4 +notation +.Em "rXwYeZ" . +String of +.Em "r0w0e0" +means, that given device isn't used by any consumer and is availiable. +.Sh EXIT STATUS +.Ex -std ggetmode +.Sh SEE ALSO +.Xr geom 8 , +.Xr geom 4 +.Sh HISTORY +The +.Nm +utility and manual page first appeared in +.Fx 10.0 . +.Sh AUTHORS +This utility and manual page was written by +.An Lev Serebryakov Aq lev@FreeBSD.org . Added: projects/geom-events/usr.sbin/ggetmode/ggetmode.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/ggetmode/ggetmode.c Tue Oct 4 16:48:57 2011 (r225985) @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2011 Lev Serebryakov + * 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 AUTHORS 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 AUTHORS 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char pathdev[] = _PATH_DEV; + +int +main(int argc, char *argv[]) +{ + struct gmesh mesh; + struct gclass *mp; + struct ggeom *gp; + struct gprovider *pp; + int error; + char mode[16] = ""; + char *device; + + if (argc != 2) + errx(EX_USAGE, "Syntax: %s ", basename(argv[0])); + + device = argv[1]; + if (!strncmp(device, pathdev, sizeof(pathdev) - 1)) + device += sizeof(pathdev) - 1; + + error = geom_gettree(&mesh); + if (error != 0) + errc(EX_UNAVAILABLE, error, "Can not get GEOM configuration: "); + + LIST_FOREACH(mp, &mesh.lg_class, lg_class) { + LIST_FOREACH(gp, &mp->lg_geom, lg_geom) { + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + if (!strcmp(pp->lg_name, device)) { + strlcpy(mode, pp->lg_mode, sizeof(mode) - 1); + goto end; + } + } + } + } +end: + geom_deletetree(&mesh); + if (mode[0]) + printf("%s\n", mode); + else + errx(EX_DATAERR, "%s not found", argv[1]); + + return (EX_OK); +}