From patchwork Tue Sep 15 09:02:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 517730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7B009140082 for ; Tue, 15 Sep 2015 19:11:42 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZbmFQ-0003oK-TP; Tue, 15 Sep 2015 09:09:56 +0000 Received: from [59.151.112.132] (helo=heian.cn.fujitsu.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZbmEt-0002kO-NK for linux-mtd@lists.infradead.org; Tue, 15 Sep 2015 09:09:24 +0000 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100730365" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 15 Sep 2015 17:11:59 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8F98qmS008016; Tue, 15 Sep 2015 17:08:52 +0800 Received: from yds-PC.g08.fujitsu.local (10.167.226.66) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 15 Sep 2015 17:09:07 +0800 From: Dongsheng Yang To: , , , Subject: [PATCH v3 09/39] fs: char_dev: introduce lookup_cdev to get cdev by pathname Date: Tue, 15 Sep 2015 17:02:04 +0800 Message-ID: <1442307754-13233-10-git-send-email-yangds.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1442307754-13233-1-git-send-email-yangds.fnst@cn.fujitsu.com> References: <1442307754-13233-1-git-send-email-yangds.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.66] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150915_020924_019650_DF618D93 X-CRM114-Status: UNSURE ( 7.79 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, Dongsheng Yang , linux-mtd@lists.infradead.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Function lookup_cdev works similarly with lookup_bdev, we can get a cdev instance by lookup_cdev with a parameter of dev name. This function will be used in quotactl to get a cdev by a dev name. Signed-off-by: Dongsheng Yang Reviewed-by: Jan Kara --- fs/char_dev.c | 13 +++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/fs/char_dev.c b/fs/char_dev.c index e818faa..12c1bd5 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -474,6 +474,18 @@ out: return cdev; } +struct cdev *lookup_cdev(const char *pathname) +{ + struct cdev *cdev; + int error; + + error = __lookup_dev(pathname, &cdev, NULL); + if (error) + return ERR_PTR(error); + + return cdev; +} + /** * cdev_add() - add a char device to the system * @p: the cdev structure for the device @@ -596,6 +608,7 @@ void __init chrdev_init(void) EXPORT_SYMBOL(register_chrdev_region); EXPORT_SYMBOL(unregister_chrdev_region); EXPORT_SYMBOL(alloc_chrdev_region); +EXPORT_SYMBOL(lookup_cdev); EXPORT_SYMBOL(cdev_init); EXPORT_SYMBOL(cdev_alloc); EXPORT_SYMBOL(cdev_del); diff --git a/include/linux/fs.h b/include/linux/fs.h index 2c1c122..6f0c614 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2346,6 +2346,8 @@ extern void __unregister_chrdev(unsigned int major, unsigned int baseminor, unsigned int count, const char *name); extern void unregister_chrdev_region(dev_t, unsigned); extern void chrdev_show(struct seq_file *,off_t); +extern struct cdev *lookup_cdev(const char *); + static inline int register_chrdev(unsigned int major, const char *name, const struct file_operations *fops)