From patchwork Thu Feb 9 18:13:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 140419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A586BB71A8 for ; Fri, 10 Feb 2012 05:16:19 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RvYWK-0005GS-4R; Thu, 09 Feb 2012 18:15:00 +0000 Received: from mail-pw0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RvYWH-0005ES-GT for linux-mtd@lists.infradead.org; Thu, 09 Feb 2012 18:14:58 +0000 Received: by mail-pw0-f49.google.com with SMTP id un1so605964pbc.36 for ; Thu, 09 Feb 2012 10:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=9mdhfYYzgCncgI+48eSbYYCxAupgW9w39CTUKXVOjH8=; b=Vjsks3nRJWafIF79Hq+u0RlmIwVLZtwkdmTwlxB9Wzl7zV1pqJLNcSedgwyS+SvFqR htU7TyIzn33A5N+LgU/0/BimrPjwUmQX03bXbFDb0LfclVUnN3MP1hJskpavVxf7JBqF NdzPbmEJsCllePy4GFWCMRYvArxxTBHrpV5pI= Received: by 10.68.218.202 with SMTP id pi10mr8463803pbc.16.1328811297245; Thu, 09 Feb 2012 10:14:57 -0800 (PST) Received: from localhost.localdomain (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPS id p9sm7789473pbb.9.2012.02.09.10.14.56 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Feb 2012 10:14:56 -0800 (PST) From: Brian Norris To: Artem Bityutskiy Subject: [PATCH 1/3] limbtd: implement mtd_dev_present for old kernels Date: Thu, 9 Feb 2012 10:13:29 -0800 Message-Id: <1328811211-13653-2-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1328811211-13653-1-git-send-email-computersforpeace@gmail.com> References: <1328811211-13653-1-git-send-email-computersforpeace@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Brian Foster , Artem Bityutskiy , Brian Norris , linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Artem Bityutskiy Implement the 'legacy_dev_present()' function which will check whether an MTD device is present by scanning the /proc/mtd file when the MTD subsystem does not support sysfs (the case for pre-2.6.30 kernels). This patch also moves the 'mtd_dev_present()' function to a slightly more logical position. Signed-off-by: Artem Bityutskiy --- lib/libmtd.c | 25 ++++++++++++------------- lib/libmtd_int.h | 1 + lib/libmtd_legacy.c | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index da9da00..2bb4e57 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -641,6 +641,18 @@ void libmtd_close(libmtd_t desc) free(lib); } +int mtd_dev_present(libmtd_t desc, int mtd_num) { + struct stat st; + struct libmtd *lib = (struct libmtd *)desc; + char file[strlen(lib->mtd) + 10]; + + if (!lib->sysfs_supported) + return legacy_dev_present(mtd_num); + + sprintf(file, lib->mtd, mtd_num); + return !stat(file, &st); +} + int mtd_get_info(libmtd_t desc, struct mtd_info *info) { DIR *sysfs_mtd; @@ -713,19 +725,6 @@ out_close: return -1; } -int mtd_dev_present(libmtd_t desc, int mtd_num) { - struct stat st; - struct libmtd *lib = (struct libmtd *)desc; - char file[strlen(lib->mtd) + 10]; - - if (!lib->sysfs_supported) - /* TODO: add legacy_dev_present() function */ - return 1; - - sprintf(file, lib->mtd, mtd_num); - return !stat(file, &st); -} - int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd) { int ret; diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h index bb48d35..7913e67 100644 --- a/lib/libmtd_int.h +++ b/lib/libmtd_int.h @@ -95,6 +95,7 @@ struct libmtd }; int legacy_libmtd_open(void); +int legacy_dev_present(int mtd_num); int legacy_mtd_get_info(struct mtd_info *info); int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd); int legacy_get_dev_info1(int dev_num, struct mtd_dev_info *mtd); diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c index f0646f3..1ae9946 100644 --- a/lib/libmtd_legacy.c +++ b/lib/libmtd_legacy.c @@ -170,6 +170,31 @@ int legacy_libmtd_open(void) } /** + * legacy_dev_presentl - legacy version of 'mtd_dev_present()'. + * @info: the MTD device information is returned here + * + * When the kernel does not provide sysfs files for the MTD subsystem, + * fall-back to parsing the /proc/mtd file to determine whether an mtd device + * number @mtd_num is present. + */ +int legacy_dev_present(int mtd_num) +{ + int ret; + struct proc_parse_info pi; + + ret = proc_parse_start(&pi); + if (ret) + return -1; + + while (proc_parse_next(&pi)) { + if (pi.mtd_num == mtd_num) + return 1; + } + + return 0; +} + +/** * legacy_mtd_get_info - legacy version of 'mtd_get_info()'. * @info: the MTD device information is returned here *