1 ext4: add support for adding boolean toggles to ext4's sysfs directory
3 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
5 fs/ext4/super.c | 38 ++++++++++++++++++++++++++++++++++----
6 1 file changed, 34 insertions(+), 4 deletions(-)
8 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
9 index bf1b8a8..2d294b7 100644
12 @@ -2535,6 +2535,7 @@ struct ext4_attr {
19 static int parse_strtoull(const char *buf,
20 @@ -2677,7 +2678,33 @@ static ssize_t sbi_deprecated_show(struct ext4_attr *a,
21 return snprintf(buf, PAGE_SIZE, "%d\n", a->u.deprecated_val);
24 -#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
25 +static ssize_t sbi_bool_show(struct ext4_attr *a,
26 + struct ext4_sb_info *sbi, char *buf)
28 + unsigned int *ui = (unsigned int *) (((char *) sbi) + a->u.offset);
30 + return snprintf(buf, PAGE_SIZE, "%d\n",
31 + ((*ui & a->mask) == 0) ? 0 : 1);
34 +static ssize_t sbi_bool_store(struct ext4_attr *a,
35 + struct ext4_sb_info *sbi,
36 + const char *buf, size_t count)
38 + unsigned int *ui = (unsigned int *) (((char *) sbi) + a->u.offset);
39 + unsigned long long t;
41 + if (parse_strtoull(buf, 0xffffffff, &t))
51 +#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname,_mask)\
52 static struct ext4_attr ext4_attr_##_name = { \
53 .attr = {.name = __stringify(_name), .mode = _mode }, \
55 @@ -2685,6 +2712,7 @@ static struct ext4_attr ext4_attr_##_name = { \
57 .offset = offsetof(struct ext4_sb_info, _elname),\
62 #define EXT4_ATTR_OFFSET_ES(_name,_mode,_show,_store,_elname) \
63 @@ -2707,8 +2735,10 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
64 #define EXT4_RO_ATTR_ES_UI(name, elname) \
65 EXT4_ATTR_OFFSET_ES(name, 0444, es_ui_show, NULL, elname)
66 #define EXT4_RW_ATTR_SBI_UI(name, elname) \
67 - EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
69 + EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname, 0)
70 +#define EXT4_RW_ATTR_SBI_BOOL(name, elname, mask) \
71 + EXT4_ATTR_OFFSET(name, 0644, sbi_bool_show, sbi_bool_store, \
73 #define ATTR_LIST(name) &ext4_attr_##name.attr
74 #define EXT4_DEPRECATED_ATTR(_name, _val) \
75 static struct ext4_attr ext4_attr_##_name = { \
76 @@ -2724,7 +2754,7 @@ EXT4_RO_ATTR(session_write_kbytes);
77 EXT4_RO_ATTR(lifetime_write_kbytes);
78 EXT4_RW_ATTR(reserved_clusters);
79 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
80 - inode_readahead_blks_store, s_inode_readahead_blks);
81 + inode_readahead_blks_store, s_inode_readahead_blks, 0);
82 EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
83 EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
84 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);