From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Sun, 17 Oct 2004 13:01:40 -0400 From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] truncation via wstat on ken's fs In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: Topicbox-Message-UUID: ef766658-eacd-11e9-9e20-41e7f4b1d025 > Changing the length is easy, but giving back the no-longer-needed > blocks is messy, involving a recursive walk of the indirect blocks. > I'm tempted to just change the length, which gives the desired > user-visible effect, unless the side-effect of freeing the > unneeded storage is important to someone. I thought about this too, but it's not actually true. It's important to free or zero the blocks: fd = create("foo", ORDWR); write(fd, "hello world", 12); ftruncate(fd, 0); pwrite(fd, "", 1, 11); should result in a file with 12 zero bytes, not the string "hello world\0". It's not that hard to do the recursive walk. Remove does it already. In fossil we just pulled that code out of remove and made it a separate function that can be passed a length instead of assuming 0. Russ