From cf6c58298298caeb25b29001ebbd42d321e1964d Mon Sep 17 00:00:00 2001 From: green Date: Tue, 25 Feb 2003 22:14:38 +0000 Subject: Add a new subcommand to pccardc(8), "dumpcisfile", which reads a CIS structure from a file instead of a PC-CARD itself before parsing and dumping it. (E.g. useful when you get a CIS file from a manufacturer which fixes they broken card's CIS, and add it to the pccard quirks.) --- usr.sbin/pccard/pccardc/Makefile | 4 +- usr.sbin/pccard/pccardc/dumpcisfile.c | 72 +++++++++++++++++++++++++++++++++++ usr.sbin/pccard/pccardc/pccardc.8 | 13 ++++++- usr.sbin/pccard/pccardc/pccardc.c | 2 + usr.sbin/pccard/pccardd/readcis.c | 5 ++- usr.sbin/pccard/pccardd/readcis.h | 2 + 6 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 usr.sbin/pccard/pccardc/dumpcisfile.c (limited to 'usr.sbin') diff --git a/usr.sbin/pccard/pccardc/Makefile b/usr.sbin/pccard/pccardc/Makefile index 0d09f92..aa833b1 100644 --- a/usr.sbin/pccard/pccardc/Makefile +++ b/usr.sbin/pccard/pccardc/Makefile @@ -4,8 +4,8 @@ PROG= pccardc MAN= pccardc.8 -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 +SRCS= beep.c dumpcis.c dumpcisfile.c enabler.c pccardc.c pccardmem.c power.c \ + printcis.c rdattr.c rdmap.c rdreg.c readcis.c wrattr.c wrreg.c CFLAGS+= -I${.CURDIR}/../pccardd diff --git a/usr.sbin/pccard/pccardc/dumpcisfile.c b/usr.sbin/pccard/pccardc/dumpcisfile.c new file mode 100644 index 0000000..6a415ba --- /dev/null +++ b/usr.sbin/pccard/pccardc/dumpcisfile.c @@ -0,0 +1,72 @@ +/* + * 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 +#include + +#include +#include +#include "readcis.h" + +static void +scanfile(name) + char *name; +{ + int fd; + struct cis *cp; + + fd = open(name, O_RDONLY); + if (fd < 0) + return; + cp = readcis(fd); + if (cp) { + printf("Configuration data for file %s\n", + name); + dumpcis(cp); + freecis(cp); + } + close(fd); +} + +int +dumpcisfile_main(int argc, char **argv) +{ + + isdumpcisfile = 1; + for (argc--, argv++; argc; argc--, argv++) + scanfile(*argv); + return 0; +} diff --git a/usr.sbin/pccard/pccardc/pccardc.8 b/usr.sbin/pccard/pccardc/pccardc.8 index 5fcc941..81bea7a 100644 --- a/usr.sbin/pccard/pccardc/pccardc.8 +++ b/usr.sbin/pccard/pccardc/pccardc.8 @@ -44,11 +44,13 @@ The utility controls PC-CARD slots and configures and displays information about PCMCIA cards. It understands the following subcommands: .Pp -.Bl -tag -width pccardmem -compact +.Bl -tag -width dumpcisfile -compact .It Ic beep Set beep type .It Ic dumpcis Print card CIS(s) +.It Ic dumpcisfile +Print card CIS(s) from files .It Ic enabler Device driver enabler .It Ic help @@ -101,6 +103,15 @@ specifies which slot to read. When no option is supplied, it displays the CIS of all of the available cards. .It +.Ic dumpcisfile +.Ar files Op Ar ... +.Pp +Displays CIS(s) in the same format as +.Ic dumpcis , +but does so using +.Ar files +as the input CIS data instead of physical PC-CARD cards. +.It .Ic enabler Ar slot driver .Op Fl m Ar card addr size .Op Fl a Ar iobase diff --git a/usr.sbin/pccard/pccardc/pccardc.c b/usr.sbin/pccard/pccardc/pccardc.c index 743493b..2de5f9e 100644 --- a/usr.sbin/pccard/pccardc/pccardc.c +++ b/usr.sbin/pccard/pccardc/pccardc.c @@ -38,6 +38,7 @@ typedef int (*main_t)(int, char **); #define DECL(foo) int foo(int, char**); DECL(beep_main); DECL(dumpcis_main); +DECL(dumpcisfile_main); DECL(enabler_main); DECL(help_main); DECL(pccardmem_main); @@ -55,6 +56,7 @@ struct { } subcommands[] = { { "beep", beep_main, "Beep type" }, { "dumpcis", dumpcis_main, "Prints CIS for all cards" }, + { "dumpcisfile", dumpcisfile_main, "Prints CIS from a file" }, { "enabler", enabler_main, "Device driver enabler" }, { "help", help_main, "Prints command summary" }, { "pccardmem", pccardmem_main, "Allocate memory for pccard driver" }, diff --git a/usr.sbin/pccard/pccardd/readcis.c b/usr.sbin/pccard/pccardd/readcis.c index 6953337..35fbcb6 100644 --- a/usr.sbin/pccard/pccardd/readcis.c +++ b/usr.sbin/pccard/pccardd/readcis.c @@ -49,6 +49,7 @@ static const char rcsid[] = #ifdef RATOCLAN static int rex5588 = 0; #endif +int isdumpcisfile = 0; static int read_attr(int, char *, int); static int ck_linktarget(int, off_t, int); @@ -745,7 +746,9 @@ read_attr(int fd, char *bp, int len) { char blk[1024], *p = blk; int i, l; - + + if (isdumpcisfile) + return (read(fd, bp, len)); if (len > sizeof(blk) / 2) len = sizeof(blk) / 2; l = i = read(fd, blk, len * 2); diff --git a/usr.sbin/pccard/pccardd/readcis.h b/usr.sbin/pccard/pccardd/readcis.h index 8c718e2..8ebd745 100644 --- a/usr.sbin/pccard/pccardd/readcis.h +++ b/usr.sbin/pccard/pccardd/readcis.h @@ -144,3 +144,5 @@ struct cis *readcis(int); char *tuple_name(unsigned char); u_int parse_num(int, u_char *, u_char **, int); + +int isdumpcisfile; -- cgit v1.1