]> err.no Git - systemd/commitdiff
[PATCH] introduce OPTIONS=ignore_device, ignore_remove, all_partitions" key
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Mon, 14 Feb 2005 05:03:06 +0000 (06:03 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:36:12 +0000 (23:36 -0700)
Here we move all possible options into a own key to make it possible
to have options-only rules.

The options on the NAME key are removed from the man page and will
be removed from a future version of udev.

For ignore rules, OPTIONS="ignore" should be used.

The rule:
  SUBSYSTEM="block", SYSFS{removable}="1", OPTIONS="all_partitions"

will create all partitions for a block device which is known to have
removable media (a check for cdrom drives would be needed too).

namedev.c
namedev.h
namedev_parse.c
test/udev-test.pl
udev.8.in
udev_add.c

index 42e8032be5d818fbeab2bbc338fc51ec8cceefe7..5c328594d4971bb0e545a395bce2856c845b37af 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -4,6 +4,7 @@
  * Userspace devfs
  *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *
  *     This program is free software; you can redistribute it and/or modify it
@@ -749,14 +750,31 @@ int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_d
                dbg("process rule");
                if (match_rule(udev, dev, class_dev, sysfs_device) == 0) {
 
-                       /* empty name, symlink and perms will not create any node */
+                       /* FIXME: remove old style ignore rule and make OPTION="ignore" mandatory */
                        if (dev->name[0] == '\0' && dev->symlink[0] == '\0' &&
-                           dev->mode == 0000 && dev->owner[0] == '\0' && dev->group[0] == '\0') {
+                           dev->mode == 0000 && dev->owner[0] == '\0' && dev->group[0] == '\0' &&
+                           !dev->ignore_device && !dev->partitions && !dev->ignore_remove) {
                                info("configured rule in '%s[%i]' applied, '%s' is ignored",
                                     dev->config_file, dev->config_line, udev->kernel_name);
                                return -1;
                        }
 
+                       /* apply options */
+                       if (dev->ignore_device) {
+                               info("configured rule in '%s[%i]' applied, '%s' is ignored",
+                                    dev->config_file, dev->config_line, udev->kernel_name);
+                               return -1;
+                       }
+                       if (dev->ignore_remove) {
+                               udev->ignore_remove = dev->ignore_remove;
+                               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') {
+                               udev->partitions = dev->partitions;
+                               dbg("creation of partition nodes requested");
+                       }
+
                        /* apply permissions */
                        if (dev->mode != 0000) {
                                udev->mode = dev->mode;
@@ -788,11 +806,6 @@ int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_d
 
                        /* rule matches */
                        if (dev->name[0] != '\0') {
-                               /* apply all_partitions flag only at a main block device */
-                               if (dev->partitions > 0 &&
-                                   (udev->type != 'b' || udev->kernel_number[0] != '\0'))
-                                       continue;
-
                                info("configured rule in '%s[%i]' applied, '%s' becomes '%s'",
                                     dev->config_file, dev->config_line, udev->kernel_name, dev->name);
 
@@ -800,15 +813,10 @@ int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_d
                                apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
                                strfieldcpy(udev->config_file, dev->config_file);
                                udev->config_line = dev->config_line;
-                               udev->ignore_remove = dev->ignore_remove;
-
-                               if (udev->type == 'n')
-                                       goto exit;
-
-                               udev->partitions = dev->partitions;
 
-                               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);
+                               if (udev->type != 'n')
+                                       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);
 
                                goto exit;
                        }
index 43381bfbd665dc49a27cc7b39cdfc8cffa3fa63f..1e1a9bbc3450013a7dafe306c3e965b9e637e3f2 100644 (file)
--- a/namedev.h
+++ b/namedev.h
@@ -50,9 +50,11 @@ struct sysfs_class_device;
 #define FIELD_OWNER            "OWNER"
 #define FIELD_GROUP            "GROUP"
 #define FIELD_MODE             "MODE"
+#define FIELD_OPTIONS          "OPTIONS"
 
-#define ATTR_PARTITIONS                "all_partitions"
+#define ATTR_IGNORE_DEVICE     "ignore_device"
 #define ATTR_IGNORE_REMOVE     "ignore_remove"
+#define ATTR_PARTITIONS                "all_partitions"
 
 #define MAX_SYSFS_PAIRS                5
 
@@ -77,11 +79,15 @@ struct config_device {
        char name[NAME_SIZE];
        char symlink[NAME_SIZE];
        struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
+
        char owner[USER_SIZE];
        char group[USER_SIZE];
        mode_t mode;
+
        int partitions;
+       int ignore_device;
        int ignore_remove;
+
        char config_file[NAME_SIZE];
        int config_line;
 };
index 7b5b963020275eb181c168217044e62593f2cbd5..981daa7b3b1d3e5e6a173c2e75e8b3d308d37ee3 100644 (file)
@@ -4,6 +4,7 @@
  * Userspace devfs
  *
  * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *
  *     This program is free software; you can redistribute it and/or modify it
@@ -247,6 +248,7 @@ static int namedev_parse(const char *filename, void *data)
 
                        if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) {
                                attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1);
