void * getpointfrombuf(struct pbuf *pbuf, int len) { void * ret = pbuf->arg[0]; pbuf_adv_arg(pbuf, 0, len); return ret; }
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; }
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; }
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); }
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; } }
void addtobuf(struct pbuf *pbuf, char *data, int len) { memcpy(pbuf->arg[0], data, len); pbuf_adv_arg(pbuf, 0, len); }
void getfrombuf(struct pbuf *pbuf, char* data, int len) { memcpy(data, pbuf->arg[0], len); pbuf_adv_arg(pbuf, 0, len); }