1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2013 Lennart Poettering
19 #include "alloc-util.h"
20 #include "btrfs-util.h"
21 #include "chattr-util.h"
23 #include "dirent-util.h"
24 #include "dissect-image.h"
30 #include "hostname-util.h"
31 #include "id128-util.h"
32 #include "lockfile-util.h"
34 #include "loop-util.h"
35 #include "machine-image.h"
39 #include "path-util.h"
41 #include "string-table.h"
42 #include "string-util.h"
44 #include "time-util.h"
47 #include "xattr-util.h"
49 static const char image_search_path
[] =
51 "/var/lib/container\0" /* legacy */
52 "/usr/local/lib/machines\0"
53 "/usr/lib/machines\0";
55 Image
*image_unref(Image
*i
) {
63 strv_free(i
->machine_info
);
64 strv_free(i
->os_release
);
69 static char **image_settings_path(Image
*image
) {
70 _cleanup_strv_free_
char **l
= NULL
;
80 fn
= strjoina(image
->name
, ".nspawn");
82 FOREACH_STRING(s
, "/etc/systemd/nspawn/", "/run/systemd/nspawn/") {
83 l
[i
] = strappend(s
, fn
);
90 l
[i
] = file_in_same_dir(image
->path
, fn
);
97 static char *image_roothash_path(Image
*image
) {
102 fn
= strjoina(image
->name
, ".roothash");
104 return file_in_same_dir(image
->path
, fn
);
107 static int image_new(
111 const char *filename
,
117 _cleanup_(image_unrefp
) Image
*i
= NULL
;
120 assert(t
< _IMAGE_TYPE_MAX
);
130 i
->read_only
= read_only
;
133 i
->usage
= i
->usage_exclusive
= (uint64_t) -1;
134 i
->limit
= i
->limit_exclusive
= (uint64_t) -1;
136 i
->name
= strdup(pretty
);
141 i
->path
= strjoin(path
, "/", filename
);
143 i
->path
= strdup(filename
);
148 path_kill_slashes(i
->path
);
155 static int image_make(
159 const char *filename
,
168 /* We explicitly *do* follow symlinks here, since we want to allow symlinking trees, raw files and block
169 * devices into /var/lib/machines/, and treat them normally. */
171 if (fstatat(dfd
, filename
, &st
, 0) < 0)
175 (path
&& path_startswith(path
, "/usr")) ||
176 (faccessat(dfd
, filename
, W_OK
, AT_EACCESS
) < 0 && errno
== EROFS
);
178 if (S_ISDIR(st
.st_mode
)) {
179 _cleanup_close_
int fd
= -1;
180 unsigned file_attr
= 0;
188 fd
= openat(dfd
, filename
, O_CLOEXEC
|O_NOCTTY
|O_DIRECTORY
);
192 /* btrfs subvolumes have inode 256 */
193 if (st
.st_ino
== 256) {
195 r
= btrfs_is_filesystem(fd
);
199 BtrfsSubvolInfo info
;
201 /* It's a btrfs subvolume */
203 r
= btrfs_subvol_get_info_fd(fd
, 0, &info
);
207 r
= image_new(IMAGE_SUBVOLUME
,
211 info
.read_only
|| read_only
,
218 if (btrfs_quota_scan_ongoing(fd
) == 0) {
219 BtrfsQuotaInfo quota
;
221 r
= btrfs_subvol_get_subtree_quota_fd(fd
, 0, "a
);
223 (*ret
)->usage
= quota
.referenced
;
224 (*ret
)->usage_exclusive
= quota
.exclusive
;
226 (*ret
)->limit
= quota
.referenced_max
;
227 (*ret
)->limit_exclusive
= quota
.exclusive_max
;
235 /* If the IMMUTABLE bit is set, we consider the
236 * directory read-only. Since the ioctl is not
237 * supported everywhere we ignore failures. */
238 (void) read_attr_fd(fd
, &file_attr
);
240 /* It's just a normal directory. */
241 r
= image_new(IMAGE_DIRECTORY
,
245 read_only
|| (file_attr
& FS_IMMUTABLE_FL
),
254 } else if (S_ISREG(st
.st_mode
) && endswith(filename
, ".raw")) {
257 /* It's a RAW disk image */
262 fd_getcrtime_at(dfd
, filename
, &crtime
, 0);
265 pretty
= strndupa(filename
, strlen(filename
) - 4);
267 r
= image_new(IMAGE_RAW
,
271 !(st
.st_mode
& 0222) || read_only
,
273 timespec_load(&st
.st_mtim
),
278 (*ret
)->usage
= (*ret
)->usage_exclusive
= st
.st_blocks
* 512;
279 (*ret
)->limit
= (*ret
)->limit_exclusive
= st
.st_size
;
283 } else if (S_ISBLK(st
.st_mode
)) {
284 _cleanup_close_
int block_fd
= -1;
285 uint64_t size
= UINT64_MAX
;
295 block_fd
= openat(dfd
, filename
, O_RDONLY
|O_NONBLOCK
|O_CLOEXEC
|O_NOCTTY
);
297 log_debug_errno(errno
, "Failed to open block device %s/%s, ignoring: %m", path
, filename
);
299 if (fstat(block_fd
, &st
) < 0)
301 if (!S_ISBLK(st
.st_mode
)) /* Verify that what we opened is actually what we think it is */
307 if (ioctl(block_fd
, BLKROGET
, &state
) < 0)
308 log_debug_errno(errno
, "Failed to issue BLKROGET on device %s/%s, ignoring: %m", path
, filename
);
313 if (ioctl(block_fd
, BLKGETSIZE64
, &size
) < 0)
314 log_debug_errno(errno
, "Failed to issue BLKFLSBUF on device %s/%s, ignoring: %m", path
, filename
);
316 block_fd
= safe_close(block_fd
);
319 r
= image_new(IMAGE_BLOCK
,
323 !(st
.st_mode
& 0222) || read_only
,
330 if (size
!= 0 && size
!= UINT64_MAX
)
331 (*ret
)->usage
= (*ret
)->usage_exclusive
= (*ret
)->limit
= (*ret
)->limit_exclusive
= size
;
339 int image_find(const char *name
, Image
**ret
) {
345 /* There are no images with invalid names */
346 if (!image_name_is_valid(name
))
349 NULSTR_FOREACH(path
, image_search_path
) {
350 _cleanup_closedir_
DIR *d
= NULL
;
360 r
= image_make(NULL
, dirfd(d
), path
, name
, ret
);
361 if (IN_SET(r
, 0, -ENOENT
)) {
362 _cleanup_free_
char *raw
= NULL
;
364 raw
= strappend(name
, ".raw");
368 r
= image_make(NULL
, dirfd(d
), path
, raw
, ret
);
369 if (IN_SET(r
, 0, -ENOENT
))
378 if (streq(name
, ".host"))
379 return image_make(".host", AT_FDCWD
, NULL
, "/", ret
);
384 int image_discover(Hashmap
*h
) {
390 NULSTR_FOREACH(path
, image_search_path
) {
391 _cleanup_closedir_
DIR *d
= NULL
;
402 FOREACH_DIRENT_ALL(de
, d
, return -errno
) {
403 _cleanup_(image_unrefp
) Image
*image
= NULL
;
405 if (!image_name_is_valid(de
->d_name
))
408 if (hashmap_contains(h
, de
->d_name
))
411 r
= image_make(NULL
, dirfd(d
), path
, de
->d_name
, &image
);
412 if (IN_SET(r
, 0, -ENOENT
))
417 r
= hashmap_put(h
, image
->name
, image
);
425 if (!hashmap_contains(h
, ".host")) {
426 _cleanup_(image_unrefp
) Image
*image
= NULL
;
428 r
= image_make(".host", AT_FDCWD
, NULL
, "/", &image
);
432 r
= hashmap_put(h
, image
->name
, image
);
443 int image_remove(Image
*i
) {
444 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
;
445 _cleanup_strv_free_
char **settings
= NULL
;
446 _cleanup_free_
char *roothash
= NULL
;
452 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
455 settings
= image_settings_path(i
);
459 roothash
= image_roothash_path(i
);
463 /* Make sure we don't interfere with a running nspawn */
464 r
= image_path_lock(i
->path
, LOCK_EX
|LOCK_NB
, &global_lock
, &local_lock
);
470 case IMAGE_SUBVOLUME
:
472 /* Let's unlink first, maybe it is a symlink? If that works we are happy. Otherwise, let's get out the
474 if (unlink(i
->path
) < 0) {
475 r
= btrfs_subvol_remove(i
->path
, BTRFS_REMOVE_RECURSIVE
|BTRFS_REMOVE_QUOTA
);
482 case IMAGE_DIRECTORY
:
483 /* Allow deletion of read-only directories */
484 (void) chattr_path(i
->path
, 0, FS_IMMUTABLE_FL
);
485 r
= rm_rf(i
->path
, REMOVE_ROOT
|REMOVE_PHYSICAL
|REMOVE_SUBVOLUME
);
493 /* If this is inside of /dev, then it's a real block device, hence let's not touch the device node
494 * itself (but let's remove the stuff stored alongside it). If it's anywhere else, let's try to unlink
495 * the thing (it's most likely a symlink after all). */
497 if (path_startswith(i
->path
, "/dev"))
502 if (unlink(i
->path
) < 0)
510 STRV_FOREACH(j
, settings
) {
511 if (unlink(*j
) < 0 && errno
!= ENOENT
)
512 log_debug_errno(errno
, "Failed to unlink %s, ignoring: %m", *j
);
515 if (unlink(roothash
) < 0 && errno
!= ENOENT
)
516 log_debug_errno(errno
, "Failed to unlink %s, ignoring: %m", roothash
);
521 static int rename_auxiliary_file(const char *path
, const char *new_name
, const char *suffix
) {
522 _cleanup_free_
char *rs
= NULL
;
525 fn
= strjoina(new_name
, suffix
);
527 rs
= file_in_same_dir(path
, fn
);
531 return rename_noreplace(AT_FDCWD
, path
, AT_FDCWD
, rs
);
534 int image_rename(Image
*i
, const char *new_name
) {
535 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
, name_lock
= LOCK_FILE_INIT
;
536 _cleanup_free_
char *new_path
= NULL
, *nn
= NULL
, *roothash
= NULL
;
537 _cleanup_strv_free_
char **settings
= NULL
;
538 unsigned file_attr
= 0;
544 if (!image_name_is_valid(new_name
))
547 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
550 settings
= image_settings_path(i
);
554 roothash
= image_roothash_path(i
);
558 /* Make sure we don't interfere with a running nspawn */
559 r
= image_path_lock(i
->path
, LOCK_EX
|LOCK_NB
, &global_lock
, &local_lock
);
563 /* Make sure nobody takes the new name, between the time we
564 * checked it is currently unused in all search paths, and the
565 * time we take possession of it */
566 r
= image_name_lock(new_name
, LOCK_EX
|LOCK_NB
, &name_lock
);
570 r
= image_find(new_name
, NULL
);
578 case IMAGE_DIRECTORY
:
579 /* Turn of the immutable bit while we rename the image, so that we can rename it */
580 (void) read_attr_path(i
->path
, &file_attr
);
582 if (file_attr
& FS_IMMUTABLE_FL
)
583 (void) chattr_path(i
->path
, 0, FS_IMMUTABLE_FL
);
586 case IMAGE_SUBVOLUME
:
587 new_path
= file_in_same_dir(i
->path
, new_name
);
592 /* Refuse renaming raw block devices in /dev, the names are picked by udev after all. */
593 if (path_startswith(i
->path
, "/dev"))
596 new_path
= file_in_same_dir(i
->path
, new_name
);
602 fn
= strjoina(new_name
, ".raw");
603 new_path
= file_in_same_dir(i
->path
, fn
);
614 nn
= strdup(new_name
);
618 r
= rename_noreplace(AT_FDCWD
, i
->path
, AT_FDCWD
, new_path
);
622 /* Restore the immutable bit, if it was set before */
623 if (file_attr
& FS_IMMUTABLE_FL
)
624 (void) chattr_path(new_path
, FS_IMMUTABLE_FL
, FS_IMMUTABLE_FL
);
626 free_and_replace(i
->path
, new_path
);
627 free_and_replace(i
->name
, nn
);
629 STRV_FOREACH(j
, settings
) {
630 r
= rename_auxiliary_file(*j
, new_name
, ".nspawn");
631 if (r
< 0 && r
!= -ENOENT
)
632 log_debug_errno(r
, "Failed to rename settings file %s, ignoring: %m", *j
);
635 r
= rename_auxiliary_file(roothash
, new_name
, ".roothash");
636 if (r
< 0 && r
!= -ENOENT
)
637 log_debug_errno(r
, "Failed to rename roothash file %s, ignoring: %m", roothash
);
642 static int clone_auxiliary_file(const char *path
, const char *new_name
, const char *suffix
) {
643 _cleanup_free_
char *rs
= NULL
;
646 fn
= strjoina(new_name
, suffix
);
648 rs
= file_in_same_dir(path
, fn
);
652 return copy_file_atomic(path
, rs
, 0664, 0, COPY_REFLINK
);
655 int image_clone(Image
*i
, const char *new_name
, bool read_only
) {
656 _cleanup_(release_lock_file
) LockFile name_lock
= LOCK_FILE_INIT
;
657 _cleanup_strv_free_
char **settings
= NULL
;
658 _cleanup_free_
char *roothash
= NULL
;
659 const char *new_path
;
665 if (!image_name_is_valid(new_name
))
668 settings
= image_settings_path(i
);
672 roothash
= image_roothash_path(i
);
676 /* Make sure nobody takes the new name, between the time we
677 * checked it is currently unused in all search paths, and the
678 * time we take possession of it */
679 r
= image_name_lock(new_name
, LOCK_EX
|LOCK_NB
, &name_lock
);
683 r
= image_find(new_name
, NULL
);
691 case IMAGE_SUBVOLUME
:
692 case IMAGE_DIRECTORY
:
693 /* If we can we'll always try to create a new btrfs subvolume here, even if the source is a plain
696 new_path
= strjoina("/var/lib/machines/", new_name
);
698 r
= btrfs_subvol_snapshot(i
->path
, new_path
,
699 (read_only
? BTRFS_SNAPSHOT_READ_ONLY
: 0) |
700 BTRFS_SNAPSHOT_FALLBACK_COPY
|
701 BTRFS_SNAPSHOT_FALLBACK_DIRECTORY
|
702 BTRFS_SNAPSHOT_FALLBACK_IMMUTABLE
|
703 BTRFS_SNAPSHOT_RECURSIVE
|
704 BTRFS_SNAPSHOT_QUOTA
);
706 /* Enable "subtree" quotas for the copy, if we didn't copy any quota from the source. */
707 (void) btrfs_subvol_auto_qgroup(new_path
, 0, true);
712 new_path
= strjoina("/var/lib/machines/", new_name
, ".raw");
714 r
= copy_file_atomic(i
->path
, new_path
, read_only
? 0444 : 0644, FS_NOCOW_FL
, COPY_REFLINK
);
725 STRV_FOREACH(j
, settings
) {
726 r
= clone_auxiliary_file(*j
, new_name
, ".nspawn");
727 if (r
< 0 && r
!= -ENOENT
)
728 log_debug_errno(r
, "Failed to clone settings %s, ignoring: %m", *j
);
731 r
= clone_auxiliary_file(roothash
, new_name
, ".roothash");
732 if (r
< 0 && r
!= -ENOENT
)
733 log_debug_errno(r
, "Failed to clone root hash file %s, ignoring: %m", roothash
);
738 int image_read_only(Image
*i
, bool b
) {
739 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
;
744 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
747 /* Make sure we don't interfere with a running nspawn */
748 r
= image_path_lock(i
->path
, LOCK_EX
|LOCK_NB
, &global_lock
, &local_lock
);
754 case IMAGE_SUBVOLUME
:
756 /* Note that we set the flag only on the top-level
757 * subvolume of the image. */
759 r
= btrfs_subvol_set_read_only(i
->path
, b
);
765 case IMAGE_DIRECTORY
:
766 /* For simple directory trees we cannot use the access
767 mode of the top-level directory, since it has an
768 effect on the container itself. However, we can
769 use the "immutable" flag, to at least make the
770 top-level directory read-only. It's not as good as
771 a read-only subvolume, but at least something, and
772 we can read the value back. */
774 r
= chattr_path(i
->path
, b
? FS_IMMUTABLE_FL
: 0, FS_IMMUTABLE_FL
);
783 if (stat(i
->path
, &st
) < 0)
786 if (chmod(i
->path
, (st
.st_mode
& 0444) | (b
? 0000 : 0200)) < 0)
789 /* If the images is now read-only, it's a good time to
790 * defrag it, given that no write patterns will
791 * fragment it again. */
793 (void) btrfs_defrag(i
->path
);
798 _cleanup_close_
int fd
= -1;
802 fd
= open(i
->path
, O_CLOEXEC
|O_RDONLY
|O_NONBLOCK
|O_NOCTTY
);
806 if (fstat(fd
, &st
) < 0)
808 if (!S_ISBLK(st
.st_mode
))
811 if (ioctl(fd
, BLKROSET
, &state
) < 0)
824 int image_path_lock(const char *path
, int operation
, LockFile
*global
, LockFile
*local
) {
825 _cleanup_free_
char *p
= NULL
;
826 LockFile t
= LOCK_FILE_INIT
;
834 /* Locks an image path. This actually creates two locks: one
835 * "local" one, next to the image path itself, which might be
836 * shared via NFS. And another "global" one, in /run, that
837 * uses the device/inode number. This has the benefit that we
838 * can even lock a tree that is a mount point, correctly. */
840 if (!path_is_absolute(path
))
843 if (getenv_bool("SYSTEMD_NSPAWN_LOCK") == 0) {
844 *local
= *global
= (LockFile
) LOCK_FILE_INIT
;
848 if (path_equal(path
, "/"))
851 if (stat(path
, &st
) >= 0) {
852 if (S_ISBLK(st
.st_mode
))
853 r
= asprintf(&p
, "/run/systemd/nspawn/locks/block-%u:%u", major(st
.st_rdev
), minor(st
.st_rdev
));
854 else if (S_ISDIR(st
.st_mode
) || S_ISREG(st
.st_mode
))
855 r
= asprintf(&p
, "/run/systemd/nspawn/locks/inode-%lu:%lu", (unsigned long) st
.st_dev
, (unsigned long) st
.st_ino
);
863 /* For block devices we don't need the "local" lock, as the major/minor lock above should be sufficient, since
864 * block devices are device local anyway. */
865 if (!path_startswith(path
, "/dev")) {
866 r
= make_lock_file_for(path
, operation
, &t
);
868 if ((operation
& LOCK_SH
) && r
== -EROFS
)
869 log_debug_errno(r
, "Failed to create shared lock for '%s', ignoring: %m", path
);
876 mkdir_p("/run/systemd/nspawn/locks", 0700);
878 r
= make_lock_file(p
, operation
, global
);
880 release_lock_file(&t
);
884 *global
= (LockFile
) LOCK_FILE_INIT
;
890 int image_set_limit(Image
*i
, uint64_t referenced_max
) {
893 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
896 if (i
->type
!= IMAGE_SUBVOLUME
)
899 /* We set the quota both for the subvolume as well as for the
900 * subtree. The latter is mostly for historical reasons, since
901 * we didn't use to have a concept of subtree quota, and hence
902 * only modified the subvolume quota. */
904 (void) btrfs_qgroup_set_limit(i
->path
, 0, referenced_max
);
905 (void) btrfs_subvol_auto_qgroup(i
->path
, 0, true);
906 return btrfs_subvol_set_subtree_quota_limit(i
->path
, 0, referenced_max
);
909 int image_read_metadata(Image
*i
) {
910 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
;
915 r
= image_path_lock(i
->path
, LOCK_SH
|LOCK_NB
, &global_lock
, &local_lock
);
921 case IMAGE_SUBVOLUME
:
922 case IMAGE_DIRECTORY
: {
923 _cleanup_strv_free_
char **machine_info
= NULL
, **os_release
= NULL
;
924 sd_id128_t machine_id
= SD_ID128_NULL
;
925 _cleanup_free_
char *hostname
= NULL
;
926 _cleanup_free_
char *path
= NULL
;
927 _cleanup_fclose_
FILE *f
= NULL
;
929 r
= chase_symlinks("/etc/hostname", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
930 if (r
< 0 && r
!= -ENOENT
)
931 log_debug_errno(r
, "Failed to chase /etc/hostname in image %s: %m", i
->name
);
933 r
= read_etc_hostname(path
, &hostname
);
935 log_debug_errno(errno
, "Failed to read /etc/hostname of image %s: %m", i
->name
);
940 r
= chase_symlinks("/etc/machine-id", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
941 if (r
< 0 && r
!= -ENOENT
)
942 log_debug_errno(r
, "Failed to chase /etc/machine-id in image %s: %m", i
->name
);
944 _cleanup_close_
int fd
= -1;
946 fd
= open(path
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
948 log_debug_errno(errno
, "Failed to open %s: %m", path
);
950 r
= id128_read_fd(fd
, ID128_PLAIN
, &machine_id
);
952 log_debug_errno(r
, "Image %s contains invalid machine ID.", i
->name
);
958 r
= chase_symlinks("/etc/machine-info", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
959 if (r
< 0 && r
!= -ENOENT
)
960 log_debug_errno(r
, "Failed to chase /etc/machine-info in image %s: %m", i
->name
);
962 r
= load_env_file_pairs(NULL
, path
, NULL
, &machine_info
);
964 log_debug_errno(r
, "Failed to parse machine-info data of %s: %m", i
->name
);
967 r
= load_os_release_pairs(i
->path
, &os_release
);
969 log_debug_errno(r
, "Failed to read os-release in image, ignoring: %m");
971 free_and_replace(i
->hostname
, hostname
);
972 i
->machine_id
= machine_id
;
973 strv_free_and_replace(i
->machine_info
, machine_info
);
974 strv_free_and_replace(i
->os_release
, os_release
);
981 _cleanup_(loop_device_unrefp
) LoopDevice
*d
= NULL
;
982 _cleanup_(dissected_image_unrefp
) DissectedImage
*m
= NULL
;
984 r
= loop_device_make_by_path(i
->path
, O_RDONLY
, &d
);
988 r
= dissect_image(d
->fd
, NULL
, 0, DISSECT_IMAGE_REQUIRE_ROOT
, &m
);
992 r
= dissected_image_acquire_metadata(m
);
996 free_and_replace(i
->hostname
, m
->hostname
);
997 i
->machine_id
= m
->machine_id
;
998 strv_free_and_replace(i
->machine_info
, m
->machine_info
);
999 strv_free_and_replace(i
->os_release
, m
->os_release
);
1008 i
->metadata_valid
= true;
1013 int image_name_lock(const char *name
, int operation
, LockFile
*ret
) {
1019 /* Locks an image name, regardless of the precise path used. */
1021 if (!image_name_is_valid(name
))
1024 if (getenv_bool("SYSTEMD_NSPAWN_LOCK") == 0) {
1025 *ret
= (LockFile
) LOCK_FILE_INIT
;
1029 if (streq(name
, ".host"))
1032 mkdir_p("/run/systemd/nspawn/locks", 0700);
1033 p
= strjoina("/run/systemd/nspawn/locks/name-", name
);
1035 return make_lock_file(p
, operation
, ret
);
1038 bool image_name_is_valid(const char *s
) {
1039 if (!filename_is_valid(s
))
1042 if (string_has_cc(s
, NULL
))
1045 if (!utf8_is_valid(s
))
1048 /* Temporary files for atomically creating new files */
1049 if (startswith(s
, ".#"))
1055 static const char* const image_type_table
[_IMAGE_TYPE_MAX
] = {
1056 [IMAGE_DIRECTORY
] = "directory",
1057 [IMAGE_SUBVOLUME
] = "subvolume",
1058 [IMAGE_RAW
] = "raw",
1059 [IMAGE_BLOCK
] = "block",
1062 DEFINE_STRING_TABLE_LOOKUP(image_type
, ImageType
);