Exemplo n.º 1
0
int sys_pipe2_hdlr(int paddr, int flags)
{
    int *pfd = (int*)paddr;
    struct fnode *rd, *wr;
    struct pipe_priv *pp;
    pp = kalloc(sizeof (struct pipe_priv));
    if (!pp) {
        return -ENOMEM;
    }

    rd = fno_create(&mod_pipe, "", &PIPE_ROOT);
    if (!rd) {
        goto fail_rd;
    }
    wr = fno_create(&mod_pipe, "", &PIPE_ROOT);
    if (!wr) {
        goto fail_wr;
    }

    pfd[0] = task_filedesc_add(rd);
    pfd[1] = task_filedesc_add(wr);

    if (pfd[0] < 0 || pfd[1] < 0) {
        goto fail_all;
    }

    task_fd_setmask(pfd[0], O_RDONLY);
    task_fd_setmask(pfd[1], O_WRONLY);

    rd->priv = pp;
    wr->priv = pp;

    pp->fno_r = rd;
    pp->fno_w = wr;
    pp->pid_r = 0;
    pp->pid_w = 0;
    pp->w_off = 0;
    pp->cb = cirbuf_create(PIPE_BUFSIZE);
    if (!pp->cb) {
        goto fail_all;
    }
    return 0;

fail_all:
        fno_unlink(wr);
fail_wr:
        fno_unlink(rd);
fail_rd:
        kfree(pp);
        return -ENOMEM;

}
Exemplo n.º 2
0
static int klog_open(const char *path, int flags)
{
    if (klog.used)
        return -EBUSY;
    klog.used++;
    return task_filedesc_add(fno_search("/dev/klog"));
}