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: dir.c,v 1.84 2004/11/16 20:36:11 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 these. */
26 #include <linux/version.h>
27 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,48)
28 typedef int mknod_arg_t;
29 #define NAMEI_COMPAT(x) ((void *)x)
31 typedef dev_t mknod_arg_t;
32 #define NAMEI_COMPAT(x) (x)
35 static int jffs2_readdir (struct file *, void *, filldir_t);
37 static int jffs2_create (struct inode *,struct dentry *,int,
39 static struct dentry *jffs2_lookup (struct inode *,struct dentry *,
41 static int jffs2_link (struct dentry *,struct inode *,struct dentry *);
42 static int jffs2_unlink (struct inode *,struct dentry *);
43 static int jffs2_symlink (struct inode *,struct dentry *,const char *);
44 static int jffs2_mkdir (struct inode *,struct dentry *,int);
45 static int jffs2_rmdir (struct inode *,struct dentry *);
46 static int jffs2_mknod (struct inode *,struct dentry *,int,mknod_arg_t);
47 static int jffs2_rename (struct inode *, struct dentry *,
48 struct inode *, struct dentry *);
50 struct file_operations jffs2_dir_operations =
52 .read = generic_read_dir,
53 .readdir = jffs2_readdir,
59 struct inode_operations jffs2_dir_inode_operations =
61 .create = NAMEI_COMPAT(jffs2_create),
62 .lookup = NAMEI_COMPAT(jffs2_lookup),
64 .unlink = jffs2_unlink,
65 .symlink = jffs2_symlink,
69 .rename = jffs2_rename,
70 .setattr = jffs2_setattr,
73 /***********************************************************************/
76 /* We keep the dirent list sorted in increasing order of name hash,
77 and we use the same hash function as the dentries. Makes this
80 static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
83 struct jffs2_inode_info *dir_f;
84 struct jffs2_sb_info *c;
85 struct jffs2_full_dirent *fd = NULL, *fd_list;
87 struct inode *inode = NULL;
89 D1(printk(KERN_DEBUG "jffs2_lookup()\n"));
91 dir_f = JFFS2_INODE_INFO(dir_i);
92 c = JFFS2_SB_INFO(dir_i->i_sb);
96 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
97 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) {
98 if (fd_list->nhash == target->d_name.hash &&
99 (!fd || fd_list->version > fd->version) &&
100 strlen(fd_list->name) == target->d_name.len &&
101 !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) {
109 inode = iget(dir_i->i_sb, ino);
111 printk(KERN_WARNING "iget() failed for ino #%u\n", ino);
112 return (ERR_PTR(-EIO));
116 d_add(target, inode);
121 /***********************************************************************/
124 static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
126 struct jffs2_inode_info *f;
127 struct jffs2_sb_info *c;
128 struct inode *inode = filp->f_dentry->d_inode;
129 struct jffs2_full_dirent *fd;
130 unsigned long offset, curofs;
132 D1(printk(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", filp->f_dentry->d_inode->i_ino));
134 f = JFFS2_INODE_INFO(inode);
135 c = JFFS2_SB_INFO(inode->i_sb);
137 offset = filp->f_pos;
140 D1(printk(KERN_DEBUG "Dirent 0: \".\", ino #%lu\n", inode->i_ino));
141 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR) < 0)
146 unsigned long pino = parent_ino(filp->f_dentry);
147 D1(printk(KERN_DEBUG "Dirent 1: \"..\", ino #%lu\n", pino));
148 if (filldir(dirent, "..", 2, 1, pino, DT_DIR) < 0)
155 for (fd = f->dents; fd; fd = fd->next) {
158 /* First loop: curofs = 2; offset = 2 */
159 if (curofs < offset) {
160 D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n",
161 fd->name, fd->ino, fd->type, curofs, offset));
165 D2(printk(KERN_DEBUG "Skipping deletion dirent \"%s\"\n", fd->name));
169 D2(printk(KERN_DEBUG "Dirent %ld: \"%s\", ino #%u, type %d\n", offset, fd->name, fd->ino, fd->type));
170 if (filldir(dirent, fd->name, strlen(fd->name), offset, fd->ino, fd->type) < 0)
176 filp->f_pos = offset;
180 /***********************************************************************/
183 static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
184 struct nameidata *nd)
186 struct jffs2_raw_inode *ri;
187 struct jffs2_inode_info *f, *dir_f;
188 struct jffs2_sb_info *c;
192 ri = jffs2_alloc_raw_inode();
196 c = JFFS2_SB_INFO(dir_i->i_sb);
198 D1(printk(KERN_DEBUG "jffs2_create()\n"));
200 inode = jffs2_new_inode(dir_i, mode, ri);
203 D1(printk(KERN_DEBUG "jffs2_new_inode() failed\n"));
204 jffs2_free_raw_inode(ri);
205 return PTR_ERR(inode);
208 inode->i_op = &jffs2_file_inode_operations;
209 inode->i_fop = &jffs2_file_operations;
210 inode->i_mapping->a_ops = &jffs2_file_address_operations;
211 inode->i_mapping->nrpages = 0;
213 f = JFFS2_INODE_INFO(inode);
214 dir_f = JFFS2_INODE_INFO(dir_i);
216 ret = jffs2_do_create(c, dir_f, f, ri,
217 dentry->d_name.name, dentry->d_name.len);
220 make_bad_inode(inode);
222 jffs2_free_raw_inode(ri);
226 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(ri->ctime));
228 jffs2_free_raw_inode(ri);
229 d_instantiate(dentry, inode);
231 D1(printk(KERN_DEBUG "jffs2_create: Created ino #%lu with mode %o, nlink %d(%d). nrpages %ld\n",
232 inode->i_ino, inode->i_mode, inode->i_nlink, f->inocache->nlink, inode->i_mapping->nrpages));
236 /***********************************************************************/
239 static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
241 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
242 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
243 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode);
246 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
247 dentry->d_name.len, dead_f);
248 if (dead_f->inocache)
249 dentry->d_inode->i_nlink = dead_f->inocache->nlink;
252 /***********************************************************************/
255 static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct dentry *dentry)
257 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dentry->d_inode->i_sb);
258 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
259 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
263 /* Don't let people make hard links to bad inodes. */
267 if (S_ISDIR(old_dentry->d_inode->i_mode))
270 /* XXX: This is ugly */
271 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
272 if (!type) type = DT_REG;
274 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len);
278 old_dentry->d_inode->i_nlink = ++f->inocache->nlink;
280 d_instantiate(dentry, old_dentry->d_inode);
281 atomic_inc(&old_dentry->d_inode->i_count);
286 /***********************************************************************/
288 static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char *target)
290 struct jffs2_inode_info *f, *dir_f;
291 struct jffs2_sb_info *c;
293 struct jffs2_raw_inode *ri;
294 struct jffs2_raw_dirent *rd;
295 struct jffs2_full_dnode *fn;
296 struct jffs2_full_dirent *fd;
298 uint32_t alloclen, phys_ofs;
301 /* FIXME: If you care. We'd need to use frags for the target
302 if it grows much more than this */
303 if (strlen(target) > 254)
306 ri = jffs2_alloc_raw_inode();
311 c = JFFS2_SB_INFO(dir_i->i_sb);
313 /* Try to reserve enough space for both node and dirent.
314 * Just the node will do for now, though
316 namelen = dentry->d_name.len;
317 ret = jffs2_reserve_space(c, sizeof(*ri) + strlen(target), &phys_ofs, &alloclen, ALLOC_NORMAL);
320 jffs2_free_raw_inode(ri);
324 inode = jffs2_new_inode(dir_i, S_IFLNK | S_IRWXUGO, ri);
327 jffs2_free_raw_inode(ri);
328 jffs2_complete_reservation(c);
329 return PTR_ERR(inode);
332 inode->i_op = &jffs2_symlink_inode_operations;
334 f = JFFS2_INODE_INFO(inode);
336 inode->i_size = strlen(target);
337 ri->isize = ri->dsize = ri->csize = cpu_to_je32(inode->i_size);
338 ri->totlen = cpu_to_je32(sizeof(*ri) + inode->i_size);
339 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
341 ri->compr = JFFS2_COMPR_NONE;
342 ri->data_crc = cpu_to_je32(crc32(0, target, strlen(target)));
343 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
345 fn = jffs2_write_dnode(c, f, ri, target, strlen(target), phys_ofs, ALLOC_NORMAL);
347 jffs2_free_raw_inode(ri);
350 /* Eeek. Wave bye bye */
352 jffs2_complete_reservation(c);
353 jffs2_clear_inode(inode);
356 /* No data here. Only a metadata node, which will be
357 obsoleted by the first data write
362 jffs2_complete_reservation(c);
363 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
366 jffs2_clear_inode(inode);
370 rd = jffs2_alloc_raw_dirent();
372 /* Argh. Now we treat it like a normal delete */
373 jffs2_complete_reservation(c);
374 jffs2_clear_inode(inode);
378 dir_f = JFFS2_INODE_INFO(dir_i);
381 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
382 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
383 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
384 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
386 rd->pino = cpu_to_je32(dir_i->i_ino);
387 rd->version = cpu_to_je32(++dir_f->highest_version);
388 rd->ino = cpu_to_je32(inode->i_ino);
389 rd->mctime = cpu_to_je32(get_seconds());
392 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
393 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
395 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL);
398 /* dirent failed to write. Delete the inode normally
399 as if it were the final unlink() */
400 jffs2_complete_reservation(c);
401 jffs2_free_raw_dirent(rd);
403 jffs2_clear_inode(inode);
407 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
409 jffs2_free_raw_dirent(rd);
411 /* Link the fd into the inode's list, obsoleting an old
413 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
416 jffs2_complete_reservation(c);
418 d_instantiate(dentry, inode);
423 static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
425 struct jffs2_inode_info *f, *dir_f;
426 struct jffs2_sb_info *c;
428 struct jffs2_raw_inode *ri;
429 struct jffs2_raw_dirent *rd;
430 struct jffs2_full_dnode *fn;
431 struct jffs2_full_dirent *fd;
433 uint32_t alloclen, phys_ofs;
438 ri = jffs2_alloc_raw_inode();
442 c = JFFS2_SB_INFO(dir_i->i_sb);
444 /* Try to reserve enough space for both node and dirent.
445 * Just the node will do for now, though
447 namelen = dentry->d_name.len;
448 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL);
451 jffs2_free_raw_inode(ri);
455 inode = jffs2_new_inode(dir_i, mode, ri);
458 jffs2_free_raw_inode(ri);
459 jffs2_complete_reservation(c);
460 return PTR_ERR(inode);
463 inode->i_op = &jffs2_dir_inode_operations;
464 inode->i_fop = &jffs2_dir_operations;
465 /* Directories get nlink 2 at start */
468 f = JFFS2_INODE_INFO(inode);
470 ri->data_crc = cpu_to_je32(0);
471 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
473 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
475 jffs2_free_raw_inode(ri);
478 /* Eeek. Wave bye bye */
480 jffs2_complete_reservation(c);
481 jffs2_clear_inode(inode);
484 /* No data here. Only a metadata node, which will be
485 obsoleted by the first data write
490 jffs2_complete_reservation(c);
491 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
494 jffs2_clear_inode(inode);
498 rd = jffs2_alloc_raw_dirent();
500 /* Argh. Now we treat it like a normal delete */
501 jffs2_complete_reservation(c);
502 jffs2_clear_inode(inode);
506 dir_f = JFFS2_INODE_INFO(dir_i);
509 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
510 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
511 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
512 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
514 rd->pino = cpu_to_je32(dir_i->i_ino);
515 rd->version = cpu_to_je32(++dir_f->highest_version);
516 rd->ino = cpu_to_je32(inode->i_ino);
517 rd->mctime = cpu_to_je32(get_seconds());
520 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
521 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
523 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL);
526 /* dirent failed to write. Delete the inode normally
527 as if it were the final unlink() */
528 jffs2_complete_reservation(c);
529 jffs2_free_raw_dirent(rd);
531 jffs2_clear_inode(inode);
535 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
538 jffs2_free_raw_dirent(rd);
540 /* Link the fd into the inode's list, obsoleting an old
542 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
545 jffs2_complete_reservation(c);
547 d_instantiate(dentry, inode);
551 static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
553 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
554 struct jffs2_full_dirent *fd;
557 for (fd = f->dents ; fd; fd = fd->next) {
561 ret = jffs2_unlink(dir_i, dentry);
567 static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, mknod_arg_t rdev)
569 struct jffs2_inode_info *f, *dir_f;
570 struct jffs2_sb_info *c;
572 struct jffs2_raw_inode *ri;
573 struct jffs2_raw_dirent *rd;
574 struct jffs2_full_dnode *fn;
575 struct jffs2_full_dirent *fd;
579 uint32_t alloclen, phys_ofs;
582 if (!old_valid_dev(rdev))
585 ri = jffs2_alloc_raw_inode();
589 c = JFFS2_SB_INFO(dir_i->i_sb);
591 if (S_ISBLK(mode) || S_ISCHR(mode)) {
592 dev = cpu_to_je16(old_encode_dev(rdev));
593 devlen = sizeof(dev);
596 /* Try to reserve enough space for both node and dirent.
597 * Just the node will do for now, though
599 namelen = dentry->d_name.len;
600 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, ALLOC_NORMAL);
603 jffs2_free_raw_inode(ri);
607 inode = jffs2_new_inode(dir_i, mode, ri);
610 jffs2_free_raw_inode(ri);
611 jffs2_complete_reservation(c);
612 return PTR_ERR(inode);
614 inode->i_op = &jffs2_file_inode_operations;
615 init_special_inode(inode, inode->i_mode, rdev);
617 f = JFFS2_INODE_INFO(inode);
619 ri->dsize = ri->csize = cpu_to_je32(devlen);
620 ri->totlen = cpu_to_je32(sizeof(*ri) + devlen);
621 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
623 ri->compr = JFFS2_COMPR_NONE;
624 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
625 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
627 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL);
629 jffs2_free_raw_inode(ri);
632 /* Eeek. Wave bye bye */
634 jffs2_complete_reservation(c);
635 jffs2_clear_inode(inode);
638 /* No data here. Only a metadata node, which will be
639 obsoleted by the first data write
644 jffs2_complete_reservation(c);
645 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
648 jffs2_clear_inode(inode);
652 rd = jffs2_alloc_raw_dirent();
654 /* Argh. Now we treat it like a normal delete */
655 jffs2_complete_reservation(c);
656 jffs2_clear_inode(inode);
660 dir_f = JFFS2_INODE_INFO(dir_i);
663 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
664 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
665 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
666 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
668 rd->pino = cpu_to_je32(dir_i->i_ino);
669 rd->version = cpu_to_je32(++dir_f->highest_version);
670 rd->ino = cpu_to_je32(inode->i_ino);
671 rd->mctime = cpu_to_je32(get_seconds());
674 /* XXX: This is ugly. */
675 rd->type = (mode & S_IFMT) >> 12;
677 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
678 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
680 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL);
683 /* dirent failed to write. Delete the inode normally
684 as if it were the final unlink() */
685 jffs2_complete_reservation(c);
686 jffs2_free_raw_dirent(rd);
688 jffs2_clear_inode(inode);
692 dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
694 jffs2_free_raw_dirent(rd);
696 /* Link the fd into the inode's list, obsoleting an old
698 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
701 jffs2_complete_reservation(c);
703 d_instantiate(dentry, inode);
708 static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
709 struct inode *new_dir_i, struct dentry *new_dentry)
712 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
713 struct jffs2_inode_info *victim_f = NULL;
716 /* The VFS will check for us and prevent trying to rename a
717 * file over a directory and vice versa, but if it's a directory,
718 * the VFS can't check whether the victim is empty. The filesystem
719 * needs to do that for itself.
721 if (new_dentry->d_inode) {
722 victim_f = JFFS2_INODE_INFO(new_dentry->d_inode);
723 if (S_ISDIR(new_dentry->d_inode->i_mode)) {
724 struct jffs2_full_dirent *fd;
726 down(&victim_f->sem);
727 for (fd = victim_f->dents; fd; fd = fd->next) {
737 /* XXX: We probably ought to alloc enough space for
738 both nodes at the same time. Writing the new link,
739 then getting -ENOSPC, is quite bad :)
742 /* Make a hard link */
744 /* XXX: This is ugly */
745 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
746 if (!type) type = DT_REG;
748 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
749 old_dentry->d_inode->i_ino, type,
750 new_dentry->d_name.name, new_dentry->d_name.len);
756 /* There was a victim. Kill it off nicely */
757 new_dentry->d_inode->i_nlink--;
758 /* Don't oops if the victim was a dirent pointing to an
759 inode which didn't exist. */
760 if (victim_f->inocache) {
761 down(&victim_f->sem);
762 victim_f->inocache->nlink--;
767 /* If it was a directory we moved, and there was no victim,
768 increase i_nlink on its new parent */
769 if (S_ISDIR(old_dentry->d_inode->i_mode) && !victim_f)
770 new_dir_i->i_nlink++;
772 /* Unlink the original */
773 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
774 old_dentry->d_name.name, old_dentry->d_name.len, NULL);
776 /* We don't touch inode->i_nlink */
779 /* Oh shit. We really ought to make a single node which can do both atomically */
780 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
782 old_dentry->d_inode->i_nlink++;
784 f->inocache->nlink++;
787 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret);
788 /* Might as well let the VFS know */
789 d_instantiate(new_dentry, old_dentry->d_inode);
790 atomic_inc(&old_dentry->d_inode->i_count);
794 if (S_ISDIR(old_dentry->d_inode->i_mode))
795 old_dir_i->i_nlink--;