Exemplo n.º 1
0
void
lazyopen_wresp(struct puffs_usermount *pu, struct puffs_framebuf *pb,
	void *arg, int error)
{
	struct psshfs_node *psn = arg;

	/* XXX: this is not enough */
	if (psn->stat & PSN_RECLAIMED) {
		error = ENOENT;
		goto moreout;
	}
	if (error)
		goto out;

	error = psbuf_expect_handle(pb, &psn->fhand_w, &psn->fhand_w_len);

 out:
	psn->lazyopen_err_w = error;
	psn->lazyopen_w = NULL;
	if (error)
		psn->stat &= ~PSN_DOLAZY_W;
	if (psn->stat & PSN_HANDLECLOSE && (psn->stat & PSN_LAZYWAIT_W) == 0)
		closehandles(pu, psn, HANDLE_WRITE);
 moreout:
	puffs_framebuf_destroy(pb);
}
/* for our eyes only */
void
puffs__ml_dispatch(struct puffs_usermount *pu, struct puffs_framebuf *pb)
{
	struct puffs_cc *pcc = puffs_cc_getcc(pu);
	struct puffs_req *preq;

	pcc->pcc_pb = pb;
	pcc->pcc_flags |= PCC_MLCONT;
	dispatch(pcc);

	/* Put result to kernel sendqueue if necessary */
	preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
	if (PUFFSOP_WANTREPLY(preq->preq_opclass)) {
		if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
			puffsdump_rv(preq);

		puffs_framev_enqueue_justsend(pu, pu->pu_fd,
		    pcc->pcc_pb, 0, 0);
	} else {
		puffs_framebuf_destroy(pcc->pcc_pb);
	}

	/* who needs information when you're living on borrowed time? */
	if (pcc->pcc_flags & PCC_BORROWED) {
		puffs_cc_yield(pcc); /* back to borrow source */
	}
	pcc->pcc_flags = 0;
}
Exemplo n.º 3
0
static int
doflush(struct puffs_usermount *pu, puffs_cookie_t cookie, int op,
        off_t start, off_t end)
{
    struct puffs_framebuf *pb;
    struct puffs_flush *pf;
    size_t winlen;
    int rv;

    pb = puffs_framebuf_make();
    if (pb == NULL)
        return ENOMEM;

    winlen = sizeof(struct puffs_flush);
    if ((rv = puffs_framebuf_getwindow(pb, 0, (void *)&pf, &winlen)) == -1)
        goto out;
    assert(winlen == sizeof(struct puffs_flush));

    pf->pf_req.preq_buflen = sizeof(struct puffs_flush);
    pf->pf_req.preq_opclass = PUFFSOP_FLUSH;
    pf->pf_req.preq_id = puffs__nextreq(pu);

    pf->pf_op = op;
    pf->pf_cookie = cookie;
    pf->pf_start = start;
    pf->pf_end = end;

    rv = puffs_framev_enqueue_cc(puffs_cc_getcc(pu),
                                 puffs_getselectable(pu), pb, 0);

out:
    puffs_framebuf_destroy(pb);
    return rv;
}
Exemplo n.º 4
0
Arquivo: fs.c Projeto: glk/puffs
int
psshfs_handshake(struct puffs_usermount *pu, int fd)
{
	struct psshfs_ctx *pctx = puffs_getspecific(pu);
	struct puffs_framebuf *pb;
	struct puffs_pathobj *po_root;
	struct puffs_node *pn_root;
	struct vattr va, *rva;
	const struct extunit *extu;
	char *rootpath;
	char *ext, *val;
	uint32_t count;
	int rv, done;

	pb = psbuf_makeout();
	psbuf_put_1(pb, SSH_FXP_INIT);
	psbuf_put_4(pb, SFTP_PROTOVERSION);
	DO_IO(psbuf_write, pu, pb, fd, &done, rv);

	puffs_framebuf_recycle(pb);
	DO_IO(psbuf_read, pu, pb, fd, &done, rv);
	if (psbuf_get_type(pb) != SSH_FXP_VERSION)
		reterr((stderr, "invalid server response: %d",
		    psbuf_get_type(pb)), EPROTO);
	pctx->protover = psbuf_get_reqid(pb);

	/*
	 * Check out which extensions are available.  Currently
	 * we are only interested in the openssh statvfs extension.
	 */
	for (;;) {
		if (psbuf_get_str(pb, &ext, NULL) != 0)
			break;
		if (psbuf_get_str(pb, &val, NULL) != 0)
			break;

		for (extu = exttable; extu->ext; extu++)
			if (strcmp(ext, extu->ext) == 0
			    && strcmp(val, extu->val) == 0)
				pctx->extensions |= extu->extflag;
	}

	/* scope out our rootpath */
	psbuf_recycleout(pb);
	psbuf_put_1(pb, SSH_FXP_REALPATH);
	psbuf_put_4(pb, NEXTREQ(pctx));
	psbuf_put_str(pb, pctx->mountpath);
	DO_IO(psbuf_write, pu, pb, fd, &done, rv);

	puffs_framebuf_recycle(pb);
	DO_IO(psbuf_read, pu, pb, fd, &done, rv);
	if (psbuf_get_type(pb) != SSH_FXP_NAME)
		reterr((stderr, "invalid server realpath response for \"%s\"",
		    pctx->mountpath), EPROTO);
	if (psbuf_get_4(pb, &count) == -1)
		reterr((stderr, "invalid realpath response: count"), EPROTO);
	if (psbuf_get_str(pb, &rootpath, NULL) == -1)
		reterr((stderr, "invalid realpath response: rootpath"), EPROTO);

	/* stat the rootdir so that we know it's a dir */
	psbuf_recycleout(pb);
	psbuf_req_str(pb, SSH_FXP_LSTAT, NEXTREQ(pctx), rootpath);
	DO_IO(psbuf_write, pu, pb, fd, &done, rv);

	puffs_framebuf_recycle(pb);
	DO_IO(psbuf_read, pu, pb, fd, &done, rv);

	rv = psbuf_expect_attrs(pb, &va);
	if (rv)
		reterr((stderr, "couldn't stat rootpath"), rv);
	puffs_framebuf_destroy(pb);

	if (puffs_mode2vt(va.va_mode) != VDIR)
		reterr((stderr, "remote path (%s) not a directory", rootpath),
		    ENOTDIR);

	pn_root = puffs_getroot(pu);
	rva = &pn_root->pn_va;
	puffs_setvattr(rva, &va);

	po_root = puffs_getrootpathobj(pu);
	if (po_root == NULL)
		err(1, "getrootpathobj");
	po_root->po_path = rootpath;
	po_root->po_len = strlen(rootpath);

	return 0;
}