]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
discover-image: store image class in Image object too, if known
authorLennart Poettering <lennart@poettering.net>
Tue, 29 Nov 2022 15:40:15 +0000 (16:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 7 Dec 2022 16:44:35 +0000 (17:44 +0100)
src/shared/discover-image.c
src/shared/discover-image.h

index 43582d0dd3ac656311ccbfe4f686a8042c3565c5..8bc165ef4ca4186f710c3af8cc2f2c413ae800e4 100644 (file)
@@ -123,6 +123,7 @@ static char *image_roothash_path(Image *image) {
 
 static int image_new(
                 ImageType t,
+                ImageClass c,
                 const char *pretty,
                 const char *path,
                 const char *filename,
@@ -146,6 +147,7 @@ static int image_new(
         *i = (Image) {
                 .n_ref = 1,
                 .type = t,
+                .class = c,
                 .read_only = read_only,
                 .crtime = crtime,
                 .mtime = mtime,
@@ -203,6 +205,7 @@ static int extract_pretty(const char *path, const char *suffix, char **ret) {
 }
 
 static int image_make(
+                ImageClass c,
                 const char *pretty,
                 int dfd,
                 const char *path,
@@ -278,6 +281,7 @@ static int image_make(
                                         return r;
 
                                 r = image_new(IMAGE_SUBVOLUME,
+                                              c,
                                               pretty,
                                               path,
                                               filename,
@@ -314,6 +318,7 @@ static int image_make(
 
                 /* It's just a normal directory. */
                 r = image_new(IMAGE_DIRECTORY,
+                              c,
                               pretty,
                               path,
                               filename,
@@ -345,6 +350,7 @@ static int image_make(
                 }
 
                 r = image_new(IMAGE_RAW,
+                              c,
                               pretty,
                               path,
                               filename,
@@ -405,6 +411,7 @@ static int image_make(
                 }
 
                 r = image_new(IMAGE_BLOCK,
+                              c,
                               pretty,
                               path,
                               filename,
@@ -475,13 +482,13 @@ int image_find(ImageClass class,
                         if (!S_ISREG(st.st_mode))
                                 continue;
 
-                        r = image_make(name, dirfd(d), resolved, raw, &st, ret);
+                        r = image_make(class, name, dirfd(d), resolved, raw, &st, ret);
 
                 } else {
                         if (!S_ISDIR(st.st_mode) && !S_ISBLK(st.st_mode))
                                 continue;
 
-                        r = image_make(name, dirfd(d), resolved, name, &st, ret);
+                        r = image_make(class, name, dirfd(d), resolved, name, &st, ret);
                 }
                 if (IN_SET(r, -ENOENT, -EMEDIUMTYPE))
                         continue;
@@ -495,7 +502,7 @@ int image_find(ImageClass class,
         }
 
         if (class == IMAGE_MACHINE && streq(name, ".host")) {
-                r = image_make(".host", AT_FDCWD, NULL, empty_to_root(root), NULL, ret);
+                r = image_make(class, ".host", AT_FDCWD, NULL, empty_to_root(root), NULL, ret);
                 if (r < 0)
                         return r;
 
@@ -515,9 +522,9 @@ int image_from_path(const char *path, Image **ret) {
          * overridden by another, different image earlier in the search path */
 
         if (path_equal(path, "/"))
-                return image_make(".host", AT_FDCWD, NULL, "/", NULL, ret);
+                return image_make(IMAGE_MACHINE, ".host", AT_FDCWD, NULL, "/", NULL, ret);
 
-        return image_make(NULL, AT_FDCWD, NULL, path, NULL, ret);
+        return image_make(_IMAGE_CLASS_INVALID, NULL, AT_FDCWD, NULL, path, NULL, ret);
 }
 
 int image_find_harder(ImageClass class, const char *name_or_path, const char *root, Image **ret) {
@@ -591,7 +598,7 @@ int image_discover(
                         if (hashmap_contains(h, pretty))
                                 continue;
 
-                        r = image_make(pretty, dirfd(d), resolved, de->d_name, &st, &image);
+                        r = image_make(class, pretty, dirfd(d), resolved, de->d_name, &st, &image);
                         if (IN_SET(r, -ENOENT, -EMEDIUMTYPE))
                                 continue;
                         if (r < 0)
@@ -610,7 +617,7 @@ int image_discover(
         if (class == IMAGE_MACHINE && !hashmap_contains(h, ".host")) {
                 _cleanup_(image_unrefp) Image *image = NULL;
 
-                r = image_make(".host", AT_FDCWD, NULL, empty_to_root("/"), NULL, &image);
+                r = image_make(IMAGE_MACHINE, ".host", AT_FDCWD, NULL, empty_to_root("/"), NULL, &image);
                 if (r < 0)
                         return r;
 
index 3286061d61f9c6401a2e6e4df33baf290377413d..a8874228dcf70ae30e3a8cb5c9c72f1dbeb7f884 100644 (file)
@@ -34,6 +34,7 @@ typedef struct Image {
         unsigned n_ref;
 
         ImageType type;
+        ImageClass class;
         char *name;
         char *path;
         bool read_only;