static void test_twrite (void) { Npfcall *fc, *fc2; u8 buf[128]; memset (buf, 0x0f, sizeof(buf)); if (!(fc = np_create_twrite (1, 2, sizeof (buf), buf))) msg_exit ("out of memory in %s", __FUNCTION__); fc2 = _rcv_buf (fc, P9_TWRITE, __FUNCTION__); assert (fc->u.twrite.fid == fc2->u.twrite.fid); assert (fc->u.twrite.offset == fc2->u.twrite.offset); assert (fc->u.twrite.count == fc2->u.twrite.count); assert (memcmp (fc->u.twrite.data, fc2->u.twrite.data, fc->u.twrite.count) == 0); free (fc); free (fc2); }
int npc_pwrite(Npcfid *fid, void *buf, u32 count, u64 offset) { int maxio = fid->fsys->msize - P9_IOHDRSZ; Npfcall *tc = NULL, *rc = NULL; int ret = -1; if (count > maxio) count = maxio; if (!(tc = np_create_twrite(fid->fid, offset, count, buf))) { np_uerror (ENOMEM); goto done; } if (fid->fsys->rpc(fid->fsys, tc, &rc) < 0) goto done; ret = rc->u.rwrite.count; done: if (tc) free(tc); if (rc) free(rc); return ret; }