[systemd-devel] [PATCH] cryptsetup-generator: Allow specifiying a name on the kernel command line

Jan Janssen medhefgo at web.de
Fri Aug 29 06:28:25 PDT 2014


---
 man/systemd-cryptsetup-generator.xml  |  8 ++++++--
 src/cryptsetup/cryptsetup-generator.c | 32 +++++++++++++++++---------------
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/man/systemd-cryptsetup-generator.xml b/man/systemd-cryptsetup-generator.xml
index 3abb39d..44c8658 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -120,8 +120,12 @@
                                 activate the specified device as part
                                 of the boot process as if it was
                                 listed in
-                                <filename>/etc/fstab</filename>. This
-                                option may be specified more than once
+                                <filename>/etc/fstab</filename>.
+                                If the UUID is followed with <literal>:name</literal>,
+                                the plain test device will appear under that name
+                                in <filename>/dev/mapper/</filename>, otherwise
+                                it will be <literal>luks-UUID</literal>.</para>
+                                <para>This option may be specified more than once
                                 in order to set up multiple
                                 devices. <varname>rd.luks.uuid=</varname>
                                 is honored only by initial RAM disk
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 3233e15..dea2b1f 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -279,7 +279,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
 
         } else if (STR_IN_SET(key, "luks.uuid", "rd.luks.uuid") && value) {
 
-                if (strv_extend(&arg_disks, value) < 0)
+                if (strv_extend(&arg_disks, startswith(value, "luks-") ? value+5 : value) < 0)
                         return log_oom();
 
         } else if (STR_IN_SET(key, "luks.options", "rd.luks.options") && value) {
@@ -401,13 +401,14 @@ int main(int argc, char *argv[]) {
                                 */
                                 STRV_FOREACH(i, arg_disks) {
                                         _cleanup_free_ char *proc_device = NULL, *proc_name = NULL;
-                                        const char *p = *i;
+                                        const char *p = NULL;
 
-                                        if (startswith(p, "luks-"))
-                                                p += 5;
-
-                                        proc_name = strappend("luks-", p);
-                                        proc_device = strappend("UUID=", p);
+                                        p = strchrnul(*i, ':');
+                                        proc_device = strnappend("UUID=", *i, p - *i);
+                                        if (*p && !isempty(p + 1))
+                                                proc_name = strdup(p + 1);
+                                        else
+                                                proc_name = strnappend("luks-", *i, p - *i);
 
                                         if (!proc_name || !proc_device) {
                                                 log_oom();
@@ -418,7 +419,7 @@ int main(int argc, char *argv[]) {
                                                 if (create_disk(name, device, password, options) < 0)
                                                         goto cleanup;
 
-                                                if (strv_extend(&disks_done, p) < 0) {
+                                                if (strv_extend(&disks_done, *i) < 0) {
                                                         log_oom();
                                                         goto cleanup;
                                                 }
@@ -440,16 +441,17 @@ next:
                 */
 
                 _cleanup_free_ char *name = NULL, *device = NULL, *options = NULL;
-                const char *p = *i;
-
-                if (startswith(p, "luks-"))
-                        p += 5;
+                const char *p = NULL;
 
-                if (strv_contains(disks_done, p))
+                if (strv_contains(disks_done, *i))
                         continue;
 
-                name = strappend("luks-", p);
-                device = strappend("UUID=", p);
+                p = strchrnul(*i, ':');
+                device = strnappend("UUID=", *i, p - *i);
+                if (*p && !isempty(p + 1))
+                        name = strdup(p + 1);
+                else
+                        name = strnappend("luks-", *i, p - *i);
 
                 if (!name || !device) {
                         log_oom();
-- 
2.1.0



More information about the systemd-devel mailing list