From: Richard Purdie <rpurdie@openedhand.com>
To: LKML <linux-kernel@vger.kernel.org>,
David Woodhouse <dwmw2@infradead.org>,
herbert@gondor.apana.org.au
Cc: linux-mtd <linux-mtd@lists.infradead.org>, linux-crypto@vger.kernel.org
Subject: [PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute
Date: Wed, 28 Feb 2007 19:13:54 +0000 [thread overview]
Message-ID: <1172690034.16062.144.camel@localhost.localdomain> (raw)
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 <rpurdie@openedhand.com>
---
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 <linux/kobject.h>
#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
next reply other threads:[~2007-02-28 19:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-28 19:13 Richard Purdie [this message]
2007-02-28 19:39 ` [PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute Artem Bityutskiy
2007-02-28 20:56 ` Richard Purdie
2007-04-25 12:31 ` David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1172690034.16062.144.camel@localhost.localdomain \
--to=rpurdie@openedhand.com \
--cc=dwmw2@infradead.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox