linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH, RFC 2/3] ext4: Add support for adding boolean toggls to ext4's sysfs directory
Date: Thu, 18 Mar 2010 20:50:41 -0400	[thread overview]
Message-ID: <1268959842-4697-2-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1268959842-4697-1-git-send-email-tytso@mit.edu>

Signed-off-by: "Theodore Ts'o" <tytso@mit.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


  reply	other threads:[~2010-03-19  0:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-19  0:50 [PATCH, RFC 1/3] ext4: Convert calls of ext4_error() to EXT4_ERROR_INODE() Theodore Ts'o
2010-03-19  0:50 ` Theodore Ts'o [this message]
2010-03-19  0:50 ` [PATCH, RFC 3/3] ext4: Add option for squelching ext4 errors to prevent dmesg from filling up Theodore Ts'o
2010-03-19 22:56   ` Andreas Dilger
2010-03-20  2:20     ` tytso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268959842-4697-2-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).