]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
find-esp: make use of XAT_FDROOT
authorLennart Poettering <lennart@poettering.net>
Mon, 8 Dec 2025 12:33:20 +0000 (13:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 17 Jan 2026 11:37:39 +0000 (12:37 +0100)
src/shared/find-esp.c

index 8e1737eebb9f9b01c48f371d33f2037c1384acc3..cf4eddbbfa67579c6868f7301f7cd04ac73c69e9 100644 (file)
@@ -332,7 +332,7 @@ static int verify_esp(
         dev_t devid = 0;
         int r;
 
-        assert(rfd >= 0 || rfd == AT_FDCWD);
+        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
         assert(path);
 
         /* This logs about all errors, except:
@@ -442,14 +442,14 @@ int find_esp_and_warn_at(
         VerifyESPFlags flags;
         int r;
 
+        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+
         /* This logs about all errors except:
          *
          *    -ENOKEY → when we can't find the partition
          *   -EACCESS → when unprivileged_mode is true, and we can't access something
          */
 
-        assert(rfd >= 0 || rfd == AT_FDCWD);
-
         flags = verify_esp_flags_init(unprivileged_mode, "SYSTEMD_RELAX_ESP_CHECKS");
 
         if (path)
@@ -527,9 +527,13 @@ int find_esp_and_warn(
         dev_t devid;
         int r;
 
-        rfd = open(empty_to_root(root), O_PATH|O_DIRECTORY|O_CLOEXEC);
-        if (rfd < 0)
-                return -errno;
+        if (empty_or_root(root))
+                rfd = XAT_FDROOT;
+        else {
+                rfd = open(root, O_PATH|O_DIRECTORY|O_CLOEXEC);
+                if (rfd < 0)
+                        return -errno;
+        }
 
         r = find_esp_and_warn_at(
                         rfd,
@@ -737,7 +741,7 @@ static int verify_xbootldr(
         dev_t devid = 0;
         int r;
 
-        assert(rfd >= 0 || rfd == AT_FDCWD);
+        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
         assert(path);
 
         r = chaseat(rfd, path, CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_TRIGGER_AUTOFS, &p, &pfd);
@@ -800,7 +804,7 @@ int find_xbootldr_and_warn_at(
 
         /* Similar to find_esp_and_warn(), but finds the XBOOTLDR partition. Returns the same errors. */
 
-        assert(rfd >= 0 || rfd == AT_FDCWD);
+        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
 
         flags = verify_esp_flags_init(unprivileged_mode, "SYSTEMD_RELAX_XBOOTLDR_CHECKS");
 
@@ -862,9 +866,13 @@ int find_xbootldr_and_warn(
         dev_t devid;
         int r;
 
-        rfd = open(empty_to_root(root), O_PATH|O_DIRECTORY|O_CLOEXEC);
-        if (rfd < 0)
-                return -errno;
+        if (empty_or_root(root))
+                rfd = XAT_FDROOT;
+        else {
+                rfd = open(root, O_PATH|O_DIRECTORY|O_CLOEXEC);
+                if (rfd < 0)
+                        return -errno;
+        }
 
         r = find_xbootldr_and_warn_at(
                         rfd,