Exemplo n.º 1
0
Npfcall*
diod_readdir(Npfid *fid, u64 offset, u32 count, Npreq *req)
{
    int n;
    Fid *f = fid->aux;
    Npfcall *ret = NULL;

    if (!(ret = np_create_rreaddir (count))) {
        np_uerror (ENOMEM);
        goto error;
    }
    n = _read_dir_linux (f, ret->u.rreaddir.data, offset, count);
    if (np_rerror ()) {
        free (ret);
        ret = NULL;
    } else
        np_finalize_rreaddir (ret, n);
    return ret;
error:
    errn (np_rerror (), "diod_readdir %s@%s:%s",
          fid->user->uname, np_conn_get_client_id (fid->conn), f->path);
    if (ret)
        free (ret);
    return NULL;
}
Exemplo n.º 2
0
static void
test_rreaddir (void)
{
    Npfcall *fc, *fc2;
    int n = 0, len = 256;
    struct p9_qid qid[3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, qid2[3];
    char *name[3] = { "abc", "def", "ghi" }, name2[3][128];
    u64 offset;
    u8 type;

    if (!(fc = np_create_rreaddir (len)))
        msg_exit ("out of memory");
    n += np_serialize_p9dirent (&qid[0], 0, 1, name[0],
                                fc->u.rreaddir.data + n, len - n);
    n += np_serialize_p9dirent (&qid[1], 50, 2, name[1],
                                fc->u.rreaddir.data + n, len - n);
    n += np_serialize_p9dirent (&qid[2], 100, 3, name[2],
                                fc->u.rreaddir.data + n, len - n);
    assert (n < len);
    np_finalize_rreaddir (fc, n);
    fc2 = _rcv_buf (fc, P9_RREADDIR,  __FUNCTION__);

    assert (fc->u.rreaddir.count == fc2->u.rreaddir.count);

    n = 0;
    n += np_deserialize_p9dirent (&qid2[0], &offset, &type, name2[0], 128,
                           fc2->u.rreaddir.data + n, fc2->u.rreaddir.count - n);
    assert (offset == 0);
    assert (type == 1);
    assert (strcmp (name2[0], name[0]) == 0);
    n += np_deserialize_p9dirent (&qid2[1], &offset, &type, name2[1], 128,
                           fc2->u.rreaddir.data + n, fc2->u.rreaddir.count - n);
    assert (offset == 50);
    assert (type == 2);
    assert (strcmp (name2[1], name[1]) == 0);
    n += np_deserialize_p9dirent (&qid2[2], &offset, &type, name2[2], 128,
                           fc2->u.rreaddir.data + n, fc2->u.rreaddir.count - n);
    assert (offset == 100);
    assert (type == 3);
    assert (strcmp (name2[2], name[2]) == 0);
    assert (n == fc2->u.rreaddir.count);

    free (fc);
    free (fc2);
}