2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright © 2001-2007 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@infradead.org>
8 * For licensing information, see the file 'LICENCE' in this directory.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/init.h>
16 #include <linux/list.h>
18 #include <linux/err.h>
19 #include <linux/mount.h>
20 #include <linux/jffs2.h>
21 #include <linux/pagemap.h>
22 #include <linux/mtd/super.h>
23 #include <linux/ctype.h>
24 #include <linux/namei.h>
28 static void jffs2_put_super(struct super_block *);
30 static struct kmem_cache *jffs2_inode_cachep;
32 static struct inode *jffs2_alloc_inode(struct super_block *sb)
34 struct jffs2_inode_info *ei;
35 ei = (struct jffs2_inode_info *)kmem_cache_alloc(jffs2_inode_cachep, GFP_KERNEL);
38 return &ei->vfs_inode;
41 static void jffs2_destroy_inode(struct inode *inode)
43 kmem_cache_free(jffs2_inode_cachep, JFFS2_INODE_INFO(inode));
46 static void jffs2_i_init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
48 struct jffs2_inode_info *ei = (struct jffs2_inode_info *) foo;
50 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
51 SLAB_CTOR_CONSTRUCTOR) {
53 inode_init_once(&ei->vfs_inode);
57 static int jffs2_sync_fs(struct super_block *sb, int wait)
59 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
62 jffs2_flush_wbuf_pad(c);
67 static const struct super_operations jffs2_super_operations =
69 .alloc_inode = jffs2_alloc_inode,
70 .destroy_inode =jffs2_destroy_inode,
71 .read_inode = jffs2_read_inode,
72 .put_super = jffs2_put_super,
73 .write_super = jffs2_write_super,
74 .statfs = jffs2_statfs,
75 .remount_fs = jffs2_remount_fs,
76 .clear_inode = jffs2_clear_inode,
77 .dirty_inode = jffs2_dirty_inode,
78 .sync_fs = jffs2_sync_fs,
82 * fill in the superblock
84 static int jffs2_fill_super(struct super_block *sb, void *data, int silent)
86 struct jffs2_sb_info *c;
88 D1(printk(KERN_DEBUG "jffs2_get_sb_mtd():"
89 " New superblock for device %d (\"%s\")\n",
90 sb->s_mtd->index, sb->s_mtd->name));
92 c = kzalloc(sizeof(*c), GFP_KERNEL);
100 /* Initialize JFFS2 superblock locks, the further initialization will
102 init_MUTEX(&c->alloc_sem);
103 init_MUTEX(&c->erase_free_sem);
104 init_waitqueue_head(&c->erase_wait);
105 init_waitqueue_head(&c->inocache_wq);
106 spin_lock_init(&c->erase_completion_lock);
107 spin_lock_init(&c->inocache_lock);
109 sb->s_op = &jffs2_super_operations;
110 sb->s_flags = sb->s_flags | MS_NOATIME;
111 sb->s_xattr = jffs2_xattr_handlers;
112 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
113 sb->s_flags |= MS_POSIXACL;
115 return jffs2_do_fill_super(sb, data, silent);
118 static int jffs2_get_sb(struct file_system_type *fs_type,
119 int flags, const char *dev_name,
120 void *data, struct vfsmount *mnt)
122 return get_sb_mtd(fs_type, flags, dev_name, data, jffs2_fill_super,
126 static void jffs2_put_super (struct super_block *sb)
128 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
130 D2(printk(KERN_DEBUG "jffs2: jffs2_put_super()\n"));
133 jffs2_flush_wbuf_pad(c);
138 jffs2_free_ino_caches(c);
139 jffs2_free_raw_node_refs(c);
140 if (jffs2_blocks_use_vmalloc(c))
144 jffs2_flash_cleanup(c);
145 kfree(c->inocache_list);
146 jffs2_clear_xattr_subsystem(c);
148 c->mtd->sync(c->mtd);
150 D1(printk(KERN_DEBUG "jffs2_put_super returning\n"));
153 static void jffs2_kill_sb(struct super_block *sb)
155 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
156 if (!(sb->s_flags & MS_RDONLY))
157 jffs2_stop_garbage_collect_thread(c);
162 static struct file_system_type jffs2_fs_type = {
163 .owner = THIS_MODULE,
165 .get_sb = jffs2_get_sb,
166 .kill_sb = jffs2_kill_sb,
169 static int __init init_jffs2_fs(void)
173 /* Paranoia checks for on-medium structures. If we ask GCC
174 to pack them with __attribute__((packed)) then it _also_
175 assumes that they're not aligned -- so it emits crappy
176 code on some architectures. Ideally we want an attribute
177 which means just 'no padding', without the alignment
178 thing. But GCC doesn't have that -- we have to just
179 hope the structs are the right sizes, instead. */
180 BUILD_BUG_ON(sizeof(struct jffs2_unknown_node) != 12);
181 BUILD_BUG_ON(sizeof(struct jffs2_raw_dirent) != 40);
182 BUILD_BUG_ON(sizeof(struct jffs2_raw_inode) != 68);
183 BUILD_BUG_ON(sizeof(struct jffs2_raw_summary) != 32);
185 printk(KERN_INFO "JFFS2 version 2.2."
186 #ifdef CONFIG_JFFS2_FS_WRITEBUFFER
189 #ifdef CONFIG_JFFS2_SUMMARY
192 " © 2001-2006 Red Hat, Inc.\n");
194 jffs2_inode_cachep = kmem_cache_create("jffs2_i",
195 sizeof(struct jffs2_inode_info),
196 0, (SLAB_RECLAIM_ACCOUNT|
198 jffs2_i_init_once, NULL);
199 if (!jffs2_inode_cachep) {
200 printk(KERN_ERR "JFFS2 error: Failed to initialise inode cache\n");
203 ret = jffs2_compressors_init();
205 printk(KERN_ERR "JFFS2 error: Failed to initialise compressors\n");
208 ret = jffs2_create_slab_caches();
210 printk(KERN_ERR "JFFS2 error: Failed to initialise slab caches\n");
211 goto out_compressors;
213 ret = register_filesystem(&jffs2_fs_type);
215 printk(KERN_ERR "JFFS2 error: Failed to register filesystem\n");
221 jffs2_destroy_slab_caches();
223 jffs2_compressors_exit();
225 kmem_cache_destroy(jffs2_inode_cachep);
229 static void __exit exit_jffs2_fs(void)
231 unregister_filesystem(&jffs2_fs_type);
232 jffs2_destroy_slab_caches();
233 jffs2_compressors_exit();
234 kmem_cache_destroy(jffs2_inode_cachep);
237 module_init(init_jffs2_fs);
238 module_exit(exit_jffs2_fs);
240 MODULE_DESCRIPTION("The Journalling Flash File System, v2");
241 MODULE_AUTHOR("Red Hat, Inc.");
242 MODULE_LICENSE("GPL"); // Actually dual-licensed, but it doesn't matter for
243 // the sake of this tag. It's Free Software.