Hello,
I have been working on an application, part of which copies files from
a source location to the destination. To make sure that the file is
written out to the disk, i have been using fsync() call on the
destination file descriptor.
To test whether the file is being written out to the disk,
- i mount a usb thumb drive
- copy a file into the mounted usb partition and call fsync() before
closing the fd
- when the process is complete, disconnect the pen drive (without umount'ing)
- connect and mount it again and check if the file exists and is
copied correctly.
I have tested this on vfat partitions and it works correctly.
I have added support for ntfs partitions via ntfs-3g (2010.8.8
release), and i am able to mount ntfs partitions. However if i copy a
file to a destination which is a ntfs partition, the above test fails.
i.e. after disconnecting, reconnecting and mounting the ntfs
partition, the file does not exist. Which leads me to believe that the
fsync() call is not working as expected.
If i manually call the 'sync' command before disconnecting the pen
drive, the file gets written out correctly.
Please find attached a sample C application that exhibits this
behaviour. Is there something else that i need to be doing so that the
file gets written out to the disk.
Awaiting for your response.
Thanks and Regards
~Sameer
#include <stdio.h>
#define MAX_BUFFER 512
int main (int argc, char *argv[])
{
FILE *infile;
FILE *outfile;
char buffer[MAX_BUFFER];
int len;
int eof = 0;
int fd;
if (argc < 3) {
printf ("Usage: %s src dest\n", argv[0]);
return 1;
}
infile = fopen (argv[1], "r");
if (infile == NULL) {
printf ("error: could not open %s for reading\n", argv[1]);
return 1;
}
outfile = fopen (argv[2], "w");
if (outfile == NULL) {
printf ("error: could not open %s for writing\n", argv[2]);
return 1;
}
while (eof == 0) {
len = fread (buffer, 1, MAX_BUFFER, infile);
if (len < MAX_BUFFER) {
eof = feof (infile);
}
if (len)
fwrite (buffer, 1, len, outfile);
}
fclose (infile);
printf ("sync'ing %s...", argv[2]);
fd = fileno (outfile);
fsync (fd);
printf ("done\n");
fclose (outfile);
return 0;
}
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
ntfs-3g-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel