Skip to contentSkip to conversation

utimensat: AT_EMPTY_PATH support

PATCH In review Miklos Szeredi 2 participants 2 messages Nov 7, 2018 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utimensat: AT_EMPTY_PATH support

This makes it possible to use utimensat on an O_PATH file (including symlinks).

It supersedes the nonstandard utimensat(fd, NULL, ...) form.

---
 fs/utimes.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/utimes.c +4 -2
index bdcf2daf39c1..f9c7ebad19d7 100644
@@ -97,13 +97,13 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times,
 		goto out;
 	}
 
-	if (flags & ~AT_SYMLINK_NOFOLLOW)
+	if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
 		goto out;
 
 	if (filename == NULL && dfd != AT_FDCWD) {
 		struct fd f;
 
-		if (flags & AT_SYMLINK_NOFOLLOW)
+		if (flags)
 			goto out;
 
 		f = fdget(dfd);
@@ -119,6 +119,8 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times,
 
 		if (!(flags & AT_SYMLINK_NOFOLLOW))
 			lookup_flags |= LOOKUP_FOLLOW;
+		if (flags & AT_EMPTY_PATH)
+			lookup_flags |= LOOKUP_EMPTY;
 retry:
 		error = user_path_at(dfd, filename, lookup_flags, &path);
 		if (error)
Signature · 1 line
2.14.3
#1 lore raw
Quoted 6 lines · Miklos Szeredi

This makes it possible to use utimensat on an O_PATH file (including symlinks).

It supersedes the nonstandard utimensat(fd, NULL, ...) form.

Thanks for fixing this Miklos. It seems to work for me for following use case I have where I want to change time on symlink opened with O_PATH.

symfd = open("foo-symlink.txt", O_PATH | O_NOFOLLOW); utimensat(fd, "", NULL, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);

Thanks
Vivek

Quoted 36 lines
---
 fs/utimes.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/utimes.c +4 -2
index bdcf2daf39c1..f9c7ebad19d7 100644
@@ -97,13 +97,13 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times,
 		goto out;
 	}
 
-	if (flags & ~AT_SYMLINK_NOFOLLOW)
+	if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
 		goto out;
 
 	if (filename == NULL && dfd != AT_FDCWD) {
 		struct fd f;
 
-		if (flags & AT_SYMLINK_NOFOLLOW)
+		if (flags)
 			goto out;
 
 		f = fdget(dfd);
@@ -119,6 +119,8 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times,
 
 		if (!(flags & AT_SYMLINK_NOFOLLOW))
 			lookup_flags |= LOOKUP_FOLLOW;
+		if (flags & AT_EMPTY_PATH)
+			lookup_flags |= LOOKUP_EMPTY;
 retry:
 		error = user_path_at(dfd, filename, lookup_flags, &path);
 		if (error)
Signature · 1 line
2.14.3