Is `mv dir dir2` atomic ?
if I rename a dir
mv dir dir2 Is this operation atomic? Suppose there 100 files in dir, does linux rename them one by one or at once? In other words, is there a time at which both dir and dir2 exist, with dir has, say 30 files and dir2 has the rest 70 files? |
Quote:
---------------------- Steve Stites |
I'm not certain, but I think that there are no truly atomic file system operations - or at least no guarantees. I think the details are specific to each file system implementation.
|
Quote:
edit: lots of simultaneous replies. hehehe |
Thanks all.
Can I get an official link or resource for "mv is actually change the dir name" and "OS locks the dir duing the change"? I am writing a tech document of them. Thanks. Quote:
|
Quote:
http://www.oreilly.com/pub/topic/linux ---------------------- Steve Stites |
But I think mv belongs to GNU coreutils, which is not linux kernel.
Correct me if I am wrong. Quote:
|
Quote:
--------------------- Steve Stites |
Look at it this way, mv is a synonym for rename (in this case); ie it doesn't 'move' anything, it just 'renames' it.
|
I agree that the "final" answer to your question would come from reading up on the rename system call. Ultimately, mv just wraps around that system call. The man page available here:
http://www.linuxmanpages.com/man2/rename.2.php seems to suggest that it is atomic. That said, we should clarify some things. Moving one directory to another may be atomic, but moving multiple things may not be. That is because the coreutils (or busybox, etc) mv just calls rename over and over. Each rename is atomic, but if you specify a number of files to move that might not be. Summary: mv dir dir2 - looks atomic mv file1 file2 file3 file4 dir - probably not atomic Hope that helps! |
All times are GMT -5. The time now is 05:22 AM. |