Ejemplo n.º 1
0
Archivo: mount.c Proyecto: eugmes/diod
Npcfid*
npc_auth (Npcfsys *fs, char *aname, u32 uid, AuthFun auth)
{
        Npcfid *afid = NULL;
        Npfcall *tc = NULL, *rc = NULL;

        if (!(afid = npc_fid_alloc (fs)))
                goto done;
        if (!(tc = np_create_tauth (afid->fid, NULL, aname, uid))) {
		np_uerror (ENOMEM);
		npc_fid_free (afid);
		afid = NULL;
                goto done;
	}
        if (afid->fsys->rpc (afid->fsys, tc, &rc) < 0) {
		npc_fid_free (afid);
		afid = NULL;
		goto done;
	}
	if (auth && auth (afid, uid) < 0) {
		int saved_err = np_rerror ();
		(void)npc_clunk (afid);
		afid = NULL;
		np_uerror (saved_err);
		goto done;
	}
done:
        if (tc)
                free(tc);
        if (rc)
                free(rc);
        return afid;
}
Ejemplo n.º 2
0
Archivo: mount.c Proyecto: 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;	
}
Ejemplo n.º 3
0
Archivo: open.c Proyecto: nuxlli/npfs
static int
npc_clunk(Npcfid *fid)
{
	Npfcall *tc, *rc;
	Npcfsys *fs;

	fs = fid->fsys;
	tc = np_create_tclunk(fid->fid);
	if (npc_rpc(fid->fsys, tc, &rc) < 0) {
		free(tc);
		return -1;
	}

	npc_fid_free(fid);
	free(tc);
	free(rc);

	return 0;
}
Ejemplo n.º 4
0
Archivo: mount.c Proyecto: eugmes/diod
int
npc_clunk (Npcfid *fid)
{
        Npfcall *tc = NULL, *rc = NULL;
	int ret = -1;

        if (!(tc = np_create_tclunk (fid->fid))) {
		np_uerror (ENOMEM);
                goto done;
	}
        if (fid->fsys->rpc (fid->fsys, tc, &rc) < 0)
                goto done;
        npc_fid_free(fid);
	ret = 0;
done:
	if (tc)
        	free (tc);
	if (rc)
        	free (rc);
        return ret;
}
Ejemplo n.º 5
0
Archivo: remove.c Proyecto: chaos/diod
int
npc_remove (Npcfid *fid)
{
	Npfcall *tc = NULL, *rc = NULL;
	int ret = -1;

	if (!(tc = np_create_tremove(fid->fid))) {
		np_uerror (ENOMEM);
		goto done;
	}
	if (fid->fsys->rpc(fid->fsys, tc, &rc) < 0)
		goto done;
	ret = 0;
done:
	npc_fid_free (fid); /* fid is no longer valid after remove */
	if (tc)
		free(tc);
	if (rc)
		free(rc);
	return ret;
}
Ejemplo n.º 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;
}