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.)
This commit is contained in:
green 2003-02-25 22:14:38 +00:00
parent a3f8d3d819
commit cf6c582982
6 changed files with 94 additions and 4 deletions

View File

@ -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

View File

@ -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 <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <pccard/cardinfo.h>
#include <pccard/cis.h>
#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;
}

View File

@ -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

View File

@ -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" },

View File

@ -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);

View File

@ -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;