summaryrefslogtreecommitdiff
path: root/libsysfs
diff options
context:
space:
mode:
Diffstat (limited to 'libsysfs')
-rw-r--r--libsysfs/LGPL441
-rw-r--r--libsysfs/dlist.c621
-rw-r--r--libsysfs/libsysfs.txt1954
-rw-r--r--libsysfs/sysfs.h64
-rw-r--r--libsysfs/sysfs/dlist.h207
-rw-r--r--libsysfs/sysfs/libsysfs.h225
-rw-r--r--libsysfs/sysfs_bus.c317
-rw-r--r--libsysfs/sysfs_class.c557
-rw-r--r--libsysfs/sysfs_device.c341
-rw-r--r--libsysfs/sysfs_dir.c491
-rw-r--r--libsysfs/sysfs_driver.c261
-rw-r--r--libsysfs/sysfs_utils.c290
12 files changed, 0 insertions, 5769 deletions
diff --git a/libsysfs/LGPL b/libsysfs/LGPL
deleted file mode 100644
index e00a829bb6..0000000000
--- a/libsysfs/LGPL
+++ /dev/null
@@ -1,441 +0,0 @@
-
- GNU Lesser Public License
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- [This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your freedom to
- share and change it. By contrast, the GNU General Public Licenses are
- intended to guarantee your freedom to share and change free software--to
- make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some specially
- designated software packages--typically libraries--of the Free Software
- Foundation and other authors who decide to use it. You can use it too, but
- we suggest you first think carefully about whether this license or the
- ordinary General Public License is the better strategy to use in any
- particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use, not
- price. Our General Public Licenses are designed to make sure that you have
- the freedom to distribute copies of free software (and charge for this
- service if you wish); that you receive source code or can get it if you
- want it; that you can change the software and use pieces of it in new free
- programs; and that you are informed that you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
- distributors to deny you these rights or to ask you to surrender these
- rights. These restrictions translate to certain responsibilities for you
- if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis or
- for a fee, you must give the recipients all the rights that we gave you.
- You must make sure that they, too, receive or can get the source code. If
- you link other code with the library, you must provide complete object
- files to the recipients, so that they can relink them with the library
- after making changes to the library and recompiling it. And you must show
- them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
- library, and (2) we offer you this license, which gives you legal
- permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that there is
- no warranty for the free library. Also, if the library is modified by
- someone else and passed on, the recipients should know that what they have
- is not the original version, so that the original author's reputation will
- not be affected by problems that might be introduced by others.
-
- Finally, software patents pose a constant threat to the existence of any
- free program. We wish to make sure that a company cannot effectively
- restrict the users of a free program by obtaining a restrictive license
- from a patent holder. Therefore, we insist that any patent license
- obtained for a version of the library must be consistent with the full
- freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the ordinary
- GNU General Public License. This license, the GNU Lesser General Public
- License, applies to certain designated libraries, and is quite different
- from the ordinary General Public License. We use this license for certain
- libraries in order to permit linking those libraries into non-free
- programs.
-
- When a program is linked with a library, whether statically or using a
- shared library, the combination of the two is legally speaking a combined
- work, a derivative of the original library. The ordinary General Public
- License therefore permits such linking only if the entire combination fits
- its criteria of freedom. The Lesser General Public License permits more
- lax criteria for linking other code with the library.
-
- We call this license the "Lesser" General Public License because it does
- Less to protect the user's freedom than the ordinary General Public
- License. It also provides other free software developers Less of an
- advantage over competing non-free programs. These disadvantages are the
- reason we use the ordinary General Public License for many libraries.
- However, the Lesser license provides advantages in certain special
- circumstances.
-
- For example, on rare occasions, there may be a special need to encourage
- the widest possible use of a certain library, so that it becomes a
- de-facto standard. To achieve this, non-free programs must be allowed to
- use the library. A more frequent case is that a free library does the same
- job as widely used non-free libraries. In this case, there is little to
- gain by limiting the free library to free software only, so we use the
- Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
- programs enables a greater number of people to use a large body of free
- software. For example, permission to use the GNU C Library in non-free
- programs enables many more people to use the whole GNU operating system,
- as well as its variant, the GNU/Linux operating system.
-
- Although the Lesser General Public License is Less protective of the
- users' freedom, it does ensure that the user of a program that is linked
- with the Library has the freedom and the wherewithal to run that program
- using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
- modification follow. Pay close attention to the difference between a "work
- based on the library" and a "work that uses the library". The former
- contains code derived from the library, whereas the latter must be
- combined with the library in order to run.
-
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other program
- which contains a notice placed by the copyright holder or other authorized
- party saying it may be distributed under the terms of this Lesser General
- Public License (also called "this License"). Each licensee is addressed as
- "you".
-
- A "library" means a collection of software functions and/or data prepared
- so as to be conveniently linked with application programs (which use some
- of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work which
- has been distributed under these terms. A "work based on the Library"
- means either the Library or any derivative work under copyright law: that
- is to say, a work containing the Library or a portion of it, either
- verbatim or with modifications and/or translated straightforwardly into
- another language. (Hereinafter, translation is included without limitation
- in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for making
- modifications to it. For a library, complete source code means all the
- source code for all modules it contains, plus any associated interface
- definition files, plus the scripts used to control compilation and
- installation of the library.
-
- Activities other than copying, distribution and modification are not
- covered by this License; they are outside its scope. The act of running a
- program using the Library is not restricted, and output from such a
- program is covered only if its contents constitute a work based on the
- Library (independent of the use of the Library in a tool for writing it).
- Whether that is true depends on what the Library does and what the program
- that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's complete
- source code as you receive it, in any medium, provided that you
- conspicuously and appropriately publish on each copy an appropriate
- copyright notice and disclaimer of warranty; keep intact all the notices
- that refer to this License and to the absence of any warranty; and
- distribute a copy of this License along with the Library.
-
- You may charge a fee for the physical act of transferring a copy, and you
- may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Library or any portion of it,
- thus forming a work based on the Library, and copy and distribute such
- modifications or work under the terms of Section 1 above, provided that
- you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices stating
- that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no charge to
- all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a table
- of data to be supplied by an application program that uses the facility,
- other than as an argument passed when the facility is invoked, then you
- must make a good faith effort to ensure that, in the event an
- application does not supply such function or table, the facility still
- operates, and performs whatever part of its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has a
- purpose that is entirely well-defined independent of the application.
- Therefore, Subsection 2d requires that any application-supplied function
- or table used by this function must be optional: if the application does
- not supply it, the square root function must still compute square
- roots.)
-
- These requirements apply to the modified work as a whole. If
- identifiable sections of that work are not derived from the Library, and
- can be reasonably considered independent and separate works in
- themselves, then this License, and its terms, do not apply to those
- sections when you distribute them as separate works. But when you
- distribute the same sections as part of a whole which is a work based on
- the Library, the distribution of the whole must be on the terms of this
- License, whose permissions for other licensees extend to the entire
- whole, and thus to each and every part regardless of who wrote it.
-
- Thus, it is not the intent of this section to claim rights or contest
- your rights to work written entirely by you; rather, the intent is to
- exercise the right to control the distribution of derivative or
- collective works based on the Library.
-
- In addition, mere aggregation of another work not based on the Library
- with the Library (or with a work based on the Library) on a volume of a
- storage or distribution medium does not bring the other work under the
- scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
- License instead of this License to a given copy of the Library. To do
- this, you must alter all the notices that refer to this License, so that
- they refer to the ordinary GNU General Public License, version 2, instead
- of to this License. (If a newer version than version 2 of the ordinary GNU
- General Public License has appeared, then you can specify that version
- instead if you wish.) Do not make any other change in these notices.
-
- Once this change is made in a given copy, it is irreversible for that
- copy, so the ordinary GNU General Public License applies to all subsequent
- copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of the
- Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or derivative of
- it, under Section 2) in object code or executable form under the terms of
- Sections 1 and 2 above provided that you accompany it with the complete
- corresponding machine-readable source code, which must be distributed
- under the terms of Sections 1 and 2 above on a medium customarily used for
- software interchange.
-
- If distribution of object code is made by offering access to copy from a
- designated place, then offering equivalent access to copy the source code
- from the same place satisfies the requirement to distribute the source
- code, even though third parties are not compelled to copy the source along
- with the object code.
-
- 5. A program that contains no derivative of any portion of the Library,
- but is designed to work with the Library by being compiled or linked with
- it, is called a "work that uses the Library". Such a work, in isolation,
- is not a derivative work of the Library, and therefore falls outside the
- scope of this License.
-
- However, linking a "work that uses the Library" with the Library creates
- an executable that is a derivative of the Library (because it contains
- portions of the Library), rather than a "work that uses the library". The
- executable is therefore covered by this License. Section 6 states terms
- for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file that
- is part of the Library, the object code for the work may be a derivative
- work of the Library even though the source code is not. Whether this is
- true is especially significant if the work can be linked without the
- Library, or if the work is itself a library. The threshold for this to be
- true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data structure
- layouts and accessors, and small macros and small inline functions (ten
- lines or less in length), then the use of the object file is unrestricted,
- regardless of whether it is legally a derivative work. (Executables
- containing this object code plus portions of the Library will still fall
- under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may distribute
- the object code for the work under the terms of Section 6. Any executables
- containing that work also fall under Section 6, whether or not they are
- linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or link a
- "work that uses the Library" with the Library to produce a work containing
- portions of the Library, and distribute that work under terms of your
- choice, provided that the terms permit modification of the work for the
- customer's own use and reverse engineering for debugging such
- modifications.
-
- You must give prominent notice with each copy of the work that the Library
- is used in it and that the Library and its use are covered by this
- License. You must supply a copy of this License. If the work during
- execution displays copyright notices, you must include the copyright
- notice for the Library among them, as well as a reference directing the
- user to the copy of this License. Also, you must do one of these things:
-
- a) Accompany the work with the complete corresponding machine-readable
- source code for the Library including whatever changes were used in the
- work (which must be distributed under Sections 1 and 2 above); and, if
- the work is an executable linked with the Library, with the complete
- machine-readable "work that uses the Library", as object code and/or
- source code, so that the user can modify the Library and then relink to
- produce a modified executable containing the modified Library. (It is
- understood that the user who changes the contents of definitions files
- in the Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the Library.
- A suitable mechanism is one that (1) uses at run time a copy of the
- library already present on the user's computer system, rather than
- copying library functions into the executable, and (2) will operate
- properly with a modified version of the library, if the user installs
- one, as long as the modified version is interface-compatible with the
- version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at least three
- years, to give the same user the materials specified in Subsection 6a,
- above, for a charge no more than the cost of performing this
- distribution.
-
- d) If distribution of the work is made by offering access to copy from a
- designated place, offer equivalent access to copy the above specified
- materials from the same place.
-
- e) Verify that the user has already received a copy of these materials
- or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the Library"
- must include any data and utility programs needed for reproducing the
- executable from it. However, as a special exception, the materials to be
- distributed need not include anything that is normally distributed (in
- either source or binary form) with the major components (compiler, kernel,
- and so on) of the operating system on which the executable runs, unless
- that component itself accompanies the executable.
-
- It may happen that this requirement contradicts the license restrictions
- of other proprietary libraries that do not normally accompany the
- operating system. Such a contradiction means you cannot use both them and
- the Library together in an executable that you distribute.
-
- 7. You may place library facilities that are a work based on the Library
- side-by-side in a single library together with other library facilities
- not covered by this License, and distribute such a combined library,
- provided that the separate distribution of the work based on the Library
- and of the other library facilities is otherwise permitted, and provided
- that you do these two things:
-
- a) Accompany the combined library with a copy of the same work based on
- the Library, uncombined with any other library facilities. This must be
- distributed under the terms of the Sections above.
-
- b) Give prominent notice with the combined library of the fact that part
- of it is a work based on the Library, and explaining where to find the
- accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute the
- Library except as expressly provided under this License. Any attempt
- otherwise to copy, modify, sublicense, link with, or distribute the
- Library is void, and will automatically terminate your rights under this
- License. However, parties who have received copies, or rights, from you
- under this License will not have their licenses terminated so long as such
- parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not signed
- it. However, nothing else grants you permission to modify or distribute
- the Library or its derivative works. These actions are prohibited by law
- if you do not accept this License. Therefore, by modifying or distributing
- the Library (or any work based on the Library), you indicate your
- acceptance of this License to do so, and all its terms and conditions for
- copying, distributing or modifying the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
- Library), the recipient automatically receives a license from the original
- licensor to copy, distribute, link with or modify the Library subject to
- these terms and conditions. You may not impose any further restrictions on
- the recipients' exercise of the rights granted herein. You are not
- responsible for enforcing compliance by third parties with this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
- infringement or for any other reason (not limited to patent issues),
- conditions are imposed on you (whether by court order, agreement or
- otherwise) that contradict the conditions of this License, they do not
- excuse you from the conditions of this License. If you cannot distribute
- so as to satisfy simultaneously your obligations under this License and
- any other pertinent obligations, then as a consequence you may not
- distribute the Library at all. For example, if a patent license would not
- permit royalty-free redistribution of the Library by all those who receive
- copies directly or indirectly through you, then the only way you could
- satisfy both it and this License would be to refrain entirely from
- distribution of the Library.
-
- If any portion of this section is held invalid or unenforceable under any
- particular circumstance, the balance of the section is intended to apply,
- and the section as a whole is intended to apply in other circumstances.
-
- It is not the purpose of this section to induce you to infringe any
- patents or other property right claims or to contest validity of any such
- claims; this section has the sole purpose of protecting the integrity of
- the free software distribution system which is implemented by public
- license practices. Many people have made generous contributions to the
- wide range of software distributed through that system in reliance on
- consistent application of that system; it is up to the author/donor to
- decide if he or she is willing to distribute software through any other
- system and a licensee cannot impose that choice.
-
- This section is intended to make thoroughly clear what is believed to be a
- consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in certain
- countries either by patents or by copyrighted interfaces, the original
- copyright holder who places the Library under this License may add an
- explicit geographical distribution limitation excluding those countries,
- so that distribution is permitted only in or among countries not thus
- excluded. In such case, this License incorporates the limitation as if
- written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new versions
- of the Lesser General Public License from time to time. Such new versions
- will be similar in spirit to the present version, but may differ in detail
- to address new problems or concerns.
-
- Each version is given a distinguishing version number. If the Library
- specifies a version number of this License which applies to it and "any
- later version", you have the option of following the terms and conditions
- either of that version or of any later version published by the Free
- Software Foundation. If the Library does not specify a license version
- number, you may choose any version ever published by the Free Software
- Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
- programs whose distribution conditions are incompatible with these, write
- to the author to ask for permission. For software which is copyrighted by
- the Free Software Foundation, write to the Free Software Foundation; we
- sometimes make exceptions for this. Our decision will be guided by the two
- goals of preserving the free status of all derivatives of our free
- software and of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
- LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
- ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT
- LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
- SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE
- WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
-
diff --git a/libsysfs/dlist.c b/libsysfs/dlist.c
deleted file mode 100644
index 5579602bbc..0000000000
--- a/libsysfs/dlist.c
+++ /dev/null
@@ -1,621 +0,0 @@
-/*
- * dlist.c
- *
- * Copyright (C) 2003 Eric J Bohm
- *
- * 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 021110307 USA
- *
- */
-
-
-/* Double linked list implementation.
-
- * You allocate the data and give dlist the pointer.
- * If your data is complex set the dlist->del_func to a an appropriate
- * delete function. Otherwise dlist will just use free.
-
-*/
-#include "stdlib.h"
-#include "dlist.h"
-
-/*
- * Return pointer to node at marker.
- * else null if no nodes.
- */
-
-inline void *dlist_mark(Dlist *list)
-{
- if(list->marker!=NULL)
- return(list->marker->data);
- else
- return(NULL);
-}
-
-/*
- * Set marker to start.
- */
-
-inline void dlist_start(Dlist *list)
-{
- list->marker=list->head;
-}
-
-/*
- * Set marker to end.
- */
-
-inline void dlist_end(Dlist *list)
-{
- list->marker=list->head;
-}
-
-/* internal use function
- * quickie inline to consolidate the marker movement logic
- * in one place
- *
- * when direction true it moves marker after
- * when direction false it moves marker before.
- * return pointer to data at new marker
- * if nowhere to move the marker in desired direction return null
- */
-inline void *_dlist_mark_move(Dlist *list,int direction)
-{
- if(direction)
- {
- if( list->marker && list->marker->next!=NULL)
- list->marker=list->marker->next;
- else
- return(NULL);
- }
- else
- {
- if( list->marker && list->marker->prev!=NULL)
- list->marker=list->marker->prev;
- else
- return(NULL);
- }
- if(list->marker!=list->head)
- return(list->marker->data);
- else
- return(NULL);
-}
-
-/*
- * Create new linked list to store nodes of datasize.
- * return null if list cannot be created.
- */
-Dlist *dlist_new(size_t datasize)
-{
- Dlist *list=NULL;
- if((list=malloc(sizeof(Dlist))))
- {
- list->marker=NULL;
- list->count=0L;
- list->data_size=datasize;
- list->del_func=free;
- list->head=&(list->headnode);
- list->head->prev=NULL;
- list->head->next=NULL;
- list->head->data=NULL;
- }
- return(list);
-}
-
-/*
- * Create new linked list to store nodes of datasize set list
- * data node delete function to the passed in del_func
- * return null if list cannot be created.
- */
-Dlist *dlist_new_with_delete(size_t datasize,void (*del_func)(void*))
-{
- Dlist *list=NULL;
- list=dlist_new(datasize);
- if(list!=NULL)
- list->del_func=del_func;
- return(list);
-}
-
-
-/*
- * remove marker node from list
- * call data_delete function on data if registered.
- * otherwise call free.
- * when direction true it moves marker after
- * when direction false it moves marker before.
- * free marker node
- * return nothing.
- */
-void dlist_delete(Dlist *list,int direction)
-{
- if((list->marker != list->head)&&(list->marker!=NULL))
- {
- DL_node *corpse;
- corpse=list->marker;
- _dlist_mark_move(list,direction);
- if(list->head->next==corpse)
- list->head->next=corpse->next;
- if(list->head->prev==corpse)
- list->head->prev=corpse->prev;
- if(corpse->prev!=NULL) //should be impossible
- corpse->prev->next=corpse->next;
- if(corpse->next!=NULL) //should be impossible
- corpse->next->prev=corpse->prev;
- list->del_func(corpse->data);
- list->count--;
- free(corpse);
- }
-}
-
-/*
- * Insert node containing data at marker.
- * If direction true it inserts after.
- * If direction false it inserts before.
- * move marker to inserted node
- * return pointer to inserted node
- */
-void *dlist_insert(Dlist *list,void *data,int direction)
-{
- DL_node *new_node=NULL;
- if(list==NULL || data==NULL)
- return(NULL);
- if(list->marker==NULL) //in case the marker ends up unset
- list->marker=list->head;
- if((new_node=malloc(sizeof(DL_node))))
- {
- new_node->data=data;
- new_node->prev=NULL;
- new_node->next=NULL;
- list->count++;
- if(list->head->next==NULL) //no l
- {
- list->head->next=list->head->prev=new_node;
- new_node->prev=list->head;
- new_node->next=list->head;
- }
- else if(direction)
- {
- new_node->next=list->marker->next;
- new_node->prev=list->marker;
- list->marker->next->prev=new_node;
- list->marker->next=new_node;
- }
- else
- {
- new_node->prev=list->marker->prev;
- new_node->next=list->marker;
- list->marker->prev->next=new_node;
- list->marker->prev=new_node;
- }
- list->marker=new_node;
- }
- else
- {
- return(NULL);
- }
- return(list->marker->data);
-}
-
-/* internal use only
- * Insert dl_node at marker.
- * If direction true it inserts after.
- * If direction false it inserts before.
- * move marker to inserted node
- * return pointer to inserted node
- */
-void *_dlist_insert_dlnode(struct dlist *list,struct dl_node *new_node,int direction)
-{
- if(list==NULL || new_node==NULL)
- return(NULL);
- if(list->marker==NULL) //in case the marker ends up unset
- list->marker=list->head;
- list->count++;
- if(list->head->next==NULL)
- {
- list->head->next=list->head->prev=new_node;
- new_node->prev=list->head;
- new_node->next=list->head;
- }
- else if(direction)
- {
- new_node->next=list->marker->next;
- new_node->prev=list->marker;
- list->marker->next->prev=new_node;
- list->marker->next=new_node;
- }
- else
- {
- new_node->prev=list->marker->prev;
- new_node->next=list->marker;
- list->marker->prev->next=new_node;
- list->marker->prev=new_node;
- }
- list->marker=new_node;
- return(list->marker);
-}
-
-
-
-/*
- * Remove DL_node from list without deallocating data.
- * if marker == killme .
- * when direction true it moves marker after
- * when direction false it moves marker before.
- * to previous if there is no next.
- */
-void *_dlist_remove(Dlist *list,DL_node *killme,int direction)
-{
- if(killme!=NULL)
- {
- void *killer_data=killme->data;
- // take care of head and marker pointers.
- if(list->marker==killme)
- _dlist_mark_move(list,direction);
- if(killme ==list->head->next)
- list->head->next=killme->next;
- if(killme==list->head->prev)
- list->head->prev=killme->prev;
- // remove from list
- if(killme->prev !=NULL)
- killme->prev->next=killme->next;
- if(killme->next !=NULL)
- killme->next->prev=killme->prev;
- list->count--;
- free(killme);
- return(killer_data);
- }
- else
- return (NULL);
-}
-
-/*
- * move dl_node from source to dest
- * if marker == target .
- * when direction true it moves marker after
- * when direction false it moves marker before.
- * to previous if there is no next.
- */
-void dlist_move(struct dlist *source, struct dlist *dest, struct dl_node *target,int direction)
-{
-
- if(target!=NULL)
- {
- if(target==source->head)
- {
- //not even going to try
- }
- else
- {
- // take care of head and marker pointers.
- if(source->marker==target)
- _dlist_mark_move(source,direction);
- if(target ==source->head->next)
- source->head->next=target->next;
- if(target==source->head->prev)
- source->head->prev=target->prev;
- // remove from list
- if(source->count==1)
- {
- target->prev=NULL;
- target->next=NULL;
- source->head->next=NULL;
- source->head->prev=NULL;
- }
- else
- {
- if(target->prev !=NULL)
- target->prev->next=target->next;
- if(target->next !=NULL)
- target->next->prev=target->prev;
- target->prev=NULL;
- target->next=NULL;
- }
- source->count--;
- _dlist_insert_dlnode(dest,target,direction);
- }
- }
-}
-
-
-/*
- * Insert node containing data after end.
- */
-void dlist_push(Dlist *list,void *data)
-{
- list->marker=list->head->prev;
- dlist_insert(list,data,1);
-}
-
-/*
- * Insert node containing data at start.
- */
-
-void dlist_unshift(Dlist *list,void *data)
-
-{
- list->marker=list->head->next;
- dlist_insert(list,data,0);
-}
-
-void dlist_unshift_sorted(Dlist *list, void *data,
- int (*sorter)(void *new_elem, void *old_elem))
-{
- if (list->count == 0)
- dlist_unshift(list, data);
- else {
- list->marker=list->head->next;
- dlist_insert_sorted(list, data, sorter);
- }
-}
-
-/*
- * Remove end node from list.
- * Return pointer to data in removed node.
- * Null if no nodes.
- */
-
-void *dlist_pop(Dlist *list)
-{
- return(_dlist_remove(list,list->head->prev,0));
-}
-
-/*
- * Remove start node from list.
- * Return pointer to data in removed node.
- * Null if no nodes.
- */
-
-void *dlist_shift(Dlist *list)
-{
- return(_dlist_remove(list,list->head->next,1));
-}
-
-
-/*
- * destroy the list freeing all memory
- */
-
-
-void dlist_destroy(Dlist *list)
-{
- if(list !=NULL)
- {
- dlist_start(list);
- dlist_next(list);
- while (dlist_mark(list)) {
- dlist_delete(list,1);
- }
- free(list);
- }
-}
-
-/**
- * Return void pointer to list_data element matching comp function criteria
- * else null
- * Does not move the marker.
- */
-
-void *dlist_find_custom(struct dlist *list, void *target, int (*comp)(void *, void *))
-{
- /* test the comp function on each node */
- struct dl_node *nodepointer;
- dlist_for_each_nomark(list,nodepointer)
- if(comp(target,nodepointer->data))
- return(nodepointer->data);
- return(NULL);
-}
-
-/**
- * Apply the node_operation function to each data node in the list
- */
-void dlist_transform(struct dlist *list, void (*node_operation)(void *))
-{
- struct dl_node *nodepointer;
- dlist_for_each_nomark(list,nodepointer)
- node_operation(nodepointer->data);
-}
-
-/**
- * insert new into list in sorted order
- * sorter function in form int sorter(new,ith)
- * must return 1 for when new should go before ith
- * else 0
- * return pointer to inserted node
- * NOTE: assumes list is already sorted
- */
-void *dlist_insert_sorted(struct dlist *list, void *new, int (*sorter)(void *, void *))
-{
- for(dlist_start(list),dlist_next(list); \
- list->marker!=list->head && !sorter(new,list->marker->data);dlist_next(list));
- return(dlist_insert_before(list,new));
-}
-
-/*
- * NOTE: internal use only
- */
-int _dlist_merge(struct dlist *listsource, struct dlist *listdest, unsigned int passcount, int (*compare)(void *, void *))
-{
-
- struct dl_node *l1head;
- struct dl_node *l2head;
- struct dl_node *target;
- unsigned int l1count=0;
- unsigned int l2count=0;
- unsigned int mergecount=0;
- while(listsource->count>0)
- {
- l1head=listsource->head->next;
- l2head=l1head;
- while((l1count<passcount)&&(l2head!=listsource->head))
- {
- l2head=l2head->next;
- l1count++;
- }
- // so now we have two lists to merge
-
- if(l2head==listsource->head)
- {// l2count
- l2count=0;
- }
- else
- {
- l2count=passcount;
- }
- while(l1count>0 || l2count>0)
- {
- mergecount++;
- if((l2count>0)&&(l1count>0))
- {
- // we have things to merge
- int result=compare(l1head->data,l2head->data);
- if(result>0)
- {
- // move from l2
- target=l2head;
- l2head=l2head->next;
- dlist_move(listsource,listdest,target,1);
- l2count--;
- if(l2head==listsource->head)
- l2count=0;
- }
- else
- {
- // move from l1
- target=l1head;
- l1head=l1head->next;
- dlist_move(listsource,listdest,target,1);
- l1count--;
- }
- }
- else if(l1count>0)
- {
- // only have l1 to work with
- while(l1count>0)
- {
- target=l1head;
- l1head=l1head->next;
- dlist_move(listsource,listdest,target,1);
- l1count--;
- }
- }
- else if(l2count>0)
- {
- // only have l2 to work with
- while(l2count>0)
- {
- if(l2head==listsource->head)
- {
- l2count=0;
- }
- else
- {
- target=l2head;
- l2head=l2head->next;
- dlist_move(listsource,listdest,target,1);
- l2count--;
- }
- }
- }
- else
- { //nothing left and this should be unreachable
- }
- }
- }
- return(mergecount);
-}
-
-/**
- * mergesort the list based on compare
- * compare function in form int sorter(void * a,void * b)
- * must return >0 for a after b
- * must return <0 for a before b
- * else 0
-
- * NOTE: mergesort changes the mark pointer
- */
-void dlist_sort_custom(struct dlist *list, int (*compare)(void *, void *))
-{
-
- struct dlist *listsource, *listdest, *swap;
- struct dlist *templist;
- unsigned int passcount = 1;
- unsigned int mergecount = 1;
-
- dlist_start(list);
- templist = dlist_new(list->data_size);
-
- // do nothing if there isn't anything to sort
- listsource = list;
- listdest = templist;
- if(listsource->count<2)
- { //nothing to do
- return;
- }
- else
- {
- while(mergecount>0)
- {
- mergecount=_dlist_merge(listsource, listdest, passcount, compare);
- if(mergecount>1)
- {
- passcount=passcount*2;
- //start new pass
- swap=listsource;
- listsource=listdest;
- listdest=swap;
- }
- }
- }
- // now put the input list pointers right
- // list pointers = newlist pointers
- // including the forward and next nodes prev and back pointers
- if(list->count==0)
- {//copy
- list->marker = listdest->marker;
- list->count = listdest->count;
- list->data_size = listdest->data_size;
- list->del_func = listdest->del_func;
- list->head->prev = listdest->head->prev;
- list->head->next = listdest->head->next;
- list->head->data = listdest->head->data;
- list->head->next->prev=list->head;
- list->head->prev->next=list->head;
- templist->head->next=NULL;
- templist->head->prev=NULL;
- templist->count=0;
- }
- else
- {// no need to copy
-
- }
-
- dlist_destroy(templist);
-}
-
-
-
-/* internal use function
- swaps elements a and b
- No sense in juggling node pointers when we can just swap the data pointers
-*/
-
-void _dlist_swap(struct dlist *list, struct dl_node *a, struct dl_node *b)
-{
-
- void *swap=a->data;
- a->data=b->data;
- b->data=swap;
-
-}
-
diff --git a/libsysfs/libsysfs.txt b/libsysfs/libsysfs.txt
deleted file mode 100644
index b877cb8030..0000000000
--- a/libsysfs/libsysfs.txt
+++ /dev/null
@@ -1,1954 +0,0 @@
-
- System Utilities sysfs Library - libsysfs
- =========================================
-
-Version: 1.2.0
-September 13, 2004
-
-Contents
---------
-1. Introduction
-2. Requirements
-3. Definitions
-4. Overview
-5. Data Structures
- 5.1 Directory and Attribute Data Structures
- 5.1.1 Attribute Structure
- 5.1.2 Link Structure
- 5.1.3 Directory Structure
- 5.2 Bus Data Structure
- 5.3 Class Data Structures
- 5.4 Root Device Data Structure
- 5.5 Device Data Structure
- 5.6 Driver Data Structure
-6. Functions
- 6.1 Calling Conventions in Libsysfs
- 6.2 Utility Functions
- 6.3 Filesystem Functions
- 6.3.1 Attribute Functions
- 6.3.2 Directory Link Functions
- 6.3.3 Directory Functions
- 6.4 Bus Functions
- 6.5 Class Functions
- 6.6 Device Functions
- 6.7 Driver Functions
-7. Dlists
- 7.1 Navigating a dlist
- 7.2 Custom sorting using dlist_sort_custom()
-8. Usage
-9. Testsuite
-10. Conclusion
-
-
-1. Introduction
----------------
-
-Libsysfs' purpose is to provide a consistent and stable interface for
-querying system device information exposed through the sysfs filesystem.
-The library implements functions for querying filesystem information,
-such as reading directories and files. It also contains routines for
-working with buses, classes, and the device tree.
-
-
-2. Requirements
----------------
-
-The library must satisfy the following requirements:
-
-- It must provide a stable programming interfaces that applications can
- be built upon.
-
-- It must provide functions to retrieve device Vital Product Data (VPD)
- information for Error Log Analysis (ELA) support. ELA will provide
- device driver and device bus address information.
-
-- It must provide access to all system devices and information exposed
- by sysfs.
-
-- It must provide a function to find sysfs' current mount point.
-
-- It must provide a function for udev to retrieve a device's major and
- minor numbers.
-
-
-3. Definitions
---------------
-
-- sysfs: Sysfs is a virtual filesystem in 2.5+ Linux kernels that
- presents a hierarchical representation of all system physical and
- virtual devices. It presents system devices by bus, by class, and
- by topology. Callbacks to device drivers are exposed as files in
- device directories. Sysfs, for all purposes, is our tree of system
- devices. For more information, please see:
-
- http://www.kernel.org/pub/linux/kernel/people/mochel/doc/
-
-- udev: Udev is Greg Kroah-Hartman's User Space implementation of devfs.
- Udev creates /dev nodes for devices upon Hotplug events. The Hotplug
- event provides udev with a sysfs directory location of the device. Udev
- must use that directory to grab device's major and minor number, which it
- will use to create the /dev node. For more information, please see:
-
- http://www.kernel.org/pub/linux/utils/kernel/hotplug/
-
- Udev provides persistent device naming based on a set of user specified
- rules. The rules a device name is based on could one or a combination of a
- number of parameters such as the bus the device is on, the serial number
- of the device (in case of USB), the vendor name (in case of SCSI) and so
- on. Udev uses Libsysfs to retrieve relevent information to appropriately
- name devices.
-
-
-4. Overview
------------
-
-Libsysfs grew from a common need. There are several applications under
-development that need access to sysfs and system devices. Udev, on a
-hotplug event, must take a sysfs device path and create a /dev node. Our
-diagnostic client needs to list all system devices. Finally, our Error
-Log Analysis piece is required to retrieve VPD information for a
-failing device. We divided to create a single library interface rather
-than having these separate applications create their own accesses to
-sysfs involving reading directories and files.
-
-Libsysfs will also provide stability for applications to be built upon. Sysfs
-currently doesn't enforce any standards for callback or file names. File
-names change depending on bus or class. Sysfs is also changing, it is
-currently being developed. Libsysfs will provide a stable interface to
-applications while allowing sysfs to change underneath it.
-
-Like sysfs, the library will provide devices to applications by bus, by
-class, and by topology. The library will function similar to directories
-and files that lie underneath it. To query a device on a PCI bus, one would
-"open" the bus to scan or read devices and "close" the bus when
-completed. Besides supplying functions to retrieve devices, the library
-will also provide some utility functions like getting sysfs mount point.
-
-A paper on Libsysfs was presented at Linux.Conf.Au 2004 (Adelaide, January
-2004). The paper is available online at:
-
-http://oss.software.ibm.com/linux/papers/libsysfs/libsysfs-linuxconfau2004.pdf
-
-
-5. Data Structures
-------------------
-
-Libsysfs will classify system devices following sysfs' example, dividing
-them by bus, class, and devices. The library presents this information
-generically. It doesn't, for example, differentiate between PCI and USB
-buses. Device attributes are presented with values as they are exposed
-by sysfs, the values are not formatted.
-
-The library will provide standard definitions for working with sysfs
-and devices, here's some examples:
-
-#define SYSFS_FSTYPE_NAME "sysfs"
-#define SYSFS_PROC_MNTS "/proc/mounts"
-#define SYSFS_BUS_NAME "bus"
-#define SYSFS_CLASS_NAME "class"
-#define SYSFS_BLOCK_NAME "block"
-#define SYSFS_DEVICES_NAME "devices"
-#define SYSFS_DRIVERS_NAME "drivers"
-#define SYSFS_NAME_ATTRIBUTE "name"
-
-The library uses some definitions to mark maximum size of a sysfs name or
-path length:
-
-#define SYSFS_PATH_MAX 255
-#define SYSFS_NAME_LEN 50
-#define SYSFS_BUS_ID_SIZE 20
-
-
-NOTE:
- a. As of release 0.4.0 of sysfsutils, a number of changes have been
- made so that the dlists and "directory" references in all libsysfs's
- structures are not populated until such time that it is absolutely
- necessary. Hence, these elements may not contain valid data at all
- times (as was the case before).
- b. As of release 1.0.0 of sysfsutils, all dlists in the library are
- sorted in alphabetical order. It is now a requirement that the
- "name" and "path" be the first two elements of all libsysfs
- structures.
-
-
-5.1 Directory and Attribute Data Structures
--------------------------------------------
-
-The library implements structures to represent sysfs directories, links,
-and files.
-
-
-5.1.1 Attribute Structure
--------------------------
-
-A file in sysfs represents a device or driver attribute. Attributes can be
-read only, write only, or read and write. File data can be ASCII and
-binary. The library has the following structure to represent files:
-
-struct sysfs_attribute {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- char *value;
- unsigned short len; /* value length */
- unsigned short method; /* show and store */
-};
-
-Path represents the file/attribute's full path. Value is used when reading
-from or writing to an attribute. "len" is the length of data in "value".
-Method is a bitmask for defining if the attribute supports show(read)
-and/or store(write).
-
-
-5.1.2 Link Structure
---------------------
-
-Symbolic links are used in sysfs to link bus or class views with
-particular devices.
-
-struct sysfs_link {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- char target[SYSFS_PATH_MAX];
-};
-
-Link's name is stored in "name' and it's target stored in "target". Absolute
-path to the link is stored in "path".
-
-
-5.1.3 Directory Structure
--------------------------
-
-The directory structure represents a sysfs directory:
-
-struct sysfs_directory {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
-
- /* Private: for internal use only */
- struct dlist *subdirs;
- struct dlist *links;
- struct dlist *attributes;
-};
-
-The sysfs_directory structure includes the list of subdirectories, links and
-attributes. The "name" and absolute "path" are also stored in the structure.
-The sysfs_directory structure is intended for use internal to the library.
-Applications needing access to attributes and links from the directory
-will need to make appropriate calls (described below) to get the same.
-
-
-5.2 Bus Data Structure
-----------------------
-
-All buses look similar in sysfs including lists of devices and drivers,
-therefore we use the following structure to represent all sysfs buses:
-
-struct sysfs_bus {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
-
- /* Private: for internal use only */
- struct dlist *drivers;
- struct dlist *devices;
- struct sysfs_directory *directory;
-};
-
-The sysfs_bus structure contains the bus "name", while the "path" to bus
-directory is also stored. It also contains lists of devices on the bus
-and drivers that are registered on it. The bus' directory is represented
-by the sysfs_directory structure and it contains references to all the
-subdirectories, links, and attributes. The sysfs_directory structure
-is for internal use only. The following functions may be used by
-applications to retrieve data from the sysfs_directory structure:
-
-struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus)
-struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus,
- char *attrname)
-
-
-5.3 Class Data Structures
--------------------------
-
-The library uses two data structures to represent classes in sysfs. Sysfs
-classes contains a class directory like "net" or "scsi_host" and then
-class devices like "eth0", "lo", or "eth1" for the "net" class.
-
-struct sysfs_class {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
-
- /* Private: for internal use only */
- struct dlist *devices;
- struct sysfs_directory *directory;
-};
-
-The sysfs_class represents device classes in sysfs like "net". It contains
-the class "name", "path" to the class, a list of class devices and the
-directory representation (for internal use only).
-
-struct sysfs_class_device {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- char classname[SYSFS_NAME_LEN];
-
- /* Private: for internal use only */
- struct sysfs_class_device *parent;
- struct sysfs_device *sysdevice; /* NULL if virtual */
- struct sysfs_driver *driver; /* NULL if not implemented */
- struct sysfs_directory *directory;
-};
-
-A class device isn't the same as a sysfs_device, it's specific to the class in
-which it belongs. The class device structure contains the name of the class
-the class device belongs to, its sysfs_device reference and that device's
-driver reference (if any). It also contains the name of the class device
-- like "eth0", its parent point (if present) and its sysfs directory
-information including links and attributes (for internal use only).
-The following function may be used by applications to retrieve data
-from the sysfs_directory structure:
-
-struct dlist *sysfs_get_classdev_attributes(struct sysfs_class_device *cdev);
-
-
-5.4 Root Device Data Structure
-------------------------------
-
-Device hierarchies in sysfs are represented under the /sys/devices directory
-structure. Sysfs devices typically spawn off from base devices which are
-represented by a sysfs_root_device.
-
-struct sysfs_root_device {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
-
- /* Private: for internal use only */
- struct dlist *devices;
- struct sysfs_directory *directory;
-};
-
-The sysfs_root_device structure contains a list of "devices" that spawn off it.
-The name of the root device as represented under /sys/devices is read into
-"name" and the absolute path into "path" and its sysfs_directory information
-intended to be used internal to the library.
-
-
-5.5 Device Data Structure
--------------------------
-
-The sysfs_device structure represents a system device that's exposed
-in sysfs under the /sys/devices directory structure.
-
-struct sysfs_device {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- char bus_id[SYSFS_NAME_LEN];
- char bus[SYSFS_NAME_LEN];
- char driver_name[SYSFS_NAME_LEN];
-
- /* Private: for internal use only */
- struct sysfs_device *parent;
- struct dlist *children;
- struct sysfs_directory *directory;
-};
-
-The sysfs_device structure contains a "parent" pointer, a list of child
-devices, if any, device's directory, its bus id - which is the name of
-device's directory, the bus name on which this device is registered and
-its driver name. The device structure also contains the absolute path
-to the device and a directory structure, which contains a list of the
-device's attributes (for internal use only). The following functions
-may be used to obtain information from sysfs_directory structure:
-
-struct sysfs_attribute *sysfs_get_device_attribute(struct sysfs_device *dev,
- const char *name)
-struct dlist *sysfs_get_device_attributes(struct sysfs_device *device)
-
-
-5.6 Driver Data Structure
--------------------------
-
-The sysfs_driver structure represents a device driver.
-
-struct sysfs_driver {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
-
- /* Private: for internal use only */
- struct dlist *devices;
- struct sysfs_directory *directory;
-};
-
-The sysfs_driver structure contains a list of devices that use this driver,
-the name of the driver, its path, and its directory information, which
-includes the driver's attributes (for internal use only). The following
-function may be used to retrieve driver attribute information from the
-sysfs_directory structure:
-
-struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver)
-
-
-6. Functions
-------------
-
-Libsysfs will provide functions to access system devices by bus, by class,
-and by device. Functions will act like accessing directories and files,
-using "open" and "close". Open returns a structure and close is used
-to clean that structure up.
-
-
-6.1 Calling Conventions in Libsysfs
------------------------------------
-
-Libsysfs uses a simple API calling convention. APIs are classified to be
-one of "open", "get", "close" types. The convention is as follows:
-
- a. All "open" APIs have a corresponding "close" API.
- b. References obtained using "get" calls should not be closed
- explicitly.
- c. All "opened" references have to be closed with a call to
- their corresponding "close" call. This takes care of
- freeing structure references obtained with "get" calls.
-
-
-6.2 Utility Functions
----------------------
-
-The library will provide a few utility functions for working with sysfs.
-
--------------------------------------------------------------------------------
-Name: sysfs_get_mnt_path
-
-Description: Function finds the mount path for filesystem type "sysfs".
-
-Arguments: char *mnt_path Mount path buffer
- size_t len Size of mount path buffer
-
-Returns: Zero with success.
- -1 with error. Errno will be set with error:
- - EINVAL for invalid argument, if buffer is NULL or
- if len is zero
-
-Prototype: sysfs_get_mnt_path(char *mnt_path, size_t len);
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_name_from_path
-
-Description: Function returns the last directory or file name from the
- included path.
-
-Arguments: const char *path Path to parse name from
- char *name Buffer to put parsed name into
- size_t *len Size of name buffer
-
-Returns: 0 with success.
- -1 on Error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_get_name_from_path(const char *path,
- char *name, size_t *len)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_link
-
-Description: Sysfs readlink function, reads the link at supplied path
- and returns its target path.
-
-Arguments: const char *path Link's path
- char *target Buffer to place link's target
- size_t len Size of target buffer
-
-Returns: 0 with success
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_get_link(const char *path, char *target, size_t len)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_subsystem_list
-
-Description: Function returns the list of entries for the given subsystem. If
- the argument is "bus", this function will return a list of buses
- ("pci", "scsi", etc) supported on the system.
-
- sysfs_close_list() has to be called to free the list obtained
- from this call.
-
-Arguments: char *name Subsystem to open, like "bus"..
-
-Returns: dlist of entries for the subsystem on success
- NULL with error indicating the "name" subsystem is invalid.
-
-Prototype: struct dlist *sysfs_open_subsystem_list(char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_bus_devices_list
-
-Description: Function returns the list of devices on the given bus.
-
- sysfs_close_list() has to be called to free the list obtained
- from this call.
-
-Arguments: char *name Bus name to open "pci"/"scsi"/"usb"..
-
-Returns: dlist of device names for the given bus on success
- NULL with error indicating the bus is not supported.
-
-Prototype: struct dlist *sysfs_open_bus_devices_list(char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_list
-
-Description: Closes a given dlist. This can be used as a generic list close
- routine.
-
-Arguments: struct dlist *list List to be closed
-
-Prototype: void sysfs_close_list(struct dlist *list)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_path_is_dir
-
-Description: Utility function to verify if a given path is to a directory.
-
-Arguments: const char *path Path to verify
-
-Returns: 0 on success, 1 on error
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_path_is_dir(const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_path_is_file
-
-Description: Utility function to verify if a given path is to a file.
-
-Arguments: const char *path Path to verify
-
-Returns: 0 on success, 1 on error
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_path_is_file(const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_path_is_link
-
-Description: Utility function to verify if a given path is to a link.
-
-Arguments: const char *path Path to verify
-
-Returns: 0 on success, 1 on error
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_path_is_link(const char *path)
--------------------------------------------------------------------------------
-
-
-6.3 Filesystem Functions
-------------------------
-
-Libsysfs provides a set of functions to open, read, and close directories
-and attributes/files in sysfs. These functions mirror their filesystem
-function counterparts.
-
-
-6.3.1 Attribute Functions
--------------------------
-
-Along with the usual open, read, and close functions, libsysfs provides
-a couple other functions for accessing attribute values.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_attribute
-
-Description: Opens up a file in sysfs and creates a sysfs_attribute
- structure. File isn't read with this function.
-
-Arguments: const char *path File/Attribute's path
-
-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_open_attribute(const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_attribute
-
-Description: Cleans up and closes sysfs_attribute structure.
-
-Arguments: struct sysfs_attribute *sysattr Attribute to close
-
-Prototype: void sysfs_close_attribute(struct sysfs_attribute *sysattr)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_dir_attributes
-
-Description: Reads the given sysfs_directory to create a list of attributes.
-
-Arguments: struct sysfs_directory *sysdir sysfs_directory whose
- attributes to read
-
-Returns: struct dlist * of attributes on success
- NULL with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: struct dlist *sysfs_read_dir_attributes
- (struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_dir_attributes
-
-Description: Given a list sysfs_directory, this function refreshes the list
- of attributes for the given directory.
-
-Arguments: struct sysfs_directory *sysdir sysfs_ directory whose
- attributes list to refresh
-
-Returns: 0 with success.
- 1 with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_dir_attributes
-
-Description: Returns a list of attributes for the given sysfs_directory.
-
-Arguments: struct sysfs_directory *sysdir sysfs_directory whose
- attributes list to return
-
-Returns: struct dlist * of attributes with success
- NULL with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: struct dlist *sysfs_read_dir_attributes
- (struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_attribute
-
-Description: Reads the supplied attribute. Since the maximum transfer
- from a sysfs attribute is a pagesize, function reads in
- up to a page from the file and stores it in the "value"
- field in the attribute.
-
-Arguments: struct sysfs_attribute *sysattr Attribute to read
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_read_attribute(struct sysfs_attribute *sysattr)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_write_attribute
-
-Description: Writes to the supplied attribute. Function validates if the
- given attribute is writable, and writes the new value to the
- attribute. Value to write as well as its length is user
- supplied. In case the length written is not equal to the
- length requested to be written, the original value is
- restored and an error is returned.
-
-Arguments: struct sysfs_attribute *sysattr Attribute to write to
- const char *new_value sysattr's new value
- size_t len Length of "new_value"
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_write_attribute(struct sysfs_attribute *sysattr,
- const char *new_value, size_t len)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_attribute_value
-
-Description: Given a path to a specific attribute, function reads and
- returns its value to the supplied value buffer.
-
-Arguments: const char *attrpath Attribute path to read
- char *value Buffer to read in attribute's value
- size_t vsize Size of buffer
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_read_attribute_value(const char *attrpath,
- char *value, size_t vsize)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_value_from_attributes
-
-Description: Function takes a single or linked list of sysfs attribute
- structures and returns the value of the specified attribute
- name.
-
-Arguments: struct dlist *attr Attribute list to search through
- const char *name Name of attribute whose value
- to retrieve
-
-Returns: char * attribute value with success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: char *sysfs_get_value_from_attributes
- (struct sysfs_attribute *attr, const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_directory_attribute
-
-Description: Function walks the list of attributes for the given sysfs
- directory and returns the sysfs_attribute structure for
- the specified attribute name.
-
-Arguments: struct sysfs_directory *dir Directory in which to search
- char *attrname Attribute name to look for
-
-Returns: struct sysfs_attribute on success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_attribute *sysfs_get_directory_attribute
- (struct sysfs_directory *dir, char *attrname)
--------------------------------------------------------------------------------
-
-
-6.3.2 Link Functions
---------------------
-
-Sysfs contains many symbolic links, like bus links to bus devices. Libsysfs
-treats links differently than directories due to processing differences. A
-link in the /sys/bus/"busname"/devices/ directory indicates a device in the
-/sys/devices directory. Through links we give the functionality to know
-what is and what isn't a link and the ability to query the links target.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_link
-
-Description: Opens a directory link.
-
-Arguments: const char *linkpath Path to link
-
-Returns: struct sysfs_link * with success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_link *sysfs_open_link(const char *linkpath)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_link
-
-Description: Closes a directory link structure.
-
-Arguments: struct sysfs_link *ln Link to close
-
-Prototype: void sysfs_close_link(struct sysfs_link *ln)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_dir_links
-
-Description: Reads the given sysfs_directory to create a list of links.
-
-Arguments: struct sysfs_directory *sysdir sysfs_directory whose
- links to read
-
-Returns: struct dlist * of links with success
- NULL with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: struct dlist *sysfs_read_dir_links
- (struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_dir_links
-
-Description: Returns a list of links for the given sysfs_directory.
-
-Arguments: struct sysfs_directory *sysdir sysfs_directory whose
- list of links to return
-
-Returns: struct dlist * of links with success
- NULL with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: struct dlist *sysfs_read_dir_links
- (struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_directory_link
-
-Description: Function walks the list of links for the given sysfs directory
- and returns the sysfs_link structure for the specified link
- name.
-
-Arguments: struct sysfs_directory *dir Directory in which to search
- char *linkname Link name to look for
-
-Returns: struct sysfs_link * with success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_link *sysfs_get_directory_link
- (struct sysfs_directory *dir, char *linkname)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_subdirectory_link
-
-Description: Function walks the list of links for the given sysfs directory
- and its subdirectories returns the sysfs_link structure for
- the specified link name.
-
-Arguments: struct sysfs_directory *dir Directory in which to search
- char *linkname Link name to look for
-
-Returns: struct sysfs_link * with success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_link *sysfs_get_subdirectory_link
- (struct sysfs_directory *dir, char *linkname)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_dir_links
-
-Description: Given a list sysfs_directory, this function refreshes the list
- of links under the given directory.
-
-Arguments: struct sysfs_directory *sysdir sysfs_ directory whose
- links list to refresh
-
-Returns: 0 with success.
- 1 with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: int sysfs_refresh_dir_links(struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
-
-6.3.3 Directory Functions
--------------------------
-
-Sysfs directories can represent every directory under sysfs. The structures
-keep track of subdirectories, links, and files. Like opendir, readdir, and
-closedir, libsysfs provides open, read, and close functions for working with
-sysfs directories. Open creates the sysfs_directory structure. Read reads in
-its contents - like subdirectories, links, and files. Close cleans it all
-up.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_directory
-
-Description: Opens a sysfs directory at a specific path
-
-Arguments: const char *path Directory path to open
-
-Returns: struct sysfs_directory * with success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_directory *sysfs_open_directory(const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_directory
-
-Description: Closes specific directory, its subdirectories, links, and
- files.
-
-Arguments: struct sysfs_directory *sysdir Directory to close
-
-Prototype: void sysfs_close_directory(struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_dir_subdirs
-
-Description: Reads the given sysfs_directory to create a list of subdirs.
-
-Arguments: struct sysfs_directory *sysdir sysfs_directory whose
- subdirs have to be read
-
-Returns: struct dlist * of links with success
- NULL with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: struct dlist *sysfs_read_dir_subdirs
- (struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_directory
-
-Description: Read the supplied directory. Reading fills in the directory's
- contents like subdirectories, links, and attributes.
-
-Arguments: struct sysfs_directory *sysdir Directory to read
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_read_directory(struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_read_all_subdirs
-
-Description: Reads all subdirs under a given supplied directory.
-
-Arguments: struct sysfs_directory *sysdir Directory to read
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_read_all_subdirs(struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_subdirectory
-
-Description: Function walks the directory tree for the given directory and
- returns a sysfs_directory structure for the specified directory
- name.
-
-Arguments: struct sysfs_directory *dir Directory in which to search
- char *subname Name of directory to look for
-
-Returns: struct sysfs_directory with success.
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_directory *sysfs_get_subdirectory
- (struct sysfs_directory *dir, char *subname)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_dir_subdirs
-
-Description: Returns a list of subdirs for the given sysfs_directory.
-
-Arguments: struct sysfs_directory *sysdir sysfs_directory whose
- subdirectories list to return
-
-Returns: struct dlist * of directories with success
- NULL with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: struct dlist *sysfs_read_dir_subdirs
- (struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_dir_subdirs
-
-Description: Given a list sysfs_directory, this function refreshes the list
- of subdirectories under the given directory.
-
-Arguments: struct sysfs_directory *sysdir sysfs_ directory whose
- subdirs list to refresh
-
-Returns: 0 with success.
- 1 with error. Errno will be set on error, returning EINVAL
- for invalid arguments
-
-Prototype: int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir)
--------------------------------------------------------------------------------
-
-
-6.4 Bus Functions
------------------
-
-The library provides a functions for viewing buses represented in sysfs.
-The sysfs_open_bus opens a bus in the /sys/bus directory, such as "pci",
-"usb", or "scsi". The open command returns a sysfs_bus structure that
-contains a list of the bus' devices. The sysfs_close_bus function is
-used to clean up the bus structure. Given a device or a driver,
-functions are provided to determine what bus they are on.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_bus
-
-Description: Function opens up one of the buses represented in sysfs in
- the /sys/bus directory. It returns a sysfs_bus structure
- that includes a list of bus devices and drivers.
-
-Arguments: const char *name Bus name to open, like "pci"...
-
-Returns: struct sysfs_bus * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_bus *sysfs_open_bus(const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_bus
-
-Description: Function closes up the sysfs_bus structure including its
- devices, drivers, and directory.
-
-Arguments: sysfs_bus *bus Bus structure to close
-
-Prototype: void sysfs_close_bus(struct sysfs_bus *bus)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_bus_devices
-
-Description: Function returns a list of devices that are registered with
- this bus.
-
-Arguments: struct sysfs_bus *bus Bus whose devices list to return
-
-Returns: struct dlist * of sysfs_devices on success
- NULL with error. Errno will be sent with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_bus_drivers
-
-Description: Function returns a list of drivers that are registered with
- this bus.
-
-Arguments: struct sysfs_bus *bus Bus whose drivers list to return
-
-Returns: struct dlist * of sysfs_drivers on success
- NULL with error. Errno will be sent with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_bus_device
-
-Description: Function takes a sysfs_bus structure(obtained on a successful
- return from a sysfs_open_bus() call) and looks for the given
- device on this bus. On success, it returns a sysfs_device
- structure corresponding to the device.
-
-Arguments: struct sysfs_bus *bus Bus structure on which to search
- char *id Device to look for
-
-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_get_bus_device
- (struct sysfs_bus *bus, char *id)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_bus_driver
-
-Description: Function takes a sysfs_bus structure (obtained on a successful
- return from a sysfs_open_bus() call) and looks for the given
- driver on this bus. On success, it returns a sysfs_driver
- structure corresponding to the driver.
-
-Arguments: struct sysfs_bus *bus Bus structure on which to search
- char *drvname Driver to look for
-
-Returns: struct sysfs_driver * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_device *sysfs_get_bus_driver
- (struct sysfs_bus *bus, char *drvname)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_bus_attributes
-
-Description: Function takes a sysfs_bus structure and returns a list of
- attributes for the bus.
-
-Arguments: struct sysfs_bus *bus Bus 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_bus_attributes(struct sysfs_bus *bus)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_bus_attribute
-
-Description: Function takes a sysfs_bus structure and looks for the required
- attribute on the bus. On success, it returns a sysfs_attribute
- structure corresponding to the given attribute.
-
-Arguments: struct sysfs_bus *bus Bus structure on which to search
- char *attrname Attribute to look for
-
-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_bus_attribute
- (struct sysfs_bus *bus, char *attrname)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_bus_attributes
-
-Description: Function refreshes the list of attributes for a given sysfs_bus
-
-Arguments: struct sysfs_bus *bus Bus whose attributes list to refresh
-
-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_bus_attributes(struct sysfs_bus *bus)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_find_driver_bus
-
-Description: Given the name of a driver, this function finds the name of the
- bus the driver is on
-
-Arguments: const char *driver Name of the driver to look for
- char *busname Buffer to return the bus name
- size_t bsize Size of the "busname" buffer
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_find_driver_bus(const char *driver,
- char *busname, size_t bsize)
--------------------------------------------------------------------------------
-
-
-6.5 Class Functions
--------------------
-
-Libsysfs provides functions to open sysfs classes and their class devices.
-These functions too operate with open and close, close must be called to
-clean up the class structures. Given a class device name, functions are
-provided to determine what class they belong to. Once a class device
-name and the class it belongs to is known, a function to open the
-class device is provided. This method can be used when details of
-a single class device is required.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_class
-
-Description: Function opens up one of the classes represented in sysfs in
- the /sys/class directory. It returns a sysfs_class structure
- that includes a list of class devices.
-
-Arguments: const char *name Class name to open, like "net"..
-
-Returns: struct sysfs_class * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_class *sysfs_open_class(const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_class
-
-Description: Function closes up the sysfs_class structure including its
- class devices.
-
-Arguments: sysfs_class *cls Class structure to close
-
-Prototype: void sysfs_close_class(struct sysfs_class *cls);
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_class_device_path
-
-Description: Function opens up one of the class devices represented in
- sysfs in sysfs/class/"class"/ directory. It returns a
- sysfs_class_device structure.
-
-Arguments: const char *path Path to class device
-
-Returns: struct sysfs_class_device * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_class_device *sysfs_open_class_device_path
- (const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_class_device
-
-Description: Function closes up the sysfs_class_device structure.
-
-Arguments: sysfs_class_device *dev Class device structure to close
-
-Prototype: void sysfs_close_class_device(struct sysfs_class_device *dev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_class_device
-
-Description: Function takes a sysfs_class structure(obtained on a successful
- return from a sysfs_open_class() call) and looks for the given
- device in this class. On success, it returns a sysfs_class_device
- structure corresponding to the class device.
-
-Arguments: struct sysfs_class *cls Class on which to search
- char *name Class device "name" to look for
-
-Returns: struct sysfs_class_device * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_class_device *sysfs_get_class_device
- (struct sysfs_class *cls, char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_class_devices
-
-Description: Function returns a list of class devices for the given class.
-
-Arguments: struct sysfs_class *cls Class whose class device list
- is required
-
-Returns: struct dlist * of sysfs_class_devices on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_class_devices(struct sysfs_class *cls)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_class_device
-
-Description: Given the name of the class on which to look for, this function
- locates a given class device and returns a sysfs_class_device
- structure corresponding to the requested class device.
-
- NOTE:
- 1. The sysfs_class_device structure obtained upon successful
- return from this function has to be closed by calling
- sysfs_close_class_device().
- 2. Class this device belongs to must be known prior to calling
- this function.
-
-Arguments: const char *classname Class on which to search
- char *name Class device "name" to open
-
-Returns: struct sysfs_class_device * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_class_device *sysfs_open_class_device
- (const char *classname, char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_classdev_device
-
-Description: Function returns the sysfs_device reference (if present) for the
- given class device.
-
-Arguments: struct sysfs_class_device *clsdev Class device whose
- sysfs_device reference
- is required
-
-Returns: struct sysfs_device * on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_device *sysfs_get_classdev_device
- (struct sysfs_class_device *clsdev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_classdev_driver
-
-Description: Function returns the sysfs_driver reference (if present) for
- the given class device.
-
-Arguments: struct sysfs_class_device *clsdev Class device whose
- sysfs_driver reference
- is required
-
-Returns: struct sysfs_driver * on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_driver *sysfs_get_classdev_driver
- (struct sysfs_class_device *clsdev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_classdev_parent
-
-Description: Function returns the sysfs_class_device reference for the
- parent (if present) of the given class device.
-
-Arguments: struct sysfs_class_device *clsdev Class device whose
- parent reference
- is required
-
-Returns: struct sysfs_class_device * on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_class_device *sysfs_get_classdev_parent
- (struct sysfs_class_device *clsdev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_classdev_attributes
-
-Description: Function takes a sysfs_class_device structure and returns a
- list of attributes for the class device.
-
-Arguments: struct sysfs_class_device *cdev Class 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_classdev_attributes
- (struct sysfs_class_device *cdev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_classdev_attr
-
-Description: Searches supplied class device's attributes by name and returns
- the attribute.
-
-Arguments: struct sysfs_class_device *clsdev Device to search
- const 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_classdev_attr
- (struct sysfs_class_device *clsdev, const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_classdev_attributes
-
-Description: Function refreshes the list of attributes for a given
- sysfs_class_device.
-
-Arguments: struct sysfs_class_device *cdev Class device whose attributes
- list to refresh
-
-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_classdev_attributes
- (struct sysfs_class_device *cdev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_classdev_attr
-
-Description: Function takes as arguments, a the name of the class, the class
- device name and the name of the required attribute.
-
- NOTE:
- 1. The struct sysfs_attribute * obtained upon successful
- return from this function has to be closed by making
- a call to sysfs_close_attribute()
-
-Arguments: char *classname Class name on which to search
- char *dev Name of the class device
- char *attrib Attribute to open
-
-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_write_classdev_attr
- (const char *classname, const char *dev,
- const char *attrib)
--------------------------------------------------------------------------------
-
-
-6.6 Device Functions
---------------------
-
-Devices represent everything in sysfs under /sys/devices, which is a
-hierarchical view of system devices. Besides the expected open and
-close functions, libsysfs provides open and close functions for
-root devices. These functions recursively open or close a device
-and all of its children.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_device_path
-
-Description: Opens up a device at a specific path. It opens the device's
- directory, reads the directory, and returns a sysfs_device
- structure.
-
-Arguments: const char *path Path to device
-
-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_path(const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_device
-
-Description: Function closes up the sysfs_device structure.
-
-Arguments: sysfs_device *dev Device structure to close
-
-Prototype: void sysfs_close_device(struct sysfs_device *dev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_root_device
-
-Description: Function opens up one of the root devices represented in sysfs
- in the /sys/devices directory. It returns a sysfs_root_device
- structure that includes a list of devices in the tree.
-
-Arguments: const char *name Name of the root device to open
-
-Returns: struct sysfs_root_device * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_device *sysfs_open_root_device(const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_root_device
-
-Description: Function closes up the sysfs_root_device structure including the
- devices in the root device tree.
-
-Arguments: sysfs_device *root Root device structure to close
-
-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 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 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
- (if present) of the given sysfs_device.
-
-Arguments: struct sysfs_device *dev sysfs_device whose parent
- reference is required
-
-Returns: struct sysfs_device * on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_device *sysfs_get_device_parent
- (struct sysfs_device *dev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_root_devices
-
-Description: Function returns a list of devices under the given root device.
-
-Arguments: struct sysfs_root_device *root sysfs_root_device whose devices
- list is required
-
-Returns: struct dlist * of sysfs_devices on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_root_devices
- (struct sysfs_root_device *root)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_device_attr
-
-Description: Searches supplied device's attributes by name and returns
- the attribute.
-
-Arguments: struct sysfs_device *dev Device to search
- const 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_device_attr
- (struct sysfs_device *dev, const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_device_attributes
-
-Description: Function takes a sysfs_device structure and returns a list
- of attributes for the device.
-
-Arguments: struct sysfs_device *device 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_device_attributes
- (struct sysfs_device *device)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_device_attributes
-
-Description: Function refreshes the list of attributes for a given
- sysfs_device.
-
-Arguments: struct sysfs_device *device Device whose attributes list
- to refresh
-
-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_refresh_device_attributes
- (struct sysfs_device *device)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_device
-
-Description: Given the name of the bus on which to look for, this function
- locates a given device and returns a sysfs_device structure
- corresponding to the requested device.
-
-Arguments: const char *bus Bus on which to search
- const char *bus_id Device to look for
-
-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
- (const char *bus, const char *bus_id)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_device_bus
-
-Description: Given a sysfs_device, this function fills in the bus this
- device is on in the sysfs_device->bus field.
-
-Arguments: struct sysfs_device *dev Device whose bus name to find
-
-Returns: 0 with success.
- -1 with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: int sysfs_get_device_bus(struct sysfs_device *dev)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_device_attr
-
-Description: Function takes as arguments, the bus on which to search for a
- device, and an attribute of the device to open.
-
- NOTE:
- 1. The struct sysfs_attribute * obtained upon successful
- return from this function has to be closed by making
- a call to sysfs_close_attribute()
-
-Arguments: char *bus Bus on which to search
- char *bus_id Device to look for
- char *attrib Name of the attribute to open
-
-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_open_device_attr
- (const char *bus, const char *bus_id, const char *attrib)
--------------------------------------------------------------------------------
-
-
-6.7 Driver Functions
---------------------
-
-Drivers are represented in sysfs under the /sys/bus/xxx/drivers (xxx being
-the bus type, such as "pci", "usb, and so on). Functions are provided to
-open and close drivers.
-
--------------------------------------------------------------------------------
-Name: sysfs_open_driver_path
-
-Description: Opens driver at specific path.
-
-Arguments: const char *path Path to driver
-
-Returns: struct sysfs_driver * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_driver *sysfs_open_driver_path(const char *path)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_close_driver
-
-Description: Closes and cleans up sysfs_driver structure.
-
-Arguments: sysfs_driver *driver Driver structure to close
-
-Prototype: void sysfs_close_driver(struct sysfs_driver *driver)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_driver_devices
-
-Description: Function returns a list of devices that use this driver.
-
-Arguments: struct sysfs_driver *driver Driver whose devices list is
- required
-
-Returns: struct dlist * of sysfs_devices on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_driver_devices
- (struct sysfs_driver *driver)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_driver_devices
-
-Description: Function refreshes the list of devices that use this driver.
-
-Arguments: struct sysfs_driver *driver Driver whose devices list is
- required to be refreshed
-
-Returns: struct dlist * of sysfs_devices on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_refresh_driver_devices
- (struct sysfs_driver *driver)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_driver_device
-
-Description: Function returns a sysfs_device reference for the device with
- "name" that uses this driver
-
-Arguments: struct sysfs_driver *driver Driver on which to search
- const char *name Name of the device to look for
-
-Returns: struct sysfs_device * corresponding to "name" on success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct dlist *sysfs_get_driver_device
- (struct sysfs_driver *driver, const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_driver_attr
-
-Description: Searches supplied driver's attributes by name and returns
- the attribute.
-
-Arguments: struct sysfs_driver *drv Driver to search
- const 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_driver_attr
- (struct sysfs_driver *drv, const char *name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_driver_attributes
-
-Description: Function takes a sysfs_driver structure and returns a list
- of attributes for the driver.
-
-Arguments: struct sysfs_driver *driver Driver 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_driver_attributes
- (struct sysfs_driver *driver)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_refresh_driver_attributes
-
-Description: Function refreshes the list of attributes for a given
- sysfs_driver.
-
-Arguments: struct sysfs_driver *driver Driver whose attributes list
- to refresh
-
-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_refresh_driver_attributes
- (struct sysfs_driver *driver)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_driver
-
-Description: Given the name of the bus on which to look for, this function
- locates a given driver and returns a sysfs_driver structure
- corresponding to the requested device.
-
- NOTE:
- 1. The sysfs_driver structure obtained upon successful return
- from this function has to be closed by calling
- sysfs_close_driver_by_name().
- 2. Bus on which to look for this driver should be known prior
- to calling this function. Use sysfs_find_driver_bus()
- to determine this.
-
-Arguments: const char *bus_name Bus on which to search
- const char *drv_name Driver name to look for
-
-Returns: struct sysfs_driver * with success
- NULL with error. Errno will be set with error, returning
- - EINVAL for invalid arguments
-
-Prototype: struct sysfs_driver *sysfs_open_driver(const char *bus_name,
- const char *drv_name)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_get_driver_links
-
-Description: Function returns a list of links for a given driver
-
-Arguments: struct sysfs_driver *driver Driver to get links from
-
-Returns: struct dlist * of links on success
- NULL with error
-
-Prototype: struct dlist *sysfs_get_driver_links
- (struct sysfs_driver *driver)
--------------------------------------------------------------------------------
-
--------------------------------------------------------------------------------
-Name: sysfs_open_driver_attr
-
-Description: Function takes as arguments, the bus the driver is registered
- on, the driver name and the name of the attribute to open.
-
- NOTE:
- 1. The struct sysfs_attribute * obtained upon successful
- return from this function has to be closed by making
- a call to sysfs_close_attribute()
-
-Arguments: char *bus Bus on which driver is present
- char *drv Driver to look for
- char *attrib Name of the attribute to open
-
-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_open_driver_attr
- (const char *bus, const char *drv, const char *attrib)
--------------------------------------------------------------------------------
-
-
-7 Dlists
---------
-
-Libsysfs uses (yet another) list implementation thanks to Eric J Bohm.
-
-
-7.1 Navigating a dlist
-----------------------
-
-Some library functions return a dlist of devices/drivers/attributes, etc.
-To navigate the list returned the macro "dlist_for_each_data" is to be used.
-
-------------------------------------------------------------------------------
-Function/Macro name: dlist_for_each_data
-
-Description: Walk the given list, returning a known data type/
- structure in each iteration.
-
-Arguments: struct dlist *list List pointer
- data_iterator Data type/structure variable
- contained in the list
- datatype Data type/structure contained
- in the list
-
-Returns: On each iteration, "data_iterator" will contain a list
- element of "datatype"
-
-Usage example: The function sysfs_get_classdev_attributes() returns a
- dlist of attributes. To navigate the list:
-
- struct sysfs_attribute *attr = NULL;
- struct dlist *attrlist = NULL;
- .
- .
- .
- attrlist = sysfs_get_classdev_attributes
- (struct sysfs_class_device *cdev)
- if (attrlist != NULL) {
- dlist_for_each_data(attrlist, attr,
- struct sysfs_attribute) {
- .
- .
- .
- }
- }
--------------------------------------------------------------------------------
-
-
-7.2 Custom sorting using dlist_sort_custom()
---------------------------------------------
-
-As of release 1.2.0, libsysfs provides a new interface for custom sorting
-of dlists. The API dlist_sort_custom() has been added for this purpose.
-Applications that would like to define their own sorter function can now
-make use of this API.
-
-The sorter function must conform to the following prototype:
-
- int compare(void *a, void*b)
-
-dlist_sort_custom() expects that the compare function will:
- return >0 for a before b
- return <0 for b before a
- return 0 for a == b
-
-
-8. Usage
---------
-
-Accessing devices through libsysfs is supposed to mirror accessing devices
-in the filesystem it represents. Here's a typical order of operation:
-
- - get sysfs mount point
- - "open" sysfs category, ie. bus, class, or device
- - work with category
- - "close" sysfs category
-
-
-9. Testsuite
-------------
-
-Version 1.0.0 of sysfsutils ships with a comprehensive testsuite. The testsuite
-shipped as part of the "test" directory of the sysfsutils source package,
-results in an executable "testlibsysfs" which will be installed in the
-/usr/local/bin directory. Some of the salient features of the testsuite are:
-
-a. Tests _every_ API exported by the library.
-b. Tests are performed for all possible combinations of input parameters.
-c. Detailed output is provided for the correct case.
-d. Facility to redirect output of the tests to a normal file.
-e. Number of iterations of tests can be specified.
-
-The testsuite comes with its own configuration file "libsysfs.conf" in the
-"test" directory. This file is used to generate a header file at the time
-the tests are built.
-
-To use the testsuite:
-
-a. Modify the variables libsysfs.conf file to appropriate values for your
- system. (The libsysfs.conf file contains comments describing what each
- variable stands for and, in some cases, how to determine an appropriate
- value for the system under test).
-
-b. Build and install the testsuite.
-
-c. Run the testsuite:
-
- testlibsysfs <number of iterations> <logfile>
-
-The default logfile is stdout.
-
-NOTE: If the libsysfs.conf file is changed, make sure to run "make clean" in
-the test directory and then a "make" for the changes to take effect.
-
-
-10. Conclusion
---------------
-
-Libsysfs is meant to provide a stable application programming interface to
-sysfs. Applications can depend upon the library to access system devices
-and functions exposed through sysfs.
diff --git a/libsysfs/sysfs.h b/libsysfs/sysfs.h
deleted file mode 100644
index 2add8227a4..0000000000
--- a/libsysfs/sysfs.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * sysfs.h
- *
- * Internal Header Definitions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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
- *
- */
-#ifndef _SYSFS_H_
-#define _SYSFS_H_
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1)
-#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
-
-#define safestrcpymax(to, from, max) \
-do { \
- to[max-1] = '\0'; \
- strncpy(to, from, max-1); \
-} while (0)
-
-#define safestrcatmax(to, from, max) \
-do { \
- to[max-1] = '\0'; \
- strncat(to, from, max - strlen(to)-1); \
-} while (0)
-
-extern struct sysfs_attribute *get_attribute(void *dev, const char *name);
-extern struct dlist *read_dir_subdirs(const char *path);
-extern struct dlist *read_dir_links(const char *path);
-extern struct dlist *get_attributes_list(void *dev);
-
-/* Debugging */
-#ifdef DEBUG
-#include "../logging.h"
-#define dprintf(format, arg...) dbg(format, ## arg)
-#else
-#define dprintf(format, arg...) do { } while (0)
-#endif
-
-#endif /* _SYSFS_H_ */
diff --git a/libsysfs/sysfs/dlist.h b/libsysfs/sysfs/dlist.h
deleted file mode 100644
index 335a490a0a..0000000000
--- a/libsysfs/sysfs/dlist.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * dlist.h
- *
- * Copyright (C) 2003 Eric J Bohm
- *
- * 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
- *
- */
-#ifndef _DLIST_H_
-#define _DLIST_H_
-
-/* Double linked list header.
-
-* navigate your list with DLIST_PREV and DLIST_NEXT. These are macros
-* so function call overhead is minimized.
-
-* Supports perl style push, pop, shift, unshift list semantics.
-
-* You allocate the data and give dlist the pointer. If your data is
-* complex set the dlist->del_func to a an appropriate delete using
-* dlist_new_with_delete. Your delete function must match
-(void * )(del(void *)
-*Otherwise dlist will just use free.
-
-* NOTE: The small amount of pain involved in doing that allows us to
-* avoid copy in copy out semantics.
-
-* Dlist uses an internal mark pointer to keep track of where you are
-* in the list.
-
-* insert and delete take a directional parameter. Where direction
-* corresponds to the direction in which you want the list to go.
-* true direction corresponded to progressing forward in the last
-* false to regressing in the list.
-* so a dlist_insert(yourlist,item,1) will insert it after the mark
-* so a dlist_insert(yourlist,item,0) will insert it before the mark
-* any insert will move the mark to the new node regardless of the direction.
-
-* Just use the dlist_(insert|delete)_(before|after) macros if you do not want
-* to think about it.
-
-*/
-
-#include <stddef.h>
-
-typedef struct dl_node {
- struct dl_node *prev;
- struct dl_node *next;
- void *data;
-} DL_node;
-
-typedef struct dlist {
- DL_node *marker;
- unsigned long count;
- size_t data_size;
- void (*del_func)(void *);
- DL_node headnode;
- DL_node *head;
-} Dlist;
-
-Dlist *dlist_new(size_t datasize);
-Dlist *dlist_new_with_delete(size_t datasize,void (*del_func)(void*));
-void *_dlist_mark_move(Dlist *list,int direction);
-void *dlist_mark(Dlist *);
-void dlist_start(Dlist *);
-void dlist_end(Dlist *);
-void dlist_move(struct dlist *source, struct dlist *dest, struct dl_node *target,int direction);
-void *dlist_insert(Dlist *,void *,int) ;
-
-void *dlist_insert_sorted(struct dlist *list, void *new_elem, int (*sorter)(void *, void *));
-
-void dlist_delete(Dlist *,int);
-
-void dlist_push(Dlist *,void *);
-
-void dlist_unshift(Dlist *,void *);
-void dlist_unshift_sorted(Dlist *,void *,int (*sorter)(void *, void *));
-
-void *dlist_pop(Dlist *);
-
-void *dlist_shift(Dlist *);
-
-void dlist_destroy(Dlist *);
-
-int _dlist_merge(struct dlist *listsource, struct dlist *listdest, unsigned int passcount, int (*compare)(void *, void *));
-
-void *dlist_find_custom(struct dlist *list, void *target, int (*comp)(void *, void *));
-
-void dlist_sort_custom(struct dlist *list, int (*compare)(void *, void *));
-
-
-void _dlist_swap(struct dlist *list, struct dl_node *a, struct dl_node *b);
-
-void dlist_transform(struct dlist *list, void (*node_operation)(void *));
-
-
-/*
- * _dlist_remove is for internal use only
- * _dlist_mark_move is for internal use only
- */
-void *_dlist_remove(struct dlist *,struct dl_node *,int );
-void *_dlist_insert_dlnode(struct dlist *list,struct dl_node *new_node,int direction);
-
-#define dlist_prev(A) _dlist_mark_move((A),0)
-#define dlist_next(A) _dlist_mark_move((A),1)
-
-#define dlist_insert_before(A,B) dlist_insert((A),(B),0)
-#define dlist_insert_after(A,B) dlist_insert((A),(B),1)
-
-#define dlist_delete_before(A) dlist_delete((A),0)
-#define dlist_delete_after(A) dlist_delete((A),1)
-
-/**
- * provide for loop header which iterates the mark from start to end
- * list: the dlist pointer, use dlist_mark(list) to get iterator
- */
-#define dlist_for_each(list) \
- for(dlist_start(list),dlist_next(list); \
- (list)->marker!=(list)->head;dlist_next(list))
-
-/**
- * provide for loop header which iterates the mark from end to start
- * list: the dlist pointer, use dlist_mark(list) to get iterator
- */
-#define dlist_for_each_rev(list) \
- for(dlist_end(list),dlist_prev(list); \
- (list)->marker!=(list)->head;dlist_prev(list))
-
-/**
- * provide for loop header which iterates through the list without moving mark
- * list: the dlist_pointer
- * iterator: dl_node pointer to iterate
- */
-#define dlist_for_each_nomark(list,iterator) \
- for((iterator)=(list)->head->next; (iterator)!=(list)->head; \
- (iterator)=(iterator)->next)
-
-/**
- * provide for loop header which iterates through the list without moving mark
- * in reverse
- * list: the dlist_pointer
- * iterator: dl_node pointer to iterate
- */
-#define dlist_for_each_nomark_rev(list,iterator) \
- for((iterator)=(list)->head->prev; (iterator)!=(list)->head; \
- (iterator)=(iterator)->prev)
-/**
- * provide for loop header which iterates through the list providing a
- * data iterator
- * list: the dlist pointer
- * data_iterator: the pointer of type datatype to iterate
- * datatype: actual type of the contents in the dl_node->data
- */
-
-#define dlist_for_each_data(list,data_iterator,datatype) \
- for(dlist_start(list), (data_iterator)=(datatype *) dlist_next(list); \
- (list)->marker!=(list)->head;(data_iterator)=(datatype *) dlist_next(list))
-
-/**
- * provide for loop header which iterates through the list providing a
- * data iterator in reverse
- * list: the dlist pointer
- * data_iterator: the pointer of type datatype to iterate
- * datatype: actual type of the contents in the dl_node->data
- */
-#define dlist_for_each_data_rev(list,data_iterator,datatype) \
- for(dlist_end(list), (data_iterator)=(datatype *) dlist_prev(list); \
- (list)->marker!=(list)->head;(data_iterator)=(datatype *) dlist_prev(list))
-
-/**
- * provide for loop header which iterates through the list providing a
- * data iterator without moving the mark
- * list: the dlist pointer
- * iterator: the dl_node pointer to iterate
- * data_iterator: the pointer of type datatype to iterate
- * datatype: actual type of the contents in the dl_node->data
- */
-
-#define dlist_for_each_data_nomark(list,iterator,data_iterator,datatype) \
- for((iterator)=(list)->head->next, (data_iterator)=(datatype *) (iterator)->data; \
- (iterator)!=(list)->head;(iterator)=(iterator)->next,(data_iterator)=(datatype *) (iterator))
-
-/**
- * provide for loop header which iterates through the list providing a
- * data iterator in reverse without moving the mark
- * list: the dlist pointer
- * iterator: the dl_node pointer to iterate
- * data_iterator: the pointer of type datatype to iterate
- * datatype: actual type of the contents in the dl_node->data
- */
-#define dlist_for_each_data_nomark_rev(list,iterator, data_iterator,datatype) \
- for((iterator)=(list)->head->prev, (data_iterator)=(datatype *) (iterator)->data; \
- (iterator)!=(list)->head;(iterator)=(iterator)->prev,(data_iterator)=(datatype *) (iterator))
-
-#endif /* _DLIST_H_ */
diff --git a/libsysfs/sysfs/libsysfs.h b/libsysfs/sysfs/libsysfs.h
deleted file mode 100644
index 12e7cc5f99..0000000000
--- a/libsysfs/sysfs/libsysfs.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * libsysfs.h
- *
- * Header Definitions for libsysfs
- *
- * Copyright (C) IBM Corp. 2004-2005
- *
- * 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
- *
- */
-#ifndef _LIBSYSFS_H_
-#define _LIBSYSFS_H_
-
-#include <sys/types.h>
-#include <string.h>
-#include "dlist.h"
-
-#define SYSFS_FSTYPE_NAME "sysfs"
-#define SYSFS_PROC_MNTS "/proc/mounts"
-#define SYSFS_BUS_NAME "bus"
-#define SYSFS_CLASS_NAME "class"
-#define SYSFS_BLOCK_NAME "block"
-#define SYSFS_DEVICES_NAME "devices"
-#define SYSFS_DRIVERS_NAME "drivers"
-#define SYSFS_MODULE_NAME "module"
-#define SYSFS_NAME_ATTRIBUTE "name"
-#define SYSFS_UNKNOWN "unknown"
-#define SYSFS_PATH_ENV "SYSFS_PATH"
-
-#define SYSFS_PATH_MAX 256
-#define SYSFS_NAME_LEN 64
-#define SYSFS_BUS_ID_SIZE 32
-
-/* mount path for sysfs, can be overridden by exporting SYSFS_PATH */
-#define SYSFS_MNT_PATH "/sys"
-
-enum sysfs_attribute_method {
- SYSFS_METHOD_SHOW = 0x01, /* attr can be read by user */
- SYSFS_METHOD_STORE = 0x02, /* attr can be changed by user */
-};
-
-/*
- * NOTE:
- * 1. We have the statically allocated "name" as the first element of all
- * the structures. This feature is used in the "sorter" function for dlists
- * 2. As is the case with attrlist
- * 3. As is the case with path
- */
-struct sysfs_attribute {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- char *value;
- unsigned short len; /* value length */
- enum sysfs_attribute_method method; /* show and store */
-};
-
-struct sysfs_driver {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- struct dlist *attrlist;
- char bus[SYSFS_NAME_LEN];
-
- /* Private: for internal use only */
- struct dlist *devices;
-};
-
-struct sysfs_device {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- struct dlist *attrlist;
- char bus_id[SYSFS_NAME_LEN];
- char bus[SYSFS_NAME_LEN];
- char driver_name[SYSFS_NAME_LEN];
-
- /* Private: for internal use only */
- struct sysfs_device *parent;
- /* NOTE - we still don't populate this */
- struct dlist *children;
-};
-
-/* NOTE: not used as of now */
-struct sysfs_bus {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- struct dlist *attrlist;
-
- /* Private: for internal use only */
- struct dlist *drivers;
- struct dlist *devices;
-};
-
-struct sysfs_class_device {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- struct dlist *attrlist;
- char classname[SYSFS_NAME_LEN];
-
- /* Private: for internal use only */
- struct sysfs_class_device *parent;
- struct sysfs_device *sysdevice; /* NULL if virtual */
-};
-
-/* NOTE: not used as of now */
-struct sysfs_class {
- char name[SYSFS_NAME_LEN];
- char path[SYSFS_PATH_MAX];
- struct dlist *attrlist;
-
- /* Private: for internal use only */
- struct dlist *devices;
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Function Prototypes
- */
-extern int sysfs_get_mnt_path(char *mnt_path, size_t len);
-extern int sysfs_remove_trailing_slash(char *path);
-extern int sysfs_get_name_from_path(const char *path, char *name, size_t len);
-extern int sysfs_path_is_dir(const char *path);
-extern int sysfs_path_is_link(const char *path);
-extern int sysfs_path_is_file(const char *path);
-extern int sysfs_get_link(const char *path, char *target, size_t len);
-extern struct dlist *sysfs_open_directory_list(const char *path);
-extern void sysfs_close_list(struct dlist *list);
-
-/* sysfs directory and file access */
-extern void sysfs_close_attribute(struct sysfs_attribute *sysattr);
-extern struct sysfs_attribute *sysfs_open_attribute(const char *path);
-extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
-extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,
- const char *new_value, size_t len);
-
-/* sysfs driver access */
-extern void sysfs_close_driver(struct sysfs_driver *driver);
-extern struct sysfs_driver *sysfs_open_driver
- (const char *bus_name, const char *drv_name);
-extern struct sysfs_driver *sysfs_open_driver_path(const char *path);
-extern struct sysfs_attribute *sysfs_get_driver_attr
- (struct sysfs_driver *drv, const char *name);
-extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver);
-extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver);
-
-/* generic sysfs device access */
-extern void sysfs_close_device_tree(struct sysfs_device *device);
-extern struct sysfs_device *sysfs_open_device_tree(const char *path);
-extern void sysfs_close_device(struct sysfs_device *dev);
-extern struct sysfs_device *sysfs_open_device
- (const char *bus, const char *bus_id);
-extern struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev);
-extern struct sysfs_device *sysfs_open_device_path(const char *path);
-extern int sysfs_get_device_bus(struct sysfs_device *dev);
-extern struct sysfs_attribute *sysfs_get_device_attr
- (struct sysfs_device *dev, const char *name);
-extern struct dlist *sysfs_get_device_attributes
- (struct sysfs_device *dev);
-
-/* generic sysfs class access */
-extern void sysfs_close_class_device(struct sysfs_class_device *dev);
-extern struct sysfs_class_device *sysfs_open_class_device_path
- (const char *path);
-extern struct sysfs_class_device *sysfs_open_class_device
- (const char *classname, const char *name);
-extern struct sysfs_class_device *sysfs_get_classdev_parent
- (struct sysfs_class_device *clsdev);
-extern struct sysfs_attribute *sysfs_get_classdev_attr
- (struct sysfs_class_device *clsdev, const char *name);
-extern struct dlist *sysfs_get_classdev_attributes
- (struct sysfs_class_device *clsdev);
-extern struct sysfs_device *sysfs_get_classdev_device
- (struct sysfs_class_device *clsdev);
-extern void sysfs_close_class(struct sysfs_class *cls);
-extern struct sysfs_class *sysfs_open_class(const char *name);
-extern struct sysfs_class_device *sysfs_get_class_device
- (struct sysfs_class *cls, const char *name);
-extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls);
-
-/* generic sysfs bus access */
-extern void sysfs_close_bus(struct sysfs_bus *bus);
-extern struct sysfs_bus *sysfs_open_bus(const char *name);
-extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus);
-extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus);
-extern struct sysfs_device *sysfs_get_bus_device
- (struct sysfs_bus *bus, const char *id);
-extern struct sysfs_driver *sysfs_get_bus_driver
- (struct sysfs_bus *bus, const char *drvname);
-
-/**
- * sort_list: sorter function to keep list elements sorted in alphabetical
- * order. Just does a strncmp as you can see :)
- *
- * Returns 1 if less than 0 otherwise
- *
- * NOTE: We take care to have a statically allocated "name" as the first
- * lement of all libsysfs structures. Hence, this function will work
- * AS IS for _ALL_ the lists that have to be sorted.
- */
-static inline int sort_list(void *new_elem, void *old_elem)
-{
- return ((strncmp(((struct sysfs_attribute *)new_elem)->name,
- ((struct sysfs_attribute *)old_elem)->name,
- strlen(((struct sysfs_attribute *)new_elem)->name))) < 0 ? 1 : 0);
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LIBSYSFS_H_ */
diff --git a/libsysfs/sysfs_bus.c b/libsysfs/sysfs_bus.c
deleted file mode 100644
index 921ef32094..0000000000
--- a/libsysfs/sysfs_bus.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * sysfs_bus.c
- *
- * Generic bus utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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"
-
-static void sysfs_close_dev(void *dev)
-{
- sysfs_close_device((struct sysfs_device *)dev);
-}
-
-static void sysfs_close_drv(void *drv)
-{
- sysfs_close_driver((struct sysfs_driver *)drv);
-}
-
-/*
- * compares names.
- * @a: name looked for
- * @b: sysfs_device comparing being compared
- * returns 1 if a==b->name or 0 not equal
- */
-static int name_equal(void *a, void *b)
-{
- if (!a || !b)
- return 0;
-
- if (strcmp(((char *)a), ((struct sysfs_device *)b)->name) == 0)
- return 1;
-
- return 0;
-}
-
-/**
- * sysfs_close_bus: close single bus
- * @bus: bus structure
- */
-void sysfs_close_bus(struct sysfs_bus *bus)
-{
- if (bus) {
- if (bus->attrlist)
- dlist_destroy(bus->attrlist);
- if (bus->devices)
- dlist_destroy(bus->devices);
- if (bus->drivers)
- dlist_destroy(bus->drivers);
- free(bus);
- }
-}
-
-/**
- * alloc_bus: mallocs new bus structure
- * returns sysfs_bus_bus struct or NULL
- */
-static struct sysfs_bus *alloc_bus(void)
-{
- return (struct sysfs_bus *)calloc(1, sizeof(struct sysfs_bus));
-}
-
-/**
- * sysfs_get_bus_devices: gets all devices for bus
- * @bus: bus to get devices for
- * returns dlist of devices with success and NULL with failure
- */
-struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus)
-{
- struct sysfs_device *dev;
- struct dlist *linklist;
- char path[SYSFS_PATH_MAX], devpath[SYSFS_PATH_MAX];
- char target[SYSFS_PATH_MAX];
- char *curlink;
-
- if (!bus) {
- errno = EINVAL;
- return NULL;
- }
- memset(path, 0, SYSFS_PATH_MAX);
- safestrcpy(path, bus->path);
- safestrcat(path, "/");
- safestrcat(path, SYSFS_DEVICES_NAME);
-
- linklist = read_dir_links(path);
- if (linklist) {
- dlist_for_each_data(linklist, curlink, char) {
- if (bus->devices) {
- dev = (struct sysfs_device *)
- dlist_find_custom(bus->devices,
- (void *)curlink, name_equal);
- if (dev)
- continue;
- }
- safestrcpy(devpath, path);
- safestrcat(devpath, "/");
- safestrcat(devpath, curlink);
- if (sysfs_get_link(devpath, target, SYSFS_PATH_MAX)) {
- dprintf("Error getting link - %s\n", devpath);
- continue;
- }
- dev = sysfs_open_device_path(target);
- if (!dev) {
- dprintf("Error opening device at %s\n",
- target);
- continue;
- }
- if (!bus->devices)
- bus->devices = dlist_new_with_delete
- (sizeof(struct sysfs_device),
- sysfs_close_dev);
- dlist_unshift_sorted(bus->devices, dev, sort_list);
- }
- sysfs_close_list(linklist);
- }
- return (bus->devices);
-}
-
-/**
- * sysfs_get_bus_drivers: gets all drivers for bus
- * @bus: bus to get devices for
- * returns dlist of devices with success and NULL with failure
- */
-struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus)
-{
- struct sysfs_driver *drv;
- struct dlist *dirlist;
- char path[SYSFS_PATH_MAX], drvpath[SYSFS_PATH_MAX];
- char *curdir;
-
- if (!bus) {
- errno = EINVAL;
- return NULL;
- }
- memset(path, 0, SYSFS_PATH_MAX);
- safestrcpy(path, bus->path);
- safestrcat(path, "/");
- safestrcat(path, SYSFS_DRIVERS_NAME);
-
- dirlist = read_dir_subdirs(path);
- if (dirlist) {
- dlist_for_each_data(dirlist, curdir, char) {
- if (bus->drivers) {
- drv = (struct sysfs_driver *)
- dlist_find_custom(bus->drivers,
- (void *)curdir, name_equal);
- if (drv)
- continue;
- }
- safestrcpy(drvpath, path);
- safestrcat(drvpath, "/");
- safestrcat(drvpath, curdir);
- drv = sysfs_open_driver_path(drvpath);
- if (!drv) {
- dprintf("Error opening driver at %s\n",
- drvpath);
- continue;
- }
- if (!bus->drivers)
- bus->drivers = dlist_new_with_delete
- (sizeof(struct sysfs_driver),
- sysfs_close_drv);
- dlist_unshift_sorted(bus->drivers, drv, sort_list);
- }
- sysfs_close_list(dirlist);
- }
- return (bus->drivers);
-}
-
-/**
- * sysfs_open_bus: opens specific bus and all its devices on system
- * returns sysfs_bus structure with success or NULL with error.
- */
-struct sysfs_bus *sysfs_open_bus(const char *name)
-{
- struct sysfs_bus *bus;
- char buspath[SYSFS_PATH_MAX];
-
- if (!name) {
- errno = EINVAL;
- return NULL;
- }
-
- memset(buspath, 0, SYSFS_PATH_MAX);
- if (sysfs_get_mnt_path(buspath, SYSFS_PATH_MAX)) {
- dprintf("Sysfs not supported on this system\n");
- return NULL;
- }
-
- safestrcat(buspath, "/");
- safestrcat(buspath, SYSFS_BUS_NAME);
- safestrcat(buspath, "/");
- safestrcat(buspath, name);
- if (sysfs_path_is_dir(buspath)) {
- dprintf("Invalid path to bus: %s\n", buspath);
- return NULL;
- }
- bus = alloc_bus();
- if (!bus) {
- dprintf("calloc failed\n");
- return NULL;
- }
- safestrcpy(bus->name, name);
- safestrcpy(bus->path, buspath);
- if (sysfs_remove_trailing_slash(bus->path)) {
- dprintf("Incorrect path to bus %s\n", bus->path);
- sysfs_close_bus(bus);
- return NULL;
- }
-
- return bus;
-}
-
-/**
- * sysfs_get_bus_device: Get specific device on bus using device's id
- * @bus: bus to find device on
- * @id: bus_id for device
- * returns struct sysfs_device reference or NULL if not found.
- */
-struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
- const char *id)
-{
- struct sysfs_device *dev = NULL;
- char devpath[SYSFS_PATH_MAX], target[SYSFS_PATH_MAX];
-
- if (!bus || !id) {
- errno = EINVAL;
- return NULL;
- }
-
- if (bus->devices) {
- dev = (struct sysfs_device *)dlist_find_custom
- (bus->devices, (void *)id, name_equal);
- if (dev)
- return dev;
- }
- safestrcpy(devpath, bus->path);
- safestrcat(devpath, "/");
- safestrcat(devpath, SYSFS_DEVICES_NAME);
- safestrcat(devpath, "/");
- safestrcat(devpath, id);
- if (sysfs_path_is_link(devpath)) {
- dprintf("No such device %s on bus %s?\n", id, bus->name);
- return NULL;
- }
- if (!sysfs_get_link(devpath, target, SYSFS_PATH_MAX)) {
- dev = sysfs_open_device_path(target);
- if (!dev) {
- dprintf("Error opening device at %s\n", target);
- return NULL;
- }
- if (!bus->devices)
- bus->devices = dlist_new_with_delete
- (sizeof(struct sysfs_device),
- sysfs_close_dev);
- dlist_unshift_sorted(bus->devices, dev, sort_list);
- }
- return dev;
-}
-
-/**
- * sysfs_get_bus_driver: Get specific driver on bus using driver name
- * @bus: bus to find driver on
- * @drvname: name of driver
- * returns struct sysfs_driver reference or NULL if not found.
- */
-struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
- const char *drvname)
-{
- struct sysfs_driver *drv;
- char drvpath[SYSFS_PATH_MAX];
-
- if (!bus || !drvname) {
- errno = EINVAL;
- return NULL;
- }
-
- if (bus->drivers) {
- drv = (struct sysfs_driver *)dlist_find_custom
- (bus->drivers, (void *)drvname, name_equal);
- if (drv)
- return drv;
- }
- safestrcpy(drvpath, bus->path);
- safestrcat(drvpath, "/");
- safestrcat(drvpath, SYSFS_DRIVERS_NAME);
- safestrcat(drvpath, "/");
- safestrcat(drvpath, drvname);
- drv = sysfs_open_driver_path(drvpath);
- if (!drv) {
- dprintf("Error opening driver at %s\n", drvpath);
- return NULL;
- }
- if (!bus->drivers)
- bus->drivers = dlist_new_with_delete
- (sizeof(struct sysfs_driver),
- sysfs_close_drv);
- dlist_unshift_sorted(bus->drivers, drv, sort_list);
- return drv;
-}
-
diff --git a/libsysfs/sysfs_class.c b/libsysfs/sysfs_class.c
deleted file mode 100644
index 102f09f17a..0000000000
--- a/libsysfs/sysfs_class.c
+++ /dev/null
@@ -1,557 +0,0 @@
-/*
- * sysfs_class.c
- *
- * Generic class utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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_class_device: closes a single class device.
- * @dev: class device to close.
- */
-void sysfs_close_class_device(struct sysfs_class_device *dev)
-{
- if (dev) {
- if (dev->parent)
- sysfs_close_class_device(dev->parent);
- if (dev->sysdevice)
- sysfs_close_device(dev->sysdevice);
- if (dev->attrlist)
- dlist_destroy(dev->attrlist);
- free(dev);
- }
-}
-
-static void sysfs_close_cls_dev(void *dev)
-{
- sysfs_close_class_device((struct sysfs_class_device *)dev);
-}
-
-/**
- * sysfs_close_class: close the given class
- * @cls: sysfs_class to close
- */
-void sysfs_close_class(struct sysfs_class *cls)
-{
- if (cls) {
- if (cls->devices)
- dlist_destroy(cls->devices);
- if (cls->attrlist)
- dlist_destroy(cls->attrlist);
- free(cls);
- }
-}
-
-static int cdev_name_equal(void *a, void *b)
-{
- if (!a || !b)
- return 0;
-
- if (strncmp((char *)a, ((struct sysfs_class_device *)b)->name,
- strlen((char *)a)) == 0)
- return 1;
-
- return 0;
-}
-
-static struct sysfs_class *alloc_class(void)
-{
- return (struct sysfs_class *) calloc(1, sizeof(struct sysfs_class));
-}
-
-/**
- * alloc_class_device: mallocs and initializes new class device struct.
- * returns sysfs_class_device or NULL.
- */
-static struct sysfs_class_device *alloc_class_device(void)
-{
- struct sysfs_class_device *dev;
-
- dev = calloc(1, sizeof(struct sysfs_class_device));
- return dev;
-}
-
-/**
- * set_classdev_classname: Grabs classname from path
- * @cdev: class device to set
- * Returns nothing
- */
-static void set_classdev_classname(struct sysfs_class_device *cdev)
-{
- char *c, *e;
- int count = 0;
-
- c = strstr(cdev->path, SYSFS_CLASS_NAME);
- if (c == NULL) {
- c = strstr(cdev->path, SYSFS_BLOCK_NAME);
- } else {
- c = strstr(c, "/");
- }
-
- if (c == NULL)
- safestrcpy(cdev->classname, SYSFS_UNKNOWN);
- else {
- if (*c == '/')
- c++;
- e = c;
- while (e != NULL && *e != '/' && *e != '\0') {
- e++;
- count++;
- }
- strncpy(cdev->classname, c, count);
- }
-}
-
-/**
- * sysfs_open_class_device_path: Opens and populates class device
- * @path: path to class device.
- * returns struct sysfs_class_device with success and NULL with error.
- */
-struct sysfs_class_device *sysfs_open_class_device_path(const char *path)
-{
- struct sysfs_class_device *cdev;
- char temp_path[SYSFS_PATH_MAX];
-
- if (!path) {
- errno = EINVAL;
- return NULL;
- }
-
- /*
- * Post linux-2.6.14 driver model supports nested classes with
- * links to the nested hierarchy at /sys/class/xxx/. Check for
- * a link to the actual class device if a directory isn't found
- */
- if (sysfs_path_is_dir(path)) {
- dprintf("%s: Directory not found, checking for a link\n", path);
- if (!sysfs_path_is_link(path)) {
- if (sysfs_get_link(path, temp_path, SYSFS_PATH_MAX)) {
- dprintf("Error retrieving link at %s\n", path);
- return NULL;
- }
- } else {
- dprintf("%s is not a valid class device path\n", path);
- return NULL;
- }
- } else
- safestrcpy(temp_path, path);
-
- cdev = alloc_class_device();
- if (!cdev) {
- dprintf("calloc failed\n");
- return NULL;
- }
- if (sysfs_get_name_from_path(temp_path, cdev->name, SYSFS_NAME_LEN)) {
- errno = EINVAL;
- dprintf("Error getting class device name\n");
- sysfs_close_class_device(cdev);
- return NULL;
- }
-
- safestrcpy(cdev->path, temp_path);
- if (sysfs_remove_trailing_slash(cdev->path)) {
- dprintf("Invalid path to class device %s\n", cdev->path);
- sysfs_close_class_device(cdev);
- return NULL;
- }
- set_classdev_classname(cdev);
-
- return cdev;
-}
-
-/**
- * get_blockdev_parent: Get the parent class device for a "block" subsystem
- * device if present
- * @clsdev: block subsystem class device whose parent needs to be found
- * Returns 0 on success and 1 on error
- */
-static int get_blockdev_parent(struct sysfs_class_device *clsdev)
-{
- char parent_path[SYSFS_PATH_MAX];
- char *c;
-
- safestrcpy(parent_path, clsdev->path);
- c = strstr(parent_path, SYSFS_BLOCK_NAME);
- if (c == NULL) {
- dprintf("Class device %s does not belong to BLOCK subsystem\n",
- clsdev->name);
- return 1;
- }
- c += strlen(SYSFS_BLOCK_NAME);
- if (*c == '/')
- c++;
- else
- goto errout;
-
- /* validate whether the given class device is a partition or not */
- if ((strncmp(c, clsdev->name, strlen(clsdev->name))) == 0) {
- dprintf("%s not a partition\n", clsdev->name);
- return 1;
- }
-
- c = strchr(c, '/');
- if (c == NULL)
- goto errout;
-
- *c = '\0';
-
- clsdev->parent = sysfs_open_class_device_path(parent_path);
- if (!clsdev->parent) {
- dprintf("Error opening the parent class device at %s\n",
- parent_path);
- return 1;
- }
- return 0;
-
-errout:
- dprintf("Invalid path %s\n", clsdev->path);
- return 1;
-}
-
-/**
- * sysfs_get_classdev_parent: Retrieves the parent of a class device.
- * eg., when working with hda1, this function can be used to retrieve the
- * sysfs_class_device for hda
- *
- * @clsdev: class device whose parent details are required.
- * Returns sysfs_class_device of the parent on success, NULL on failure
- */
-struct sysfs_class_device *sysfs_get_classdev_parent
- (struct sysfs_class_device *clsdev)
-{
- if (!clsdev) {
- errno = EINVAL;
- return NULL;
- }
- if (clsdev->parent)
- return (clsdev->parent);
-
- /*
- * As of now, only block devices have a parent child heirarchy in sysfs
- * We do not know, if, in the future, more classes will have a similar
- * structure. Hence, we now call a specialized function for block and
- * later we can add support functions for other subsystems as required.
- */
- if (!(strncmp(clsdev->classname, SYSFS_BLOCK_NAME,
- sizeof(SYSFS_BLOCK_NAME)))) {
- if ((get_blockdev_parent(clsdev)) == 0)
- return (clsdev->parent);
- }
- return NULL;
-}
-
-/**
- * get_classdev_path: given the class and a device in the class, return the
- * absolute path to the device
- * @classname: name of the class
- * @clsdev: the class device
- * @path: buffer to return path
- * @psize: size of "path"
- * Returns 0 on SUCCESS or -1 on error
- */
-static int get_classdev_path(const char *classname, const char *clsdev,
- char *path, size_t len)
-{
- if (!classname || !clsdev || !path) {
- errno = EINVAL;
- return -1;
- }
- if (sysfs_get_mnt_path(path, len) != 0) {
- dprintf("Error getting sysfs mount path\n");
- return -1;
- }
- if (strncmp(classname, SYSFS_BLOCK_NAME,
- sizeof(SYSFS_BLOCK_NAME)) == 0) {
- safestrcatmax(path, "/", len);
- safestrcatmax(path, SYSFS_BLOCK_NAME, len);
- } else {
- safestrcatmax(path, "/", len);
- safestrcatmax(path, SYSFS_CLASS_NAME, len);
- safestrcatmax(path, "/", len);
- safestrcatmax(path, classname, len);
- }
- safestrcatmax(path, "/", len);
- safestrcatmax(path, clsdev, len);
- return 0;
-}
-
-/**
- * sysfs_open_class_device: Locates a specific class_device and returns it.
- * Class_device must be closed using sysfs_close_class_device
- * @classname: Class to search
- * @name: name of the class_device
- *
- * NOTE:
- * Call sysfs_close_class_device() to close the class device
- */
-struct sysfs_class_device *sysfs_open_class_device
- (const char *classname, const char *name)
-{
- char devpath[SYSFS_PATH_MAX];
- struct sysfs_class_device *cdev;
-
- if (!classname || !name) {
- errno = EINVAL;
- return NULL;
- }
-
- memset(devpath, 0, SYSFS_PATH_MAX);
- if ((get_classdev_path(classname, name, devpath,
- SYSFS_PATH_MAX)) != 0) {
- dprintf("Error getting to device %s on class %s\n",
- name, classname);
- return NULL;
- }
-
- cdev = sysfs_open_class_device_path(devpath);
- if (!cdev) {
- dprintf("Error getting class device %s from class %s\n",
- name, classname);
- return NULL;
- }
- return cdev;
-}
-
-/**
- * sysfs_get_classdev_attr: searches class device's attributes by name
- * @clsdev: class device to look through
- * @name: attribute name to get
- * returns sysfs_attribute reference with success or NULL with error
- */
-struct sysfs_attribute *sysfs_get_classdev_attr
- (struct sysfs_class_device *clsdev, const char *name)
-{
- if (!clsdev || !name) {
- errno = EINVAL;
- return NULL;
- }
- return get_attribute(clsdev, (char *)name);
-}
-
-/**
- * sysfs_get_classdev_attributes: gets list of classdev attributes
- * @clsdev: class device whose attributes list is needed
- * returns dlist of attributes on success or NULL on error
- */
-struct dlist *sysfs_get_classdev_attributes(struct sysfs_class_device *clsdev)
-{
- if (!clsdev) {
- errno = EINVAL;
- return NULL;
- }
- return get_attributes_list(clsdev);
-}
-
-/**
- * sysfs_get_classdev_device: gets the sysfs_device associated with the
- * given sysfs_class_device
- * @clsdev: class device whose associated sysfs_device is needed
- * returns struct sysfs_device * on success or NULL on error
- */
-struct sysfs_device *sysfs_get_classdev_device
- (struct sysfs_class_device *clsdev)
-{
- char linkpath[SYSFS_PATH_MAX], devpath[SYSFS_PATH_MAX];
-
- if (!clsdev) {
- errno = EINVAL;
- return NULL;
- }
-
- if (clsdev->sysdevice)
- return clsdev->sysdevice;
-
- memset(linkpath, 0, SYSFS_PATH_MAX);
- safestrcpy(linkpath, clsdev->path);
- safestrcat(linkpath, "/device");
- if (!sysfs_path_is_link(linkpath)) {
- memset(devpath, 0, SYSFS_PATH_MAX);
- if (!sysfs_get_link(linkpath, devpath, SYSFS_PATH_MAX))
- clsdev->sysdevice = sysfs_open_device_path(devpath);
- }
- return clsdev->sysdevice;
-}
-
-/**
- * sysfs_open_class: opens specific class and all its devices on system
- * returns sysfs_class structure with success or NULL with error.
- */
-struct sysfs_class *sysfs_open_class(const char *name)
-{
- struct sysfs_class *cls = NULL;
- char classpath[SYSFS_PATH_MAX];
-
- if (!name) {
- errno = EINVAL;
- return NULL;
- }
-
- memset(classpath, 0, SYSFS_PATH_MAX);
- if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0) {
- dprintf("Sysfs not supported on this system\n");
- return NULL;
- }
-
- /*
- * We shall now treat "block" also as a class. Hence, check here
- * if "name" is "block" and proceed accordingly
- */
- if (strcmp(name, SYSFS_BLOCK_NAME) == 0) {
- safestrcat(classpath, "/");
- safestrcat(classpath, SYSFS_BLOCK_NAME);
- } else {
- safestrcat(classpath, "/");
- safestrcat(classpath, SYSFS_CLASS_NAME);
- safestrcat(classpath, "/");
- safestrcat(classpath, name);
- }
- if (sysfs_path_is_dir(classpath)) {
- dprintf("Class %s not found on the system\n", name);
- return NULL;
- }
-
- cls = alloc_class();
- if (cls == NULL) {
- dprintf("calloc failed\n");
- return NULL;
- }
- safestrcpy(cls->name, name);
- safestrcpy(cls->path, classpath);
- if ((sysfs_remove_trailing_slash(cls->path)) != 0) {
- dprintf("Invalid path to class device %s\n", cls->path);
- sysfs_close_class(cls);
- return NULL;
- }
-
- return cls;
-}
-
-/**
- * sysfs_get_class_device: get specific class device using the device's id
- * @cls: sysfs_class to find the device on
- * @name: name of the class device to look for
- *
- * Returns sysfs_class_device * on success and NULL on failure
- */
-struct sysfs_class_device *sysfs_get_class_device(struct sysfs_class *cls,
- const char *name)
-{
- char path[SYSFS_PATH_MAX];
- struct sysfs_class_device *cdev = NULL;
-
- if (!cls || !name) {
- errno = EINVAL;
- return NULL;
- }
-
- if (cls->devices) {
- cdev = (struct sysfs_class_device *)dlist_find_custom
- (cls->devices, (void *)name, cdev_name_equal);
- if (cdev)
- return cdev;
- }
-
- safestrcpy(path, cls->path);
- safestrcat(path, "/");
- safestrcat(path, name);
- cdev = sysfs_open_class_device_path(path);
- if (!cdev) {
- dprintf("Error opening class device at %s\n", path);
- return NULL;
- }
- if (!cls->devices)
- cls->devices = dlist_new_with_delete
- (sizeof(struct sysfs_class_device),
- sysfs_close_cls_dev);
-
- dlist_unshift_sorted(cls->devices, cdev, sort_list);
- return cdev;
-}
-
-/**
- * Add class devices to list
- */
-static void add_cdevs_to_classlist(struct sysfs_class *cls, struct dlist *list)
-{
- char path[SYSFS_PATH_MAX], *cdev_name;
- struct sysfs_class_device *cdev = NULL;
-
- if (cls == NULL || list == NULL)
- return;
-
- dlist_for_each_data(list, cdev_name, char) {
- if (cls->devices) {
- cdev = (struct sysfs_class_device *)
- dlist_find_custom(cls->devices,
- (void *)cdev_name, cdev_name_equal);
- if (cdev)
- continue;
- }
- safestrcpy(path, cls->path);
- safestrcat(path, "/");
- safestrcat(path, cdev_name);
- cdev = sysfs_open_class_device_path(path);
- if (cdev) {
- if (!cls->devices)
- cls->devices = dlist_new_with_delete
- (sizeof(struct sysfs_class_device),
- sysfs_close_cls_dev);
- dlist_unshift_sorted(cls->devices, cdev,
- sort_list);
- }
- }
-}
-
-/**
- * sysfs_get_class_devices: get all class devices in the given class
- * @cls: sysfs_class whose devices list is needed
- *
- * Returns a dlist of sysfs_class_device * on success and NULL on failure
- */
-struct dlist *sysfs_get_class_devices(struct sysfs_class *cls)
-{
- char path[SYSFS_PATH_MAX];
- struct dlist *dirlist, *linklist;
-
- if (!cls) {
- errno = EINVAL;
- return NULL;
- }
-
- /*
- * Post linux-2.6.14, we have nested classes and links under
- * /sys/class/xxx/. are also valid class devices
- */
- safestrcpy(path, cls->path);
- dirlist = read_dir_subdirs(path);
- if (dirlist) {
- add_cdevs_to_classlist(cls, dirlist);
- sysfs_close_list(dirlist);
- }
-
- linklist = read_dir_links(path);
- if (linklist) {
- add_cdevs_to_classlist(cls, linklist);
- sysfs_close_list(linklist);
- }
-
- return cls->devices;
-}
diff --git a/libsysfs/sysfs_device.c b/libsysfs/sysfs_device.c
deleted file mode 100644
index e3d70143f9..0000000000
--- a/libsysfs/sysfs_device.c
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * sysfs_device.c
- *
- * Generic device utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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"
-
-/**
- * get_dev_driver: fills in the dev->driver_name field
- * Returns 0 on SUCCESS and -1 on error
- */
-static int get_dev_driver(struct sysfs_device *dev)
-{
- char path[SYSFS_PATH_MAX];
- char devpath[SYSFS_PATH_MAX];
-
- if (!dev) {
- errno = EINVAL;
- return -1;
- }
- memset(path, 0, SYSFS_PATH_MAX);
- memset(devpath, 0, SYSFS_PATH_MAX);
- safestrcpymax(path, dev->path, SYSFS_PATH_MAX);
- safestrcatmax(path, "/driver", SYSFS_PATH_MAX);
- if (!sysfs_path_is_link(path)) {
- if (!sysfs_get_link(path, devpath, SYSFS_PATH_MAX)) {
- if (sysfs_get_name_from_path(devpath,
- dev->driver_name, SYSFS_NAME_LEN))
- return -1;
- }
- return 0;
- }
- return -1;
-}
-
-/**
- * sysfs_get_device_bus: retrieves the bus name the device is on, checks path
- * to bus' link to make sure it has correct device.
- * @dev: device to get busname.
- * returns 0 with success and -1 with error.
- */
-int sysfs_get_device_bus(struct sysfs_device *dev)
-{
- char devpath[SYSFS_PATH_MAX];
- char path[SYSFS_PATH_MAX];
-
- if (!dev) {
- errno = EINVAL;
- return -1;
- }
-
- memset(path, 0, SYSFS_PATH_MAX);
- memset(devpath, 0, SYSFS_PATH_MAX);
- safestrcpymax(path, dev->path, SYSFS_PATH_MAX);
- safestrcatmax(path, "/bus", SYSFS_PATH_MAX);
- if (!sysfs_path_is_link(path)) {
- if (!sysfs_get_link(path, devpath, SYSFS_PATH_MAX)) {
- if (sysfs_get_name_from_path(devpath,
- dev->bus, SYSFS_NAME_LEN))
- return -1;
- }
- return 0;
- }
- return -1;
-}
-
-/**
- * sysfs_close_device_tree: closes every device in the supplied tree,
- * closing children only.
- * @devroot: device root of tree.
- */
-void sysfs_close_device_tree(struct sysfs_device *devroot)
-{
- if (devroot) {
- if (devroot->children) {
- struct sysfs_device *child = NULL;
-
- dlist_for_each_data(devroot->children, child,
- struct sysfs_device) {
- sysfs_close_device_tree(child);
- }
- }
- sysfs_close_device(devroot);
- }
-}
-
-/**
- * sysfs_close_device: closes and cleans up a device
- * @dev = device to clean up
- */
-void sysfs_close_device(struct sysfs_device *dev)
-{
- if (dev) {
- if (dev->parent)
- sysfs_close_device(dev->parent);
- if (dev->children && dev->children->count)
- dlist_destroy(dev->children);
- if (dev->attrlist)
- dlist_destroy(dev->attrlist);
- free(dev);
- }
-}
-
-/**
- * alloc_device: allocates and initializes device structure
- * returns struct sysfs_device
- */
-static struct sysfs_device *alloc_device(void)
-{
- return (struct sysfs_device *) calloc(1, sizeof(struct sysfs_device));
-}
-
-/**
- * sysfs_open_device_path: opens and populates device structure
- * @path: path to device, this is the /sys/devices/ path
- * returns sysfs_device structure with success or NULL with error
- */
-struct sysfs_device *sysfs_open_device_path(const char *path)
-{
- struct sysfs_device *dev;
-
- if (!path) {
- errno = EINVAL;
- return NULL;
- }
- if (sysfs_path_is_dir(path)) {
- dprintf("Incorrect path to device: %s\n", path);
- return NULL;
- }
- dev = alloc_device();
- if (!dev) {
- dprintf("Error allocating device at %s\n", path);
- return NULL;
- }
- if (sysfs_get_name_from_path(path, dev->bus_id, SYSFS_NAME_LEN)) {
- errno = EINVAL;
- dprintf("Error getting device bus_id\n");
- sysfs_close_device(dev);
- return NULL;
- }
- safestrcpy(dev->path, path);
- if (sysfs_remove_trailing_slash(dev->path)) {
- dprintf("Invalid path to device %s\n", dev->path);
- sysfs_close_device(dev);
- return NULL;
- }
- /*
- * The "name" attribute no longer exists... return the device's
- * sysfs representation instead, in the "dev->name" field, which
- * implies that the dev->name and dev->bus_id contain same data.
- */
- safestrcpy(dev->name, dev->bus_id);
-
- if (sysfs_get_device_bus(dev))
- dprintf("Could not get device bus\n");
-
- if (get_dev_driver(dev)) {
- dprintf("Could not get device %s's driver\n", dev->bus_id);
- safestrcpy(dev->driver_name, SYSFS_UNKNOWN);
- }
-
- return dev;
-}
-
-/**
- * sysfs_get_device_attr: searches dev's attributes by name
- * @dev: device to look through
- * @name: attribute name to get
- * returns sysfs_attribute reference with success or NULL with error.
- */
-struct sysfs_attribute *sysfs_get_device_attr(struct sysfs_device *dev,
- const char *name)
-{
- if (!dev || !name) {
- errno = EINVAL;
- return NULL;
- }
- return get_attribute(dev, (char *)name);
-}
-
-/**
- * sysfs_get_device_attributes: gets list of device attributes
- * @dev: device whose attributes list is needed
- * returns dlist of attributes on success or NULL on error
- */
-struct dlist *sysfs_get_device_attributes(struct sysfs_device *dev)
-{
- if (!dev) {
- errno = EINVAL;
- return NULL;
- }
- return get_attributes_list(dev);
-}
-
-/**
- * get_device_absolute_path: looks up the bus the device is on, gets
- * absolute path to the device
- * @device: device for which path is needed
- * @path: buffer to store absolute path
- * @psize: size of "path"
- * Returns 0 on success -1 on failure
- */
-static int get_device_absolute_path(const char *device, const char *bus,
- char *path, size_t psize)
-{
- char bus_path[SYSFS_PATH_MAX];
-
- if (!device || !path) {
- errno = EINVAL;
- return -1;
- }
-
- memset(bus_path, 0, SYSFS_PATH_MAX);
- if (sysfs_get_mnt_path(bus_path, SYSFS_PATH_MAX)) {
- dprintf ("Sysfs not supported on this system\n");
- return -1;
- }
- safestrcat(bus_path, "/");
- safestrcat(bus_path, SYSFS_BUS_NAME);
- safestrcat(bus_path, "/");
- safestrcat(bus_path, bus);
- safestrcat(bus_path, "/");
- safestrcat(bus_path, SYSFS_DEVICES_NAME);
- safestrcat(bus_path, "/");
- safestrcat(bus_path, device);
- /*
- * We now are at /sys/bus/"bus_name"/devices/"device" which is a link.
- * Now read this link to reach to the device.
- */
- if (sysfs_get_link(bus_path, path, psize)) {
- dprintf("Error getting to device %s\n", device);
- return -1;
- }
- return 0;
-}
-
-/**
- * sysfs_open_device: open a device by id (use the "bus" subsystem)
- * @bus: bus the device belongs to
- * @bus_id: bus_id of the device to open - has to be the "bus_id" in
- * /sys/bus/xxx/devices
- * returns struct sysfs_device if found, NULL otherwise
- * NOTE:
- * 1. Use sysfs_close_device to close the device
- * 2. Bus the device is on must be supplied
- * Use sysfs_find_device_bus to get the bus name
- */
-struct sysfs_device *sysfs_open_device(const char *bus, const char *bus_id)
-{
- char sysfs_path[SYSFS_PATH_MAX];
- struct sysfs_device *device;
-
- if (!bus_id || !bus) {
- errno = EINVAL;
- return NULL;
- }
- memset(sysfs_path, 0, SYSFS_PATH_MAX);
- if (get_device_absolute_path(bus_id, bus, sysfs_path,
- SYSFS_PATH_MAX)) {
- dprintf("Error getting to device %s\n", bus_id);
- return NULL;
- }
-
- device = sysfs_open_device_path(sysfs_path);
- if (!device) {
- dprintf("Error opening device %s\n", bus_id);
- return NULL;
- }
- return device;
-}
-
-/**
- * sysfs_get_device_parent: opens up given device's parent and returns a
- * reference to its sysfs_device
- * @dev: sysfs_device whose parent is requested
- * Returns sysfs_device of the parent on success and NULL on failure
- */
-struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev)
-{
- char ppath[SYSFS_PATH_MAX], dpath[SYSFS_PATH_MAX], *tmp;
-
- if (!dev) {
- errno = EINVAL;
- return NULL;
- }
-
- if (dev->parent)
- return (dev->parent);
-
- memset(ppath, 0, SYSFS_PATH_MAX);
- memset(dpath, 0, SYSFS_PATH_MAX);
- safestrcpy(ppath, dev->path);
- tmp = strrchr(ppath, '/');
- if (!tmp) {
- dprintf("Invalid path to device %s\n", ppath);
- return NULL;
- }
- if (*(tmp + 1) == '\0') {
- *tmp = '\0';
- tmp = strrchr(tmp, '/');
- if (tmp == NULL) {
- dprintf("Invalid path to device %s\n", ppath);
- return NULL;
- }
- }
- *tmp = '\0';
-
- /* Make sure we're not at the top of the device tree */
- sysfs_get_mnt_path(dpath, SYSFS_PATH_MAX);
- safestrcat(dpath, "/" SYSFS_DEVICES_NAME);
- if (strcmp(dpath, ppath) == 0) {
- dprintf("Device at %s does not have a parent\n", dev->path);
- return NULL;
- }
-
- dev->parent = sysfs_open_device_path(ppath);
- if (!dev->parent) {
- dprintf("Error opening device %s's parent at %s\n",
- dev->bus_id, ppath);
- return NULL;
- }
- return (dev->parent);
-}
diff --git a/libsysfs/sysfs_dir.c b/libsysfs/sysfs_dir.c
deleted file mode 100644
index 7d98c669c6..0000000000
--- a/libsysfs/sysfs_dir.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * sysfs_dir.c
- *
- * Directory utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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"
-
-static int sort_char(void *new, void *old)
-{
- return ((strncmp((char *)new, (char *)old,
- strlen((char *)new))) < 0 ? 1 : 0);
-}
-
-/**
- * sysfs_del_name: free function for sysfs_open_subsystem_list
- * @name: memory area to be freed
- */
-static void sysfs_del_name(void *name)
-{
- free(name);
-}
-
-/**
- * sysfs_del_attribute: routine for dlist integration
- */
-static void sysfs_del_attribute(void *attr)
-{
- sysfs_close_attribute((struct sysfs_attribute *)attr);
-}
-
-/**
- * attr_name_equal: compares attributes by name
- * @a: attribute name for comparison
- * @b: sysfs_attribute to be compared.
- * returns 1 if a==b->name or 0 if not equal
- */
-static int attr_name_equal(void *a, void *b)
-{
- if (!a || !b)
- return 0;
-
- if (strcmp(((char *)a), ((struct sysfs_attribute *)b)->name) == 0)
- return 1;
-
- return 0;
-}
-
-/**
- * sysfs_close_attribute: closes and cleans up attribute
- * @sysattr: attribute to close.
- */
-void sysfs_close_attribute(struct sysfs_attribute *sysattr)
-{
- if (sysattr) {
- if (sysattr->value)
- free(sysattr->value);
- free(sysattr);
- }
-}
-
-/**
- * alloc_attribute: allocates and initializes attribute structure
- * returns struct sysfs_attribute with success and NULL with error.
- */
-static struct sysfs_attribute *alloc_attribute(void)
-{
- return (struct sysfs_attribute *)
- calloc(1, sizeof(struct sysfs_attribute));
-}
-
-/**
- * sysfs_open_attribute: creates sysfs_attribute structure
- * @path: path to attribute.
- * returns sysfs_attribute struct with success and NULL with error.
- */
-struct sysfs_attribute *sysfs_open_attribute(const char *path)
-{
- struct sysfs_attribute *sysattr = NULL;
- struct stat fileinfo;
-
- if (!path) {
- errno = EINVAL;
- return NULL;
- }
- sysattr = alloc_attribute();
- if (!sysattr) {
- dprintf("Error allocating attribute at %s\n", path);
- return NULL;
- }
- if (sysfs_get_name_from_path(path, sysattr->name,
- SYSFS_NAME_LEN) != 0) {
- dprintf("Error retrieving attrib name from path: %s\n", path);
- sysfs_close_attribute(sysattr);
- return NULL;
- }
- safestrcpy(sysattr->path, path);
- if ((stat(sysattr->path, &fileinfo)) != 0) {
- dprintf("Stat failed: No such attribute?\n");
- sysattr->method = 0;
- free(sysattr);
- sysattr = NULL;
- } else {
- if (fileinfo.st_mode & S_IRUSR)
- sysattr->method |= SYSFS_METHOD_SHOW;
- if (fileinfo.st_mode & S_IWUSR)
- sysattr->method |= SYSFS_METHOD_STORE;
- }
-
- return sysattr;
-}
-
-/**
- * sysfs_read_attribute: reads value from attribute
- * @sysattr: attribute to read
- * returns 0 with success and -1 with error.
- */
-int sysfs_read_attribute(struct sysfs_attribute *sysattr)
-{
- char *fbuf = NULL;
- char *vbuf = NULL;
- ssize_t length = 0;
- long pgsize = 0;
- int fd;
-
- if (!sysattr) {
- errno = EINVAL;
- return -1;
- }
- if (!(sysattr->method & SYSFS_METHOD_SHOW)) {
- dprintf("Show method not supported for attribute %s\n",
- sysattr->path);
- errno = EACCES;
- return -1;
- }
- pgsize = getpagesize();
- fbuf = (char *)calloc(1, pgsize+1);
- if (!fbuf) {
- dprintf("calloc failed\n");
- return -1;
- }
- if ((fd = open(sysattr->path, O_RDONLY)) < 0) {
- dprintf("Error reading attribute %s\n", sysattr->path);
- free(fbuf);
- return -1;
- }
- length = read(fd, fbuf, pgsize);
- if (length < 0) {
- dprintf("Error reading from attribute %s\n", sysattr->path);
- close(fd);
- free(fbuf);
- return -1;
- }
- if (sysattr->len > 0) {
- if ((sysattr->len == length) &&
- (!(strncmp(sysattr->value, fbuf, length)))) {
- close(fd);
- free(fbuf);
- return 0;
- }
- free(sysattr->value);
- }
- sysattr->len = length;
- close(fd);
- vbuf = (char *)realloc(fbuf, length+1);
- if (!vbuf) {
- dprintf("realloc failed\n");
- free(fbuf);
- return -1;
- }
- sysattr->value = vbuf;
-
- return 0;
-}
-
-/**
- * sysfs_write_attribute: write value to the attribute
- * @sysattr: attribute to write
- * @new_value: value to write
- * @len: length of "new_value"
- * returns 0 with success and -1 with error.
- */
-int sysfs_write_attribute(struct sysfs_attribute *sysattr,
- const char *new_value, size_t len)
-{
- int fd;
- int length;
-
- if (!sysattr || !new_value || len == 0) {
- errno = EINVAL;
- return -1;
- }
-
- if (!(sysattr->method & SYSFS_METHOD_STORE)) {
- dprintf ("Store method not supported for attribute %s\n",
- sysattr->path);
- errno = EACCES;
- return -1;
- }
- if (sysattr->method & SYSFS_METHOD_SHOW) {
- /*
- * read attribute again to see if we can get an updated value
- */
- if ((sysfs_read_attribute(sysattr))) {
- dprintf("Error reading attribute\n");
- return -1;
- }
- if ((strncmp(sysattr->value, new_value, sysattr->len)) == 0) {
- dprintf("Attr %s already has the requested value %s\n",
- sysattr->name, new_value);
- return 0;
- }
- }
- /*
- * open O_WRONLY since some attributes have no "read" but only
- * "write" permission
- */
- if ((fd = open(sysattr->path, O_WRONLY)) < 0) {
- dprintf("Error reading attribute %s\n", sysattr->path);
- return -1;
- }
-
- length = write(fd, new_value, len);
- if (length < 0) {
- dprintf("Error writing to the attribute %s - invalid value?\n",
- sysattr->name);
- close(fd);
- return -1;
- } else if ((unsigned int)length != len) {
- dprintf("Could not write %zd bytes to attribute %s\n",
- len, sysattr->name);
- /*
- * since we could not write user supplied number of bytes,
- * restore the old value if one available
- */
- if (sysattr->method & SYSFS_METHOD_SHOW) {
- length = write(fd, sysattr->value, sysattr->len);
- close(fd);
- return -1;
- }
- }
-
- /*
- * Validate length that has been copied. Alloc appropriate area
- * in sysfs_attribute. Verify first if the attribute supports reading
- * (show method). If it does not, do not bother
- */
- if (sysattr->method & SYSFS_METHOD_SHOW) {
- if (length != sysattr->len) {
- sysattr->value = (char *)realloc
- (sysattr->value, length);
- sysattr->len = length;
- safestrcpymax(sysattr->value, new_value, length);
- } else {
- /*"length" of the new value is same as old one */
- safestrcpymax(sysattr->value, new_value, length);
- }
- }
-
- close(fd);
- return 0;
-}
-
-/**
- * add_attribute: open and add attribute at path to given directory
- * @dev: device whose attribute is to be added
- * @path: path to attribute
- * returns pointer to attr added with success and NULL with error.
- */
-static struct sysfs_attribute *add_attribute(void *dev, const char *path)
-{
- struct sysfs_attribute *attr;
-
- attr = sysfs_open_attribute(path);
- if (!attr) {
- dprintf("Error opening attribute %s\n", path);
- return NULL;
- }
- if (attr->method & SYSFS_METHOD_SHOW) {
- if (sysfs_read_attribute(attr)) {
- dprintf("Error reading attribute %s\n", path);
- sysfs_close_attribute(attr);
- return NULL;
- }
- }
-
- if (!((struct sysfs_device *)dev)->attrlist) {
- ((struct sysfs_device *)dev)->attrlist = dlist_new_with_delete
- (sizeof(struct sysfs_attribute), sysfs_del_attribute);
- }
- dlist_unshift_sorted(((struct sysfs_device *)dev)->attrlist,
- attr, sort_list);
-
- return attr;
-}
-
-/*
- * get_attribute - given a sysfs_* struct and a name, return the
- * sysfs_attribute corresponding to "name"
- * returns sysfs_attribute on success and NULL on error
- */
-struct sysfs_attribute *get_attribute(void *dev, const char *name)
-{
- struct sysfs_attribute *cur = NULL;
- char path[SYSFS_PATH_MAX];
-
- if (!dev || !name) {
- errno = EINVAL;
- return NULL;
- }
-
- if (((struct sysfs_device *)dev)->attrlist) {
- /* check if attr is already in the list */
- cur = (struct sysfs_attribute *)dlist_find_custom
- ((((struct sysfs_device *)dev)->attrlist),
- (void *)name, attr_name_equal);
- if (cur)
- return cur;
- }
- safestrcpymax(path, ((struct sysfs_device *)dev)->path,
- SYSFS_PATH_MAX);
- safestrcatmax(path, "/", SYSFS_PATH_MAX);
- safestrcatmax(path, name, SYSFS_PATH_MAX);
- if (!sysfs_path_is_file(path))
- cur = add_attribute((void *)dev, path);
- return cur;
-}
-
-/**
- * read_dir_links: grabs links in a specific directory
- * @sysdir: sysfs directory to read
- * returns list of link names with success and NULL with error.
- */
-struct dlist *read_dir_links(const char *path)
-{
- DIR *dir = NULL;
- struct dirent *dirent = NULL;
- char file_path[SYSFS_PATH_MAX], *linkname;
- struct dlist *linklist = NULL;
-
- if (!path) {
- errno = EINVAL;
- return NULL;
- }
- dir = opendir(path);
- if (!dir) {
- dprintf("Error opening directory %s\n", path);
- return NULL;
- }
- while ((dirent = readdir(dir)) != NULL) {
- if (0 == strcmp(dirent->d_name, "."))
- continue;
- if (0 == strcmp(dirent->d_name, ".."))
- continue;
- memset(file_path, 0, SYSFS_PATH_MAX);
- safestrcpy(file_path, path);
- safestrcat(file_path, "/");
- safestrcat(file_path, dirent->d_name);
- if (!sysfs_path_is_link(file_path)) {
- if (!linklist) {
- linklist = dlist_new_with_delete
- (SYSFS_NAME_LEN, sysfs_del_name);
- if (!linklist) {
- dprintf("Error creating list\n");
- return NULL;
- }
- }
- linkname = (char *)calloc(1, SYSFS_NAME_LEN);
- safestrcpymax(linkname, dirent->d_name, SYSFS_NAME_LEN);
- dlist_unshift_sorted(linklist, linkname, sort_char);
- }
- }
- closedir(dir);
- return linklist;
-}
-
-/**
- * read_dir_subdirs: grabs subdirs in a specific directory
- * @sysdir: sysfs directory to read
- * returns list of directory names with success and NULL with error.
- */
-struct dlist *read_dir_subdirs(const char *path)
-{
- DIR *dir = NULL;
- struct dirent *dirent = NULL;
- char file_path[SYSFS_PATH_MAX], *dir_name;
- struct dlist *dirlist = NULL;
-
- if (!path) {
- errno = EINVAL;
- return NULL;
- }
- dir = opendir(path);
- if (!dir) {
- dprintf("Error opening directory %s\n", path);
- return NULL;
- }
- while ((dirent = readdir(dir)) != NULL) {
- if (0 == strcmp(dirent->d_name, "."))
- continue;
- if (0 == strcmp(dirent->d_name, ".."))
- continue;
- memset(file_path, 0, SYSFS_PATH_MAX);
- safestrcpy(file_path, path);
- safestrcat(file_path, "/");
- safestrcat(file_path, dirent->d_name);
- if (!sysfs_path_is_dir(file_path)) {
- if (!dirlist) {
- dirlist = dlist_new_with_delete
- (SYSFS_NAME_LEN, sysfs_del_name);
- if (!dirlist) {
- dprintf("Error creating list\n");
- return NULL;
- }
- }
- dir_name = (char *)calloc(1, SYSFS_NAME_LEN);
- safestrcpymax(dir_name, dirent->d_name, SYSFS_NAME_LEN);
- dlist_unshift_sorted(dirlist, dir_name, sort_char);
- }
- }
- closedir(dir);
- return dirlist;
-}
-
-/**
- * get_attributes_list: build a list of attributes for the given device
- * @dev: devices whose attributes list is required
- * returns dlist of attributes on success and NULL on failure
- */
-struct dlist *get_attributes_list(void *dev)
-{
- DIR *dir = NULL;
- struct dirent *dirent = NULL;
- struct sysfs_attribute *attr = NULL;
- char file_path[SYSFS_PATH_MAX], path[SYSFS_PATH_MAX];
-
- if (!dev) {
- errno = EINVAL;
- return NULL;
- }
- memset(path, 0, SYSFS_PATH_MAX);
- safestrcpy(path, ((struct sysfs_device *)dev)->path);
- dir = opendir(path);
- if (!dir) {
- dprintf("Error opening directory %s\n", path);
- return NULL;
- }
- while ((dirent = readdir(dir)) != NULL) {
- if (0 == strcmp(dirent->d_name, "."))
- continue;
- if (0 == strcmp(dirent->d_name, ".."))
- continue;
- memset(file_path, 0, SYSFS_PATH_MAX);
- safestrcpy(file_path, path);
- safestrcat(file_path, "/");
- safestrcat(file_path, dirent->d_name);
- if (!sysfs_path_is_file(file_path)) {
- if (((struct sysfs_device *)dev)->attrlist) {
- /* check if attr is already in the list */
- attr = (struct sysfs_attribute *)
- dlist_find_custom
- ((((struct sysfs_device *)dev)->attrlist),
- (void *)dirent->d_name, attr_name_equal);
- if (attr)
- continue;
- else
- add_attribute(dev, file_path);
- } else
- attr = add_attribute(dev, file_path);
- }
- }
- closedir(dir);
- return ((struct sysfs_device *)dev)->attrlist;
-}
diff --git a/libsysfs/sysfs_driver.c b/libsysfs/sysfs_driver.c
deleted file mode 100644
index c2464faa9e..0000000000
--- a/libsysfs/sysfs_driver.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * sysfs_driver.c
- *
- * Driver utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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"
-
-static void sysfs_close_driver_device(void *device)
-{
- sysfs_close_device((struct sysfs_device *)device);
-}
-
-/**
- * sysfs_close_driver: closes driver and deletes device lists too
- * @driver: driver to close
- */
-void sysfs_close_driver(struct sysfs_driver *driver)
-{
- if (driver) {
- if (driver->devices)
- dlist_destroy(driver->devices);
- if (driver->attrlist)
- dlist_destroy(driver->attrlist);
- free(driver);
- }
-}
-
-/**
- * alloc_driver: allocates and initializes driver
- * returns struct sysfs_driver with success and NULL with error.
- */
-static struct sysfs_driver *alloc_driver(void)
-{
- return (struct sysfs_driver *)calloc(1, sizeof(struct sysfs_driver));
-}
-
-/**
- * get_driver_bus: gets bus the driver is on
- * Returns 0 on success and 1 on error
- */
-static int get_driver_bus(struct sysfs_driver *drv)
-{
- char drvpath[SYSFS_PATH_MAX], *c = NULL;
-
- if (!drv) {
- errno = EINVAL;
- return 1;
- }
-
- safestrcpy(drvpath, drv->path);
- c = strstr(drvpath, SYSFS_DRIVERS_NAME);
- if (c == NULL)
- return 1;
- *--c = '\0';
- c = strstr(drvpath, SYSFS_BUS_NAME);
- if (c == NULL)
- return 1;
- c = strstr(c, "/");
- if (c == NULL)
- return 1;
- c++;
- safestrcpy(drv->bus, c);
- return 0;
-}
-
-/**
- * sysfs_get_driver_attr: searches drv's attributes by name
- * @drv: driver to look through
- * @name: attribute name to get
- * returns sysfs_attribute reference with success or NULL with error.
- */
-struct sysfs_attribute *sysfs_get_driver_attr(struct sysfs_driver *drv,
- const char *name)
-{
- if (!drv || !name) {
- errno = EINVAL;
- return NULL;
- }
- return get_attribute(drv, (char *)name);
-}
-
-/**
- * sysfs_get_driver_attributes: gets list of driver attributes
- * @dev: driver whose attributes list is needed
- * returns dlist of attributes on success or NULL on error
- */
-struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *drv)
-{
- if (!drv) {
- errno = EINVAL;
- return NULL;
- }
- return get_attributes_list(drv);
-}
-
-/**
- * sysfs_open_driver_path: opens and initializes driver structure
- * @path: path to driver directory
- * returns struct sysfs_driver with success and NULL with error
- */
-struct sysfs_driver *sysfs_open_driver_path(const char *path)
-{
- struct sysfs_driver *driver = NULL;
-
- if (!path) {
- errno = EINVAL;
- return NULL;
- }
- if (sysfs_path_is_dir(path)) {
- dprintf("Invalid path to driver: %s\n", path);
- return NULL;
- }
- driver = alloc_driver();
- if (!driver) {
- dprintf("Error allocating driver at %s\n", path);
- return NULL;
- }
- if (sysfs_get_name_from_path(path, driver->name, SYSFS_NAME_LEN)) {
- dprintf("Error getting driver name from path\n");
- free(driver);
- return NULL;
- }
- safestrcpy(driver->path, path);
- if (sysfs_remove_trailing_slash(driver->path)) {
- dprintf("Invalid path to driver %s\n", driver->path);
- sysfs_close_driver(driver);
- return NULL;
- }
- if (get_driver_bus(driver)) {
- dprintf("Could not get the bus driver is on\n");
- sysfs_close_driver(driver);
- return NULL;
- }
-
- return driver;
-}
-
-/**
- * get_driver_path: looks up the bus the driver is on and builds path to
- * the driver.
- * @bus: bus on which to search
- * @drv: driver to look for
- * @path: buffer to return path to driver
- * @psize: size of "path"
- * Returns 0 on success and -1 on error
- */
-static int get_driver_path(const char *bus, const char *drv,
- char *path, size_t psize)
-{
- if (!bus || !drv || !path || psize == 0) {
- errno = EINVAL;
- return -1;
- }
- if (sysfs_get_mnt_path(path, psize)) {
- dprintf("Error getting sysfs mount path\n");
- return -1;
- }
- safestrcatmax(path, "/", psize);
- safestrcatmax(path, SYSFS_BUS_NAME, psize);
- safestrcatmax(path, "/", psize);
- safestrcatmax(path, bus, psize);
- safestrcatmax(path, "/", psize);
- safestrcatmax(path, SYSFS_DRIVERS_NAME, psize);
- safestrcatmax(path, "/", psize);
- safestrcatmax(path, drv, psize);
- return 0;
-}
-
-/**
- * sysfs_open_driver: open driver by name, given its bus
- * @bus_name: Name of the bus
- * @drv_name: Name of the driver
- * Returns the sysfs_driver reference on success and NULL on failure
- */
-struct sysfs_driver *sysfs_open_driver(const char *bus_name,
- const char *drv_name)
-{
- char path[SYSFS_PATH_MAX];
- struct sysfs_driver *driver = NULL;
-
- if (!drv_name || !bus_name) {
- errno = EINVAL;
- return NULL;
- }
-
- memset(path, 0, SYSFS_PATH_MAX);
- if (get_driver_path(bus_name, drv_name, path, SYSFS_PATH_MAX)) {
- dprintf("Error getting to driver %s\n", drv_name);
- return NULL;
- }
- driver = sysfs_open_driver_path(path);
- if (!driver) {
- dprintf("Error opening driver at %s\n", path);
- return NULL;
- }
- return driver;
-}
-
-/**
- * sysfs_get_driver_devices: gets list of devices that use the driver
- * @drv: sysfs_driver whose device list is needed
- * Returns dlist of struct sysfs_device on success and NULL on failure
- */
-struct dlist *sysfs_get_driver_devices(struct sysfs_driver *drv)
-{
- char *ln = NULL;
- struct dlist *linklist = NULL;
- struct sysfs_device *dev = NULL;
-
- if (!drv) {
- errno = EINVAL;
- return NULL;
- }
-
- linklist = read_dir_links(drv->path);
- if (linklist) {
- dlist_for_each_data(linklist, ln, char) {
-
- if (!strncmp(ln, SYSFS_MODULE_NAME, strlen(ln)))
- continue;
-
- dev = sysfs_open_device(drv->bus, ln);
- if (!dev) {
- dprintf("Error opening driver's device\n");
- sysfs_close_list(linklist);
- return NULL;
- }
- if (!drv->devices) {
- drv->devices = dlist_new_with_delete
- (sizeof(struct sysfs_device),
- sysfs_close_driver_device);
- if (!drv->devices) {
- dprintf("Error creating device list\n");
- sysfs_close_list(linklist);
- return NULL;
- }
- }
- dlist_unshift_sorted(drv->devices, dev, sort_list);
- }
- sysfs_close_list(linklist);
- }
- return drv->devices;
-}
diff --git a/libsysfs/sysfs_utils.c b/libsysfs/sysfs_utils.c
deleted file mode 100644
index c5558a43a1..0000000000
--- a/libsysfs/sysfs_utils.c
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * sysfs_utils.c
- *
- * System utility functions for libsysfs
- *
- * Copyright (C) IBM Corp. 2003-2005
- *
- * 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_remove_trailing_slash: Removes any trailing '/' in the given path
- * @path: Path to look for the trailing '/'
- * Returns 0 on success 1 on error
- */
-int sysfs_remove_trailing_slash(char *path)
-{
- size_t len;
-
- if (!path) {
- errno = EINVAL;
- return 1;
- }
-
- len = strlen(path);
- while (len > 0 && path[len-1] == '/')
- path[--len] = '\0';
- return 0;
-}
-
-/*
- * sysfs_get_mnt_path: Gets the sysfs mount point.
- * @mnt_path: place to put "sysfs" mount point
- * @len: size of mnt_path
- * returns 0 with success and -1 with error.
- */
-int sysfs_get_mnt_path(char *mnt_path, size_t len)
-{
- static char sysfs_path[SYSFS_PATH_MAX] = "";
- const char *sysfs_path_env;
-
- /* evaluate only at the first call */
- if (sysfs_path[0] == '\0') {
- /* possible overrride of real mount path */
- sysfs_path_env = getenv(SYSFS_PATH_ENV);
- if (sysfs_path_env != NULL) {
- safestrcpymax(mnt_path, sysfs_path_env, len);
- sysfs_remove_trailing_slash(mnt_path);
- return 0;
- }
- safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
- }
-
- return 0;
-}
-
-/**
- * sysfs_get_name_from_path: returns last name from a "/" delimited path
- * @path: path to get name from
- * @name: where to put name
- * @len: size of name
- */
-int sysfs_get_name_from_path(const char *path, char *name, size_t len)
-{
- char tmp[SYSFS_PATH_MAX];
- char *n = NULL;
-
- if (!path || !name || len == 0) {
- errno = EINVAL;
- return -1;
- }
- memset(tmp, 0, SYSFS_PATH_MAX);
- safestrcpy(tmp, path);
- n = strrchr(tmp, '/');
- if (n == NULL) {
- errno = EINVAL;
- return -1;
- }
- if (*(n+1) == '\0') {
- *n = '\0';
- n = strrchr(tmp, '/');
- if (n == NULL) {
- errno = EINVAL;
- return -1;
- }
- }
- n++;
- safestrcpymax(name, n, len);
- return 0;
-}
-
-/**
- * sysfs_get_link: returns link source
- * @path: symbolic link's path
- * @target: where to put name
- * @len: size of name
- */
-int sysfs_get_link(const char *path, char *target, size_t len)
-{
- char devdir[SYSFS_PATH_MAX];
- char linkpath[SYSFS_PATH_MAX];
- char temp_path[SYSFS_PATH_MAX];
- char *d = NULL, *s = NULL;
- int slashes = 0, count = 0;
-
- if (!path || !target || len == 0) {
- errno = EINVAL;
- return -1;
- }
-
- memset(devdir, 0, SYSFS_PATH_MAX);
- memset(linkpath, 0, SYSFS_PATH_MAX);
- memset(temp_path, 0, SYSFS_PATH_MAX);
- safestrcpy(devdir, path);
-
- if ((readlink(path, linkpath, SYSFS_PATH_MAX)) < 0) {
- return -1;
- }
- d = linkpath;
- /*
- * Three cases here:
- * 1. relative path => format ../..
- * 2. absolute path => format /abcd/efgh
- * 3. relative path _from_ this dir => format abcd/efgh
- */
- switch (*d) {
- case '.':
- /*
- * handle the case where link is of type ./abcd/xxx
- */
- safestrcpy(temp_path, devdir);
- if (*(d+1) == '/')
- d += 2;
- else if (*(d+1) == '.')
- goto parse_path;
- s = strrchr(temp_path, '/');
- if (s != NULL) {
- *(s+1) = '\0';
- safestrcat(temp_path, d);
- } else {
- safestrcpy(temp_path, d);
- }
- safestrcpymax(target, temp_path, len);
- break;
- /*
- * relative path, getting rid of leading "../.."
- */
-parse_path:
- while (*d == '/' || *d == '.') {
- if (*d == '/')
- slashes++;
- d++;
- }
- d--;
- s = &devdir[strlen(devdir)-1];
- while (s != NULL && count != (slashes+1)) {
- s--;
- if (*s == '/')
- count++;
- }
- safestrcpymax(s, d, (SYSFS_PATH_MAX-strlen(devdir)));
- safestrcpymax(target, devdir, len);
- break;
- case '/':
- /* absolute path - copy as is */
- safestrcpymax(target, linkpath, len);
- break;
- default:
- /* relative path from this directory */
- safestrcpy(temp_path, devdir);
- s = strrchr(temp_path, '/');
- if (s != NULL) {
- *(s+1) = '\0';
- safestrcat(temp_path, linkpath);
- } else {
- safestrcpy(temp_path, linkpath);
- }
- safestrcpymax(target, temp_path, len);
- }
- return 0;
-}
-
-/**
- * sysfs_close_list: generic list free routine
- * @list: dlist to free
- * Returns nothing
- */
-void sysfs_close_list(struct dlist *list)
-{
- if (list)
- dlist_destroy(list);
-}
-
-/**
- * sysfs_open_directory_list: gets a list of all directories under "path"
- * @path: path to read
- * Returns a dlist of supported names or NULL no directories (errno is set
- * in case of error
- */
-struct dlist *sysfs_open_directory_list(const char *path)
-{
- if (!path)
- return NULL;
-
- return (read_dir_subdirs(path));
-}
-
-/**
- * sysfs_path_is_dir: Check if the path supplied points to a directory
- * @path: path to validate
- * Returns 0 if path points to dir, 1 otherwise
- */
-int sysfs_path_is_dir(const char *path)
-{
- struct stat astats;
-
- if (!path) {
- errno = EINVAL;
- return 1;
- }
- if ((lstat(path, &astats)) != 0) {
- dprintf("stat() failed\n");
- return 1;
- }
- if (S_ISDIR(astats.st_mode))
- return 0;
-
- return 1;
-}
-
-/**
- * sysfs_path_is_link: Check if the path supplied points to a link
- * @path: path to validate
- * Returns 0 if path points to link, 1 otherwise
- */
-int sysfs_path_is_link(const char *path)
-{
- struct stat astats;
-
- if (!path) {
- errno = EINVAL;
- return 1;
- }
- if ((lstat(path, &astats)) != 0) {
- dprintf("stat() failed\n");
- return 1;
- }
- if (S_ISLNK(astats.st_mode))
- return 0;
-
- return 1;
-}
-
-/**
- * sysfs_path_is_file: Check if the path supplied points to a file
- * @path: path to validate
- * Returns 0 if path points to file, 1 otherwise
- */
-int sysfs_path_is_file(const char *path)
-{
- struct stat astats;
-
- if (!path) {
- errno = EINVAL;
- return 1;
- }
- if ((lstat(path, &astats)) != 0) {
- dprintf("stat() failed\n");
- return 1;
- }
- if (S_ISREG(astats.st_mode))
- return 0;
-
- return 1;
-}