Hi,<br>
<br>
  I am facing one problem only with mv command not with cp command. I have a test program <br>
<br>
<font color="#ff00ff">#include <stdio.h></font><br>
<font color="#ff00ff">#include <string.h></font><br>
<font color="#ff00ff">#include <sys/types.h></font><br>
<font color="#ff00ff">#include <sys/stat.h></font><br>
<font color="#ff00ff">#include <sys/mount.h></font><br>
<font color="#ff00ff">#include <fcntl.h></font><br>
<font color="#ff00ff">#include <errno.h></font><br>
<br>
<font color="#ff00ff">int sync_file(char *file)</font><br>
<font color="#ff00ff">{</font><br>
<font color="#ff00ff">    FILE *fp=NULL;</font><br>
<font color="#ff00ff">    int fd;</font><br>
<br>
<font color="#ff00ff">    printf("file is %s\n",file);</font><br>
<font color="#ff00ff">    fp = fopen(file, "r");</font><br>
<font color="#ff00ff">    if(!fp)</font><br>
<font color="#ff00ff">        return -1;</font><br>
<br>
<font color="#ff00ff">    fd = fileno(fp);</font><br>
<font color="#ff00ff">    fflush(fp);</font><br>
<font color="#ff00ff">    fsync(fd);</font><br>
<font color="#ff00ff">    ioctl (fd, BLKFLSBUF, 0);</font><br>
<font color="#ff00ff">    fclose(fp);</font><br>
<font color="#ff00ff">    return 0;</font><br>
<br>
<font color="#ff00ff">}</font><br>
<br>
<font color="#ff00ff">int main()</font><br>
<font color="#ff00ff">{</font><br>
<font color="#ff00ff">    int len=0;</font><br>
<font color="#ff00ff">    FILE *fp = NULL;</font><br>
<font color="#ff00ff">    char buf[1024];</font><br>
<font color="#ff00ff">    char *fname = "/etc/test.conf";</font><br>
<font color="#ff00ff">    char fname_tmp[129] = "";</font><br>
<br>
<br>
<font color="#ff00ff">    len = sprintf(buf, "%s\n", "Newly added Line is there");</font><br>
<br>
<font color="#ff00ff">    snprintf(fname_tmp, 128, "%s.tmp", fname);</font><br>
<br>
<font color="#ff00ff">    if( (fp = fopen(fname_tmp,"a")) == NULL )</font><br>
<font color="#ff00ff">        printf(" ERROR: open(), error - %s\n",strerror(errno));</font><br>
<br>
<font color="#ff00ff">    fprintf(fp,"%s",buf);</font><br>
<font color="#ff00ff">    fflush(fp);</font><br>
<br>
<font color="#ff00ff">    fsync(fileno(fp));</font><br>
<font color="#ff00ff">    fclose(fp);</font><br>
<font color="#ff00ff">    system("cp -f /etc/test.conf.tmp /etc/test.conf");</font><br>
<font color="#ff00ff">   // system("mv -f /etc/test.conf.tmp /etc/test.conf");</font><br>
<font color="#ff00ff">    sync_file(fname);</font><br>
<font color="#ff00ff">    return 0;</font><br>
<font color="#ff00ff">}</font><br>
<br>
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?<br>

<br>
Thanks,<br>Indira.<br>