Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423891AbbFEOhG (ORCPT ); Fri, 5 Jun 2015 10:37:06 -0400 Received: from opensource.wolfsonmicro.com ([80.75.67.52]:55226 "EHLO opensource.wolfsonmicro.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030242AbbFEOgz (ORCPT ); Fri, 5 Jun 2015 10:36:55 -0400 From: Richard Fitzgerald 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 Message-Id: <1433514886-11884-2-git-send-email-rf@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1433514886-11884-1-git-send-email-rf@opensource.wolfsonmicro.com> References: <1433514886-11884-1-git-send-email-rf@opensource.wolfsonmicro.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2438 Lines: 76 The various integer functions support read-only and write-only versions so extend this to bool types. Signed-off-by: Richard Fitzgerald --- 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/