]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: fix generation of UUID= line for vfat in fstab entries
authorLennart Poettering <lennart@poettering.net>
Mon, 2 Jun 2025 08:12:10 +0000 (10:12 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 25 Jun 2025 17:17:42 +0000 (18:17 +0100)
Fixes: #36735
(cherry picked from commit 8504721e0e758aadf454141de014fe28d14cefcd)
(cherry picked from commit ddddef495d7f59db6040d89336c1eeccc7251fce)

src/partition/repart.c

index df7b6feee0ba6074b7772b9635898d1ce6bc5682..db54c7ed0c762dec7320332f82afad16e195bbf6 100644 (file)
@@ -6576,6 +6576,29 @@ static bool need_fstab(const Context *context) {
         return false;
 }
 
+static int make_by_uuid_symlink_path(const Partition *p, char **ret) {
+        _cleanup_free_ char *what = NULL;
+
+        assert(p);
+        assert(ret);
+
+        if (streq_ptr(p->format, "vfat")) {
+                if (asprintf(&what, "UUID=%04X-%04X",
+                             ((uint32_t) p->fs_uuid.bytes[0] << 8) |
+                             ((uint32_t) p->fs_uuid.bytes[1] << 0),
+                             ((uint32_t) p->fs_uuid.bytes[2] << 8) |
+                             ((uint32_t) p->fs_uuid.bytes[3])) < 0) /* Take first 32 bytes of UUID */
+                        return log_oom();
+        } else {
+                what = strjoin("UUID=", SD_ID128_TO_UUID_STRING(p->fs_uuid));
+                if (!what)
+                        return log_oom();
+        }
+
+        *ret = TAKE_PTR(what);
+        return 0;
+}
+
 static int context_fstab(Context *context) {
         _cleanup_(unlink_and_freep) char *t = NULL;
         _cleanup_fclose_ FILE *f = NULL;
@@ -6609,9 +6632,9 @@ static int context_fstab(Context *context) {
                 if (!need_fstab_one(p))
                         continue;
 
-                what = strjoin("UUID=", SD_ID128_TO_UUID_STRING(p->fs_uuid));
-                if (!what)
-                        return log_oom();
+                r = make_by_uuid_symlink_path(p, &what);
+                if (r < 0)
+                        return r;
 
                 FOREACH_ARRAY(mountpoint, p->mountpoints, p->n_mountpoints) {
                         r = partition_pick_mount_options(