Re: Linux's interpretation of trailing '/'

Michael Mess (michael@kawo2.rwth-aachen.de)
Wed, 16 Dec 1998 00:31:42 +0100


Hi!

This is a really interesting issue. :-)

<michael@michael>:/tmp>dir -d kkk/ ddd
-rw-r--r-- 1 michael users 5 Dec 16 00:14 ddd
drwxr-xr-x 2 michael users 1024 Dec 16 00:15 kkk//
<michael@michael>:/tmp>

So let's look what strace says:

<michael@michael>:/tmp>strace cat ddd/
...
fstat(1, {st_mode=S_IFCHR|0622, st_rdev=makedev(3, 0), ...}) = 0
open("ddd/", O_RDONLY) = -1 ENOTDIR (Not a directory)
write(2, "cat: ", 5cat: ) = 5
write(2, "ddd/", 4ddd/) = 4
write(2, ": Not a directory", 17: Not a directory) = 17
write(2, "\n", 1
) = 1
close(1) = 0
_exit(1) = ?
<michael@michael>:/tmp>strace cat kkk/
...
fstat(1, {st_mode=S_IFCHR|0622, st_rdev=makedev(3, 0), ...}) = 0
open("kkk/", O_RDONLY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
brk(0x8005000) = 0x8005000
read(3, 0x8002b30, 4096) = -1 EISDIR (Is a directory)
write(2, "cat: ", 5cat: ) = 5
write(2, "kkk/", 4kkk/) = 4
write(2, ": Is a directory", 16: Is a directory) = 16
write(2, "\n", 1
) = 1
close(3) = 0
close(1) = 0
_exit(1) = ?

If I try to open the file "ddd/" open fails, because it isn't a
directory and a trailing "/" means it is a directory.
If I try to open the file "kkk/" open does not fail but read does,
because this is a directory and you can open a directory, but you can't
read it like a file.
If you say that "/" is a delimitor like a space, then this shouldn't
fail.
<michael@michael>:/tmp>cat/kkk/
bash: cat/kkk/: No such file or directory
<michael@michael>:/tmp>

Greetings, Michael

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/