-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linux: zpl: inode: pass through RENAME_NOREPLACE
Fragment cited from Documentation/filesystems/vfs.rst, the description is unchanged since the original in kernel commit 520c8b16505236fc82daa352e6c5e73cd9870cff ("vfs: add renameat2 syscall") Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
- Loading branch information
1 parent
0b2428d
commit 42bea64
Showing
8 changed files
with
108 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: 0BSD | ||
|
||
#undef NDEBUG | ||
#include <assert.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
|
||
#ifdef RENAME_NOREPLACE | ||
static void makeff(int in, size_t sz, struct stat *madeff) { | ||
int ff = openat(in, "from", | ||
O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | O_CLOEXEC, 0644); | ||
assert(write(ff, "from", sz) == sz); | ||
fstat(ff, madeff); | ||
close(ff); | ||
} | ||
|
||
int main(int argc, const char **argv) { | ||
int from = argc > 1 ? | ||
open(argv[1], O_PATH | O_DIRECTORY | O_CLOEXEC) : AT_FDCWD; | ||
int to = argc > 2 ? | ||
open(argv[2], O_PATH | O_DIRECTORY | O_CLOEXEC) : AT_FDCWD; | ||
assert(from != -1 && to != -1); | ||
|
||
struct stat ffbuf, frombuf, tobuf; | ||
makeff(from, 3, &ffbuf); | ||
fstatat(from, "from", &frombuf, 0); | ||
assert(!memcmp(&ffbuf, &frombuf, sizeof (struct stat))); | ||
assert(!renameat2(from, "from", to, "to", RENAME_NOREPLACE)); | ||
assert(!fstatat(to, "to", &tobuf, 0)); | ||
assert(!memcmp(&ffbuf, &tobuf, sizeof (struct stat))); | ||
|
||
struct stat ffbuf2, frombuf2, from2buf2, tobuf2; | ||
makeff(from, 4, &ffbuf2); | ||
fstatat(from, "from", &frombuf2, 0); | ||
assert(!memcmp(&ffbuf2, &frombuf2, sizeof (struct stat))); | ||
assert(memcmp(&ffbuf, &ffbuf2, sizeof (struct stat))); | ||
assert(renameat2(from, "from", to, "to", RENAME_NOREPLACE) == -1 && | ||
errno == EEXIST); | ||
assert(!fstatat(from, "from", &from2buf2, 0)); | ||
assert(!memcmp(&frombuf2, &from2buf2, sizeof (struct stat))); | ||
assert(!fstatat(to, "to", &tobuf2, 0)); | ||
assert(!memcmp(&tobuf, &tobuf2, sizeof (struct stat))); | ||
} | ||
#else | ||
int main(void) { | ||
abort(); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/zfs-tests/tests/functional/rename_dirs/rename_no_replace_001_pos.ksh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/ksh -p | ||
# SPDX-License-Identifier: 0BSD | ||
|
||
. $STF_SUITE/include/libtest.shlib | ||
|
||
is_linux || [ $(linux_version) -ge $(linux_version "3.15.0") ] || log_unsupported "renameat2(2) is Linux-only" | ||
|
||
verify_runnable "both" | ||
|
||
log_assert "renameat2(RENAME_NOREPLACE) works" | ||
log_onexit log_must rm -r "$TESTDIR"/* | ||
|
||
mkdir "$TESTDIR"/{a,b,c} | ||
|
||
log_must rename_no_replace "$TESTDIR" "$TESTDIR" ; rm "$TESTDIR"/from | ||
log_must rename_no_replace "$TESTDIR" "$TESTDIR"/a | ||
|
||
cd "$TESTDIR"/b | ||
log_must rename_no_replace ../c; rm to | ||
log_must rename_no_replace | ||
|
||
log_pass |