6
5
On Linux/Unix file-systems, I understand the reason why you need the execute permission on the parent folder to read or write a file: the execute permission gives you access to the inode on the file, and without that, you can never reach the content of the file.
However for renaming a file (actually, even deleting), you just need to change the name of the file in the list, which shouldn't require to have access to the inode. So why is the execute bit required for renaming a file, write permissions should be enough?
This doesn't seem symetric with read access: with r--
permissions, you can do ls
on the directory and access the list of filenames in that directory. You don't need execute because you are not accessing the inodes. Similarly, with -w-
, you should be able to change the list of filenames (you don't need to access the inodes either), but you can't, why?
So technically you could delete a file or directory with just
rw-
? The way the answer is written now it sounds like if you had a (probably malicious) utility that simply unlinked files/directories without updating their link count or trying to check what kind of directory entry they are, then you could remove directory entries without needing thex
bit. – Ajedi32 – 2015-07-20T18:43:38.8731@Ajedi32, no, you really do need the
x
permission. A malicious utility cannot skip those steps that require looking up and decrementing the link count because the POSIX kernel does not offer a system call that skips those steps. POSIX only offersunlink()
(for files) andrmdir()
(for directories) and those system calls both do all the right things with looking up and link counts. – Celada – 2015-07-20T19:18:18.237I know what I can do, and what I can't. That's not my question, my question is why. I don't need to lookup any filename to rename a file. I just change a name to another name, I don't need to know what that name resolves to. – Flavien – 2012-06-28T13:36:57.247
I tried to emphasize the nature of the "lookup" ability in my answer as an explanation for why. Another way to say it: the
rename
system call takes two pathnames as arguments. It looks up both.x
is required to do that. But in the end, the best answer to "why" is "because POSIX defines it that way". – Celada – 2012-06-28T13:43:31.357It sort of make sense that for delete, you need to decrement the link count, therefore you need
x
to access the inode. For rename, I don't see why access to the inodes is needed. – Flavien – 2012-06-28T14:14:56.997