summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormananth <mananth>2003-10-22 12:59:29 +0000
committermananth <mananth>2003-10-22 12:59:29 +0000
commit18170e71126615eaf49be5add2915d8fa6edb4a5 (patch)
tree28f557e4ae9733dad2cec6f61555e6c90be4c9eb
parent35d0758e6dc564de3c2dd1571a7455985eaf7bb6 (diff)
downloadsysfsutils-18170e71126615eaf49be5add2915d8fa6edb4a5.tar.gz
Removed block subsystem support per Greg/Dan
-rw-r--r--ChangeLog3
-rw-r--r--cmd/systool.c107
-rw-r--r--docs/libsysfs.txt200
-rw-r--r--include/libsysfs.h35
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/Makefile.in10
-rw-r--r--lib/sysfs_block.c331
7 files changed, 19 insertions, 669 deletions
diff --git a/ChangeLog b/ChangeLog
index a034368..9cb2000 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
+10/22/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com>
+ * Removed "block" subsystem support
+
10/20/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com>
* Added code to install header files (from include dir)
to /usr/local/include/ directory
diff --git a/cmd/systool.c b/cmd/systool.c
index b6e1b78..1da9018 100644
--- a/cmd/systool.c
+++ b/cmd/systool.c
@@ -48,7 +48,7 @@ unsigned char *show_bus = NULL;
#define SHOW_ALL 0xff
-static unsigned char cmd_options[] = "aA:b:B:c:dDhr:v";
+static unsigned char cmd_options[] = "aA:b:c:dDhr:v";
/*
* binary_files - defines existing sysfs binary files. These files will be
@@ -89,7 +89,6 @@ void usage(void)
"\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-B <block_name>\t\tShow specific block device\n");
fprintf(stdout, "\t-D\t\t\tShow only drivers\n");
}
@@ -524,84 +523,6 @@ int show_sysfs_root(unsigned char *rootname)
}
/**
- * show_block_partitions: show partition details
- * @partitions: dlist of partitions
- * returns nothing
- */
-void show_block_partitions(struct dlist *partitions, int level)
-{
- struct sysfs_block_partition *part = NULL;
- struct dlist *attributes = NULL;
-
- if (partitions == NULL)
- return;
- indent(level);
- fprintf(stdout, "Partitions:\n");
- dlist_for_each_data(partitions, part, struct sysfs_block_partition) {
- indent(level+4);
- fprintf(stdout, "%s\n", part->name);
- if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE
- | SHOW_ALL_ATTRIB_VALUES)) {
- attributes = sysfs_get_partition_attributes(part);
- if (attributes != NULL)
- show_attributes(attributes, level+8);
- }
- }
-}
-
-/**
- * show_sysfs_block: prints out details of the given block device
- * @blockname: name of the block device to show
- * returns 0 on success, 1 on error
- */
-int show_sysfs_block(unsigned char *blockname)
-{
- struct sysfs_block_device *block = NULL;
- struct dlist *attributes = NULL;
-
- if (blockname == NULL) {
- errno = EINVAL;
- return 1;
- }
-
- block = sysfs_open_block_device(blockname);
- if (block == NULL) {
- fprintf(stderr, "Error opening block device %s\n", blockname);
- return 1;
- }
-
- fprintf(stdout, "Block: %s\n", blockname);
- if (show_options & (SHOW_ATTRIBUTES | SHOW_ATTRIBUTE_VALUE
- | SHOW_ALL_ATTRIB_VALUES)) {
- attributes = sysfs_get_blockdev_attributes(block);
- if (attributes != NULL)
- show_attributes(attributes, 4);
- attributes = sysfs_get_queue_attributes(block);
- if (attributes != NULL) {
- indent(4);
- fprintf(stdout, "queue:\n");
- show_attributes(attributes, 8);
- }
- attributes = sysfs_get_iosched_attributes(block);
- if (attributes != NULL) {
- indent(8);
- fprintf(stdout, "iosched:\n");
- show_attributes(attributes, 12);
- }
- }
- if (block->partitions != NULL)
- show_block_partitions(block->partitions, 4);
- if (block->device != NULL) {
- indent(4);
- fprintf(stdout, "Physical device:");
- show_device(block->device, 4);
- }
- sysfs_close_block_device(block);
-
- return 0;
-}
-
-/**
* show_default_info: prints current buses, classes, and root devices
* supported by sysfs.
* returns 0 with success or 1 with error.
@@ -640,20 +561,6 @@ int show_default_info(void)
}
sysfs_close_list(list);
- strcpy(subsys, SYSFS_BLOCK_DIR);
- list = sysfs_open_subsystem_list(subsys);
- if (list != NULL) {
- fprintf(stdout, "Supported sysfs block devices:\n");
- i = 1;
- dlist_for_each_data(list, cur, char) {
- fprintf(stdout, "\t%s", cur);
- if (!(i++ % 8))
- fprintf(stdout, "\n");
- }
- fprintf(stdout, "\n");
- }
- sysfs_close_list(list);
-
return retval;
}
@@ -663,7 +570,6 @@ int main(int argc, char *argv[])
/* unsigned char *show_bus = NULL;*/
unsigned char *show_class = NULL;
unsigned char *show_root = NULL;
- unsigned char *show_block = NULL;
int retval = 0;
int opt;
extern int optind;
@@ -688,9 +594,6 @@ int main(int argc, char *argv[])
case 'b':
show_bus = optarg;
break;
- case 'B':
- show_block = optarg;
- break;
case 'c':
show_class = optarg;
break;
@@ -737,8 +640,7 @@ int main(int argc, char *argv[])
exit(1);
}
- if ((show_bus == NULL && show_class == NULL &&
- show_root == NULL && show_block == NULL) &&
+ if ((show_bus == NULL && show_class == NULL && show_root == NULL) &&
(show_options & (SHOW_ATTRIBUTES |
SHOW_ATTRIBUTE_VALUE | SHOW_DEVICES |
SHOW_DRIVERS | SHOW_ALL_ATTRIB_VALUES))) {
@@ -764,11 +666,8 @@ int main(int argc, char *argv[])
retval = show_sysfs_class(show_class);
if (show_root != NULL)
retval = show_sysfs_root(show_root);
- if (show_block != NULL)
- retval = show_sysfs_block(show_block);
- if (show_bus == NULL && show_class == NULL &&
- show_root == NULL && show_block == NULL)
+ if (show_bus == NULL && show_class == NULL && show_root == NULL)
retval = show_default_info();
if (show_bus != NULL)
diff --git a/docs/libsysfs.txt b/docs/libsysfs.txt
index ac647b3..7b8f890 100644
--- a/docs/libsysfs.txt
+++ b/docs/libsysfs.txt
@@ -3,7 +3,7 @@
=========================================
Version: 0.3.0
-October 9, 2003
+October 22, 2003
Contents
--------
@@ -19,10 +19,8 @@ Contents
5.2 Bus Data Structure
5.3 Class Data Structures
5.4 Root Device Data Structure
- 5.5 Block Data Structure
- 5.5.1 Block Partition Data Structure
- 5.6 Device Data Structure
- 5.7 Driver Data Structure
+ 5.5 Device Data Structure
+ 5.6 Driver Data Structure
6. Functions
6.1 Utility Functions
6.2 Filesystem Functions
@@ -31,9 +29,8 @@ Contents
6.2.3 Directory Functions
6.3 Bus Functions
6.4 Class Functions
- 6.5 Block Functions
- 6.6 Device Functions
- 6.7 Driver Functions
+ 6.5 Device Functions
+ 6.6 Driver Functions
7. Usage
8. Conclusion
@@ -302,65 +299,7 @@ The name of the root device as represented under /sys/devices is read into
intended to be used internal to the library.
-5.5 Block Data Structure
-------------------------
-Block devices and their heirarchies (partitions) in sysfs are repersented under
-the /sys/block directory structure. Partitions are also represented in the
-heirarchy as directories under the parent device. As an example, if a
-SCSI disk (sda) has two partitions (sda1, sda2), they show up as
-
-sda---
- |
- |--- sda1
- |
- |--- sda2
-
-In addition to this, statistics related to I/O scheduling on these block devices
-are also included.
-
-struct sysfs_block_device {
- struct sysfs_device *device; /* the physical device */
- struct dlist *partitions; /* struct sysfs_block_partition */
- unsigned char name[SYSFS_NAME_LEN];
- unsigned char path[SYSFS_PATH_MAX];
-
- /* for internal use only */
- struct sysfs_directory *directory;
-};
-
-The sysfs_block_device structure imbeds in it a sysfs_device (if present), which
-is the physical device corresponding to this block device. In addition, it
-contains a list of partitions. The name of the block device is read into "name"
-and the absolute path to the block device into "path". Its directory information
-is also stored but is intended to be used internal to the library. Applications
-desirous of obtaining block device attributes, queue attributes and I/O
-scheduling information need to use:
-
-struct dlist *sysfs_get_blockdev_attributes(struct sysfs_block_device *block)
-struct dlist *sysfs_get_queue_attributes(struct sysfs_block_device *block)
-struct dlist *sysfs_get_iosched_attributes(struct sysfs_block_device *block)
-
-
-5.5.1 Block Partition Data Structure
-------------------------------------
-Partitions under block devices are represented by the sysfs_block_partition data
-structure.
-
-struct sysfs_block_partition {
- unsigned char *name[SYSFS_NAME_LEN];
-
- /* for internal use only */
- struct sysfs_directory *directory;
-};
-
-The sysfs_block_partition structure contains the name of the partition (hda1,
-hda2, sda1, etc) and its directory information. Applications may use the
-following function to get a list of attributes for the partition
-
-struct dlist *sysfs_get_partition_attributes
- (struct sysfs_block_partition *part)
-
-5.6 Device Data Structure
+5.5 Device Data Structure
-------------------------
The sysfs_device structure represents a system device that's exposed
@@ -389,7 +328,7 @@ struct sysfs_attribute *sysfs_get_device_attribute(struct sysfs_device *dev,
struct dlist *sysfs_get_device_attributes(struct sysfs_device *device)
-5.7 Driver Data Structure
+5.6 Driver Data Structure
-------------------------
The sysfs_driver structure represents a device driver.
@@ -1159,128 +1098,7 @@ Prototype: int sysfs_write_classdev_attr(unsigned char *dev,
-------------------------------------------------------------------------------
-6.5 Block Functions
--------------------
-Libsysfs supports functions to access the "block" subsystem. Semantics for
-the calls are similar to the subsystems detailed above.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_block_device
-
-Description: Function opens up one of the block devices represented in sysfs
- in /sys/block directory. It returns a sysfs_block_device
- structure, containing details about the "physical" entity
- for the block device and its partitions.
-
-Arguments: unsigned char *name Name of the block device to open, "sda"..
-
-Returns: struct sysfs_block_device * on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_block_device *sysfs_open_block_device
- (unsigned char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_block_device
-
-Description: Function closes a sysfs_block_device structure including its
- partitions.
-
-Arguments: struct sysfs_block_device *block Block device to close
-
-Prototype: void sysfs_close_block_device(struct sysfs_block_device *block)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_blockdev_attributes
-
-Description: Function takes a sysfs_block_device structure and returns a list
- of attributes for the block device.
-
-Arguments: struct sysfs_block_device *block Block device for which
- attributes are required
-
-Returns: struct dlist * of attributes with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_blockdev_attributes
- (struct sysfs_block_device *block)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_blockdev_attr
-
-Description: Searches supplied block device's attributes by name and returns
- the attribute.
-
-Arguments: struct sysfs_block_device *block Device to search
- const unsigned char *name Attribute name to find
-
-Returns: struct sysfs_attribute * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_attribute *sysfs_get_blockdev_attr
- (struct sysfs_block_device *block, const unsigned char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_partition_attributes
-
-Description: Function takes a sysfs_block_partition structure and returns a
- list of attributes for the block partition.
-
-Arguments: struct sysfs_block_partition *part Block partition for
- which attributes are
- required
-
-Returns: struct dlist * of attributes with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_partition_attributes
- (struct sysfs_block_partition *part)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_queue_attributes
-
-Description: Function takes a sysfs_block_device structure and returns a list
- of "queue" attributes for the block device.
-
-Arguments: struct sysfs_block_device *block Block device for which
- attributes are required
-
-Returns: struct dlist * of attributes with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_queue_attributes
- (struct sysfs_block_device *block)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_iosched_attributes
-
-Description: Function takes a sysfs_block_device structure and returns a list
- of "iosched" attributes for the block device.
-
-Arguments: struct sysfs_block_device *block Block device for which
- attributes are required
-
-Returns: struct dlist * of attributes with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_iosched_attributes
- (struct sysfs_block_device *block)
--------------------------------------------------------------------------------
-
-
-6.6 Device Functions
+6.5 Device Functions
--------------------
Devices represent everything in sysfs under /sys/devices, which is a
@@ -1427,7 +1245,7 @@ Prototype: int sysfs_write_device_attr(unsigned char *dev,
-------------------------------------------------------------------------------
-6.7 Driver Functions
+6.6 Driver Functions
--------------------
Drivers are represented in sysfs under the /sys/bus/xxx/drivers (xxx being
diff --git a/include/libsysfs.h b/include/libsysfs.h
index 980d91b..6b3055b 100644
--- a/include/libsysfs.h
+++ b/include/libsysfs.h
@@ -41,10 +41,6 @@
#define SYSFS_NAME_ATTRIBUTE "name"
#define SYSFS_UNKNOWN "unknown"
-/* Some "block" subsystem specific #defines */
-#define SYSFS_QUEUE_NAME "queue"
-#define SYSFS_IOSCHED_NAME "iosched"
-
#define SYSFS_PATH_MAX 255
#define SYSFS_NAME_LEN 50
#define SYSFS_BUS_ID_SIZE 20
@@ -133,23 +129,6 @@ struct sysfs_class {
struct sysfs_directory *directory;
};
-struct sysfs_block_device {
- struct sysfs_device *device; /* the physical device */
- struct dlist *partitions; /* struct sysfs_block_partition */
- unsigned char name[SYSFS_NAME_LEN];
- unsigned char path[SYSFS_PATH_MAX];
-
- /* for internal use only */
- struct sysfs_directory *directory;
-};
-
-struct sysfs_block_partition {
- unsigned char name[SYSFS_NAME_LEN];
-
- /* for internal use only */
- struct sysfs_directory *directory;
-};
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -260,20 +239,6 @@ extern int sysfs_write_classdev_attr(unsigned char *dev, unsigned char *attrib,
extern int sysfs_read_classdev_attr(unsigned char *dev, unsigned char *attrib,
unsigned char *value, size_t len);
-/* generic sysfs block access */
-extern void sysfs_close_block_device(struct sysfs_block_device *block);
-extern struct sysfs_block_device *sysfs_open_block_device(unsigned char *name);
-extern struct dlist *sysfs_get_blockdev_attributes
- (struct sysfs_block_device *block);
-extern struct sysfs_attribute *sysfs_get_blockdev_attr
- (struct sysfs_block_device *block, const unsigned char *name);
-extern struct dlist *sysfs_get_partition_attributes
- (struct sysfs_block_partition *part);
-extern struct dlist *sysfs_get_queue_attributes
- (struct sysfs_block_device *block);
-extern struct dlist *sysfs_get_iosched_attributes
- (struct sysfs_block_device *block);
-
#ifdef __cplusplus
}
#endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 3d5f66c..baaa784 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,5 +1,5 @@
lib_LTLIBRARIES = libsysfs.la
libsysfs_la_SOURCES = sysfs_utils.c sysfs_dir.c sysfs_bus.c sysfs_class.c \
- sysfs_device.c sysfs_driver.c sysfs_block.c sysfs.h dlist.c
+ sysfs_device.c sysfs_driver.c sysfs.h dlist.c
INCLUDES = -I../include
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 4387ad5..9490316 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -85,7 +85,7 @@ am__quote = @am__quote@
install_sh = @install_sh@
lib_LTLIBRARIES = libsysfs.la
libsysfs_la_SOURCES = sysfs_utils.c sysfs_dir.c sysfs_bus.c sysfs_class.c \
- sysfs_device.c sysfs_driver.c sysfs_block.c sysfs.h dlist.c
+ sysfs_device.c sysfs_driver.c sysfs.h dlist.c
INCLUDES = -I../include
subdir = lib
@@ -97,8 +97,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libsysfs_la_LDFLAGS =
libsysfs_la_LIBADD =
am_libsysfs_la_OBJECTS = sysfs_utils.lo sysfs_dir.lo sysfs_bus.lo \
- sysfs_class.lo sysfs_device.lo sysfs_driver.lo sysfs_block.lo \
- dlist.lo
+ sysfs_class.lo sysfs_device.lo sysfs_driver.lo dlist.lo
libsysfs_la_OBJECTS = $(am_libsysfs_la_OBJECTS)
DEFS = @DEFS@
@@ -108,9 +107,7 @@ LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/dlist.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/sysfs_block.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/sysfs_bus.Plo \
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/dlist.Plo ./$(DEPDIR)/sysfs_bus.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/sysfs_class.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/sysfs_device.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/sysfs_dir.Plo \
@@ -175,7 +172,6 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dlist.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysfs_block.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysfs_bus.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysfs_class.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysfs_device.Plo@am__quote@
diff --git a/lib/sysfs_block.c b/lib/sysfs_block.c
deleted file mode 100644
index 6a9c97c..0000000
--- a/lib/sysfs_block.c
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * sysfs_block.c
- *
- * Generic block utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-#include "libsysfs.h"
-#include "sysfs.h"
-
-/**
- * sysfs_close_block_partition: closes a block partition
- * @partition: sysfs_block_partition to close
- */
-static void sysfs_close_block_partition(struct sysfs_block_partition *partition)
-{
- if (partition != NULL) {
- if (partition->directory != NULL)
- partition->directory = NULL;
- }
-}
-
-static void sysfs_del_partition(void *partition)
-{
- sysfs_close_block_partition((struct sysfs_block_partition *)partition);
-}
-
-/**
- * sysfs_close_block_device: closes a sysfs_block_device
- * @block: sysfs_block_device structure
- */
-void sysfs_close_block_device(struct sysfs_block_device *block)
-{
- if (block != NULL) {
- if (block->directory != NULL)
- sysfs_close_directory(block->directory);
- if (block->device != NULL)
- sysfs_close_device(block->device);
- if (block->partitions != NULL)
- dlist_destroy(block->partitions);
- }
-}
-
-/**
- * alloc_block_device: allocate a sysfs_block_device
- * returns sysfs_block_device or NULL
- */
-static struct sysfs_block_device *alloc_block_device()
-{
- return (struct sysfs_block_device *)
- calloc(1, sizeof(struct sysfs_block_device));
-}
-
-/**
- * open_block_dir: opens a sysfs block directory
- * returns sysfs_directory on success or NULL on error
- */
-static struct sysfs_directory *open_block_dir(const unsigned char *name)
-{
- unsigned char path[SYSFS_PATH_MAX];
- struct sysfs_directory *directory = NULL;
-
- if (name == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- memset(path, 0, SYSFS_PATH_MAX);
- if ((sysfs_get_mnt_path(path, SYSFS_PATH_MAX)) != 0) {
- dprintf("Error getting sysfs mount path\n");
- return NULL;
- }
-
- strcat(path, SYSFS_BLOCK_DIR);
- strcat(path, "/");
- strcat(path, name);
- directory = sysfs_open_directory(path);
- if (directory == NULL) {
- dprintf("Block device %s not supported on this system", name);
- return NULL;
- }
- if ((sysfs_read_directory(directory)) != 0) {
- dprintf("Error reading directory %s\n", directory->path);
- sysfs_close_directory(directory);
- return NULL;
- }
- sysfs_read_all_subdirs(directory);
-
- return directory;
-}
-
-/**
- * alloc_block_partition: alloc a sysfs_block_partition structure
- */
-static struct sysfs_block_partition *alloc_block_partition(void)
-{
- return(struct sysfs_block_partition *)
- calloc(1, sizeof(struct sysfs_block_partition));
-}
-
-/**
- * get_all_block_devices: Retrieves details of block directory
- * @block: sysfs_block_device for which details are required
- * returns 0 on success, -1 on failure
- */
-static int get_all_block_devices(struct sysfs_block_device *block)
-{
- struct sysfs_directory *cur = NULL;
- struct sysfs_block_partition *part = NULL;
-
- if (block == NULL || block->directory == NULL) {
- errno = EINVAL;
- return -1;
- }
- if (block->directory->subdirs == NULL)
- return 0;
-
- dlist_for_each_data(block->directory->subdirs, cur,
- struct sysfs_directory) {
- switch(strcmp(cur->name, SYSFS_QUEUE_NAME)) {
- case 0: /* this is the "queue" directory */
- if ((sysfs_read_directory(cur)) < 0) {
- dprintf("Error reading directory %s\n",
- cur->path);
- return -1;
- }
- break;
- default: /* these are the partitions */
- part = alloc_block_partition();
- if (part == NULL) {
- dprintf("calloc failed\n");
- return -1;
- }
- part->directory = cur;
- strcpy(part->name, cur->name);
- if (block->partitions == NULL)
- block->partitions =
- dlist_new_with_delete
- (sizeof(struct
- sysfs_block_partition),
- sysfs_del_partition);
- dlist_unshift(block->partitions, part);
- break;
- }
- }
- return 0;
-}
-
-/**
- * sysfs_open_block_device: opens the specific block device and all its related
- * details as partitions, etc
- * returns sysfs_block_device struct on success and NULL on error
- */
-struct sysfs_block_device *sysfs_open_block_device(unsigned char *name)
-{
- struct sysfs_block_device *block = NULL;
- struct sysfs_directory *blockdir = NULL;
- struct sysfs_link *curlink = NULL;
-
- if (name == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- block = alloc_block_device();
- if (block == NULL) {
- dprintf("calloc failed\n");
- return NULL;
- }
- strcpy(block->name, name);
- blockdir = open_block_dir(name);
- if (blockdir == NULL) {
- sysfs_close_block_device(block);
- return NULL;
- }
- strcpy(block->path, blockdir->path);
- block->directory = blockdir;
- if ((get_all_block_devices(block)) != 0) {
- dprintf("Error retrieving devices for block %s\n", name);
- sysfs_close_block_device(block);
- return NULL;
- }
- /* check if the "block" device has a link to the physical device */
- if (block->directory->links != NULL) {
- dlist_for_each_data(block->directory->links, curlink,
- struct sysfs_link) {
- block->device = sysfs_open_device(curlink->target);
- if (block->device == NULL) {
- dprintf("Error opening device at %s\n",
- curlink->target);
- }
- }
- }
-
- return block;
-}
-
-/**
- * sysfs_get_blockdev_attributes: returns attributes for the block device
- * @block: block device for which attribs are to be returned
- */
-struct dlist *sysfs_get_blockdev_attributes(struct sysfs_block_device *block)
-{
- if (block == NULL || block->directory == NULL)
- return NULL;
-
- return(block->directory->attributes);
-}
-
-/**
- * sysfs_get_blockdev_attr: searches block device's attributes by name
- * @block: block device to look through
- * @name: attribute name to get
- * returns sysfs_attribute reference with success or NULL with error.
- */
-struct sysfs_attribute *sysfs_get_blockdev_attr
- (struct sysfs_block_device *block, const unsigned char *name)
-{
- struct sysfs_attribute *cur = NULL;
-
- if (block == NULL || block->directory == NULL
- || block->directory->attributes == NULL || name == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- cur = sysfs_get_directory_attribute(block->directory,
- (unsigned char *)name);
- if (cur != NULL)
- return cur;
-
- return NULL;
-}
-
-/**
- * sysfs_get_partition_attributes: returns attributes for the block
- * device partition
- * @block: block device partition for which attribs are to be returned
- */
-struct dlist *sysfs_get_partition_attributes
- (struct sysfs_block_partition *part)
-{
- if (part == NULL || part->directory == NULL)
- return NULL;
-
- return(part->directory->attributes);
-}
-
-/**
- * sysfs_get_queue_attributes: returns attributes for the block device's
- * QUEUE parameters. Used to set #of queued
- * requests as well as the choice of IO
- * scheduler
- * @block: block device for which the attributes are needed.
- */
-struct dlist *sysfs_get_queue_attributes(struct sysfs_block_device *block)
-{
- struct sysfs_directory *dir = NULL;
-
- if (block->directory->subdirs == NULL)
- return NULL;
-
- dlist_for_each_data(block->directory->subdirs, dir,
- struct sysfs_directory) {
- if ((strcmp(dir->name, SYSFS_QUEUE_NAME)) != 0)
- continue;
- else
- return (dir->attributes);
- }
- return NULL;
-}
-
-/**
- * sysfs_get_iosched_attributes: returns attributes for the block device's
- * IOSCHED parameters for the given device
- * @block: block device for which the attributes are needed
- * returns a dlist of iosched attributes.
- */
-struct dlist *sysfs_get_iosched_attributes(struct sysfs_block_device *block)
-{
- struct dlist *list = NULL;
- struct sysfs_directory *dir = NULL, *new = NULL;
- unsigned int found = 0;
-
- if (block->directory->subdirs == NULL)
- return NULL;
-
- dlist_for_each_data(block->directory->subdirs, dir,
- struct sysfs_directory) {
- if ((strcmp(dir->name, SYSFS_QUEUE_NAME)) != 0)
- continue;
- else {
- found = 1;
- break;
- }
- }
- if (found) {
- /*
- * this is the queue directory - read this and the
- * iosched directory too
- */
- if (dir->subdirs == NULL)
- goto noiosched;
-
- dlist_for_each_data(dir->subdirs, new,
- struct sysfs_directory) {
- if ((strcmp(new->name, SYSFS_IOSCHED_NAME)) == 0)
- if ((sysfs_read_directory(new)) == 0)
- return new->attributes;
- }
- }
-noiosched:
- dprintf("IOSCHED attributes not found\n");
- return NULL;
-}
-