Home | History | Annotate | Line # | Download | only in rump_syspuffs
      1  1.14  andvar /*	$NetBSD: rump_syspuffs.c,v 1.14 2023/08/03 20:45:50 andvar Exp $	*/
      2   1.1   pooka 
      3   1.1   pooka /*
      4   1.1   pooka  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
      5   1.1   pooka  *
      6   1.1   pooka  * Development of this software was supported by the
      7   1.1   pooka  * Research Foundation of Helsinki University of Technology
      8   1.1   pooka  *
      9   1.1   pooka  * Redistribution and use in source and binary forms, with or without
     10   1.1   pooka  * modification, are permitted provided that the following conditions
     11   1.1   pooka  * are met:
     12   1.1   pooka  * 1. Redistributions of source code must retain the above copyright
     13   1.1   pooka  *    notice, this list of conditions and the following disclaimer.
     14   1.1   pooka  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1   pooka  *    notice, this list of conditions and the following disclaimer in the
     16   1.1   pooka  *    documentation and/or other materials provided with the distribution.
     17   1.1   pooka  *
     18   1.1   pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19   1.1   pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20   1.1   pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21   1.1   pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22   1.1   pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23   1.1   pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24   1.1   pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25   1.1   pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26   1.1   pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27   1.1   pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28   1.1   pooka  * SUCH DAMAGE.
     29   1.1   pooka  */
     30   1.1   pooka 
     31   1.1   pooka #include <sys/types.h>
     32   1.1   pooka #include <sys/mount.h>
     33   1.1   pooka #include <sys/socket.h>
     34   1.2   pooka #include <sys/syslimits.h>
     35   1.1   pooka 
     36   1.1   pooka #include <assert.h>
     37   1.1   pooka #include <err.h>
     38   1.1   pooka #include <paths.h>
     39   1.1   pooka #include <puffs.h>
     40   1.1   pooka #include <stdio.h>
     41   1.1   pooka #include <stdlib.h>
     42   1.1   pooka #include <unistd.h>
     43   1.1   pooka 
     44   1.4   pooka #include <rump/rump.h>
     45   1.1   pooka 
     46   1.4   pooka #include "rump_syspuffs.h"
     47   1.1   pooka 
     48   1.4   pooka #ifndef MOUNT_NOMAIN
     49   1.4   pooka #include <rump/p2k.h>
     50   1.3   pooka 
     51   1.1   pooka int
     52   1.1   pooka main(int argc, char *argv[])
     53   1.1   pooka {
     54   1.4   pooka 	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
     55   1.4   pooka 	struct syspuffs_args args;
     56   1.4   pooka 	int mntflags, rv;
     57   1.1   pooka 
     58   1.8   pooka #if 0
     59   1.7   pooka 	extern int rumpns_puffsdebug;
     60   1.7   pooka 	extern int rumpns_putterdebug;
     61   1.1   pooka 
     62   1.7   pooka 	rumpns_puffsdebug = rumpns_putterdebug = 1;
     63   1.1   pooka #endif
     64   1.1   pooka 
     65   1.1   pooka 	setprogname(argv[0]);
     66   1.1   pooka 
     67   1.4   pooka 	mount_syspuffs_parseargs(argc, argv, &args, &mntflags,
     68   1.4   pooka 	    canon_dev, canon_dir);
     69   1.4   pooka 
     70   1.4   pooka 	rv = p2k_run_fs(MOUNT_PUFFS, canon_dev, canon_dir, mntflags,
     71   1.4   pooka 		&args.us_kargs, sizeof(args.us_kargs), args.us_pflags);
     72   1.4   pooka 	if (rv)
     73   1.4   pooka 		err(1, "mount");
     74   1.4   pooka 
     75   1.4   pooka 	return 0;
     76   1.4   pooka }
     77   1.4   pooka #endif /* MOUNT_NOMAIN */
     78   1.4   pooka 
     79  1.12   joerg __dead static void
     80   1.4   pooka usage(void)
     81   1.4   pooka {
     82   1.4   pooka 
     83   1.4   pooka 	errx(1, "%s: server server_parameters", getprogname());
     84   1.4   pooka }
     85   1.4   pooka 
     86   1.4   pooka void
     87   1.4   pooka mount_syspuffs_parseargs(int argc, char *argv[],
     88   1.4   pooka 	struct syspuffs_args *args, int *mntflags,
     89   1.4   pooka 	char *canon_dev, char *canon_dir)
     90   1.4   pooka {
     91   1.4   pooka 	struct puffs_kargs *kargs = &args->us_kargs;
     92   1.4   pooka 	int *pflags = &args->us_pflags;
     93   1.4   pooka 	char comfd[16];
     94   1.4   pooka 	int sv[2];
     95   1.4   pooka 	size_t len;
     96   1.4   pooka 	int rv;
     97   1.4   pooka 
     98   1.1   pooka 	if (argc < 2)
     99   1.1   pooka 		usage();
    100   1.1   pooka 
    101  1.14  andvar 	/* Create socketpair for communication with the real file server */
    102   1.1   pooka 	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1)
    103   1.1   pooka 		err(1, "socketpair");
    104   1.3   pooka 
    105   1.5   pooka 	if ((rv = rump_init()) == -1)
    106   1.5   pooka 		err(1, "rump_init");
    107   1.1   pooka 
    108   1.1   pooka 	switch (fork()) {
    109   1.1   pooka 	case 0:
    110   1.4   pooka 		close(sv[1]);
    111   1.3   pooka 		snprintf(comfd, sizeof(sv[0]), "%d", sv[0]);
    112   1.3   pooka 		if (setenv("PUFFS_COMFD", comfd, 1) == -1)
    113   1.3   pooka 			err(1, "setenv");
    114   1.3   pooka 
    115   1.3   pooka 		argv++;
    116  1.13     mrg 		(void)execvp(argv[0], argv);
    117  1.13     mrg 		err(1, "execvp");
    118   1.1   pooka 		/*NOTREACHED*/
    119   1.1   pooka 	case -1:
    120   1.1   pooka 		err(1, "fork");
    121   1.1   pooka 		/*NOTREACHED*/
    122   1.1   pooka 	default:
    123   1.4   pooka 		close(sv[0]);
    124   1.1   pooka 		break;
    125   1.1   pooka 	}
    126   1.1   pooka 
    127   1.1   pooka 	/* read args */
    128   1.1   pooka 	if (read(sv[1], &len, sizeof(len)) != sizeof(len))
    129   1.1   pooka 		err(1, "mp 1");
    130   1.4   pooka 	if (len > MAXPATHLEN)
    131   1.4   pooka 		err(1, "mntpath > MAXPATHLEN");
    132   1.9   pooka 	if ((size_t)read(sv[1], canon_dir, len) != len)
    133   1.1   pooka 		err(1, "mp 2");
    134   1.1   pooka 	if (read(sv[1], &len, sizeof(len)) != sizeof(len))
    135   1.1   pooka 		err(1, "fn 1");
    136   1.4   pooka 	if (len > MAXPATHLEN)
    137   1.4   pooka 		err(1, "devpath > MAXPATHLEN");
    138   1.9   pooka 	if ((size_t)read(sv[1], canon_dev, len) != len)
    139   1.1   pooka 		err(1, "fn 2");
    140   1.4   pooka 	if (read(sv[1], mntflags, sizeof(*mntflags)) != sizeof(*mntflags))
    141   1.1   pooka 		err(1, "mntflags");
    142  1.11   pooka 	if (read(sv[1], kargs, sizeof(len)) != sizeof(len)) /* unused now */
    143  1.11   pooka 		err(1, "unused len");
    144   1.4   pooka 	if (read(sv[1], kargs, sizeof(*kargs)) != sizeof(*kargs))
    145   1.1   pooka 		err(1, "puffs_args");
    146   1.4   pooka 	if (read(sv[1], pflags, sizeof(*pflags)) != sizeof(*pflags))
    147   1.1   pooka 		err(1, "pflags");
    148   1.1   pooka 
    149   1.1   pooka 	/* XXX: some adjustments */
    150   1.4   pooka 	*pflags |= PUFFS_KFLAG_NOCACHE;
    151   1.4   pooka 	*pflags &= ~PUFFS_FLAG_BUILDPATH;
    152   1.1   pooka 
    153  1.10   pooka 	rv = rump_pub_syspuffs_glueinit(sv[1], &kargs->pa_fd);
    154   1.1   pooka 	assert(rv == 0);
    155   1.1   pooka }
    156