示例#1
0
unsigned int
mnt_get_export_list(void)
{
    struct pbuf *pbuf;
    struct pbuf *ret;
    char str[100];

    int opt;

    pbuf = initbuf(MNT_NUMBER, MNT_VERSION, MNTPROC_EXPORT);

    ret = rpc_call(pbuf, mount_port);

    while (getfrombuf(ret, (char*) &opt, sizeof(opt)), opt) {

	debug( "NFS Export...\n" );

	getstring(ret, str, 100);

	debug( "* Export name is %s\n", (char*) &str );

	/* now to extract more stuff... */
	while (getfrombuf(ret, (char*) &opt, sizeof(opt)), opt) {
	    getstring(ret, str, 100 );
	    debug("* Group %s\n", (char*) str);
	}
    }

    return 0;
}
示例#2
0
unsigned int
mnt_mount(char *dir, struct cookie *pfh)
{
    struct pbuf *pbuf, *ret;
    int status;

    pbuf = initbuf(MNT_NUMBER, MNT_VERSION, MNTPROC_MNT);

    addstring(pbuf, dir);
    
    ret = rpc_call(pbuf, mount_port);

	 if (ret == 0) {
		 debug( "mount call failed :(\n" );
		 return 1;
	 }

    /* now we do some stuff :) */
    getfrombuf(ret, (char*) &status, sizeof(status));

	 if (status != 0) {
		 debug( "Could not mount %s, %d!\n", dir, status );
		 return 1;
	 }

	 debug("All seems good for mount: %s!\n", dir);

    getfrombuf(ret, (char*) pfh, sizeof(struct cookie));

    return 0;
}
示例#3
0
void
nfs_write_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1;
    fattr_t pattrs;
    void (*cb) (uintptr_t, int, fattr_t *) = callback;

    err = check_errors(pbuf);

    assert(callback != NULL);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    /* it worked, so take out the return stuff! */
	    getfrombuf(pbuf, (void*) &pattrs, 
		   sizeof(fattr_t));
	}
    }

    cb(token, status, &pattrs);

    return;
}
示例#4
0
int
getentries_readdir(struct pbuf *pbuf, int *cookie)
{
    void *old_arg_0 = pbuf->arg[0];
    int tmp = 1;
    int count = 0;
    int fileid;

    getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
    debug("Got entry: %d\n", tmp);
    
    while(tmp) {
	getfrombuf(pbuf, (char*) &fileid, sizeof(fileid));
	skipstring(pbuf);
	debug("Skipped string\n");
	getfrombuf(pbuf, (char*) cookie, sizeof(int));
	debug("Skipped string %d\n", *cookie);
	count++;
	getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
    }
    
    getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
    
    if (tmp == 0)
	cookie = 0;

    pbuf->arg[0] = old_arg_0;

    debug("Returning: %d\n", count);

    return count;
}
示例#5
0
void
nfs_create_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1;
    struct cookie new_fh;
    fattr_t pattrs;
    void (*cb) (uintptr_t, int, struct cookie *, fattr_t *) = callback;

    assert(callback != NULL);

    err = check_errors(pbuf);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    /* it worked, so take out the return stuff! */
	    getfrombuf(pbuf, (void*) &new_fh, 
		   sizeof(struct cookie));
	    getfrombuf(pbuf, (void*) &pattrs, 
		   sizeof(fattr_t));
	}
    }

    debug("NFS CREATE CALLBACK\n");
    cb(token, status, &new_fh, &pattrs);

    return;

}
示例#6
0
void
nfs_read_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1;
    fattr_t pattrs;
    char *data = NULL;
    int size = 0;
    void (*cb) (uintptr_t, int, fattr_t *, int, char *) = callback;

    err = check_errors(pbuf);

    assert(callback != NULL);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    /* it worked, so take out the return stuff! */
	    getfrombuf(pbuf, (void*) &pattrs, 
		   sizeof(fattr_t));
	    getfrombuf(pbuf, (void*) &size, 
		   sizeof(int));
	    data = getpointfrombuf(pbuf, pattrs.size);
	}
    }

    cb(token, status, &pattrs, size, data);

    return;
}
示例#7
0
文件: transport.c 项目: gz/aos10
int
getdata(struct pbuf *pbuf, char* data, int len, int null)
{
    int size, padsize;

    assert( len > 0 );

    /* extract the size */
    getfrombuf(pbuf, (char*) &size, sizeof(size));

    padsize = size;

    if (size < len)
	len = size;

    /* copy bytes into tmp */
    if (padsize % 4)
	padsize += 4 - (padsize % 4);

    getfrombuf(pbuf, data, len);

    pbuf_adv_arg(pbuf, 0, (padsize - len));

    /* add the null pointer to the name */
    if (null)
	data[ len ] = '\0';

    return len;
}
示例#8
0
文件: transport.c 项目: gz/aos10
struct pbuf *
rpc_call(struct pbuf *pbuf, int port)
{
    L4_ThreadId_t from;

    opaque_auth_t auth;
    reply_stat r;

    /* Send the thing */
    rpc_send(pbuf, port, signal, NULL, L4_Myself().raw);

    /* We wait for a reply */
    L4_Wait(&from);
    pbuf_adv_arg(call_pbuf, 0, 8);

    /* check if it was an accepted reply */
    getfrombuf(call_pbuf, (char*) &r, sizeof(r));

    if(r != MSG_ACCEPTED) {
	debug( "Message NOT accepted (%d)\n", r );

	/* extract error code */
	getfrombuf(call_pbuf, (char*) &r, sizeof(r));
	debug( "Error code %d\n", r );
	
	if(r == 1) {
	    /* get the auth problem */
	    getfrombuf(call_pbuf, (char*) &r, sizeof(r));
	    debug( "auth_stat %d\n", r );
	}
	
	return 0;
    }
    
    /* and the auth data!*/
    getfrombuf(call_pbuf, (char*) &auth, sizeof(auth));

    debug("Got auth data. size is %d\n", auth.size);

    /* check its accept stat */
    getfrombuf(call_pbuf, (char*) &r, sizeof(r));
    
    if( r == SUCCESS )
	return call_pbuf;
    else {
	debug( "reply stat was %d\n", r );
	return NULL;
    }
}
示例#9
0
unsigned int
map_getport(mapping_t* pmap)
{
    int port;
    struct pbuf *pbuf;
    struct pbuf *ret;
    debug("Getting port\n");
    pmap->port = 0;
    
    /* add the xid */
    pbuf = initbuf(PMAP_NUMBER, PMAP_VERSION, PMAPPROC_GETPORT);
    
    /* pack up the map struct */
    addtobuf(pbuf, (char*) pmap, sizeof(mapping_t));
    
    /* make the call */
    ret = rpc_call(pbuf, PMAP_PORT);

    assert(ret != NULL);
    
    /* now we can extract the port */
    getfrombuf(ret, (char*) &port, sizeof(port));
    
    pmap->port = port;
    
    debug("Got port %d\n", port);

    return 0;
}
示例#10
0
static int
check_errors(struct pbuf *pbuf)
{
    xid_t txid;
    int ctype;
    opaque_auth_t auth;
    int r;
    
    /* extract the xid */
    getfrombuf(pbuf, (char*) &txid, sizeof(txid));
    
    /* and the call type */
    getfrombuf(pbuf, (char*) &ctype, sizeof(ctype));
    
    
    if (ctype != MSG_REPLY) {
	debug( "Got a reply to something else!!\n" );
	
	debug( "Looking for msgtype %d\n", MSG_REPLY );
	debug( "Got msgtype %d\n", ctype );
	
	return ERR_BAD_MSG;
    }
    
    /* check if it was an accepted reply */
    getfrombuf(pbuf, (char*) &r, sizeof(r));
    
    if (r != MSG_ACCEPTED) {
	debug( "Message NOT accepted (%d)\n", r );
	
	/* extract error code */
	getfrombuf( pbuf, (char*) &r, sizeof( r ) );
	debug( "Error code %d\n", r );
	
	if (r == 1) {
	    /* get the auth problem */
	    getfrombuf( pbuf, (char*) &r, sizeof( r ) );
	    debug( "auth_stat %d\n", r );
	}
	
	return ERR_NOT_ACCEPTED;
    }
    
    /* and the auth data!*/
    getfrombuf(pbuf, (char*) &auth, sizeof(auth));
    
    if (auth.flavour != AUTH_NULL)
	assert("gave back other auth type!\n");
    
    /* check its accept stat */
    getfrombuf(pbuf, (char*) &r, sizeof(r));
    
    if (r == SUCCESS) {
	return 0;
    } else {
	debug( "reply stat was %d\n", r );
	return ERR_FAILURE;
    }
}
示例#11
0
文件: transport.c 项目: gz/aos10
void
skipstring(struct pbuf *pbuf)
{
    int size;
    
    /* extract the size */
    getfrombuf(pbuf, (char*) &size, sizeof(size));
    
    if (size % 4)
	size += 4 - (size % 4);
    pbuf_adv_arg(pbuf, 0, size);
}
示例#12
0
void
nfs_readdir_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1, num_entries = 0, next_cookie = 0;
    struct nfs_filename *entries = NULL;
    void (*cb) (uintptr_t , int, int, struct nfs_filename *, int) = callback;
    int count = 0;

    debug("NFS READDIR CALLBACK\n");

    assert(callback != NULL);

    err = check_errors(pbuf);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    int tmp, fileid, cookie;
	    debug("Getting entries\n");
	    num_entries = getentries_readdir(pbuf, &next_cookie);
	    entries = malloc(sizeof(struct nfs_filename) * 
		     num_entries);

	    
	    getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
	    debug("Got entry: %d\n", tmp);
	    
	    while(tmp) {
		int size;
		getfrombuf(pbuf, (char*) &fileid, 
		       sizeof(fileid));
		debug("Got filed: %d\n", fileid);
		getfrombuf(pbuf, (char*) &entries[count].size,
		       sizeof(int));
		debug("Got size: %d\n", entries[count].size);
		entries[count].file = pbuf->arg[0];
		size = entries[count].size;
		if (size % 4)
		    size += 4 - (size % 4);
		pbuf_adv_arg(pbuf, 0, size);
		debug("Got size: %p\n", pbuf->arg[0]);
		
		getfrombuf(pbuf, (char*) &cookie, sizeof(int));
		
		count++;
		getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
	    }
	}
    }

    cb(token, status, num_entries, entries, next_cookie);
    if (entries)
	free(entries);

    return;

}
示例#13
0
void
nfs_remove_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
	int err = 0, status = -1;
	void (*cb) (uintptr_t, int) = callback;

	assert(callback != NULL);

	err = check_errors(pbuf);

	if (err == 0) {
		/* get the status out */
		getfrombuf(pbuf, (char*) &status, sizeof(status));
	}

	cb(token, status);

	return;
}