diff options
Diffstat (limited to 'fs/jffs2/write.c')
-rw-r--r-- | fs/jffs2/write.c | 147 |
1 files changed, 53 insertions, 94 deletions
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c index 1342f0158e9b..67176792e138 100644 --- a/fs/jffs2/write.c +++ b/fs/jffs2/write.c | |||
@@ -37,7 +37,6 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint | |||
37 | f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache; | 37 | f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache; |
38 | f->inocache->state = INO_STATE_PRESENT; | 38 | f->inocache->state = INO_STATE_PRESENT; |
39 | 39 | ||
40 | |||
41 | jffs2_add_ino_cache(c, f->inocache); | 40 | jffs2_add_ino_cache(c, f->inocache); |
42 | D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino)); | 41 | D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino)); |
43 | ri->ino = cpu_to_je32(f->inocache->ino); | 42 | ri->ino = cpu_to_je32(f->inocache->ino); |
@@ -57,12 +56,14 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint | |||
57 | /* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it, | 56 | /* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it, |
58 | write it to the flash, link it into the existing inode/fragment list */ | 57 | write it to the flash, link it into the existing inode/fragment list */ |
59 | 58 | ||
60 | struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode) | 59 | struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, |
60 | struct jffs2_raw_inode *ri, const unsigned char *data, | ||
61 | uint32_t datalen, int alloc_mode) | ||
61 | 62 | ||
62 | { | 63 | { |
63 | struct jffs2_raw_node_ref *raw; | ||
64 | struct jffs2_full_dnode *fn; | 64 | struct jffs2_full_dnode *fn; |
65 | size_t retlen; | 65 | size_t retlen; |
66 | uint32_t flash_ofs; | ||
66 | struct kvec vecs[2]; | 67 | struct kvec vecs[2]; |
67 | int ret; | 68 | int ret; |
68 | int retried = 0; | 69 | int retried = 0; |
@@ -78,34 +79,21 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2 | |||
78 | vecs[1].iov_base = (unsigned char *)data; | 79 | vecs[1].iov_base = (unsigned char *)data; |
79 | vecs[1].iov_len = datalen; | 80 | vecs[1].iov_len = datalen; |
80 | 81 | ||
81 | jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len); | ||
82 | |||
83 | if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) { | 82 | if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) { |
84 | printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen); | 83 | printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen); |
85 | } | 84 | } |
86 | raw = jffs2_alloc_raw_node_ref(); | ||
87 | if (!raw) | ||
88 | return ERR_PTR(-ENOMEM); | ||
89 | 85 | ||
90 | fn = jffs2_alloc_full_dnode(); | 86 | fn = jffs2_alloc_full_dnode(); |
91 | if (!fn) { | 87 | if (!fn) |
92 | jffs2_free_raw_node_ref(raw); | ||
93 | return ERR_PTR(-ENOMEM); | 88 | return ERR_PTR(-ENOMEM); |
94 | } | ||
95 | |||
96 | fn->ofs = je32_to_cpu(ri->offset); | ||
97 | fn->size = je32_to_cpu(ri->dsize); | ||
98 | fn->frags = 0; | ||
99 | 89 | ||
100 | /* check number of valid vecs */ | 90 | /* check number of valid vecs */ |
101 | if (!datalen || !data) | 91 | if (!datalen || !data) |
102 | cnt = 1; | 92 | cnt = 1; |
103 | retry: | 93 | retry: |
104 | fn->raw = raw; | 94 | flash_ofs = write_ofs(c); |
105 | 95 | ||
106 | raw->flash_offset = flash_ofs; | 96 | jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len); |
107 | raw->__totlen = PAD(sizeof(*ri)+datalen); | ||
108 | raw->next_phys = NULL; | ||
109 | 97 | ||
110 | if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) { | 98 | if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) { |
111 | BUG_ON(!retried); | 99 | BUG_ON(!retried); |
@@ -125,22 +113,16 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2 | |||
125 | 113 | ||
126 | /* Mark the space as dirtied */ | 114 | /* Mark the space as dirtied */ |
127 | if (retlen) { | 115 | if (retlen) { |
128 | /* Doesn't belong to any inode */ | ||
129 | raw->next_in_ino = NULL; | ||
130 | |||
131 | /* Don't change raw->size to match retlen. We may have | 116 | /* Don't change raw->size to match retlen. We may have |
132 | written the node header already, and only the data will | 117 | written the node header already, and only the data will |
133 | seem corrupted, in which case the scan would skip over | 118 | seem corrupted, in which case the scan would skip over |
134 | any node we write before the original intended end of | 119 | any node we write before the original intended end of |
135 | this node */ | 120 | this node */ |
136 | raw->flash_offset |= REF_OBSOLETE; | 121 | jffs2_add_physical_node_ref(c, flash_ofs | REF_OBSOLETE, PAD(sizeof(*ri)+datalen), NULL); |
137 | jffs2_add_physical_node_ref(c, raw); | ||
138 | jffs2_mark_node_obsolete(c, raw); | ||
139 | } else { | 122 | } else { |
140 | printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset); | 123 | printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", flash_ofs); |
141 | jffs2_free_raw_node_ref(raw); | ||
142 | } | 124 | } |
143 | if (!retried && alloc_mode != ALLOC_NORETRY && (raw = jffs2_alloc_raw_node_ref())) { | 125 | if (!retried && alloc_mode != ALLOC_NORETRY) { |
144 | /* Try to reallocate space and retry */ | 126 | /* Try to reallocate space and retry */ |
145 | uint32_t dummy; | 127 | uint32_t dummy; |
146 | struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size]; | 128 | struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size]; |
@@ -153,19 +135,20 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2 | |||
153 | jffs2_dbg_acct_paranoia_check(c, jeb); | 135 | jffs2_dbg_acct_paranoia_check(c, jeb); |
154 | 136 | ||
155 | if (alloc_mode == ALLOC_GC) { | 137 | if (alloc_mode == ALLOC_GC) { |
156 | ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, | 138 | ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &dummy, |
157 | &dummy, JFFS2_SUMMARY_INODE_SIZE); | 139 | JFFS2_SUMMARY_INODE_SIZE); |
158 | } else { | 140 | } else { |
159 | /* Locking pain */ | 141 | /* Locking pain */ |
160 | up(&f->sem); | 142 | up(&f->sem); |
161 | jffs2_complete_reservation(c); | 143 | jffs2_complete_reservation(c); |
162 | 144 | ||
163 | ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, | 145 | ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy, |
164 | &dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE); | 146 | alloc_mode, JFFS2_SUMMARY_INODE_SIZE); |
165 | down(&f->sem); | 147 | down(&f->sem); |
166 | } | 148 | } |
167 | 149 | ||
168 | if (!ret) { | 150 | if (!ret) { |
151 | flash_ofs = write_ofs(c); | ||
169 | D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); | 152 | D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); |
170 | 153 | ||
171 | jffs2_dbg_acct_sanity_check(c,jeb); | 154 | jffs2_dbg_acct_sanity_check(c,jeb); |
@@ -174,7 +157,6 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2 | |||
174 | goto retry; | 157 | goto retry; |
175 | } | 158 | } |
176 | D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret)); | 159 | D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret)); |
177 | jffs2_free_raw_node_ref(raw); | ||
178 | } | 160 | } |
179 | /* Release the full_dnode which is now useless, and return */ | 161 | /* Release the full_dnode which is now useless, and return */ |
180 | jffs2_free_full_dnode(fn); | 162 | jffs2_free_full_dnode(fn); |
@@ -188,20 +170,17 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2 | |||
188 | if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) || | 170 | if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) || |
189 | ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) && | 171 | ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) && |
190 | (je32_to_cpu(ri->dsize)+je32_to_cpu(ri->offset) == je32_to_cpu(ri->isize)))) { | 172 | (je32_to_cpu(ri->dsize)+je32_to_cpu(ri->offset) == je32_to_cpu(ri->isize)))) { |
191 | raw->flash_offset |= REF_PRISTINE; | 173 | flash_ofs |= REF_PRISTINE; |
192 | } else { | 174 | } else { |
193 | raw->flash_offset |= REF_NORMAL; | 175 | flash_ofs |= REF_NORMAL; |
194 | } | 176 | } |
195 | jffs2_add_physical_node_ref(c, raw); | 177 | fn->raw = jffs2_add_physical_node_ref(c, flash_ofs, PAD(sizeof(*ri)+datalen), f->inocache); |
196 | 178 | fn->ofs = je32_to_cpu(ri->offset); | |
197 | /* Link into per-inode list */ | 179 | fn->size = je32_to_cpu(ri->dsize); |
198 | spin_lock(&c->erase_completion_lock); | 180 | fn->frags = 0; |
199 | raw->next_in_ino = f->inocache->nodes; | ||
200 | f->inocache->nodes = raw; | ||
201 | spin_unlock(&c->erase_completion_lock); | ||
202 | 181 | ||
203 | D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n", | 182 | D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n", |
204 | flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize), | 183 | flash_ofs & ~3, flash_ofs & 3, je32_to_cpu(ri->dsize), |
205 | je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc), | 184 | je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc), |
206 | je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen))); | 185 | je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen))); |
207 | 186 | ||
@@ -212,12 +191,14 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2 | |||
212 | return fn; | 191 | return fn; |
213 | } | 192 | } |
214 | 193 | ||
215 | struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode) | 194 | struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, |
195 | struct jffs2_raw_dirent *rd, const unsigned char *name, | ||
196 | uint32_t namelen, int alloc_mode) | ||
216 | { | 197 | { |
217 | struct jffs2_raw_node_ref *raw; | ||
218 | struct jffs2_full_dirent *fd; | 198 | struct jffs2_full_dirent *fd; |
219 | size_t retlen; | 199 | size_t retlen; |
220 | struct kvec vecs[2]; | 200 | struct kvec vecs[2]; |
201 | uint32_t flash_ofs; | ||
221 | int retried = 0; | 202 | int retried = 0; |
222 | int ret; | 203 | int ret; |
223 | 204 | ||
@@ -228,26 +209,16 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff | |||
228 | D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) { | 209 | D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) { |
229 | printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n"); | 210 | printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n"); |
230 | BUG(); | 211 | BUG(); |
231 | } | 212 | }); |
232 | ); | ||
233 | 213 | ||
234 | vecs[0].iov_base = rd; | 214 | vecs[0].iov_base = rd; |
235 | vecs[0].iov_len = sizeof(*rd); | 215 | vecs[0].iov_len = sizeof(*rd); |
236 | vecs[1].iov_base = (unsigned char *)name; | 216 | vecs[1].iov_base = (unsigned char *)name; |
237 | vecs[1].iov_len = namelen; | 217 | vecs[1].iov_len = namelen; |
238 | 218 | ||
239 | jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len); | ||
240 | |||
241 | raw = jffs2_alloc_raw_node_ref(); | ||
242 | |||
243 | if (!raw) | ||
244 | return ERR_PTR(-ENOMEM); | ||
245 | |||
246 | fd = jffs2_alloc_full_dirent(namelen+1); | 219 | fd = jffs2_alloc_full_dirent(namelen+1); |
247 | if (!fd) { | 220 | if (!fd) |
248 | jffs2_free_raw_node_ref(raw); | ||
249 | return ERR_PTR(-ENOMEM); | 221 | return ERR_PTR(-ENOMEM); |
250 | } | ||
251 | 222 | ||
252 | fd->version = je32_to_cpu(rd->version); | 223 | fd->version = je32_to_cpu(rd->version); |
253 | fd->ino = je32_to_cpu(rd->ino); | 224 | fd->ino = je32_to_cpu(rd->ino); |
@@ -257,11 +228,9 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff | |||
257 | fd->name[namelen]=0; | 228 | fd->name[namelen]=0; |
258 | 229 | ||
259 | retry: | 230 | retry: |
260 | fd->raw = raw; | 231 | flash_ofs = write_ofs(c); |
261 | 232 | ||
262 | raw->flash_offset = flash_ofs; | 233 | jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len); |
263 | raw->__totlen = PAD(sizeof(*rd)+namelen); | ||
264 | raw->next_phys = NULL; | ||
265 | 234 | ||
266 | if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(rd->version) < f->highest_version)) { | 235 | if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(rd->version) < f->highest_version)) { |
267 | BUG_ON(!retried); | 236 | BUG_ON(!retried); |
@@ -280,15 +249,11 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff | |||
280 | sizeof(*rd)+namelen, flash_ofs, ret, retlen); | 249 | sizeof(*rd)+namelen, flash_ofs, ret, retlen); |
281 | /* Mark the space as dirtied */ | 250 | /* Mark the space as dirtied */ |
282 | if (retlen) { | 251 | if (retlen) { |
283 | raw->next_in_ino = NULL; | 252 | jffs2_add_physical_node_ref(c, flash_ofs | REF_OBSOLETE, PAD(sizeof(*rd)+namelen), NULL); |
284 | raw->flash_offset |= REF_OBSOLETE; | ||
285 | jffs2_add_physical_node_ref(c, raw); | ||
286 | jffs2_mark_node_obsolete(c, raw); | ||
287 | } else { | 253 | } else { |
288 | printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset); | 254 | printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", flash_ofs); |
289 | jffs2_free_raw_node_ref(raw); | ||
290 | } | 255 | } |
291 | if (!retried && (raw = jffs2_alloc_raw_node_ref())) { | 256 | if (!retried) { |
292 | /* Try to reallocate space and retry */ | 257 | /* Try to reallocate space and retry */ |
293 | uint32_t dummy; | 258 | uint32_t dummy; |
294 | struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size]; | 259 | struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size]; |
@@ -301,39 +266,33 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff | |||
301 | jffs2_dbg_acct_paranoia_check(c, jeb); | 266 | jffs2_dbg_acct_paranoia_check(c, jeb); |
302 | 267 | ||
303 | if (alloc_mode == ALLOC_GC) { | 268 | if (alloc_mode == ALLOC_GC) { |
304 | ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs, | 269 | ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &dummy, |
305 | &dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); | 270 | JFFS2_SUMMARY_DIRENT_SIZE(namelen)); |
306 | } else { | 271 | } else { |
307 | /* Locking pain */ | 272 | /* Locking pain */ |
308 | up(&f->sem); | 273 | up(&f->sem); |
309 | jffs2_complete_reservation(c); | 274 | jffs2_complete_reservation(c); |
310 | 275 | ||
311 | ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, | 276 | ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy, |
312 | &dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); | 277 | alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); |
313 | down(&f->sem); | 278 | down(&f->sem); |
314 | } | 279 | } |
315 | 280 | ||
316 | if (!ret) { | 281 | if (!ret) { |
282 | flash_ofs = write_ofs(c); | ||
317 | D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); | 283 | D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); |
318 | jffs2_dbg_acct_sanity_check(c,jeb); | 284 | jffs2_dbg_acct_sanity_check(c,jeb); |
319 | jffs2_dbg_acct_paranoia_check(c, jeb); | 285 | jffs2_dbg_acct_paranoia_check(c, jeb); |
320 | goto retry; | 286 | goto retry; |
321 | } | 287 | } |
322 | D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret)); | 288 | D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret)); |
323 | jffs2_free_raw_node_ref(raw); | ||
324 | } | 289 | } |
325 | /* Release the full_dnode which is now useless, and return */ | 290 | /* Release the full_dnode which is now useless, and return */ |
326 | jffs2_free_full_dirent(fd); | 291 | jffs2_free_full_dirent(fd); |
327 | return ERR_PTR(ret?ret:-EIO); | 292 | return ERR_PTR(ret?ret:-EIO); |
328 | } | 293 | } |
329 | /* Mark the space used */ | 294 | /* Mark the space used */ |
330 | raw->flash_offset |= REF_PRISTINE; | 295 | fd->raw = jffs2_add_physical_node_ref(c, flash_ofs | REF_PRISTINE, PAD(sizeof(*rd)+namelen), f->inocache); |
331 | jffs2_add_physical_node_ref(c, raw); | ||
332 | |||
333 | spin_lock(&c->erase_completion_lock); | ||
334 | raw->next_in_ino = f->inocache->nodes; | ||
335 | f->inocache->nodes = raw; | ||
336 | spin_unlock(&c->erase_completion_lock); | ||
337 | 296 | ||
338 | if (retried) { | 297 | if (retried) { |
339 | jffs2_dbg_acct_sanity_check(c,NULL); | 298 | jffs2_dbg_acct_sanity_check(c,NULL); |
@@ -359,14 +318,14 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, | |||
359 | struct jffs2_full_dnode *fn; | 318 | struct jffs2_full_dnode *fn; |
360 | unsigned char *comprbuf = NULL; | 319 | unsigned char *comprbuf = NULL; |
361 | uint16_t comprtype = JFFS2_COMPR_NONE; | 320 | uint16_t comprtype = JFFS2_COMPR_NONE; |
362 | uint32_t phys_ofs, alloclen; | 321 | uint32_t alloclen; |
363 | uint32_t datalen, cdatalen; | 322 | uint32_t datalen, cdatalen; |
364 | int retried = 0; | 323 | int retried = 0; |
365 | 324 | ||
366 | retry: | 325 | retry: |
367 | D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset)); | 326 | D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset)); |
368 | 327 | ||
369 | ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, | 328 | ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, |
370 | &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); | 329 | &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); |
371 | if (ret) { | 330 | if (ret) { |
372 | D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); | 331 | D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); |
@@ -394,7 +353,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, | |||
394 | ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); | 353 | ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); |
395 | ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); | 354 | ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); |
396 | 355 | ||
397 | fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, ALLOC_NORETRY); | 356 | fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, ALLOC_NORETRY); |
398 | 357 | ||
399 | jffs2_free_comprbuf(comprbuf, buf); | 358 | jffs2_free_comprbuf(comprbuf, buf); |
400 | 359 | ||
@@ -448,13 +407,13 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str | |||
448 | struct jffs2_raw_dirent *rd; | 407 | struct jffs2_raw_dirent *rd; |
449 | struct jffs2_full_dnode *fn; | 408 | struct jffs2_full_dnode *fn; |
450 | struct jffs2_full_dirent *fd; | 409 | struct jffs2_full_dirent *fd; |
451 | uint32_t alloclen, phys_ofs; | 410 | uint32_t alloclen; |
452 | int ret; | 411 | int ret; |
453 | 412 | ||
454 | /* Try to reserve enough space for both node and dirent. | 413 | /* Try to reserve enough space for both node and dirent. |
455 | * Just the node will do for now, though | 414 | * Just the node will do for now, though |
456 | */ | 415 | */ |
457 | ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, | 416 | ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL, |
458 | JFFS2_SUMMARY_INODE_SIZE); | 417 | JFFS2_SUMMARY_INODE_SIZE); |
459 | D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); | 418 | D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); |
460 | if (ret) { | 419 | if (ret) { |
@@ -465,7 +424,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str | |||
465 | ri->data_crc = cpu_to_je32(0); | 424 | ri->data_crc = cpu_to_je32(0); |
466 | ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); | 425 | ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); |
467 | 426 | ||
468 | fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); | 427 | fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL); |
469 | 428 | ||
470 | D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n", | 429 | D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n", |
471 | jemode_to_cpu(ri->mode))); | 430 | jemode_to_cpu(ri->mode))); |
@@ -484,7 +443,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str | |||
484 | 443 | ||
485 | up(&f->sem); | 444 | up(&f->sem); |
486 | jffs2_complete_reservation(c); | 445 | jffs2_complete_reservation(c); |
487 | ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, | 446 | ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen, |
488 | ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); | 447 | ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); |
489 | 448 | ||
490 | if (ret) { | 449 | if (ret) { |
@@ -516,7 +475,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str | |||
516 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); | 475 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); |
517 | rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); | 476 | rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); |
518 | 477 | ||
519 | fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); | 478 | fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL); |
520 | 479 | ||
521 | jffs2_free_raw_dirent(rd); | 480 | jffs2_free_raw_dirent(rd); |
522 | 481 | ||
@@ -545,7 +504,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, | |||
545 | { | 504 | { |
546 | struct jffs2_raw_dirent *rd; | 505 | struct jffs2_raw_dirent *rd; |
547 | struct jffs2_full_dirent *fd; | 506 | struct jffs2_full_dirent *fd; |
548 | uint32_t alloclen, phys_ofs; | 507 | uint32_t alloclen; |
549 | int ret; | 508 | int ret; |
550 | 509 | ||
551 | if (1 /* alternative branch needs testing */ || | 510 | if (1 /* alternative branch needs testing */ || |
@@ -556,7 +515,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, | |||
556 | if (!rd) | 515 | if (!rd) |
557 | return -ENOMEM; | 516 | return -ENOMEM; |
558 | 517 | ||
559 | ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, | 518 | ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen, |
560 | ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); | 519 | ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); |
561 | if (ret) { | 520 | if (ret) { |
562 | jffs2_free_raw_dirent(rd); | 521 | jffs2_free_raw_dirent(rd); |
@@ -580,7 +539,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, | |||
580 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); | 539 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); |
581 | rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); | 540 | rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); |
582 | 541 | ||
583 | fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION); | 542 | fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_DELETION); |
584 | 543 | ||
585 | jffs2_free_raw_dirent(rd); | 544 | jffs2_free_raw_dirent(rd); |
586 | 545 | ||
@@ -659,14 +618,14 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint | |||
659 | { | 618 | { |
660 | struct jffs2_raw_dirent *rd; | 619 | struct jffs2_raw_dirent *rd; |
661 | struct jffs2_full_dirent *fd; | 620 | struct jffs2_full_dirent *fd; |
662 | uint32_t alloclen, phys_ofs; | 621 | uint32_t alloclen; |
663 | int ret; | 622 | int ret; |
664 | 623 | ||
665 | rd = jffs2_alloc_raw_dirent(); | 624 | rd = jffs2_alloc_raw_dirent(); |
666 | if (!rd) | 625 | if (!rd) |
667 | return -ENOMEM; | 626 | return -ENOMEM; |
668 | 627 | ||
669 | ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, | 628 | ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen, |
670 | ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); | 629 | ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); |
671 | if (ret) { | 630 | if (ret) { |
672 | jffs2_free_raw_dirent(rd); | 631 | jffs2_free_raw_dirent(rd); |
@@ -692,7 +651,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint | |||
692 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); | 651 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); |
693 | rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); | 652 | rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); |
694 | 653 | ||
695 | fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); | 654 | fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL); |
696 | 655 | ||
697 | jffs2_free_raw_dirent(rd); | 656 | jffs2_free_raw_dirent(rd); |
698 | 657 | ||