udev_sysfs.c revision eef5447934a07279bc76f3f65b0302ddea8556ab
/*
* Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include "udev.h"
char sysfs_path[PATH_SIZE];
/* device cache */
/* attribute value cache */
struct sysfs_attr {
char *value; /* points to value_local if value is cached */
char value_local[NAME_SIZE];
};
int sysfs_init(void)
{
const char *env;
if (env) {
} else
return 0;
}
void sysfs_cleanup(void)
{
struct sysfs_attr *attr_loop;
struct sysfs_attr *attr_temp;
struct sysfs_device *dev_loop;
struct sysfs_device *dev_temp;
}
}
}
{
char *pos;
/* set kernel name */
return;
/* some devices have '!' in their name, change that to '/' */
while (pos[0] != '\0') {
if (pos[0] == '!')
pos[0] = '/';
pos++;
}
/* get kernel number */
pos--;
}
{
char devpath_real[PATH_SIZE];
struct sysfs_device *dev;
struct sysfs_device *dev_loop;
char link_target[PATH_SIZE];
int len;
char *pos;
/* look for device already in cache (we never put an untranslated path in the cache) */
return dev_loop;
}
}
/* if we got a link, resolve it to the real device */
return NULL;
}
int i;
int back;
if (len <= 0)
return NULL;
;
for (i = 0; i <= back; i++) {
return NULL;
pos[0] = '\0';
}
/* now look for device in cache after path translation */
return dev_loop;
}
}
}
/* it is a new device */
return NULL;
/* get subsystem */
pos[0] = '\0';
else
/* get subsystem from "bus" link */
if (len > 0) {
} else {
/* get subsystem from "subsystem" link */
if (len > 0) {
}
}
/* get driver name */
if (len > 0) {
}
}
dbg("add to cache 'devpath=%s', subsystem='%s', driver='%s'", dev->devpath, dev->subsystem, dev->driver);
return dev;
}
{
char parent_devpath[PATH_SIZE];
char device_link[PATH_SIZE];
char device_link_target[PATH_SIZE];
char *pos;
int i;
int len;
int back;
/* look if we already know the parent */
/* requesting a parent is only valid for devices */
return NULL;
/* strip last element */
return NULL;
pos[0] = '\0';
/* are we at the top level of /devices */
dbg("/devices top level");
return NULL;
}
dbg("/block top level, look for device link");
goto device_link;
}
dbg("/class top level, look for device link");
goto device_link;
}
}
/* get parent and remember it */
if (len < 0)
return NULL;
;
for (i = 0; i < back; i++) {
return NULL;
pos[0] = '\0';
}
/* get parent and remember it */
}
struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem)
{
struct sysfs_device *dev_parent;
while (dev_parent != NULL) {
return dev_parent;
}
return NULL;
}
{
const char *path;
struct sysfs_attr *attr_loop;
struct sysfs_attr *attr;
int fd;
/* look for attribute in cache */
}
}
/* store attribute in cache (also negatives are kept in cache) */
return NULL;
goto out;
}
/* links return the last element of the target path */
char link_target[PATH_SIZE];
int len;
const char *pos;
if (len > 0) {
}
}
} else {
/* read attribute value */
if (fd < 0) {
goto out;
}
if (size < 0)
goto out;
goto out;
/* got a valid value, store and return it */
}
out:
}