Re: [ntfs-3g-devel] fsync() does not write out the file to the disk (Sameer Naik)

2010-09-17 Thread Sameer Naik
On Fri, Sep 17, 2010 at 1:51 AM, JD jd1...@gmail.com wrote:


 On 09/16/2010 09:42 AM, Sameer Naik wrote:

 Thanks i will try it out.

 On Thu, Sep 16, 2010 at 9:59 PM, JDjd1...@gmail.com  wrote:

 On 09/16/2010 03:00 AM, Sameer Naik wrote:

 Please find attached.
 P.S. I have added the fflush () call before the fsync () call.

 Regards
 ~Sameer

 Well, as I already communicated with Pierre, the man page for fsync says:

       Calling fsync() does not necessarily ensure that the entry in the
       directory containing the file has also reached disk. For that, an
       explicit fsync() on a file descriptor for the directory is also
       needed.

 So, when creating a new file, it is not sufficient to flush and fsync the
 file descriptor.
 You also need to have opened the containing directory and fsync'ed the
 directory
 file descriptor immediately after creating the file. flushing and
 sync'ing
 the file
 comes later when you are done with writing to it.

 Cheers,

 JD


 Remember that a directory can only be opened by
       DIR *opendir(const char *name);
       DIR *fdopendir(int fd);

 Problem is, how can you fsync a dir if you cannot open it
 with the open(2) system call?
 fsync(2) needs a file descriptor.
 DIR *  is not a file descriptor.


dirfd () call gets the fd associated with an open directory.
I have noticed that after a new directory is created, it news to be
fsync'd to make sure that it is written out to the disk.

Given this, if a new directory is created in a mounted partition and
the disk is disconnected without doing an unmount (or sync), the
created directory will not show up when it is remounted or from my
experience it is sometimes present but cannot be written into,
resulting in an IO error when trying to write into the directory.

Regards
~Sameer

 And yet, the man page for fsync says:

       Calling  fsync()  does  not  necessarily  ensure  that the entry in
 the
       directory containing the file has  also  reached  disk. For  that  an
       explicit fsync() on a file descriptor for the directory is also
 needed.

 Maybe someone can clear this up a bit?




--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
ntfs-3g-devel mailing list
ntfs-3g-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel


Re: [ntfs-3g-devel] fsync() does not write out the file to the disk (Sameer Naik)

2010-09-16 Thread JD


On 09/16/2010 01:21 PM, JD wrote:


 On 09/16/2010 09:42 AM, Sameer Naik wrote:
 Thanks i will try it out.

 On Thu, Sep 16, 2010 at 9:59 PM, JDjd1...@gmail.com  wrote:

 On 09/16/2010 03:00 AM, Sameer Naik wrote:
 Please find attached.
 P.S. I have added the fflush () call before the fsync () call.

 Regards
 ~Sameer
 Well, as I already communicated with Pierre, the man page for fsync 
 says:

Calling fsync() does not necessarily ensure that the entry in 
 the
directory containing the file has also reached disk. For 
 that, an
explicit fsync() on a file descriptor for the directory is also
needed.

 So, when creating a new file, it is not sufficient to flush and 
 fsync the
 file descriptor.
 You also need to have opened the containing directory and fsync'ed the
 directory
 file descriptor immediately after creating the file. flushing and 
 sync'ing
 the file
 comes later when you are done with writing to it.

 Cheers,

 JD


 Remember that a directory can only be opened by
DIR *opendir(const char *name);
DIR *fdopendir(int fd);

 Problem is, how can you fsync a dir if you cannot open it
 with the open(2) system call?
 fsync(2) needs a file descriptor.
 DIR *  is not a file descriptor.

 And yet, the man page for fsync says:

Calling  fsync()  does  not  necessarily  ensure  that the 
 entry in the
directory containing the file has  also  reached  disk. For  
 that  an
explicit fsync() on a file descriptor for the directory is also 
 needed.

 Maybe someone can clear this up a bit?


It seems this issue was also discussed in this blog:

http://caml.inria.fr/mantis/view.php?id=2533

--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
ntfs-3g-devel mailing list
ntfs-3g-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel