For compatibility with rump disk drivers,
we need a way to pass the master device through the `-T typed device:` 
parameter of storeio.
Instead of adding a new field, this patch allows the device field to be of the 
form:

        @/path/to/master:/path/to/device

So for example, with this patch I can call:

        settrans /dev/wd0s2 /hurd/storeio -T typed 
part:2:device:@/dev/rump:/dev/wd0

This allows passing the /dev/rump master device (not the mach kernel one) to 
storeio
and still pass the device /dev/wd0 to open the device within rump.

However without the @ prefix, it still falls back to opening the regular master 
device.
 
Thoughts?

Damien
>From 938ae54389d8ce91b2575199a07c3b8787b0bdbd Mon Sep 17 00:00:00 2001
From: Damien Zammit <dam...@zamaudio.com>
Date: Sat, 9 Nov 2019 18:35:10 +1100
Subject: [PATCH] libstore alternative master device with @ prefix

---
 libstore/device.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/libstore/device.c b/libstore/device.c
index 1d8f57fd..3be6d25d 100644
--- a/libstore/device.c
+++ b/libstore/device.c
@@ -95,15 +95,28 @@ dopen (const char *name, device_t *device, int *mod_flags)
 {
   device_t dev_master;
   error_t err = ENODEV;
+  char *master;
+  char *rest;
+  char *copy;
+  char *pos;
 
-  if (name[0] == '/')
+  if (name[0] == '@')
     {
+      /* Parse @master:/dev/hello */
+      master = strdup (name);
+      copy = strdup (name);
+      pos = strchr (copy, ':');
+      *pos = '\0';
+      sprintf(master, "%s", &copy[1]);
+      rest = strdup (pos+1);
+      free(copy);
+
       if (*mod_flags & STORE_HARD_READONLY)
 	{
-	  dev_master = file_name_lookup (name, O_READ, 0);
+	  dev_master = file_name_lookup (master, O_READ, 0);
 	  if (dev_master != MACH_PORT_NULL)
 	    {
-	      err = device_open (dev_master, D_READ, "disk", device);
+	      err = device_open (dev_master, D_READ, rest, device);
 	      if (err)
 		err = ENODEV;
 
@@ -114,13 +127,13 @@ dopen (const char *name, device_t *device, int *mod_flags)
 	}
       else
 	{
-	  dev_master = file_name_lookup (name, O_READ | O_WRITE, 0);
+	  dev_master = file_name_lookup (master, O_READ | O_WRITE, 0);
 	  if (dev_master != MACH_PORT_NULL)
 	    {
-	      err = device_open (dev_master, D_READ | D_WRITE, "disk", device);
+	      err = device_open (dev_master, D_READ | D_WRITE, rest, device);
 	      if (err == ED_READ_ONLY)
 		{
-		  err = device_open (dev_master, D_READ, "disk", device);
+		  err = device_open (dev_master, D_READ, rest, device);
 		  if (! err)
 		    *mod_flags |= STORE_HARD_READONLY;
 		  else
-- 
2.23.0

Reply via email to