mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
[PATCH] switch device type to enum
This commit is contained in:
parent
7e720bd4ad
commit
5ef4268205
@ -771,7 +771,7 @@ int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_d
|
||||
dbg_parse("remove event should be ignored");
|
||||
}
|
||||
/* apply all_partitions option only at a main block device */
|
||||
if (dev->partitions && udev->type == 'b' && udev->kernel_number[0] == '\0') {
|
||||
if (dev->partitions && udev->type == BLOCK && udev->kernel_number[0] == '\0') {
|
||||
udev->partitions = dev->partitions;
|
||||
dbg("creation of partition nodes requested");
|
||||
}
|
||||
@ -815,7 +815,7 @@ int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_d
|
||||
strfieldcpy(udev->config_file, dev->config_file);
|
||||
udev->config_line = dev->config_line;
|
||||
|
||||
if (udev->type != 'n')
|
||||
if (udev->type != NET)
|
||||
dbg("name, '%s' is going to have owner='%s', group='%s', mode=%#o partitions=%i",
|
||||
udev->name, udev->owner, udev->group, udev->mode, udev->partitions);
|
||||
|
||||
|
2
udev.c
2
udev.c
@ -179,7 +179,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
dbg("udev add");
|
||||
|
||||
/* skip subsystems without "dev", but handle net devices */
|
||||
if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
|
||||
if (udev.type != NET && subsystem_expect_no_dev(udev.subsystem)) {
|
||||
dbg("don't care about '%s' devices", udev.subsystem);
|
||||
goto hotplug;
|
||||
}
|
||||
|
8
udev.h
8
udev.h
@ -48,6 +48,14 @@
|
||||
|
||||
#define DEFAULT_PARTITIONS_COUNT 15
|
||||
|
||||
enum device_type {
|
||||
UNKNOWN,
|
||||
CLASS,
|
||||
BLOCK,
|
||||
NET,
|
||||
PHYSDEV,
|
||||
};
|
||||
|
||||
struct udevice {
|
||||
char devpath[DEVPATH_SIZE];
|
||||
char subsystem[SUBSYSTEM_SIZE];
|
||||
|
14
udev_add.c
14
udev_add.c
@ -70,16 +70,12 @@ int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mo
|
||||
|
||||
create:
|
||||
switch (udev->type) {
|
||||
case 'b':
|
||||
case BLOCK:
|
||||
mode |= S_IFBLK;
|
||||
break;
|
||||
case 'c':
|
||||
case 'u':
|
||||
case CLASS:
|
||||
mode |= S_IFCHR;
|
||||
break;
|
||||
case 'p':
|
||||
mode |= S_IFIFO;
|
||||
break;
|
||||
default:
|
||||
dbg("unknown node type %c\n", udev->type);
|
||||
return -EINVAL;
|
||||
@ -277,7 +273,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
|
||||
char *pos;
|
||||
int retval = 0;
|
||||
|
||||
if (udev->type == 'b' || udev->type == 'c') {
|
||||
if (udev->type == BLOCK || udev->type == CLASS) {
|
||||
udev->devt = get_devt(class_dev);
|
||||
if (!udev->devt) {
|
||||
dbg("no dev-file found, do nothing");
|
||||
@ -292,7 +288,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
|
||||
|
||||
selinux_init();
|
||||
|
||||
if (udev->type == 'b' || udev->type == 'c') {
|
||||
if (udev->type == BLOCK || udev->type == CLASS) {
|
||||
retval = create_node(udev, class_dev);
|
||||
if (retval != 0)
|
||||
goto exit;
|
||||
@ -305,7 +301,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
|
||||
snprintf(udev->devname, NAME_SIZE, "%s/%s", udev_root, udev->name);
|
||||
udev->devname[NAME_SIZE-1] = '\0';
|
||||
|
||||
} else if (udev->type == 'n') {
|
||||
} else if (udev->type == NET) {
|
||||
/* look if we want to change the name of the netif */
|
||||
if (strcmp(udev->name, udev->kernel_name) != 0) {
|
||||
retval = rename_net_if(udev);
|
||||
|
@ -147,7 +147,7 @@ int udev_remove_device(struct udevice *udev)
|
||||
const char *temp;
|
||||
int retval;
|
||||
|
||||
if (udev->type != 'b' && udev->type != 'c')
|
||||
if (udev->type != BLOCK && udev->type != CLASS)
|
||||
return 0;
|
||||
|
||||
retval = udev_db_get_device(udev);
|
||||
|
10
udev_utils.c
10
udev_utils.c
@ -47,15 +47,15 @@ void udev_init_device(struct udevice *udev, const char* devpath, const char *sub
|
||||
strfieldcpy(udev->subsystem, subsystem);
|
||||
|
||||
if (strcmp(udev->subsystem, "block") == 0)
|
||||
udev->type = 'b';
|
||||
udev->type = BLOCK;
|
||||
else if (strcmp(udev->subsystem, "net") == 0)
|
||||
udev->type = 'n';
|
||||
udev->type = NET;
|
||||
else if (strncmp(udev->devpath, "/block/", 7) == 0)
|
||||
udev->type = 'b';
|
||||
udev->type = BLOCK;
|
||||
else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
|
||||
udev->type = 'n';
|
||||
udev->type = NET;
|
||||
else if (strncmp(udev->devpath, "/class/", 7) == 0)
|
||||
udev->type = 'c';
|
||||
udev->type = CLASS;
|
||||
|
||||
udev->mode = 0660;
|
||||
strcpy(udev->owner, "root");
|
||||
|
@ -94,7 +94,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
udev_init_device(&udev, devpath, subsystem);
|
||||
|
||||
/* skip subsystems without "dev", but handle net devices */
|
||||
if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
|
||||
if (udev.type != NET && subsystem_expect_no_dev(udev.subsystem)) {
|
||||
info("don't care about '%s' devices", udev.subsystem);
|
||||
return 2;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user