2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
8 * The original JFFS, from which the design for JFFS2 was derived,
9 * was designed and implemented by Axis Communications AB.
11 * The contents of this file are subject to the Red Hat eCos Public
12 * License Version 1.1 (the "Licence"); you may not use this file
13 * except in compliance with the Licence. You may obtain a copy of
14 * the Licence at http://www.redhat.com/
16 * Software distributed under the Licence is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
18 * See the Licence for the specific language governing rights and
19 * limitations under the Licence.
21 * The Original Code is JFFS2 - Journalling Flash File System, version 2
23 * Alternatively, the contents of this file may be used under the
24 * terms of the GNU General Public License version 2 (the "GPL"), in
25 * which case the provisions of the GPL are applicable instead of the
26 * above. If you wish to allow the use of your version of this file
27 * only under the terms of the GPL and not to allow others to use your
28 * version of this file under the RHEPL, indicate your decision by
29 * deleting the provisions above and replace them with the notice and
30 * other provisions required by the GPL. If you do not delete the
31 * provisions above, a recipient may use your version of this file
32 * under either the RHEPL or the GPL.
34 * $Id: malloc.c,v 1.16 2001/03/15 15:38:24 dwmw2 Exp $
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/init.h>
41 #include <linux/jffs2.h>
45 #define JFFS2_SLAB_POISON SLAB_POISON
47 #define JFFS2_SLAB_POISON 0
50 /* These are initialised to NULL in the kernel startup code.
51 If you're porting to other operating systems, beware */
52 static kmem_cache_t *full_dnode_slab;
53 static kmem_cache_t *raw_dirent_slab;
54 static kmem_cache_t *raw_inode_slab;
55 static kmem_cache_t *tmp_dnode_info_slab;
56 static kmem_cache_t *raw_node_ref_slab;
57 static kmem_cache_t *node_frag_slab;
58 static kmem_cache_t *inode_cache_slab;
60 void jffs2_free_tmp_dnode_info_list(struct jffs2_tmp_dnode_info *tn)
62 struct jffs2_tmp_dnode_info *next;
67 jffs2_free_full_dnode(next->fn);
68 jffs2_free_tmp_dnode_info(next);
72 void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd)
74 struct jffs2_full_dirent *next;
78 jffs2_free_full_dirent(fd);
83 int __init jffs2_create_slab_caches(void)
85 full_dnode_slab = kmem_cache_create("jffs2_full_dnode", sizeof(struct jffs2_full_dnode), 0, JFFS2_SLAB_POISON, NULL, NULL);
89 raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent", sizeof(struct jffs2_raw_dirent), 0, JFFS2_SLAB_POISON, NULL, NULL);
93 raw_inode_slab = kmem_cache_create("jffs2_raw_inode", sizeof(struct jffs2_raw_inode), 0, JFFS2_SLAB_POISON, NULL, NULL);
97 tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode", sizeof(struct jffs2_tmp_dnode_info), 0, JFFS2_SLAB_POISON, NULL, NULL);
98 if (!tmp_dnode_info_slab)
101 raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref", sizeof(struct jffs2_raw_node_ref), 0, JFFS2_SLAB_POISON, NULL, NULL);
102 if (!raw_node_ref_slab)
105 node_frag_slab = kmem_cache_create("jffs2_node_frag", sizeof(struct jffs2_node_frag), 0, JFFS2_SLAB_POISON, NULL, NULL);
109 inode_cache_slab = kmem_cache_create("jffs2_inode_cache", sizeof(struct jffs2_inode_cache), 0, JFFS2_SLAB_POISON, NULL, NULL);
111 if (inode_cache_slab)
114 jffs2_destroy_slab_caches();
118 void jffs2_destroy_slab_caches(void)
121 kmem_cache_destroy(full_dnode_slab);
123 kmem_cache_destroy(raw_dirent_slab);
125 kmem_cache_destroy(raw_inode_slab);
126 if(tmp_dnode_info_slab)
127 kmem_cache_destroy(tmp_dnode_info_slab);
128 if(raw_node_ref_slab)
129 kmem_cache_destroy(raw_node_ref_slab);
131 kmem_cache_destroy(node_frag_slab);
133 kmem_cache_destroy(inode_cache_slab);
137 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
139 return kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
142 void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
147 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
149 void *ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
153 void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
155 kmem_cache_free(full_dnode_slab, x);
158 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
160 return kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
163 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
165 kmem_cache_free(raw_dirent_slab, x);
168 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
170 return kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
173 void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
175 kmem_cache_free(raw_inode_slab, x);
178 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
180 return kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
183 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
185 kmem_cache_free(tmp_dnode_info_slab, x);
188 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
190 return kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
193 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
195 kmem_cache_free(raw_node_ref_slab, x);
198 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
200 return kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
203 void jffs2_free_node_frag(struct jffs2_node_frag *x)
205 kmem_cache_free(node_frag_slab, x);
208 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
210 struct jffs2_inode_cache *ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
211 D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret));
215 void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
217 D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x));
218 kmem_cache_free(inode_cache_slab, x);