delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/01/21/07:34:11

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2CF43858281
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1674304402;
bh=Dz2OHpsooBSCfVUYaCBZEMjfCsKqSqNZcQAnN0DNv24=;
h=Date:To:Cc:Subject:In-Reply-To:References:List-Id:
List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
From:Reply-To:From;
b=BmdUA44gV2MMniUXfTlL7kimdcfsOQtvA7Iy06TCJ4w4qypfFpkijN/hgfjPG5ENV
X2kkxXQcIylpP1naYqF3xUAyLGYlAKA7T4NGqVLrvbNDb8SivdCIsxGOdk5jwo+7gR
XrYhK9RGUNFCgohBRp2EgGekOXgMyU9BazN4Q9rY=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0AFD43858D33
DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-04.nifty.com 30LCWFTb015740
X-Nifty-SrcIP: [220.150.135.41]
Date: Sat, 21 Jan 2023 21:32:15 +0900
To: cygwin AT cygwin DOT com
Cc: Yano Ray <yanorei AT hotmail DOT co DOT jp>
Subject: Re: fsync() cause "Invalid Argument" for block device.
Message-Id: <20230121213215.280c07fee9c8377220db25d4@nifty.ne.jp>
In-Reply-To: <TYAPR01MB63808568168145322E9D9862B8CA9@TYAPR01MB6380.jpnprd01.prod.outlook.com>
References: <TYAPR01MB63808568168145322E9D9862B8CA9 AT TYAPR01MB6380 DOT jpnprd01 DOT prod DOT outlook DOT com>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE,
SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Takashi Yano via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

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 DOT yano AT nifty DOT ne DOT 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 DOT yano AT nifty DOT ne DOT jp>

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019