We have beaglebone black based custom board with 256MB RAM and 4GB eMMC. Board runs Linux kernel 4.9
we are running into a situation where we create a file in tempfs
and then after validation, we have to move it to the ext4 partition of eMMC. File nothing but a certificate
in some situations, we have multiple certs in a directory so we have to move the whole directory from tempfs to the ext4 partition on eMMC.
So one of the problems we are worried about is atomicity
of mv
(move) operation.
As per rename
system call Linux man page renaming file is an atomic operation.
http://man7.org/linux/man-pages/man2/rename.2.html
However we are not sure if rename operation involves moving files between two filesystems, atomicity is still available or not. So question is
Is moving file from tmpfs
to ext4
atomic?
Obviously, one possible solution is to keep files in a different folder on the same partition (on same filesystem obviously ) and rename it using mv
.
For directory using below approach of renaming
SRC_dir --> TMP_DEST_dir
DEST_dir --> BAK_DEST_dir
TMP_DEST_dir --> DEST_dir
delete BAK_DEST_dir
Any suggestion for alternatives ?
EDIT
After i got reply i tried following test code on the board,
#include <stdio.h>
#include <errno.h>
int main()
{
int retcode = 0;
system("touch /tmp/rename_test");
retcode = rename("/tmp/rename_test", "/home/fs_rename_test");
if ( retcode < 0) {
printf("errno : %d\n",errno );
perror("Error occurred while renaming file");
return 1;
}
return 0;
}
Which returned following output. And confirmed that rename doesn't work cross file-system.
errno : 18
Error occurred while renaming file: Invalid cross-device link