static Npfcall* np_default_version(Npconn *conn, u32 msize, Npstr *version) { int dotu; char *ver; Npfcall *rc; if (msize > conn->srv->msize) msize = conn->srv->msize; dotu = 0; if (np_strcmp(version, "9P2000.u")==0 && conn->srv->dotu) { ver = "9P2000.u"; dotu = 1; } else if (np_strncmp(version, "9P2000", 6) == 0) ver = "9P2000"; else ver = NULL; if (msize < IOHDRSZ) np_werror("msize too small", EIO); else if (ver) { np_conn_reset(conn, msize, dotu); rc = np_create_rversion(msize, ver); } else np_werror("unsupported 9P version", EIO); return rc; }
static void test_rversion (void) { Npfcall *fc, *fc2; if (!(fc = np_create_rversion (TEST_MSIZE, "9p2000.L"))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RVERSION, __FUNCTION__); assert (fc->u.rversion.msize == fc2->u.rversion.msize); assert (np_str9cmp (&fc->u.rversion.version, &fc2->u.rversion.version) == 0); free (fc); free (fc2); }
Npfcall * np_version(Npreq *req, Npfcall *tc) { Npfcall *rc = NULL; int msize = tc->u.tversion.msize; if (msize < P9_IOHDRSZ + 1) { np_uerror(EIO); return NULL; } if (msize > req->conn->msize) msize = req->conn->msize; if (msize < req->conn->msize) req->conn->msize = msize; /* conn->msize can only be reduced */ if (np_strcmp(&tc->u.tversion.version, "9P2000.L") == 0) { if (!(rc = np_create_rversion(msize, "9P2000.L"))) np_uerror(ENOMEM); } else np_uerror(EIO); return rc; }