diff options
author | Souf Oued <souf_oued@yahoo.fr> | 2009-12-05 17:56:25 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-05 17:56:25 +0100 |
commit | 982bc7176d04d9d3e2b40c4ddba24eab9f02dc4d (patch) | |
tree | 83eb0a5773b6cfa3fb383165bc7fb188a9acd4ec /util-linux | |
parent | f92874e747dae948fdfacf53537f554ccee7bd54 (diff) | |
download | busybox-w32-982bc7176d04d9d3e2b40c4ddba24eab9f02dc4d.tar.gz busybox-w32-982bc7176d04d9d3e2b40c4ddba24eab9f02dc4d.tar.bz2 busybox-w32-982bc7176d04d9d3e2b40c4ddba24eab9f02dc4d.zip |
lspci: new applet. +573 bytes
Signed-off-by: Souf Oued <souf_oued@yahoo.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/Config.in | 9 | ||||
-rw-r--r-- | util-linux/Kbuild | 1 | ||||
-rw-r--r-- | util-linux/lspci.c | 103 |
3 files changed, 113 insertions, 0 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in index 982714517..94337df8e 100644 --- a/util-linux/Config.in +++ b/util-linux/Config.in | |||
@@ -348,6 +348,15 @@ config LOSETUP | |||
348 | file or block device, and to query the status of a loop device. This | 348 | file or block device, and to query the status of a loop device. This |
349 | version does not currently support enabling data encryption. | 349 | version does not currently support enabling data encryption. |
350 | 350 | ||
351 | config LSPCI | ||
352 | bool "lspci" | ||
353 | default n | ||
354 | help | ||
355 | lspci is a utility for displaying information about PCI buses in the | ||
356 | system and devices connected to them. | ||
357 | |||
358 | This version uses sysfs (/sys/bus/pci/devices) only. | ||
359 | |||
351 | config MDEV | 360 | config MDEV |
352 | bool "mdev" | 361 | bool "mdev" |
353 | default n | 362 | default n |
diff --git a/util-linux/Kbuild b/util-linux/Kbuild index 89886cb60..3004fd0a0 100644 --- a/util-linux/Kbuild +++ b/util-linux/Kbuild | |||
@@ -21,6 +21,7 @@ lib-$(CONFIG_HWCLOCK) += hwclock.o | |||
21 | lib-$(CONFIG_IPCRM) += ipcrm.o | 21 | lib-$(CONFIG_IPCRM) += ipcrm.o |
22 | lib-$(CONFIG_IPCS) += ipcs.o | 22 | lib-$(CONFIG_IPCS) += ipcs.o |
23 | lib-$(CONFIG_LOSETUP) += losetup.o | 23 | lib-$(CONFIG_LOSETUP) += losetup.o |
24 | lib-$(CONFIG_LSPCI) += lspci.o | ||
24 | lib-$(CONFIG_MDEV) += mdev.o | 25 | lib-$(CONFIG_MDEV) += mdev.o |
25 | lib-$(CONFIG_MKFS_EXT2) += mkfs_ext2.o | 26 | lib-$(CONFIG_MKFS_EXT2) += mkfs_ext2.o |
26 | lib-$(CONFIG_MKFS_MINIX) += mkfs_minix.o | 27 | lib-$(CONFIG_MKFS_MINIX) += mkfs_minix.o |
diff --git a/util-linux/lspci.c b/util-linux/lspci.c new file mode 100644 index 000000000..752d4f5cd --- /dev/null +++ b/util-linux/lspci.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * lspci implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net> | ||
6 | * | ||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | ||
8 | */ | ||
9 | #include <libbb.h> | ||
10 | |||
11 | enum { | ||
12 | OPT_m = (1 << 0), | ||
13 | OPT_k = (1 << 1), | ||
14 | }; | ||
15 | |||
16 | /* | ||
17 | * PCI_SLOT_NAME PCI_CLASS: PCI_VID:PCI_DID [PCI_SUBSYS_VID:PCI_SUBSYS_DID] [DRIVER] | ||
18 | */ | ||
19 | static int FAST_FUNC fileAction( | ||
20 | const char *fileName, | ||
21 | struct stat *statbuf UNUSED_PARAM, | ||
22 | void *userData UNUSED_PARAM, | ||
23 | int depth UNUSED_PARAM) | ||
24 | { | ||
25 | parser_t *parser; | ||
26 | char *tokens[3]; | ||
27 | char *pci_slot_name = NULL, *driver = NULL; | ||
28 | int pci_class = 0, pci_vid = 0, pci_did = 0; | ||
29 | int pci_subsys_vid = 0, pci_subsys_did = 0; | ||
30 | |||
31 | char *uevent_filename = concat_path_file(fileName, "/uevent"); | ||
32 | parser = config_open2(uevent_filename, fopen_for_read); | ||
33 | free(uevent_filename); | ||
34 | |||
35 | while (config_read(parser, tokens, 3, 2, "\0:=", PARSE_NORMAL)) { | ||
36 | if (strcmp(tokens[0], "DRIVER") == 0) { | ||
37 | driver = xstrdup(tokens[1]); | ||
38 | continue; | ||
39 | } | ||
40 | |||
41 | if (strcmp(tokens[0], "PCI_CLASS") == 0) { | ||
42 | pci_class = xstrtou(tokens[1], 16)>>8; | ||
43 | continue; | ||
44 | } | ||
45 | |||
46 | if (strcmp(tokens[0], "PCI_ID") == 0) { | ||
47 | pci_vid = xstrtou(tokens[1], 16); | ||
48 | pci_did = xstrtou(tokens[2], 16); | ||
49 | continue; | ||
50 | } | ||
51 | |||
52 | if (strcmp(tokens[0], "PCI_SUBSYS_ID") == 0) { | ||
53 | pci_subsys_vid = xstrtou(tokens[1], 16); | ||
54 | pci_subsys_did = xstrtou(tokens[2], 16); | ||
55 | continue; | ||
56 | } | ||
57 | |||
58 | if (strcmp(tokens[0], "PCI_SLOT_NAME") == 0) { | ||
59 | pci_slot_name = xstrdup(tokens[2]); | ||
60 | continue; | ||
61 | } | ||
62 | } | ||
63 | config_close(parser); | ||
64 | |||
65 | |||
66 | if (option_mask32 & OPT_m) { | ||
67 | printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"", | ||
68 | pci_slot_name, pci_class, pci_vid, pci_did, | ||
69 | pci_subsys_vid, pci_subsys_did); | ||
70 | } else { | ||
71 | printf("%s Class %04x: %04x:%04x", | ||
72 | pci_slot_name, pci_class, pci_vid, pci_did); | ||
73 | } | ||
74 | |||
75 | if ((option_mask32 & OPT_k) && driver) { | ||
76 | if (option_mask32 & OPT_m) { | ||
77 | printf(" \"%s\"", driver); | ||
78 | } else { | ||
79 | printf(" %s", driver); | ||
80 | } | ||
81 | } | ||
82 | bb_putchar('\n'); | ||
83 | |||
84 | free(driver); | ||
85 | free(pci_slot_name); | ||
86 | |||
87 | return TRUE; | ||
88 | } | ||
89 | |||
90 | int lspci_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
91 | int lspci_main(int argc UNUSED_PARAM, char **argv) | ||
92 | { | ||
93 | getopt32(argv, "m" /*non-compat:*/ "k" /*ignored:*/ "nv"); | ||
94 | |||
95 | recursive_action("/sys/bus/pci/devices", | ||
96 | ACTION_RECURSE, | ||
97 | fileAction, | ||
98 | NULL, /* dirAction */ | ||
99 | NULL, /* userData */ | ||
100 | 0 /* depth */); | ||
101 | |||
102 | return EXIT_SUCCESS; | ||
103 | } | ||