Example #1
0
File: mount.c Project: eugmes/diod
Npcfid *
npc_attach (Npcfsys *fs, Npcfid *afid, char *aname, uid_t uid)
{
	Npfcall *tc = NULL, *rc = NULL;
	Npcfid *fid = NULL;

	if (!(fid = npc_fid_alloc (fs)))
		goto done;
	if (!(tc = np_create_tattach (fid->fid, afid ? afid->fid : P9_NOFID,
				      NULL, aname, uid))) {
		np_uerror (ENOMEM);
		goto done;
	}
	if (fs->rpc (fs, tc, &rc) < 0)
		goto done;
done:
	if (tc)
		free (tc);
	if (rc)
		free (rc);
	if (np_rerror () && fid) {
		npc_fid_free (fid);
		fid = NULL;
	}
	return fid;	
}
Example #2
0
static void
_send_tattach (Nptrans *t, uid_t uid, int fid)
{
    Npfcall *tc, *rc = _alloc_rc ();

    tc = np_create_tattach (fid, P9_NOFID, NULL, "/foo", uid);
    if (!tc)
        msg_exit ("oom");
    ttrans_rpc (t, tc, rc);
    free (tc);
    free (rc);
}
Example #3
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;
}
Example #4
0
static void
test_tattach (void)
{
    Npfcall *fc, *fc2;

    if (!(fc = np_create_tattach (1, 2, "abc", "xyz", 5)))
        msg_exit ("out of memory in %s", __FUNCTION__); 
    fc2 = _rcv_buf (fc, P9_TATTACH, __FUNCTION__);

    assert (fc->u.tattach.fid == fc2->u.tattach.fid);
    assert (fc->u.tattach.afid == fc2->u.tattach.afid);
    assert (np_str9cmp (&fc->u.tattach.uname, &fc2->u.tattach.uname) == 0);
    assert (np_str9cmp (&fc->u.tattach.aname, &fc2->u.tattach.aname) == 0);
    assert (fc->u.tattach.n_uname == fc2->u.tattach.n_uname);

    free (fc);
    free (fc2);
}
Example #5
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;
}