I am facing one problem only with mv command not with cp command. I have a test program
Here i am opening a tmp file for writing. Then i am copying/moving for original file. Then i do a fflush, fsync(), ioctl() to the original file. Then i run this binary in linux machine(ext2 file system, 2.6.23.5 kernel) after that immediately power off the machine. Then power on machine, the file is disappeared or written data lost or file gets corrupted if i move the tmp file to the original file. And there is a no problem if i copy the tmp file to original file. So i want to know the difference between the cp and mv command. Can you please give me suggestion on it?
Thanks,
Indira
Moderator's Comments:
Moved post to its own thread - please no "threadjacking"; removed colour formatting; added code tags
mv takes the file and places it in a another directory, the entry in the old directory is removed. if you mv from filesyem1 to filesystem2, mv behaves like cp + rm old file.
The rename() C call does what mv does.
cp duplicates the file - you have two entries in directories, old and new.
thanks for your replay. I know this. Actually I want to know file system data structure difference between cp and mv command. Because if copy the tmp file to original file then fsync() icotl()(seen in my source code) then power off machine there is no data loss. If i move the tmp file to original then there is a data loss. So i want to know what makes the difference between these.
well, I suggest you read the source code for cp and mv
well, for a start, cp copies the file, so opens, reads and copies. mv just moves or renames it. So the actual inode is not accessed,
only the Directory entries.
---------- Post updated at 12:16 PM ---------- Previous update was at 12:10 PM ----------
Quote:
Originally Posted by achenle
The mv command first deletes the target file if it exists. The cp command does not.
no that is wrong.
observe, if I mv (rename) a file the inode
does not change:
if I do a cp the inodes actually change.
the inode is the physical disk block(s) where the file lives.
you have only updated the directory with a mv
As for your question. I believe calling fsync has nothing to do with the directory structure, which is entirely up to the file system modules in the kernel. So, I would guess when you mv and power off, the file system has not had a chance to flush its changes. As such, you lose the modifications it made to the directory structure. When you cp the file, it may flush the changes more immediately as it is creating a new file.... This is just a guess.... However, I do not believe your fix lies in the program you are writing, because I am not sure you can programatically control when the file system changes get flushed to disk.
Moving from AIX 6.1 to RHEL 6.6, I have noticed a few command differences.
One that has been causing issue is a simple echo command when I have to use it this way -> "echo -e"
On the AIX it outputs to "-e" but since RHEL has "-e" as an option for echo and hence it outputs to blank here.
All... (3 Replies)
Hello all
the su with -l option is running normal with linux but when i try to run it on unix AIX 5.2.7 it's not working with -l option
any help (6 Replies)
OK, I've used various versions of UNIX(Solaris, HPUX, etc..) over the years. Now the organization I work for is leaning towards more Linux based systems(Redhat, Suse, etc..)
I do see differences in in comands and how to accomplish basic adminstration, but nothing mind blowing.
So, what is it... (5 Replies)
/*
* one-way-pipe.c - example of using a pipe to communicate data between a
* process and its child process. The parent reads input
* from the user, and sends it to the child via a pipe.
* The child prints the received data to the... (1 Reply)