Exemple #1
0
static int do_pipe(int *fd)
{
    register struct inode *inode;
    struct file *f1;
    struct file *f2;
    int error = -ENOMEM;
    int i;

    if(!(inode = new_inode(NULL, S_IFIFO | S_IRUSR | S_IWUSR)))	/* Create inode */
	goto no_inodes;

    /* read file */
    if((error = open_filp(O_RDONLY, inode, &f1)))
	goto no_files;

    if ((error = get_unused_fd(f1)) < 0)
	goto close_f1;
    fd[0] = error;
    i = error;

    (inode->i_count)++;		/* Increase inode usage count */
    /* write file */
    if((error = open_filp(O_WRONLY, inode, &f2)))
	goto close_f1_i;

    if ((error = get_unused_fd(f2)) < 0)
	goto close_f12;
    fd[1] = error;

    return 0;

  close_f12:
    close_filp(inode, f2);

  close_f1_i:
    current->files.fd[i] = NULL;
    inode->i_count--;

  close_f1:
    close_filp(inode, f1);

  no_files:
    iput(inode);

  no_inodes:
    return error;
}
Exemple #2
0
int open_fd(int flags, register struct inode *inode)
{
    int fd;
    struct file *filp;

    if(!(fd = open_filp(flags, inode, &filp))
	&& ((fd = get_unused_fd(filp)) < 0))
	close_filp(inode, filp);
    return fd;
}
Exemple #3
0
int open_fd(int flags, struct inode *inode)
{
    int fd;
    struct file *f;
    register struct file *filp;

    if (!(fd = open_filp(flags, inode, &f))) {
	filp = f;
	filp->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
    /*
     * We have to do this last, because we mustn't export
     * an incomplete fd to other processes which may share
     * the same file table with us.
     */
	if ((fd = get_unused_fd(filp)) < 0)
	    close_filp(inode, filp);
    }
    return fd;
}
Exemple #4
0
int sys_open(char *filename, int flags, int mode)
{
    struct inode *inode;
    register struct inode *pinode;
    struct file *f;
    int error, flag;

    flag = flags;
    if ((mode_t)((flags + 1) & O_ACCMODE))
	flag++;
    if (flag & (O_TRUNC | O_CREAT))
	flag |= FMODE_WRITE;

    error = open_namei(filename, flag, mode, &inode, NULL);
    if(error)
	goto exit_open;

    pinode = inode;
    error = open_filp(flags, pinode, &f);
    if(error)
	goto cleanup_inode;
    f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);

    /*
     * We have to do this last, because we mustn't export
     * an incomplete fd to other processes which may share
     * the same file table with us.
     */
    if ((error = get_unused_fd(f)) > -1)
	goto exit_open;
    close_filp(pinode, f);

  cleanup_inode:
    iput(pinode);
  exit_open:
    return error;
}