Re: Linux's interpretation of trailing '/'

Tom Eastep (eastep@eastep-1.mis.tandem.com)
Tue, 15 Dec 1998 08:39:48 -0800


On Tue, 15 Dec 1998, Michael H. Warfield wrote:
>Is there anything in POSIX which speaks to this issue? If there
>is, it should be settled and we can say one is right and one is not. If
>not, it's vendor implimentation dependent and we can all claim to be "right".

The Single Unix Specification says:

"If the pathname refers to a directory, it may also have one or more
trailing slashes."

and:

"If a symbolic link (see symbolic link ) is encountered during pathname
resolution, then pathname resolution is complete if all of the following
are true:"

This is the last component of the pathname.

The pathname has no trailing slash.

The function is required to act on the symbolic link itself, or
certain arguments direct that the function act on the symbolic
link itself."

The following shows that Linux adheres to this specification:

[eastep@eastep-1 test]$ mkdir foo
[eastep@eastep-1 test]$ ls foo/
[eastep@eastep-1 test]$ ln -s foo bar
[eastep@eastep-1 test]$ touch foo/bash
[eastep@eastep-1 test]$ ls bar
bash
[eastep@eastep-1 test]$ ls bar/
bash
[eastep@eastep-1 test]$ ls foo/bash/
ls: foo/bash/: Not a directory
[eastep@eastep-1 test]$ ls -l bar/
total 0
-rw-r--r-- 1 eastep loc551 0 Dec 15 08:56 bash
[eastep@eastep-1 test]$

Note that "ls bar/" is acceptable since the (resolved) pathname does refer to
a directory (foo). Also, "ls -l" uses lstat(2) which is required to act on the
symbolic link itself; since there was a trailing slash, it acted on the
referent of the link (foo).

-Tom

--
Tom Eastep
Compaq Computer Corporation
Enterprise Computing Group
Tandem Division
tom.eastep@compaq.com

- 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/