From: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
To: gregkh@linuxfoundation.org, broonie@kernel.org
Cc: linux-kernel@vger.kernel.org, patches@opensource.wolfsonmicro.com
Subject: [PATCH 1/2] debugfs: support read-only and write-only bool types
Date: Fri, 5 Jun 2015 15:34:45 +0100 [thread overview]
Message-ID: <1433514886-11884-2-git-send-email-rf@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1433514886-11884-1-git-send-email-rf@opensource.wolfsonmicro.com>
The various integer functions support read-only and write-only
versions so extend this to bool types.
Signed-off-by: Richard Fitzgerald <rf@opensource.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
next prev parent reply other threads:[~2015-06-05 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-05 14:34 [PATCH 0/2] debugfs: support read-only and write-only bool types Richard Fitzgerald
2015-06-05 14:34 ` Richard Fitzgerald [this message]
2015-06-05 16:42 ` [PATCH 1/2] " Mark Brown
2015-06-08 20:57 ` Greg KH
2015-06-05 14:34 ` [PATCH 2/2] regmap: Fix permissions on debugfs cache controls Richard Fitzgerald
2015-06-05 15:25 ` Mark Brown
2015-06-05 15:53 ` Richard Fitzgerald
2015-06-05 16:53 ` Mark Brown
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=1433514886-11884-2-git-send-email-rf@opensource.wolfsonmicro.com \
--to=rf@opensource.wolfsonmicro.com \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.wolfsonmicro.com \
/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