bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1] /hurd/null: support setting device ID


From: gfleury
Subject: [PATCH 1/1] /hurd/null: support setting device ID
Date: Sat, 18 Jan 2025 13:10:21 +0200

---
 sutils/MAKEDEV.sh |  2 +-
 trans/null.c      | 56 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/sutils/MAKEDEV.sh b/sutils/MAKEDEV.sh
index 7c35fd7..8c67d61 100644
--- a/sutils/MAKEDEV.sh
+++ b/sutils/MAKEDEV.sh
@@ -140,7 +140,7 @@ mkdev() {
        # link for compatibility with Linux.
        cmd ln -f -s random $I;;
       null)
-       st $I root 666 c /hurd/null;;
+       st $I root 666 c /hurd/null --rdev=1,3;;
       full)
        st $I root 666 c /hurd/null --full;;
       zero)
diff --git a/trans/null.c b/trans/null.c
index 19a71eb..9d7e04f 100644
--- a/trans/null.c
+++ b/trans/null.c
@@ -33,6 +33,10 @@
 #include <argp.h>
 #include <nullauth.h>
 
+#include <string.h>
+#include <argz.h>
+#include <sys/sysmacros.h>
+
 #include "libtrivfs/trivfs_fs_S.h"
 #include "libtrivfs/trivfs_io_S.h"
 
@@ -42,8 +46,13 @@ const char *argp_program_version = STANDARD_HURD_VERSION 
(null);
    If zero, they succeed in writing to the bitbucket.  */
 static error_t write_error_code;
 
+static int rdev;
+
 static const struct argp_option options[] =
 {
+  {"rdev",     'n', "ID", 0,
+   "The stat rdev number for this node; may be either a"
+   " single integer, or of the form MAJOR,MINOR"},
   {"full",     'f', 0, 0, "Cause writes to fail as if to a full disk"},
   {0}
 };
@@ -56,8 +65,31 @@ parse_opt (int opt, char *arg, struct argp_state *state)
     case 'f':
       write_error_code = ENOSPC;
       return 0;
+      break;
+    case 'n':
+      {
+       char *start = arg;
+       char *end;
+
+       rdev = strtoul (start, &end, 0);
+       if (*end == ',')
+         /* MAJOR,MINOR form */
+         {
+           start = end + 1;
+           rdev = (rdev << 8) + strtoul (start, &end, 0);
+         }
+
+       if (end == start || *end != '\0')
+         {
+           argp_error (state, "%s: Invalid argument to --rdev", arg);
+           return EINVAL;
+         }
+      }
+      break;
+    default:
+      return ARGP_ERR_UNKNOWN;
     }
-  return ARGP_ERR_UNKNOWN;
+  return 0;
 }
 
 static const struct argp argp =
@@ -107,9 +139,10 @@ int trivfs_allow_open = O_READ | O_WRITE;
 void
 trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
 {
-  st->st_blksize = vm_page_size * 256; /* Make transfers LARRRRRGE */
+  st->st_blksize = vm_page_size;
 
   st->st_size = 0;
+  st->st_rdev = rdev;
   st->st_blocks = 0;
 
   st->st_mode &= ~S_IFMT;
@@ -334,3 +367,22 @@ trivfs_S_io_mod_owner (struct trivfs_protid *cred,
   else
     return EINVAL;
 }
+
+error_t
+trivfs_append_args (struct trivfs_control *fsys,
+                   char **argz, size_t *argz_len)
+{
+  error_t err;
+
+  if (rdev != (dev_t) 0)
+    {
+      char buf[40];
+      snprintf (buf, sizeof (buf), "--rdev=%d,%d",
+               gnu_dev_major (rdev), gnu_dev_minor (rdev));
+      err = argz_add (argz, argz_len, buf);
+      if (err)
+        return err;
+    }
+
+  return 0;
+}
-- 
2.39.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]