2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001, 2002 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
8 * For licensing information, see the file 'LICENCE' in this directory.
10 * $Id: dir.c,v 1.77 2003/06/05 14:42:24 dwmw2 Exp $
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/sched.h>
18 #include <linux/crc32.h>
19 #include <linux/jffs2.h>
20 #include <linux/jffs2_fs_i.h>
21 #include <linux/jffs2_fs_sb.h>
22 #include <linux/time.h>
25 /* Urgh. Please tell me there's a nicer way of doing this. */
26 #include <linux/version.h>
27 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,48)
28 typedef int mknod_arg_t;
30 typedef dev_t mknod_arg_t;
33 static int jffs2_readdir (struct file *, void *, filldir_t);
35 static int jffs2_create (struct inode *,struct dentry *,int);
36 static struct dentry *jffs2_lookup (struct inode *,struct dentry *);
37 static int jffs2_link (struct dentry *,struct inode *,struct dentry *);
38 static int jffs2_unlink (struct inode *,struct dentry *);
39 static int jffs2_symlink (struct inode *,struct dentry *,const char *);
40 static int jffs2_mkdir (struct inode *,struct dentry *,int);
41 static int jffs2_rmdir (struct inode *,struct dentry *);
42 static int jffs2_mknod (struct inode *,struct dentry *,int,mknod_arg_t);
43 static int jffs2_rename (struct inode *, struct dentry *,
44 struct inode *, struct dentry *);
46 struct file_operations jffs2_dir_operations =
48 .read = generic_read_dir,
49 .readdir = jffs2_readdir,
55 struct inode_operations jffs2_dir_inode_operations =
57 .create = jffs2_create,
58 .lookup = jffs2_lookup,
60 .unlink = jffs2_unlink,
61 .symlink = jffs2_symlink,
65 .rename = jffs2_rename,
66 .setattr = jffs2_setattr,
69 /***********************************************************************/
72 /* We keep the dirent list sorted in increasing order of name hash,
73 and we use the same hash function as the dentries. Makes this
76 static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target)
78 struct jffs2_inode_info *dir_f;
79 struct jffs2_sb_info *c;
80 struct jffs2_full_dirent *fd = NULL, *fd_list;
82 struct inode *inode = NULL;
84 D1(printk(KERN_DEBUG "jffs2_lookup()\n"));
86 dir_f = JFFS2_INODE_INFO(dir_i);
87 c = JFFS2_SB_INFO(dir_i->i_sb);
91 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
92 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) {
93 if (fd_list->nhash == target->d_name.hash &&
94 (!fd || fd_list->version > fd->version) &&
95 strlen(fd_list->name) == target->d_name.len &&
96 !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) {
104 inode = iget(dir_i->i_sb, ino);
106 printk(KERN_WARNING "iget() failed for ino #%u\n", ino);
107 return (ERR_PTR(-EIO));
111 d_add(target, inode);
116 /***********************************************************************/
119 static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
121 struct jffs2_inode_info *f;
122 struct jffs2_sb_info *c;
123 struct inode *inode = filp->f_dentry->d_inode;
124 struct jffs2_full_dirent *fd;
125 unsigned long offset, curofs;
127 D1(printk(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", filp->f_dentry->d_inode->i_ino));
129 f = JFFS2_INODE_INFO(inode);
130 c = JFFS2_SB_INFO(inode->i_sb);
132 offset = filp->f_pos;
135 D1(printk(KERN_DEBUG "Dirent 0: \".\", ino #%lu\n", inode->i_ino));
136 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR) < 0)
141 unsigned long pino = parent_ino(filp->f_dentry);
142 D1(printk(KERN_DEBUG "Dirent 1: \"..\", ino #%lu\n", pino));
143 if (filldir(dirent, "..", 2, 1, pino, DT_DIR) < 0)
150 for (fd = f->dents; fd; fd = fd->next) {
153 /* First loop: curofs = 2; offset = 2 */
154 if (curofs < offset) {
155 D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n",
156 fd->name, fd->ino, fd->type, curofs, offset));
160 D2(printk(KERN_DEBUG "Skipping deletion dirent \"%s\"\n", fd->name));
164 D2(printk(KERN_DEBUG "Dirent %ld: \"%s\", ino #%u, type %d\n", offset, fd->name, fd->ino, fd->type));
165 if (filldir(dirent, fd->name, strlen(fd->name), offset, fd->ino, fd->type) < 0)
171 filp->f_pos = offset;
175 /***********************************************************************/
178 static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode)
180 struct jffs2_raw_inode *ri;
181 struct jffs2_inode_info *f, *dir_f;
182 struct jffs2_sb_info *c;
186 ri = jffs2_alloc_raw_inode();
190 c = JFFS2_SB_INFO(dir_i->i_sb);
192 D1(printk(KERN_DEBUG "jffs2_create()\n"));
194 inode = jffs2_new_inode(dir_i, mode, ri);
197 D1(printk(KERN_DEBUG "jffs2_new_inode() failed\n"));
198 jffs2_free_raw_inode(ri);
199 return PTR_ERR(inode);
202 inode->i_op = &jffs2_file_inode_operations;
203 inode->i_fop = &jffs2_file_operations;
204 inode->i_mapping->a_ops = &jffs2_file_address_operations;
205 inode->i_mapping->nrpages = 0;
207 f = JFFS2_INODE_INFO(inode);
208 dir_f = JFFS2_INODE_INFO(dir_i);
210 ret = jffs2_do_create(c, dir_f, f, ri,
211 dentry->d_name.name, dentry->d_name.len);
214 jffs2_clear_inode(inode);
215 make_bad_inode(inode);
217 jffs2_free_raw_inode(ri);
221 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(ri->ctime));
223 jffs2_free_raw_inode(ri);
224 d_instantiate(dentry, inode);
226 D1(printk(KERN_DEBUG "jffs2_create: Created ino #%lu with mode %o, nlink %d(%d). nrpages %ld\n",
227 inode->i_ino, inode->i_mode, inode->i_nlink, f->inocache->nlink, inode->i_mapping->nrpages));
231 /***********************************************************************/
234 static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
236 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
237 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
238 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode);
241 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
242 dentry->d_name.len, dead_f);
243 if (dead_f->inocache)
244 dentry->d_inode->i_nlink = dead_f->inocache->nlink;
247 /***********************************************************************/
250 static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct dentry *dentry)
252 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dentry->d_inode->i_sb);
253 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
254 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
258 /* Don't let people make hard links to bad inodes. */
262 if (S_ISDIR(old_dentry->d_inode->i_mode))
265 /* XXX: This is ugly */
266 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
267 if (!type) type = DT_REG;
269 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len);
273 old_dentry->d_inode->i_nlink = ++f->inocache->nlink;
275 d_instantiate(dentry, old_dentry->d_inode);
276 atomic_inc(&old_dentry->d_inode->i_count);
281 /***********************************************************************/
283 static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char *target)
285 struct jffs2_inode_info *f, *dir_f;
286 struct jffs2_sb_info *c;
288 struct jffs2_raw_inode *ri;
289 struct jffs2_raw_dirent *rd;
290 struct jffs2_full_dnode *fn;
291 struct jffs2_full_dirent *fd;
293 uint32_t alloclen, phys_ofs;
297 /* FIXME: If you care. We'd need to use frags for the target
298 if it grows much more than this */
299 if (strlen(target) > 254)
302 ri = jffs2_alloc_raw_inode();
307 c = JFFS2_SB_INFO(dir_i->i_sb);
309 /* Try to reserve enough space for both node and dirent.
310 * Just the node will do for now, though
312 namelen = dentry->d_name.len;
313 ret = jffs2_reserve_space(c, sizeof(*ri) + strlen(target), &phys_ofs, &alloclen, ALLOC_NORMAL);
316 jffs2_free_raw_inode(ri);
320 inode = jffs2_new_inode(dir_i, S_IFLNK | S_IRWXUGO, ri);
323 jffs2_free_raw_inode(ri);
324 jffs2_complete_reservation(c);
325 return PTR_ERR(inode);
328 inode->i_op = &jffs2_symlink_inode_operations;
330 f = JFFS2_INODE_INFO(inode);
332 inode->i_size = strlen(target);
333 ri->isize = ri->dsize = ri->csize = cpu_to_je32(inode->i_size);
334 ri->totlen = cpu_to_je32(sizeof(*ri) + inode->i_size);
335 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
337 ri->compr = JFFS2_COMPR_NONE;
338 ri->data_crc = cpu_to_je32(crc32(0, target, strlen(target)));
339 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
341 fn = jffs2_write_dnode(c, f, ri, target, strlen(target), phys_ofs, &writtenlen);
343 jffs2_free_raw_inode(ri);
346 /* Eeek. Wave bye bye */
348 jffs2_complete_reservation(c);
349 jffs2_clear_inode(inode);
352 /* No data here. Only a metadata node, which will be
353 obsoleted by the first data write
358 /* Work out where to put the dirent node now. */
359 writtenlen = PAD(writtenlen);
360 phys_ofs += writtenlen;
361 alloclen -= writtenlen;
363 if (alloclen < sizeof(*rd)+namelen) {
364 /* Not enough space left in this chunk. Get some more */
365 jffs2_complete_reservation(c);
366 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
369 jffs2_clear_inode(inode);
374 rd = jffs2_alloc_raw_dirent();
376 /* Argh. Now we treat it like a normal delete */
377 jffs2_complete_reservation(c);
378 jffs2_clear_inode(inode);
382 dir_f = JFFS2_INODE_INFO(dir_i);
385 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
386 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
387 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
388 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
390 rd->pino = cpu_to_je32(dir_i->i_ino);
391 rd->version = cpu_to_je32(++dir_f->highest_version);
392 rd->ino = cpu_to_je32(inode->i_ino);
393 rd->mctime = cpu_to_je32(get_seconds());
396 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
397 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
399 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
402 /* dirent failed to write. Delete the inode normally
403 as if it were the final unlink() */
404 jffs2_complete_reservation(c);
405 jffs2_free_raw_dirent(rd);
407 jffs2_clear_inode(inode);
411 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
413 jffs2_free_raw_dirent(rd);
415 /* Link the fd into the inode's list, obsoleting an old
417 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
420 jffs2_complete_reservation(c);
422 d_instantiate(dentry, inode);
427 static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
429 struct jffs2_inode_info *f, *dir_f;
430 struct jffs2_sb_info *c;
432 struct jffs2_raw_inode *ri;
433 struct jffs2_raw_dirent *rd;
434 struct jffs2_full_dnode *fn;
435 struct jffs2_full_dirent *fd;
437 uint32_t alloclen, phys_ofs;
443 ri = jffs2_alloc_raw_inode();
447 c = JFFS2_SB_INFO(dir_i->i_sb);
449 /* Try to reserve enough space for both node and dirent.
450 * Just the node will do for now, though
452 namelen = dentry->d_name.len;
453 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL);
456 jffs2_free_raw_inode(ri);
460 inode = jffs2_new_inode(dir_i, mode, ri);
463 jffs2_free_raw_inode(ri);
464 jffs2_complete_reservation(c);
465 return PTR_ERR(inode);
468 inode->i_op = &jffs2_dir_inode_operations;
469 inode->i_fop = &jffs2_dir_operations;
470 /* Directories get nlink 2 at start */
473 f = JFFS2_INODE_INFO(inode);
475 ri->data_crc = cpu_to_je32(0);
476 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
478 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, &writtenlen);
480 jffs2_free_raw_inode(ri);
483 /* Eeek. Wave bye bye */
485 jffs2_complete_reservation(c);
486 jffs2_clear_inode(inode);
489 /* No data here. Only a metadata node, which will be
490 obsoleted by the first data write
495 /* Work out where to put the dirent node now. */
496 writtenlen = PAD(writtenlen);
497 phys_ofs += writtenlen;
498 alloclen -= writtenlen;
500 if (alloclen < sizeof(*rd)+namelen) {
501 /* Not enough space left in this chunk. Get some more */
502 jffs2_complete_reservation(c);
503 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
506 jffs2_clear_inode(inode);
511 rd = jffs2_alloc_raw_dirent();
513 /* Argh. Now we treat it like a normal delete */
514 jffs2_complete_reservation(c);
515 jffs2_clear_inode(inode);
519 dir_f = JFFS2_INODE_INFO(dir_i);
522 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
523 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
524 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
525 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
527 rd->pino = cpu_to_je32(dir_i->i_ino);
528 rd->version = cpu_to_je32(++dir_f->highest_version);
529 rd->ino = cpu_to_je32(inode->i_ino);
530 rd->mctime = cpu_to_je32(get_seconds());
533 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
534 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
536 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
539 /* dirent failed to write. Delete the inode normally
540 as if it were the final unlink() */
541 jffs2_complete_reservation(c);
542 jffs2_free_raw_dirent(rd);
544 jffs2_clear_inode(inode);
548 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
551 jffs2_free_raw_dirent(rd);
553 /* Link the fd into the inode's list, obsoleting an old
555 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
558 jffs2_complete_reservation(c);
560 d_instantiate(dentry, inode);
564 static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
566 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
567 struct jffs2_full_dirent *fd;
570 for (fd = f->dents ; fd; fd = fd->next) {
574 ret = jffs2_unlink(dir_i, dentry);
580 static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, mknod_arg_t rdev)
582 struct jffs2_inode_info *f, *dir_f;
583 struct jffs2_sb_info *c;
585 struct jffs2_raw_inode *ri;
586 struct jffs2_raw_dirent *rd;
587 struct jffs2_full_dnode *fn;
588 struct jffs2_full_dirent *fd;
592 uint32_t alloclen, phys_ofs;
596 ri = jffs2_alloc_raw_inode();
600 c = JFFS2_SB_INFO(dir_i->i_sb);
602 if (S_ISBLK(mode) || S_ISCHR(mode)) {
603 dev = cpu_to_je16((MAJOR(rdev) << 8) | MINOR(rdev));
604 devlen = sizeof(dev);
607 /* Try to reserve enough space for both node and dirent.
608 * Just the node will do for now, though
610 namelen = dentry->d_name.len;
611 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, ALLOC_NORMAL);
614 jffs2_free_raw_inode(ri);
618 inode = jffs2_new_inode(dir_i, mode, ri);
621 jffs2_free_raw_inode(ri);
622 jffs2_complete_reservation(c);
623 return PTR_ERR(inode);
625 inode->i_op = &jffs2_file_inode_operations;
626 init_special_inode(inode, inode->i_mode, rdev);
628 f = JFFS2_INODE_INFO(inode);
630 ri->dsize = ri->csize = cpu_to_je32(devlen);
631 ri->totlen = cpu_to_je32(sizeof(*ri) + devlen);
632 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
634 ri->compr = JFFS2_COMPR_NONE;
635 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
636 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
638 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, &writtenlen);
640 jffs2_free_raw_inode(ri);
643 /* Eeek. Wave bye bye */
645 jffs2_complete_reservation(c);
646 jffs2_clear_inode(inode);
649 /* No data here. Only a metadata node, which will be
650 obsoleted by the first data write
655 /* Work out where to put the dirent node now. */
656 writtenlen = PAD(writtenlen);
657 phys_ofs += writtenlen;
658 alloclen -= writtenlen;
660 if (alloclen < sizeof(*rd)+namelen) {
661 /* Not enough space left in this chunk. Get some more */
662 jffs2_complete_reservation(c);
663 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
666 jffs2_clear_inode(inode);
671 rd = jffs2_alloc_raw_dirent();
673 /* Argh. Now we treat it like a normal delete */
674 jffs2_complete_reservation(c);
675 jffs2_clear_inode(inode);
679 dir_f = JFFS2_INODE_INFO(dir_i);
682 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
683 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
684 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
685 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
687 rd->pino = cpu_to_je32(dir_i->i_ino);
688 rd->version = cpu_to_je32(++dir_f->highest_version);
689 rd->ino = cpu_to_je32(inode->i_ino);
690 rd->mctime = cpu_to_je32(get_seconds());
693 /* XXX: This is ugly. */
694 rd->type = (mode & S_IFMT) >> 12;
696 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
697 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
699 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
702 /* dirent failed to write. Delete the inode normally
703 as if it were the final unlink() */
704 jffs2_complete_reservation(c);
705 jffs2_free_raw_dirent(rd);
707 jffs2_clear_inode(inode);
711 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
713 jffs2_free_raw_dirent(rd);
715 /* Link the fd into the inode's list, obsoleting an old
717 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
720 jffs2_complete_reservation(c);
722 d_instantiate(dentry, inode);
727 static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
728 struct inode *new_dir_i, struct dentry *new_dentry)
731 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
732 struct jffs2_inode_info *victim_f = NULL;
735 /* The VFS will check for us and prevent trying to rename a
736 * file over a directory and vice versa, but if it's a directory,
737 * the VFS can't check whether the victim is empty. The filesystem
738 * needs to do that for itself.
740 if (new_dentry->d_inode) {
741 victim_f = JFFS2_INODE_INFO(new_dentry->d_inode);
742 if (S_ISDIR(new_dentry->d_inode->i_mode)) {
743 struct jffs2_full_dirent *fd;
745 down(&victim_f->sem);
746 for (fd = victim_f->dents; fd; fd = fd->next) {
756 /* XXX: We probably ought to alloc enough space for
757 both nodes at the same time. Writing the new link,
758 then getting -ENOSPC, is quite bad :)
761 /* Make a hard link */
763 /* XXX: This is ugly */
764 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
765 if (!type) type = DT_REG;
767 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
768 old_dentry->d_inode->i_ino, type,
769 new_dentry->d_name.name, new_dentry->d_name.len);
775 /* There was a victim. Kill it off nicely */
776 new_dentry->d_inode->i_nlink--;
777 /* Don't oops if the victim was a dirent pointing to an
778 inode which didn't exist. */
779 if (victim_f->inocache) {
780 down(&victim_f->sem);
781 victim_f->inocache->nlink--;
786 /* If it was a directory we moved, and there was no victim,
787 increase i_nlink on its new parent */
788 if (S_ISDIR(old_dentry->d_inode->i_mode) && !victim_f)
789 new_dir_i->i_nlink++;
791 /* Unlink the original */
792 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
793 old_dentry->d_name.name, old_dentry->d_name.len, NULL);
795 /* We don't touch inode->i_nlink */
798 /* Oh shit. We really ought to make a single node which can do both atomically */
799 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
801 old_dentry->d_inode->i_nlink++;
803 f->inocache->nlink++;
806 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret);
807 /* Might as well let the VFS know */
808 d_instantiate(new_dentry, old_dentry->d_inode);
809 atomic_inc(&old_dentry->d_inode->i_count);
813 if (S_ISDIR(old_dentry->d_inode->i_mode))
814 old_dir_i->i_nlink--;