* do mount as a forward operation instead of a callback
* process -o args for mount
This commit is contained in:
parent
7cc096d8ec
commit
a67e4ce37f
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dtfs.c,v 1.12 2006/12/29 15:37:06 pooka Exp $ */
|
||||
/* $NetBSD: dtfs.c,v 1.13 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -37,7 +37,9 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <mntopts.h>
|
||||
#include <puffs.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -56,7 +58,8 @@ static void
|
||||
usage()
|
||||
{
|
||||
|
||||
errx(1, "usage: %s [-abcds] mountpath", getprogname());
|
||||
errx(1, "usage: %s [-bs] [-o mntopt] [-o puffsopt] mountpath",
|
||||
getprogname());
|
||||
}
|
||||
|
||||
int
|
||||
@ -67,25 +70,23 @@ main(int argc, char *argv[])
|
||||
struct dtfs_mount dtm;
|
||||
struct puffs_usermount *pu;
|
||||
struct puffs_ops *pops;
|
||||
int pflags, lflags;
|
||||
mntoptparse_t mp;
|
||||
int pflags, lflags, mntflags;
|
||||
int ch;
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
pflags = lflags = 0;
|
||||
while ((ch = getopt(argc, argv, "abcds")) != -1) {
|
||||
pflags = lflags = mntflags = 0;
|
||||
while ((ch = getopt(argc, argv, "bo:s")) != -1) {
|
||||
switch (ch) {
|
||||
case 'a': /* all ops */
|
||||
pflags |= PUFFS_KFLAG_ALLOPS;
|
||||
break;
|
||||
case 'b': /* build paths */
|
||||
case 'b': /* build paths, for debugging the feature */
|
||||
pflags |= PUFFS_FLAG_BUILDPATH;
|
||||
break;
|
||||
case 'c': /* no cache */
|
||||
pflags |= PUFFS_KFLAG_NOCACHE;
|
||||
break;
|
||||
case 'd': /* dump ops */
|
||||
pflags |= PUFFS_FLAG_OPDUMP;
|
||||
case 'o':
|
||||
mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags);
|
||||
if (mp == NULL)
|
||||
err(1, "getmntopts");
|
||||
freemntopts(mp);
|
||||
break;
|
||||
case 's': /* stay on top */
|
||||
lflags |= PUFFSLOOP_NODAEMON;
|
||||
@ -103,7 +104,6 @@ main(int argc, char *argv[])
|
||||
|
||||
PUFFSOP_INIT(pops);
|
||||
|
||||
PUFFSOP_SET(pops, dtfs, fs, mount);
|
||||
PUFFSOP_SET(pops, dtfs, fs, statvfs);
|
||||
PUFFSOP_SETFSNOP(pops, unmount);
|
||||
PUFFSOP_SETFSNOP(pops, sync);
|
||||
@ -126,10 +126,14 @@ main(int argc, char *argv[])
|
||||
PUFFSOP_SET(pops, dtfs, node, inactive);
|
||||
PUFFSOP_SET(pops, dtfs, node, reclaim);
|
||||
|
||||
if ((pu = puffs_mount(pops, argv[0], 0, FSNAME, &dtm, pflags, 0))
|
||||
if ((pu = puffs_mount(pops, argv[0], mntflags, FSNAME, &dtm, pflags, 0))
|
||||
== NULL)
|
||||
err(1, "mount");
|
||||
|
||||
/* init & call puffs_start() */
|
||||
if (dtfs_domount(pu) != 0)
|
||||
errx(1, "dtfs_domount failed");
|
||||
|
||||
if (puffs_mainloop(pu, lflags) == -1)
|
||||
err(1, "mainloop");
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dtfs.h,v 1.7 2006/12/07 10:54:29 pooka Exp $ */
|
||||
/* $NetBSD: dtfs.h,v 1.8 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -36,6 +36,7 @@
|
||||
#include <puffs.h>
|
||||
|
||||
PUFFSOP_PROTOS(dtfs);
|
||||
int dtfs_domount(struct puffs_usermount *);
|
||||
|
||||
struct dtfs_mount {
|
||||
ino_t dtm_nextfileid; /* running number for file id */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dtfs_vfsops.c,v 1.8 2006/12/29 15:37:06 pooka Exp $ */
|
||||
/* $NetBSD: dtfs_vfsops.c,v 1.9 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -32,6 +32,7 @@
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <puffs.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -40,9 +41,9 @@
|
||||
#include "dtfs.h"
|
||||
|
||||
int
|
||||
dtfs_fs_mount(struct puffs_usermount *pu, void **rootcookie,
|
||||
struct statvfs *sbp)
|
||||
dtfs_domount(struct puffs_usermount *pu)
|
||||
{
|
||||
struct statvfs sb;
|
||||
struct dtfs_mount *dtm;
|
||||
struct dtfs_file *dff;
|
||||
struct puffs_node *pn;
|
||||
@ -71,9 +72,12 @@ dtfs_fs_mount(struct puffs_usermount *pu, void **rootcookie,
|
||||
|
||||
pu->pu_pn_root = pn;
|
||||
puffs_setrootpath(pu, ".");
|
||||
*rootcookie = pn;
|
||||
|
||||
memset(sbp, 0, sizeof(struct statvfs));
|
||||
/* XXX: should call dtfs_fs_statvfs */
|
||||
puffs_zerostatvfs(&sb);
|
||||
|
||||
if (puffs_start(pu, pn, &sb) == -1)
|
||||
return errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dtfs_vnops.c,v 1.11 2007/01/01 21:32:12 pooka Exp $ */
|
||||
/* $NetBSD: dtfs_vnops.c,v 1.12 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -182,6 +182,8 @@ dtfs_node_rmdir(struct puffs_cc *pcc, void *opc, void *targ,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <err.h>
|
||||
|
||||
int
|
||||
dtfs_node_readdir(struct puffs_cc *pcc, void *opc,
|
||||
struct dirent *dent, const struct puffs_cred *pcr, off_t *readoff,
|
||||
@ -193,7 +195,7 @@ dtfs_node_readdir(struct puffs_cc *pcc, void *opc,
|
||||
|
||||
if (pn->pn_va.va_type != VDIR)
|
||||
return ENOTDIR;
|
||||
|
||||
|
||||
dtfs_updatetimes(pn, 1, 0, 0);
|
||||
|
||||
again:
|
||||
@ -237,7 +239,9 @@ dtfs_node_rename(struct puffs_cc *pcc, void *opc, void *src,
|
||||
|
||||
/* if there's a target file, nuke it for atomic replacement */
|
||||
if (pn_tfile) {
|
||||
assert(pn_tfile->pn_va.va_type != VDIR); /* XXX? */
|
||||
if (pn_tfile->pn_va.va_type == VDIR) {
|
||||
assert(/*CONSTCOND*/0); /* XXX FIXME */
|
||||
}
|
||||
dtfs_nukenode(pn_tfile, pn_sdir, pcn_targ->pcn_name);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sysctlfs.c,v 1.10 2006/12/29 15:37:06 pooka Exp $ */
|
||||
/* $NetBSD: sysctlfs.c,v 1.11 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -42,9 +42,11 @@
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <mntopts.h>
|
||||
#include <puffs.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
PUFFSOP_PROTOS(sysctlfs)
|
||||
@ -67,20 +69,41 @@ ino_t nextid = 3;
|
||||
#define ISADIR(a) ((SYSCTL_TYPE(a->sctln.sysctl_flags) == CTLTYPE_NODE))
|
||||
#define SFS_MAXFILE 8192
|
||||
|
||||
static int sysctlfs_domount(struct puffs_usermount *);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct puffs_usermount *pu;
|
||||
struct puffs_ops *pops;
|
||||
mntoptparse_t mp;
|
||||
int mntflags, pflags;
|
||||
int ch;
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
if (argc < 2)
|
||||
errx(1, "usage: %s mountpath", getprogname());
|
||||
errx(1, "usage: %s [-o mntopts] mountpath", getprogname());
|
||||
|
||||
mntflags = pflags = 0;
|
||||
while ((ch = getopt(argc, argv, "o:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'o':
|
||||
mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags);
|
||||
if (mp == NULL)
|
||||
err(1, "getmntopts");
|
||||
freemntopts(mp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (argc != 1)
|
||||
errx(1, "usage: %s [-o mntopts] mountpath", getprogname());
|
||||
|
||||
PUFFSOP_INIT(pops);
|
||||
|
||||
PUFFSOP_SET(pops, sysctlfs, fs, mount);
|
||||
PUFFSOP_SETFSNOP(pops, unmount);
|
||||
PUFFSOP_SETFSNOP(pops, sync);
|
||||
PUFFSOP_SETFSNOP(pops, statvfs);
|
||||
@ -93,34 +116,37 @@ main(int argc, char *argv[])
|
||||
PUFFSOP_SET(pops, sysctlfs, node, read);
|
||||
PUFFSOP_SET(pops, sysctlfs, node, write);
|
||||
|
||||
if ((pu = puffs_mount(pops, argv[1], 0, "sysctlfs", NULL,
|
||||
PUFFS_FLAG_OPDUMP, 0)) == NULL)
|
||||
if ((pu = puffs_mount(pops, argv[0], mntflags, "sysctlfs", NULL,
|
||||
pflags, 0)) == NULL)
|
||||
err(1, "mount");
|
||||
|
||||
puffs_setstacksize(pu, 1024*1024);
|
||||
if (puffs_mainloop(pu, 0) == -1)
|
||||
if (sysctlfs_domount(pu) != 0)
|
||||
errx(1, "domount");
|
||||
if (puffs_mainloop(pu, PUFFSLOOP_NODAEMON) == -1)
|
||||
err(1, "mainloop");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sysctlfs_fs_mount(struct puffs_usermount *pu, void **rootcookie,
|
||||
struct statvfs *sbp)
|
||||
static int
|
||||
sysctlfs_domount(struct puffs_usermount *pu)
|
||||
{
|
||||
struct timeval tv_now;
|
||||
struct statvfs sb;
|
||||
|
||||
rn.dotdot = NULL;
|
||||
rn.hierlen = 0;
|
||||
rn.myid = 2;
|
||||
rn.sctln.sysctl_flags = CTLTYPE_NODE;
|
||||
rn.refcount = 2;
|
||||
*rootcookie = &rn;
|
||||
|
||||
gettimeofday(&tv_now, NULL);
|
||||
TIMEVAL_TO_TIMESPEC(&tv_now, &fstime);
|
||||
|
||||
puffs_fsnop_statvfs(NULL, sbp, 0);
|
||||
puffs_zerostatvfs(&sb);
|
||||
if (puffs_start(pu, &rn, &sb) == -1)
|
||||
return errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $ */
|
||||
/* $NetBSD: fs.c,v 1.2 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $");
|
||||
__RCSID("$NetBSD: fs.c,v 1.2 2007/01/06 18:25:19 pooka Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
#include <err.h>
|
||||
@ -44,9 +44,9 @@ __RCSID("$NetBSD: fs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $");
|
||||
#include "sftp_proto.h"
|
||||
|
||||
int
|
||||
psshfs_fs_mount(struct puffs_usermount *pu, void **rootcookie,
|
||||
struct statvfs *sbp)
|
||||
psshfs_domount(struct puffs_usermount *pu)
|
||||
{
|
||||
struct statvfs sb;
|
||||
struct psshfs_ctx *pctx = pu->pu_privdata;
|
||||
struct psshfs_node *root = &pctx->psn_root;
|
||||
struct vattr va;
|
||||
@ -133,8 +133,9 @@ psshfs_fs_mount(struct puffs_usermount *pu, void **rootcookie,
|
||||
rva->va_fileid = pctx->nextino++;
|
||||
rva->va_nlink = 0156; /* XXX */
|
||||
|
||||
puffs_fsnop_statvfs(NULL, sbp, 0);
|
||||
*rootcookie = pu->pu_pn_root;
|
||||
puffs_zerostatvfs(&sb);
|
||||
if (puffs_start(pu, pu->pu_pn_root, &sb) != 0)
|
||||
return errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: psshfs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $ */
|
||||
/* $NetBSD: psshfs.c,v 1.2 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -57,7 +57,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: psshfs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $");
|
||||
__RCSID("$NetBSD: psshfs.c,v 1.2 2007/01/06 18:25:19 pooka Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -65,6 +65,7 @@ __RCSID("$NetBSD: psshfs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $");
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <mntopts.h>
|
||||
#include <poll.h>
|
||||
#include <puffs.h>
|
||||
#include <signal.h>
|
||||
@ -76,27 +77,57 @@ __RCSID("$NetBSD: psshfs.c,v 1.1 2006/12/29 15:35:39 pooka Exp $");
|
||||
|
||||
static void psshfs_eventloop(struct puffs_usermount *, struct psshfs_ctx *);
|
||||
static void pssh_connect(struct psshfs_ctx *, char **);
|
||||
static void usage(void);
|
||||
|
||||
#define SSH_PATH "/usr/bin/ssh"
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
errx(1, "usage: %s [-o opts] user@host:path mountpath", getprogname());
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct psshfs_ctx pctx;
|
||||
struct puffs_usermount *pu;
|
||||
struct puffs_ops *pops;
|
||||
mntoptparse_t mp;
|
||||
char *sshargs[16];
|
||||
char *userhost;
|
||||
char *hostpath;
|
||||
int mntflags, pflags, ch;
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
if (argc != 3)
|
||||
errx(1, "usage: %s user@host:path mountpath", getprogname());
|
||||
if (argc < 3)
|
||||
usage();
|
||||
|
||||
mntflags = 0;
|
||||
pflags = PUFFS_KFLAG_NOCACHE;
|
||||
while ((ch = getopt(argc, argv, "o:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'o':
|
||||
mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags);
|
||||
if (mp == NULL)
|
||||
err(1, "getmntopts");
|
||||
freemntopts(mp);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
PUFFSOP_INIT(pops);
|
||||
|
||||
PUFFSOP_SET(pops, psshfs, fs, mount);
|
||||
PUFFSOP_SET(pops, psshfs, fs, unmount);
|
||||
PUFFSOP_SETFSNOP(pops, sync); /* XXX */
|
||||
PUFFSOP_SETFSNOP(pops, statvfs);
|
||||
@ -123,7 +154,7 @@ main(int argc, char *argv[])
|
||||
TAILQ_INIT(&pctx.outbufq);
|
||||
TAILQ_INIT(&pctx.req_queue);
|
||||
|
||||
userhost = argv[1];
|
||||
userhost = argv[0];
|
||||
hostpath = strchr(userhost, ':');
|
||||
if (hostpath) {
|
||||
*hostpath++ = '\0';
|
||||
@ -133,7 +164,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* xblah */
|
||||
sshargs[0] = SSH_PATH;
|
||||
sshargs[1] = argv[1];
|
||||
sshargs[1] = argv[0];
|
||||
sshargs[2] = "-oClearAllForwardings=yes";
|
||||
sshargs[3] = "-a";
|
||||
sshargs[4] = "-x";
|
||||
@ -142,12 +173,14 @@ main(int argc, char *argv[])
|
||||
sshargs[7] = 0;
|
||||
pssh_connect(&pctx, sshargs);
|
||||
|
||||
if ((pu = puffs_mount(pops, argv[2], 0, "psshfs", &pctx,
|
||||
PUFFS_FLAG_BUILDPATH | PUFFS_KFLAG_NOCACHE, 0))==NULL)
|
||||
if ((pu = puffs_mount(pops, argv[1], mntflags, "psshfs", &pctx,
|
||||
PUFFS_FLAG_BUILDPATH | pflags, 0))==NULL)
|
||||
err(1, "puffs_mount");
|
||||
|
||||
if (puffs_setblockingmode(pu, PUFFSDEV_NONBLOCK) == -1)
|
||||
err(1, "setblockingmode");
|
||||
if (psshfs_domount(pu) != 0)
|
||||
errx(1, "domount");
|
||||
|
||||
daemon(0, 0);
|
||||
|
||||
@ -300,8 +333,6 @@ psshfs_eventloop(struct puffs_usermount *pu, struct psshfs_ctx *pctx)
|
||||
pfds[PFD_PUFFS].fd = puffs_getselectable(pu);
|
||||
pfds[PFD_PUFFS].events = POLLIN;
|
||||
|
||||
puffs_resetputreq(ppr);
|
||||
|
||||
if (poll(pfds, 2, INFTIM) == -1)
|
||||
err(1, "poll");
|
||||
|
||||
@ -326,6 +357,7 @@ psshfs_eventloop(struct puffs_usermount *pu, struct psshfs_ctx *pctx)
|
||||
/* stuff all replies from both of the above into kernel */
|
||||
if (puffs_putputreq(ppr) == -1)
|
||||
err(1, "putputreq");
|
||||
puffs_resetputreq(ppr);
|
||||
}
|
||||
|
||||
puffs_destroygetreq(pgr);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: psshfs.h,v 1.1 2006/12/29 15:35:39 pooka Exp $ */
|
||||
/* $NetBSD: psshfs.h,v 1.2 2007/01/06 18:25:19 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
@ -140,6 +140,8 @@ struct psshfs_ctx {
|
||||
TAILQ_HEAD(, psbuf) req_queue;
|
||||
};
|
||||
|
||||
int psshfs_domount(struct puffs_usermount *);
|
||||
|
||||
struct psbuf *psbuf_make(int);
|
||||
void psbuf_destroy(struct psbuf *);
|
||||
void psbuf_recycle(struct psbuf *, int);
|
||||
|
Loading…
Reference in New Issue
Block a user