mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-01-24 16:10:11 +07:00
[PATCH] correct udev_init_device
This commit is contained in:
parent
c98cb35eb5
commit
03cfa1394f
18
udev.c
18
udev.c
@ -96,7 +96,6 @@ static void asmlinkage sig_handler(int signum)
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
struct sigaction act;
|
||||
struct sysfs_class_device *class_dev;
|
||||
struct sysfs_device *devices_dev;
|
||||
struct udevice udev;
|
||||
@ -106,6 +105,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
const char *devpath;
|
||||
const char *subsystem;
|
||||
int managed_event;
|
||||
struct sigaction act;
|
||||
int retval = -EINVAL;
|
||||
|
||||
if (argc == 2 && strcmp(argv[1], "-V") == 0) {
|
||||
@ -153,16 +153,10 @@ int main(int argc, char *argv[], char *envp[])
|
||||
if (!subsystem && argc == 2)
|
||||
subsystem = argv[1];
|
||||
|
||||
if (!action) {
|
||||
dbg("no action");
|
||||
goto hotplug;
|
||||
}
|
||||
if (!subsystem) {
|
||||
dbg("no subsystem");
|
||||
goto hotplug;
|
||||
}
|
||||
if (!devpath) {
|
||||
dbg("no devpath");
|
||||
udev_init_device(&udev, devpath, subsystem);
|
||||
|
||||
if (!action || !subsystem || !devpath) {
|
||||
dbg("action, subsystem or devpath missing");
|
||||
goto hotplug;
|
||||
}
|
||||
|
||||
@ -170,8 +164,6 @@ int main(int argc, char *argv[], char *envp[])
|
||||
if (udev_log)
|
||||
setenv("UDEV_LOG", "1", 1);
|
||||
|
||||
udev_init_device(&udev, devpath, subsystem);
|
||||
|
||||
if (udev.type == BLOCK || udev.type == CLASS || udev.type == NET) {
|
||||
if (strcmp(action, "add") == 0) {
|
||||
/* wait for sysfs and possibly add node */
|
||||
|
5
udev.h
5
udev.h
@ -31,6 +31,7 @@
|
||||
#define ALARM_TIMEOUT 120
|
||||
#define COMMENT_CHARACTER '#'
|
||||
|
||||
#define LINE_SIZE 512
|
||||
#define NAME_SIZE 256
|
||||
#define USER_SIZE 32
|
||||
|
||||
@ -39,8 +40,6 @@
|
||||
#define SUBSYSTEM_SIZE 32
|
||||
#define SEQNUM_SIZE 32
|
||||
|
||||
#define LINE_SIZE 512
|
||||
|
||||
#define DEVD_DIR "/etc/dev.d"
|
||||
#define DEVD_SUFFIX ".dev"
|
||||
|
||||
@ -62,6 +61,7 @@ struct udevice {
|
||||
char subsystem[SUBSYSTEM_SIZE];
|
||||
|
||||
char name[NAME_SIZE];
|
||||
char devname[NAME_SIZE];
|
||||
char symlink[NAME_SIZE];
|
||||
char owner[USER_SIZE];
|
||||
char group[USER_SIZE];
|
||||
@ -69,7 +69,6 @@ struct udevice {
|
||||
char type;
|
||||
dev_t devt;
|
||||
|
||||
char devname[NAME_SIZE];
|
||||
char tmp_node[NAME_SIZE];
|
||||
int partitions;
|
||||
int ignore_remove;
|
||||
|
73
udev_utils.c
73
udev_utils.c
@ -43,52 +43,49 @@ int udev_init_device(struct udevice *udev, const char* devpath, const char *subs
|
||||
|
||||
memset(udev, 0x00, sizeof(struct udevice));
|
||||
|
||||
if (devpath) {
|
||||
strfieldcpy(udev->devpath, devpath);
|
||||
no_trailing_slash(udev->devpath);
|
||||
}
|
||||
if (subsystem)
|
||||
strfieldcpy(udev->subsystem, subsystem);
|
||||
|
||||
if (strcmp(udev->subsystem, "block") == 0)
|
||||
udev->type = BLOCK;
|
||||
else if (strcmp(udev->subsystem, "net") == 0)
|
||||
udev->type = NET;
|
||||
else if (strncmp(udev->devpath, "/block/", 7) == 0)
|
||||
udev->type = BLOCK;
|
||||
else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
|
||||
udev->type = NET;
|
||||
else if (strncmp(udev->devpath, "/class/", 7) == 0)
|
||||
udev->type = CLASS;
|
||||
else if (strncmp(udev->devpath, "/devices/", 9) == 0)
|
||||
udev->type = PHYSDEV;
|
||||
if (devpath) {
|
||||
strfieldcpy(udev->devpath, devpath);
|
||||
no_trailing_slash(udev->devpath);
|
||||
|
||||
if (strncmp(udev->devpath, "/block/", 7) == 0)
|
||||
udev->type = BLOCK;
|
||||
else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
|
||||
udev->type = NET;
|
||||
else if (strncmp(udev->devpath, "/class/", 7) == 0)
|
||||
udev->type = CLASS;
|
||||
else if (strncmp(udev->devpath, "/devices/", 9) == 0)
|
||||
udev->type = PHYSDEV;
|
||||
|
||||
/* get kernel name */
|
||||
pos = strrchr(udev->devpath, '/');
|
||||
if (pos) {
|
||||
strfieldcpy(udev->kernel_name, &pos[1]);
|
||||
dbg("kernel_name='%s'", udev->kernel_name);
|
||||
|
||||
/* Some block devices have '!' in their name, change that to '/' */
|
||||
pos = udev->kernel_name;
|
||||
while (pos[0] != '\0') {
|
||||
if (pos[0] == '!')
|
||||
pos[0] = '/';
|
||||
pos++;
|
||||
}
|
||||
|
||||
/* get kernel number */
|
||||
pos = &udev->kernel_name[strlen(udev->kernel_name)];
|
||||
while (isdigit(pos[-1]))
|
||||
pos--;
|
||||
strfieldcpy(udev->kernel_number, pos);
|
||||
dbg("kernel_number='%s'", udev->kernel_number);
|
||||
}
|
||||
}
|
||||
|
||||
udev->mode = 0660;
|
||||
strcpy(udev->owner, "root");
|
||||
strcpy(udev->group, "root");
|
||||
|
||||
/* get kernel name */
|
||||
pos = strrchr(udev->devpath, '/');
|
||||
if (pos == NULL)
|
||||
return -1;
|
||||
strfieldcpy(udev->kernel_name, &pos[1]);
|
||||
|
||||
/* get kernel number */
|
||||
pos = &udev->kernel_name[strlen(udev->kernel_name)];
|
||||
while (isdigit(pos[-1]))
|
||||
pos--;
|
||||
strfieldcpy(udev->kernel_number, pos);
|
||||
dbg("kernel_number='%s'", udev->kernel_number);
|
||||
|
||||
/* Some block devices have '!' in their name, change that to '/' */
|
||||
pos = udev->kernel_name;
|
||||
while (pos[0] != '\0') {
|
||||
if (pos[0] == '!')
|
||||
pos[0] = '/';
|
||||
pos++;
|
||||
}
|
||||
|
||||
dbg("kernel_name='%s'", udev->kernel_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user