udev_sysfs.c revision 17fcfb5972977b6a3aedca6ad2aa8d1fbfbc761d
/*
* Copyright (C) 2005-2008 Kay Sievers <kay.sievers@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include "udev.h"
/* device cache */
/* attribute value cache */
struct sysfs_attr {
char path[UTIL_PATH_SIZE];
char *value; /* points to value_local if value is cached */
char value_local[UTIL_NAME_SIZE];
};
int sysfs_init(void)
{
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 path[UTIL_PATH_SIZE];
char devpath_real[UTIL_PATH_SIZE];
struct sysfs_device *dev;
struct sysfs_device *dev_loop;
char link_path[UTIL_PATH_SIZE];
char link_target[UTIL_PATH_SIZE];
int len;
char *pos;
/* we handle only these devpathes */
return NULL;
if (devpath[0] == '\0' )
return NULL;
/* 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;
}
return NULL;
/* now look for device in cache after path translation */
return dev_loop;
}
}
}
/* it is a new device */
return NULL;
/* get subsystem name */
if (len > 0) {
/* get subsystem from "subsystem" link */
}
/* get driver name */
if (len > 0) {
}
dbg(udev, "add to cache 'devpath=%s', subsystem='%s', driver='%s'\n", dev->devpath, dev->subsystem, dev->driver);
return dev;
}
{
char parent_devpath[UTIL_PATH_SIZE];
char *pos;
/* look if we already know the parent */
/* strip last element */
return NULL;
pos[0] = '\0';
goto device_link;
}
}
goto device_link;
}
/* are we at the top level? */
return NULL;
/* get parent and remember it */
return NULL;
/* get parent and remember it */
}
struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem)
{
struct sysfs_device *dev_parent;
while (dev_parent != NULL) {
return dev_parent;
}
return NULL;
}
{
char path_full[UTIL_PATH_SIZE];
const char *path;
char value[UTIL_NAME_SIZE];
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[UTIL_PATH_SIZE];
int len;
const char *pos;
if (len > 0) {
}
}
goto out;
}
/* skip directories */
goto out;
/* skip non-readable files */
goto out;
/* read attribute value */
if (fd < 0) {
goto out;
}
if (size < 0)
goto out;
goto out;
/* got a valid value, store and return it */
out:
}
int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath_full, size_t len, const char *subsystem, const char *id)
{
char path_full[UTIL_PATH_SIZE];
char *path;
goto found;
goto found;
goto out;
goto found;
}
goto found;
goto out;
}
char subsys[UTIL_NAME_SIZE];
char *driver;
driver[0] = '\0';
goto found;
goto found;
}
goto out;
}
goto found;
goto found;
goto found;
out:
return 0;
return 1;
}