static void test_treaddir (void) { Npfcall *fc, *fc2; if (!(fc = np_create_treaddir(1, 2, 3))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TREADDIR, __FUNCTION__); assert (fc->u.treaddir.fid == fc2->u.treaddir.fid); assert (fc->u.treaddir.offset == fc2->u.treaddir.offset); assert (fc->u.treaddir.count == fc2->u.treaddir.count); free (fc); free (fc2); }
int npc_readdir (Npcfid *fid, u64 offset, char *data, u32 count) { Npfcall *tc = NULL, *rc = NULL; int ret = -1; if (!(tc = np_create_treaddir(fid->fid, offset, count))) { np_uerror (ENOMEM); goto done; } if (fid->fsys->rpc(fid->fsys, tc, &rc) < 0) goto done; NP_ASSERT(rc->u.rreaddir.count <= count); memcpy (data, rc->u.rreaddir.data, rc->u.rreaddir.count); ret = rc->u.rreaddir.count; done: if (tc) free(tc); if (rc) free(rc); return ret; }