[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1433514886-11884-2-git-send-email-rf@opensource.wolfsonmicro.com>
Date: Fri, 5 Jun 2015 15:34:45 +0100
From: Richard Fitzgerald <rf@...nsource.wolfsonmicro.com>
To: gregkh@...uxfoundation.org, broonie@...nel.org
Cc: linux-kernel@...r.kernel.org, patches@...nsource.wolfsonmicro.com
Subject: [PATCH 1/2] debugfs: support read-only and write-only bool types
The various integer functions support read-only and write-only
versions so extend this to bool types.
Signed-off-by: Richard Fitzgerald <rf@...nsource.wolfsonmicro.com>
---
fs/debugfs/file.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 830a7e7..7dc3f8a 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -43,6 +43,18 @@ const struct file_operations debugfs_file_operations = {
.llseek = noop_llseek,
};
+static ssize_t debugs_read_wo_file(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return -EACCES;
+}
+
+static ssize_t debugs_write_ro_file(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return -EACCES;
+}
+
static void *debugfs_follow_link(struct dentry *dentry, struct nameidata *nd)
{
nd_set_link(nd, d_inode(dentry)->i_private);
@@ -488,6 +500,20 @@ static const struct file_operations fops_bool = {
.llseek = default_llseek,
};
+static const struct file_operations fops_bool_ro = {
+ .read = read_file_bool,
+ .write = debugs_write_ro_file,
+ .open = simple_open,
+ .llseek = default_llseek,
+};
+
+static const struct file_operations fops_bool_wo = {
+ .read = debugs_read_wo_file,
+ .write = write_file_bool,
+ .open = simple_open,
+ .llseek = default_llseek,
+};
+
/**
* debugfs_create_bool - create a debugfs file that is used to read and write a boolean value
* @name: a pointer to a string containing the name of the file to create.
@@ -515,6 +541,15 @@ static const struct file_operations fops_bool = {
struct dentry *debugfs_create_bool(const char *name, umode_t mode,
struct dentry *parent, u32 *value)
{
+ /* if there are no write bits set, make read only */
+ if (!(mode & S_IWUGO))
+ return debugfs_create_file(name, mode, parent, value,
+ &fops_bool_ro);
+ /* if there are no read bits set, make write only */
+ if (!(mode & S_IRUGO))
+ return debugfs_create_file(name, mode, parent, value,
+ &fops_bool_wo);
+
return debugfs_create_file(name, mode, parent, value, &fops_bool);
}
EXPORT_SYMBOL_GPL(debugfs_create_bool);
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists