2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001-2003 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
8 * For licensing information, see the file 'LICENCE' in this directory.
14 #include <linux/kernel.h>
15 #include <cyg/hal/drv_api.h>
18 #if !defined(CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE)
19 # define CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0
22 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
24 return malloc(sizeof(struct jffs2_full_dirent) + namesize);
27 void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
32 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
34 return malloc(sizeof(struct jffs2_full_dnode));
37 void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
42 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
44 return malloc(sizeof(struct jffs2_raw_dirent));
47 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
52 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
54 return malloc(sizeof(struct jffs2_raw_inode));
57 void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
62 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
64 return malloc(sizeof(struct jffs2_tmp_dnode_info));
67 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
72 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
74 return malloc(sizeof(struct jffs2_node_frag));
77 void jffs2_free_node_frag(struct jffs2_node_frag *x)
82 #if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
84 int jffs2_create_slab_caches(void)
89 void jffs2_destroy_slab_caches(void)
93 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
95 return malloc(sizeof(struct jffs2_raw_node_ref));
98 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
103 #else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
105 static struct jffs2_raw_node_ref
106 rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE] __attribute__ ((aligned (4))),
108 static cyg_drv_mutex_t mutex;
110 int jffs2_create_slab_caches(void)
112 struct jffs2_raw_node_ref * p;
113 cyg_drv_mutex_init(&mutex);
116 p < rnr_pool + CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1;
119 p->next_phys = p + 1;
120 rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1].next_phys = NULL;
121 first = &rnr_pool[0];
125 void jffs2_destroy_slab_caches(void)
129 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
131 struct jffs2_raw_node_ref * p;
133 cyg_drv_mutex_lock(&mutex);
136 first = p->next_phys;
137 cyg_drv_mutex_unlock(&mutex);
141 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
143 cyg_drv_mutex_lock(&mutex);
144 x->next_phys = first;
146 cyg_drv_mutex_unlock(&mutex);
149 #endif // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
151 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
153 struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache));
154 D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret));
158 void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
160 D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x));