[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: lspci lsusb
From: Souf Oued <souf_oued () yahoo ! fr>
Date: 2009-11-21 17:17:25
Message-ID: 4B0820A5.6050904 () yahoo ! fr
[Download RAW message or body]
I rewrote 2 separated applets: lspci and lsusb
busybox --help
Currently defined functions:
[, [[, ash, basename, blkid, cat, chgrp, chmod, chown, chroot,
cksum, cp, cttyhack, cut, date, dd, depmod, dirname, dmesg,
dnsdomainname, eject, false, halt, hostname, init, insmod, kill,
killall, killall5, ln, ls, lsmod, lzmacat, mdev, mkdir, mktemp,
modprobe, mv, ping, poweroff, pwd, readlink, realpath, reboot, rm,
rmdir, rmmod, run-parts, sh, sleep, start-stop-daemon, stty, tar, test,
touch, true, tty, uname, unlzma, usleep, wget, which, who, whoami, yes
in 32 bits environment:
lspci
scripts/bloat-o-meter busybox_unstripped ../aa/busybox_unstripped
function old new delta
applet_nameofs 132 130 -2
applet_main 264 260 -4
applet_names 405 399 -6
packed_usage 4991 4950 -41
lspci_main 58 - -58
.rodata 22686 22488 -198
fileAction 904 433 -471
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/6 up/down: 0/-780) Total: -780 bytes
size lspci.o
text data bss dec hex filename
684 0 0 684 2ac lspci.o
===============================================================================================
lsusb
scripts/bloat-o-meter busybox_unstripped ../aa/busybox_unstripped
function old new delta
packed_usage 4938 4950 +12
applet_nameofs 132 130 -2
applet_main 264 260 -4
applet_names 405 399 -6
lsusb_main 38 - -38
.rodata 22576 22488 -88
fileAction 701 433 -268
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/5 up/down: 12/-406) Total: -394 bytes
size lsusb.o
text data bss dec hex filename
394 0 0 394 18a lsusb.o
in 64 bits environment:
lspci:
scripts/bloat-o-meter ../aa/busybox_unstripped busybox_unstripped
function old new delta
fileAction 489 995 +506
lspci_main - 77 +77
packed_usage 4950 4991 +41
xstrtou - 13 +13
applet_main 520 528 +8
applet_names 399 405 +6
applet_nameofs 130 132 +2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/0 up/down: 653/0) Total: 653 bytes
size(lspci.o)
text data bss dec hex filename
850 0 0 850 352 lspci.o
lsusb:
scripts/bloat-o-meter ../aa/busybox_unstripped busybox_unstripped
function old new delta
fileAction 489 794 +305
lsusb_main - 46 +46
xstrtou - 13 +13
applet_main 520 528 +8
applet_names 399 405 +6
applet_nameofs 130 132 +2
packed_usage 4950 4938 -12
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 380/-12) Total: 368 bytes
size(lsusb.o)
text data bss dec hex filename
543 0 0 543 21f lsusb.o
["lspci.patch" (text/x-patch)]
diff -U 3 -H -d -p -r -N -- busybox.orig/include/applets.h \
busybox.lspci/include/applets.h
--- busybox.orig/include/applets.h 2009-11-20 19:14:19.000000000 +0100
+++ busybox.lspci/include/applets.h 2009-11-21 15:35:01.779454280 +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.lspci/include/usage.h
--- busybox.orig/include/usage.h 2009-11-20 19:14:19.000000000 +0100
+++ busybox.lspci/include/usage.h 2009-11-21 15:36:50.826235769 +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 Parseable output" \
+ "\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.lspci/util-linux/Config.in
--- busybox.orig/util-linux/Config.in 2009-11-20 19:14:19.000000000 +0100
+++ busybox.lspci/util-linux/Config.in 2009-11-21 15:40:15.177267606 +0100
@@ -348,6 +348,15 @@ 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 version uses sysfs (/sys/bus/pci/devices) only.
+
config MDEV
bool "mdev"
default n
diff -U 3 -H -d -p -r -N -- busybox.orig/util-linux/Kbuild \
busybox.lspci/util-linux/Kbuild
--- busybox.orig/util-linux/Kbuild 2009-11-20 19:14:19.000000000 +0100
+++ busybox.lspci/util-linux/Kbuild 2009-11-21 15:33:57.859272591 +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.lspci/util-linux/lspci.c
--- busybox.orig/util-linux/lspci.c 1970-01-01 01:00:00.000000000 +0100
+++ busybox.lspci/util-linux/lspci.c 2009-11-21 15:21:40.000000000 +0100
@@ -0,0 +1,99 @@
+/* vi: set sw=4 ts=4: */
+/*
+* lspci implementation for busybox
+*
+* Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
+*
+* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+*/
+
+#include <libbb.h>
+
+enum {
+ OPT_m = (1<<0),
+ OPT_k = (1<<1),
+};
+
+/*
+ * PCI_SLOT_NAME PCI_CLASS: PCI_VID:PCI_DID [PCI_SUBSYS_VID:PCI_SUBSYS_DID] [DRIVER]
+ */
+static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf \
UNUSED_PARAM, void *userData, int depth UNUSED_PARAM) +{
+ parser_t *parser;
+ char *tokens[3];
+
+ char *pci_slot_name = NULL, *driver = NULL;
+ int pci_class = 0, pci_vid = 0, pci_did = 0;
+ int pci_subsys_vid = 0, pci_subsys_did = 0;
+
+
+ userData = concat_path_file(fileName, "/uevent");
+
+ parser = config_open2(userData, fopen_for_read);
+ while (config_read(parser, tokens, 3, 2, "\0:=", PARSE_NORMAL)) {
+ if (strcmp(tokens[0], "DRIVER") == 0) {
+ driver = xstrdup(tokens[1]);
+ continue;
+ }
+
+ if (strcmp(tokens[0], "PCI_CLASS") == 0) {
+ pci_class = xstrtou(tokens[1], 16)>>8;
+ continue;
+ }
+
+ if (strcmp(tokens[0], "PCI_ID") == 0) {
+ pci_vid = xstrtou(tokens[1], 16);
+ pci_did = xstrtou(tokens[2], 16);
+ continue;
+ }
+
+ if (strcmp(tokens[0], "PCI_SUBSYS_ID") == 0) {
+ pci_subsys_vid = xstrtou(tokens[1], 16);
+ pci_subsys_did = xstrtou(tokens[2], 16);
+ continue;
+ }
+
+ if (strcmp(tokens[0], "PCI_SLOT_NAME") == 0) {
+ pci_slot_name = xstrdup(tokens[2]);
+ continue;
+ }
+ }
+ config_close(parser);
+
+ if (option_mask32 & OPT_m) {
+ printf("%s \"%04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"",
+ pci_slot_name, pci_class, pci_vid, pci_did,
+ pci_subsys_vid, pci_subsys_did);
+ } else {
+ printf("%s %04x: %04x:%04x",
+ pci_slot_name, pci_class, pci_vid, pci_did);
+ }
+
+ if (option_mask32 & OPT_k && driver) {
+ if (option_mask32 & OPT_m) {
+ printf(" \"%s\"", driver);
+ } else {
+ printf(" %s", driver);
+ }
+ }
+ bb_putchar('\n');
+
+ free(driver);
+ free(pci_slot_name);
+
+ 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);
+
+ getopt32(argv, "mk");
+
+ recursive_action("/sys/bus/pci/devices",
+ ACTION_RECURSE,
+ fileAction, NULL, temp, 0);
+
+ return EXIT_SUCCESS;
+}
["lsusb.patch" (text/x-patch)]
diff -U 3 -H -d -p -r -N -- busybox.orig/include/applets.h \
busybox.lsusb/include/applets.h
--- busybox.orig/include/applets.h 2009-11-21 15:35:01.779454280 +0100
+++ busybox.lsusb/include/applets.h 2009-11-21 15:46:50.867298434 +0100
@@ -246,6 +246,7 @@ IF_LSATTR(APPLET(lsattr, _BB_DIR_BIN, _B
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(lsusb, _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.lsusb/include/usage.h
--- busybox.orig/include/usage.h 2009-11-21 15:36:50.826235769 +0100
+++ busybox.lsusb/include/usage.h 2009-11-21 15:49:04.432237592 +0100
@@ -2501,6 +2501,9 @@
"\n m Parseable output" \
"\n k Dump kernel driver" \
+#define lsusb_trivial_usage NOUSAGE_STR
+#define lsusb_full_usage ""
+
#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.lsusb/util-linux/Config.in
--- busybox.orig/util-linux/Config.in 2009-11-21 15:40:15.177267606 +0100
+++ busybox.lsusb/util-linux/Config.in 2009-11-21 15:45:16.358406051 +0100
@@ -357,6 +357,15 @@ config LSPCI
This version uses sysfs (/sys/bus/pci/devices) only.
+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 version uses sysfs (/sys/bus/usb/devices) only.
+
config MDEV
bool "mdev"
default n
diff -U 3 -H -d -p -r -N -- busybox.orig/util-linux/Kbuild \
busybox.lsusb/util-linux/Kbuild
--- busybox.orig/util-linux/Kbuild 2009-11-21 15:33:57.859272591 +0100
+++ busybox.lsusb/util-linux/Kbuild 2009-11-21 15:45:47.598235995 +0100
@@ -22,6 +22,7 @@ lib-$(CONFIG_IPCRM) += ipcrm
lib-$(CONFIG_IPCS) += ipcs.o
lib-$(CONFIG_LOSETUP) += losetup.o
lib-$(CONFIG_LSPCI) += lspci.o
+lib-$(CONFIG_LSUSB) += lsusb.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/lsusb.c \
busybox.lsusb/util-linux/lsusb.c
--- busybox.orig/util-linux/lsusb.c 1970-01-01 01:00:00.000000000 +0100
+++ busybox.lsusb/util-linux/lsusb.c 2009-11-21 15:28:51.000000000 +0100
@@ -0,0 +1,63 @@
+/* vi: set sw=4 ts=4: */
+/*
+* lspci implementation for busybox
+*
+* Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
+*
+* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+*/
+
+#include <libbb.h>
+
+static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf \
UNUSED_PARAM, void *userData, int depth UNUSED_PARAM) +{
+ parser_t *parser;
+ char *tokens[6];
+ char *bus = NULL, *device = NULL;
+ int product_vid = 0, product_did = 0;
+
+ userData = concat_path_file(fileName, "/uevent");
+
+ parser = config_open2(userData, fopen_for_read);
+ while (config_read(parser, tokens, 6, 1, "\\/=", PARSE_NORMAL)) {
+ if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
+ break;
+ }
+
+ if (strcmp(tokens[0], "DEVICE") == 0) {
+ bus = xstrdup(tokens[4]);
+ device = xstrdup(tokens[5]);
+ continue;
+ }
+
+ if (strcmp(tokens[0], "PRODUCT") == 0) {
+ product_vid = xstrtou(tokens[1], 16);
+ product_did = xstrtou(tokens[2], 16);
+ continue;
+ }
+ }
+ config_close(parser);
+
+ if (bus) {
+ printf("Bus %s Device %s: ID %04x:%04x\n", bus, device, product_vid, product_did);
+
+ free(bus);
+ free(device);
+ }
+
+ return TRUE;
+}
+
+int lsusb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+ RESERVE_CONFIG_BUFFER(temp, PATH_MAX);
+
+ /* no options, no getopt */
+
+ recursive_action("/sys/bus/usb/devices",
+ ACTION_RECURSE,
+ fileAction, NULL, temp, 0);
+
+ return EXIT_SUCCESS;
+}
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic