Merge pull request #6943 from poettering/dissect-ro

Automatically recognize that "squashfs" and "iso9660" area always read-only
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2017-10-02 20:39:08 +02:00
committed by GitHub
3 changed files with 32 additions and 1 deletions
+26
View File
@@ -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"
@@ -578,6 +579,31 @@ 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);
}
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;
+2
View File
@@ -45,6 +45,8 @@ 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;
+4 -1
View File
@@ -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;
@@ -681,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";