From owner-freebsd-mobile Fri Jun 1 13:45:11 2001 Delivered-To: freebsd-mobile@freebsd.org Received: from shade.nectar.com (gw.nectar.com [208.42.49.153]) by hub.freebsd.org (Postfix) with ESMTP id 08D7637B42C for ; Fri, 1 Jun 2001 13:44:58 -0700 (PDT) (envelope-from nectar@nectar.com) Received: (from nectar@localhost) by shade.nectar.com (8.11.3/8.11.3) id f51Kj4j00914 for freebsd-mobile@freebsd.org; Fri, 1 Jun 2001 15:45:04 -0500 (CDT) (envelope-from nectar) Date: Fri, 1 Jun 2001 15:44:51 -0500 From: "Jacques A. Vidrine" To: freebsd-mobile@freebsd.org Subject: `pccardc status' patch Message-ID: <20010601154451.C701@shade.nectar.com> Mail-Followup-To: "Jacques A. Vidrine" , freebsd-mobile@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Url: http://www.nectar.com/ Sender: owner-freebsd-mobile@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org I found this functionality useful for certain scripts. ISTR something similar in PAO once upon a time. $ pccardc status slot 0: filled slot 1: empty $ pccardc status 0 slot 0: filled $ pccardc status 9 || echo exit_status=$? pccardc: /dev/card9: No such file or directory exit_status=1 The patch is against 4.3-RELEASE. Cheers, -- Jacques Vidrine / n@nectar.com / jvidrine@verio.net / nectar@FreeBSD.org --- Makefile.ORIG Fri Jun 1 15:42:49 2001 +++ Makefile Fri Jun 1 15:43:20 2001 @@ -5,7 +5,7 @@ # PROG= pccardc SRCS= beep.c dumpcis.c enabler.c pccardc.c pccardmem.c power.c printcis.c \ - rdattr.c rdmap.c rdreg.c readcis.c wrattr.c wrreg.c + status.c rdattr.c rdmap.c rdreg.c readcis.c wrattr.c wrreg.c MAN8= pccardc.8 CFLAGS+= -I${.CURDIR}/../pccardd --- pccardc.8.ORIG Fri Jun 1 15:43:10 2001 +++ pccardc.8 Thu May 31 19:46:54 2001 @@ -63,6 +63,8 @@ Read pcic mappings .It Ic rdreg Read pcic register +.It Ic status +Display slot status .It Ic wrattr Write byte to attribute memory .It Ic wrreg @@ -214,6 +216,13 @@ .Op Ar slot .Pp Displays the 64 registers of the card in +.Ar slot +(all slots by default). +.It +.Ic status +.Op Ar slot +.Pp +Displays the status of .Ar slot (all slots by default). .It --- pccardc.c.ORIG Fri Jun 1 15:42:16 2001 +++ pccardc.c Thu May 31 18:54:39 2001 @@ -45,6 +45,7 @@ DECL(rdattr_main); DECL(rdmap_main); DECL(rdreg_main); +DECL(status_main); DECL(wrattr_main); DECL(wrreg_main); @@ -62,6 +63,7 @@ { "rdattr", rdattr_main, "Read attribute memory" }, { "rdmap", rdmap_main, "Read pcic mappings" }, { "rdreg", rdreg_main, "Read pcic register" }, + { "status", status_main, "Display slot status" }, { "wrattr", wrattr_main, "Write byte to attribute memory" }, { "wrreg", wrreg_main, "Write pcic register" }, { 0, 0 } --- /dev/null Fri Jun 1 15:42:38 2001 +++ status.c Thu May 31 19:27:32 2001 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 1995 Andrew McRae. 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. + */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif /* not lint */ + +#include +#include +#include +#include +#include + +#include + +static int +status(slot) + int slot; +{ + int fd; + char name[64]; + struct slotstate st; + + sprintf(name, CARD_DEVICE, slot); + fd = open(name, O_RDONLY); + if (fd < 0) + return -1; + if (ioctl(fd, PIOCGSTATE, &st)) + err(1, "ioctl (PIOCGSTATE)"); + printf("slot %d: ", slot); + switch (st.state) { + case noslot: printf("noslot\n"); break; + case empty: printf("empty\n"); break; + case suspend: printf("suspend\n"); break; + case filled: printf("filled\n"); break; + case inactive: printf("inactive\n"); break; + default: + printf("unknown state %d\n", (int)st.state); + break; + } + return 0; +} + +void +usage(cmd) + char *cmd; +{ + errx(1, "Usage: %s status {slot}\n", cmd); +} + +int +status_main(int argc, char **argv) +{ + int node; + char *p; + + node = -1; + + + if (argc == 2) { + for (p = argv[1]; *p; p++) + if (!isdigit(*p)) + break; + if (*p != '\0') + usage(argv[0]); + else + node = atoi(argv[1]); + } else if (argc != 1) + usage(argv[0]); + /* NOTREACHED */ + + if (node < 0) { + for (node = 0; node < 8; node++) + status(node); + return 0; + } else if (status(node) < 0) { + err(1, CARD_DEVICE, node); + /* NOTREACHED */ + } else + return 0; +} To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-mobile" in the body of the message