rem: err = EINVAL;
add: err = FS_EINVAL;
context: sys_opendir(bool kernel, int fd, const char *path, bool coe){    int             err;    op_opendir      *op;    op_free_cookie  *opf;    ofile           *f;    int             nfd;    vnode           *vn;    void            *cookie;    err = get_file_fd(kernel, fd, path, TRUE, &vn);    if (err)        goto error1;    op = vn->ns->fs->ops.opendir;    if (!op) {        err = EINVAL;        goto error2;    }    err = (*op)(vn->ns->data, vn->data, &cookie);    if (err)        goto error2;    /*    find a file descriptor    */    f = (ofile *) calloc(sizeof(ofile), 1);    if (!f) {        err = ENOMEM;        goto error3;    }    f->type = FD_DIR;    f->vn = vn;    f->cookie = cookie;    f->rcnt = 0;    f->ocnt = 0;    nfd = new_fd(kernel, -1, f, -1, coe);    if (nfd < 0) {        err = EMFILE;        goto error4;    }    return nfd;error4:    free(f);error3:    (*vn->ns->fs->ops.closedir)(vn->ns->data, vn->data, cookie);    opf = vn->ns->fs->ops.free_dircookie;    if (opf)        (*opf)(vn->ns->data, vn->data, cookie);error2:    dec_vnode(vn, FALSE);error1:    if (err > 0)        /* XXXdbg -- a hack for linux */        err = -err;    return err;}