ext2_lookup.c (37555) | ext2_lookup.c (43301) |
---|---|
1/* 2 * modified for Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/* 8 * Copyright (c) 1989, 1993 --- 348 unchanged lines hidden (view full) --- 357searchloop: 358 while (dp->i_offset < endsearch) { 359 /* 360 * If necessary, get the next directory block. 361 */ 362 if ((dp->i_offset & bmask) == 0) { 363 if (bp != NULL) 364 brelse(bp); | 1/* 2 * modified for Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/* 8 * Copyright (c) 1989, 1993 --- 348 unchanged lines hidden (view full) --- 357searchloop: 358 while (dp->i_offset < endsearch) { 359 /* 360 * If necessary, get the next directory block. 361 */ 362 if ((dp->i_offset & bmask) == 0) { 363 if (bp != NULL) 364 brelse(bp); |
365 if (error = 366 UFS_BLKATOFF(vdp, (off_t)dp->i_offset, NULL, &bp)) | 365 if ((error = 366 UFS_BLKATOFF(vdp, (off_t)dp->i_offset, NULL, &bp)) != 0) |
367 return (error); 368 entryoffsetinblock = 0; 369 } 370 /* 371 * If still looking for a slot, and at a DIRBLKSIZE 372 * boundary, have to start looking for free space again. 373 */ 374 if (slotstatus == NONE && --- 93 unchanged lines hidden (view full) --- 468 * allowing file to be created. 469 */ 470 if ((nameiop == CREATE || nameiop == RENAME) && 471 (flags & ISLASTCN) && dp->i_nlink != 0) { 472 /* 473 * Access for write is interpreted as allowing 474 * creation of files in the directory. 475 */ | 367 return (error); 368 entryoffsetinblock = 0; 369 } 370 /* 371 * If still looking for a slot, and at a DIRBLKSIZE 372 * boundary, have to start looking for free space again. 373 */ 374 if (slotstatus == NONE && --- 93 unchanged lines hidden (view full) --- 468 * allowing file to be created. 469 */ 470 if ((nameiop == CREATE || nameiop == RENAME) && 471 (flags & ISLASTCN) && dp->i_nlink != 0) { 472 /* 473 * Access for write is interpreted as allowing 474 * creation of files in the directory. 475 */ |
476 if (error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) | 476 if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) != 0) |
477 return (error); 478 /* 479 * Return an indication of where the new directory 480 * entry should be put. If we didn't find a slot, 481 * then set dp->i_count to 0 indicating 482 * that the new slot belongs at the end of the 483 * directory. If we found a slot, then the new entry 484 * can be put in the range from dp->i_offset to --- 64 unchanged lines hidden (view full) --- 549 * If the wantparent flag isn't set, we return only 550 * the directory (in ndp->ni_dvp), otherwise we go 551 * on and lock the inode, being careful with ".". 552 */ 553 if (nameiop == DELETE && (flags & ISLASTCN)) { 554 /* 555 * Write access to directory required to delete files. 556 */ | 477 return (error); 478 /* 479 * Return an indication of where the new directory 480 * entry should be put. If we didn't find a slot, 481 * then set dp->i_count to 0 indicating 482 * that the new slot belongs at the end of the 483 * directory. If we found a slot, then the new entry 484 * can be put in the range from dp->i_offset to --- 64 unchanged lines hidden (view full) --- 549 * If the wantparent flag isn't set, we return only 550 * the directory (in ndp->ni_dvp), otherwise we go 551 * on and lock the inode, being careful with ".". 552 */ 553 if (nameiop == DELETE && (flags & ISLASTCN)) { 554 /* 555 * Write access to directory required to delete files. 556 */ |
557 if (error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) | 557 if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) != 0) |
558 return (error); 559 /* 560 * Return pointer to current entry in dp->i_offset, 561 * and distance past previous entry (if there 562 * is a previous entry in this block) in dp->i_count. 563 * Save directory inode pointer in ndp->ni_dvp for dirremove(). 564 */ 565 if ((dp->i_offset & (DIRBLKSIZ - 1)) == 0) 566 dp->i_count = 0; 567 else 568 dp->i_count = dp->i_offset - prevoff; 569 if (dp->i_number == dp->i_ino) { 570 VREF(vdp); 571 *vpp = vdp; 572 return (0); 573 } | 558 return (error); 559 /* 560 * Return pointer to current entry in dp->i_offset, 561 * and distance past previous entry (if there 562 * is a previous entry in this block) in dp->i_count. 563 * Save directory inode pointer in ndp->ni_dvp for dirremove(). 564 */ 565 if ((dp->i_offset & (DIRBLKSIZ - 1)) == 0) 566 dp->i_count = 0; 567 else 568 dp->i_count = dp->i_offset - prevoff; 569 if (dp->i_number == dp->i_ino) { 570 VREF(vdp); 571 *vpp = vdp; 572 return (0); 573 } |
574 if (error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) | 574 if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) != 0) |
575 return (error); 576 /* 577 * If directory is "sticky", then user must own 578 * the directory, or the file in it, else she 579 * may not delete it (unless she's root). This 580 * implements append-only directories. 581 */ 582 if ((dp->i_mode & ISVTX) && --- 12 unchanged lines hidden (view full) --- 595 /* 596 * If rewriting (RENAME), return the inode and the 597 * information required to rewrite the present directory 598 * Must get inode of directory entry to verify it's a 599 * regular file, or empty directory. 600 */ 601 if (nameiop == RENAME && wantparent && 602 (flags & ISLASTCN)) { | 575 return (error); 576 /* 577 * If directory is "sticky", then user must own 578 * the directory, or the file in it, else she 579 * may not delete it (unless she's root). This 580 * implements append-only directories. 581 */ 582 if ((dp->i_mode & ISVTX) && --- 12 unchanged lines hidden (view full) --- 595 /* 596 * If rewriting (RENAME), return the inode and the 597 * information required to rewrite the present directory 598 * Must get inode of directory entry to verify it's a 599 * regular file, or empty directory. 600 */ 601 if (nameiop == RENAME && wantparent && 602 (flags & ISLASTCN)) { |
603 if (error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) | 603 if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) != 0) |
604 return (error); 605 /* 606 * Careful about locking second inode. 607 * This can only occur if the target is ".". 608 */ 609 if (dp->i_number == dp->i_ino) 610 return (EISDIR); | 604 return (error); 605 /* 606 * Careful about locking second inode. 607 * This can only occur if the target is ".". 608 */ 609 if (dp->i_number == dp->i_ino) 610 return (EISDIR); |
611 if (error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) | 611 if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) != 0) |
612 return (error); 613 *vpp = tdp; 614 cnp->cn_flags |= SAVENAME; 615 if (!lockparent) 616 VOP_UNLOCK(vdp, 0, p); 617 return (0); 618 } 619 --- 14 unchanged lines hidden (view full) --- 634 * implementing a sophisticated deadlock detection algorithm. 635 * Note also that this simple deadlock detection scheme will not 636 * work if the file system has any hard links other than ".." 637 * that point backwards in the directory structure. 638 */ 639 pdp = vdp; 640 if (flags & ISDOTDOT) { 641 VOP_UNLOCK(pdp, 0, p); /* race to get the inode */ | 612 return (error); 613 *vpp = tdp; 614 cnp->cn_flags |= SAVENAME; 615 if (!lockparent) 616 VOP_UNLOCK(vdp, 0, p); 617 return (0); 618 } 619 --- 14 unchanged lines hidden (view full) --- 634 * implementing a sophisticated deadlock detection algorithm. 635 * Note also that this simple deadlock detection scheme will not 636 * work if the file system has any hard links other than ".." 637 * that point backwards in the directory structure. 638 */ 639 pdp = vdp; 640 if (flags & ISDOTDOT) { 641 VOP_UNLOCK(pdp, 0, p); /* race to get the inode */ |
642 if (error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) { | 642 if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) != 0) { |
643 vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, p); 644 return (error); 645 } 646 if (lockparent && (flags & ISLASTCN) && 647 (error = vn_lock(pdp, LK_EXCLUSIVE, p))) { 648 vput(tdp); 649 return (error); 650 } 651 *vpp = tdp; 652 } else if (dp->i_number == dp->i_ino) { 653 VREF(vdp); /* we want ourself, ie "." */ 654 *vpp = vdp; 655 } else { | 643 vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, p); 644 return (error); 645 } 646 if (lockparent && (flags & ISLASTCN) && 647 (error = vn_lock(pdp, LK_EXCLUSIVE, p))) { 648 vput(tdp); 649 return (error); 650 } 651 *vpp = tdp; 652 } else if (dp->i_number == dp->i_ino) { 653 VREF(vdp); /* we want ourself, ie "." */ 654 *vpp = vdp; 655 } else { |
656 if (error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) | 656 if ((error = VFS_VGET(vdp->v_mount, dp->i_ino, &tdp)) != 0) |
657 return (error); 658 if (!lockparent || !(flags & ISLASTCN)) 659 VOP_UNLOCK(pdp, 0, p); 660 *vpp = tdp; 661 } 662 663 /* 664 * Insert name into cache if appropriate. --- 128 unchanged lines hidden (view full) --- 793 * 794 * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN. 795 */ 796 if (dp->i_offset + dp->i_count > dp->i_size) 797 dp->i_size = dp->i_offset + dp->i_count; 798 /* 799 * Get the block containing the space for the new directory entry. 800 */ | 657 return (error); 658 if (!lockparent || !(flags & ISLASTCN)) 659 VOP_UNLOCK(pdp, 0, p); 660 *vpp = tdp; 661 } 662 663 /* 664 * Insert name into cache if appropriate. --- 128 unchanged lines hidden (view full) --- 793 * 794 * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN. 795 */ 796 if (dp->i_offset + dp->i_count > dp->i_size) 797 dp->i_size = dp->i_offset + dp->i_count; 798 /* 799 * Get the block containing the space for the new directory entry. 800 */ |
801 if (error = UFS_BLKATOFF(dvp, (off_t)dp->i_offset, &dirbuf, &bp)) | 801 if ((error = UFS_BLKATOFF(dvp, (off_t)dp->i_offset, &dirbuf, &bp)) != 0) |
802 return (error); 803 /* 804 * Find space for the new entry. In the simple case, the entry at 805 * offset base will have the space. If it does not, then namei 806 * arranged that compacting the region dp->i_offset to 807 * dp->i_offset + dp->i_count would yield the 808 * space. 809 */ --- 61 unchanged lines hidden (view full) --- 871 struct buf *bp; 872 int error; 873 874 dp = VTOI(dvp); 875 if (dp->i_count == 0) { 876 /* 877 * First entry in block: set d_ino to zero. 878 */ | 802 return (error); 803 /* 804 * Find space for the new entry. In the simple case, the entry at 805 * offset base will have the space. If it does not, then namei 806 * arranged that compacting the region dp->i_offset to 807 * dp->i_offset + dp->i_count would yield the 808 * space. 809 */ --- 61 unchanged lines hidden (view full) --- 871 struct buf *bp; 872 int error; 873 874 dp = VTOI(dvp); 875 if (dp->i_count == 0) { 876 /* 877 * First entry in block: set d_ino to zero. 878 */ |
879 if (error = 880 UFS_BLKATOFF(dvp, (off_t)dp->i_offset, (char **)&ep, &bp)) | 879 if ((error = 880 UFS_BLKATOFF(dvp, (off_t)dp->i_offset, (char **)&ep, &bp)) != 0) |
881 return (error); 882 ep->inode = 0; 883 error = VOP_BWRITE(bp); 884 dp->i_flag |= IN_CHANGE | IN_UPDATE; 885 return (error); 886 } 887 /* 888 * Collapse new free space into previous entry. 889 */ | 881 return (error); 882 ep->inode = 0; 883 error = VOP_BWRITE(bp); 884 dp->i_flag |= IN_CHANGE | IN_UPDATE; 885 return (error); 886 } 887 /* 888 * Collapse new free space into previous entry. 889 */ |
890 if (error = UFS_BLKATOFF(dvp, (off_t)(dp->i_offset - dp->i_count), 891 (char **)&ep, &bp)) | 890 if ((error = UFS_BLKATOFF(dvp, (off_t)(dp->i_offset - dp->i_count), 891 (char **)&ep, &bp)) != 0) |
892 return (error); 893 ep->rec_len += dp->i_reclen; 894 error = VOP_BWRITE(bp); 895 dp->i_flag |= IN_CHANGE | IN_UPDATE; 896 return (error); 897} 898 899/* --- 6 unchanged lines hidden (view full) --- 906 struct inode *dp, *ip; 907 struct componentname *cnp; 908{ 909 struct buf *bp; 910 struct ext2_dir_entry *ep; 911 struct vnode *vdp = ITOV(dp); 912 int error; 913 | 892 return (error); 893 ep->rec_len += dp->i_reclen; 894 error = VOP_BWRITE(bp); 895 dp->i_flag |= IN_CHANGE | IN_UPDATE; 896 return (error); 897} 898 899/* --- 6 unchanged lines hidden (view full) --- 906 struct inode *dp, *ip; 907 struct componentname *cnp; 908{ 909 struct buf *bp; 910 struct ext2_dir_entry *ep; 911 struct vnode *vdp = ITOV(dp); 912 int error; 913 |
914 if (error = UFS_BLKATOFF(vdp, (off_t)dp->i_offset, (char **)&ep, &bp)) | 914 if ((error = UFS_BLKATOFF(vdp, (off_t)dp->i_offset, (char **)&ep, &bp)) != 0) |
915 return (error); 916 ep->inode = ip->i_number; 917 error = VOP_BWRITE(bp); 918 dp->i_flag |= IN_CHANGE | IN_UPDATE; 919 return (error); 920} 921 922/* --- 96 unchanged lines hidden (view full) --- 1019 } 1020 if (dirbuf.dotdot_ino == source->i_number) { 1021 error = EINVAL; 1022 break; 1023 } 1024 if (dirbuf.dotdot_ino == rootino) 1025 break; 1026 vput(vp); | 915 return (error); 916 ep->inode = ip->i_number; 917 error = VOP_BWRITE(bp); 918 dp->i_flag |= IN_CHANGE | IN_UPDATE; 919 return (error); 920} 921 922/* --- 96 unchanged lines hidden (view full) --- 1019 } 1020 if (dirbuf.dotdot_ino == source->i_number) { 1021 error = EINVAL; 1022 break; 1023 } 1024 if (dirbuf.dotdot_ino == rootino) 1025 break; 1026 vput(vp); |
1027 if (error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino, &vp)) { | 1027 if ((error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino, &vp)) != 0) { |
1028 vp = NULL; 1029 break; 1030 } 1031 } 1032 1033out: 1034 if (error == ENOTDIR) 1035 printf("checkpath: .. not a directory\n"); 1036 if (vp != NULL) 1037 vput(vp); 1038 return (error); 1039} 1040 | 1028 vp = NULL; 1029 break; 1030 } 1031 } 1032 1033out: 1034 if (error == ENOTDIR) 1035 printf("checkpath: .. not a directory\n"); 1036 if (vp != NULL) 1037 vput(vp); 1038 return (error); 1039} 1040 |