[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1268959842-4697-2-git-send-email-tytso@mit.edu>
Date: Thu, 18 Mar 2010 20:50:41 -0400
From: Theodore Ts'o <tytso@....edu>
To: Ext4 Developers List <linux-ext4@...r.kernel.org>
Cc: Theodore Ts'o <tytso@....edu>
Subject: [PATCH, RFC 2/3] ext4: Add support for adding boolean toggls to ext4's sysfs directory
Signed-off-by: "Theodore Ts'o" <tytso@....edu>
---
fs/ext4/super.c | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 3d1a056..1d23b65 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2213,6 +2213,7 @@ struct ext4_attr {
ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
const char *, size_t);
int offset;
+ unsigned int mask;
};
static int parse_strtoul(const char *buf,
@@ -2294,12 +2295,40 @@ static ssize_t sbi_ui_store(struct ext4_attr *a,
return count;
}
-#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
+static ssize_t sbi_bool_show(struct ext4_attr *a,
+ struct ext4_sb_info *sbi, char *buf)
+{
+ unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n",
+ ((*ui & a->mask) == 0) ? 0 : 1);
+}
+
+static ssize_t sbi_bool_store(struct ext4_attr *a,
+ struct ext4_sb_info *sbi,
+ const char *buf, size_t count)
+{
+ unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
+ unsigned long t;
+
+ if (parse_strtoul(buf, 0xffffffff, &t))
+ return -EINVAL;
+ if (t)
+ *ui |= a->mask;
+ else
+ *ui &= ~a->mask;
+
+ return count;
+}
+
+
+#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname,_mask)\
static struct ext4_attr ext4_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.show = _show, \
.store = _store, \
.offset = offsetof(struct ext4_sb_info, _elname), \
+ .mask = (_mask), \
}
#define EXT4_ATTR(name, mode, show, store) \
static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
@@ -2307,14 +2336,16 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
#define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
#define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
#define EXT4_RW_ATTR_SBI_UI(name, elname) \
- EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
+ EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname, 0)
+#define EXT4_RW_ATTR_SBI_BOOL(name, elname, mask) \
+EXT4_ATTR_OFFSET(name, 0644, sbi_bool_show, sbi_bool_store, elname, mask)
#define ATTR_LIST(name) &ext4_attr_##name.attr
EXT4_RO_ATTR(delayed_allocation_blocks);
EXT4_RO_ATTR(session_write_kbytes);
EXT4_RO_ATTR(lifetime_write_kbytes);
EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
- inode_readahead_blks_store, s_inode_readahead_blks);
+ inode_readahead_blks_store, s_inode_readahead_blks, 0);
EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
--
1.6.6.1.1.g974db.dirty
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists