Re: patch 2.1.88 - cosmetic

Linus Torvalds (torvalds@transmeta.com)
Sun, 22 Feb 1998 11:07:22 -0800 (PST)


Hi,

On Sun, 22 Feb 1998, Guest wrote:
>
> While modyfing kernel sources I noticed that in open_namei() we use O_....
> names, and in one case a number is used, so cosmetic fix follow ;-)

It's cosmetic, but it's wrong - subtly so (so don't feel bad, and the
subtlety is exactly why I'm cc'ing linux-kernel, not because I would want
to ridicule your patch).

The "2" isn't O_RDWR - rather the reverse. It's _only_ write. The flags go
tha sane way:
0 = 00 - no permissions
1 = 01 - read permissions
2 = 10 - write permissions
3 = 11 - read and write permissions

while the O_RDONLY/O_RDWR things go the wrong way

0 - read, 1 - write, 2 - read-write

due to (stupid, but understandable) historical UNIX issues. The other
O_xxx flags are the same way, because they make sense even historically.

[ side comment: so why didn't I fix "O_RDONLY" etc to make sense? The
problem is that people _know_ that O_RDONLY is 0, so there are actually
programs that use the constants directly rather than getting them
through the define in fcntl.h. This may not be very common any more,
but it was certainly common when I started Linux ]

The kernel internal flag numbers have to be different because (a) it makes
it much easier to test for readability/writability and (b) it allows the
special case of no permissions which is used for symlinks.

I don't think I ever added any clarifying defines for these magic
constants, but maybe there are defines and I have just forgotten them..

Linus

-----
> --- namei.c-orig Sun Feb 22 17:53:41 1998
> +++ namei.c Sun Feb 22 17:54:13 1998
> @@ -603,7 +603,7 @@
> flag &= ~O_TRUNC;
> } else {
> error = -EROFS;
> - if (IS_RDONLY(inode) && (flag & 2))
> + if (IS_RDONLY(inode) && (flag & O_RDWR))
> goto exit;
> }
> /*

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu