delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/04/24/10:42:55

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8036389367C
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1587739331;
bh=fT3hiFTiXZzc2giF4RHmitUYHhy1LZwEvL4zUQ57I5w=;
h=Date:From:To:Subject:References:In-Reply-To:List-Id:
List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
Reply-To:Cc:From;
b=WnQTzny8LnmL9IrzYfdT4Cwmc5wL0LvS2QvTEOAtiEQu3GxnxDw1tqBhGo7zRTgt5
5TIP4/+P4eQ5grxfW8Q4TiBiZP/6rufjbajx6khfFU2PEqKm6jul3WOlrR3Qn35Rlo
iIgmQoQycM3jWpqy5YN1zTaV0Ukrm+488mjKERQs=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BABC4386EC42
Authentication-Results: sourceware.org;
dmarc=none (p=none dis=none) header.from=cygwin.com
Authentication-Results: sourceware.org;
spf=fail smtp.mailfrom=corinna-cygwin AT cygwin DOT com
Date: Fri, 24 Apr 2020 16:42:06 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: netbsdrat AT gmail DOT com
Subject: Re: write() on 64 bit platform sometimes returns 32bit -1 as error
indicator
Message-ID: <20200424144206.GF1654005@calimero.vinschen.de>
Mail-Followup-To: netbsdrat AT gmail DOT com, cygwin AT cygwin DOT com
References: <8FBD9FC4F4994493AE1DA1DDBBAFB6B9 AT DAD325>
MIME-Version: 1.0
In-Reply-To: <8FBD9FC4F4994493AE1DA1DDBBAFB6B9@DAD325>
X-Provags-ID: V03:K1:iM/xRsN1Tlp22sHK+8IKEPSWdOt9KDRl3HiBkWUSECN/I13UXlf
8LesyINIQ62R+bizVPl3TtQO4KfDIwLWXxwDAjZXKpZ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puBC5vW7GxvwDmJVrs0QXk/i
X-Spam-Status: No, score=-99.9 required=5.0 tests=BAYES_00, GIT_PATCH_2,
GOOD_FROM_CORINNA_CYGWIN, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS,
RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL,
TXREP autolearn=ham autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: <http://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: <http://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Reply-To: cygwin AT cygwin DOT com
Cc: cygwin AT cygwin DOT com
Errors-To: cygwin-bounces AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>

Hi John,

On Apr 23 12:36, netbsdrat--- via Cygwin wrote:
>  
> write() on 64 bit platform sometimes returns 32bit -1 as error indicator:
>  
> Using 64 bit cygwin on 64 bit platform.  Doing direct read() / write of
> disks,
> this example is using the /dev/floppy device.
>  
> Opening for writing floppy device using open() succeeds.

Thanks for the test cases.

> 2 cases:
>  
> CaseA) write() a 512 byte buffer to the floppy, succeeds with return
> value of 512, errno = 0.  This works.
>  
> CaseB) write() a 5120 byte buffer to the floppy.  This fails if we have
> recently
> formatted the floppy with windows.  Perhaps windows still has some file
> descriptor to the floppy open?

This problem is due to a restriction in Windows introduced with Windows
Vista.  In theory it gets explained at length in "Changes to the file
system and to the storage stack to restrict direct disk access and
direct volume access in Windows Vista and in Windows Server 2008" in the
Help and Support Knowledge Base at http://support.microsoft.com/kb/942448.
Unfortunately, this KB article is current unaccessible for some reason.

Basically, the restriction is that you have to lock all partitions you
want to write to via raw disk access.  So if a write() crosses a
partition boundary, you have to lock both partitions.  Before you ask,
the boot sector on a floppy is a partition on its own, just like, e. g.,
the MBR or the GPT sectors on a hard disk or ssd.

Cygwin has code which performs all necessary locking and it fails if
the locking isn't possible.  However, this code was only called for
disks so far, not for floppies.

> But this is not the point.
>  
> The point is that the return value from the write() is 4294967295
> (0xffffffff).
> This value is a 32 bit -1.  When we compare the return value to -1 (64 bit),
> the compare fails, which indicates that the write succeeded, and implies
> that
> 4294967295 bytes were written.

Got it, there was a wrong cast which lead to the return value -1 being
written as DWORD value, rather than as ssize_t value, as intended.

> [...]
> CaseC) As a third control case to make sure that I was understanding all the
> data
> widths, I tried opening a fake file, and doing the same write to it,
> expecting an error.  The error propagated correctly... the return value
> of writing to a bad file descriptor was 64 bit -1 (0xffffffffffffffff)
> and can be compared to -1 directly to detect the error.  Errno is set
> correctly.

raw writes are performed in another function than file writes, so this
particular problem was restricted to raw disk I/O.

I pushed three patches and uploaded a new developer snapshot to
https://cygwin.com/snapshots/  Please give it a try.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
--
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