From b86877bef05dab48d7c3a733431361260c18fa81 Mon Sep 17 00:00:00 2001 From: mckusick Date: Wed, 26 Jul 2000 23:07:01 +0000 Subject: Clean up the snapshot code so that it no longer depends on the use of the SF_IMMUTABLE flag to prevent writing. Instead put in explicit checking for the SF_SNAPSHOT flag in the appropriate places. With this change, it is now possible to rename and link to snapshot files. It is also possible to set or clear any of the owner, group, or other read bits on the file, though none of the write or execute bits can be set. There is also an explicit test to prevent the setting or clearing of the SF_SNAPSHOT flag via chflags() or fchflags(). Note also that the modify time cannot be changed as it needs to accurately reflect the time that the snapshot was taken. Submitted by: Robert Watson --- sys/ufs/ffs/ffs_snapshot.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'sys/ufs/ffs/ffs_snapshot.c') diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c index af03143..ba74b31 100644 --- a/sys/ufs/ffs/ffs_snapshot.c +++ b/sys/ufs/ffs/ffs_snapshot.c @@ -241,7 +241,7 @@ restart: /* * Change inode to snapshot type file. */ - ip->i_flags |= SF_IMMUTABLE | SF_SNAPSHOT; + ip->i_flags |= SF_SNAPSHOT; ip->i_flag |= IN_CHANGE | IN_UPDATE; /* * Ensure that the snapshot is completely on disk. @@ -414,7 +414,7 @@ restart: ino_to_fsbo(fs, xp->i_number); dip->di_size = 0; dip->di_blocks = 0; - dip->di_flags &= ~(SF_IMMUTABLE | SF_SNAPSHOT); + dip->di_flags &= ~SF_SNAPSHOT; bzero(&dip->di_db[0], (NDADDR + NIADDR) * sizeof(ufs_daddr_t)); nbp->b_flags |= B_VALIDSUSPWRT; bdwrite(nbp); @@ -636,11 +636,9 @@ ffs_snapremove(vp) ip->i_copyonwrite = 0; break; } - if (xp == 0) { + if (xp == 0) printf("ffs_snapremove: lost snapshot vnode %d\n", ip->i_number); - vref(vp); - } if (VTOI(devvp)->i_copyonwrite == 0) devvp->v_flag &= ~VCOPYONWRITE; /* @@ -673,9 +671,8 @@ ffs_snapremove(vp) /* * Clear snapshot flag and drop reference. */ - ip->i_flags &= ~(SF_IMMUTABLE | SF_SNAPSHOT); + ip->i_flags &= ~SF_SNAPSHOT; ip->i_flag |= IN_CHANGE | IN_UPDATE; - vrele(vp); } /* @@ -905,7 +902,8 @@ ffs_snapshot_unmount(mp) while ((xp = devip->i_copyonwrite) != 0) { devip->i_copyonwrite = xp->i_copyonwrite; xp->i_copyonwrite = 0; - vrele(ITOV(xp)); + if (xp->i_effnlink > 0) + vrele(ITOV(xp)); } ump->um_devvp->v_flag &= ~VCOPYONWRITE; } -- cgit v1.1