1 /* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Free Software Foundation, Inc. 5 * 6 * Created by David Woodhouse <[email protected]> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * 10 * $Id: malloc-ecos.c,v 1.4 2003/11/26 15:55:35 dwmw2 Exp $ 11 * 12 */ 13 14 #include <linux/kernel.h> 15 #include <cyg/hal/drv_api.h> 16 #include "nodelist.h" 17 18 #if !defined(CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE) 19 # define CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0 20 #endif 21 jffs2_alloc_full_dirent(int namesize)22struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) 23 { 24 return rt_malloc(sizeof(struct jffs2_full_dirent) + namesize); 25 } 26 jffs2_free_full_dirent(struct jffs2_full_dirent * x)27void jffs2_free_full_dirent(struct jffs2_full_dirent *x) 28 { 29 rt_free(x); 30 } 31 jffs2_alloc_full_dnode(void)32struct jffs2_full_dnode *jffs2_alloc_full_dnode(void) 33 { 34 return rt_malloc(sizeof(struct jffs2_full_dnode)); 35 } 36 jffs2_free_full_dnode(struct jffs2_full_dnode * x)37void jffs2_free_full_dnode(struct jffs2_full_dnode *x) 38 { 39 rt_free(x); 40 } 41 jffs2_alloc_raw_dirent(void)42struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void) 43 { 44 return rt_malloc(sizeof(struct jffs2_raw_dirent)); 45 } 46 jffs2_free_raw_dirent(struct jffs2_raw_dirent * x)47void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x) 48 { 49 rt_free(x); 50 } 51 jffs2_alloc_raw_inode(void)52struct jffs2_raw_inode *jffs2_alloc_raw_inode(void) 53 { 54 return rt_malloc(sizeof(struct jffs2_raw_inode)); 55 } 56 jffs2_free_raw_inode(struct jffs2_raw_inode * x)57void jffs2_free_raw_inode(struct jffs2_raw_inode *x) 58 { 59 rt_free(x); 60 } 61 jffs2_alloc_tmp_dnode_info(void)62struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void) 63 { 64 return rt_malloc(sizeof(struct jffs2_tmp_dnode_info)); 65 } 66 jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info * x)67void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) 68 { 69 rt_free(x); 70 } 71 jffs2_alloc_node_frag(void)72struct jffs2_node_frag *jffs2_alloc_node_frag(void) 73 { 74 return rt_malloc(sizeof(struct jffs2_node_frag)); 75 } 76 jffs2_free_node_frag(struct jffs2_node_frag * x)77void jffs2_free_node_frag(struct jffs2_node_frag *x) 78 { 79 rt_free(x); 80 } 81 82 #if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0 83 jffs2_create_slab_caches(void)84int jffs2_create_slab_caches(void) 85 { 86 return 0; 87 } 88 jffs2_destroy_slab_caches(void)89void jffs2_destroy_slab_caches(void) 90 { 91 } 92 jffs2_alloc_raw_node_ref(void)93struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void) 94 { 95 return rt_malloc(sizeof(struct jffs2_raw_node_ref)); 96 } 97 jffs2_free_raw_node_ref(struct jffs2_raw_node_ref * x)98void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) 99 { 100 rt_free(x); 101 } 102 103 #else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0 104 105 static struct jffs2_raw_node_ref 106 rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE] __attribute__ ((aligned (4))), 107 * first = NULL; 108 static cyg_drv_mutex_t mutex; 109 jffs2_create_slab_caches(void)110int jffs2_create_slab_caches(void) 111 { 112 struct jffs2_raw_node_ref * p; 113 cyg_drv_mutex_init(&mutex); 114 for ( 115 p = rnr_pool; 116 p < rnr_pool + CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1; 117 p++ 118 ) 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]; 122 return 0; 123 } 124 jffs2_destroy_slab_caches(void)125void jffs2_destroy_slab_caches(void) 126 { 127 } 128 jffs2_alloc_raw_node_ref(void)129struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void) 130 { 131 struct jffs2_raw_node_ref * p; 132 133 cyg_drv_mutex_lock(&mutex); 134 p = first; 135 if (p != NULL) 136 first = p->next_phys; 137 cyg_drv_mutex_unlock(&mutex); 138 return p; 139 } 140 jffs2_free_raw_node_ref(struct jffs2_raw_node_ref * x)141void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) 142 { 143 cyg_drv_mutex_lock(&mutex); 144 x->next_phys = first; 145 first = x; 146 cyg_drv_mutex_unlock(&mutex); 147 } 148 149 #endif // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0 150 jffs2_alloc_inode_cache(void)151struct jffs2_inode_cache *jffs2_alloc_inode_cache(void) 152 { 153 struct jffs2_inode_cache *ret = rt_malloc(sizeof(struct jffs2_inode_cache)); 154 D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret)); 155 return ret; 156 } 157 jffs2_free_inode_cache(struct jffs2_inode_cache * x)158void jffs2_free_inode_cache(struct jffs2_inode_cache *x) 159 { 160 D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x)); 161 rt_free(x); 162 } 163 164