Hi all !
I tried to write a version of lspci, it only uses sysfs and supports 2
options: m and k, it dumps data only in numeric form (not uses pci.ids file)
Regards !
diff -U 3 -H -d -p -r -N -- busybox.orig/include/applets.h busybox/include/applets.h
--- busybox.orig/include/applets.h 2009-11-09 11:12:45.000000000 +0100
+++ busybox/include/applets.h 2009-11-11 20:32:43.762798402 +0100
@@ -245,6 +245,7 @@ IF_LS(APPLET_NOEXEC(ls, ls, _BB_DIR_BIN,
IF_LSATTR(APPLET(lsattr, _BB_DIR_BIN, _BB_SUID_DROP))
IF_LSMOD(APPLET(lsmod, _BB_DIR_SBIN, _BB_SUID_DROP))
IF_MODPROBE_SMALL(APPLET_ODDNAME(lsmod, modprobe, _BB_DIR_SBIN, _BB_SUID_DROP, modprobe))
+IF_LSPCI(APPLET(lspci, _BB_DIR_SBIN, _BB_SUID_DROP))
IF_UNLZMA(APPLET_ODDNAME(lzmacat, unlzma, _BB_DIR_USR_BIN, _BB_SUID_DROP, lzmacat))
IF_LZOP(APPLET(lzop, _BB_DIR_BIN, _BB_SUID_DROP))
IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, _BB_DIR_USR_BIN, _BB_SUID_DROP, lzopcat))
diff -U 3 -H -d -p -r -N -- busybox.orig/include/usage.h busybox/include/usage.h
--- busybox.orig/include/usage.h 2009-11-09 11:12:45.000000000 +0100
+++ busybox/include/usage.h 2009-11-11 21:15:59.813826119 +0100
@@ -2493,6 +2493,14 @@
#define lsmod_full_usage "\n\n" \
"List the currently loaded kernel modules"
+#define lspci_trivial_usage \
+ "[-mk]"
+#define lspci_full_usage "\n\n" \
+ "List all PCI devices" \
+ "\n" \
+ "\n m Produce easily parsed data by scripts." \
+ "\n k Dump kernel driver." \
+
#if ENABLE_FEATURE_MAKEDEVS_LEAF
#define makedevs_trivial_usage \
"NAME TYPE MAJOR MINOR FIRST LAST [s]"
diff -U 3 -H -d -p -r -N -- busybox.orig/util-linux/Config.in busybox/util-linux/Config.in
--- busybox.orig/util-linux/Config.in 2009-11-09 11:12:45.000000000 +0100
+++ busybox/util-linux/Config.in 2009-11-11 21:33:51.255765043 +0100
@@ -348,6 +348,16 @@ config LOSETUP
file or block device, and to query the status of a loop device. This
version does not currently support enabling data encryption.
+config LSPCI
+ bool "lspci"
+ default n
+ help
+ lspci is a utility for displaying information about PCI buses in the
+ system and devices connected to them.
+
+ This vesrsion uses only sysfs (/sys/bus/pci/devices) to collect
+ informations.
+
config MDEV
bool "mdev"
default n
diff -U 3 -H -d -p -r -N -- busybox.orig/util-linux/Kbuild busybox/util-linux/Kbuild
--- busybox.orig/util-linux/Kbuild 2009-11-09 11:12:45.000000000 +0100
+++ busybox/util-linux/Kbuild 2009-11-11 20:51:29.804827323 +0100
@@ -21,6 +21,7 @@ lib-$(CONFIG_HWCLOCK) += hwclo
lib-$(CONFIG_IPCRM) += ipcrm.o
lib-$(CONFIG_IPCS) += ipcs.o
lib-$(CONFIG_LOSETUP) += losetup.o
+lib-$(CONFIG_LSPCI) += lspci.o
lib-$(CONFIG_MDEV) += mdev.o
lib-$(CONFIG_MKFS_EXT2) += mkfs_ext2.o
lib-$(CONFIG_MKFS_MINIX) += mkfs_minix.o
diff -U 3 -H -d -p -r -N -- busybox.orig/util-linux/lspci.c busybox/util-linux/lspci.c
--- busybox.orig/util-linux/lspci.c 1970-01-01 01:00:00.000000000 +0100
+++ busybox/util-linux/lspci.c 2009-11-11 21:18:59.054826572 +0100
@@ -0,0 +1,71 @@
+#include <libbb.h>
+
+#define SCRATCH_SIZE 80
+
+#define printf_vid_did(d) { \
+ snprintf(did, 5, d); \
+ if (option_mask32 & 1) \
+ printf(" \"%04x\" ", xstrtou(did, 16)); \
+ else \
+ printf(" %04x:", xstrtou(did, 16)); \
+ sprintf(did, d+5); \
+ if (option_mask32 & 1) \
+ printf("\"%04x\"", xstrtou(did, 16)); \
+ else \
+ printf("%04x", xstrtou(did, 16)); \
+ }
+
+static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf UNUSED_PARAM, void *userData, int depth UNUSED_PARAM)
+{
+ FILE *uevent;
+ char *uevent_line;
+ char did[5];
+
+ strcpy(userData, (char *)fileName);
+ strcat(userData, "/uevent");
+
+ uevent = xfopen_for_read(userData);
+ while((uevent_line = xmalloc_fgetline(uevent)) != NULL) {
+ putenv(uevent_line);
+ }
+ free(uevent_line);
+ fclose(uevent);
+
+ printf("%s ", getenv("PCI_SLOT_NAME")+5);
+
+ if (option_mask32 & 1) /* -m */
+ printf("\"%04x\"", xstrtou(getenv("PCI_CLASS"), 16)>>8);
+ else
+ printf("%04x:", xstrtou(getenv("PCI_CLASS"), 16)>>8);
+
+ printf_vid_did(getenv("PCI_ID"));
+
+ if (option_mask32 & 1)
+ printf_vid_did(getenv("PCI_SUBSYS_ID"));
+
+ if ((option_mask32 & 2) && getenv("DRIVER")) { /* -k */
+ if (option_mask32 & 1) {
+ printf(" \"%s\"", getenv("DRIVER"));
+ } else {
+ printf(" %s", getenv("DRIVER"));
+ }
+ }
+
+ printf("\n");
+ clearenv();
+ return TRUE;
+}
+
+int lspci_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lspci_main(int argc UNUSED_PARAM, char **argv)
+{
+ RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
+
+ getopt32(argv, "mk");
+
+ recursive_action("/sys/bus/pci/devices",
+ ACTION_RECURSE,
+ fileAction, NULL, temp, 0);
+
+ return 0;
+}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox