* fsync bug
@ 2011-09-22 14:33 Eric Blake
2011-09-22 14:49 ` Christopher Faylor
0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2011-09-22 14:33 UTC (permalink / raw)
To: cygwin
fsync() is required to work on read-only fds (in theory, you can sync
the atime metadata, which is a write operation triggered by a read-only
fd). But cygwin rejects this program, which works on Linux:
$ cat foo.c
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
int main (void)
{
int fd = open("file", O_CREAT|O_EXCL|O_WRONLY, 0600);
if (fd < 0)
return 1;
if (close(fd))
return 2;
fd = open("file", O_RDONLY);
if (fd < 0)
return 3;
if (fsync(fd))
return 4;
if (unlink("file"))
return 5;
puts("success");
return 0;
}
$ rm -f file && ./foo; echo $?
4
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fsync bug
2011-09-22 14:33 fsync bug Eric Blake
@ 2011-09-22 14:49 ` Christopher Faylor
2011-09-22 14:57 ` Eric Blake
0 siblings, 1 reply; 4+ messages in thread
From: Christopher Faylor @ 2011-09-22 14:49 UTC (permalink / raw)
To: cygwin
On Wed, Sep 21, 2011 at 02:43:21PM -0600, Eric Blake wrote:
>fsync() is required to work on read-only fds (in theory, you can sync
>the atime metadata, which is a write operation triggered by a read-only
>fd). But cygwin rejects this program, which works on Linux:
>
>$ cat foo.c
>#include <errno.h>
>#include <unistd.h>
>#include <stdio.h>
>#include <stdlib.h>
>#include <assert.h>
>#include <fcntl.h>
>int main (void)
>{
> int fd = open("file", O_CREAT|O_EXCL|O_WRONLY, 0600);
> if (fd < 0)
> return 1;
> if (close(fd))
> return 2;
> fd = open("file", O_RDONLY);
> if (fd < 0)
> return 3;
> if (fsync(fd))
> return 4;
> if (unlink("file"))
> return 5;
> puts("success");
> return 0;
>}
>$ rm -f file && ./foo; echo $?
>4
http://msdn.microsoft.com/en-us/library/aa364439%28VS.85%29.aspx
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fsync bug
2011-09-22 14:49 ` Christopher Faylor
@ 2011-09-22 14:57 ` Eric Blake
2011-09-22 14:58 ` Christopher Faylor
0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2011-09-22 14:57 UTC (permalink / raw)
To: cygwin
On 09/21/2011 02:54 PM, Christopher Faylor wrote:
> On Wed, Sep 21, 2011 at 02:43:21PM -0600, Eric Blake wrote:
>> fsync() is required to work on read-only fds (in theory, you can sync
>> the atime metadata, which is a write operation triggered by a read-only
>> fd). But cygwin rejects this program, which works on Linux:
>>
>> $ cat foo.c
>> #include<errno.h>
>> #include<unistd.h>
>> #include<stdio.h>
>> #include<stdlib.h>
>> #include<assert.h>
>> #include<fcntl.h>
>> int main (void)
>> {
>> int fd = open("file", O_CREAT|O_EXCL|O_WRONLY, 0600);
>> if (fd< 0)
>> return 1;
>> if (close(fd))
>> return 2;
>> fd = open("file", O_RDONLY);
>> if (fd< 0)
>> return 3;
>> if (fsync(fd))
>> return 4;
>> if (unlink("file"))
>> return 5;
>> puts("success");
>> return 0;
>> }
>> $ rm -f file&& ./foo; echo $?
>> 4
>
> http://msdn.microsoft.com/en-us/library/aa364439%28VS.85%29.aspx
So what's wrong with making fsync() a no-op for read-only fds, on the
grounds that windows doesn't give us a way to flush that data, so the
best emulation we can do is by ignoring the request rather than
propagating a spurious failure back to the user?
Also, FlushFileBuffers sounds more like fdatasync(); I'm wondering if
fsync() should also be flushing the containing directory of any given
file, in case file metadata (such as timestamps or changes in size via
truncate) still need to be flushed to disk by flushing the directory.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fsync bug
2011-09-22 14:57 ` Eric Blake
@ 2011-09-22 14:58 ` Christopher Faylor
0 siblings, 0 replies; 4+ messages in thread
From: Christopher Faylor @ 2011-09-22 14:58 UTC (permalink / raw)
To: cygwin
On Wed, Sep 21, 2011 at 03:07:21PM -0600, Eric Blake wrote:
>On 09/21/2011 02:54 PM, Christopher Faylor wrote:
>> On Wed, Sep 21, 2011 at 02:43:21PM -0600, Eric Blake wrote:
>>> fsync() is required to work on read-only fds (in theory, you can sync
>>> the atime metadata, which is a write operation triggered by a read-only
>>> fd). But cygwin rejects this program, which works on Linux:
>>>
>>> $ cat foo.c
>>> #include<errno.h>
>>> #include<unistd.h>
>>> #include<stdio.h>
>>> #include<stdlib.h>
>>> #include<assert.h>
>>> #include<fcntl.h>
>>> int main (void)
>>> {
>>> int fd = open("file", O_CREAT|O_EXCL|O_WRONLY, 0600);
>>> if (fd< 0)
>>> return 1;
>>> if (close(fd))
>>> return 2;
>>> fd = open("file", O_RDONLY);
>>> if (fd< 0)
>>> return 3;
>>> if (fsync(fd))
>>> return 4;
>>> if (unlink("file"))
>>> return 5;
>>> puts("success");
>>> return 0;
>>> }
>>> $ rm -f file&& ./foo; echo $?
>>> 4
>>
>> http://msdn.microsoft.com/en-us/library/aa364439%28VS.85%29.aspx
>
>So what's wrong with making fsync() a no-op for read-only fds, on the
>grounds that windows doesn't give us a way to flush that data, so the
>best emulation we can do is by ignoring the request rather than
>propagating a spurious failure back to the user?
It's hard to see how lying that fsync worked would satisfy the
requirements to write metadata. But, then, it isn't clear that this is
even an issue on Windows.
But, in any event, you know where the source code is.
cgf
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-09-22 5:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 14:33 fsync bug Eric Blake
2011-09-22 14:49 ` Christopher Faylor
2011-09-22 14:57 ` Eric Blake
2011-09-22 14:58 ` Christopher Faylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).