+                               /* FIXME: remove old style options and make OPTIONS= mandatory */
                                if (attr != NULL) {
                                        if (strstr(attr, ATTR_PARTITIONS) != NULL) {
                                                dbg_parse("creation of partition nodes requested");
@@ -286,6 +288,23 @@ static int namedev_parse(const char *filename, void *data)
                                continue;
                        }
 
+                       if (strcasecmp(temp2, FIELD_OPTIONS) == 0) {
+                               if (strstr(temp3, ATTR_IGNORE_DEVICE) != NULL) {
+                                       dbg_parse("device should be ignored");
+                                       dev.ignore_device = 1;
+                               }
+                               if (strstr(temp3, ATTR_IGNORE_REMOVE) != NULL) {
+                                       dbg_parse("remove event should be ignored");
+                                       dev.ignore_remove = 1;
+                               }
+                               if (strstr(temp3, ATTR_PARTITIONS) != NULL) {
+                                       dbg_parse("creation of partition nodes requested");
+                                       dev.partitions = DEFAULT_PARTITIONS_COUNT;
+                               }
+                               valid = 1;
+                               continue;
+                       }
+
                        dbg("unknown type of field '%s'", temp2);
                        goto error;
                }
index fc0e89eeb3eeffaea002774f82e82bc7273ddc5c..5f9c0cb9c503a46f56660e4d1082d61e0daf9a4f 100644 (file)
@@ -1018,6 +1018,37 @@ EOF
                exp_name        => "cdrom",
                conf            => <<EOF
 KERNEL="sda", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "ignore rule test",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "node",
+               exp_error       => "yes",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda", NAME="node", OPTIONS="ignore"
+EOF
+       },
+       {
+               desc            => "all_partitions, option-only rule",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "node6",
+               conf            => <<EOF
+SUBSYSTEM="block", OPTIONS="all_partitions"
+BUS="scsi", KERNEL="sda", NAME="node"
+EOF
+       },
+       {
+               desc            => "all_partitions, option-only rule (fail on partition)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda1",
+               exp_name        => "node6",
+               exp_error       => "yes",
+               conf            => <<EOF
+SUBSYSTEM="block", OPTIONS="all_partitions"
+BUS="scsi", KERNEL="sda", NAME="node"
 EOF
        },
        {
@@ -1027,7 +1058,7 @@ EOF
                exp_name        => "node",
                exp_error       => "yes",
                conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME{ignore_remove}="node"
+BUS="scsi", KERNEL="sda", NAME="node", OPTIONS="ignore_remove"
 EOF
        },
        {
@@ -1038,7 +1069,7 @@ EOF
                exp_error       => "yes",
                option          => "clear",
                conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME{ignore_remove, all_partitions}="node"
+BUS="scsi", KERNEL="sda", NAME="node", OPTIONS="ignore_remove, all_partitions"
 EOF
        },
        {
index 3fb4bdb8da9e0ff08ad813d9d7ecaa3c8150f2cc..936ec15d2a1ed77b3c49423db917ad3a3789b3f2 100644 (file)
--- a/udev.8.in
+++ b/udev.8.in
@@ -145,20 +145,6 @@ call.
 .B NAME
 The name of the node to be created, or the name, the network interface
 should be renamed to.
-.br
-If given with the attribute
-.BR NAME{ all_partitions }
-.B udev
-will create device nodes for all 15 partitions of a blockdevice.
-This may be useful for removable media devices.
-.br
-If given with the attribute
-.BR NAME{ ignore_remove }
-.B udev
-will ignore any later remove event for this device.
-This may be useful as a workaround for broken device drivers.
-.sp
-Multiple attributes may be separated by comma.
 .TP
 .B SYMLINK
 The name of a symlink targeting the node. Multiple symlinks may be
@@ -177,6 +163,21 @@ distribution provided rules file.
 .B OWNER, GROUP, MODE
 The permissions for the device node. Every specified value overwrites the
 compiled-in default value.
+.TP
+.B OPTIONS
+.B ignore_device
+will ignore this device. No node will be created.
+.sp
+.B ignore_remove
+will ignore any later remove event for this device.
+This may be useful as a workaround for broken device drivers.
+.sp
+.B all_partitions
+will create device nodes for all available partitions of a blockdevice.
+This may be useful for removable media devices which do not detect a media
+change.
+.sp
+Multiple attributes may be separated by comma.
 .P
 .RB "The " NAME ", " SYMLINK ", " PROGRAM ", " OWNER " and " GROUP
 fields support simple printf-like string substitutions:
index be62e130ab4cc33bf2f2bd111bbc4681a21ced3d..f384ea96e50043405fb37abfb70705f721024a8a 100644 (file)
@@ -194,7 +194,7 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
        }
 
        /* create all_partitions if requested */
-       if (udev->partitions > 0) {
+       if (udev->partitions) {
                struct sysfs_attribute *attr;
                int range;