2013-12-06 12:04:52 +01:00
|
|
|
/* $NetBSD: puffs.c,v 1.117 2011/11/14 01:27:42 chs Exp $ */
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Development of this software was supported by the
|
|
|
|
* Google Summer of Code program and the Ulla Tuominen Foundation.
|
|
|
|
* The Google SoC project was mentored by Bill Studenmund.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if !defined(lint)
|
2013-12-06 12:04:52 +01:00
|
|
|
__RCSID("$NetBSD: puffs.c,v 1.117 2011/11/14 01:27:42 chs Exp $");
|
2011-11-14 12:53:05 +01:00
|
|
|
#endif /* !lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
#if defined(__minix)
|
|
|
|
#include "fs.h"
|
|
|
|
#endif /* defined(__minix) */
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2013-12-06 12:04:52 +01:00
|
|
|
#include <mntopts.h>
|
2011-11-14 12:53:05 +01:00
|
|
|
#include <paths.h>
|
2013-12-06 12:04:52 +01:00
|
|
|
#include <puffs.h>
|
2011-11-14 12:53:05 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "puffs_priv.h"
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
/* Most file systems want this for opts, so just give it to them */
|
|
|
|
const struct mntopt puffsmopts[] = {
|
|
|
|
MOPT_STDOPTS,
|
|
|
|
PUFFSMOPT_STD,
|
|
|
|
MOPT_NULL,
|
|
|
|
};
|
2011-11-14 12:53:05 +01:00
|
|
|
#ifdef PUFFS_WITH_THREADS
|
|
|
|
#include <pthread.h>
|
|
|
|
pthread_mutex_t pu_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
#if defined(__minix)
|
|
|
|
static message fs_msg;
|
|
|
|
static int fs_ipc_status;
|
|
|
|
#endif
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* Declare some local functions. */
|
2014-08-24 11:51:35 +02:00
|
|
|
static int get_work(message *msg, int *ipc_status);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* SEF functions and variables. */
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sef_local_startup(void);
|
|
|
|
static int sef_cb_init_fresh(int type, sef_init_info_t *info);
|
|
|
|
static void sef_cb_signal_handler(int signo);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
EXTERN int env_argc;
|
|
|
|
EXTERN char **env_argv;
|
|
|
|
|
|
|
|
|
|
|
|
#define PUFFS_MAX_ARGS 20
|
|
|
|
|
|
|
|
int __real_main(int argc, char* argv[]);
|
2012-12-11 18:42:21 +01:00
|
|
|
int __wrap_main(int argc, char* argv[]);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
int __wrap_main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int new_argc = 0;
|
|
|
|
static char* new_argv[PUFFS_MAX_ARGS];
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
/* SEF local startup. */
|
|
|
|
env_setargs(argc, argv);
|
|
|
|
sef_local_startup();
|
|
|
|
|
|
|
|
global_kcred.pkcr_type = PUFFCRED_TYPE_INTERNAL;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
panic("Unexpected arguments, use:\
|
|
|
|
mount -t fs /dev/ /dir [-o option1,option2]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
name = argv[0] + strlen(argv[0]);
|
|
|
|
while (*name != '/' && name != argv[0])
|
|
|
|
name--;
|
|
|
|
if (name != argv[0])
|
|
|
|
name++;
|
|
|
|
strcpy(fs_name, name);
|
|
|
|
|
|
|
|
new_argv[new_argc] = argv[0];
|
|
|
|
new_argc++;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (new_argc >= PUFFS_MAX_ARGS) {
|
|
|
|
panic("Too many arguments, change PUFFS_MAX_ARGS");
|
|
|
|
}
|
|
|
|
new_argv[new_argc] = argv[i];
|
|
|
|
new_argc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(new_argc > 0);
|
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
/* Get the mount request from VFS, so we can deal with it later. */
|
|
|
|
(void)get_work(&fs_msg, &fs_ipc_status);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
return __real_main(new_argc, new_argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define FILLOP(lower, upper) \
|
|
|
|
do { \
|
|
|
|
if (pops->puffs_node_##lower) \
|
|
|
|
opmask[PUFFS_VN_##upper] = 1; \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
static void
|
2013-12-06 12:04:52 +01:00
|
|
|
fillvnopmask(struct puffs_ops *pops, struct puffs_kargs *pa)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
2013-12-06 12:04:52 +01:00
|
|
|
uint8_t *opmask = pa->pa_vnopmask;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
memset(opmask, 0, sizeof(pa->pa_vnopmask));
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
FILLOP(create, CREATE);
|
|
|
|
FILLOP(mknod, MKNOD);
|
|
|
|
FILLOP(open, OPEN);
|
|
|
|
FILLOP(close, CLOSE);
|
|
|
|
FILLOP(access, ACCESS);
|
|
|
|
FILLOP(getattr, GETATTR);
|
|
|
|
FILLOP(setattr, SETATTR);
|
2013-12-06 12:04:52 +01:00
|
|
|
FILLOP(poll, POLL);
|
2011-11-14 12:53:05 +01:00
|
|
|
FILLOP(mmap, MMAP);
|
|
|
|
FILLOP(fsync, FSYNC);
|
|
|
|
FILLOP(seek, SEEK);
|
|
|
|
FILLOP(remove, REMOVE);
|
|
|
|
FILLOP(link, LINK);
|
|
|
|
FILLOP(rename, RENAME);
|
|
|
|
FILLOP(mkdir, MKDIR);
|
|
|
|
FILLOP(rmdir, RMDIR);
|
|
|
|
FILLOP(symlink, SYMLINK);
|
|
|
|
FILLOP(readdir, READDIR);
|
|
|
|
FILLOP(readlink, READLINK);
|
|
|
|
FILLOP(reclaim, RECLAIM);
|
|
|
|
FILLOP(inactive, INACTIVE);
|
|
|
|
FILLOP(print, PRINT);
|
|
|
|
FILLOP(read, READ);
|
|
|
|
FILLOP(write, WRITE);
|
|
|
|
FILLOP(abortop, ABORTOP);
|
|
|
|
}
|
|
|
|
#undef FILLOP
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2013-08-31 22:59:44 +02:00
|
|
|
__dead static void
|
2011-11-14 12:53:05 +01:00
|
|
|
puffs_defaulterror(struct puffs_usermount *pu, uint8_t type,
|
|
|
|
int error, const char *str, puffs_cookie_t cookie)
|
|
|
|
{
|
|
|
|
|
|
|
|
lpuffs_debug("abort: type %d, error %d, cookie %p (%s)\n",
|
|
|
|
type, error, cookie, str);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
puffs_getstate(struct puffs_usermount *pu)
|
|
|
|
{
|
|
|
|
|
|
|
|
return pu->pu_state & PU_STATEMASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setstacksize(struct puffs_usermount *pu, size_t ss)
|
|
|
|
{
|
2013-12-06 12:04:52 +01:00
|
|
|
long psize, minsize;
|
2011-11-14 12:53:05 +01:00
|
|
|
int stackshift;
|
|
|
|
int bonus;
|
|
|
|
|
|
|
|
assert(puffs_getstate(pu) == PUFFS_STATE_BEFOREMOUNT);
|
|
|
|
|
|
|
|
psize = sysconf(_SC_PAGESIZE);
|
|
|
|
minsize = 4*psize;
|
2013-12-06 12:04:52 +01:00
|
|
|
if (ss < (size_t)minsize || ss == PUFFS_STACKSIZE_MIN) {
|
2011-11-14 12:53:05 +01:00
|
|
|
if (ss != PUFFS_STACKSIZE_MIN)
|
|
|
|
lpuffs_debug("puffs_setstacksize: adjusting "
|
|
|
|
"stacksize to minimum %ld\n", minsize);
|
|
|
|
ss = 4*psize;
|
|
|
|
}
|
|
|
|
|
|
|
|
stackshift = -1;
|
|
|
|
bonus = 0;
|
|
|
|
while (ss) {
|
|
|
|
if (ss & 0x1)
|
|
|
|
bonus++;
|
|
|
|
ss >>= 1;
|
|
|
|
stackshift++;
|
|
|
|
}
|
|
|
|
if (bonus > 1) {
|
|
|
|
stackshift++;
|
|
|
|
lpuffs_debug("puffs_setstacksize: using next power of two: "
|
|
|
|
"%d\n", 1<<stackshift);
|
|
|
|
}
|
|
|
|
|
|
|
|
pu->pu_cc_stackshift = stackshift;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct puffs_pathobj *
|
|
|
|
puffs_getrootpathobj(struct puffs_usermount *pu)
|
|
|
|
{
|
|
|
|
struct puffs_node *pnr;
|
|
|
|
|
|
|
|
pnr = pu->pu_pn_root;
|
|
|
|
if (pnr == NULL) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pnr->pn_po;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setroot(struct puffs_usermount *pu, struct puffs_node *pn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_pn_root = pn;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct puffs_node *
|
|
|
|
puffs_getroot(struct puffs_usermount *pu)
|
|
|
|
{
|
|
|
|
|
|
|
|
return pu->pu_pn_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setrootinfo(struct puffs_usermount *pu, enum vtype vt,
|
|
|
|
vsize_t vsize, dev_t rdev)
|
|
|
|
{
|
|
|
|
struct puffs_kargs *pargs = pu->pu_kargp;
|
|
|
|
|
|
|
|
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT) {
|
|
|
|
warnx("puffs_setrootinfo: call has effect only "
|
|
|
|
"before mount\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pargs->pa_root_vtype = vt;
|
|
|
|
pargs->pa_root_vsize = vsize;
|
|
|
|
pargs->pa_root_rdev = rdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
puffs_getspecific(struct puffs_usermount *pu)
|
|
|
|
{
|
|
|
|
|
|
|
|
return pu->pu_privdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setspecific(struct puffs_usermount *pu, void *privdata)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_privdata = privdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setmntinfo(struct puffs_usermount *pu,
|
|
|
|
const char *mntfromname, const char *puffsname)
|
|
|
|
{
|
|
|
|
struct puffs_kargs *pargs = pu->pu_kargp;
|
|
|
|
|
|
|
|
(void)strlcpy(pargs->pa_mntfromname, mntfromname,
|
|
|
|
sizeof(pargs->pa_mntfromname));
|
|
|
|
(void)strlcpy(pargs->pa_typename, puffsname,
|
|
|
|
sizeof(pargs->pa_typename));
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
puffs_getmaxreqlen(struct puffs_usermount *pu)
|
|
|
|
{
|
|
|
|
|
|
|
|
return pu->pu_maxreqlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setmaxreqlen(struct puffs_usermount *pu, size_t reqlen)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT)
|
|
|
|
warnx("puffs_setmaxreqlen: call has effect only "
|
|
|
|
"before mount\n");
|
|
|
|
|
|
|
|
pu->pu_kargp->pa_maxmsglen = reqlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setfhsize(struct puffs_usermount *pu, size_t fhsize, int flags)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT)
|
|
|
|
warnx("puffs_setfhsize: call has effect only before mount\n");
|
|
|
|
|
|
|
|
pu->pu_kargp->pa_fhsize = fhsize;
|
|
|
|
pu->pu_kargp->pa_fhflags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_setncookiehash(struct puffs_usermount *pu, int nhash)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT)
|
|
|
|
warnx("puffs_setfhsize: call has effect only before mount\n");
|
|
|
|
|
|
|
|
pu->pu_kargp->pa_nhashbuckets = nhash;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_pathbuild(struct puffs_usermount *pu, pu_pathbuild_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_pathbuild = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_pathtransform(struct puffs_usermount *pu, pu_pathtransform_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_pathtransform = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_pathcmp(struct puffs_usermount *pu, pu_pathcmp_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_pathcmp = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_pathfree(struct puffs_usermount *pu, pu_pathfree_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_pathfree = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_namemod(struct puffs_usermount *pu, pu_namemod_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_namemod = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_errnotify(struct puffs_usermount *pu, pu_errnotify_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_errnotify = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_cmap(struct puffs_usermount *pu, pu_cmap_fn fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_cmap = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_ml_setloopfn(struct puffs_usermount *pu, puffs_ml_loop_fn lfn)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_ml_lfn = lfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_ml_settimeout(struct puffs_usermount *pu, struct timespec *ts)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ts == NULL) {
|
|
|
|
pu->pu_ml_timep = NULL;
|
|
|
|
} else {
|
|
|
|
pu->pu_ml_timeout = *ts;
|
|
|
|
pu->pu_ml_timep = &pu->pu_ml_timeout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_set_prepost(struct puffs_usermount *pu,
|
|
|
|
pu_prepost_fn pre, pu_prepost_fn pst)
|
|
|
|
{
|
|
|
|
|
|
|
|
pu->pu_oppre = pre;
|
|
|
|
pu->pu_oppost = pst;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
puffs_mount(struct puffs_usermount *pu, const char *dir, int mntflags,
|
|
|
|
puffs_cookie_t cookie)
|
|
|
|
{
|
2013-12-06 12:04:52 +01:00
|
|
|
#if defined(__minix)
|
|
|
|
pu->pu_kargp->pa_root_cookie = cookie;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
/* Process the already-received mount request. */
|
|
|
|
fsdriver_process(&puffs_table, &fs_msg, fs_ipc_status, FALSE);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
if (!mounted) {
|
|
|
|
/* This should never happen, unless VFS misbehaves.. */
|
2013-12-06 12:04:52 +01:00
|
|
|
free(pu->pu_kargp);
|
|
|
|
pu->pu_kargp = NULL;
|
2014-08-24 11:51:35 +02:00
|
|
|
errno = -EINVAL;
|
2013-12-06 12:04:52 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
PU_SETSTATE(pu, PUFFS_STATE_RUNNING);
|
|
|
|
return 0;
|
|
|
|
#endif /* defined(__minix) */
|
2011-11-14 12:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
struct puffs_usermount *
|
2014-08-24 11:51:35 +02:00
|
|
|
puffs_init(struct puffs_ops *pops, const char *mntfromname,
|
2011-11-14 12:53:05 +01:00
|
|
|
const char *puffsname, void *priv, uint32_t pflags)
|
|
|
|
{
|
|
|
|
struct puffs_usermount *pu;
|
|
|
|
struct puffs_kargs *pargs;
|
|
|
|
int sverrno;
|
|
|
|
|
|
|
|
if (puffsname == PUFFS_DEFER)
|
|
|
|
puffsname = "n/a";
|
|
|
|
if (mntfromname == PUFFS_DEFER)
|
|
|
|
mntfromname = "n/a";
|
|
|
|
if (priv == PUFFS_DEFER)
|
|
|
|
priv = NULL;
|
|
|
|
|
|
|
|
pu = malloc(sizeof(struct puffs_usermount));
|
|
|
|
if (pu == NULL)
|
|
|
|
goto failfree;
|
|
|
|
memset(pu, 0, sizeof(struct puffs_usermount));
|
|
|
|
|
|
|
|
pargs = pu->pu_kargp = malloc(sizeof(struct puffs_kargs));
|
|
|
|
if (pargs == NULL)
|
|
|
|
goto failfree;
|
|
|
|
memset(pargs, 0, sizeof(struct puffs_kargs));
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
pargs->pa_vers = PUFFSVERSION;
|
2011-11-14 12:53:05 +01:00
|
|
|
pargs->pa_flags = PUFFS_FLAG_KERN(pflags);
|
2014-08-24 11:51:35 +02:00
|
|
|
fillvnopmask(pops, pargs);
|
2011-11-14 12:53:05 +01:00
|
|
|
puffs_setmntinfo(pu, mntfromname, puffsname);
|
|
|
|
|
|
|
|
puffs_zerostatvfs(&pargs->pa_svfsb);
|
|
|
|
pargs->pa_root_cookie = NULL;
|
|
|
|
pargs->pa_root_vtype = VDIR;
|
|
|
|
pargs->pa_root_vsize = 0;
|
|
|
|
pargs->pa_root_rdev = 0;
|
|
|
|
pargs->pa_maxmsglen = 0;
|
2013-12-06 12:04:52 +01:00
|
|
|
if (/*CONSTCOND*/ sizeof(time_t) == 4)
|
|
|
|
pargs->pa_time32 = 1;
|
|
|
|
else
|
|
|
|
pargs->pa_time32 = 0;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
pu->pu_flags = pflags;
|
|
|
|
buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH; /* XXX */
|
|
|
|
pu->pu_ops = *pops;
|
|
|
|
free(pops); /* XXX */
|
|
|
|
|
|
|
|
pu->pu_privdata = priv;
|
|
|
|
pu->pu_cc_stackshift = PUFFS_CC_STACKSHIFT_DEFAULT;
|
|
|
|
LIST_INIT(&pu->pu_pnodelst);
|
|
|
|
LIST_INIT(&pu->pu_pnode_removed_lst);
|
|
|
|
LIST_INIT(&pu->pu_ios);
|
|
|
|
LIST_INIT(&pu->pu_ios_rmlist);
|
|
|
|
LIST_INIT(&pu->pu_ccmagazin);
|
|
|
|
TAILQ_INIT(&pu->pu_sched);
|
|
|
|
|
|
|
|
/* defaults for some user-settable translation functions */
|
|
|
|
pu->pu_cmap = NULL; /* identity translation */
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
pu->pu_pathbuild = puffs_stdpath_buildpath;
|
|
|
|
pu->pu_pathfree = puffs_stdpath_freepath;
|
|
|
|
pu->pu_pathcmp = puffs_stdpath_cmppath;
|
|
|
|
pu->pu_pathtransform = NULL;
|
|
|
|
pu->pu_namemod = NULL;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
pu->pu_errnotify = puffs_defaulterror;
|
|
|
|
|
|
|
|
PU_SETSTATE(pu, PUFFS_STATE_BEFOREMOUNT);
|
|
|
|
|
|
|
|
global_pu = pu;
|
|
|
|
|
|
|
|
return pu;
|
|
|
|
|
|
|
|
failfree:
|
|
|
|
/* can't unmount() from here for obvious reasons */
|
|
|
|
sverrno = errno;
|
|
|
|
free(pu);
|
|
|
|
errno = sverrno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puffs_cancel(struct puffs_usermount *pu, int error)
|
|
|
|
{
|
2013-12-06 12:04:52 +01:00
|
|
|
|
2011-11-14 12:53:05 +01:00
|
|
|
assert(puffs_getstate(pu) < PUFFS_STATE_RUNNING);
|
|
|
|
free(pu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED1*/
|
|
|
|
int
|
|
|
|
puffs_exit(struct puffs_usermount *pu, int force)
|
|
|
|
{
|
|
|
|
struct puffs_node *pn;
|
|
|
|
|
|
|
|
lpuffs_debug("puffs_exit\n");
|
|
|
|
|
|
|
|
while ((pn = LIST_FIRST(&pu->pu_pnodelst)) != NULL)
|
|
|
|
puffs_pn_put(pn);
|
|
|
|
|
|
|
|
while ((pn = LIST_FIRST(&pu->pu_pnode_removed_lst)) != NULL)
|
|
|
|
puffs_pn_put(pn);
|
|
|
|
|
|
|
|
puffs__cc_exit(pu);
|
|
|
|
if (pu->pu_state & PU_HASKQ)
|
|
|
|
close(pu->pu_kq);
|
|
|
|
free(pu);
|
|
|
|
|
|
|
|
return 0; /* always succesful for now, WILL CHANGE */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actual mainloop. This is called from a context which can block.
|
|
|
|
* It is called either from puffs_mainloop (indirectly, via
|
|
|
|
* puffs_cc_continue() or from puffs_cc_yield()).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
puffs__theloop(struct puffs_cc *pcc)
|
|
|
|
{
|
|
|
|
struct puffs_usermount *pu = pcc->pcc_pu;
|
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
while (mounted || !exitsignaled) {
|
2011-11-14 12:53:05 +01:00
|
|
|
/*
|
|
|
|
* Schedule existing requests.
|
|
|
|
*/
|
|
|
|
while ((pcc = TAILQ_FIRST(&pu->pu_sched)) != NULL) {
|
|
|
|
lpuffs_debug("scheduling existing tasks\n");
|
|
|
|
TAILQ_REMOVE(&pu->pu_sched, pcc, pcc_schedent);
|
|
|
|
puffs__goto(pcc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pu->pu_ml_lfn) {
|
|
|
|
lpuffs_debug("Calling user mainloop handler\n");
|
|
|
|
pu->pu_ml_lfn(pu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for request message. */
|
2014-08-24 11:51:35 +02:00
|
|
|
if (get_work(&fs_msg, &fs_ipc_status) != OK)
|
|
|
|
continue; /* recheck loop conditions */
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
/* Process it, and send a reply. */
|
|
|
|
fsdriver_process(&puffs_table, &fs_msg, fs_ipc_status, FALSE);
|
2011-11-14 12:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (puffs__cc_restoremain(pu) == -1)
|
|
|
|
warn("cannot restore main context. impending doom");
|
|
|
|
|
|
|
|
/* May get here, if puffs_fakecc is set to 1. Currently librefuse sets it.
|
|
|
|
* Now we just return to the caller.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
int
|
|
|
|
puffs_mainloop(struct puffs_usermount *pu)
|
|
|
|
{
|
|
|
|
struct puffs_cc *pcc;
|
|
|
|
int sverrno;
|
|
|
|
|
|
|
|
assert(puffs_getstate(pu) >= PUFFS_STATE_RUNNING);
|
|
|
|
|
|
|
|
pu->pu_state |= PU_HASKQ | PU_INLOOP;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create alternate execution context and jump to it. Note
|
|
|
|
* that we come "out" of savemain twice. Where we come out
|
|
|
|
* of it depends on the architecture. If the return address is
|
|
|
|
* stored on the stack, we jump out from puffs_cc_continue(),
|
|
|
|
* for a register return address from puffs__cc_savemain().
|
|
|
|
* PU_MAINRESTORE makes sure we DTRT in both cases.
|
|
|
|
*/
|
|
|
|
if (puffs__cc_create(pu, puffs__theloop, &pcc) == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (puffs__cc_savemain(pu) == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if ((pu->pu_state & PU_MAINRESTORE) == 0)
|
|
|
|
puffs_cc_continue(pcc);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* store the real error for a while */
|
|
|
|
sverrno = errno;
|
|
|
|
|
|
|
|
errno = sverrno;
|
|
|
|
if (errno)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
#if defined(__minix)
|
2011-11-14 12:53:05 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_local_startup *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
static void sef_local_startup(void)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
/* Register init callbacks. */
|
|
|
|
sef_setcb_init_fresh(sef_cb_init_fresh);
|
|
|
|
|
|
|
|
/* Register signal callbacks. */
|
|
|
|
sef_setcb_signal_handler(sef_cb_signal_handler);
|
|
|
|
|
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_init_fresh *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sef_cb_init_fresh(int type, sef_init_info_t *info)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
/* Initialize the Minix file server. */
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_signal_handler *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sef_cb_signal_handler(int signo)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
/* Only check for termination signal, ignore anything else. */
|
|
|
|
if (signo != SIGTERM) return;
|
|
|
|
|
|
|
|
exitsignaled = 1;
|
|
|
|
fs_sync();
|
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
sef_cancel();
|
2011-11-14 12:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_work *
|
|
|
|
*===========================================================================*/
|
2014-08-24 11:51:35 +02:00
|
|
|
static int get_work(message *msg, int *ipc_status)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
2014-08-24 11:51:35 +02:00
|
|
|
int r;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
for (;;) {
|
|
|
|
if ((r = sef_receive_status(ANY, msg, ipc_status)) != OK) {
|
|
|
|
if (r == EINTR) /* sef_cancel from signal handler? */
|
|
|
|
break; /* see if we can exit the main loop */
|
2011-11-14 12:53:05 +01:00
|
|
|
panic("sef_receive failed: %d", r);
|
2014-08-24 11:51:35 +02:00
|
|
|
}
|
|
|
|
if (msg->m_source == VFS_PROC_NR)
|
|
|
|
break;
|
|
|
|
lpuffs_debug("libpuffs: unexpected source %d\n", msg->m_source);
|
|
|
|
}
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2014-08-24 11:51:35 +02:00
|
|
|
return r;
|
2011-11-14 12:53:05 +01:00
|
|
|
}
|
2013-12-06 12:04:52 +01:00
|
|
|
#endif /* defined(__minix) */
|