Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751551AbXB1Ti1 (ORCPT ); Wed, 28 Feb 2007 14:38:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751755AbXB1Ti0 (ORCPT ); Wed, 28 Feb 2007 14:38:26 -0500 Received: from 3a.49.1343.static.theplanet.com ([67.19.73.58]:39231 "EHLO pug.o-hand.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751529AbXB1ThS (ORCPT ); Wed, 28 Feb 2007 14:37:18 -0500 Subject: [PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute From: Richard Purdie To: LKML , David Woodhouse , herbert@gondor.apana.org.au Cc: linux-mtd , linux-crypto@vger.kernel.org Content-Type: text/plain Date: Wed, 28 Feb 2007 19:13:54 +0000 Message-Id: <1172690034.16062.144.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5250 Lines: 194 Allow selection of the compression mode for jffs2 via a sysfs attribute. This establishes a sysfs presence for jffs2 through which other compression options could easily be exported too. Signed-off-by: Richard Purdie --- fs/jffs2/compr.c | 131 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 37 deletions(-) Index: linux/fs/jffs2/compr.c =================================================================== --- linux.orig/fs/jffs2/compr.c 2007-02-28 18:12:33.000000000 +0000 +++ linux/fs/jffs2/compr.c 2007-02-28 18:12:33.000000000 +0000 @@ -13,6 +13,7 @@ * */ +#include #include "compr.h" static DEFINE_SPINLOCK(jffs2_compressor_list_lock); @@ -298,6 +299,43 @@ int jffs2_unregister_compressor(struct j return 0; } +char *jffs2_get_compression_mode_name(void) +{ + switch (jffs2_compression_mode) { + case JFFS2_COMPR_MODE_NONE: + return "none"; + case JFFS2_COMPR_MODE_PRIORITY: + return "priority"; + case JFFS2_COMPR_MODE_SIZE: + return "size"; + case JFFS2_COMPR_MODE_FAVOURLZO: + return "favourlzo"; + } + return "unkown"; +} + +int jffs2_set_compression_mode_name(const char *name) +{ + if (!strncmp("none", name, 4)) { + jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; + return 0; + } + if (!strncmp("priority", name, 8)) { + jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY; + return 0; + } + if (!strncmp("size", name, 4)) { + jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE; + return 0; + } + if (!strncmp("favourlzo", name, 9)) { + jffs2_compression_mode = JFFS2_COMPR_MODE_FAVOURLZO; + return 0; + } + return -EINVAL; +} + + #ifdef CONFIG_JFFS2_PROC #define JFFS2_STAT_BUF_SIZE 16000 @@ -347,42 +385,6 @@ char *jffs2_stats(void) return buf; } -char *jffs2_get_compression_mode_name(void) -{ - switch (jffs2_compression_mode) { - case JFFS2_COMPR_MODE_NONE: - return "none"; - case JFFS2_COMPR_MODE_PRIORITY: - return "priority"; - case JFFS2_COMPR_MODE_SIZE: - return "size"; - case JFFS2_COMPR_MODE_FAVOURLZO: - return "favourlzo"; - } - return "unkown"; -} - -int jffs2_set_compression_mode_name(const char *name) -{ - if (!strcmp("none",name)) { - jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; - return 0; - } - if (!strcmp("priority",name)) { - jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY; - return 0; - } - if (!strcmp("size",name)) { - jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE; - return 0; - } - if (!strncmp("favourlzo", name, 9)) { - jffs2_compression_mode = JFFS2_COMPR_MODE_FAVOURLZO; - return 0; - } - return 1; -} - static int jffs2_compressor_Xable(const char *name, int disabled) { struct jffs2_compressor *this; @@ -448,8 +450,54 @@ void jffs2_free_comprbuf(unsigned char * kfree(comprbuf); } +static struct attribute jffs2_attr_mode = { + .name = "mode", + .mode = S_IRUGO | S_IWUSR, +}; + +static struct attribute *jffs2_attrs[] = { + &jffs2_attr_mode, + NULL, +}; + +static ssize_t jffs2_attr_show(struct kobject *kobj, struct attribute *attr, + char *page) +{ + if (!strcmp("mode", attr->name)) + return sprintf(page, "%s\n", jffs2_get_compression_mode_name()); + return 0; +} + +static ssize_t jffs2_attr_store(struct kobject *kobj, struct attribute *attr, + const char *page, size_t count) +{ + int ret = -EINVAL; + + if (!strcmp("mode", attr->name)) { + ret = jffs2_set_compression_mode_name(page); + if (ret >= 0) + return count; + } + return ret; +} + +static struct sysfs_ops jffs2_sysfs_ops = { + .show = jffs2_attr_show, + .store = jffs2_attr_store, +}; + +static struct kobj_type jffs2_subsys_type = { + .default_attrs = jffs2_attrs, + .sysfs_ops = &jffs2_sysfs_ops, +}; + +/* gives us jffs2_subsys */ +static decl_subsys(jffs2, NULL, NULL); + int __init jffs2_compressors_init(void) { + int ret; + /* Registering compressors */ #ifdef CONFIG_JFFS2_ZLIB jffs2_zlib_init(); @@ -481,12 +529,21 @@ int __init jffs2_compressors_init(void) #endif #endif #endif + /* Errors here are not fatal */ + kset_set_kset_s(&jffs2_subsys, fs_subsys); + jffs2_subsys.kset.kobj.ktype = &jffs2_subsys_type; + ret = subsystem_register(&jffs2_subsys); + if (ret) + printk(KERN_WARNING "Error registering JFFS2 sysfs attributes\n"); + return 0; } int jffs2_compressors_exit(void) { -/* Unregistering compressors */ + subsystem_unregister(&jffs2_subsys); + + /* Unregistering compressors */ #ifdef CONFIG_JFFS2_LZO jffs2_lzo_exit(); #endif - 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/