- 论坛徽章:
- 1
|
回复 6# slackware12
"对于目录文件来说, 改变它的目录块的内容, size值并没有发生变化"
这里目录文件的size值是发生变化的,你所说的没有发生变化应该是指从目录的父目录中看时没有发生变化
我理解的是目录下所有文件占用的空间并不计入比如ls时查看目录大小得到的值中
你在目录文件中添加一条目录项,目录文件变化,但是目录文件对应的其父目录中的目录项长度还是不变的
刚查看了一下ext2中添加目录项的代码- 474/*
- 475 * Parent is locked.
- 476 */
- 477int ext2_add_link (struct dentry *dentry, struct inode *inode)
- 478{
- 479 struct inode *dir = dentry->d_parent->d_inode;
- 480 const char *name = dentry->d_name.name;
- 481 int namelen = dentry->d_name.len;
- 482 unsigned chunk_size = ext2_chunk_size(dir);
- 483 unsigned reclen = EXT2_DIR_REC_LEN(namelen);
- 484 unsigned short rec_len, name_len;
- 485 struct page *page = NULL;
- 486 ext2_dirent * de;
- 487 unsigned long npages = dir_pages(dir);
- 488 unsigned long n;
- 489 char *kaddr;
- 490 loff_t pos;
- 491 int err;
- 492
- 493 /*
- 494 * We take care of directory expansion in the same loop.
- 495 * This code plays outside i_size, so it locks the page
- 496 * to protect that region.
- 497 */
- 498 for (n = 0; n <= npages; n++) {
- 499 char *dir_end;
- 500
- 501 page = ext2_get_page(dir, n, 0);
- 502 err = PTR_ERR(page);
- 503 if (IS_ERR(page))
- 504 goto out;
- 505 lock_page(page);
- 506 kaddr = page_address(page);
- 507 dir_end = kaddr + ext2_last_byte(dir, n);
- 508 de = (ext2_dirent *)kaddr;
- 509 kaddr += PAGE_CACHE_SIZE - reclen;
- 510 while ((char *)de <= kaddr) {
- 511 if ((char *)de == dir_end) {
- 512 /* We hit i_size */
- 513 name_len = 0;
- 514 rec_len = chunk_size;
- 515 de->rec_len = ext2_rec_len_to_disk(chunk_size);
- 516 de->inode = 0;
- 517 goto got_it;
- 518 }
- 519 if (de->rec_len == 0) {
- 520 ext2_error(dir->i_sb, __func__,
- 521 "zero-length directory entry");
- 522 err = -EIO;
- 523 goto out_unlock;
- 524 }
- 525 err = -EEXIST;
- 526 if (ext2_match (namelen, name, de))
- 527 goto out_unlock;
- 528 name_len = EXT2_DIR_REC_LEN(de->name_len);
- 529 rec_len = ext2_rec_len_from_disk(de->rec_len);
- 530 if (!de->inode && rec_len >= reclen)
- 531 goto got_it;
- 532 if (rec_len >= name_len + reclen)
- 533 goto got_it;
- 534 de = (ext2_dirent *) ((char *) de + rec_len);
- 535 }
- 536 unlock_page(page);
- 537 ext2_put_page(page);
- 538 }
- 539 BUG();
- 540 return -EINVAL;
- 541
- 542got_it:
- 543 pos = page_offset(page) +
- 544 (char*)de - (char*)page_address(page);
- 545 err = __ext2_write_begin(NULL, page->mapping, pos, rec_len, 0,
- 546 &page, NULL);
- 547 if (err)
- 548 goto out_unlock;
- 549 if (de->inode) {
- 550 ext2_dirent *de1 = (ext2_dirent *) ((char *) de + name_len);
- 551 de1->rec_len = ext2_rec_len_to_disk(rec_len - name_len);
- 552 de->rec_len = ext2_rec_len_to_disk(name_len);
- 553 de = de1;
- 554 }
- 555 de->name_len = namelen;
- 556 memcpy(de->name, name, namelen);
- 557 de->inode = cpu_to_le32(inode->i_ino);
- 558 ext2_set_de_type (de, inode);
- 559 err = ext2_commit_chunk(page, pos, rec_len);
- 560 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
- 561 EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
- 562 mark_inode_dirty(dir);
- 563 /* OFFSET_CACHE */
- 564out_put:
- 565 ext2_put_page(page);
- 566out:
- 567 return err;
- 568out_unlock:
- 569 unlock_page(page);
- 570 goto out_put;
- 571}
复制代码 注意 560 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
这里mtime/ctime都发生了变化 |
|