Пример #1
0
Npcfsys*
npc_start (int rfd, int wfd, int msize, int flags)
{
	Npcfsys *fs;
	Npfcall *tc = NULL, *rc = NULL;

	if ((flags & NPC_MULTI_RPC))
		fs = npc_create_mtfsys (rfd, wfd, msize, flags);
	else 
		fs = npc_create_fsys (rfd, wfd, msize, flags);
	if (!fs)
		goto done;
	if (!(tc = np_create_tversion (msize, "9P2000.L"))) {
		np_uerror (ENOMEM);
		goto done;
	}
	if (fs->rpc (fs, tc, &rc) < 0)
		goto done;
	if (rc->u.rversion.msize < msize)
		fs->msize = rc->u.rversion.msize;
	if (np_strcmp (&rc->u.rversion.version, "9P2000.L") != 0) {
		np_uerror(EIO);
		goto done;
	}
done:
	if (tc)
		free (tc);
	if (rc)
		free (rc);
	if (np_rerror () && fs) {
		npc_finish (fs);
		fs = NULL;
	}			
	return fs;
}
Пример #2
0
static void 
_send_tversion (Nptrans *t)
{
    Npfcall *tc, *rc = _alloc_rc ();

    tc = np_create_tversion (TEST_MSIZE, "9P2000.L");
    if (!tc)
        msg_exit ("oom");
    ttrans_rpc (t, tc, rc);
    free (tc);
    free (rc);
}
Пример #3
0
static void
test_tversion (void)
{
    Npfcall *fc, *fc2;

    if (!(fc = np_create_tversion (TEST_MSIZE, "9p2000.L")))
        msg_exit ("out of memory");
    fc2 = _rcv_buf (fc, P9_TVERSION,  __FUNCTION__);

    assert (fc->u.tversion.msize == fc2->u.tversion.msize);
    assert (np_str9cmp (&fc->u.tversion.version, &fc2->u.tversion.version) == 0);

    free (fc);
    free (fc2);
}
Пример #4
0
Npcfsys*
npc_mount(int fd, char *aname, char *uname)
{
	Npcfsys *fs;
	Npfcall *tc, *rc;

	fs = npc_create_fsys(fd, 8216);
	if (!fs)
		return NULL;

	tc = np_create_tversion(8216, "9P2000.u");
	if (npc_rpc(fs, tc, &rc) < 0)
		goto error;

	if (rc->version.len==8 && !memcmp(rc->version.str, "9P2000.u", 8)) {
		fs->dotu = 1;
	} else if (rc->version.len==6 && !memcmp(rc->version.str, "9P2000", 6)) {
		fs->dotu = 0;
	} else {
		np_werror("unsupported 9P version", EIO);
		goto error;
	}
	free(tc);
	free(rc);
	tc = rc = NULL;

	fs->root = npc_fid_alloc(fs);
	if (!fs->root) 
		goto error;

	tc = np_create_tattach(fs->root->fid, NOFID, uname, aname);
	if (npc_rpc(fs, tc, &rc) < 0)
		goto error;

	free(tc);
	free(rc);
	return fs;

error:
	free(tc);
	free(rc);
	npc_disconnect_fsys(fs);
	npc_decref_fsys(fs);

	return NULL;
}
Пример #5
0
static void
_flush_series (Npcfsys *fs, Npcfid *root)
{
    Npfcall *rc = NULL, *tc = NULL, *ac = NULL;
    u16 tag, flushtag;
    int n, i;
    struct sigaction sa;

    assert (fs->trans != NULL);

    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);
    sa.sa_handler = _alarm_clock;
    if (sigaction (SIGALRM, &sa, NULL) < 0)
        err_exit ("sigaction");

    /* write 100 tversions */
    for (i = 0; i < 100; i++) {
        if (!(tc = np_create_tversion (fs->msize, "9P2000.L")))
            msg_exit ("out of memory");
        flushtag = tag = npc_get_id(fs->tagpool);
        np_set_tag(tc, tag);
        n = np_trans_write(fs->trans, tc->pkt, tc->size);
        if (n < 0)
            errn_exit (np_rerror (), "np_trans_write");
        if (n != tc->size)
            msg_exit ("np_trans_write came up unexpectedly short");
        //msg ("sent tversion tag %d", tc->tag);
        free(tc);
    }
    msg ("sent 100 tversions");

    /* flush the most recent */
    if (!(ac = np_create_tflush (flushtag)))
        msg_exit ("out of memory");
    tag = npc_get_id(fs->tagpool);
    np_set_tag(ac, tag);
    n = np_trans_write(fs->trans, ac->pkt, ac->size);
    if (n < 0)
        errn_exit (np_rerror (), "np_trans_write");
    if (n != ac->size)
        msg_exit ("np_trans_write came up unexpectedly short");
    //msg ("sent tflush tag %d (flushing tag %d)", ac->tag, flushtag);
    free (ac);
    msg ("sent 1 tflush");
        
    /* receive up to 101 responses with 1s timeout */
    for (i = 0; i < 101; i++) {
        if (!(rc = malloc(sizeof(*rc) + fs->msize)))
            msg_exit ("out of memory");
        rc->pkt = (u8*)rc + sizeof(*rc);
        alarm (1);
        n = np_trans_read(fs->trans, rc->pkt, fs->msize);
        if (n < 0) {
            if (errno == EINTR)
                break;
            errn_exit (np_rerror (), "np_trans_read");
        }
        alarm (0);
        if (n == 0)
            msg_exit ("np_trans_read: unexpected EOF");
        if (!np_deserialize (rc, rc->pkt))
            msg_exit ("failed to deserialize response in one go");
        //msg ("received tag %d", rc->tag);
        free(rc);
        //npc_put_id(fs->tagpool, rc->tag);
    }
    if (i == 100 || i == 101)
        msg ("received 100/101 respones");
    else 
        msg ("received %d responses", i);
}
Пример #6
0
Npcfsys*
npc_mount(int fd, char *aname, Npuser *user, 
	int (*auth)(Npcfid *afid, Npuser *user, void *aux), void *aux)
{
	Npcfsys *fs;
	Npfcall *tc, *rc;

	fs = npc_create_fsys(fd, 8216);
	if (!fs)
		return NULL;

	tc = np_create_tversion(8216, "9P2000.u");
	if (npc_rpc(fs, tc, &rc) < 0)
		goto error;

	if (rc->version.len==8 && !memcmp(rc->version.str, "9P2000.u", 8)) {
		fs->dotu = 1;
	} else if (rc->version.len==6 && !memcmp(rc->version.str, "9P2000", 6)) {
		fs->dotu = 0;
	} else {
		np_werror("unsupported 9P version", EIO);
		goto error;
	}
	free(tc);
	free(rc);
	tc = rc = NULL;

	if (auth) {
		fs->afid = npc_fid_alloc(fs);
		if (!fs->afid)
			goto error;

		tc = np_create_tauth(fs->afid->fid, user?user->uname:NULL, aname, 
			user?user->uid:-1, fs->dotu);
		if (npc_rpc(fs, tc, &rc) < 0) {
			npc_fid_free(fs->afid);
			fs->afid = NULL;
		} else if ((*auth)(fs->afid, user, aux) < 0)
				goto error;

		free(tc);
		free(rc);
		tc = rc = NULL;
	}

	fs->root = npc_fid_alloc(fs);
	if (!fs->root) 
		goto error;

	tc = np_create_tattach(fs->root->fid, fs->afid?fs->afid->fid:NOFID, 
		user->uname, aname, user->uid, fs->dotu);
	if (npc_rpc(fs, tc, &rc) < 0)
		goto error;

	free(tc);
	free(rc);
	return fs;

error:
	free(tc);
	free(rc);
	npc_disconnect_fsys(fs);
	npc_decref_fsys(fs);

	return NULL;
}