Hello, Zhaoming Luo, le sam. 22 févr. 2025 14:27:07 +0800, a ecrit: > This is not completed, but I would to confirm whether I have > understanded the code.
Yes, this is the idea. > Then we use 'machdev_trivfs_init ()' to init it so ext2fs can use > device_open('hd0s1'); the following stuff it is required to initialize > the machdev trivfs. The port will also need to implement the device RPCs: device_read/write/set/get_status. read/write would probably be pluggable almost directly to dev_read/write. Samuel > --- > libstore/Makefile | 2 +- > libstore/store.h | 9 ++++ > storeio/storeio.c | 110 ++++++++++++++++++++++++++++++++++++++++------ > 3 files changed, 107 insertions(+), 14 deletions(-) > > diff --git a/libstore/Makefile b/libstore/Makefile > index 10def3ce..1f7be1bf 100644 > --- a/libstore/Makefile > +++ b/libstore/Makefile > @@ -60,7 +60,7 @@ ifeq ($(USE_PARTED), 1) > endif > installhdrs=store.h > > -HURDLIBS = shouldbeinlibc > +HURDLIBS = shouldbeinlibc machdev > LDLIBS += -lpthread $(and $(HAVE_LIBBZ2),-lbz2) $(and $(HAVE_LIBZ),-lz) > GUNZIP_OBJS = do-gunzip.o util.o > BUNZIP2_OBJS = do-bunzip2.o > diff --git a/libstore/store.h b/libstore/store.h > index f4697460..d9aaf969 100644 > --- a/libstore/store.h > +++ b/libstore/store.h > @@ -774,6 +774,15 @@ struct store_argp_params > If zero, the parser fails with the error message "No store specified". > If nonzero, the parser succeeds and sets `result' to null. */ > int store_optional; > + > + /* Next bootstrap task */ > + mach_port_t next_task; > + > + /* Host privileged port */ > + mach_port_t host_priv_port; > + > + /* Device master port */ > + mach_port_t dev_master_port; > }; > > /* The result of parsing a store, which should be enough information to open > diff --git a/storeio/storeio.c b/storeio/storeio.c > index 4e8a9628..a3be3a51 100644 > --- a/storeio/storeio.c > +++ b/storeio/storeio.c > @@ -29,11 +29,13 @@ > #include <hurd.h> > #include <hurd/ports.h> > #include <hurd/trivfs.h> > +#include <hurd/fsys.h> > #include <version.h> > > #include "open.h" > #include "dev.h" > #include "libtrivfs/trivfs_fsys_S.h" > +#include "libmachdev/machdev.h" > > static struct argp_option options[] = > { > @@ -48,6 +50,9 @@ static 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"}, > + {"next-task", 'N', "TASK", 0, "Next bootstrap task"}, > + {"host-priv-port", 'H', "PORT", 0, "Port for bootstrapping host"}, > + {"device-master-port", 'P', "PORT", 0, "Port for bootstrapping device > master"}, > {0} > }; > static const char doc[] = "Translator for devices and other stores"; > @@ -57,6 +62,10 @@ const char *argp_program_version = STANDARD_HURD_VERSION > (storeio); > static bool debug=false; > static char *debug_fname=NULL; > > +struct store *bootstrap_part_store; > +mach_port_t bootstrap_resume_task = MACH_PORT_NULL; > +static mach_port_t store_control_port; > + > /* Desired store parameters specified by the user. */ > struct storeio_argp_params > { > @@ -80,6 +89,10 @@ parse_opt (int key, char *arg, struct argp_state *state) > case 'e': params->dev->enforced = 1; break; > case 'F': params->dev->no_fileio = 1; break; > > + case 'N': params->store_params.next_task = atoi (arg); break; > + case 'H': params->store_params.host_priv_port = atoi (arg); break; > + case 'P': params->store_params.dev_master_port = atoi (arg); break; > + > case 'n': > { > char *start = arg, *end; > @@ -119,11 +132,17 @@ parse_opt (int key, char *arg, struct argp_state *state) > memset (¶ms->store_params, 0, sizeof params->store_params); > params->store_params.default_type = "device"; > params->store_params.store_optional = 1; > + params->store_params.next_task = MACH_PORT_NULL; > + params->store_params.host_priv_port = MACH_PORT_NULL; > + params->store_params.dev_master_port = MACH_PORT_NULL; > state->child_inputs[0] = ¶ms->store_params; > break; > > case ARGP_KEY_SUCCESS: > params->dev->store_name = params->store_params.result; > + bootstrap_resume_task = params->store_params.next_task; > + _hurd_host_priv = params->store_params.host_priv_port; > + _hurd_device_master = params->store_params.dev_master_port; > break; > > default: > @@ -137,6 +156,37 @@ static const struct argp argp = { options, parse_opt, 0, > doc, argp_kids }; > > struct trivfs_control *storeio_fsys; > > +static io_return_t > +store_part_device_open (mach_port_t reply_port, mach_msg_type_name_t > reply_port_type, > + dev_mode_t mode, const char *name, device_t * devp, > + mach_msg_type_name_t * devicePoly) > +{ > + *devp = bootstrap_part_store->port; > + *devicePoly = MACH_MSG_TYPE_COPY_SEND; > + return D_SUCCESS; > +} > + > +static struct machdev_device_emulation_ops store_part_emulation_ops = { > + NULL, > + NULL, > + NULL, > + NULL, > + store_part_device_open, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > + NULL, > +}; > + > int > main (int argc, char *argv[]) > { > @@ -144,6 +194,9 @@ main (int argc, char *argv[]) > mach_port_t bootstrap; > struct dev device; > struct storeio_argp_params params; > + pthread_t t; > + device_t disk_device; > + struct store *bootstrap_disk_store; > > memset (&device, 0, sizeof device); > pthread_mutex_init (&device.lock, NULL); > @@ -151,24 +204,55 @@ main (int argc, char *argv[]) > params.dev = &device; > argp_parse (&argp, argc, argv, 0, 0, ¶ms); > > - if (debug) > + if (bootstrap_resume_task != MACH_PORT_NULL) > { > - if (!debug_fname) > - error (3, EINVAL, "missing translated node"); > - err = trivfs_startup_debug (debug_fname, 0, 0, 0, 0, &storeio_fsys); > + /* We are a bootstrap process */ > + > + machdev_register (&store_part_emulation_ops); > + task_get_bootstrap_port (mach_task_self (), &bootstrap); > + device_open (bootstrap, D_READ, "hd0", &disk_device); > + err = store_device_create (disk_device, STORE_READONLY, > &bootstrap_disk_store); > + err = store_part_create (bootstrap_disk_store, 1, 0, > &bootstrap_part_store); > + machdev_trivfs_init (argc, argv, bootstrap_resume_task, "hd0s1", NULL, > &bootstrap); > + > +// /* Make sure we will not swap out, in case we drive the partition for > +// swapping */ > +// err = wire_task_self (); > +// if (err) > +// error (1, errno, "cannot lock all memory"); > + > + machdev_device_init (); > + err = pthread_create (&t, NULL, machdev_server, NULL); > if (err) > - error (3, err, "trivfs_startup_debug failed"); > + error (1, err, "Creating machdev_server thread"); > + pthread_detach (t); > + > + machdev_trivfs_server_startup (bootstrap); > + machdev_trivfs_server_loop (NULL); > + /* Never reached */ > + return 0; > } > else > { > - task_get_bootstrap_port (mach_task_self (), &bootstrap); > - if (bootstrap == MACH_PORT_NULL) > - error (2, 0, "Must be started as a translator"); > - > - /* Reply to our parent */ > - err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &storeio_fsys); > - if (err) > - error (3, err, "trivfs_startup"); > + if (debug) > + { > + if (!debug_fname) > + error (3, EINVAL, "missing translated node"); > + err = trivfs_startup_debug (debug_fname, 0, 0, 0, 0, > &storeio_fsys); > + if (err) > + error (3, err, "trivfs_startup_debug failed"); > + } > + else > + { > + task_get_bootstrap_port (mach_task_self (), &bootstrap); > + if (bootstrap == MACH_PORT_NULL) > + error (2, 0, "Must be started as a translator"); > + > + /* Reply to our parent */ > + err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &storeio_fsys); > + if (err) > + error (3, err, "trivfs_startup"); > + } > } > > storeio_fsys->hook = &device; > -- > 2.47.2 > > -- Samuel #ifndef I_WISH_WORLD_WERE_PERFECT /* It is not :-( All the routers (except for Linux) return only ... -+- linux/net/ipv4/ipip.c -+-