fix bug in add-support-collapse-range
[ext4-patch-queue.git] / kill-i_version-support-for-hurd-OS-filesystems
blob8a263616bcdb4b97a3f60055af4b85d690ea56df
1 ext4: kill i_version support for Hurd-castrated file systems
3 The Hurd file system uses uses the inode field which is now used for
4 i_version for its translator block.  This means that ext2 file systems
5 that are formatted for GNU Hurd can't be used to support NFSv4.  Given
6 that Hurd file systems don't support extents, and a huge number of
7 modern file system features, this is no great loss.
9 If we don't do this, the attempt to update the i_version field will
10 stomp over the translator block field, which will cause file system
11 corruption for Hurd file systems.  This can be replicated via:
13 mke2fs -t ext2 -o hurd /dev/vdc
14 mount -t ext4 /dev/vdc /vdc
15 touch /vdc/bug0000
16 umount /dev/vdc
17 e2fsck -f /dev/vdc
19 Addresses-Debian-Bug: #738758
21 Reported-By: Gabriele Giacone <1o5g4r8o@gmail.com>
22 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
23 ---
24  fs/ext4/inode.c | 29 ++++++++++++++++++-----------
25  1 file changed, 18 insertions(+), 11 deletions(-)
27 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
28 index 7cc2455..ed2c13a 100644
29 --- a/fs/ext4/inode.c
30 +++ b/fs/ext4/inode.c
31 @@ -4168,11 +4168,14 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
32         EXT4_INODE_GET_XTIME(i_atime, inode, raw_inode);
33         EXT4_EINODE_GET_XTIME(i_crtime, ei, raw_inode);
35 -       inode->i_version = le32_to_cpu(raw_inode->i_disk_version);
36 -       if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
37 -               if (EXT4_FITS_IN_INODE(raw_inode, ei, i_version_hi))
38 -                       inode->i_version |=
39 -                       (__u64)(le32_to_cpu(raw_inode->i_version_hi)) << 32;
40 +       if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
41 +           cpu_to_le32(EXT4_OS_HURD)) {
42 +               inode->i_version = le32_to_cpu(raw_inode->i_disk_version);
43 +               if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
44 +                       if (EXT4_FITS_IN_INODE(raw_inode, ei, i_version_hi))
45 +                               inode->i_version |=
46 +                   (__u64)(le32_to_cpu(raw_inode->i_version_hi)) << 32;
47 +               }
48         }
50         ret = 0;
51 @@ -4388,12 +4391,16 @@ static int ext4_do_update_inode(handle_t *handle,
52                         raw_inode->i_block[block] = ei->i_data[block];
53         }
55 -       raw_inode->i_disk_version = cpu_to_le32(inode->i_version);
56 -       if (ei->i_extra_isize) {
57 -               if (EXT4_FITS_IN_INODE(raw_inode, ei, i_version_hi))
58 -                       raw_inode->i_version_hi =
59 -                       cpu_to_le32(inode->i_version >> 32);
60 -               raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);
61 +       if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
62 +           cpu_to_le32(EXT4_OS_HURD)) {
63 +               raw_inode->i_disk_version = cpu_to_le32(inode->i_version);
64 +               if (ei->i_extra_isize) {
65 +                       if (EXT4_FITS_IN_INODE(raw_inode, ei, i_version_hi))
66 +                               raw_inode->i_version_hi =
67 +                                       cpu_to_le32(inode->i_version >> 32);
68 +                       raw_inode->i_extra_isize =
69 +                               cpu_to_le16(ei->i_extra_isize);
70 +               }
71         }
73         ext4_inode_csum_set(inode, raw_inode, ei);