Writing to '\\.\X:' that has no backing PhysicalDrive?

Christian Franke Christian.Franke@t-online.de
Fri Oct 25 08:48:47 GMT 2024


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



More information about the Cygwin mailing list