The problem Miklos is trying to solve is the problem of exchanging two files — both files continue to exist, but their names have been swapped. To achieve this, he has posted a patch set adding a new renameat2() system call:
int renameat2(int olddir, const char *oldname,
int newdir, const char *newname, unsigned int flags);
This system call differs from renameat() in that it has the new flags argument; if flags is zero, renameat2() behaves exactly as renameat() . If, instead, flags contains RENAME_EXCHANGE , an existing file at newname will not be deleted; instead, it will be renamed to oldname . Thus, with this flag, renameat2() can be used to atomically exchange two files. The main use case for renameat2() is to support union filesystems, where it is often desirable to atomically replace files or directories with "whiteouts" indicating that they have been deleted. One could imagine other possibilities as well; Miklos suggests atomically replacing a directory with a symbolic link as one of them.
No review comments have been posted as of this writing.
| Index entries for this article | |
|---|---|
| Kernel | renameat2() |