From 896f937f58f42284dbebcd0a7f5ddc87fd5517b7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Sep 2017 14:19:22 +0200 Subject: [PATCH 1/3] dissect: automatically mark partitions read-only that have a read-only file system Specifically, squashfs and iso9660 are always read-only, hence make sure we never even think about mounting them writable. --- src/basic/mount-util.c | 13 +++++++++++++ src/basic/mount-util.h | 1 + src/shared/dissect-image.c | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index cff44116c8..843d266a2f 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -578,6 +578,19 @@ bool fstype_is_api_vfs(const char *fstype) { return nulstr_contains(table, fstype); } +bool fstype_is_ro(const char *fstype) { + + /* All Linux file systems that are necessarily read-only */ + + static const char table[] = + "DM_verity_hash\0" + "iso9660\0" + "squashfs\0" + ; + + return nulstr_contains(table, fstype); +} + int repeat_unmount(const char *path, int flags) { bool done = false; diff --git a/src/basic/mount-util.h b/src/basic/mount-util.h index 70af11c2ff..3ec0e7d1f8 100644 --- a/src/basic/mount-util.h +++ b/src/basic/mount-util.h @@ -45,6 +45,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent); bool fstype_is_network(const char *fstype); bool fstype_is_api_vfs(const char *fstype); +bool fstype_is_ro(const char *fsype); union file_handle_union { struct file_handle handle; diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index f11b522558..b02b2897d3 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -591,6 +591,9 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI if (streq_ptr(p->fstype, "crypto_LUKS")) m->encrypted = true; + + if (p->fstype && fstype_is_ro(p->fstype)) + p->rw = false; } *ret = m; From 154d22695ad6f131f0e2f99b895b3b1038c10eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Sep 2017 14:23:17 +0200 Subject: [PATCH 2/3] dissect: split list of discard-supporting fs out into mount-util.c Let's manage the list of file systems that do a specific thing at one place, following similar naming. No functional changes. --- src/basic/mount-util.c | 12 ++++++++++++ src/basic/mount-util.h | 1 + src/shared/dissect-image.c | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index 843d266a2f..9069280721 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -591,6 +591,18 @@ bool fstype_is_ro(const char *fstype) { return nulstr_contains(table, fstype); } +bool fstype_can_discard(const char *fstype) { + + static const char table[] = + "btrfs\0" + "ext4\0" + "vfat\0" + "xfs\0" + ; + + return nulstr_contains(table, fstype); +} + int repeat_unmount(const char *path, int flags) { bool done = false; diff --git a/src/basic/mount-util.h b/src/basic/mount-util.h index 3ec0e7d1f8..1e066d8886 100644 --- a/src/basic/mount-util.h +++ b/src/basic/mount-util.h @@ -46,6 +46,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent); bool fstype_is_network(const char *fstype); bool fstype_is_api_vfs(const char *fstype); bool fstype_is_ro(const char *fsype); +bool fstype_can_discard(const char *fstype); union file_handle_union { struct file_handle handle; diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index b02b2897d3..243a46f2e3 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -684,7 +684,7 @@ static int mount_partition( p = where; /* If requested, turn on discard support. */ - if (STR_IN_SET(fstype, "btrfs", "ext4", "vfat", "xfs") && + if (fstype_can_discard(fstype) && ((flags & DISSECT_IMAGE_DISCARD) || ((flags & DISSECT_IMAGE_DISCARD_ON_LOOP) && is_loop_device(m->node)))) options = "discard"; From 7941e2189bf0a2118d4ad1fcf5ff2da534c3b67d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Sep 2017 14:36:06 +0200 Subject: [PATCH 3/3] mount-util: add fusectl to list of API VFS --- src/basic/mount-util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index 9069280721..8c1d2bc9c9 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -564,6 +564,7 @@ bool fstype_is_api_vfs(const char *fstype) { "devpts\0" "devtmpfs\0" "efivarfs\0" + "fusectl\0" "hugetlbfs\0" "mqueue\0" "proc\0"