delphij's Chaos

选择chaos这个词是因为~~实在很难找到一个更合适的词来形容这儿了……

11 Aug 2004

Is this a problem?

While reading the snapshot code in FFS Soft Updates’s FreeBSD implementation, I got a question about the following code:

		/*
		 * If there is a fragment, clear it here.
		 */
		blkno = 0;
		loc = howmany(xp->i_size, fs->fs_bsize) - 1;
		if (loc < NDADDR) {
			__len = fragroundup(fs, blkoff(fs, xp->i\_size));__
			if (len < fs->fs_bsize) {
				ffs_blkfree(copy_fs, vp, DIP(xp, i_db[loc]),
				    len, xp->i_number);
				blkno = DIP(xp, i_db[loc]);
				DIP_SET(xp, i_db[loc], 0);
			}
		}

The code indicated with bold is what I have question on. Isn’t it possible to get a zero if the unlinked file is zero-sized? If so, then what will happen when doing ffs_blkfree()?

My intention is to modify the if statement like this:

if ((len != 0) && len < (fs->fs_base))

I have e-mailed Kirk about this issue.