1 | #include "rtems-jffs2-config.h" |
---|
2 | |
---|
3 | /* |
---|
4 | * JFFS2 -- Journalling Flash File System, Version 2. |
---|
5 | * |
---|
6 | * Copyright (C) 2001-2003 Free Software Foundation, Inc. |
---|
7 | * |
---|
8 | * Created by David Woodhouse <dwmw2@cambridge.redhat.com> |
---|
9 | * |
---|
10 | * For licensing information, see the file 'LICENCE' in this directory. |
---|
11 | * |
---|
12 | * $Id: malloc-ecos.c,v 1.4 2003/11/26 15:55:35 dwmw2 Exp $ |
---|
13 | * |
---|
14 | */ |
---|
15 | |
---|
16 | #include <linux/kernel.h> |
---|
17 | #include "nodelist.h" |
---|
18 | |
---|
19 | struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) |
---|
20 | { |
---|
21 | return malloc(sizeof(struct jffs2_full_dirent) + namesize); |
---|
22 | } |
---|
23 | |
---|
24 | void jffs2_free_full_dirent(struct jffs2_full_dirent *x) |
---|
25 | { |
---|
26 | free(x); |
---|
27 | } |
---|
28 | |
---|
29 | struct jffs2_full_dnode *jffs2_alloc_full_dnode(void) |
---|
30 | { |
---|
31 | return malloc(sizeof(struct jffs2_full_dnode)); |
---|
32 | } |
---|
33 | |
---|
34 | void jffs2_free_full_dnode(struct jffs2_full_dnode *x) |
---|
35 | { |
---|
36 | free(x); |
---|
37 | } |
---|
38 | |
---|
39 | struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void) |
---|
40 | { |
---|
41 | return malloc(sizeof(struct jffs2_raw_dirent)); |
---|
42 | } |
---|
43 | |
---|
44 | void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x) |
---|
45 | { |
---|
46 | free(x); |
---|
47 | } |
---|
48 | |
---|
49 | struct jffs2_raw_inode *jffs2_alloc_raw_inode(void) |
---|
50 | { |
---|
51 | return malloc(sizeof(struct jffs2_raw_inode)); |
---|
52 | } |
---|
53 | |
---|
54 | void jffs2_free_raw_inode(struct jffs2_raw_inode *x) |
---|
55 | { |
---|
56 | free(x); |
---|
57 | } |
---|
58 | |
---|
59 | struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void) |
---|
60 | { |
---|
61 | return malloc(sizeof(struct jffs2_tmp_dnode_info)); |
---|
62 | } |
---|
63 | |
---|
64 | void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) |
---|
65 | { |
---|
66 | free(x); |
---|
67 | } |
---|
68 | |
---|
69 | static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void) |
---|
70 | { |
---|
71 | struct jffs2_raw_node_ref *ret; |
---|
72 | |
---|
73 | ret = malloc((REFS_PER_BLOCK + 1) * sizeof(*ret)); |
---|
74 | if (ret) { |
---|
75 | int i = 0; |
---|
76 | for (i=0; i < REFS_PER_BLOCK; i++) { |
---|
77 | ret[i].flash_offset = REF_EMPTY_NODE; |
---|
78 | ret[i].next_in_ino = NULL; |
---|
79 | } |
---|
80 | ret[i].flash_offset = REF_LINK_NODE; |
---|
81 | ret[i].next_in_ino = NULL; |
---|
82 | } |
---|
83 | return ret; |
---|
84 | } |
---|
85 | |
---|
86 | int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, |
---|
87 | struct jffs2_eraseblock *jeb, int nr) |
---|
88 | { |
---|
89 | struct jffs2_raw_node_ref **p, *ref; |
---|
90 | int i = nr; |
---|
91 | |
---|
92 | p = &jeb->last_node; |
---|
93 | ref = *p; |
---|
94 | |
---|
95 | /* If jeb->last_node is really a valid node then skip over it */ |
---|
96 | if (ref && ref->flash_offset != REF_EMPTY_NODE) |
---|
97 | ref++; |
---|
98 | |
---|
99 | while (i) { |
---|
100 | if (!ref) { |
---|
101 | ref = *p = jffs2_alloc_refblock(); |
---|
102 | if (!ref) |
---|
103 | return -ENOMEM; |
---|
104 | } |
---|
105 | if (ref->flash_offset == REF_LINK_NODE) { |
---|
106 | p = &ref->next_in_ino; |
---|
107 | ref = *p; |
---|
108 | continue; |
---|
109 | } |
---|
110 | i--; |
---|
111 | ref++; |
---|
112 | } |
---|
113 | jeb->allocated_refs = nr; |
---|
114 | |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | void jffs2_free_refblock(struct jffs2_raw_node_ref *x) |
---|
119 | { |
---|
120 | free(x); |
---|
121 | } |
---|
122 | |
---|
123 | struct jffs2_node_frag *jffs2_alloc_node_frag(void) |
---|
124 | { |
---|
125 | return malloc(sizeof(struct jffs2_node_frag)); |
---|
126 | } |
---|
127 | |
---|
128 | void jffs2_free_node_frag(struct jffs2_node_frag *x) |
---|
129 | { |
---|
130 | free(x); |
---|
131 | } |
---|
132 | |
---|
133 | struct jffs2_inode_cache *jffs2_alloc_inode_cache(void) |
---|
134 | { |
---|
135 | struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache)); |
---|
136 | D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret)); |
---|
137 | return ret; |
---|
138 | } |
---|
139 | |
---|
140 | void jffs2_free_inode_cache(struct jffs2_inode_cache *x) |
---|
141 | { |
---|
142 | D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x)); |
---|
143 | free(x); |
---|
144 | } |
---|
145 | |
---|