[PATCH] Cygwin: Fix access to block devices below /proc/sys.

2020-11-28 Thread Christian Franke
There a very few but occasionally interesting use cases for read access 
to block devices below /proc/sys:


- Read raw images behind drive letters which are not linked to regular 
/dev/sdXN partitions. For example read decrypted images of VeraCrypt 
partitions or container files:

/proc/sys/DosDevices/X: -> /proc/sys/Device/VeraCryptVolumeX

- Read raw images of Volume Shadow Copies:
/proc/sys/Device/HarddiskVolumeShadowCopy*

Copying such an image actually works with 'dd', but 'ddrescue' reports a 
non seekable device. This is because fhandler_virtual::lseek() is used. 
It calls fhandler_procsys::fill_filebuf() which does not make any sense 
in this context. This lseek() always fails - without setting errno, BTW.


The attached experimental patch does not fix the lseek() (sorry), but 
handles such block devices with fhandler_dev_floppy instead. Tested with 
above use cases.


I'm not sure whether this could break access to other /proc/sys block 
devices. This would happen if fh->exists() returns virt_blk for devices 
which do not support IOCTL_DISK_GET_DRIVE_GEOMETRY* or 
IOCTL_DISK_GET_PARTITION_INFO*.


Regards,
Christian

From ed8f419524fc81a378280579ec3c23af527d4772 Mon Sep 17 00:00:00 2001
From: Christian Franke 
Date: Sat, 28 Nov 2020 22:09:23 +0100
Subject: [PATCH] Cygwin: Fix access to block devices below /proc/sys.

Use fhandler_dev_floppy instead of fhandler_procsys for such devices.
The read()/write() functions from fhandler_procsys do not ensure
sector aligned transfers and lseek() fails always.

Signed-off-by: Christian Franke 
---
 winsup/cygwin/path.cc | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 4f5f03a76..7e6243d32 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -863,19 +863,28 @@ path_conv::check (const char *src, unsigned opt,
dev.parse (FH_FS);
goto is_fs_via_procsys;
  case virt_blk:
-   /* Block special device.  If the trailing slash has been
-  requested, the target is the root directory of the
-  filesystem on this block device.  So we convert this
-  to a real file and attach the backslash. */
-   if (component == 0 && need_directory)
+   /* Block special device.  Convert to a /dev/sd* like
+  block device unless the trailing slash has been
+  requested.  In this case, the target is the root
+  directory of the filesystem on this block device.
+  So we convert this to a real file and attach the
+  backslash. */
+   if (component == 0)
  {
-   dev.parse (FH_FS);
-   strcat (full_path, "\\");
-   fileattr = FILE_ATTRIBUTE_DIRECTORY
-  | FILE_ATTRIBUTE_DEVICE;
+   fileattr = FILE_ATTRIBUTE_DEVICE;
+   if (!need_directory)
+ /* Use a /dev/sd* device number > /dev/sddx.
+FIXME: Define a new major DEV_ice number. */
+ dev.parse (DEV_SD_HIGHPART_END, );
+   else
+ {
+   dev.parse (FH_FS);
+   strcat (full_path, "\\");
+   fileattr |= FILE_ATTRIBUTE_DIRECTORY;
+ }
goto out;
  }
-   fallthrough;
+   break;
  case virt_chr:
if (component == 0)
  fileattr = FILE_ATTRIBUTE_DEVICE;
-- 
2.29.2



Re: [PATCH] Cygwin: Speed up mkimport

2020-11-28 Thread Achim Gratz
Achim Gratz writes:
> That actually works, but the speedup is quite modest on my system
> (4C/8T) even though I've allowed it to use unlimited resources.  So it
> basically forks slower than the runtime for each of the invocations is.
> Some more speedup can be had if the assembler is run on actual files in
> the same way, but the best I've come up with goes from 93s to 47s and
> runs at 150% CPU (up from 85%).  Most of that time is spent in system,
> so forking and I/O.

Not that I really know what I'm doing, but creating a single .s file and
running as just once gets mkimport down to 21s / 110%.  Now the
resulting library doesn't actually link, because somehow the information
ends up in the wrong place…


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Terratec KOMPLEXER:
http://Synth.Stromeko.net/Downloads.html#KomplexerWaves


Re: [PATCH] Cygwin: Speed up mkimport

2020-11-28 Thread Achim Gratz
Achim Gratz writes:
> b) Open up two pipes to an "xargs -P $ncpu/2 L 1 …" and feed in the file
> names.

That actually works, but the speedup is quite modest on my system
(4C/8T) even though I've allowed it to use unlimited resources.  So it
basically forks slower than the runtime for each of the invocations is.
Some more speedup can be had if the assembler is run on actual files in
the same way, but the best I've come up with goes from 93s to 47s and
runs at 150% CPU (up from 85%).  Most of that time is spent in system,
so forking and I/O.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds