.gear/rules | 2 + .../tags/81d5db20ea9fc0cee1de8c31ce5a963864e0bb15 | 35 ++ .gear/tags/list | 1 + Makefile | 76 ++--- build/ccdv.c | 387 -------------------- doc/mini-howto.txt | 3 +- pcmciautils.spec | 120 ++++++ src/pccardctl.c | 199 +++++------ src/pcmcia-check-broken-cis.c | 22 +- src/read-cis.c | 3 +- src/startup.c | 101 +++--- udev/rules-modprobe | 2 +- 12 files changed, 347 insertions(+), 604 deletions(-) diff --git a/.gear/rules b/.gear/rules new file mode 100644 index 0000000..f78a96e --- /dev/null +++ b/.gear/rules @@ -0,0 +1,2 @@ +tar: @name@-@version@:. +diff: @name@-@version@:. . diff --git a/.gear/tags/81d5db20ea9fc0cee1de8c31ce5a963864e0bb15 b/.gear/tags/81d5db20ea9fc0cee1de8c31ce5a963864e0bb15 new file mode 100644 index 0000000..06ef9c7 --- /dev/null +++ b/.gear/tags/81d5db20ea9fc0cee1de8c31ce5a963864e0bb15 @@ -0,0 +1,35 @@ +object 26b1a2f41a859db31d73e9cf48e40d267095d482 +type commit +tag pcmciautils-018 +tagger Dominik Brodowski 1302852145 +0200 + +Release of pcmciautils-018 + +Colin Watson (1): + Don't link pcmcia-check-broken-cis against libsysfs + +Dominik Brodowski (5): + gitignore update + lspcmcia: print out card resource configuration + src: coding style bugfixes + Makefile: allow command-line overrides + pcmciautils-018 + +Jirka Klimes (1): + pccardctl: fix segmentation fault on unknown long option + +Wolfram Sang (7): + Makefile: add short help target + Makefile: let plain 'make' be like 'make all' again + lex: disable unused options + read-cis: fix type-punning pointers + read-cis: Remove the now pointless macros + read-cis: Remove a forward declaration and some whitespaces + pccardctl: remove superfluous check +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.10 (GNU/Linux) + +iEYEABECAAYFAk2n8nMACgkQZ8MDCHJbN8a5eACcDOtaAj0ViAcH2UVasPF0uxGQ +c9UAoIH+cRlOb8p5pROyCmIGMB5akdOj +=iX8O +-----END PGP SIGNATURE----- diff --git a/.gear/tags/list b/.gear/tags/list new file mode 100644 index 0000000..97e8420 --- /dev/null +++ b/.gear/tags/list @@ -0,0 +1 @@ +81d5db20ea9fc0cee1de8c31ce5a963864e0bb15 pcmciautils-018 diff --git a/Makefile b/Makefile index 0a61d56..93b0f4c 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ exec_prefix = ${prefix} etcdir = ${prefix}/etc sbindir = ${exec_prefix}/sbin mandir = ${prefix}/usr/share/man -udevdir = ${prefix}/lib/udev +udevdir = /lib/udev INSTALL = /usr/bin/install -c INSTALL_PROGRAM = ${INSTALL} @@ -122,8 +122,7 @@ GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(. GCC_LIB := $(shell $(CC) -print-libgcc-file-name ) # use '-Os' optimization if available, else use -O2 -OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ - then echo "-Os"; else echo "-O2" ; fi} +OPTIMIZATION := $(RPM_OPT_FLAGS) # check if compiler option is supported cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;} @@ -156,35 +155,16 @@ CFLAGS += -I$(PWD)/src CFLAGS += $(WARNINGS) -I$(GCCINCDIR) -LIB_OBJS = -lc -lsysfs +LIB_OBJS = -lc LIB_PLAIN_OBJS = -lc LIB_PCI_OBJS = -lc -lpci -ifeq ($(strip $(STATIC)),true) - LIB_OBJS = -lsysfs - LIB_PLAIN_OBJS = - LIB_PCI_OBJS = -lpci - LDFLAGS += -static -else - LDFLAGS += -Wl,-warn-common -endif - -ifeq ($(strip $(V)),false) - QUIET=@$(PWD)/build/ccdv - HOST_PROGS=build/ccdv -else - QUIET= - HOST_PROGS= -endif +QUIET= +ECHO= @\# -# if DEBUG is enabled, then we do not strip or optimize -ifeq ($(strip $(DEBUG)),true) - CFLAGS += -O1 -g -DDEBUG -D_GNU_SOURCE - STRIPCMD = /bin/true -Since_we_are_debugging -else - CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE - STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment -endif +CFLAGS += $(OPTIMIZATION) -D_GNU_SOURCE +LDFLAGS += -Wl,-warn-common +STRIPCMD = /bin/true # HOTPLUG or UDEV? ifeq ($(strip $(UDEV)),false) @@ -219,48 +199,57 @@ endif UDEV_RULES += udev/rules-end -all: ccdv $(PCCARDCTL) $(PCMCIA_CHECK_BROKEN_CIS) $(PCMCIA_SOCKET_STARTUP_BUILD) udevrules - -ccdv: build/ccdv -build/ccdv: build/ccdv.c - @echo "Building ccdv" - @$(HOSTCC) -O1 $< -o $@ +all: $(PCCARDCTL) $(PCMCIA_CHECK_BROKEN_CIS) $(PCMCIA_SOCKET_STARTUP_BUILD) $(UDEV_RULES_FILE) -%.o : %.c ccdv - $(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< +%.o : %.c + $(ECHO) " CC " $@ + $(QUIET) $(CC) -c $(CFLAGS) $< -o $@ %.c %.h : %.y - $(YACC) $(YFLAGS) $< - mv y.tab.c $*.c - mv y.tab.h $*.h + $(ECHO) " YACC " $@ + $(QUIET) $(YACC) $(YFLAGS) $< + $(QUIET) mv y.tab.c $*.c + $(QUIET) mv y.tab.h $*.h $(PCCARDCTL): $(LIBC) src/$(PCCARDCTL).o src/$(PCCARDCTL).c $(OBJS) $(HEADERS) + $(ECHO) " LD " $@ $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) src/$(PCCARDCTL).o $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(ECHO) " STRIP " $@ $(QUIET) $(STRIPCMD) $@ $(PCMCIA_CHECK_BROKEN_CIS): $(LIBC) src/$(PCMCIA_CHECK_BROKEN_CIS).o src/read-cis.o $(OBJS) $(HEADERS) + $(ECHO) " LD " $@ $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) src/$(PCMCIA_CHECK_BROKEN_CIS).o src/read-cis.o $(LIB_PLAIN_OBJS) $(ARCH_LIB_OBJS) + $(ECHO) " STRIP " $@ $(QUIET) $(STRIPCMD) $@ $(PCMCIA_SOCKET_STARTUP): $(LIBC) src/startup.o src/yacc_config.o src/lex_config.o $(OBJS) $(HEADERS) + $(ECHO) " LD " $@ $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) src/startup.o src/yacc_config.o src/lex_config.o $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(ECHO) " STRIP " $@ $(QUIET) $(STRIPCMD) $@ yacc_config.o lex_config.o: %.o: %.c - $(CC) -c -MD -O -pipe $(CPPFLAGS) $< + $(ECHO) " CC " $@ + $(QUIET) $(CC) -c -MD -O -pipe $(CFLAGS) $< -debugtools: ccdv $(CBDUMP) $(CISDUMP) +debugtools: $(CBDUMP) $(CISDUMP) $(CBDUMP): $(LIBC) debug/cbdump.o + $(ECHO) " LD " $@ $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) debug/$(CBDUMP).o $(LIB_PCI_OBJS) $(ARCH_LIB_OBJS) + $(ECHO) " STRIP " $@ $(QUIET) $(STRIPCMD) $@ $(CISDUMP): $(LIBC) src/read-cis.o debug/parse_cis.o debug/dump_cis.o + $(ECHO) " LD " $@ $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) debug/$(CISDUMP).o src/read-cis.o debug/parse_cis.o $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(ECHO) " STRIP " $@ $(QUIET) $(STRIPCMD) $@ -udevrules: - cat $(UDEV_RULES) | sed -e "s#__UDEVHELPERDIR__#${udevhelperdir}#g" > $(UDEV_RULES_FILE) +$(UDEV_RULES_FILE): $(UDEV_RULES) + $(ECHO) " SED " $@ + @cat $(UDEV_RULES) | sed -e "s#__UDEVHELPERDIR__#${udevhelperdir}#g" > $@ clean: -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ @@ -269,7 +258,6 @@ clean: -rm -f $(CBDUMP) $(CISDUMP) -rm -f src/yacc_config.c src/yacc_config.d src/lex_config.c src/lex_config.d src/yacc_config.h -rm -f udev/60-pcmcia.rules - -rm -f build/ccdv install-hotplug: $(INSTALL) -d $(DESTDIR)$(hotplugdir) diff --git a/build/ccdv.c b/build/ccdv.c deleted file mode 100644 index e3ae9da..0000000 --- a/build/ccdv.c +++ /dev/null @@ -1,387 +0,0 @@ -/* ccdv.c - * - * Copyright (C) 2002-2003, by Mike Gleason, NcFTP Software. - * All Rights Reserved. - * - * Licensed under the GNU Public License. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SETCOLOR_SUCCESS (gANSIEscapes ? "\033\1331;32m" : "") -#define SETCOLOR_FAILURE (gANSIEscapes ? "\033\1331;31m" : "") -#define SETCOLOR_WARNING (gANSIEscapes ? "\033\1331;33m" : "") -#define SETCOLOR_NORMAL (gANSIEscapes ? "\033\1330;39m" : "") - -#define TEXT_BLOCK_SIZE 8192 -#define INDENT 2 - -#define TERMS "vt100:vt102:vt220:vt320:xterm:xterm-color:ansi:linux:scoterm:scoansi:dtterm:cons25:cygwin" - -size_t gNBufUsed = 0, gNBufAllocated = 0; -char *gBuf = NULL; -int gCCPID; -char gAction[200] = ""; -char gTarget[200] = ""; -char gAr[32] = ""; -char gArLibraryTarget[64] = ""; -int gDumpCmdArgs = 0; -char gArgsStr[1000]; -int gColumns = 80; -int gANSIEscapes = 0; -int gExitStatus = 95; - -static void DumpFormattedOutput(void) -{ - char *cp; - char spaces[8 + 1] = " "; - char *saved; - int curcol; - int i; - - curcol = 0; - saved = NULL; - for (cp = gBuf + ((gDumpCmdArgs == 0) ? strlen(gArgsStr) : 0); ; cp++) { - if (*cp == '\0') { - if (saved != NULL) { - cp = saved; - saved = NULL; - } else break; - } - if (*cp == '\r') - continue; - if (*cp == '\t') { - saved = cp + 1; - cp = spaces + 8 - (8 - ((curcol - INDENT - 1) % 8)); - } - if (curcol == 0) { - for (i = INDENT; --i >= 0; ) - putchar(' '); - curcol = INDENT; - } - putchar(*cp); - if (++curcol == (gColumns - 1)) { - putchar('\n'); - curcol = 0; - } else if (*cp == '\n') - curcol = 0; - } - free(gBuf); -} /* DumpFormattedOutput */ - - - -/* Difftime(), only for timeval structures. */ -static void TimeValSubtract(struct timeval *tdiff, struct timeval *t1, struct timeval *t0) -{ - tdiff->tv_sec = t1->tv_sec - t0->tv_sec; - tdiff->tv_usec = t1->tv_usec - t0->tv_usec; - if (tdiff->tv_usec < 0) { - tdiff->tv_sec--; - tdiff->tv_usec += 1000000; - } -} /* TimeValSubtract */ - - - -static void Wait(void) -{ - int pid2, status; - - do { - status = 0; - pid2 = (int) waitpid(gCCPID, &status, 0); - } while (((pid2 >= 0) && (! WIFEXITED(status))) || ((pid2 < 0) && (errno == EINTR))); - if (WIFEXITED(status)) - gExitStatus = WEXITSTATUS(status); -} /* Wait */ - - - -static int SlurpProgress(int fd) -{ - char s1[71]; - char *newbuf; - int nready; - size_t ntoread; - ssize_t nread; - struct timeval now, tnext, tleft; - fd_set ss; - fd_set ss2; - const char *trail = "/-\\|", *trailcp; - - trailcp = trail; - snprintf(s1, sizeof(s1), "%s%s%s... ", gAction, gTarget[0] ? " " : "", gTarget); - printf("\r%-70s%-9s", s1, ""); - fflush(stdout); - - gettimeofday(&now, NULL); - tnext = now; - tnext.tv_sec++; - tleft.tv_sec = 1; - tleft.tv_usec = 0; - FD_ZERO(&ss2); - FD_SET(fd, &ss2); - for(;;) { - if (gNBufUsed == (gNBufAllocated - 1)) { - if ((newbuf = (char *) realloc(gBuf, gNBufAllocated + TEXT_BLOCK_SIZE)) == NULL) { - perror("ccdv: realloc"); - return (-1); - } - gNBufAllocated += TEXT_BLOCK_SIZE; - gBuf = newbuf; - } - for (;;) { - ss = ss2; - nready = select(fd + 1, &ss, NULL, NULL, &tleft); - if (nready == 1) - break; - if (nready < 0) { - if (errno != EINTR) { - perror("ccdv: select"); - return (-1); - } - continue; - } - gettimeofday(&now, NULL); - if ((now.tv_sec > tnext.tv_sec) || ((now.tv_sec == tnext.tv_sec) && (now.tv_usec >= tnext.tv_usec))) { - tnext = now; - tnext.tv_sec++; - tleft.tv_sec = 1; - tleft.tv_usec = 0; - printf("\r%-71s%c%-7s", s1, *trailcp, ""); - fflush(stdout); - if (*++trailcp == '\0') - trailcp = trail; - } else { - TimeValSubtract(&tleft, &tnext, &now); - } - } - ntoread = (gNBufAllocated - gNBufUsed - 1); - nread = read(fd, gBuf + gNBufUsed, ntoread); - if (nread < 0) { - if (errno == EINTR) - continue; - perror("ccdv: read"); - return (-1); - } else if (nread == 0) { - break; - } - gNBufUsed += nread; - gBuf[gNBufUsed] = '\0'; - } - snprintf(s1, sizeof(s1), "%s%s%s: ", gAction, gTarget[0] ? " " : "", gTarget); - Wait(); - if (gExitStatus == 0) { - printf("\r%-70s", s1); - printf("[%s%s%s]", ((gNBufUsed - strlen(gArgsStr)) < 4) ? SETCOLOR_SUCCESS : SETCOLOR_WARNING, "OK", SETCOLOR_NORMAL); - printf("%-5s\n", " "); - } else { - printf("\r%-70s", s1); - printf("[%s%s%s]", SETCOLOR_FAILURE, "ERROR", SETCOLOR_NORMAL); - printf("%-2s\n", " "); - gDumpCmdArgs = 1; /* print cmd when there are errors */ - } - fflush(stdout); - return (0); -} /* SlurpProgress */ - - - -static int SlurpAll(int fd) -{ - char *newbuf; - size_t ntoread; - ssize_t nread; - - printf("%s%s%s.\n", gAction, gTarget[0] ? " " : "", gTarget); - fflush(stdout); - - for(;;) { - if (gNBufUsed == (gNBufAllocated - 1)) { - if ((newbuf = (char *) realloc(gBuf, gNBufAllocated + TEXT_BLOCK_SIZE)) == NULL) { - perror("ccdv: realloc"); - return (-1); - } - gNBufAllocated += TEXT_BLOCK_SIZE; - gBuf = newbuf; - } - ntoread = (gNBufAllocated - gNBufUsed - 1); - nread = read(fd, gBuf + gNBufUsed, ntoread); - if (nread < 0) { - if (errno == EINTR) - continue; - perror("ccdv: read"); - return (-1); - } else if (nread == 0) { - break; - } - gNBufUsed += nread; - gBuf[gNBufUsed] = '\0'; - } - Wait(); - gDumpCmdArgs = (gExitStatus != 0); /* print cmd when there are errors */ - return (0); -} /* SlurpAll */ - - - -static const char *Basename(const char *path) -{ - const char *cp; - cp = strrchr(path, '/'); - if (cp == NULL) - return (path); - return (cp + 1); -} /* Basename */ - - - -static const char * Extension(const char *path) -{ - const char *cp = path; - cp = strrchr(path, '.'); - if (cp == NULL) - return (""); - // printf("Extension='%s'\n", cp); - return (cp); -} /* Extension */ - - - -static void Usage(void) -{ - fprintf(stderr, "Usage: ccdv /path/to/cc CFLAGS...\n\n"); - fprintf(stderr, "I wrote this to reduce the deluge Make output to make finding actual problems\n"); - fprintf(stderr, "easier. It is intended to be invoked from Makefiles, like this. Instead of:\n\n"); - fprintf(stderr, "\t.c.o:\n"); - fprintf(stderr, "\t\t$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c\n"); - fprintf(stderr, "\nRewrite your rule so it looks like:\n\n"); - fprintf(stderr, "\t.c.o:\n"); - fprintf(stderr, "\t\t@ccdv $(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c\n\n"); - fprintf(stderr, "ccdv 1.1.0 is Free under the GNU Public License. Enjoy!\n"); - fprintf(stderr, " -- Mike Gleason, NcFTP Software \n"); - exit(96); -} /* Usage */ - - - -int main(int argc, char **argv) -{ - int pipe1[2]; - int devnull; - char emerg[256]; - int fd; - int nread; - int i; - int cc = 0, pch = 0; - const char *quote; - - if (argc < 2) - Usage(); - - snprintf(gAction, sizeof(gAction), "Running %s", Basename(argv[1])); - memset(gArgsStr, 0, sizeof(gArgsStr)); - for (i = 1; i < argc; i++) { - // printf("argv[%d]='%s'\n", i, argv[i]); - quote = (strchr(argv[i], ' ') != NULL) ? "\"" : ""; - snprintf(gArgsStr + strlen(gArgsStr), sizeof(gArgsStr) - strlen(gArgsStr), "%s%s%s%s%s", (i == 1) ? "" : " ", quote, argv[i], quote, (i == (argc - 1)) ? "\n" : ""); - if ((strcmp(argv[i], "-o") == 0) && ((i + 1) < argc)) { - if (strcasecmp(Extension(argv[i + 1]), ".o") != 0) { - strcpy(gAction, "Linking"); - snprintf(gTarget, sizeof(gTarget), "%s", Basename(argv[i + 1])); - } - } else if (strchr("-+", (int) argv[i][0]) != NULL) { - continue; - } else if (strncasecmp(Extension(argv[i]), ".c", 2) == 0) { - cc++; - snprintf(gTarget, sizeof(gTarget), "%s", Basename(argv[i])); - // printf("gTarget='%s'\n", gTarget); - } else if ((strncasecmp(Extension(argv[i]), ".h", 2) == 0) && (cc == 0)) { - pch++; - snprintf(gTarget, sizeof(gTarget), "%s", Basename(argv[i])); - } else if ((i == 1) && (strcmp(Basename(argv[i]), "ar") == 0)) { - snprintf(gAr, sizeof(gAr), "%s", Basename(argv[i])); - } else if ((gArLibraryTarget[0] == '\0') && (strcasecmp(Extension(argv[i]), ".a") == 0)) { - snprintf(gArLibraryTarget, sizeof(gArLibraryTarget), "%s", Basename(argv[i])); - } - } - if ((gAr[0] != '\0') && (gArLibraryTarget[0] != '\0')) { - strcpy(gAction, "Creating library"); - snprintf(gTarget, sizeof(gTarget), "%s", gArLibraryTarget); - } else if (pch > 0) { - strcpy(gAction, "Precompiling"); - } else if (cc > 0) { - strcpy(gAction, "Compiling"); - } - - if (pipe(pipe1) < 0) { - perror("ccdv: pipe"); - exit(97); - } - - (void) close(0); - devnull = open("/dev/null", O_RDWR, 00666); - if ((devnull != 0) && (dup2(devnull, 0) == 0)) - close(devnull); - - gCCPID = (int) fork(); - if (gCCPID < 0) { - (void) close(pipe1[0]); - (void) close(pipe1[1]); - perror("ccdv: fork"); - exit(98); - } else if (gCCPID == 0) { - /* Child */ - (void) close(pipe1[0]); /* close read end */ - if (pipe1[1] != 1) { /* use write end on stdout */ - (void) dup2(pipe1[1], 1); - (void) close(pipe1[1]); - } - (void) dup2(1, 2); /* use write end on stderr */ - execvp(argv[1], argv + 1); - perror(argv[1]); - exit(99); - } - - /* parent */ - (void) close(pipe1[1]); /* close write end */ - fd = pipe1[0]; /* use read end */ - - gColumns = (getenv("COLUMNS") != NULL) ? atoi(getenv("COLUMNS")) : 80; - gANSIEscapes = (getenv("TERM") != NULL) && (strstr(TERMS, getenv("TERM")) != NULL); - gBuf = (char *) malloc(TEXT_BLOCK_SIZE); - if (gBuf == NULL) - goto panic; - gNBufUsed = 0; - gNBufAllocated = TEXT_BLOCK_SIZE; - if (strlen(gArgsStr) < (gNBufAllocated - 1)) { - strcpy(gBuf, gArgsStr); - gNBufUsed = strlen(gArgsStr); - } - - if (isatty(1)) { - if (SlurpProgress(fd) < 0) - goto panic; - } else { - if (SlurpAll(fd) < 0) - goto panic; - } - DumpFormattedOutput(); - exit(gExitStatus); - -panic: - gDumpCmdArgs = 1; /* print cmd when there are errors */ - DumpFormattedOutput(); - while ((nread = read(fd, emerg, (size_t) sizeof(emerg))) > 0) - (void) write(2, emerg, (size_t) nread); - Wait(); - exit(gExitStatus); -} /* main */ diff --git a/doc/mini-howto.txt b/doc/mini-howto.txt index 78d8d2b..3e4ecd3 100644 --- a/doc/mini-howto.txt +++ b/doc/mini-howto.txt @@ -112,8 +112,7 @@ Table of contents: 2.3. Dependencies ----------------- - To use any of the PCMCIAutils tools, you need sysfsutils 1.3.0 or - newer. However, if you do not need a resource database, you do not run + If you do not need a resource database, you do not run a modular kernel and you are lucky, you might not need any userspace tools at all. diff --git a/pcmciautils.spec b/pcmciautils.spec new file mode 100644 index 0000000..85e04c2 --- /dev/null +++ b/pcmciautils.spec @@ -0,0 +1,120 @@ +Name: pcmciautils +Version: 018 +Release: alt1 +Summary: PCMCIA utilities +Group: System/Configuration/Hardware +License: GPL +Url: http://www.kernel.org/pub/linux/utils/kernel/pcmcia/pcmcia.html +Packager: Valery Inozemtsev + +Requires: udev >= 118 + +Source: %name-%version.tar +Patch: %name-%version-%release.patch + +BuildRequires: flex libpci-devel + +%description +%name contains udev config and initialization tools necessary +to allow the PCMCIA subsystem to behave (almost) as every other +hotpluggable bus system + +%prep +%setup -q +%patch -p1 + +%build +%make all + +%install +%make DESTDIR=%buildroot install + +%files +/lib/udev/rules.d/*.rules +%dir %_sysconfdir/pcmcia +%config(noreplace) %_sysconfdir/pcmcia/config.opts +/sbin/lspcmcia +/sbin/pccardctl +/lib/udev/pcmcia-* +%_man8dir/*.8* + +%changelog +* Fri Apr 22 2011 Valery Inozemtsev 018-alt1 +- 018 + +* Mon Nov 22 2010 Valery Inozemtsev 017-alt2 +- updated to master git.c96724a + +* Sat Jan 09 2010 Valery Inozemtsev 017-alt1 +- 017 + +* Sun Sep 28 2008 Valery Inozemtsev 015-alt1 +- 015 + +* Sat Jun 14 2008 Valery Inozemtsev 014-alt7 +- added %_sysconfdir/pcmcia/cis +- fixed segfault on pcmcia-socket-startup + +* Sun Feb 10 2008 Valery Inozemtsev 014-alt6 +- fixed udev rules +- droped cis + +* Sun Apr 01 2007 Valery Inozemtsev 014-alt5 +- added -b option to all modprobe invocations +- removed exclude irq 7 +- drop %name-hotplug subpackage + +* Tue Feb 27 2007 Valery Inozemtsev 014-alt4 +- added exclude irq 3,4,7 for config.opts + +* Fri Jan 19 2007 Valery Inozemtsev 014-alt3 +- correct update %_sysconfdir/sysconfig/hotplug + +* Wed Jan 17 2007 Valery Inozemtsev 014-alt2 +- added udev rules +- moved hotplug scripts to %name-hotplug subpackage + +* Sun Jun 04 2006 Valery Inozemtsev 014-alt1 +- 014 + +* Sun May 07 2006 Valery Inozemtsev 013-alt2 +- used optimization flags from RPM_OPT_FLAGS + +* Mon Mar 27 2006 Valery Inozemtsev 013-alt1 +- 013 + +* Tue Feb 21 2006 Valery Inozemtsev 012-alt4 +- removed obsoleted probe io options +- removed support APM + +* Thu Feb 02 2006 Valery Inozemtsev 012-alt3 +- fixed post scripts (#9006) + +* Sat Jan 28 2006 Valery Inozemtsev 012-alt2 +- fixed #8733 + +* Tue Dec 20 2005 Valery Inozemtsev 012-alt1 +- 012 + +* Tue Sep 20 2005 Valery Inozemtsev 010-alt1 +- 010 + +* Thu Sep 15 2005 Valery Inozemtsev 009-alt1 +- 009 + +* Tue Sep 06 2005 Valery Inozemtsev 008-alt1 +- 008 + +* Tue Jul 26 2005 Valery Inozemtsev 007-alt1 +- 007 +- added apm support + +* Sat Jul 16 2005 Valery Inozemtsev 006-alt1 +- 006 + +* Mon Jul 04 2005 Valery Inozemtsev 005-alt1 +- 005 + +* Sun Jun 19 2005 Valery Inozemtsev 003-alt1 +- initial release + diff --git a/src/pccardctl.c b/src/pccardctl.c index 05cb3a0..2147989 100644 --- a/src/pccardctl.c +++ b/src/pccardctl.c @@ -19,12 +19,13 @@ #include #include #include - -#include - +#include +#include +#include #include #define MAX_SOCKET 8 +#define SYSFS_PATH_MAX 255 static const char * const fn[] = { "multifunction", @@ -51,87 +52,89 @@ static unsigned int crc32(unsigned char const *p, unsigned int len) return crc; } +static int sysfs_write_file(const char *fname, const char *value, size_t len) +{ + ssize_t numwrite; + int fd; + int ret = 0; + + fd = open(fname, O_WRONLY); + if (fd <= 0) + return fd; + + numwrite = write(fd, value, len); + if ((numwrite < 1) || ((size_t) numwrite != len)) + ret = -EIO; + + close(fd); + return ret; +} static int pccardctl_power_socket(unsigned long socket_no, unsigned int power) { - int ret; char file[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/card_pm_state", socket_no); - attr = sysfs_open_attribute(file); - if (!attr) - return -ENODEV; - - ret = sysfs_write_attribute(attr, power ? "off" : "on", power ? 3 : 2); - - sysfs_close_attribute(attr); - - return ret; + return sysfs_write_file(file, power ? "off" : "on", power ? 3 : 2); } static int pccardctl_echo_one(unsigned long socket_no, const char *in_file) { - int ret; char file[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/%s", socket_no, in_file); - attr = sysfs_open_attribute(file); - if (!attr) - return -ENODEV; - - ret = sysfs_write_attribute(attr, "42", 2); - - sysfs_close_attribute(attr); - - return ret; + return sysfs_write_file(file, "42", 2); } static int pccardctl_socket_exists(unsigned long socket_no) { char file[SYSFS_PATH_MAX]; + struct stat st; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/card_insert", socket_no); - return !(sysfs_path_is_file(file)); + return !stat(file, &st); } -static int read_out_file(char *file, char **output) +static int sysfs_read_whole_file(char *file, char **output) { - struct sysfs_attribute *attr = sysfs_open_attribute(file); - int ret; char *result = NULL; + ssize_t numread; + off_t size; + int fd, ret = 0; *output = NULL; - if (!attr) - return -EIO; - ret = sysfs_read_attribute(attr); + fd = open(file, O_RDONLY); + if (fd <= 0) + return fd; - if (ret || !attr->value || !attr->len || (attr->len > SYSFS_PATH_MAX)) - goto close_out; + /* determine size */ + size = lseek(fd, 0, SEEK_END) + SYSFS_PATH_MAX; + result = malloc(size); + if (!result) { + close(fd); + return -ENOMEM; + } - result = malloc(attr->len + 1); - if (result) { - memcpy(result, attr->value, attr->len); - result[attr->len] = '\0'; - if (result[attr->len - 1] == '\n') - result[attr->len - 1] = '\0'; + lseek(fd, 0, SEEK_SET); + numread = read(fd, result, size - 1); + if (numread < 1) + ret = -EIO; + else { + result[numread] = '\0'; *output = result; - } else - ret = -ENOMEM; + } - close_out: - sysfs_close_attribute(attr); + close(fd); return ret; } @@ -144,7 +147,7 @@ static int pccardctl_get_string_socket(unsigned long socket_no, "/sys/class/pcmcia_socket/pcmcia_socket%lu/%s", socket_no, in_file); - return read_out_file(file, output); + return sysfs_read_whole_file(file, output); } static int pccardctl_get_string(unsigned long socket_no, @@ -155,7 +158,7 @@ static int pccardctl_get_string(unsigned long socket_no, snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.0/%s", socket_no, in_file); - return read_out_file(file, output); + return sysfs_read_whole_file(file, output); } static int pccardctl_get_one_f(unsigned long socket_no, unsigned int dev, @@ -163,17 +166,19 @@ static int pccardctl_get_one_f(unsigned long socket_no, unsigned int dev, { char *value; char file[SYSFS_PATH_MAX]; - int ret; + int ret = 0; snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/%s", socket_no, dev, in_file); - ret = read_out_file(file, &value); + ret = sysfs_read_whole_file(file, &value); if (ret || !value) return -EINVAL; if (sscanf(value, "0x%X", result) != 1) - return -EIO; - return 0; + ret = -EIO; + + free(value); + return ret; } static int pccardctl_get_one(unsigned long socket_no, const char *in_file, @@ -187,36 +192,40 @@ static int pccardctl_get_power_device(unsigned long socket_no, { char *value; char file[SYSFS_PATH_MAX]; + int ret = -ENODEV; snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/pm_state", socket_no, func); - read_out_file(file, &value); + sysfs_read_whole_file(file, &value); if (value) { if (!strncmp(value, "off", 3)) - return 1; - return 0; + ret = 1; + ret = 0; + free(value); } - return -ENODEV; + return ret; } static int pccardctl_get_power_socket(unsigned long socket_no) { char *value; char file[SYSFS_PATH_MAX]; + int ret = -ENODEV; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/card_pm_state", socket_no); - read_out_file(file, &value); + sysfs_read_whole_file(file, &value); if (value) { if (!strncmp(value, "off", 3)) - return 1; - return 0; + ret = 1; + ret = 0; + free(value); } - return -ENODEV; + return ret; } @@ -262,7 +271,6 @@ static int pccardctl_ident(unsigned long socket_no) printf(" function: %d (%s)\n", manf_id, s); } - return 0; } @@ -323,6 +331,8 @@ static int pccardctl_status(unsigned long socket_no) printf(" %s %s %s", card_voltage, card_type, is_cardbus ? "CardBus card" : "PC Card"); + free(card_type); + free(card_voltage); susp = pccardctl_get_power_socket(socket_no); if (susp > 0) @@ -365,7 +375,7 @@ static int pccardctl_status(unsigned long socket_no) static void print_header(void) { printf("pcmciautils %s\n", PCMCIAUTILS_VERSION); - printf("Copyright (C) 2004-2005 Dominik Brodowski, " + printf("Copyright (C) 2004-2011 Dominik Brodowski, " "(C) 1999 David A. Hinds\n"); printf("Report errors and bugs to ," "please.\n"); @@ -412,7 +422,6 @@ static void lspcmcia_socket_available_resources(unsigned long socket_no, char *which) { char file[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; int ret, length, first = 0; char *sep; char *result = NULL; @@ -421,27 +430,10 @@ static void lspcmcia_socket_available_resources(unsigned long socket_no, "/sys/class/pcmcia_socket/pcmcia_socket%lu/available_resources_%s", socket_no, which); - attr = sysfs_open_attribute(file); - if (!attr) - return; - - - ret = sysfs_read_attribute(attr); - if (ret) - goto close_out; - printf("\t\t\tAvailable %s:\t", which[0] == 'i' ? "ioports" : "iomem"); - if (!attr->value || !attr->len || (attr->len < 5)) - goto close_out; - - result = malloc(attr->len + 1); - if (result) { - memcpy(result, attr->value, attr->len); - result[attr->len] = '\0'; - if (result[attr->len - 1] == '\n') - result[attr->len - 1] = '\0'; - } else + ret = sysfs_read_whole_file(file, &result); + if (ret) goto close_out; ret = 0; @@ -458,15 +450,13 @@ static void lspcmcia_socket_available_resources(unsigned long socket_no, ret += length + 1; } } while (sep); - if (result) { - printf("%s\n", &result[ret]); - first++; - } + printf("%s\n", &result[ret]); + first++; + free(result); close_out: if (!first) printf("--none--\n"); - sysfs_close_attribute(attr); return; } @@ -479,7 +469,6 @@ static void lspcmcia_socket(unsigned long socket_no, int verbose, char *driver) pccardctl_get_string_socket(socket_no, "available_resources_setup_done", &ready); - printf("\tConfiguration:\tstate: %s\tready: %s\n", pm_state ? "suspended" : "on", ready ? ready : "unknown"); @@ -489,6 +478,10 @@ static void lspcmcia_socket(unsigned long socket_no, int verbose, char *driver) if (card_voltage && card_vpp && card_vcc) printf("\t\t\tVoltage: %s Vcc: %s Vpp: %s\n", card_voltage, card_vcc, card_vpp); + free(card_voltage); + free(card_vpp); + free(card_vcc); + free(ready); if (verbose > 1) { char *irq_mask_s; @@ -511,7 +504,7 @@ static void lspcmcia_socket(unsigned long socket_no, int verbose, char *driver) printf("none"); printf("\n"); } - + free(irq_mask_s); lspcmcia_socket_available_resources(socket_no, "io"); lspcmcia_socket_available_resources(socket_no, "mem"); } @@ -521,7 +514,6 @@ static void lspcmcia_socket(unsigned long socket_no, int verbose, char *driver) static void lspcmcia_device_resources(unsigned long socket_no, int fun) { char file[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; int ret, length; char *sep; char *result = NULL; @@ -529,25 +521,9 @@ static void lspcmcia_device_resources(unsigned long socket_no, int fun) snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/resources", socket_no, fun); - attr = sysfs_open_attribute(file); - if (!attr) - return; - - ret = sysfs_read_attribute(attr); + ret = sysfs_read_whole_file(file, &result); if (ret) - goto close_out; - - if (!attr->value || !attr->len || (attr->len < 5)) - goto close_out; - - result = malloc(attr->len + 1); - if (result) { - memcpy(result, attr->value, attr->len); - result[attr->len] = '\0'; - if (result[attr->len - 1] == '\n') - result[attr->len - 1] = '\0'; - } else - goto close_out; + return; ret = 0; printf("\t\t\t"); @@ -563,11 +539,9 @@ static void lspcmcia_device_resources(unsigned long socket_no, int fun) ret += length + 1; } } while (sep); - if (result) - printf("%s\n", &result[ret]); + printf("%s\n", &result[ret]); - close_out: - sysfs_close_attribute(attr); + free(result); return; } @@ -620,7 +594,6 @@ static int lspcmcia(unsigned long socket_no, int verbose) if (verbose) lspcmcia_socket(socket_no, verbose, drv); - pccardctl_get_string_socket(socket_no, "card_type", &res); if (!res) return 0; @@ -628,8 +601,10 @@ static int lspcmcia(unsigned long socket_no, int verbose) if (!strncmp(res, "32", 2)) { printf(" CardBus card -- see \"lspci\" " "for more information\n"); + free(res); return 0; } + free(res); for (i = 0; i < 4; i++) { int function; @@ -666,6 +641,7 @@ static int lspcmcia(unsigned long socket_no, int verbose) pccardctl_get_string(socket_no, file, &res); if (res) printf("%s ", res); + free(res); } printf("\n"); @@ -694,6 +670,7 @@ static int lspcmcia(unsigned long socket_no, int verbose) printf("prod_id(%u): --- (---)\n", j); if (j < 4) printf("\t\t\t"); + free(res); } } } diff --git a/src/pcmcia-check-broken-cis.c b/src/pcmcia-check-broken-cis.c index aec1f67..98f0f9b 100644 --- a/src/pcmcia-check-broken-cis.c +++ b/src/pcmcia-check-broken-cis.c @@ -24,12 +24,12 @@ #include #include +#include #include "cistpl.h" #define FIRMWARE_PATH "/lib/firmware" -#define CIS_PATH "/etc/pcmcia/cis" #define SOCKET_PATH "/sys/class/pcmcia_socket/pcmcia_socket%d/cis" struct needs_cis { @@ -72,17 +72,23 @@ static char *read_cis(char *cis_file, int *size) char *ret; int rc, cis_fd; struct stat sbuf; + struct utsname kernel; - cis_path = alloca(strlen(FIRMWARE_PATH) + strlen(cis_file) + 2); - sprintf(cis_path, "%s/%s", FIRMWARE_PATH, cis_file); + uname(&kernel); + cis_path = alloca(strlen(FIRMWARE_PATH) + strlen(kernel.release) + strlen(cis_file) + 7); + sprintf(cis_path,"%s/%s/%s/%s", FIRMWARE_PATH, kernel.release, "cis", cis_file); cis_fd = open(cis_path, O_RDONLY); if (cis_fd == -1) { - cis_path = alloca(strlen(CIS_PATH) + strlen(cis_file) + 2); - sprintf(cis_path, "%s/%s", CIS_PATH, cis_file); + cis_path = alloca(strlen(FIRMWARE_PATH) + strlen(cis_file) + 6); + sprintf(cis_path,"%s/%s/%s", FIRMWARE_PATH, "cis", cis_file); if (cis_fd == -1) { - rc = errno; - errno = rc; - return NULL; + cis_path = alloca(strlen(FIRMWARE_PATH) + strlen(cis_file) + 2); + sprintf(cis_path,"%s/%s", FIRMWARE_PATH, cis_file); + if (cis_fd == -1) { + rc = errno; + errno = rc; + return NULL; + } } } fstat(cis_fd, &sbuf); diff --git a/src/read-cis.c b/src/read-cis.c index 0c2fb48..7204f69 100644 --- a/src/read-cis.c +++ b/src/read-cis.c @@ -18,11 +18,10 @@ #include #include -#include - #include "cistpl.h" #define MAX_TUPLES 0x200 +#define SYSFS_PATH_MAX 255 #define PATH_TO_SOCKET "/sys/class/pcmcia_socket/" diff --git a/src/startup.c b/src/startup.c index ac0ba54..d8e6679 100644 --- a/src/startup.c +++ b/src/startup.c @@ -15,10 +15,11 @@ #include #include #include +#include +#include +#include #include -#include - #include "startup.h" /* uncomment for debug output */ @@ -48,6 +49,46 @@ static const char *resource_files[MAX_RESOURCE_FILES] = { #define PATH_TO_SOCKET "/sys/class/pcmcia_socket/" +#define SYSFS_PATH_MAX 255 + + +static int sysfs_read_file(const char *fname, char *buf, size_t buflen) +{ + ssize_t numread; + int fd; + int ret = 0; + + fd = open(fname, O_RDONLY); + if (fd <= 0) + return fd; + + numread = read(fd, buf, buflen - 1); + if (numread < 1) + ret = -EIO; + else + buf[numread] = '\0'; + + close(fd); + return ret; +} + +static int sysfs_write_file(const char *fname, const char *value, size_t len) +{ + ssize_t numwrite; + int fd; + int ret = 0; + + fd = open(fname, O_WRONLY); + if (fd <= 0) + return fd; + + numwrite = write(fd, value, len); + if ((numwrite < 1) || ((size_t) numwrite != len)) + ret = -EIO; + + close(fd); + return ret; +} static int add_available_resource(unsigned int socket_no, unsigned int type, unsigned int action, @@ -55,7 +96,6 @@ static int add_available_resource(unsigned int socket_no, unsigned int type, { char file[SYSFS_PATH_MAX]; char content[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; int ret; size_t len; @@ -85,44 +125,24 @@ static int add_available_resource(unsigned int socket_no, unsigned int type, return -EINVAL; } - dprintf("content is %s\n", content); - - dprintf("file is %s\n", file); - - attr = sysfs_open_attribute(file); - if (!attr) - return -ENODEV; + dprintf("content is %s, file is %s\n", content, file); - dprintf("open, len %zu\n", len); - - ret = sysfs_write_attribute(attr, content, len); + ret = sysfs_write_file(file, content, len); dprintf("ret is %d\n", ret); - sysfs_close_attribute(attr); - return ret; } static int setup_done(unsigned int socket_no) { - int ret; char file[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; snprintf(file, SYSFS_PATH_MAX, PATH_TO_SOCKET "pcmcia_socket%u/available_resources_setup_done", socket_no); - attr = sysfs_open_attribute(file); - if (!attr) - return -ENODEV; - - ret = sysfs_write_attribute(attr, "42", 2); - - sysfs_close_attribute(attr); - - return ret; + return sysfs_write_file(file, "42", 2); } @@ -130,7 +150,6 @@ static int disallow_irq(unsigned int socket_no, unsigned int irq) { char file[SYSFS_PATH_MAX]; char content[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; unsigned int mask = 0xfff; unsigned int new_mask; int ret; @@ -144,24 +163,13 @@ static int disallow_irq(unsigned int socket_no, unsigned int irq) socket_no); dprintf("file is %s\n", file); - attr = sysfs_open_attribute(file); - if (!attr) + ret = sysfs_read_file(file, content, SYSFS_PATH_MAX); + if (ret) return -ENODEV; - dprintf("open, len %zu\n", len); - - ret = sysfs_read_attribute(attr); - if (ret) { - ret = -EINVAL; - goto out; - } - - if (!attr->value || (attr->len < 6)) { - ret = -EIO; - goto out; - } - - ret = sscanf(attr->value, "0x%x\n", &mask); + ret = sscanf(content, "0x%x\n", &mask); + if (ret != 1) + return -EIO; new_mask = 1 << irq; @@ -171,12 +179,7 @@ static int disallow_irq(unsigned int socket_no, unsigned int irq) dprintf("content is %s\n", content); - ret = sysfs_write_attribute(attr, content, len); - - out: - sysfs_close_attribute(attr); - - return ret; + return sysfs_write_file(file, content, len); } diff --git a/udev/rules-modprobe b/udev/rules-modprobe index 7fb03f4..3ce59cb 100644 --- a/udev/rules-modprobe +++ b/udev/rules-modprobe @@ -1,3 +1,3 @@ # modprobe $env{MODALIAS} loads all possibly appropriate modules SUBSYSTEM=="pcmcia", ENV{MODALIAS}=="?*", \ - RUN+="/sbin/modprobe $env{MODALIAS}" + RUN+="/sbin/modprobe -b $env{MODALIAS}"