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