]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add support for ID=
authorKarel Zak <kzak@redhat.com>
Wed, 3 Jun 2020 14:53:00 +0000 (16:53 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Jun 2020 14:53:00 +0000 (16:53 +0200)
This patch add support for a new tag. The tag is based on udev block
device ID (see /dev/disk/by-id). The usual use-case is to use
WWN for this purpose, for example

  # mount ID=wwn-0x50026b724b09a1ff /mnt

Note that ID is not strictly defined and udevd generates various IDs
also for HW where WWN is undefined. This is reason why introduce ID=
seems better and more generic than more restrictive WWN=.

Addresses: https://github.com/karelzak/util-linux/issues/1008
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/evaluate.c
libmount/src/utils.c
sys-utils/mount.8
sys-utils/mount.c

index 8ba8bd5f372b3a87c96af6634388caa4aa544b87..710eac95663487c67e66c06772fbf494c10060f9 100644 (file)
@@ -59,6 +59,9 @@ static int verify_tag(const char *devname, const char *name, const char *value)
        const char *data;
        int errsv = 0;
 
        const char *data;
        int errsv = 0;
 
+       if (strcmp(token, "ID") == 0)
+               return 0; /* non-content tag */
+
        pr = blkid_new_probe();
        if (!pr)
                return -1;
        pr = blkid_new_probe();
        if (!pr)
                return -1;
@@ -149,6 +152,8 @@ static char *evaluate_by_udev(const char *token, const char *value, int uevent)
                strcpy(dev, _PATH_DEV_BYPARTLABEL "/");
        else if (!strcmp(token, "PARTUUID"))
                strcpy(dev, _PATH_DEV_BYPARTUUID "/");
                strcpy(dev, _PATH_DEV_BYPARTLABEL "/");
        else if (!strcmp(token, "PARTUUID"))
                strcpy(dev, _PATH_DEV_BYPARTUUID "/");
+       else if (!strcmp(token, "ID"))
+               strcpy(dev, _PATH_DEV_BYID "/");
        else {
                DBG(EVALUATE, ul_debug("unsupported token %s", token));
                return NULL;    /* unsupported tag */
        else {
                DBG(EVALUATE, ul_debug("unsupported token %s", token));
                return NULL;    /* unsupported tag */
index 6be7a72c0a6cd01600581ccb169da9e9de0b95d5..92829ebb01f267fb70e92dc835ccf407d289f178 100644 (file)
@@ -72,6 +72,7 @@ int is_file_empty(const char *name)
 int mnt_valid_tagname(const char *tagname)
 {
        if (tagname && *tagname && (
 int mnt_valid_tagname(const char *tagname)
 {
        if (tagname && *tagname && (
+           strcmp("ID", tagname) == 0 ||
            strcmp("UUID", tagname) == 0 ||
            strcmp("LABEL", tagname) == 0 ||
            strcmp("PARTUUID", tagname) == 0 ||
            strcmp("UUID", tagname) == 0 ||
            strcmp("LABEL", tagname) == 0 ||
            strcmp("PARTUUID", tagname) == 0 ||
index f1d114cb338ab99a8affa8f7b46fd258a45bfb93..082fa1719e34c7f62ad26dc1afa38931e0f941c2 100644 (file)
@@ -177,6 +177,14 @@ PARTUUID=\fIuuid\fR
 Partition universally unique identifier.  This identifier is independent on
 filesystem and does not change by mkfs or mkswap operations  It's supported
 for example for GUID Partition Tables (GPT).
 Partition universally unique identifier.  This identifier is independent on
 filesystem and does not change by mkfs or mkswap operations  It's supported
 for example for GUID Partition Tables (GPT).
+.TP
+ID=\fIid\fR
+Hardware block device ID as generated by udevd.  This identifier is usually
+based on WWN (unique storage identifier) and assigned by the hardware
+manufacturer.  See \fBls /dev/disk/by-id\fR for more details, this directory
+and running udevd is required.  This identifier is not recommended for generic
+use as the identifier is not strictly defined and it depends on udev, udev rules
+and hardware.
 .RE
 .sp
 The command \fBlsblk \-\-fs\fR provides an overview of filesystems, LABELs and UUIDs
 .RE
 .sp
 The command \fBlsblk \-\-fs\fR provides an overview of filesystems, LABELs and UUIDs
@@ -189,7 +197,7 @@ unique, especially if you move, share or copy the device.  Use
 to verify that the UUIDs are really unique in your system.
 
 The recommended setup is to use tags (e.g.\& \fBUUID=\fIuuid\fR) rather than
 to verify that the UUIDs are really unique in your system.
 
 The recommended setup is to use tags (e.g.\& \fBUUID=\fIuuid\fR) rather than
-.I /dev/disk/by-{label,uuid,partuuid,partlabel}
+.I /dev/disk/by-{label,uuid,id,partuuid,partlabel}
 udev symlinks in the
 .I /etc/fstab
 file.  Tags are
 udev symlinks in the
 .I /etc/fstab
 file.  Tags are
@@ -301,7 +309,7 @@ program does not read the
 .I /etc/fstab
 file if both
 .I device
 .I /etc/fstab
 file if both
 .I device
-(or LABEL, UUID, PARTUUID or PARTLABEL) and
+(or LABEL, UUID, ID, PARTUUID or PARTLABEL) and
 .I dir
 are specified.  For example, to mount device
 .BR foo " at " /dir :
 .I dir
 are specified.  For example, to mount device
 .BR foo " at " /dir :
index 49d3beb0d51d485279d8e301374f5d584ade0ab1..a87833eee381b4122e61eb4c3fbc6eaa1c44903d 100644 (file)
@@ -493,7 +493,8 @@ static void __attribute__((__noreturn__)) usage(void)
        " LABEL=<label>           specifies device by filesystem label\n"
        " UUID=<uuid>             specifies device by filesystem UUID\n"
        " PARTLABEL=<label>       specifies device by partition label\n"
        " LABEL=<label>           specifies device by filesystem label\n"
        " UUID=<uuid>             specifies device by filesystem UUID\n"
        " PARTLABEL=<label>       specifies device by partition label\n"
-       " PARTUUID=<uuid>         specifies device by partition UUID\n"));
+       " PARTUUID=<uuid>         specifies device by partition UUID\n"
+       " ID=<id>                 specifies device by udev hardware ID\n"));
 
        fprintf(out, _(
        " <device>                specifies device by path\n"
 
        fprintf(out, _(
        " <device>                specifies device by path\n"