* fsync() cause "Invalid Argument" for block device.
@ 2023-01-21 5:57 Yano Ray
2023-01-21 12:32 ` Takashi Yano
0 siblings, 1 reply; 2+ messages in thread
From: Yano Ray @ 2023-01-21 5:57 UTC (permalink / raw)
To: cygwin
Hi,
I tried to format a partition using mkfs.ext4 (e2fsprogs) but it failed with an error.
$ /usr/sbin/mkfs.ext4 /dev/sde1
mke2fs 1.44.5 (15-Dec-2018)
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: fb09cfbf-9f2a-4874-82f7-26c7cb853093
Superblock backups stored on blocks:
8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: mkfs.ext4: Invalid argument while writing out and closing file system
$
This also seems to happen with mkfs.minix (linux-utils).
$ /sbin/mkfs.minix /dev/sde1
5472 inodes
16384 blocks
Firstdatazone=176 (176)
Zonesize=1024
Maxsize=268966912
mkfs.minix: write failed: Invalid argument
$
I think it's because fsync is not implemented (causes InvalidArgument) for block devices.
Why fsync is not implemented for block devices?
/* test code */
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
int fd;
if (argc != 2) {
puts("./program [file]");
return -1;
}
fd = open(argv[1], O_RDWR);
printf("open: %s\n", strerror(errno));
if (errno) return -1;
fsync(fd);
printf("fsync: %s\n", strerror(errno));
if (errno) return -1;
}
on Cygwin:
$ ./a.exe /dev/sde
open: No error
fsync: Invalid argument
$ ./a.exe /dev/sde1
open: No error
fsync: Invalid argument
$ uname -a
CYGWIN_NT-10.0-22621 DESKTOP-5H6F7L3 3.4.5-1.x86_64 2023-01-19 19:09 UTC x86_64 Cygwin
$
expected behaviour (on Arch Linux):
$ sudo ./a.out /dev/sda
$ sudo ./a.out /dev/sda
open: Success
fsync: Success
$ sudo ./a.out /dev/sda1
open: Success
fsync: Success
$ uname -a
Linux arch 6.0.11-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 02 Dec 2022 17:25:31 +0000 x86_64 GNU/Linux
$
Thanks,
---
Rei Yano <yanorei@hotmail.co.jp>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: fsync() cause "Invalid Argument" for block device.
2023-01-21 5:57 fsync() cause "Invalid Argument" for block device Yano Ray
@ 2023-01-21 12:32 ` Takashi Yano
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Yano @ 2023-01-21 12:32 UTC (permalink / raw)
To: cygwin; +Cc: Yano Ray
On Sat, 21 Jan 2023 05:57:35 +0000
Yano Ray wrote:
> Hi,
> I tried to format a partition using mkfs.ext4 (e2fsprogs) but it failed with an error.
>
> $ /usr/sbin/mkfs.ext4 /dev/sde1
> mke2fs 1.44.5 (15-Dec-2018)
> Creating filesystem with 16384 1k blocks and 4096 inodes
> Filesystem UUID: fb09cfbf-9f2a-4874-82f7-26c7cb853093
> Superblock backups stored on blocks:
> 8193
>
> Allocating group tables: done
> Writing inode tables: done
> Creating journal (1024 blocks): done
> Writing superblocks and filesystem accounting information: mkfs.ext4: Invalid argument while writing out and closing file system
> $
>
> This also seems to happen with mkfs.minix (linux-utils).
>
> $ /sbin/mkfs.minix /dev/sde1
> 5472 inodes
> 16384 blocks
> Firstdatazone=176 (176)
> Zonesize=1024
> Maxsize=268966912
>
> mkfs.minix: write failed: Invalid argument
> $
>
> I think it's because fsync is not implemented (causes InvalidArgument) for block devices.
> Why fsync is not implemented for block devices?
>
> /* test code */
> #include <unistd.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <stdio.h>
> #include <string.h>
>
> int main(int argc, char** argv) {
> int fd;
>
> if (argc != 2) {
> puts("./program [file]");
> return -1;
> }
>
> fd = open(argv[1], O_RDWR);
> printf("open: %s\n", strerror(errno));
> if (errno) return -1;
>
> fsync(fd);
> printf("fsync: %s\n", strerror(errno));
> if (errno) return -1;
> }
>
> on Cygwin:
> $ ./a.exe /dev/sde
> open: No error
> fsync: Invalid argument
> $ ./a.exe /dev/sde1
> open: No error
> fsync: Invalid argument
> $ uname -a
> CYGWIN_NT-10.0-22621 DESKTOP-5H6F7L3 3.4.5-1.x86_64 2023-01-19 19:09 UTC x86_64 Cygwin
> $
>
> expected behaviour (on Arch Linux):
> $ sudo ./a.out /dev/sda
> $ sudo ./a.out /dev/sda
> open: Success
> fsync: Success
> $ sudo ./a.out /dev/sda1
> open: Success
> fsync: Success
> $ uname -a
> Linux arch 6.0.11-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 02 Dec 2022 17:25:31 +0000 x86_64 GNU/Linux
> $
Thanks for the report. I looked into this problem and found
this causes after the commit:
commit af8a7c13b516c77c1e6092157e23ca26db44b1af
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Sat Mar 12 06:19:53 2022 +0900
Cygwin: fsync: Return EINVAL for special files.
- Unlike linux, fsync() calls FlushFileBuffers() even for special
files. This causes the problem reported in:
https://cygwin.com/pipermail/cygwin/2022-March/251022.html
This patch fixes the issue.
I will submit a patch for this issue.
--
Takashi Yano <takashi.yano@nifty.ne.jp>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-21 12:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21 5:57 fsync() cause "Invalid Argument" for block device Yano Ray
2023-01-21 12:32 ` Takashi Yano
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).