]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/fs/jffs2/v2_0/src/malloc-ecos.c
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / packages / fs / jffs2 / v2_0 / src / malloc-ecos.c
1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright (C) 2001-2003 Red Hat, Inc.
5  *
6  * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
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
22 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
23 {
24         return malloc(sizeof(struct jffs2_full_dirent) + namesize);
25 }
26
27 void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
28 {
29         free(x);
30 }
31
32 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
33 {
34         return malloc(sizeof(struct jffs2_full_dnode));
35 }
36
37 void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
38 {
39         free(x);
40 }
41
42 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
43 {
44         return malloc(sizeof(struct jffs2_raw_dirent));
45 }
46
47 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
48 {
49         free(x);
50 }
51
52 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
53 {
54         return malloc(sizeof(struct jffs2_raw_inode));
55 }
56
57 void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
58 {
59         free(x);
60 }
61
62 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
63 {
64         return malloc(sizeof(struct jffs2_tmp_dnode_info));
65 }
66
67 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
68 {
69         free(x);
70 }
71
72 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
73 {
74         return malloc(sizeof(struct jffs2_node_frag));
75 }
76
77 void jffs2_free_node_frag(struct jffs2_node_frag *x)
78 {
79         free(x);
80 }
81
82 #if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
83
84 int jffs2_create_slab_caches(void)
85 {
86         return 0;
87 }
88
89 void jffs2_destroy_slab_caches(void)
90 {
91 }
92
93 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
94 {
95         return malloc(sizeof(struct jffs2_raw_node_ref));
96 }
97
98 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
99 {
100         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
110 int 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
125 void jffs2_destroy_slab_caches(void)
126 {
127 }
128
129 struct 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
141 void 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
151 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
152 {
153         struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache));
154         D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret));
155         return ret;
156 }
157
158 void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
159 {
160         D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x));
161         free(x);
162 }
163