diff options
author | mananth <mananth> | 2004-02-12 06:44:31 +0000 |
---|---|---|
committer | mananth <mananth> | 2004-02-12 06:44:31 +0000 |
commit | 89b3488f92c6bdcc65a44aeec834af9edfcae689 (patch) | |
tree | 88441500558b23e4947bf19ddbb4704b31cbb90e | |
parent | 0daeac52d9c351453c7964695ed3fcb9f34406bd (diff) | |
download | sysfsutils-89b3488f92c6bdcc65a44aeec834af9edfcae689.tar.gz |
Removed lsbus; added Nitin's name to AUTHORS, updated systool
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | cmd/Makefile.am | 3 | ||||
-rw-r--r-- | cmd/Makefile.in | 21 | ||||
-rw-r--r-- | cmd/lsbus.c | 460 | ||||
-rw-r--r-- | cmd/systool.c | 248 | ||||
-rw-r--r-- | docs/libsysfs.txt | 30 | ||||
-rw-r--r-- | include/libsysfs.h | 2 | ||||
-rw-r--r-- | lib/sysfs_device.c | 4 | ||||
-rw-r--r-- | lsbus.1 | 58 | ||||
-rw-r--r-- | systool.1 | 29 |
14 files changed, 234 insertions, 633 deletions
@@ -1,2 +1,3 @@ Ananth Mavinakayanahalli <ananth@in.ibm.com> Daniel Stekloff <dsteklof@us.ibm.com> +Nitin Vashisth <nitin@in.ibm.com> @@ -1,4 +1,10 @@ +02/12/2004 - Ananth Mavinakayanahalli <ananth@in.ibm.com> + * Added Nitin Vashisth to AUTHORS + * Removed lsbus and its manpage + * Updated systool for better display + * Updated manpage for systool + 02/10/2004 - Ananth Mavinakayanahalli <ananth@in.ibm.com> * Updated docs/libsysfs.txt diff --git a/Makefile.am b/Makefile.am index 1407a56..7689330 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -man_MANS = lsbus.1 systool.1 +man_MANS = systool.1 EXTRA_DIST = docs include $(man_MANS) CREDITS lib/LGPL cmd/GPL test/GPL SUBDIRS = lib cmd test include_HEADERS = include/libsysfs.h include/dlist.h diff --git a/Makefile.in b/Makefile.in index 989e379..4ce169a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -83,7 +83,7 @@ VERSION = @VERSION@ am__include = @am__include@ am__quote = @am__quote@ install_sh = @install_sh@ -man_MANS = lsbus.1 systool.1 +man_MANS = systool.1 EXTRA_DIST = docs include $(man_MANS) CREDITS lib/LGPL cmd/GPL test/GPL SUBDIRS = lib cmd test include_HEADERS = include/libsysfs.h include/dlist.h @@ -23,7 +23,6 @@ and their attributes. This package currently includes: - libsysfs: a library for accessing system devices. -- lsbus: a small application to query system bus information. - systool: an application to view system device information by bus, class, and topology. - A number of example usage routines in the "test" directory. diff --git a/cmd/Makefile.am b/cmd/Makefile.am index 816b510..4ecf20a 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -1,6 +1,5 @@ -bin_PROGRAMS = systool lsbus +bin_PROGRAMS = systool systool_SOURCES = systool.c names.c names.h -lsbus_SOURCES = lsbus.c names.c names.h INCLUDES = -I../include LDADD = ../lib/libsysfs.la CFLAGS = -Wall -Wshadow -W -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls diff --git a/cmd/Makefile.in b/cmd/Makefile.in index c998b4f..25ea859 100644 --- a/cmd/Makefile.in +++ b/cmd/Makefile.in @@ -83,9 +83,8 @@ VERSION = @VERSION@ am__include = @am__include@ am__quote = @am__quote@ install_sh = @install_sh@ -bin_PROGRAMS = systool lsbus +bin_PROGRAMS = systool systool_SOURCES = systool.c names.c names.h -lsbus_SOURCES = lsbus.c names.c names.h INCLUDES = -I../include LDADD = ../lib/libsysfs.la CFLAGS = -Wall -Wshadow -W -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls @@ -93,14 +92,9 @@ subdir = cmd mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = -bin_PROGRAMS = systool$(EXEEXT) lsbus$(EXEEXT) +bin_PROGRAMS = systool$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) -am_lsbus_OBJECTS = lsbus.$(OBJEXT) names.$(OBJEXT) -lsbus_OBJECTS = $(am_lsbus_OBJECTS) -lsbus_LDADD = $(LDADD) -lsbus_DEPENDENCIES = ../lib/libsysfs.la -lsbus_LDFLAGS = am_systool_OBJECTS = systool.$(OBJEXT) names.$(OBJEXT) systool_OBJECTS = $(am_systool_OBJECTS) systool_LDADD = $(LDADD) @@ -114,8 +108,7 @@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles -@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/lsbus.Po ./$(DEPDIR)/names.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/systool.Po +@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/names.Po ./$(DEPDIR)/systool.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ @@ -123,9 +116,9 @@ LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ CCLD = $(CC) LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ -DIST_SOURCES = $(lsbus_SOURCES) $(systool_SOURCES) +DIST_SOURCES = $(systool_SOURCES) DIST_COMMON = Makefile.am Makefile.in -SOURCES = $(lsbus_SOURCES) $(systool_SOURCES) +SOURCES = $(systool_SOURCES) all: all-am @@ -165,9 +158,6 @@ clean-binPROGRAMS: echo " rm -f $$p $$f"; \ rm -f $$p $$f ; \ done -lsbus$(EXEEXT): $(lsbus_OBJECTS) $(lsbus_DEPENDENCIES) - @rm -f lsbus$(EXEEXT) - $(LINK) $(lsbus_LDFLAGS) $(lsbus_OBJECTS) $(lsbus_LDADD) $(LIBS) systool$(EXEEXT): $(systool_OBJECTS) $(systool_DEPENDENCIES) @rm -f systool$(EXEEXT) $(LINK) $(systool_LDFLAGS) $(systool_OBJECTS) $(systool_LDADD) $(LIBS) @@ -178,7 +168,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsbus.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/names.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/systool.Po@am__quote@ diff --git a/cmd/lsbus.c b/cmd/lsbus.c deleted file mode 100644 index 75d484c..0000000 --- a/cmd/lsbus.c +++ /dev/null @@ -1,460 +0,0 @@ -/* - * lsbus.c - * - * Utility to list bus devices - * - * Copyright (C) IBM Corp. 2003 - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <mntent.h> -#include <dirent.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <ctype.h> - -#include "libsysfs.h" -#include "names.h" - -/* Command Options */ -static int show_options = 0; /* bitmask of show options */ -static unsigned char *attr_to_show = NULL; /* print value for this attribute*/ -static unsigned char *bus_device = NULL; /* print only this bus device */ -struct pci_access *pacc = NULL; -unsigned char *bus_to_print = NULL; - -#define SHOW_ATTRIBUTES 0x01 /* show attributes command option */ -#define SHOW_ATTRIBUTE_VALUE 0x02 /* show an attribute value option */ -#define SHOW_DEVICES 0x04 /* show only devices option */ -#define SHOW_DRIVERS 0x08 /* show only drivers option */ -#define SHOW_ALL_ATTRIB_VALUES 0x10 /* show all attributes with values */ - -#define SHOW_ALL 0xff - -static unsigned char cmd_options[] = "aA:dDhv"; - -/* - * binary_files - defines existing sysfs binary files that should be printed - * in hex. - */ -static unsigned char *binary_files[] = { - "config", - "data" -}; - -static int binfiles = 2; - -static unsigned int get_pciconfig_word(int offset, unsigned char *buf) -{ - unsigned short val = (unsigned char)buf[offset] | - ((unsigned char)buf[offset+1] << 8); - return val; -} - -/** - * usage: prints utility usage. - */ -static void usage(void) -{ - fprintf(stdout, "Usage: lsbus [<options> bus [device]]\n"); - fprintf(stdout, "\t-a\t\t\tShow attributes\n"); - fprintf(stdout, "\t-d\t\t\tShow only devices\n"); - fprintf(stdout, "\t-h\t\t\tShow usage\n"); - fprintf(stdout, "\t-v\t\t\tShow all attributes with values\n"); - fprintf(stdout, "\t-A <attribute_name>\tShow attribute value\n"); - fprintf(stdout, "\t-D\t\t\tShow only drivers\n"); -} - -/** - * remove_end_newline: removes newline on the end of an attribute value - * @value: string to remove newline from - */ -static void remove_end_newline(unsigned char *value) -{ - unsigned char *p = value + (strlen(value) - 1); - - if (p != NULL && *p == '\n') - *p = '\0'; -} - -/** - * isbinaryvalue: checks to see if attribute is binary or not. - * @attr: attribute to check. - * returns 1 if binary or 0 if not. - */ -static int isbinaryvalue(struct sysfs_attribute *attr) -{ - int i; - - if (attr == NULL || attr->value == NULL) - return 0; - - for (i = 0; i < binfiles; i++) - if ((strcmp(attr->name, binary_files[i])) == 0) - return 1; - - return 0; -} - -/** - * print_attribute_value: prints out single attribute value. - * @attr: attricute to print. - */ -static void print_attribute_value(struct sysfs_attribute *attr) -{ - if (attr == NULL) - return; - - if (attr->method & SYSFS_METHOD_SHOW) { - if (isbinaryvalue(attr) != 0) { - int i; - fprintf(stdout, "\t: "); - for (i = 0; i < attr->len; i++) { - if (!(i %16)) { - fprintf(stdout, "\n\t\t\t"); - } else if (!(i %8)) - fprintf(stdout, " "); - fprintf(stdout, "%02x ", - (unsigned char)attr->value[i]); - } - fprintf(stdout, "\n"); - } else if (attr->value != NULL && strlen(attr->value) > 0) { - remove_end_newline(attr->value); - fprintf(stdout, "\t: %s\n", attr->value); - } else - fprintf(stdout, "\n"); - } else { - fprintf(stdout, "\t: store method only\n"); - } -} - -/** - * print_attribute: prints out a single attribute - * @attr: attribute to print. - */ -static void print_attribute(struct sysfs_attribute *attr) -{ - if (attr == NULL) - return; - - if (show_options & SHOW_ALL_ATTRIB_VALUES) { - fprintf(stdout, "\t\t%s", attr->name); - print_attribute_value(attr); - - } else if ((show_options & SHOW_ATTRIBUTES) || ((show_options - & SHOW_ATTRIBUTE_VALUE) && (strcmp(attr->name, attr_to_show) - == 0))) { - fprintf (stdout, "\t\t%s", attr->name); - if (show_options & SHOW_ATTRIBUTE_VALUE && attr->value != NULL - && (strcmp(attr->name, attr_to_show)) == 0) { - print_attribute_value(attr); - } else { - fprintf(stdout, "\n"); - } - } -} - -/** - * print_device_attributes: prints out device attributes. - * @sdir: print this device's attributes/files. - */ -static void print_device_attributes(struct dlist *attributes) -{ - struct sysfs_attribute *cur = NULL;; - - fprintf (stdout, "\tAttributes:\n"); - dlist_for_each_data(attributes, cur, - struct sysfs_attribute) { - print_attribute(cur); - } -} - -/** - * print_device: prints out device information. - * @device: device to print. - */ -static void print_device(struct sysfs_device *device) -{ - struct dlist *attributes = NULL; - unsigned int vendor_id, device_id; - unsigned char buf[128], path[SYSFS_PATH_MAX], value[256]; - - if (device != NULL) { - if (!(strcmp(bus_to_print, "pci"))) { - fprintf(stdout, " %s: ", device->bus_id); - memset(path, 0, SYSFS_PATH_MAX); - memset(value, 0, SYSFS_PATH_MAX); - strcpy(path, device->path); - strcat(path, "/config"); - if ((sysfs_read_attribute_value(path, - value, 256)) == 0) { - vendor_id = get_pciconfig_word - (PCI_VENDOR_ID, value); - device_id = get_pciconfig_word - (PCI_DEVICE_ID, value); - fprintf(stdout, "%s\n", - pci_lookup_name(pacc, buf, 128, - PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, - vendor_id, device_id, 0, 0)); - } else - fprintf(stdout, "\n"); - } else - fprintf(stdout, " %s:\n", device->bus_id); - - if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE | - SHOW_ALL_ATTRIB_VALUES)) { - attributes = sysfs_get_device_attributes(device); - if (attributes != NULL) - print_device_attributes(attributes); - } - if (isalnum(device->driver_name[0])) - fprintf (stdout, "\tDriver: %s\n\n", - device->driver_name); - } -} - -/** - * print_driver_attributes: prints out driver attributes . - * @driver: print this driver's attributes. - */ -static void print_driver_attributes(struct sysfs_driver *driver) -{ - struct dlist *attributes = NULL; - - if (driver != NULL) { - attributes = sysfs_get_driver_attributes(driver); - if (attributes != NULL) { - struct sysfs_attribute *cur = NULL; - - fprintf (stdout, "\t%s Attributes:\n", driver->name); - dlist_for_each_data(attributes, cur, - struct sysfs_attribute) { - print_attribute(cur); - } - } - } -} - -/** - * print_driver: prints out driver information. - * @driver: driver to print. - */ -static void print_driver(struct sysfs_driver *driver) -{ - struct dlist *devlist = NULL; - - if (driver != NULL) { - fprintf (stdout, " %s\n", driver->name); - devlist = sysfs_get_driver_devices(driver); - if (devlist != NULL) { - struct sysfs_device *dev = NULL; - fprintf(stdout, "\tDevices:\n"); - dlist_for_each_data(devlist, dev, - struct sysfs_device) - fprintf(stdout, "\t\t%s\n", dev->bus_id); - } - if(show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE - | SHOW_ALL_ATTRIB_VALUES)) - print_driver_attributes(driver); - } -} - -/** - * print_default_bus: prints out everything on a bus. - * @busname: bus to print. - * returns 0 with success or 1 with error. - */ -static int print_sysfs_bus(unsigned char *busname) -{ - struct sysfs_bus *bus = NULL; - struct sysfs_device *curdev = NULL; - struct sysfs_driver *curdrv = NULL; - struct dlist *devlist = NULL; - struct dlist *drvlist = NULL; - - if (busname == NULL) { - errno = EINVAL; - return 1; - } - bus = sysfs_open_bus(busname); - if (bus == NULL) { - fprintf(stderr, "Error opening bus %s\n", busname); - return 1; - } - - fprintf(stdout, "Bus: %s\n", busname); - if (show_options & SHOW_DEVICES) { - devlist = sysfs_get_bus_devices(bus); - if (devlist != NULL) { - if (bus_device == NULL) - fprintf(stdout, "Devices:\n"); - dlist_for_each_data(devlist, curdev, - struct sysfs_device) { - if (bus_device == NULL || (strcmp(bus_device, - curdev->bus_id) == 0)) - print_device(curdev); - } - } - } - if (show_options & SHOW_DRIVERS) { - drvlist = sysfs_get_bus_drivers(bus); - if (drvlist != NULL) { - fprintf(stdout, "Drivers:\n"); - dlist_for_each_data(drvlist, curdrv, - struct sysfs_driver) { - print_driver(curdrv); - } - } - } - sysfs_close_bus(bus); - return 0; -} - -/** - * print_sysfs_buses: prints out supported buses. - * @buses: list of supported system buses. - * returns 0 with success or 1 with error. - */ -static int print_sysfs_buses(void) -{ - unsigned char subsys[SYSFS_NAME_LEN]; - struct dlist *list = NULL; - unsigned char *cur = NULL; - int ret = 0; - - strcat(subsys, "/"); - strcpy(subsys, SYSFS_BUS_NAME); - list = sysfs_open_subsystem_list(subsys); - if (list != NULL) { - fprintf(stdout, "Supported sysfs buses:\n"); - dlist_for_each_data(list, cur, char) - fprintf(stdout, "\t%s\n", cur); - } - sysfs_close_list(list); - - return ret; -} - -/* MAIN */ -int main(int argc, char *argv[]) -{ - //unsigned char *bus_to_print = NULL; - int retval = 0; - int opt; - - /*pci ids*/ - unsigned char *pci_id_file = "/usr/local/share/pci.ids"; - - while((opt = getopt(argc, argv, cmd_options)) != EOF) { - switch(opt) { - case 'a': - show_options |= SHOW_ATTRIBUTES; - break; - case 'A': - if ((strlen(optarg) + 1) > SYSFS_NAME_LEN) { - fprintf(stderr, - "Attribute name %s is too long\n", - optarg); - exit(1); - } - attr_to_show = optarg; - show_options |= SHOW_ATTRIBUTE_VALUE; - break; - case 'd': - show_options |= SHOW_DEVICES; - break; - case 'D': - show_options |= SHOW_DRIVERS; - break; - case 'h': - usage(); - exit(0); - break; - case 'v': - show_options |= SHOW_ALL_ATTRIB_VALUES; - break; - default: - usage(); - exit(1); - } - } - argc -= optind; - argv += optind; - - switch(argc) { - case 0: - break; - case 1: - /* get bus to view */ - if ((strlen(*argv)+1) < SYSFS_NAME_LEN) - bus_to_print = *argv; - else - fprintf(stderr, - "Invalid argument: busname too long\n"); - break; - case 2: - /* get bus and device to view */ - if ((strlen(argv[0])) < SYSFS_NAME_LEN && (strlen(argv[1])) - < SYSFS_NAME_LEN) { - bus_to_print = argv[0]; - bus_device = argv[1]; - show_options |= SHOW_DEVICES; - } else { - fprintf(stderr, - "Invalid argument: bus or device name too long\n"); - exit(1); - } - break; - default: - usage(); - exit(1); - } - - if (bus_to_print == NULL && (show_options & (SHOW_ATTRIBUTES - | SHOW_ATTRIBUTE_VALUE | SHOW_DEVICES | SHOW_DRIVERS - | SHOW_ALL_ATTRIB_VALUES))) { - fprintf(stderr, "Please specify a bus\n"); - usage(); - exit(1); - } - /* default is to print devices */ - if (!(show_options & (SHOW_DEVICES | SHOW_DRIVERS))) - show_options |= SHOW_DEVICES; - - if (bus_to_print != NULL) { - if ((!(strcmp(bus_to_print, "pci"))) && - (show_options & SHOW_DEVICES)) { - pacc = (struct pci_access *)calloc(1, sizeof(struct pci_access)); - pacc->pci_id_file_name = pci_id_file; - pacc->numeric_ids = 0; - } - retval = print_sysfs_bus(bus_to_print); - } else - retval = print_sysfs_buses(); - - if (bus_to_print != NULL) { - if ((!(strcmp(bus_to_print, "pci"))) && - (show_options & SHOW_DEVICES)) { - pci_free_name_list(pacc); - free (pacc); - } - } - exit(retval); -} diff --git a/cmd/systool.c b/cmd/systool.c index 6ecfb15..04a4e9d 100644 --- a/cmd/systool.c +++ b/cmd/systool.c @@ -40,15 +40,21 @@ static unsigned char *device_to_show = NULL; /* show only this bus device */ struct pci_access *pacc = NULL; unsigned char *show_bus = NULL; +static void show_device(struct sysfs_device *device, int level); +static void show_class_device(struct sysfs_class_device *dev, int level); + #define SHOW_ATTRIBUTES 0x01 /* show attributes command option */ #define SHOW_ATTRIBUTE_VALUE 0x02 /* show an attribute value option */ #define SHOW_DEVICES 0x04 /* show only devices option */ #define SHOW_DRIVERS 0x08 /* show only drivers option */ #define SHOW_ALL_ATTRIB_VALUES 0x10 /* show all attributes with values */ +#define SHOW_CHILDREN 0x20 /* show device children */ +#define SHOW_PARENT 0x40 /* show device parent */ +#define SHOW_PATH 0x80 /* show device/driver path */ #define SHOW_ALL 0xff -static unsigned char cmd_options[] = "aA:b:c:dDhr:v"; +static unsigned char cmd_options[] = "aA:b:c:CdDhpPr:v"; /* * binary_files - defines existing sysfs binary files. These files will be @@ -79,11 +85,14 @@ static void usage(void) fprintf(stdout, "\t-c <class_name>\t\tShow a specific class\n"); fprintf(stdout, "\t-d\t\t\tShow only devices\n"); fprintf(stdout, "\t-h\t\t\tShow usage\n"); + fprintf(stdout, "\t-p\t\t\tShow path to device/driver\n"); fprintf(stdout, "\t-r <root_device>\tShow a specific root device tree\n"); fprintf(stdout, "\t-v\t\t\tShow all attributes with values\n"); fprintf(stdout, "\t-A <attribute_name>\tShow attribute value\n"); + fprintf(stdout, "\t-C\t\t\tShow device's children\n"); fprintf(stdout, "\t-D\t\t\tShow only drivers\n"); + fprintf(stdout, "\t-P\t\t\tShow device's parent\n"); } /** @@ -95,7 +104,7 @@ static void indent(int level) { int i; - for (i = 0; i <= level; i++) + for (i = 0; i < level; i++) fprintf(stdout, " "); } @@ -115,18 +124,29 @@ static void remove_end_newline(unsigned char *value) * show_device_children: prints out device subdirs. * @children: dlist of child devices. */ -static void show_device_children(struct dlist *children, int level) +static void show_device_children(struct sysfs_device *device, int level) { - struct sysfs_device *child = NULL; + struct sysfs_device *temp_device = NULL, *child = NULL; + unsigned int flag = 1; - if (children != NULL) { - indent(level); - fprintf(stdout, "Children:\n"); - dlist_for_each_data(children, child, - struct sysfs_device) { - indent(level+4); - fprintf(stdout, "%s\n", child->bus_id); + temp_device = sysfs_open_device_tree(device->path); + if (temp_device) { + if (temp_device->children) { + fprintf(stdout, "\n"); + dlist_for_each_data(temp_device->children, child, + struct sysfs_device) { + if (strncmp(child->name, "power", 5) == 0) + continue; + if (flag) { + flag--; + indent(level); + fprintf(stdout, "Device \"%s\"'s children\n", + temp_device->name); + } + show_device(child, (level+2)); + } } + sysfs_close_device_tree(temp_device); } } @@ -161,25 +181,24 @@ static void show_attribute_value(struct sysfs_attribute *attr, int level) if (attr->method & SYSFS_METHOD_SHOW) { if (isbinaryvalue(attr) != 0) { int i; - fprintf(stdout, "\t: "); for (i = 0; i < attr->len; i++) { - if (!(i %16)) { + if (!(i % 16) && (i != 0)) { fprintf(stdout, "\n"); - indent(level+8); - } else if (!(i %8)) + indent(level+22); + } else if (!(i % 8) && (i != 0)) fprintf(stdout, " "); - fprintf(stdout, "%02x ", + fprintf(stdout, " %02x", (unsigned char)attr->value[i]); } fprintf(stdout, "\n"); } else if (attr->value != NULL && strlen(attr->value) > 0) { remove_end_newline(attr->value); - fprintf(stdout, "\t: %s\n", attr->value); + fprintf(stdout, "\"%s\"\n", attr->value); } else fprintf(stdout, "\n"); } else { - fprintf(stdout, "\t: store method only\n"); + fprintf(stdout, "<store method only>\n"); } } @@ -194,14 +213,13 @@ static void show_attribute(struct sysfs_attribute *attr, int level) if (show_options & SHOW_ALL_ATTRIB_VALUES) { indent(level); - fprintf(stdout, "%s", attr->name); + fprintf(stdout, "%-20s= ", attr->name); show_attribute_value(attr, level); - } else if ((show_options & SHOW_ATTRIBUTES) || ((show_options & SHOW_ATTRIBUTE_VALUE) && (strcmp(attr->name, attribute_to_show) == 0))) { indent(level); - fprintf (stdout, "%s", attr->name); + fprintf (stdout, "%-20s=", attr->name); if (show_options & SHOW_ATTRIBUTE_VALUE && attr->value != NULL && (strcmp(attr->name, attribute_to_show)) == 0) show_attribute_value(attr, level); @@ -220,16 +238,31 @@ static void show_attributes(struct dlist *attributes, int level) if (attributes != NULL) { struct sysfs_attribute *cur = NULL; - indent(level); - fprintf (stdout, "Attributes:\n"); dlist_for_each_data(attributes, cur, struct sysfs_attribute) { - show_attribute(cur, (level+4)); + show_attribute(cur, (level)); } } } /** + * show_device_parent: prints device's parent (if present) + * @device: sysfs_device whose parent information is needed + */ +static void show_device_parent(struct sysfs_device *device, int level) +{ + struct sysfs_device *parent = NULL; + + parent = sysfs_get_device_parent(device); + if (parent) { + fprintf(stdout, "\n"); + indent(level); + fprintf(stdout, "Device \"%s\"'s parent\n", device->name); + show_device(parent, (level+2)); + } +} + +/** * show_device: prints out device information. * @device: device to print. */ @@ -242,7 +275,7 @@ static void show_device(struct sysfs_device *device, int level) if (device != NULL) { indent(level); if (show_bus != NULL && (!(strcmp(show_bus, "pci")))) { - fprintf(stdout, "%s: ", device->bus_id); + fprintf(stdout, "%s ", device->bus_id); memset(path, 0, SYSFS_PATH_MAX); memset(value, 0, SYSFS_PATH_MAX); strcpy(path, device->path); @@ -260,40 +293,32 @@ static void show_device(struct sysfs_device *device, int level) } else fprintf(stdout, "\n"); } else - fprintf(stdout, "%s\n", device->bus_id); + fprintf(stdout, "Device = \"%s\"\n", device->bus_id); + + if (show_options & (SHOW_PATH | SHOW_ALL_ATTRIB_VALUES)) { + indent(level); + fprintf(stdout, "Device path = \"%s\"\n", + device->path); + } if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE | SHOW_ALL_ATTRIB_VALUES)) { attributes = sysfs_get_device_attributes(device); if (attributes != NULL) - show_attributes(attributes, (level+4)); + show_attributes(attributes, (level+2)); } - if (device->children != NULL) - show_device_children(device->children, (level+4)); - if (isalnum(device->driver_name[0])) { - indent(level+6); - fprintf (stdout, "Driver: %s\n", - device->driver_name); - } - } -} - -/** - * show_root_device: prints out sys/devices device information. - * @device: device to print. - */ -static void show_root_device(struct sysfs_device *device, int level) -{ - if (device != NULL) { - indent(level); - fprintf (stdout, "%s\n", device->bus_id); - if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE - | SHOW_ALL_ATTRIB_VALUES)) { - struct dlist *attributes = NULL; - attributes = sysfs_get_device_attributes(device); - if (attributes != NULL) - show_attributes(attributes, (level+4)); + if ((device_to_show != NULL) && + (show_options & SHOW_CHILDREN)) { + show_options &= ~SHOW_CHILDREN; + show_device_children(device, (level+2)); + } + if ((device_to_show != NULL) && (show_options & SHOW_PARENT)) { + show_options &= ~SHOW_PARENT; + show_device_parent(device, (level+2)); } + if (show_options ^ SHOW_DEVICES) + if (!(show_options & SHOW_DRIVERS)) + fprintf(stdout, "\n"); } } @@ -310,12 +335,11 @@ static void show_driver_attributes(struct sysfs_driver *driver, int level) if (attributes != NULL) { struct sysfs_attribute *cur = NULL; - indent(level); - fprintf (stdout, "%s Attributes:\n", driver->name); dlist_for_each_data(attributes, cur, struct sysfs_attribute) { - show_attribute(cur, (level+4)); + show_attribute(cur, (level)); } + fprintf(stdout, "\n"); } } } @@ -330,22 +354,34 @@ static void show_driver(struct sysfs_driver *driver, int level) if (driver != NULL) { indent(level); - fprintf (stdout, "%s\n", driver->name); + fprintf (stdout, "Driver = \"%s\"\n", driver->name); + if (show_options & (SHOW_PATH | SHOW_ALL_ATTRIB_VALUES)) { + indent(level); + fprintf(stdout, "Driver path = \"%s\"\n", + driver->path); + } + if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE + | SHOW_ALL_ATTRIB_VALUES)) + show_driver_attributes(driver, (level+2)); devlist = sysfs_get_driver_devices(driver); if (devlist != NULL) { struct sysfs_device *cur = NULL; - indent(level+4); - fprintf(stdout, "Devices:\n"); + indent(level+2); + fprintf(stdout, "Devices using \"%s\" are:\n", + driver->name); dlist_for_each_data(devlist, cur, struct sysfs_device) { - indent(level+8); - fprintf(stdout, "%s\n", cur->bus_id); + if (show_options & SHOW_DRIVERS) { + show_device(cur, (level+4)); + fprintf(stdout, "\n"); + } else { + indent(level+4); + fprintf(stdout, "\"%s\"\n", cur->name); + } } - } - if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE - | SHOW_ALL_ATTRIB_VALUES)) - show_driver_attributes(driver, (level+4)); + } + fprintf(stdout, "\n"); } } @@ -360,14 +396,14 @@ static void show_device_tree(struct sysfs_device *root, int level) if (device_to_show == NULL || (strcmp(device_to_show, root->bus_id) == 0)) { - show_root_device(root, level); + show_device(root, level); } if (root->children != NULL) { dlist_for_each_data(root->children, cur, struct sysfs_device) { if (strncmp(cur->name, "power", 5) == 0) continue; - show_device_tree(cur, (level+6)); + show_device_tree(cur, (level+2)); } } } @@ -396,12 +432,12 @@ static int show_sysfs_bus(unsigned char *busname) return 1; } - fprintf(stdout, "Bus: %s\n", busname); + fprintf(stdout, "Bus = \"%s\"\n", busname); + if (show_options ^ (SHOW_DEVICES | SHOW_DRIVERS)) + fprintf(stdout, "\n"); if (show_options & SHOW_DEVICES) { devlist = sysfs_get_bus_devices(bus); if (devlist != NULL) { - if (device_to_show == NULL) - fprintf(stdout, "Devices:\n"); dlist_for_each_data(devlist, curdev, struct sysfs_device) { if (device_to_show == NULL || @@ -414,7 +450,6 @@ static int show_sysfs_bus(unsigned char *busname) if (show_options & SHOW_DRIVERS) { drvlist = sysfs_get_bus_drivers(bus); if (drvlist != NULL) { - fprintf(stdout, "Drivers:\n"); dlist_for_each_data(drvlist, curdrv, struct sysfs_driver) { show_driver(curdrv, 2); @@ -426,6 +461,24 @@ static int show_sysfs_bus(unsigned char *busname) } /** + * show_classdev_parent: prints the class device's parent if present + * @dev: class device whose parent is needed + */ +static void show_classdev_parent(struct sysfs_class_device *dev, int level) +{ + struct sysfs_class_device *parent = NULL; + + parent = sysfs_get_classdev_parent(dev); + if (parent) { + fprintf(stdout, "\n"); + indent(level); + fprintf(stdout, "Class device \"%s\"'s parent is\n", + dev->name); + show_class_device(parent, level+2); + } +} + +/** * show_class_device: prints out class device. * @dev: class device to print. */ @@ -437,23 +490,38 @@ static void show_class_device(struct sysfs_class_device *dev, int level) if (dev != NULL) { indent(level); - fprintf(stdout, "%s\n", dev->name); + fprintf(stdout, "Class Device = \"%s\"\n", dev->name); + if (show_options & (SHOW_PATH | SHOW_ALL_ATTRIB_VALUES)) { + indent(level); + fprintf(stdout, "Class Device path = \"%s\"\n", + dev->path); + } if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE | SHOW_ALL_ATTRIB_VALUES)) { attributes = sysfs_get_classdev_attributes(dev); if (attributes != NULL) - show_attributes(attributes, (level+4)); + show_attributes(attributes, (level+2)); + fprintf(stdout, "\n"); } if (show_options & (SHOW_DEVICES | SHOW_ALL_ATTRIB_VALUES)) { device = sysfs_get_classdev_device(dev); - if (device != NULL) - show_device(device, (level+4)); + if (device != NULL) { + show_device(device, (level+2)); + } } if (show_options & (SHOW_DRIVERS | SHOW_ALL_ATTRIB_VALUES)) { driver = sysfs_get_classdev_driver(dev); - if (driver != NULL) - show_driver(driver, (level+4)); + if (driver != NULL) { + show_driver(driver, (level+2)); + } } + if ((device_to_show != NULL) && (show_options & SHOW_PARENT)) { + show_options &= ~SHOW_PARENT; + show_classdev_parent(dev, level+2); + } + if (show_options & ~(SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE + | SHOW_ALL_ATTRIB_VALUES)) + fprintf(stdout, "\n"); } } @@ -477,11 +545,9 @@ static int show_sysfs_class(unsigned char *classname) fprintf(stderr, "Error opening class %s\n", classname); return 1; } - fprintf(stdout, "Class: %s\n", classname); + fprintf(stdout, "Class = \"%s\"\n\n", classname); clsdevlist = sysfs_get_class_devices(cls); if (clsdevlist != NULL) { - if (device_to_show == NULL) - fprintf(stdout, "Class Devices:\n"); dlist_for_each_data(clsdevlist, cur, struct sysfs_class_device) { if (device_to_show == NULL || (strcmp(device_to_show, @@ -517,7 +583,7 @@ static int show_sysfs_root(unsigned char *rootname) devlist = sysfs_get_root_devices(root); if (devlist != NULL) { - fprintf(stdout, "Root Device Tree: %s\n", rootname); + fprintf(stdout, "Root Device = \"%s\"\n\n", rootname); if (devlist != NULL) { dlist_for_each_data(devlist, device, @@ -606,6 +672,9 @@ int main(int argc, char *argv[]) case 'c': show_class = optarg; break; + case 'C': + show_options |= SHOW_CHILDREN; + break; case 'd': show_options |= SHOW_DEVICES; break; @@ -616,6 +685,12 @@ int main(int argc, char *argv[]) usage(); exit(0); break; + case 'p': + show_options |= SHOW_PATH; + break; + case 'P': + show_options |= SHOW_PARENT; + break; case 'r': show_root = optarg; break; @@ -663,8 +738,9 @@ int main(int argc, char *argv[]) show_options |= SHOW_DEVICES; if (show_bus != NULL) { - if ((!(strcmp(show_bus, "pci"))) && - (show_options & SHOW_DEVICES)) { + /* if ((!(strcmp(show_bus, "pci"))) && + (show_options & SHOW_DEVICES)) { */ + if ((!(strcmp(show_bus, "pci")))) { pacc = (struct pci_access *) calloc(1, sizeof(struct pci_access)); pacc->pci_id_file_name = pci_id_file; @@ -681,12 +757,16 @@ int main(int argc, char *argv[]) retval = show_default_info(); if (show_bus != NULL) { - if ((!(strcmp(show_bus, "pci"))) && - (show_options & SHOW_DEVICES)) { + /*if ((!(strcmp(show_bus, "pci"))) && + (show_options & SHOW_DEVICES)) { */ + if ((!(strcmp(show_bus, "pci")))) { pci_free_name_list(pacc); free (pacc); pacc = NULL; } } + if (!(show_options ^ SHOW_DEVICES)) + fprintf(stdout, "\n"); + exit(retval); } diff --git a/docs/libsysfs.txt b/docs/libsysfs.txt index 5dce0cb..5929a25 100644 --- a/docs/libsysfs.txt +++ b/docs/libsysfs.txt @@ -1438,7 +1438,7 @@ Returns: struct sysfs_root_device * with success - EINVAL for invalid arguments Prototype: struct sysfs_device *sysfs_open_root_device - (const unsigned char *name) + (const unsigned char *name) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- @@ -1453,6 +1453,34 @@ Prototype: void sysfs_close_root_device(struct sysfs_root_device *root) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_open_device_tree + +Description: Function opens up the device tree at the specified path. + +Arguments: const unsigned char *path Path at which to open the + device tree + +Returns: struct sysfs_device * with success + NULL with error, Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct sysfs_device *sysfs_open_device_tree + (const unsigned char *path) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_close_device_tree + +Description: Function closes the device tree originating at the given + sysfs_device. + +Arguments: struct sysfs_device *devroot Device from which the device + tree has to be closed + +Prototype: void sysfs_close_device_tree(struct sysfs_device *devroot) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_get_device_parent Description: Function returns the sysfs_device reference for the parent diff --git a/include/libsysfs.h b/include/libsysfs.h index abef288..3e9514c 100644 --- a/include/libsysfs.h +++ b/include/libsysfs.h @@ -216,6 +216,8 @@ extern void sysfs_close_root_device(struct sysfs_root_device *root); extern struct sysfs_root_device *sysfs_open_root_device (const unsigned char *name); extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root); +extern void sysfs_close_device_tree(struct sysfs_device *device); +extern struct sysfs_device *sysfs_open_device_tree(const unsigned char *path); extern void sysfs_close_device(struct sysfs_device *dev); extern struct sysfs_device *sysfs_open_device (const unsigned char *bus, const unsigned char *bus_id); diff --git a/lib/sysfs_device.c b/lib/sysfs_device.c index e14d12a..b9a6d04 100644 --- a/lib/sysfs_device.c +++ b/lib/sysfs_device.c @@ -89,7 +89,7 @@ int sysfs_get_device_bus(struct sysfs_device *dev) * closing children only. * @devroot: device root of tree. */ -static void sysfs_close_device_tree(struct sysfs_device *devroot) +void sysfs_close_device_tree(struct sysfs_device *devroot) { if (devroot != NULL) { if (devroot->children != NULL) { @@ -222,7 +222,7 @@ struct sysfs_device *sysfs_open_device_path(const unsigned char *path) * returns struct sysfs_device and its children with success or NULL with * error. */ -static struct sysfs_device *sysfs_open_device_tree(const unsigned char *path) +struct sysfs_device *sysfs_open_device_tree(const unsigned char *path) { struct sysfs_device *rootdev = NULL, *new = NULL; struct sysfs_directory *cur = NULL; diff --git a/lsbus.1 b/lsbus.1 deleted file mode 100644 index ca02c06..0000000 --- a/lsbus.1 +++ /dev/null @@ -1,58 +0,0 @@ -.TH LSBUS 1 "October 12, 2003" "Martin Pitt" -.SH NAME -lsbus \- query system bus information - -.SH SYNOPSIS -.B lsbus -[ -.I options -.I bus -[ -.I device -] ] - -.SH DESCRIPTION -When -.B lsbus -is called without arguments, it shows the available bus types (usb, -pci, etc.). -.P -When \fIbus\fR is supplied, then a tree of all devices (without -further arguments) or a specific device (when \fIdevice\fR is -given) on this bus is displayed. - -.SH OPTIONS -.TP -.B \-a -Show attributes -.TP -.B \-d -Show only devices -.TP -.B \-v -Show all attributes with values -.TP -.B \-A \fIattribute -Show attribute value -.TP -.B \-D -Show only drivers -.TP -.B \-h -Show usage - -.SH SEE ALSO -.B systool -(1) -.P -The web page of -.B libsysfs -at http://linux\-diag.sourceforge.net/Sysfsutils.html - -.SH AUTHOR -.B lsbus -was written by Ananth Mavinakayanahalli <ananth@in.ibm.com> and -Daniel Stekloff <dsteklof@us.ibm.com>. -.P -This man page was contributed by Martin Pitt <mpitt@debian.org> for -the Debian GNU/Linux system (but may be used by others). @@ -18,17 +18,25 @@ is supplied, the information reqested by .I options is shown only for the specified device, otherwise all present devices are displayed. +.P +.B systool +uses APIs provided by +.B libsysfs +to gather information. +.B systool +runs only on Linux systems running kernels 2.5 or later, with the sysfs +filesystem mounted. .SH OPTIONS .TP .B \-a -Show attributes +Show attributes of the requested resource .TP .B \-b \fIbus -Show a specific bus +Show information for a specific bus .TP .B \-c \fIclass -Show a specific class +Show information for a specific class .TP .B \-d Show only devices @@ -36,21 +44,28 @@ Show only devices .B \-h Show usage .TP +.B \-p +Show absolute sysfs path to the resource +.TP .B \-r \fIroot_device Show a specific root device tree .TP .B \-v Show all attributes with values .TP -.B \-A \fI attribute -Show attribute value +.B \-A \fIattribute +Show attribute value for the requested resource +.TP +.B \-C +Show device's children .TP .B \-D Show only drivers +.TP +.B \-P +Show device's parent .SH SEE ALSO -.B lsbus -(1) .P The web page of .B libsysfs |