DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 49P8nhtW311936
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=YOl0GN7U
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7D573858D21
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1729846182;
	bh=NzWQ+lLrH5Y98TBn3gqFRRQx3a4hp1q0TV0hXQHdj3A=;
	h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=YOl0GN7Ud/s4wgnQc0nzjKsGYtn59Fh/IBCr3doyOXxUJAnFKBcpi5q+uHB/qr56y
	 2h3vwovFljTi5AkrXWLsHDItXo71e2at18+OLjZ3C/epHdZDvOKPn732RCzm8hr5LV
	 Ig7ydfp/riy800VP9CWjDmu6GHHHFfoquVz9gJ7w=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59B463858D21
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59B463858D21
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729846135; cv=none;
 b=o1MwgNhP1V9SiWWGfA75ZjfmV12QtrjhtbdLLykBwHFm2A3BtaagwQIYuwO6BJPj01RDSNu04V1WUxPue/qgvJmYBylomsRg46A65kzQdEQePDAeWmTarn+eMAJ3GPZcFadMpqijP1XBAuel5n+kIZzSl9Mzjyy6VnUQs2WKkmI=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1729846135; c=relaxed/simple;
 bh=hamGrik5O9TCrFAiFSRFNLha3PsPBbLu7TZEnGf6ueE=;
 h=Subject:To:From:Message-ID:Date:MIME-Version;
 b=F55PkTExnyb/zmlo/6rC9omgJnen8b5RBJ/vivjzpoCioRaGkHdBN4Ht8QkLl3JYv/Fy7UOOT7YhbdfFefwJL1saLi1bIvn/yY6mUiN/NNEHfp/gUfmwqukOXu+f3B1CrGAFUD6U7humqSi7xdJlHOR5pNbr650ToubAnf5ee3w=
ARC-Authentication-Results: i=1; server2.sourceware.org
Subject: Re: Writing to '\\.\X:' that has no backing PhysicalDrive?
To: cygwin@cygwin.com
References: <a6a5b28d-9d57-4b5d-82b2-b4090e55e1fd@gmail.com>
 <85bb9413-91f0-5776-3f0a-3917e5a153ad@t-online.de>
Message-ID: <e08865af-395a-515d-80e3-2097a9d1cb68@t-online.de>
Date: Fri, 25 Oct 2024 10:48:47 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
 SeaMonkey/2.53.18.2
MIME-Version: 1.0
In-Reply-To: <85bb9413-91f0-5776-3f0a-3917e5a153ad@t-online.de>
X-TOI-EXPURGATEID: 150726::1729846128-1AFFB5E0-B090A3FA/0/0 CLEAN NORMAL
X-TOI-MSGID: 64c5f0fd-ea21-435b-befa-95725890d332
X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, BODY_8BITS,
 FREEMAIL_FROM, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE,
 RCVD_IN_MSPIKE_H2, 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@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Christian Franke via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Christian Franke <Christian.Franke@t-online.de>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 49P8nhtW311936

Christian Franke via Cygwin wrote:
> Ilya Basin via Cygwin wrote:
>> Hi.
>> I was trying to write an .img file to a VeraCrypt drive.
>> VeraCrypt doesn't create a virtual PhysicalDrive so tools like Rufus 
>> don't see it.
>> I hoped that with cygwin I would be able to do that, but Cygwin only 
>> creates /dev/sd?? nodes for PhysicalDrive partitions.
>> I tried `dd` with '\\.\X:', but it can't open for writing because it 
>> treats it as a directory (reading succeeds).
>>
>> $ dd count=1 if='\\.\E:' | xxd
>> 1+0 records in
>> 1+0 records out
>> 512 bytes copied, 0.0213007 s, 24.0 kB/s
>> 00000000: eb52 904e 5446 5320 2020 2000 0208 0000  .R.NTFS .....
>> ...
>>
>> $ dd if=/dev/null count=0 of='\\.\E:'
>> dd: failed to open '\\.\E:': Is a directory
>
> Could reproduce this. The inconsistency between open for reading vs. 
> writing of '\\.\E:' is actually interesting. Subtle bug in Cygwin?
>
>

'\\.\X:' is mapped to NT path '\??\X:' internally. It is (mis-?)detected 
as a directory. Open for write then fails intentionally:

int
fhandler_base::open_fs (int flags, mode_t mode)
{
   /* Unfortunately NT allows to open directories for writing, but that's
      disallowed according to SUSv3. */
   if (pc.isdir () && (flags & O_ACCMODE) != O_RDONLY)
     {
       set_errno (EISDIR);
       return 0;
     }
   ...
}

stat() apparently returns garbage (X: is a mount point of a 1MiB 
VeraCrypt file with FAT FS):

$ stat '\\.\X:'
   File: \\.\X:
   Size: 140720951294304 Blocks: 1          IO Block: 65536  regular file
Device: 0,195   Inode: 264012044753263394  Links: 0
Access: (0644/-rw-r--r--)  Uid: ( 1000/  franke)   Gid: (  513/ none)
Access: 1601-01-01 01:22:04.,'-((0,00 +0053
Modify: 1601-01-01 01:22:04.+0/+'-,00 +0053
Change: 1601-01-01 00:53:29.'''''--00 +0053
  Birth: -

$ ls -l /proc/sys/DosDevices/X:
lr--r--r-- 1 ... /proc/sys/DosDevices/X: -> 
/proc/sys/Device/VeraCryptVolumeX

-- 
Regards,
Christian


-- 
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

