RE: Why is the kfree() argument const?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Friday, January 18, 2008 - 9:10 am

On Thu, 17 Jan 2008, David Schwartz wrote:

Here's an idea. Think it through. 

Why don't we need write permissions to a file to unlink it?

Here's a hint: because unlinking doesn't *write* to it. In fact, it 
doesn't read from it either. It doesn't do any access at all to that 
object, it just *removes* it.

Is the file gone after you unlink it? Yes (modulo refcounting for aliasing 
"pointers" aka filenames, but that's the same for any memory manager - 
malloc/free just doesn't have any, so you could think of it as a 
non-hardlinking filesystem).

So you're the one who are speaking nonsense. Making something "not exist" 
is not at all the same thing as accessing it for a write (or a read). It 
is a metadata operation that doesn't conceptually change the data in any 
way, shape or form - it just makes it go away.

And btw, exactly as with kfree(), a unlink() may well do something like 
"disk scrubbing" for security purposes, or cancel pending writes to the 
backing store. But even though it may write (or, by undoing a pending 
write, effectively "change the state") to the disk sectors that used to 
contain the file data, ONLY AN IDIOT would call it "writing to the file". 
Because "the file" is gone. Writing to the place where the file used to be 
is a different thing.

So give it up. You're wrong. Freeing a memory area is not "writing to it" 
or accessing it in *any* manner, it's an operation on another level 
entirely.

			Linus
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
RE: Why is the kfree() argument const?, Linus Torvalds, (Thu Jan 17, 2:25 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Thu Jan 17, 3:28 pm)
RE: Why is the kfree() argument const?, Linus Torvalds, (Thu Jan 17, 4:10 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Thu Jan 17, 5:56 pm)
RE: Why is the kfree() argument const?, Linus Torvalds, (Thu Jan 17, 6:15 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Thu Jan 17, 10:02 pm)
Re: Why is the kfree() argument const?, Giacomo Catenazzi, (Fri Jan 18, 1:20 am)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 1:30 am)
Re: Why is the kfree() argument const?, Giacomo A. Catenazzi, (Fri Jan 18, 4:47 am)
Re: Why is the kfree() argument const?, Björn, (Fri Jan 18, 6:31 am)
Re: Why is the kfree() argument const?, Andy Lutomirski, (Fri Jan 18, 6:53 am)
Re: Why is the kfree() argument const?, Andy Lutomirski, (Fri Jan 18, 6:54 am)
Re: Why is the kfree() argument const?, Jakob Oestergaard, (Fri Jan 18, 7:39 am)
Re: Why is the kfree() argument const?, Chris Friesen, (Fri Jan 18, 8:38 am)
RE: Why is the kfree() argument const?, Linus Torvalds, (Fri Jan 18, 9:10 am)
Re: Why is the kfree() argument const?, Olivier Galibert, (Fri Jan 18, 10:24 am)
Re: Why is the kfree() argument const?, Olivier Galibert, (Fri Jan 18, 10:37 am)
Re: Why is the kfree() argument const?, DM, (Fri Jan 18, 11:06 am)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 12:06 pm)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 12:14 pm)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 12:55 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Fri Jan 18, 1:55 pm)
Re: Why is the kfree() argument const?, J.A. , (Fri Jan 18, 3:29 pm)
Re: Why is the kfree() argument const?, Krzysztof Halasa, (Fri Jan 18, 4:44 pm)