From 3a72bc7f889b43174b7b61a10e93505e5cbfd640 Mon Sep 17 00:00:00 2001 From: Fedor Date: Tue, 9 Feb 2010 18:13:25 -0500 Subject: [PATCH] Busybox: patches from trunc (modprobe, swap vol id, lspci/lsusb, mount, bb_ask, wget) --- release/src/router/busybox/include/applets.h | 2 + release/src/router/busybox/include/usage.h | 11 +++ release/src/router/busybox/libbb/bb_askpass.c | 5 +- release/src/router/busybox/modutils/modprobe.c | 14 +-- release/src/router/busybox/networking/wget.c | 6 +- release/src/router/busybox/util-linux/Config.in | 18 ++++ release/src/router/busybox/util-linux/Kbuild | 2 + release/src/router/busybox/util-linux/lspci.c | 103 +++++++++++++++++++++ release/src/router/busybox/util-linux/lsusb.c | 67 ++++++++++++++ release/src/router/busybox/util-linux/mount.c | 5 + .../busybox/util-linux/volume_id/linux_swap.c | 6 +- 11 files changed, 228 insertions(+), 11 deletions(-) create mode 100644 release/src/router/busybox/util-linux/lspci.c create mode 100644 release/src/router/busybox/util-linux/lsusb.c diff --git a/release/src/router/busybox/include/applets.h b/release/src/router/busybox/include/applets.h index 32c596d6d6..6a83b5ea88 100644 --- a/release/src/router/busybox/include/applets.h +++ b/release/src/router/busybox/include/applets.h @@ -240,6 +240,8 @@ USE_LS(APPLET_NOEXEC(ls, ls, _BB_DIR_BIN, _BB_SUID_NEVER, ls)) USE_LSATTR(APPLET(lsattr, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_LSMOD(APPLET(lsmod, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_MODPROBE_SMALL(APPLET_ODDNAME(lsmod, modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER, modprobe)) +USE_LSPCI(APPLET(lspci, _BB_DIR_SBIN, _BB_SUID_NEVER)) +USE_LSUSB(APPLET(lsusb, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_UNLZMA(APPLET_ODDNAME(lzmacat, unlzma, _BB_DIR_USR_BIN, _BB_SUID_NEVER, lzmacat)) USE_MAKEDEVS(APPLET(makedevs, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_MAKEMIME(APPLET(makemime, _BB_DIR_BIN, _BB_SUID_NEVER)) diff --git a/release/src/router/busybox/include/usage.h b/release/src/router/busybox/include/usage.h index b99dd50555..3ec2755542 100644 --- a/release/src/router/busybox/include/usage.h +++ b/release/src/router/busybox/include/usage.h @@ -2408,6 +2408,17 @@ #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 Show 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 --git a/release/src/router/busybox/libbb/bb_askpass.c b/release/src/router/busybox/libbb/bb_askpass.c index c0dcf0c5ff..57283b98e4 100644 --- a/release/src/router/busybox/libbb/bb_askpass.c +++ b/release/src/router/busybox/libbb/bb_askpass.c @@ -39,7 +39,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) tio = oldtio; tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP); - tcsetattr_stdin_TCSANOW(&tio); + tcsetattr(fd, TCSANOW, &tio); memset(&sa, 0, sizeof(sa)); /* sa.sa_flags = 0; - no SA_RESTART! */ @@ -71,8 +71,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) alarm(0); } sigaction_set(SIGINT, &oldsa); - - tcsetattr_stdin_TCSANOW(&oldtio); + tcsetattr(fd, TCSANOW, &oldtio); bb_putchar('\n'); fflush(stdout); return ret; diff --git a/release/src/router/busybox/modutils/modprobe.c b/release/src/router/busybox/modutils/modprobe.c index 4ca057af27..5a99719218 100644 --- a/release/src/router/busybox/modutils/modprobe.c +++ b/release/src/router/busybox/modutils/modprobe.c @@ -69,12 +69,14 @@ static int read_config(const char *path); static char *gather_options_str(char *opts, const char *append) { /* Speed-optimized. We call gather_options_str many times. */ - if (opts == NULL) { - opts = xstrdup(append); - } else { - int optlen = strlen(opts); - opts = xrealloc(opts, optlen + strlen(append) + 2); - sprintf(opts + optlen, " %s", append); + if (append) { + if (opts == NULL) { + opts = xstrdup(append); + } else { + int optlen = strlen(opts); + opts = xrealloc(opts, optlen + strlen(append) + 2); + sprintf(opts + optlen, " %s", append); + } } return opts; } diff --git a/release/src/router/busybox/networking/wget.c b/release/src/router/busybox/networking/wget.c index 8ec4eb0397..a3781f2c54 100644 --- a/release/src/router/busybox/networking/wget.c +++ b/release/src/router/busybox/networking/wget.c @@ -329,8 +329,10 @@ static void parse_url(char *src_url, struct host_info *h) h->path = sp; } + // We used to set h->user to NULL here, but this interferes + // with handling of code 302 ("object was moved") + sp = strrchr(h->host, '@'); - h->user = NULL; if (sp != NULL) { h->user = h->host; *sp = '\0'; @@ -526,6 +528,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv) } #endif + target.user = NULL; parse_url(argv[optind], &target); server.host = target.host; server.port = target.port; @@ -534,6 +537,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv) if (use_proxy) { proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); if (proxy && *proxy) { + server.user = NULL; parse_url(proxy, &server); } else { use_proxy = 0; diff --git a/release/src/router/busybox/util-linux/Config.in b/release/src/router/busybox/util-linux/Config.in index f4b75fd67c..182d1b9a76 100644 --- a/release/src/router/busybox/util-linux/Config.in +++ b/release/src/router/busybox/util-linux/Config.in @@ -329,6 +329,24 @@ 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 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 --git a/release/src/router/busybox/util-linux/Kbuild b/release/src/router/busybox/util-linux/Kbuild index ac071c6207..dde306ba27 100644 --- a/release/src/router/busybox/util-linux/Kbuild +++ b/release/src/router/busybox/util-linux/Kbuild @@ -21,6 +21,8 @@ lib-$(CONFIG_HWCLOCK) += hwclock.o lib-$(CONFIG_IPCRM) += ipcrm.o 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_MINIX) += mkfs_minix.o lib-$(CONFIG_MKFS_VFAT) += mkfs_vfat.o diff --git a/release/src/router/busybox/util-linux/lspci.c b/release/src/router/busybox/util-linux/lspci.c new file mode 100644 index 0000000000..752d4f5cd0 --- /dev/null +++ b/release/src/router/busybox/util-linux/lspci.c @@ -0,0 +1,103 @@ +/* vi: set sw=4 ts=4: */ +/* +* lspci implementation for busybox +* +* Copyright (C) 2009 Malek Degachi +* +* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. +*/ +#include + +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 UNUSED_PARAM, + 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; + + char *uevent_filename = concat_path_file(fileName, "/uevent"); + parser = config_open2(uevent_filename, fopen_for_read); + free(uevent_filename); + + 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 \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"", + pci_slot_name, pci_class, pci_vid, pci_did, + pci_subsys_vid, pci_subsys_did); + } else { + printf("%s Class %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) +{ + getopt32(argv, "m" /*non-compat:*/ "k" /*ignored:*/ "nv"); + + recursive_action("/sys/bus/pci/devices", + ACTION_RECURSE, + fileAction, + NULL, /* dirAction */ + NULL, /* userData */ + 0 /* depth */); + + return EXIT_SUCCESS; +} diff --git a/release/src/router/busybox/util-linux/lsusb.c b/release/src/router/busybox/util-linux/lsusb.c new file mode 100644 index 0000000000..7c5b6b947a --- /dev/null +++ b/release/src/router/busybox/util-linux/lsusb.c @@ -0,0 +1,67 @@ +/* vi: set sw=4 ts=4: */ +/* +* lspci implementation for busybox +* +* Copyright (C) 2009 Malek Degachi +* +* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. +*/ +#include + +static int FAST_FUNC fileAction( + const char *fileName, + struct stat *statbuf UNUSED_PARAM, + void *userData UNUSED_PARAM, + int depth UNUSED_PARAM) +{ + parser_t *parser; + char *tokens[6]; + char *bus = NULL, *device = NULL; + int product_vid = 0, product_did = 0; + + char *uevent_filename = concat_path_file(fileName, "/uevent"); + parser = config_open2(uevent_filename, fopen_for_read); + free(uevent_filename); + + 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) +{ + /* no options, no getopt */ + + recursive_action("/sys/bus/usb/devices", + ACTION_RECURSE, + fileAction, + NULL, /* dirAction */ + NULL, /* userData */ + 0 /* depth */); + + return EXIT_SUCCESS; +} diff --git a/release/src/router/busybox/util-linux/mount.c b/release/src/router/busybox/util-linux/mount.c index 76789cfa8e..49034b5edf 100644 --- a/release/src/router/busybox/util-linux/mount.c +++ b/release/src/router/busybox/util-linux/mount.c @@ -43,6 +43,9 @@ # include #endif +#ifndef MS_UNION +#define MS_UNION (1 << 8) +#endif #ifndef MS_SILENT #define MS_SILENT (1 << 15) #endif @@ -151,6 +154,7 @@ static const int32_t mount_options[] = { /* "loud" */ ~MS_SILENT, // action flags + /* "union" */ MS_UNION, /* "bind" */ MS_BIND, /* "move" */ MS_MOVE, /* "shared" */ MS_SHARED, @@ -205,6 +209,7 @@ static const char mount_option_str[] = "loud\0" // action flags + "union\0" "bind\0" "move\0" "shared\0" diff --git a/release/src/router/busybox/util-linux/volume_id/linux_swap.c b/release/src/router/busybox/util-linux/volume_id/linux_swap.c index c9b62e9bf6..a87de7cac1 100644 --- a/release/src/router/busybox/util-linux/volume_id/linux_swap.c +++ b/release/src/router/busybox/util-linux/volume_id/linux_swap.c @@ -52,7 +52,11 @@ int volume_id_probe_linux_swap(struct volume_id *id /*,uint64_t off*/) goto found; } - if (memcmp(buf, "SWAPSPACE2", 10) == 0) { + if (memcmp(buf, "SWAPSPACE2", 10) == 0 + || memcmp(buf, "S1SUSPEND", 9) == 0 + || memcmp(buf, "S2SUSPEND", 9) == 0 + || memcmp(buf, "ULSUSPEND", 9) == 0 + ) { sw = volume_id_get_buffer(id, off, sizeof(struct swap_header_v1_2)); if (sw == NULL) return -1; -- 2.11.4.GIT