add patch fix-mmap-data-corruption-in-nodelalloc-mode-when-blocksize-lt-pagesize
[ext4-patch-queue.git] / support-read-only-images
blobebf1beff1d0370a6995c44ee6d4fe8f3b5276d09
1 ext4: support read-only images
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 Add a rocompat feature, "readonly" to mark a FS image as read-only.
6 The feature prevents the kernel and e2fsprogs from changing the image;
7 the flag can be toggled by tune2fs.
9 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/ext4.h  |    1 +
13  fs/ext4/super.c |   10 +++++++++-
14  2 files changed, 10 insertions(+), 1 deletion(-)
17 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
18 the body of a message to majordomo@vger.kernel.org
19 More majordomo info at  http://vger.kernel.org/majordomo-info.html
21 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
22 index 3950a2f..5cf937d 100644
23 --- a/fs/ext4/ext4.h
24 +++ b/fs/ext4/ext4.h
25 @@ -1557,6 +1557,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
26   * GDT_CSUM bits are mutually exclusive.
27   */
28  #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM   0x0400
29 +#define EXT4_FEATURE_RO_COMPAT_READONLY                0x1000
31  #define EXT4_FEATURE_INCOMPAT_COMPRESSION      0x0001
32  #define EXT4_FEATURE_INCOMPAT_FILETYPE         0x0002
33 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
34 index 74c5f53..c65dede 100644
35 --- a/fs/ext4/super.c
36 +++ b/fs/ext4/super.c
37 @@ -2776,6 +2776,12 @@ static int ext4_feature_set_ok(struct super_block *sb, int readonly)
38         if (readonly)
39                 return 1;
41 +       if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_READONLY)) {
42 +               ext4_msg(sb, KERN_INFO, "filesystem is read-only");
43 +               sb->s_flags |= MS_RDONLY;
44 +               return 1;
45 +       }
47         /* Check that feature set is OK for a read-write mount */
48         if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP)) {
49                 ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of "
50 @@ -4930,7 +4936,9 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
51                                 ext4_mark_recovery_complete(sb, es);
52                 } else {
53                         /* Make sure we can mount this feature set readwrite */
54 -                       if (!ext4_feature_set_ok(sb, 0)) {
55 +                       if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
56 +                                       EXT4_FEATURE_RO_COMPAT_READONLY) ||
57 +                           !ext4_feature_set_ok(sb, 0)) {
58                                 err = -EROFS;
59                                 goto restore_opts;
60                         }