From patchwork Fri Feb 11 11:46:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatolij Gustschin X-Patchwork-Id: 82747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C62B8B6EE8 for ; Fri, 11 Feb 2011 22:49:02 +1100 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1PnrSO-0004b2-Cg; Fri, 11 Feb 2011 11:46:36 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PnrSL-00062t-Mb; Fri, 11 Feb 2011 11:46:33 +0000 Received: from mail-out.m-online.net ([212.18.0.10]) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PnrSH-00062Z-UZ for linux-mtd@lists.infradead.org; Fri, 11 Feb 2011 11:46:31 +0000 Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 94119186DEC6 for ; Fri, 11 Feb 2011 12:46:27 +0100 (CET) X-Auth-Info: H9AwxnQzuzc2F5YKFuQ7RScfw4cbTc89wspoaylj2rE= Received: from localhost (p4FE3D9F7.dip.t-dialin.net [79.227.217.247]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA id C0E2B1C000F3 for ; Fri, 11 Feb 2011 12:46:27 +0100 (CET) From: Anatolij Gustschin To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: export mtd->writebufsize attribute over sysfs Date: Fri, 11 Feb 2011 12:46:29 +0100 Message-Id: <1297424789-4144-1-git-send-email-agust@denx.de> X-Mailer: git-send-email 1.7.1 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110211_064630_257013_3F9C0264 X-CRM114-Status: GOOD ( 13.46 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [212.18.0.10 listed in list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 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 Also allow to change mtd->writebufsize for MTD ram test device dynamicaly. Signed-off-by: Anatolij Gustschin --- drivers/mtd/mtdcore.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index b177e75..282ad41 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -230,12 +230,40 @@ static ssize_t mtd_name_show(struct device *dev, } static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL); +static ssize_t mtd_writebufsize_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mtd_info *mtd = dev_to_mtd(dev); + + return snprintf(buf, PAGE_SIZE, "%lu\n", + (unsigned long)mtd->writebufsize); +} + +static ssize_t mtd_writebufsize_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct mtd_info *mtd = dev_to_mtd(dev); + unsigned long value; + int ret; + + ret = strict_strtoul(buf, 0, &value); + if (ret < 0) + return ret; + + mtd->writebufsize = value; + return size; +} +static DEVICE_ATTR(writebufsize, S_IRUGO, mtd_writebufsize_show, + mtd_writebufsize_store); + static struct attribute *mtd_attrs[] = { &dev_attr_type.attr, &dev_attr_flags.attr, &dev_attr_size.attr, &dev_attr_erasesize.attr, &dev_attr_writesize.attr, + &dev_attr_writebufsize.attr, &dev_attr_subpagesize.attr, &dev_attr_oobsize.attr, &dev_attr_numeraseregions.attr, @@ -258,6 +286,28 @@ static struct device_type mtd_devtype = { .release = mtd_release, }; +/* + * Make attributes of the mtdram test device writable. + * Useful for testing different UBIFS images. + */ +static inline void mtd_fixup_attr(struct mtd_info *mtd) +{ + struct attribute *attr = mtd_attrs[0]; + int i = 0; + + if (mtd->type != MTD_RAM) + return; + + for (i = 0; mtd_attrs[i]; i++) { + attr = mtd_attrs[i]; + if (!strcmp(attr->name, "writebufsize")) { + sysfs_chmod_file(&mtd->dev.kobj, attr, + S_IRUGO | S_IWUSR | S_IWGRP); + break; + } + } +} + /** * add_mtd_device - register an MTD device * @mtd: pointer to new MTD device info structure @@ -339,6 +389,8 @@ int add_mtd_device(struct mtd_info *mtd) MTD_DEVT(i) + 1, NULL, "mtd%dro", i); + mtd_fixup_attr(mtd); + DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name); /* No need to get a refcount on the module containing the notifier, since we hold the mtd_table_mutex */