chiark / gitweb /
machined: beef up machined image listing with creation/modification times of subvolumes
[elogind.git] / src / machine / image.c
index 8f577adb59c36044aedc29c945c6cf2d5b0e38b2..9f88b0551f51c1e4328b59e9d2272591c2dbead2 100644 (file)
@@ -24,8 +24,8 @@
 #include "strv.h"
 #include "utf8.h"
 #include "btrfs-util.h"
+#include "path-util.h"
 #include "image.h"
-#include "bus-label.h"
 
 static const char image_search_path[] =
         "/var/lib/container\0"
@@ -46,8 +46,8 @@ static int image_new(
                 const char *name,
                 const char *path,
                 bool read_only,
+                usec_t crtime,
                 usec_t mtime,
-                usec_t btime,
                 Image **ret) {
 
         _cleanup_(image_unrefp) Image *i = NULL;
@@ -63,17 +63,19 @@ static int image_new(
 
         i->type = t;
         i->read_only = read_only;
+        i->crtime = crtime;
         i->mtime = mtime;
-        i->btime = btime;
 
         i->name = strdup(name);
         if (!i->name)
                 return -ENOMEM;
 
         if (path) {
-                i->path = strdup(path);
+                i->path = strjoin(path, "/", name, NULL);
                 if (!i->path)
                         return -ENOMEM;
+
+                path_kill_slashes(i->path);
         }
 
         *ret = i;
@@ -114,25 +116,20 @@ static int image_make(int dfd, const char *name, const char *path, Image **ret)
                                 return -errno;
 
                         if (F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC)) {
-                                usec_t btime = 0;
-                                int ro;
+                                BtrfsSubvolInfo info;
 
                                 /* It's a btrfs subvolume */
 
-                                ro = btrfs_subvol_is_read_only_fd(fd);
-                                if (ro < 0)
-                                        return ro;
-
-                                /* r = btrfs_subvol_get_btime(fd, &btime); */
-                                /* if (r < 0) */
-                                /*         return r; */
+                                r = btrfs_subvol_get_info_fd(fd, &info);
+                                if (r < 0)
+                                        return r;
 
                                 r = image_new(IMAGE_SUBVOLUME,
                                               name,
                                               path,
-                                              ro,
+                                              info.read_only,
+                                              info.otime,
                                               0,
-                                              btime,
                                               ret);
                                 if (r < 0)
                                         return r;
@@ -156,18 +153,24 @@ static int image_make(int dfd, const char *name, const char *path, Image **ret)
                 return 1;
 
         } else if (S_ISREG(st.st_mode) && endswith(name, ".gpt")) {
+                const char *truncated;
+                usec_t crtime = 0;
 
                 /* It's a GPT block device */
 
                 if (!ret)
                         return 1;
 
+                fd_getcrtime_at(dfd, name, &crtime, 0);
+
+                truncated = strndupa(name, strlen(name) - 4);
+
                 r = image_new(IMAGE_GPT,
-                              name,
+                              truncated,
                               path,
-                              !!(st.st_mode & 0111),
+                              !(st.st_mode & 0222),
+                              crtime,
                               timespec_load(&st.st_mtim),
-                              0,
                               ret);
                 if (r < 0)
                         return r;
@@ -264,18 +267,6 @@ void image_hashmap_free(Hashmap *map) {
         hashmap_free(map);
 }
 
-char *image_bus_path(const char *name) {
-        _cleanup_free_ char *e = NULL;
-
-        assert(name);
-
-        e = bus_label_escape(name);
-        if (!e)
-                return NULL;
-
-        return strappend("/org/freedesktop/machine1/image/", e);
-}
-
 static const char* const image_type_table[_IMAGE_TYPE_MAX] = {
         [IMAGE_DIRECTORY] = "directory",
         [IMAGE_SUBVOLUME] = "subvolume",