1 ext4: sysfs: print ext4_super_block fields as little-endian
3 From: Arnd Bergmann <arnd@arndb.de>
5 While working on extended rand for last_error/first_error timestamps,
6 I noticed that the endianess is wrong; we access the little-endian
7 fields in struct ext4_super_block as native-endian when we print them.
9 This adds a special case in ext4_attr_show() and ext4_attr_store()
10 to byteswap the superblock fields if needed.
12 In older kernels, this code was part of super.c, it got moved to
15 Cc: stable@vger.kernel.org
16 Fixes: 52c198c6820f ("ext4: add sysfs entry showing whether the fs contains errors")
17 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
18 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
19 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 fs/ext4/sysfs.c | 13 ++++++++++---
22 1 file changed, 10 insertions(+), 3 deletions(-)
24 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
25 index f34da0bb8f17..b970a200f20c 100644
28 @@ -274,8 +274,12 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
32 - return snprintf(buf, PAGE_SIZE, "%u\n",
33 - *((unsigned int *) ptr));
34 + if (a->attr_ptr == ptr_ext4_super_block_offset)
35 + return snprintf(buf, PAGE_SIZE, "%u\n",
38 + return snprintf(buf, PAGE_SIZE, "%u\n",
39 + *((unsigned int *) ptr));
40 case attr_pointer_atomic:
43 @@ -308,7 +312,10 @@ static ssize_t ext4_attr_store(struct kobject *kobj,
44 ret = kstrtoul(skip_spaces(buf), 0, &t);
47 - *((unsigned int *) ptr) = t;
48 + if (a->attr_ptr == ptr_ext4_super_block_offset)
49 + *((__le32 *) ptr) = cpu_to_le32(t);
51 + *((unsigned int *) ptr) = t;
53 case attr_inode_readahead:
54 return inode_readahead_blks_store(sbi, buf, len);