• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright © 2001-2007 Red Hat, Inc.
5  *
6  * Created by David Woodhouse <dwmw2@infradead.org>
7  *
8  * For licensing information, see the file 'LICENCE' in this directory.
9  *
10  */
11 
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <stdlib.h>
15 #include "nodelist.h"
16 
17 #if !defined(JFFS2NUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE)
18 # define JFFS2NUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0
19 #endif
20 
jffs2_create_slab_caches(void)21 int __init jffs2_create_slab_caches(void)
22 {
23 	return 0;
24 
25 }
26 
jffs2_destroy_slab_caches(void)27 void jffs2_destroy_slab_caches(void)
28 {
29 	return;
30 }
31 
32 
jffs2_alloc_full_dirent(int namesize)33 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
34 {
35 	struct jffs2_full_dirent *ret;
36 	ret = zalloc(sizeof(struct jffs2_full_dirent) + namesize);
37 	dbg_memalloc("%p\n", ret);
38 	return ret;
39 }
40 
jffs2_free_full_dirent(struct jffs2_full_dirent * x)41 void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
42 {
43 	dbg_memalloc("%p\n", x);
44 	kfree(x);
45 }
46 
jffs2_alloc_full_dnode(void)47 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
48 {
49 	struct jffs2_full_dnode *ret;
50 	ret = zalloc(sizeof(struct jffs2_full_dnode));
51 	dbg_memalloc("%p\n", ret);
52 	return ret;
53 }
54 
jffs2_free_full_dnode(struct jffs2_full_dnode * x)55 void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
56 {
57 	dbg_memalloc("%p\n", x);
58 	free(x);
59 }
60 
jffs2_alloc_raw_dirent(void)61 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
62 {
63 	struct jffs2_raw_dirent *ret;
64 	ret = zalloc(sizeof(struct jffs2_raw_dirent));
65 	dbg_memalloc("%p\n", ret);
66 	return ret;
67 }
68 
jffs2_free_raw_dirent(struct jffs2_raw_dirent * x)69 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
70 {
71 	dbg_memalloc("%p\n", x);
72 	free(x);
73 }
74 
jffs2_alloc_raw_inode(void)75 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
76 {
77 	struct jffs2_raw_inode *ret;
78 	ret = zalloc(sizeof(struct jffs2_raw_inode));
79 	dbg_memalloc("%p\n", ret);
80 	return ret;
81 }
82 
jffs2_free_raw_inode(struct jffs2_raw_inode * x)83 void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
84 {
85 	dbg_memalloc("%p\n", x);
86 	free(x);
87 }
88 
jffs2_alloc_tmp_dnode_info(void)89 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
90 {
91 	struct jffs2_tmp_dnode_info *ret;
92 	ret = zalloc(sizeof(struct jffs2_tmp_dnode_info));
93 	dbg_memalloc("%p\n",
94 		ret);
95 	return ret;
96 }
97 
jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info * x)98 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
99 {
100 	dbg_memalloc("%p\n", x);
101 	free(x);
102 }
103 
jffs2_alloc_refblock(void)104 static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void)
105 {
106 	struct jffs2_raw_node_ref *ret;
107 
108 	ret = malloc(sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK+1));
109 	if (ret) {
110 		int i = 0;
111 		for (i=0; i < REFS_PER_BLOCK; i++) {
112 			ret[i].flash_offset = REF_EMPTY_NODE;
113 			ret[i].next_in_ino = NULL;
114 		}
115 		ret[i].flash_offset = REF_LINK_NODE;
116 		ret[i].next_in_ino = NULL;
117 	}
118 	return ret;
119 }
120 
jffs2_prealloc_raw_node_refs(struct jffs2_sb_info * c,struct jffs2_eraseblock * jeb,int nr)121 int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c,
122 				 struct jffs2_eraseblock *jeb, int nr)
123 {
124 	struct jffs2_raw_node_ref **p, *ref;
125 	int i = nr;
126 
127 	dbg_memalloc("%d\n", nr);
128 
129 	p = &jeb->last_node;
130 	ref = *p;
131 
132 	dbg_memalloc("Reserving %d refs for block @0x%08x\n", nr, jeb->offset);
133 
134 	/* If jeb->last_node is really a valid node then skip over it */
135 	if (ref && ref->flash_offset != REF_EMPTY_NODE)
136 		ref++;
137 
138 	while (i) {
139 		if (!ref) {
140 			dbg_memalloc("Allocating new refblock linked from %p\n", p);
141 			ref = *p = jffs2_alloc_refblock();
142 			if (!ref)
143 				return -ENOMEM;
144 		}
145 		if (ref->flash_offset == REF_LINK_NODE) {
146 			p = &ref->next_in_ino;
147 			ref = *p;
148 			continue;
149 		}
150 		i--;
151 		ref++;
152 	}
153 	jeb->allocated_refs = nr;
154 
155 	dbg_memalloc("Reserved %d refs for block @0x%08x, last_node is %p (%08x,%p)\n",
156 		  nr, jeb->offset, jeb->last_node, jeb->last_node->flash_offset,
157 		  jeb->last_node->next_in_ino);
158 
159 	return 0;
160 }
161 
jffs2_free_refblock(struct jffs2_raw_node_ref * x)162 void jffs2_free_refblock(struct jffs2_raw_node_ref *x)
163 {
164 	dbg_memalloc("%p\n", x);
165 	free(x);
166 }
167 
jffs2_alloc_node_frag(void)168 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
169 {
170 	struct jffs2_node_frag *ret;
171 	ret = malloc(sizeof(struct jffs2_node_frag));
172 	dbg_memalloc("%p\n", ret);
173 	return ret;
174 }
175 
jffs2_free_node_frag(struct jffs2_node_frag * x)176 void jffs2_free_node_frag(struct jffs2_node_frag *x)
177 {
178 	dbg_memalloc("%p\n", x);
179 	free(x);
180 }
181 
182 
jffs2_alloc_inode_cache(void)183 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
184 {
185 	struct jffs2_inode_cache *ret;
186 	ret = zalloc(sizeof(struct jffs2_inode_cache));;
187 	dbg_memalloc("%p\n", ret);
188 	return ret;
189 }
190 
jffs2_free_inode_cache(struct jffs2_inode_cache * x)191 void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
192 {
193 	dbg_memalloc("%p\n", x);
194 	kfree(x);
195 }
196 
197 #ifdef CONFIG_JFFS2_FS_XATTR
jffs2_alloc_xattr_datum(void)198 struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
199 {
200 	struct jffs2_xattr_datum *xd;
201 	xd = malloc(sizeof(struct jffs2_xattr_datum));
202 	dbg_memalloc("%p\n", xd);
203 	if (!xd)
204 		return NULL;
205 
206 	xd->class = RAWNODE_CLASS_XATTR_DATUM;
207 	xd->node = (void *)xd;
208 	INIT_LIST_HEAD(&xd->xindex);
209 	return xd;
210 }
211 
jffs2_free_xattr_datum(struct jffs2_xattr_datum * xd)212 void jffs2_free_xattr_datum(struct jffs2_xattr_datum *xd)
213 {
214 	dbg_memalloc("%p\n", xd);
215 	kfree(xd);
216 }
217 
jffs2_alloc_xattr_ref(void)218 struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
219 {
220 	struct jffs2_xattr_ref *ref;
221 	ref = malloc(sizeof(struct jffs2_xattr_ref));
222 	dbg_memalloc("%p\n", ref);
223 	if (!ref)
224 		return NULL;
225 
226 	ref->class = RAWNODE_CLASS_XATTR_REF;
227 	ref->node = (void *)ref;
228 	return ref;
229 }
230 
jffs2_free_xattr_ref(struct jffs2_xattr_ref * ref)231 void jffs2_free_xattr_ref(struct jffs2_xattr_ref *ref)
232 {
233 	dbg_memalloc("%p\n", ref);
234 	kfree(ref);
235 }
236 #endif
237