Hi all,
I Thank you for your comments, I send you a new version with lspci and
lsusb.
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-16 05:51:18.000000000 +0100
+++ busybox/include/applets.h 2009-11-17 22:43:02.146828893 +0100
@@ -245,6 +245,8 @@ 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_LSUSB(APPLET_ODDNAME(lsusb, lspci, _BB_DIR_SBIN, _BB_SUID_DROP, lsusb))
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-16 05:51:18.000000000 +0100
+++ busybox/include/usage.h 2009-11-17 22:37:54.726828604 +0100
@@ -2493,6 +2493,19 @@
#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." \
+
+#define lsusb_trivial_usage \
+ ""
+#define lsusb_full_usage "\n\n" \
+ "List all USB devices"
+
#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-16 05:51:18.000000000 +0100
+++ busybox/util-linux/Config.in 2009-11-17 22:33:43.008016386 +0100
@@ -348,6 +348,26 @@ 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 LSUSB
+ bool "lsusb"
+ default n
+ help
+ lsusb is a utility for displaying information about USB buses in the
+ system and devices connected to them.
+
+ This vesrsion uses only sysfs (/sys/bus/usb/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-16 05:51:18.000000000 +0100
+++ busybox/util-linux/Kbuild 2009-11-17 22:34:32.104830061 +0100
@@ -21,6 +21,8 @@ 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_LSUSB) += 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-17 22:25:46.000000000 +0100
@@ -0,0 +1,175 @@
+#include <libbb.h>
+
+#define SCRATCH_SIZE 80
+
+/*
+ * read_uevent: reads uevent file and write the values in the same order as given keys.
+ */
+static void read_uevent(const char *fileName, const char **keys, const char *values[])
+{
+ FILE *uevent;
+ char *uevent_line;
+
+ uevent = xfopen_for_read(fileName);
+ while ((uevent_line = xmalloc_fgetline(uevent)) != NULL) {
+ int i;
+
+ for (i=0; keys[i]; i++) {
+ char *s = strstr(uevent_line, keys[i]);
+ if (s) {
+ values[i] = xstrdup(s+strlen(keys[i])+1);
+ }
+ }
+ }
+ free(uevent_line);
+ fclose(uevent);
+}
+
+#ifdef CONFIG_LSPCI
+enum {
+ OPT_m = (1<<0) * ENABLE_LSPCI,
+ OPT_k = (1<<1) * ENABLE_LSPCI,
+};
+
+static void printf_pci(const char *fileName)
+{
+ const char *values[64];
+ const char *pci_keys[] = {"PCI_SLOT_NAME", "PCI_CLASS", "PCI_ID", "PCI_SUBSYS_ID", "DRIVER", NULL};
+ char did[5];
+
+ memset(did, 0, 5);
+
+ read_uevent(fileName, pci_keys, values);
+
+ // PCI_SLOT_NAME
+ printf("%s ", values[0]+5);
+
+ // PCI_CLASS
+ if (option_mask32 & OPT_m)
+ printf("\"%04x\"", xstrtou(values[1], 16)>>8);
+ else
+ printf("%04x:", xstrtou(values[1], 16)>>8);
+
+ // PCI_ID VID
+ memcpy(did, values[2], 4);
+
+ if (option_mask32 & OPT_m)
+ printf(" \"%04x\" ", xstrtou(did, 16));
+ else
+ printf(" %04x:", xstrtou(did, 16));
+ // PCI_ID DID
+ memcpy(did, values[2]+5, 4);
+ if (option_mask32 & OPT_m)
+ printf("\"%04x\"", xstrtou(did, 16));
+ else
+ printf("%04x", xstrtou(did, 16));
+
+ if (option_mask32 & OPT_m) {
+ // PCI_SUBSYS_ID VID
+ memcpy(did, values[3], 4);
+ if (option_mask32 & OPT_m)
+ printf(" \"%04x\" ", xstrtou(did, 16));
+ else
+ printf(" %04x:", xstrtou(did, 16));
+
+ // PCI_SUBSYS_ID DID
+ memcpy(did, values[3]+5, 4);
+ if (option_mask32 & OPT_m)
+ printf("\"%04x\"", xstrtou(did, 16));
+ else
+ printf("%04x", xstrtou(did, 16));
+ }
+
+ if ((option_mask32 & OPT_k) && values[4]) {
+ if (option_mask32 & OPT_m) {
+ printf(" \"%s\"", values[4]);
+ } else {
+ printf(" %s", values[4]);
+ }
+ }
+ bb_putchar('\n');
+}
+#endif
+
+#ifdef CONFIG_LSUSB
+static void printf_usb(const char *fileName)
+{
+ const char *values[3];
+ const char *usb_keys[] = {"DEVTYPE", "DEVICE", "PRODUCT", NULL};
+ char did[5];
+ const char *s1, *s2;
+
+ memset(did, 0, 5);
+
+ read_uevent(fileName, usb_keys, values);
+
+ if (strcmp(values[0], "usb_interface")) return;
+
+ memcpy(did, values[1]+strlen("/proc/bus/usb/"), 3);
+ printf("Bus %s Device %s: ", did, values[1]+strlen("/proc/bus/usb/000/"));
+
+ s1 = values[2];
+ if (s1[3] == '/') {
+ did[0] = '0';
+ memcpy(did+1, s1, 3);
+ s1 += 4;
+ } else {
+ memcpy(did, s1, 4);
+ s1 += 5;
+ }
+ printf("ID %s:", did);
+
+ s2 = strchr(s1, '/');
+
+ memset(did, 0, 5);
+ memcpy(did, s1, strlen(s1) - strlen(s2));
+
+ printf("%04x", xstrtou(did, 16));
+ bb_putchar('\n');
+}
+#endif
+
+static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf UNUSED_PARAM, void *userData, int depth UNUSED_PARAM)
+{
+ strcpy(userData, (char *)fileName);
+ strcat(userData, "/uevent");
+
+ switch (applet_name[2]) {
+#ifdef CONFIG_LSPCI
+ case 'p':
+ printf_pci(userData);
+ break;
+#endif
+#ifdef CONFIG_LSUSB
+ case 'u':
+ printf_usb(userData);
+ break;
+#endif
+ default:
+ break;
+ }
+
+ 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);
+ const char *bus;
+
+ if (applet_name[2] == 'p') { /* lspci */
+ bus = "/sys/bus/pci/devices";
+ getopt32(argv, "mk");
+ } else { /* lsusb */
+ if (argc != 1)
+ bb_show_usage();
+ bus = "/sys/bus/usb/devices";
+ }
+
+ recursive_action(bus,
+ ACTION_RECURSE,
+ fileAction, NULL, temp, 0);
+
+ return EXIT_SUCCESS;
+}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox