2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001-2003 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@infradead.org>
8 * For licensing information, see the file 'LICENCE' in this directory.
10 * $Id: write.c,v 1.97 2005/11/07 11:14:42 gleixner Exp $
14 #include <linux/kernel.h>
16 #include <linux/crc32.h>
17 #include <linux/slab.h>
18 #include <linux/pagemap.h>
19 #include <linux/mtd/mtd.h>
24 int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri)
26 struct jffs2_inode_cache *ic;
28 ic = jffs2_alloc_inode_cache();
33 memset(ic, 0, sizeof(*ic));
36 f->inocache->nlink = 1;
37 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
38 f->inocache->state = INO_STATE_PRESENT;
40 jffs2_add_ino_cache(c, f->inocache);
41 D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino));
42 ri->ino = cpu_to_je32(f->inocache->ino);
44 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
45 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
46 ri->totlen = cpu_to_je32(PAD(sizeof(*ri)));
47 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
48 ri->mode = cpu_to_jemode(mode);
50 f->highest_version = 1;
51 ri->version = cpu_to_je32(f->highest_version);
56 /* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it,
57 write it to the flash, link it into the existing inode/fragment list */
59 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)
62 struct jffs2_raw_node_ref *raw;
63 struct jffs2_full_dnode *fn;
68 unsigned long cnt = 2;
70 D1(if(je32_to_cpu(ri->hdr_crc) != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
71 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dnode()\n");
75 vecs[0].iov_base = ri;
76 vecs[0].iov_len = sizeof(*ri);
77 vecs[1].iov_base = (unsigned char *)data;
78 vecs[1].iov_len = datalen;
80 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
82 if (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 raw = jffs2_alloc_raw_node_ref();
87 return ERR_PTR(-ENOMEM);
89 fn = jffs2_alloc_full_dnode();
91 jffs2_free_raw_node_ref(raw);
92 return ERR_PTR(-ENOMEM);
95 fn->ofs = je32_to_cpu(ri->offset);
96 fn->size = je32_to_cpu(ri->dsize);
99 /* check number of valid vecs */
100 if (!datalen || !data)
105 raw->flash_offset = flash_ofs;
106 raw->__totlen = PAD(sizeof(*ri)+datalen);
107 raw->next_phys = NULL;
109 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) {
111 D1(printk(KERN_DEBUG "jffs2_write_dnode : dnode_version %d, "
112 "highest version %d -> updating dnode\n",
113 je32_to_cpu(ri->version), f->highest_version));
114 ri->version = cpu_to_je32(++f->highest_version);
115 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
118 ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen,
119 (alloc_mode==ALLOC_GC)?0:f->inocache->ino);
121 if (ret || (retlen != sizeof(*ri) + datalen)) {
122 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
123 sizeof(*ri)+datalen, flash_ofs, ret, retlen);
125 /* Mark the space as dirtied */
127 /* Doesn't belong to any inode */
128 raw->next_in_ino = NULL;
130 /* Don't change raw->size to match retlen. We may have
131 written the node header already, and only the data will
132 seem corrupted, in which case the scan would skip over
133 any node we write before the original intended end of
135 raw->flash_offset |= REF_OBSOLETE;
136 jffs2_add_physical_node_ref(c, raw);
137 jffs2_mark_node_obsolete(c, raw);
139 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset);
140 jffs2_free_raw_node_ref(raw);
142 if (!retried && alloc_mode != ALLOC_NORETRY && (raw = jffs2_alloc_raw_node_ref())) {
143 /* Try to reallocate space and retry */
145 struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size];
149 D1(printk(KERN_DEBUG "Retrying failed write.\n"));
151 jffs2_dbg_acct_sanity_check(c,jeb);
152 jffs2_dbg_acct_paranoia_check(c, jeb);
154 if (alloc_mode == ALLOC_GC) {
155 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs,
156 &dummy, JFFS2_SUMMARY_INODE_SIZE);
160 jffs2_complete_reservation(c);
162 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs,
163 &dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
168 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
170 jffs2_dbg_acct_sanity_check(c,jeb);
171 jffs2_dbg_acct_paranoia_check(c, jeb);
175 D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
176 jffs2_free_raw_node_ref(raw);
178 /* Release the full_dnode which is now useless, and return */
179 jffs2_free_full_dnode(fn);
180 return ERR_PTR(ret?ret:-EIO);
182 /* Mark the space used */
183 /* If node covers at least a whole page, or if it starts at the
184 beginning of a page and runs to the end of the file, or if
185 it's a hole node, mark it REF_PRISTINE, else REF_NORMAL.
187 if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) ||
188 ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) &&
189 (je32_to_cpu(ri->dsize)+je32_to_cpu(ri->offset) == je32_to_cpu(ri->isize)))) {
190 raw->flash_offset |= REF_PRISTINE;
192 raw->flash_offset |= REF_NORMAL;
194 jffs2_add_physical_node_ref(c, raw);
196 /* Link into per-inode list */
197 spin_lock(&c->erase_completion_lock);
198 raw->next_in_ino = f->inocache->nodes;
199 f->inocache->nodes = raw;
200 spin_unlock(&c->erase_completion_lock);
202 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",
203 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize),
204 je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc),
205 je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen)));
208 jffs2_dbg_acct_sanity_check(c,NULL);
214 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)
216 struct jffs2_raw_node_ref *raw;
217 struct jffs2_full_dirent *fd;
223 D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n",
224 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
225 je32_to_cpu(rd->name_crc)));
227 D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
228 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n");
233 vecs[0].iov_base = rd;
234 vecs[0].iov_len = sizeof(*rd);
235 vecs[1].iov_base = (unsigned char *)name;
236 vecs[1].iov_len = namelen;
238 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
240 raw = jffs2_alloc_raw_node_ref();
243 return ERR_PTR(-ENOMEM);
245 fd = jffs2_alloc_full_dirent(namelen+1);
247 jffs2_free_raw_node_ref(raw);
248 return ERR_PTR(-ENOMEM);
251 fd->version = je32_to_cpu(rd->version);
252 fd->ino = je32_to_cpu(rd->ino);
253 fd->nhash = full_name_hash(name, strlen(name));
255 memcpy(fd->name, name, namelen);
261 raw->flash_offset = flash_ofs;
262 raw->__totlen = PAD(sizeof(*rd)+namelen);
263 raw->next_phys = NULL;
265 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(rd->version) < f->highest_version)) {
267 D1(printk(KERN_DEBUG "jffs2_write_dirent : dirent_version %d, "
268 "highest version %d -> updating dirent\n",
269 je32_to_cpu(rd->version), f->highest_version));
270 rd->version = cpu_to_je32(++f->highest_version);
271 fd->version = je32_to_cpu(rd->version);
272 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
275 ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen,
276 (alloc_mode==ALLOC_GC)?0:je32_to_cpu(rd->pino));
277 if (ret || (retlen != sizeof(*rd) + namelen)) {
278 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
279 sizeof(*rd)+namelen, flash_ofs, ret, retlen);
280 /* Mark the space as dirtied */
282 raw->next_in_ino = NULL;
283 raw->flash_offset |= REF_OBSOLETE;
284 jffs2_add_physical_node_ref(c, raw);
285 jffs2_mark_node_obsolete(c, raw);
287 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset);
288 jffs2_free_raw_node_ref(raw);
290 if (!retried && (raw = jffs2_alloc_raw_node_ref())) {
291 /* Try to reallocate space and retry */
293 struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size];
297 D1(printk(KERN_DEBUG "Retrying failed write.\n"));
299 jffs2_dbg_acct_sanity_check(c,jeb);
300 jffs2_dbg_acct_paranoia_check(c, jeb);
302 if (alloc_mode == ALLOC_GC) {
303 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs,
304 &dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
308 jffs2_complete_reservation(c);
310 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs,
311 &dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
316 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
317 jffs2_dbg_acct_sanity_check(c,jeb);
318 jffs2_dbg_acct_paranoia_check(c, jeb);
321 D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
322 jffs2_free_raw_node_ref(raw);
324 /* Release the full_dnode which is now useless, and return */
325 jffs2_free_full_dirent(fd);
326 return ERR_PTR(ret?ret:-EIO);
328 /* Mark the space used */
329 raw->flash_offset |= REF_PRISTINE;
330 jffs2_add_physical_node_ref(c, raw);
332 spin_lock(&c->erase_completion_lock);
333 raw->next_in_ino = f->inocache->nodes;
334 f->inocache->nodes = raw;
335 spin_unlock(&c->erase_completion_lock);
338 jffs2_dbg_acct_sanity_check(c,NULL);
344 /* The OS-specific code fills in the metadata in the jffs2_raw_inode for us, so that
345 we don't have to go digging in struct inode or its equivalent. It should set:
346 mode, uid, gid, (starting)isize, atime, ctime, mtime */
347 int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
348 struct jffs2_raw_inode *ri, unsigned char *buf,
349 uint32_t offset, uint32_t writelen, uint32_t *retlen)
352 uint32_t writtenlen = 0;
354 D1(printk(KERN_DEBUG "jffs2_write_inode_range(): Ino #%u, ofs 0x%x, len 0x%x\n",
355 f->inocache->ino, offset, writelen));
358 struct jffs2_full_dnode *fn;
359 unsigned char *comprbuf = NULL;
360 uint16_t comprtype = JFFS2_COMPR_NONE;
361 uint32_t phys_ofs, alloclen;
362 uint32_t datalen, cdatalen;
366 D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset));
368 ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs,
369 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
371 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
375 datalen = min_t(uint32_t, writelen, PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1)));
376 cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen);
378 comprtype = jffs2_compress(c, f, buf, &comprbuf, &datalen, &cdatalen);
380 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
381 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
382 ri->totlen = cpu_to_je32(sizeof(*ri) + cdatalen);
383 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
385 ri->ino = cpu_to_je32(f->inocache->ino);
386 ri->version = cpu_to_je32(++f->highest_version);
387 ri->isize = cpu_to_je32(max(je32_to_cpu(ri->isize), offset + datalen));
388 ri->offset = cpu_to_je32(offset);
389 ri->csize = cpu_to_je32(cdatalen);
390 ri->dsize = cpu_to_je32(datalen);
391 ri->compr = comprtype & 0xff;
392 ri->usercompr = (comprtype >> 8 ) & 0xff;
393 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
394 ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
396 fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, ALLOC_NORETRY);
398 jffs2_free_comprbuf(comprbuf, buf);
403 jffs2_complete_reservation(c);
405 /* Write error to be retried */
407 D1(printk(KERN_DEBUG "Retrying node write in jffs2_write_inode_range()\n"));
412 ret = jffs2_add_full_dnode_to_inode(c, f, fn);
414 jffs2_mark_node_obsolete(c, f->metadata->raw);
415 jffs2_free_full_dnode(f->metadata);
420 D1(printk(KERN_DEBUG "Eep. add_full_dnode_to_inode() failed in commit_write, returned %d\n", ret));
421 jffs2_mark_node_obsolete(c, fn->raw);
422 jffs2_free_full_dnode(fn);
425 jffs2_complete_reservation(c);
429 jffs2_complete_reservation(c);
431 printk(KERN_WARNING "Eep. We didn't actually write any data in jffs2_write_inode_range()\n");
435 D1(printk(KERN_DEBUG "increasing writtenlen by %d\n", datalen));
436 writtenlen += datalen;
441 *retlen = writtenlen;
445 int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen)
447 struct jffs2_raw_dirent *rd;
448 struct jffs2_full_dnode *fn;
449 struct jffs2_full_dirent *fd;
450 uint32_t alloclen, phys_ofs;
453 /* Try to reserve enough space for both node and dirent.
454 * Just the node will do for now, though
456 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL,
457 JFFS2_SUMMARY_INODE_SIZE);
458 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
464 ri->data_crc = cpu_to_je32(0);
465 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
467 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
469 D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n",
470 jemode_to_cpu(ri->mode)));
473 D1(printk(KERN_DEBUG "jffs2_write_dnode() failed\n"));
474 /* Eeek. Wave bye bye */
476 jffs2_complete_reservation(c);
479 /* No data here. Only a metadata node, which will be
480 obsoleted by the first data write
485 jffs2_complete_reservation(c);
486 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
487 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
491 D1(printk(KERN_DEBUG "jffs2_reserve_space() for dirent failed\n"));
495 rd = jffs2_alloc_raw_dirent();
497 /* Argh. Now we treat it like a normal delete */
498 jffs2_complete_reservation(c);
504 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
505 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
506 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
507 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
509 rd->pino = cpu_to_je32(dir_f->inocache->ino);
510 rd->version = cpu_to_je32(++dir_f->highest_version);
512 rd->mctime = ri->ctime;
515 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
516 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
518 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL);
520 jffs2_free_raw_dirent(rd);
523 /* dirent failed to write. Delete the inode normally
524 as if it were the final unlink() */
525 jffs2_complete_reservation(c);
530 /* Link the fd into the inode's list, obsoleting an old
532 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
534 jffs2_complete_reservation(c);
541 int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
542 const char *name, int namelen, struct jffs2_inode_info *dead_f,
545 struct jffs2_raw_dirent *rd;
546 struct jffs2_full_dirent *fd;
547 uint32_t alloclen, phys_ofs;
550 if (1 /* alternative branch needs testing */ ||
551 !jffs2_can_mark_obsolete(c)) {
552 /* We can't mark stuff obsolete on the medium. We need to write a deletion dirent */
554 rd = jffs2_alloc_raw_dirent();
558 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
559 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
561 jffs2_free_raw_dirent(rd);
567 /* Build a deletion node */
568 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
569 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
570 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
571 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
573 rd->pino = cpu_to_je32(dir_f->inocache->ino);
574 rd->version = cpu_to_je32(++dir_f->highest_version);
575 rd->ino = cpu_to_je32(0);
576 rd->mctime = cpu_to_je32(time);
578 rd->type = DT_UNKNOWN;
579 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
580 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
582 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION);
584 jffs2_free_raw_dirent(rd);
587 jffs2_complete_reservation(c);
592 /* File it. This will mark the old one obsolete. */
593 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
596 struct jffs2_full_dirent **prev = &dir_f->dents;
597 uint32_t nhash = full_name_hash(name, namelen);
601 while ((*prev) && (*prev)->nhash <= nhash) {
602 if ((*prev)->nhash == nhash &&
603 !memcmp((*prev)->name, name, namelen) &&
604 !(*prev)->name[namelen]) {
605 struct jffs2_full_dirent *this = *prev;
607 D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) @%08x obsolete\n",
608 this->ino, ref_offset(this->raw)));
611 jffs2_mark_node_obsolete(c, (this->raw));
612 jffs2_free_full_dirent(this);
615 prev = &((*prev)->next);
620 /* dead_f is NULL if this was a rename not a real unlink */
621 /* Also catch the !f->inocache case, where there was a dirent
622 pointing to an inode which didn't exist. */
623 if (dead_f && dead_f->inocache) {
627 if (S_ISDIR(OFNI_EDONI_2SFFJ(dead_f)->i_mode)) {
628 while (dead_f->dents) {
629 /* There can be only deleted ones */
632 dead_f->dents = fd->next;
635 printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n",
636 dead_f->inocache->ino, fd->name, fd->ino);
638 D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n",
639 fd->name, dead_f->inocache->ino));
641 jffs2_mark_node_obsolete(c, fd->raw);
642 jffs2_free_full_dirent(fd);
646 dead_f->inocache->nlink--;
647 /* NB: Caller must set inode nlink if appropriate */
651 jffs2_complete_reservation(c);
657 int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time)
659 struct jffs2_raw_dirent *rd;
660 struct jffs2_full_dirent *fd;
661 uint32_t alloclen, phys_ofs;
664 rd = jffs2_alloc_raw_dirent();
668 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
669 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
671 jffs2_free_raw_dirent(rd);
677 /* Build a deletion node */
678 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
679 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
680 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
681 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
683 rd->pino = cpu_to_je32(dir_f->inocache->ino);
684 rd->version = cpu_to_je32(++dir_f->highest_version);
685 rd->ino = cpu_to_je32(ino);
686 rd->mctime = cpu_to_je32(time);
691 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
692 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
694 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL);
696 jffs2_free_raw_dirent(rd);
699 jffs2_complete_reservation(c);
704 /* File it. This will mark the old one obsolete. */
705 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
707 jffs2_complete_reservation(c);