#include "libsysfs/sysfs/libsysfs.h"
#include "list.h"
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_version.h"
*/
static int find_free_number(struct udevice *udev, const char *name)
{
- char devpath[NAME_SIZE];
- char filename[NAME_SIZE];
+ char devpath[PATH_SIZE];
+ char filename[PATH_SIZE];
int num = 0;
- strfieldcpy(filename, name);
+ strlcpy(filename, name, sizeof(filename));
while (1) {
dbg("look for existing node '%s'", filename);
- if (udev_db_search_name(devpath, DEVPATH_SIZE, filename) != 0) {
+ if (udev_db_search_name(devpath, sizeof(devpath), filename) != 0) {
dbg("free num=%d", num);
return num;
}
info("find_free_number gone crazy (num=%d), aborted", num);
return -1;
}
- snprintf(filename, NAME_SIZE, "%s%d", name, num);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s%d", name, num);
+ filename[sizeof(filename)-1] = '\0';
}
}
static void apply_format(struct udevice *udev, char *string, size_t maxsize,
struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
{
- char temp[NAME_SIZE];
- char temp2[NAME_SIZE];
+ char temp[PATH_SIZE];
+ char temp2[PATH_SIZE];
char *tail, *pos, *cpos, *attr, *rest;
int len;
int i;
tail = pos+1;
len = get_format_len(&tail);
c = tail[0];
- strfieldcpy(temp, tail+1);
+ strlcpy(temp, tail+1, sizeof(temp));
tail = temp;
dbg("format=%c, string='%s', tail='%s'",c , string, tail);
attr = get_format_attribute(&tail);
switch (c) {
case 'p':
- strfieldcatmax(string, udev->devpath, maxsize);
+ strlcat(string, udev->devpath, maxsize);
dbg("substitute kernel name '%s'", udev->kernel_name);
break;
case 'b':
- strfieldcatmax(string, udev->bus_id, maxsize);
+ strlcat(string, udev->bus_id, maxsize);
dbg("substitute bus_id '%s'", udev->bus_id);
break;
case 'k':
- strfieldcatmax(string, udev->kernel_name, maxsize);
+ strlcat(string, udev->kernel_name, maxsize);
dbg("substitute kernel name '%s'", udev->kernel_name);
break;
case 'n':
- strfieldcatmax(string, udev->kernel_number, maxsize);
+ strlcat(string, udev->kernel_number, maxsize);
dbg("substitute kernel number '%s'", udev->kernel_number);
break;
case 'm':
sprintf(temp2, "%d", minor(udev->devt));
- strfieldcatmax(string, temp2, maxsize);
+ strlcat(string, temp2, maxsize);
dbg("substitute minor number '%s'", temp2);
break;
case 'M':
sprintf(temp2, "%d", major(udev->devt));
- strfieldcatmax(string, temp2, maxsize);
+ strlcat(string, temp2, maxsize);
dbg("substitute major number '%s'", temp2);
break;
case 'c':
dbg("requested part of result string not found");
break;
}
- strfieldcpy(temp2, cpos);
+ strlcpy(temp2, cpos, sizeof(temp2));
/* %{2+}c copies the whole string from the second part on */
if (rest[0] != '+') {
cpos = strchr(temp2, ' ');
if (cpos)
cpos[0] = '\0';
}
- strfieldcatmax(string, temp2, maxsize);
+ strlcat(string, temp2, maxsize);
dbg("substitute part of result string '%s'", temp2);
} else {
- strfieldcatmax(string, udev->program_result, maxsize);
+ strlcat(string, udev->program_result, maxsize);
dbg("substitute result string '%s'", udev->program_result);
}
break;
len - i, tmpattr->value);
}
}
- strfieldcatmax(string, tmpattr->value, maxsize);
+ strlcat(string, tmpattr->value, maxsize);
dbg("substitute sysfs value '%s'", tmpattr->value);
break;
case '%':
- strfieldcatmax(string, "%", maxsize);
+ strlcat(string, "%", maxsize);
pos++;
break;
case 'e':
next_free_number = find_free_number(udev, string);
if (next_free_number > 0) {
sprintf(temp2, "%d", next_free_number);
- strfieldcatmax(string, temp2, maxsize);
+ strlcat(string, temp2, maxsize);
}
break;
case 'P':
udev_init_device(&udev_parent, NULL, NULL);
/* lookup the name in the udev_db with the DEVPATH of the parent */
if (udev_db_get_device(&udev_parent, &class_dev_parent->path[strlen(sysfs_path)]) == 0) {
- strfieldcatmax(string, udev_parent.name, maxsize);
+ strlcat(string, udev_parent.name, maxsize);
dbg("substitute parent node name'%s'", udev_parent.name);
} else
dbg("parent not found in database");
case 'N':
if (udev->tmp_node[0] == '\0') {
dbg("create temporary device node for callout");
- snprintf(udev->tmp_node, NAME_SIZE, "%s/.tmp-%u-%u", udev_root, major(udev->devt), minor(udev->devt));
- udev->tmp_node[NAME_SIZE] = '\0';
+ snprintf(udev->tmp_node, sizeof(udev->tmp_node), "%s/.tmp-%u-%u",
+ udev_root, major(udev->devt), minor(udev->devt));
+ udev->tmp_node[sizeof(udev->tmp_node)-1] = '\0';
udev_make_node(udev, udev->tmp_node, udev->devt, 0600, 0, 0);
}
- strfieldcatmax(string, udev->tmp_node, maxsize);
+ strlcat(string, udev->tmp_node, maxsize);
dbg("substitute temporary device node name '%s'", udev->tmp_node);
break;
case 'r':
- strfieldcatmax(string, udev_root, maxsize);
+ strlcat(string, udev_root, maxsize);
dbg("substitute udev_root '%s'", udev_root);
break;
default:
if (len > 0)
pos[len] = '\0';
- strfieldcatmax(string, tail, maxsize);
+ strlcat(string, tail, maxsize);
}
}
int fds[2];
pid_t pid;
char *pos;
- char arg[PROGRAM_SIZE];
- char *argv[(PROGRAM_SIZE / 2) + 1];
+ char arg[PATH_SIZE];
+ char *argv[(sizeof(arg) / 2) + 1];
int i;
- strfieldcpy(arg, path);
+ strlcpy(arg, path, sizeof(arg));
i = 0;
if (strchr(path, ' ')) {
pos = arg;
static int match_id(struct config_device *dev, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
{
- char path[SYSFS_PATH_MAX];
+ char path[PATH_SIZE];
char *temp;
/* we have to have a sysfs device for ID to work */
if (!sysfs_device)
return -ENODEV;
- strfieldcpy(path, sysfs_device->path);
+ strlcpy(path, sysfs_device->path, sizeof(path));
temp = strrchr(path, '/');
temp++;
dbg("search '%s' in '%s', path='%s'", dev->id, temp, path);
static int match_place(struct config_device *dev, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
{
- char path[SYSFS_PATH_MAX];
+ char path[PATH_SIZE];
char *temp;
/* we have to have a sysfs device for PLACE to work */
if (!sysfs_device)
return -ENODEV;
- strfieldcpy(path, sysfs_device->path);
+ strlcpy(path, sysfs_device->path, sizeof(path));
temp = strrchr(path, '/');
dbg("search '%s' in '%s', path='%s'", dev->place, temp, path);
if (strstr(temp, dev->place) != NULL)
/* execute external program */
if (dev->program[0] != '\0') {
- char program[PROGRAM_SIZE];
+ char program[PATH_SIZE];
dbg("check " FIELD_PROGRAM);
- strfieldcpy(program, dev->program);
+ strlcpy(program, dev->program, sizeof(program));
apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
- if (execute_program(udev, program, udev->program_result, NAME_SIZE) != 0) {
+ if (execute_program(udev, program, udev->program_result, sizeof(udev->program_result)) != 0) {
dbg(FIELD_PROGRAM " returned nonzero");
goto try_parent;
}
if (sysfs_device) {
dbg("found devices device: path='%s', bus_id='%s', bus='%s'",
sysfs_device->path, sysfs_device->bus_id, sysfs_device->bus);
- strfieldcpy(udev->bus_id, sysfs_device->bus_id);
+ strlcpy(udev->bus_id, sysfs_device->bus_id, sizeof(udev->bus_id));
}
dbg("udev->kernel_name='%s'", udev->kernel_name);
dbg("applied mode=%#o to '%s'", udev->mode, udev->kernel_name);
}
if (dev->owner[0] != '\0') {
- strfieldcpy(udev->owner, dev->owner);
+ strlcpy(udev->owner, dev->owner, sizeof(udev->owner));
apply_format(udev, udev->owner, sizeof(udev->owner), class_dev, sysfs_device);
dbg("applied owner='%s' to '%s'", udev->owner, udev->kernel_name);
}
if (dev->group[0] != '\0') {
- strfieldcpy(udev->group, dev->group);
+ strlcpy(udev->group, dev->group, sizeof(udev->group));
apply_format(udev, udev->group, sizeof(udev->group), class_dev, sysfs_device);
dbg("applied group='%s' to '%s'", udev->group, udev->kernel_name);
}
/* collect symlinks */
if (dev->symlink[0] != '\0') {
- char temp[NAME_SIZE];
+ char temp[PATH_SIZE];
char *pos, *next;
info("configured rule in '%s[%i]' applied, added symlink '%s'",
dev->config_file, dev->config_line, dev->symlink);
- strfieldcpy(temp, dev->symlink);
+ strlcpy(temp, dev->symlink, sizeof(temp));
apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device);
/* add multiple symlinks separated by spaces */
info("configured rule in '%s[%i]' applied, '%s' becomes '%s'",
dev->config_file, dev->config_line, udev->kernel_name, dev->name);
- strfieldcpy(udev->name, dev->name);
+ strlcpy(udev->name, dev->name, sizeof(udev->name));
apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
- strfieldcpy(udev->config_file, dev->config_file);
+ strlcpy(udev->config_file, dev->config_file, sizeof(udev->config_file));
udev->config_line = dev->config_line;
if (udev->type != NET)
if (udev->name[0] == '\0') {
/* no rule matched, so we use the kernel name */
- strfieldcpy(udev->name, udev->kernel_name);
+ strlcpy(udev->name, udev->kernel_name, sizeof(udev->name));
dbg("no rule found, use kernel name '%s'", udev->name);
}
struct sysfs_class_device;
-#define BUS_SIZE 32
-#define FILE_SIZE 64
-#define VALUE_SIZE 128
-#define ID_SIZE 64
-#define PLACE_SIZE 64
-#define DRIVER_SIZE 64
-#define PROGRAM_SIZE 128
-
#define FIELD_KERNEL "KERNEL"
#define FIELD_SUBSYSTEM "SUBSYSTEM"
#define FIELD_BUS "BUS"
#define RULEFILE_SUFFIX ".rules"
struct sysfs_pair {
- char file[FILE_SIZE];
+ char file[PATH_SIZE];
char value[VALUE_SIZE];
};
struct list_head node;
char kernel[NAME_SIZE];
- char subsystem[SUBSYSTEM_SIZE];
- char bus[BUS_SIZE];
- char id[ID_SIZE];
- char place[PLACE_SIZE];
+ char subsystem[NAME_SIZE];
+ char bus[NAME_SIZE];
+ char id[NAME_SIZE];
+ char place[NAME_SIZE];
struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
- char program[PROGRAM_SIZE];
- char result[PROGRAM_SIZE];
- char driver[DRIVER_SIZE];
- char name[NAME_SIZE];
- char symlink[NAME_SIZE];
+ char program[PATH_SIZE];
+ char result[PATH_SIZE];
+ char driver[NAME_SIZE];
+ char name[PATH_SIZE];
+ char symlink[PATH_SIZE];
char owner[USER_SIZE];
char group[USER_SIZE];
int ignore_device;
int ignore_remove;
- char config_file[NAME_SIZE];
+ char config_file[PATH_SIZE];
int config_line;
};
#include <sys/stat.h>
#include <errno.h>
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "logging.h"
cur += count+1;
lineno++;
- if (count >= LINE_SIZE) {
+ if (count >= sizeof(line)) {
info("line too long, rule skipped %s, line %d", filename, lineno);
continue;
}
break;
if (strcasecmp(temp2, FIELD_KERNEL) == 0) {
- strfieldcpy(dev.kernel, temp3);
+ strlcpy(dev.kernel, temp3, sizeof(dev.kernel));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_SUBSYSTEM) == 0) {
- strfieldcpy(dev.subsystem, temp3);
+ strlcpy(dev.subsystem, temp3, sizeof(dev.subsystem));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_BUS) == 0) {
- strfieldcpy(dev.bus, temp3);
+ strlcpy(dev.bus, temp3, sizeof(dev.bus));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_ID) == 0) {
- strfieldcpy(dev.id, temp3);
+ strlcpy(dev.id, temp3, sizeof(dev.id));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_PLACE) == 0) {
- strfieldcpy(dev.place, temp3);
+ strlcpy(dev.place, temp3, sizeof(dev.place));
valid = 1;
continue;
}
dbg("error parsing " FIELD_SYSFS " attribute");
continue;
}
- strfieldcpy(pair->file, attr);
- strfieldcpy(pair->value, temp3);
+ strlcpy(pair->file, attr, sizeof(pair->file));
+ strlcpy(pair->value, temp3, sizeof(pair->value));
valid = 1;
}
continue;
}
if (strcasecmp(temp2, FIELD_DRIVER) == 0) {
- strfieldcpy(dev.driver, temp3);
+ strlcpy(dev.driver, temp3, sizeof(dev.driver));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_PROGRAM) == 0) {
program_given = 1;
- strfieldcpy(dev.program, temp3);
+ strlcpy(dev.program, temp3, sizeof(dev.program));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_RESULT) == 0) {
- strfieldcpy(dev.result, temp3);
+ strlcpy(dev.result, temp3, sizeof(dev.result));
valid = 1;
continue;
}
}
}
if (temp3[0] != '\0')
- strfieldcpy(dev.name, temp3);
+ strlcpy(dev.name, temp3, sizeof(dev.name));
else
dev.ignore_device = 1;
valid = 1;
}
if (strcasecmp(temp2, FIELD_SYMLINK) == 0) {
- strfieldcpy(dev.symlink, temp3);
+ strlcpy(dev.symlink, temp3, sizeof(dev.symlink));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_OWNER) == 0) {
- strfieldcpy(dev.owner, temp3);
+ strlcpy(dev.owner, temp3, sizeof(dev.owner));
valid = 1;
continue;
}
if (strcasecmp(temp2, FIELD_GROUP) == 0) {
- strfieldcpy(dev.group, temp3);
+ strlcpy(dev.group, temp3, sizeof(dev.group));
valid = 1;
continue;
}
}
dev.config_line = lineno;
- strfieldcpy(dev.config_file, filename);
+ strlcpy(dev.config_file, filename, sizeof(dev.config_file));
retval = add_config_dev(&dev);
if (retval) {
dbg("add_config_dev returned with error %d", retval);
#include <unistd.h>
#include "libsysfs/sysfs/libsysfs.h"
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_sysfs.h"
struct sysfs_class_device *class_dev;
struct sysfs_device *devices_dev;
struct udevice udev;
- char path[SYSFS_PATH_MAX];
+ char path[PATH_SIZE];
const char *error;
const char *action;
const char *devpath;
goto hotplug;
}
- snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
+ snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
+ path[sizeof(path)-1] = '\0';
class_dev = wait_class_device_open(path);
if (class_dev == NULL) {
dbg ("open class device failed");
/* wait for sysfs */
dbg("devices add");
- snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath);
+ snprintf(path, sizeof(path), "%s%s", sysfs_path, devpath);
+ path[sizeof(path)-1] = '\0';
devices_dev = wait_devices_device_open(path);
if (!devices_dev) {
dbg("devices device unavailable (probably remove has beaten us)");
#define COMMENT_CHARACTER '#'
#define LINE_SIZE 512
-#define NAME_SIZE 256
+#define NAME_SIZE 128
+#define PATH_SIZE 256
#define USER_SIZE 32
-
-#define ACTION_SIZE 32
-#define DEVPATH_SIZE 256
-#define SUBSYSTEM_SIZE 32
#define SEQNUM_SIZE 32
+#define VALUE_SIZE 128
#define DEVD_DIR "/etc/dev.d"
#define DEVD_SUFFIX ".dev"
};
struct udevice {
- char devpath[DEVPATH_SIZE];
- char subsystem[SUBSYSTEM_SIZE];
+ char devpath[PATH_SIZE];
+ char subsystem[NAME_SIZE];
- char name[NAME_SIZE];
- char devname[NAME_SIZE];
+ char name[PATH_SIZE];
+ char devname[PATH_SIZE];
struct list_head symlink_list;
char owner[USER_SIZE];
char group[USER_SIZE];
char type;
dev_t devt;
- char tmp_node[NAME_SIZE];
+ char tmp_node[PATH_SIZE];
int partitions;
int ignore_remove;
int config_line;
- char config_file[NAME_SIZE];
- char bus_id[SYSFS_NAME_LEN];
- char program_result[NAME_SIZE];
+ char config_file[PATH_SIZE];
+ char bus_id[NAME_SIZE];
+ char program_result[PATH_SIZE];
char kernel_number[NAME_SIZE];
char kernel_name[NAME_SIZE];
int test_run;
extern void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix);
extern int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
-extern char sysfs_path[SYSFS_PATH_MAX];
-extern char udev_root[PATH_MAX];
-extern char udev_db_path[PATH_MAX+NAME_MAX];
-extern char udev_config_filename[PATH_MAX+NAME_MAX];
-extern char udev_rules_filename[PATH_MAX+NAME_MAX];
+extern char sysfs_path[PATH_SIZE];
+extern char udev_root[PATH_SIZE];
+extern char udev_db_path[PATH_SIZE];
+extern char udev_config_filename[PATH_SIZE];
+extern char udev_rules_filename[PATH_SIZE];
extern int udev_log;
extern int udev_dev_d;
extern int udev_hotplug_d;
static int create_node(struct udevice *udev, struct sysfs_class_device *class_dev)
{
- char filename[NAME_SIZE];
- char partitionname[NAME_SIZE];
+ char filename[PATH_SIZE];
+ char partitionname[PATH_SIZE];
struct name_entry *name_loop;
uid_t uid = 0;
gid_t gid = 0;
int tail;
int i;
- snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", udev_root, udev->name);
+ filename[sizeof(filename)-1] = '\0';
/* create parent directories if needed */
if (strchr(udev->name, '/'))
for (i = 1; i <= udev->partitions; i++) {
dev_t part_devt;
- snprintf(partitionname, NAME_SIZE, "%s%d", filename, i);
- partitionname[NAME_SIZE-1] = '\0';
+ snprintf(partitionname, sizeof(partitionname), "%s%d", filename, i);
+ partitionname[sizeof(partitionname)-1] = '\0';
part_devt = makedev(major(udev->devt), minor(udev->devt)+1);
udev_make_node(udev, partitionname, part_devt, udev->mode, uid, gid);
}
/* create symlink(s) if requested */
list_for_each_entry(name_loop, &udev->symlink_list, node) {
- char linktarget[NAME_SIZE];
+ char linktarget[PATH_SIZE];
- snprintf(filename, NAME_SIZE, "%s/%s", udev_root, name_loop->name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
+ filename[sizeof(filename)-1] = '\0';
dbg("symlink '%s' to node '%s' requested", filename, udev->name);
if (!udev->test_run)
}
while (name_loop->name[i] != '\0') {
if (name_loop->name[i] == '/')
- strfieldcat(linktarget, "../");
+ strlcat(linktarget, "../", sizeof(linktarget));
i++;
}
- strfieldcat(linktarget, &udev->name[tail]);
+ strlcat(linktarget, &udev->name[tail], sizeof(linktarget));
dbg("symlink(%s, %s)", linktarget, filename);
if (!udev->test_run) {
}
memset(&ifr, 0x00, sizeof(struct ifreq));
- strfieldcpy(ifr.ifr_name, udev->kernel_name);
- strfieldcpy(ifr.ifr_newname, udev->name);
+ strlcpy(ifr.ifr_name, udev->kernel_name, IFNAMSIZ);
+ strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
retval = ioctl(sk, SIOCSIFNAME, &ifr);
if (retval != 0)
"remove might not work for custom names");
/* use full path to the environment */
- snprintf(udev->devname, NAME_SIZE, "%s/%s", udev_root, udev->name);
- udev->devname[NAME_SIZE-1] = '\0';
+ snprintf(udev->devname, sizeof(udev->devname), "%s/%s", udev_root, udev->name);
+ udev->devname[sizeof(udev->devname)-1] = '\0';
} else if (udev->type == NET) {
/* look if we want to change the name of the netif */
pos = strrchr(udev->devpath, '/');
if (pos != NULL) {
pos[1] = '\0';
- strfieldcat(udev->devpath, udev->name);
+ strlcat(udev->devpath, udev->name, sizeof(udev->devpath));
setenv("DEVPATH", udev->devpath, 1);
setenv("INTERFACE", udev->name, 1);
}
/* use netif name for the environment */
- strfieldcpy(udev->devname, udev->name);
+ strlcpy(udev->devname, udev->name, sizeof(udev->devname));
}
}
#include <ctype.h>
#include "libsysfs/sysfs/libsysfs.h"
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_version.h"
#include "namedev.h"
/* global variables */
-char sysfs_path[SYSFS_PATH_MAX];
-char udev_root[PATH_MAX];
-char udev_db_path[PATH_MAX+NAME_MAX];
-char udev_rules_filename[PATH_MAX+NAME_MAX];
-char udev_config_filename[PATH_MAX+NAME_MAX];
+char sysfs_path[PATH_SIZE];
+char udev_root[PATH_SIZE];
+char udev_db_path[PATH_SIZE];
+char udev_rules_filename[PATH_SIZE];
+char udev_config_filename[PATH_SIZE];
int udev_log;
int udev_dev_d;
int udev_hotplug_d;
int lineno;
int retval = 0;
- if (file_map(udev_config_filename, &buf, &bufsize) == 0) {
- dbg("reading '%s' as config file", udev_config_filename);
- } else {
+ if (file_map(udev_config_filename, &buf, &bufsize) != 0) {
dbg("can't open '%s' as config file", udev_config_filename);
return -ENODEV;
}
+ dbg("reading '%s' as config file", udev_config_filename);
/* loop through the whole file */
lineno = 0;
cur += count+1;
lineno++;
- if (count >= LINE_SIZE) {
+ if (count >= sizeof(line)) {
info("line too long, conf line skipped %s, line %d",
udev_config_filename, lineno);
continue;
if (bufline[0] == COMMENT_CHARACTER)
continue;
- strncpy(line, bufline, count);
- line[count] = '\0';
+ strlcpy(line, bufline, count);
temp = line;
dbg_parse("read '%s'", temp);
dbg_parse("variable='%s', value='%s'", variable, value);
if (strcasecmp(variable, "udev_root") == 0) {
- strfieldcpy(udev_root, value);
+ strlcpy(udev_root, value, sizeof(udev_root));
no_trailing_slash(udev_root);
continue;
}
if (strcasecmp(variable, "udev_db") == 0) {
- strfieldcpy(udev_db_path, value);
+ strlcpy(udev_db_path, value, sizeof(udev_db_path));
no_trailing_slash(udev_db_path);
continue;
}
if (strcasecmp(variable, "udev_rules") == 0) {
- strfieldcpy(udev_rules_filename, value);
+ strlcpy(udev_rules_filename, value, sizeof(udev_rules_filename));
no_trailing_slash(udev_rules_filename);
continue;
}
char *temp;
int retval;
- retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
+ retval = sysfs_get_mnt_path(sysfs_path, sizeof(sysfs_path));
if (retval)
dbg("sysfs_get_mnt_path failed");
if (getenv("UDEV_TEST") != NULL) {
temp = getenv("SYSFS_PATH");
if (temp != NULL) {
- strfieldcpy(sysfs_path, temp);
+ strlcpy(sysfs_path, temp, sizeof(sysfs_path));
no_trailing_slash(sysfs_path);
}
temp = getenv("UDEV_CONFIG_FILE");
if (temp != NULL)
- strfieldcpy(udev_config_filename, temp);
+ strlcpy(udev_config_filename, temp, sizeof(udev_config_filename));
}
parse_config_file();
#include <dirent.h>
#include "libsysfs/sysfs/libsysfs.h"
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "logging.h"
static int get_db_filename(const char *devpath, char *filename, int len)
{
- char temp[SYSFS_PATH_MAX];
+ char temp[PATH_SIZE];
char *pos;
/* replace '/' to transform path into a filename */
- strfieldcpy(temp, devpath);
+ strlcpy(temp, devpath, sizeof(temp));
pos = strchr(&temp[1], '/');
while (pos) {
pos[0] = PATH_TO_NAME_CHAR;
int udev_db_add_device(struct udevice *udev)
{
- char filename[SYSFS_PATH_MAX];
+ char filename[PATH_SIZE];
struct name_entry *name_loop;
FILE *f;
if (udev->test_run)
return 0;
- get_db_filename(udev->devpath, filename, SYSFS_PATH_MAX);
+ get_db_filename(udev->devpath, filename, sizeof(filename));
create_path(filename);
static int parse_db_file(struct udevice *udev, const char *filename)
{
- char line[NAME_SIZE];
- char temp[NAME_SIZE];
+ char line[PATH_SIZE];
unsigned int major, minor;
char *bufline;
char *buf;
switch(bufline[0]) {
case 'P':
- if (count > DEVPATH_SIZE)
- count = DEVPATH_SIZE-1;
- strncpy(udev->devpath, &bufline[2], count-2);
- udev->devpath[count-2] = '\0';
+ if (count > sizeof(udev->devpath))
+ count = sizeof(udev->devpath)-1;
+ strlcpy(udev->devpath, &bufline[2], count-2);
break;
case 'N':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(udev->name, &bufline[2], count-2);
- udev->name[count-2] = '\0';
+ if (count > sizeof(udev->name))
+ count = sizeof(udev->name)-1;
+ strlcpy(udev->name, &bufline[2], count-2);
break;
case 'M':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(temp, &bufline[2], count-2);
- temp[count-2] = '\0';
- sscanf(temp, "%u:%u", &major, &minor);
+ if (count > sizeof(line))
+ count = sizeof(line)-1;
+ strlcpy(line, &bufline[2], count-2);
+ sscanf(line, "%u:%u", &major, &minor);
udev->devt = makedev(major, minor);
break;
case 'S':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(temp, &bufline[2], count-2);
- temp[count-2] = '\0';
- name_list_add(&udev->symlink_list, temp, 0);
+ if (count > sizeof(line))
+ count = sizeof(line)-1;
+ strlcpy(line, &bufline[2], count-2);
+ name_list_add(&udev->symlink_list, line, 0);
break;
case 'A':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(line, &bufline[2], count-2);
- line[count-2] = '\0';
+ if (count > sizeof(line))
+ count = sizeof(line)-1;
+ strlcpy(line, &bufline[2], count-2);
udev->partitions = atoi(line);
break;
case 'R':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(line, &bufline[2], count-2);
- line[count-2] = '\0';
+ if (count > sizeof(line))
+ count = sizeof(line)-1;
+ strlcpy(line, &bufline[2], count-2);
udev->ignore_remove = atoi(line);
break;
}
int udev_db_delete_device(struct udevice *udev)
{
- char filename[SYSFS_PATH_MAX];
+ char filename[PATH_SIZE];
- get_db_filename(udev->devpath, filename, SYSFS_PATH_MAX);
+ get_db_filename(udev->devpath, filename, sizeof(filename));
unlink(filename);
return 0;
int udev_db_get_device(struct udevice *udev, const char *devpath)
{
- char filename[SYSFS_PATH_MAX];
+ char filename[PATH_SIZE];
- get_db_filename(devpath, filename, SYSFS_PATH_MAX);
+ get_db_filename(devpath, filename, sizeof(filename));
if (parse_db_file(udev, filename) != 0)
return -1;
while (1) {
struct dirent *ent;
- char filename[NAME_SIZE];
- char path[DEVPATH_SIZE];
- char nodename[NAME_SIZE];
+ char filename[PATH_SIZE];
+ char path[PATH_SIZE];
+ char nodename[PATH_SIZE];
char *bufline;
char *buf;
size_t bufsize;
if (ent->d_name[0] == '.')
continue;
- snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", udev_db_path, ent->d_name);
+ filename[sizeof(filename)-1] = '\0';
dbg("looking at '%s'", filename);
if (file_map(filename, &buf, &bufsize) != 0) {
switch(bufline[0]) {
case 'P':
- if (count > DEVPATH_SIZE)
- count = DEVPATH_SIZE-1;
- strncpy(path, &bufline[2], count-2);
- path[count-2] = '\0';
+ if (count > sizeof(path))
+ count = sizeof(path)-1;
+ strlcpy(path, &bufline[2], count-2);
break;
case 'N':
case 'S':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(nodename, &bufline[2], count-2);
- nodename[count-2] = '\0';
+ if (count > sizeof(nodename))
+ count = sizeof(nodename)-1;
+ strlcpy(nodename, &bufline[2], count-2);
dbg("compare '%s' '%s'", nodename, name);
if (strcmp(nodename, name) == 0) {
- strncpy(devpath, path, len);
- devpath[len] = '\0';
+ strlcpy(devpath, path, len);
file_unmap(buf, bufsize);
closedir(dir);
return 0;
while (1) {
struct dirent *ent;
- char filename[NAME_SIZE];
- char path[DEVPATH_SIZE];
- char nodename[NAME_SIZE];
+ char filename[PATH_SIZE];
+ char path[PATH_SIZE];
+ char nodename[PATH_SIZE];
char *bufline;
char *buf;
size_t bufsize;
if (ent->d_name[0] == '.')
continue;
- snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", udev_db_path, ent->d_name);
+ filename[sizeof(filename)-1] = '\0';
dbg("looking at '%s'", filename);
if (file_map(filename, &buf, &bufsize) != 0) {
switch(bufline[0]) {
case 'P':
- if (count > DEVPATH_SIZE)
- count = DEVPATH_SIZE-1;
- strncpy(path, &bufline[2], count-2);
- path[count-2] = '\0';
+ if (count > sizeof(path))
+ count = sizeof(path)-1;
+ strlcpy(path, &bufline[2], count-2);
break;
case 'N':
- if (count > NAME_SIZE)
- count = NAME_SIZE-1;
- strncpy(nodename, &bufline[2], count-2);
- nodename[count-2] = '\0';
+ if (count > sizeof(nodename))
+ count = sizeof(nodename)-1;
+ strlcpy(nodename, &bufline[2], count-2);
break;
default:
continue;
#include "../udev_utils.h"
#include "../logging.h"
-
#ifdef __KLIBC__
#define __OWN_USERDB_PARSER__
#endif
+
#ifdef USE_STATIC
#define __OWN_USERDB_PARSER__
#endif
-#ifndef __OWN_USERDB_PARSER__
+#ifndef strlcpy
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while ((ch = *p++)) {
+ if (bytes < size)
+ *q++ = ch;
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+#endif
+
+#ifndef strlcat
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while (bytes < size && *q) {
+ q++;
+ bytes++;
+ }
+ while ((ch = *p++)) {
+ if (bytes < size)
+ *q++ = ch;
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+#endif
+
+#ifndef __OWN_USERDB_PARSER__
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
bufline = &buf[cur];
cur += count+1;
- if (count >= LINE_SIZE)
+ if (count >= sizeof(line))
continue;
- strncpy(line, bufline, count);
- line[count] = '\0';
+ strlcpy(line, bufline, count);
pos = line;
/* get name */
id = get_id_by_name(group, GROUP_FILE);
return (gid_t) id;
}
-
#endif /* __OWN_USERDB_PARSER__ */
#ifndef _UDEV_LIBC_WRAPPER_H_
#define _UDEV_LIBC_WRAPPER_H_
+#ifdef asmlinkage
+# undef asmlinkage
+#endif
+#ifdef __i386__
+# define asmlinkage __attribute__((regparm(0)))
+#endif
+#ifndef asmlinkage
+# define asmlinkage
+#endif
+
+#include <string.h>
+
extern uid_t lookup_user(const char *user);
extern gid_t lookup_group(const char *group);
+#ifndef strlcat
+extern size_t strlcpy(char *dst, const char *src, size_t size);
+#endif
+
+#ifndef strlcat
+extern size_t strlcat(char *dst, const char *src, size_t size);
+#endif
+
#endif /* _UDEV_LIBC_WRAPPER_H_ */
#include <fcntl.h>
#include "udev.h"
+#include "udev_libc_wrapper.h"
#include "udev_utils.h"
#include "logging.h"
*/
void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix)
{
- char dirname[PATH_MAX];
+ char dirname[PATH_SIZE];
/* chop the device name up into pieces based on '/' */
if (udev->name[0] != '\0') {
- char devname[NAME_SIZE];
+ char devname[PATH_SIZE];
char *temp;
- strfieldcpy(devname, udev->name);
+ strlcpy(devname, udev->name, sizeof(devname));
temp = strchr(devname, '/');
while (temp != NULL) {
temp[0] = '\0';
/* don't call the subsystem directory here */
if (strcmp(devname, udev->subsystem) != 0) {
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, devname);
- dirname[PATH_MAX-1] = '\0';
+ snprintf(dirname, sizeof(dirname), "%s/%s", basedir, devname);
+ dirname[sizeof(dirname)-1] = '\0';
call_foreach_file(run_program, udev, dirname, suffix);
}
}
if (udev->name[0] != '\0') {
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
- dirname[PATH_MAX-1] = '\0';
+ snprintf(dirname, sizeof(dirname), "%s/%s", basedir, udev->name);
+ dirname[sizeof(dirname)-1] = '\0';
call_foreach_file(run_program, udev, dirname, suffix);
}
if (udev->subsystem[0] != '\0') {
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
- dirname[PATH_MAX-1] = '\0';
+ snprintf(dirname, sizeof(dirname), "%s/%s", basedir, udev->subsystem);
+ dirname[sizeof(dirname)-1] = '\0';
call_foreach_file(run_program, udev, dirname, suffix);
}
- snprintf(dirname, PATH_MAX, "%s/default", basedir);
- dirname[PATH_MAX-1] = '\0';
+ snprintf(dirname, sizeof(dirname), "%s/default", basedir);
+ dirname[sizeof(dirname)-1] = '\0';
call_foreach_file(run_program, udev, dirname, suffix);
}
#include <errno.h>
#include <sys/stat.h>
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_version.h"
static int delete_node(struct udevice *udev)
{
- char filename[NAME_SIZE];
- char partitionname[NAME_SIZE];
+ char filename[PATH_SIZE];
+ char partitionname[PATH_SIZE];
struct name_entry *name_loop;
struct stat stats;
int retval;
int i;
int num;
- snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", udev_root, udev->name);
+ filename[sizeof(filename)-1] = '\0';
dbg("checking major/minor of device node '%s'", filename);
if (stat(filename, &stats) != 0)
return -1;
}
for (i = 1; i <= num; i++) {
- snprintf(partitionname, NAME_SIZE, "%s%d", filename, i);
- partitionname[NAME_SIZE-1] = '\0';
+ snprintf(partitionname, sizeof(partitionname), "%s%d", filename, i);
+ partitionname[sizeof(partitionname)-1] = '\0';
unlink_secure(partitionname);
}
}
delete_path(filename);
list_for_each_entry(name_loop, &udev->symlink_list, node) {
- snprintf(filename, NAME_SIZE, "%s/%s", udev_root, name_loop->name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
+ filename[sizeof(filename)-1] = '\0';
dbg("unlinking symlink '%s'", filename);
retval = unlink(filename);
temp = strrchr(udev->devpath, '/');
if (temp == NULL)
return -ENODEV;
- strfieldcpy(udev->name, &temp[1]);
+ strlcpy(udev->name, &temp[1], sizeof(udev->name));
dbg("'%s' not found in database, falling back on default name", udev->name);
}
/* use full path to the environment */
- snprintf(udev->devname, NAME_SIZE, "%s/%s", udev_root, udev->name);
+ snprintf(udev->devname, sizeof(udev->devname), "%s/%s", udev_root, udev->name);
+ udev->devname[sizeof(udev->devname)-1] = '\0';
return delete_node(udev);
}
const char **error)
{
const char *file;
- char filename[SYSFS_PATH_MAX];
+ char filename[PATH_SIZE];
int loop;
file = get_subsystem_specific_file(class_dev->classname);
return 0;
}
- snprintf(filename, SYSFS_PATH_MAX-1, "%s/%s", class_dev->path, file);
+ snprintf(filename, sizeof(filename), "%s/%s", class_dev->path, file);
+ filename[sizeof(filename)-1] = '\0';
dbg("looking at class '%s' for specific file '%s'", class_dev->classname, filename);
loop = WAIT_MAX_SECONDS * WAIT_LOOP_PER_SECOND;
for (devicefile = device_files; devicefile->bus != NULL; devicefile++) {
if (strcmp(devices_dev->bus, devicefile->bus) == 0) {
- char filename[SYSFS_PATH_MAX];
+ char filename[PATH_SIZE];
struct stat stats;
if (devicefile->file == NULL) {
}
found_bus_type = 1;
- snprintf(filename, SYSFS_PATH_MAX-1, "%s/%s", devices_dev->path, devicefile->file);
+ snprintf(filename, sizeof(filename), "%s/%s", devices_dev->path, devicefile->file);
+ filename[sizeof(filename)-1] = '\0';
dbg("looking at bus '%s' device for specific file '%s'", devices_dev->bus, filename);
if (stat(filename, &stats) == 0) {
#include <sys/mman.h>
#include <sys/utsname.h>
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "logging.h"
#include "udev_utils.h"
INIT_LIST_HEAD(&udev->symlink_list);
if (subsystem)
- strfieldcpy(udev->subsystem, subsystem);
+ strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem));
if (devpath) {
- strfieldcpy(udev->devpath, devpath);
+ strlcpy(udev->devpath, devpath, sizeof(udev->devpath));
no_trailing_slash(udev->devpath);
if (strncmp(udev->devpath, "/block/", 7) == 0)
/* get kernel name */
pos = strrchr(udev->devpath, '/');
if (pos) {
- strfieldcpy(udev->kernel_name, &pos[1]);
+ strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name));
dbg("kernel_name='%s'", udev->kernel_name);
/* Some block devices have '!' in their name, change that to '/' */
pos = &udev->kernel_name[strlen(udev->kernel_name)];
while (isdigit(pos[-1]))
pos--;
- strfieldcpy(udev->kernel_number, pos);
+ strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number));
dbg("kernel_number='%s'", udev->kernel_number);
}
}
int create_path(const char *path)
{
- char p[NAME_SIZE];
+ char p[PATH_SIZE];
char *pos;
struct stat stats;
return -ENODEV;
/* take the right side and strip off the '"' */
- while (isspace(*string))
+ while (isspace(string[0]))
++string;
- if (*string == '"')
+ if (string[0] == '"')
++string;
else
return -ENODEV;
temp = strsep(&string, "\"");
- if (!string || *temp == '\0')
+ if (!string || temp[0] == '\0')
return -ENODEV;
*right = temp;
*orig_string = string;
-
+
return 0;
}
return -ENOMEM;
}
- strfieldcpy(new_name->name, name);
+ strlcpy(new_name->name, name, sizeof(new_name->name));
list_add_tail(&new_name->node, &loop_name->node);
return 0;
/* call function for every file in the list */
list_for_each_entry_safe(loop_file, tmp_file, &file_list, node) {
- char filename[NAME_SIZE];
+ char filename[PATH_SIZE];
- snprintf(filename, NAME_SIZE, "%s/%s", dirname, loop_file->name);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/%s", dirname, loop_file->name);
+ filename[sizeof(filename)-1] = '\0';
handler_function(udev, filename);
#include "udev.h"
-#define strfieldcpy(to, from) \
-do { \
- to[sizeof(to)-1] = '\0'; \
- strncpy(to, from, sizeof(to)-1); \
-} while (0)
-
-#define strfieldcat(to, from) \
-do { \
- to[sizeof(to)-1] = '\0'; \
- strncat(to, from, sizeof(to) - strlen(to)-1); \
-} while (0)
-
-#define strfieldcpymax(to, from, maxsize) \
-do { \
- to[maxsize-1] = '\0'; \
- strncpy(to, from, maxsize-1); \
-} while (0)
-
-#define strfieldcatmax(to, from, maxsize) \
-do { \
- to[maxsize-1] = '\0'; \
- strncat(to, from, maxsize - strlen(to)-1); \
-} while (0)
-
-#ifdef asmlinkage
-# undef asmlinkage
-#endif
-#ifdef __i386__
-# define asmlinkage __attribute__((regparm(0)))
-#endif
-#ifndef asmlinkage
-# define asmlinkage
-#endif
-
struct name_entry {
struct list_head node;
- char name[NAME_SIZE];
+ char name[PATH_SIZE];
};
extern int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem);
#include <sys/stat.h>
#include "list.h"
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_version.h"
#include "udev_utils.h"
{
int i;
- for (i = 0; i < DEVPATH_SIZE; i++) {
+ for (i = 0; i < PATH_SIZE; i++) {
/* identical device event found */
if (running[i] == '\0' && waiting[i] == '\0')
return 1;
#include "libsysfs/sysfs/libsysfs.h"
#include "libsysfs/dlist.h"
+#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_version.h"
#include "logging.h"
-#define SYSFS_VALUE_SIZE 256
-
#ifdef USE_LOG
void log_message (int level, const char *format, ...)
{
static void print_all_attributes(struct dlist *attr_list)
{
struct sysfs_attribute *attr;
- char value[SYSFS_VALUE_SIZE];
+ char value[VALUE_SIZE];
int len;
dlist_for_each_data(attr_list, attr, struct sysfs_attribute) {
if (attr->value != NULL) {
- strfieldcpy(value, attr->value);
+ strlcpy(value, attr->value, sizeof(value));
len = strlen(value);
if (len == 0)
continue;
int root = 0;
int attributes = 0;
enum query_type query = NONE;
- char path[NAME_SIZE] = "";
- char name[NAME_SIZE] = "";
- char temp[NAME_SIZE];
+ char path[PATH_SIZE] = "";
+ char name[PATH_SIZE] = "";
+ char temp[PATH_SIZE];
struct name_entry *name_loop;
char *pos;
int retval = 0;
switch (option) {
case 'n':
dbg("udev name: %s\n", optarg);
- strfieldcpy(name, optarg);
+ strlcpy(name, optarg, sizeof(name));
break;
case 'p':
dbg("udev path: %s\n", optarg);
- strfieldcpy(path, optarg);
+ strlcpy(path, optarg, sizeof(path));
break;
case 'q':
if (path[0] != '/') {
/* prepend '/' if missing */
strcpy(temp, "/");
- strfieldcat(temp, path);
+ strlcpy(temp, path, sizeof(temp));
pos = temp;
} else {
pos = path;
}
if (name[0] != '\0') {
- char devpath[NAME_SIZE];
+ char devpath[PATH_SIZE];
int len;
/* remove udev_root if given */
} else
pos = name;
- retval = udev_db_search_name(devpath, DEVPATH_SIZE, pos);
+ retval = udev_db_search_name(devpath, sizeof(devpath), pos);
if (retval != 0) {
printf("device not found in database\n");
goto exit;
} else {
if (strncmp(path, sysfs_path, strlen(sysfs_path)) != 0) {
/* prepend sysfs mountpoint if not given */
- strfieldcpy(temp, path);
- strfieldcpy(path, sysfs_path);
- strfieldcat(path, temp);
+ snprintf(temp, sizeof(temp), "%s%s", sysfs_path, path);
+ temp[sizeof(temp)-1] = '\0';
+ strlcpy(path, temp, sizeof(temp));
}
print_device_chain(path);
goto exit;
#include <sys/types.h>
#include "libsysfs/sysfs/libsysfs.h"
+#include "udev_libc_wrapper.h"
+#include "udev.h"
#include "logging.h"
#include "namedev.h"
#include "udev_utils.h"
#include "list.h"
-#include "udev.h"
#ifdef USE_LOG
void log_message(int level, const char *format, ...)
struct device {
struct list_head list;
- char path[DEVPATH_SIZE];
- char subsys[SUBSYSTEM_SIZE];
+ char path[PATH_SIZE];
+ char subsys[NAME_SIZE];
};
/* sort files in lexical order */
return -ENOMEM;
}
- strfieldcpy(new_device->path, path);
- strfieldcpy(new_device->subsys, subsystem);
+ strlcpy(new_device->path, path, sizeof(new_device->path));
+ strlcpy(new_device->subsys, subsystem, sizeof(new_device->subsys));
list_add_tail(&new_device->list, &loop_device->list);
dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
return 0;
static int has_devt(const char *directory)
{
- char filename[NAME_SIZE];
+ char filename[PATH_SIZE];
struct stat statbuf;
- snprintf(filename, NAME_SIZE, "%s/dev", directory);
- filename[NAME_SIZE-1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/dev", directory);
+ filename[sizeof(filename)-1] = '\0';
if (stat(filename, &statbuf) == 0)
return 1;
static void udev_scan_block(void)
{
- char base[NAME_SIZE];
+ char base[PATH_SIZE];
DIR *dir;
struct dirent *dent;
LIST_HEAD(device_list);
- snprintf(base, DEVPATH_SIZE, "%s/block", sysfs_path);
- base[DEVPATH_SIZE-1] = '\0';
+ snprintf(base, sizeof(base), "%s/block", sysfs_path);
+ base[sizeof(base)-1] = '\0';
dir = opendir(base);
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[DEVPATH_SIZE];
+ char dirname[PATH_SIZE];
DIR *dir2;
struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
- snprintf(dirname, NAME_SIZE, "%s/%s", base, dent->d_name);
- dirname[NAME_SIZE-1] = '\0';
+ snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
+ dirname[sizeof(dirname)-1] = '\0';
if (has_devt(dirname))
device_list_insert(dirname, "block", &device_list);
else
dir2 = opendir(dirname);
if (dir2 != NULL) {
for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[DEVPATH_SIZE];
+ char dirname2[PATH_SIZE];
if (dent2->d_name[0] == '.')
continue;
- snprintf(dirname2, DEVPATH_SIZE, "%s/%s", dirname, dent2->d_name);
- dirname2[DEVPATH_SIZE-1] = '\0';
+ snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+ dirname2[sizeof(dirname2)-1] = '\0';
if (has_devt(dirname2))
device_list_insert(dirname2, "block", &device_list);
static void udev_scan_class(void)
{
- char base[DEVPATH_SIZE];
+ char base[PATH_SIZE];
DIR *dir;
struct dirent *dent;
LIST_HEAD(device_list);
- snprintf(base, DEVPATH_SIZE, "%s/class", sysfs_path);
- base[DEVPATH_SIZE-1] = '\0';
+ snprintf(base, sizeof(base), "%s/class", sysfs_path);
+ base[sizeof(base)-1] = '\0';
dir = opendir(base);
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[DEVPATH_SIZE];
+ char dirname[PATH_SIZE];
DIR *dir2;
struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
- snprintf(dirname, DEVPATH_SIZE, "%s/%s", base, dent->d_name);
- dirname[DEVPATH_SIZE-1] = '\0';
+ snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
+ dirname[sizeof(dirname)-1] = '\0';
dir2 = opendir(dirname);
if (dir2 != NULL) {
for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[DEVPATH_SIZE];
+ char dirname2[PATH_SIZE];
if (dent2->d_name[0] == '.')
continue;
- snprintf(dirname2, DEVPATH_SIZE, "%s/%s", dirname, dent2->d_name);
- dirname2[DEVPATH_SIZE-1] = '\0';
+ snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+ dirname2[sizeof(dirname2)-1] = '\0';
/* pass the net class as it is */
if (strcmp(dent->d_name, "net") == 0)
/*
- * udev.c
+ * udevtest.c
*
* Userspace devfs
*
{
struct sysfs_class_device *class_dev;
char *devpath;
- char path[SYSFS_PATH_MAX];
- char temp[NAME_SIZE];
+ char path[PATH_SIZE];
+ char temp[PATH_SIZE];
struct udevice udev;
char *subsystem = NULL;
udev_init_config();
/* remove sysfs_path if given */
- if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0) {
+ if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
devpath = &argv[1][strlen(sysfs_path)] ;
- }
else
if (argv[1][0] != '/') {
/* prepend '/' if missing */
- strfieldcpy(temp, "/");
- strfieldcat(temp, argv[1]);
+ snprintf(temp, sizeof(temp), "/%s", argv[1]);
+ temp[sizeof(temp)-1] = '\0';
devpath = temp;
- } else {
+ } else
devpath = argv[1];
- }
info("looking at '%s'", devpath);
}
/* open the device */
- snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
+ snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
+ path[sizeof(path)-1] = '\0';
class_dev = sysfs_open_class_device_path(path);
if (class_dev == NULL) {
info("sysfs_open_class_device_path failed");