Skip to content

Commit 0d7a855

Browse files
author
Miklos Szeredi
committed
vfs: add RENAME_WHITEOUT
This adds a new RENAME_WHITEOUT flag. This flag makes rename() create a whiteout of source. The whiteout creation is atomic relative to the rename. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 787fb6b commit 0d7a855

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

fs/namei.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,12 +4209,16 @@ SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname,
42094209
bool should_retry = false;
42104210
int error;
42114211

4212-
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
4212+
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
42134213
return -EINVAL;
42144214

4215-
if ((flags & RENAME_NOREPLACE) && (flags & RENAME_EXCHANGE))
4215+
if ((flags & (RENAME_NOREPLACE | RENAME_WHITEOUT)) &&
4216+
(flags & RENAME_EXCHANGE))
42164217
return -EINVAL;
42174218

4219+
if ((flags & RENAME_WHITEOUT) && !capable(CAP_MKNOD))
4220+
return -EPERM;
4221+
42184222
retry:
42194223
from = user_path_parent(olddfd, oldname, &oldnd, lookup_flags);
42204224
if (IS_ERR(from)) {

include/uapi/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#define RENAME_NOREPLACE (1 << 0) /* Don't overwrite target */
3939
#define RENAME_EXCHANGE (1 << 1) /* Exchange source and dest */
40+
#define RENAME_WHITEOUT (1 << 2) /* Whiteout source */
4041

4142
struct fstrim_range {
4243
__u64 start;

0 commit comments

Comments
 (0)