rem: fdarray         *fds;
context: sys_open(bool kernel, int fd, const char *path, int omode, int perms,        bool coe){    int             err;    char            filename[FILE_NAME_LENGTH];    vnode           *vn, *dvn;    vnode_id        vnid;    void            *cookie;    ofile           *f;    int             nfd;    fdarray         *fds;    op_create       *opc;    op_open         *opo;    op_free_cookie  *opf;    if (omode & O_CREAT) {        err = get_dir_fd(kernel, fd, path, filename, &dvn);        if (err)            goto errorA;        opc = dvn->ns->fs->ops.create;        if (!opc) {            err = EINVAL;            goto errorB;        }        err = (*opc)(dvn->ns->data, dvn->data, filename, omode, perms, &vnid,                        &cookie);        if (err)            goto errorB;        LOCK(vnlock);        vn = lookup_vnode(dvn->ns->nsid, vnid);        UNLOCK(vnlock);        dec_vnode(dvn, FALSE);    } else {        err = get_file_fd(kernel, fd, path, TRUE, &vn);        if (err)            goto error1;        opo = vn->ns->fs->ops.open;        if (!opo) {            err = EINVAL;            goto error2;        }        err = (*opo)(vn->ns->data, vn->data, omode, &cookie);        if (err)            goto error2;    }    /*    find a file descriptor    */    f = (ofile *) calloc(sizeof(ofile), 1);    if (!f) {        err = ENOMEM;        goto error3;    }    f->type = FD_FILE;    f->vn = vn;    f->cookie = cookie;    f->ocnt = 0;    f->rcnt = 0;    f->pos = 0;    f->omode = omode;    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.close)(vn->ns->data, vn->data, cookie);    opf = vn->ns->fs->ops.free_cookie;    if (opf)        (*opf)(vn->ns->data, vn->data, cookie);    if (omode & O_CREAT)        goto errorC;error2:    dec_vnode(vn, FALSE);error1:    return err;errorC:    (*vn->ns->fs->ops.unlink)(dvn->ns->data, dvn->data, filename);    dec_vnode(vn, FALSE);errorB:    dec_vnode(dvn, FALSE);errorA:    if (err > 0)        /* XXXdbg -- a hack for linux */        err = -err;    return err;}