diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-06-25 08:49:11 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-25 13:01:22 -0400 |
commit | 45c9b11a1d07770cabb48cb0f7960a77650ffc64 (patch) | |
tree | f1928b66fa23a5350cc15b0c448e9acefff66758 /fs/namei.c | |
parent | 584e1236bbcdfec3f64c751908b8b4fe868c2d20 (diff) |
[PATCH] Implement AT_SYMLINK_FOLLOW flag for linkat
When the linkat() syscall was added the flag parameter was added in the
last minute but it wasn't used so far. The following patch should change
that. My tests show that this is all that's needed.
If OLDNAME is a symlink setting the flag causes linkat to follow the
symlink and create a hardlink with the target. This is actually the
behavior POSIX demands for link() as well but Linux wisely does not do
this. With this flag (which will most likely be in the next POSIX
revision) the programmer can choose the behavior, defaulting to the safe
variant. As a side effect it is now possible to implement a
POSIX-compliant link(2) function for those who are interested.
touch file
ln -s file symlink
linkat(fd, "symlink", fd, "newlink", 0)
-> newlink is hardlink of symlink
linkat(fd, "symlink", fd, "newlink", AT_SYMLINK_FOLLOW)
-> newlink is hardlink of file
The value of AT_SYMLINK_FOLLOW is determined by the definition we already
use in glibc.
Signed-off-by: Ulrich Drepper <drepper@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/namei.c b/fs/namei.c index bb4a3e40e432..c784e8bb57a3 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -2243,14 +2243,16 @@ asmlinkage long sys_linkat(int olddfd, const char __user *oldname, | |||
2243 | int error; | 2243 | int error; |
2244 | char * to; | 2244 | char * to; |
2245 | 2245 | ||
2246 | if (flags != 0) | 2246 | if ((flags & ~AT_SYMLINK_FOLLOW) != 0) |
2247 | return -EINVAL; | 2247 | return -EINVAL; |
2248 | 2248 | ||
2249 | to = getname(newname); | 2249 | to = getname(newname); |
2250 | if (IS_ERR(to)) | 2250 | if (IS_ERR(to)) |
2251 | return PTR_ERR(to); | 2251 | return PTR_ERR(to); |
2252 | 2252 | ||
2253 | error = __user_walk_fd(olddfd, oldname, 0, &old_nd); | 2253 | error = __user_walk_fd(olddfd, oldname, |
2254 | flags & AT_SYMLINK_FOLLOW ? LOOKUP_FOLLOW : 0, | ||
2255 | &old_nd); | ||
2254 | if (error) | 2256 | if (error) |
2255 | goto exit; | 2257 | goto exit; |
2256 | error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd); | 2258 | error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd); |