Date: Sun, 7 Jun 2009 12:42:59 GMT From: Zhao Shuai <zhaoshuai@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 163706 for review Message-ID: <200906071242.n57CgxUM093068@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=163706 Change 163706 by zhaoshuai@zhaoshuai on 2009/06/07 12:42:12 add fifo_stat_f() and fifo_ioctl_f() several coding style fix Affected files ... .. //depot/projects/soc2009/fifo/sys/fs/fifofs/fifo_vnops.c#10 edit .. //depot/projects/soc2009/fifo/sys/kern/sys_pipe.c#11 edit Differences ... ==== //depot/projects/soc2009/fifo/sys/fs/fifofs/fifo_vnops.c#10 (text+ko) ==== @@ -43,8 +43,10 @@ #include <sys/kernel.h> #include <sys/lock.h> #include <sys/mutex.h> +#include <sys/stat.h> #include <sys/unistd.h> #include <sys/vnode.h> +#include <sys/proc.h> #include <sys/pipe.h> #include <fs/fifofs/fifo.h> @@ -146,7 +148,8 @@ return (EINVAL); if ((fip = vp->v_fifoinfo) == NULL) { fip = malloc(sizeof(*fip), M_VNODE, M_WAITOK); - if (( error = generic_pipe_create(td, &rpipe, &wpipe)) != 0) { + error = generic_pipe_create(td, &rpipe, &wpipe); + if (error) { free(fip, M_VNODE); return (error); } @@ -389,9 +392,8 @@ { struct fifoinfo *fip = fp->f_data; - struct pipe *rpipe = fip->fi_rpipe; - return (generic_pipe_read(rpipe, uio, cred, flags, td)); + return (generic_pipe_read(fip->fi_rpipe, uio, cred, flags, td)); } static int @@ -399,16 +401,22 @@ { struct fifoinfo *fip = fp->f_data; - struct pipe *wpipe = fip->fi_wpipe; - return (generic_pipe_write(wpipe, uio, cred, flags, td)); + return (generic_pipe_write(fip->fi_wpipe, uio, cred, flags, td)); } static int fifo_stat_f(struct file *fp, struct stat *sb, struct ucred *cred, struct thread *td) { + struct fifoinfo *fip = fp->f_data; + int error; - return (vnops.fo_stat(fp, sb, cred, td)); + error = generic_pipe_stat(fip->fi_rpipe, sb, cred, td); + if (error) + return (error); + sb->st_uid = fp->f_cred->cr_uid; + sb->st_gid = fp->f_cred->cr_gid; + return (0); } static int @@ -425,12 +433,52 @@ return (vnops.fo_close(fp, td)); } +/* + * The implementation of ioctl() for named fifos is complicated by the fact + * that we permit O_RDWR fifo file descriptors, meaning that the actions of + * ioctls may have to be applied to both the underlying pipes rather than + * just one. + * + * Unlike sys_pipe.c, fifos do not implement the deprecated TIOCSPGRP and + * TIOCGPGRP ioctls. Earlier implementations of fifos did forward SIOCSPGRP + * and SIOCGPGRP ioctls, so we might need to re-add those here. + */ static int fifo_ioctl_f(struct file *fp, u_long com, void *data, struct ucred *cred, struct thread *td) { + struct fifoinfo *fip = fp->f_data; + int error = ENOTTY; + + switch (com) { + case FIONBIO: + case FIOASYNC: + case FIOSETOWN: + case FIOGETOWN: + if (fp->f_flag & FREAD) { + error = generic_pipe_ioctl(fip->fi_rpipe, com, data, cred, td); + if (error) + return (error); + } + if (fp->f_flag & FWRITE) + error = generic_pipe_ioctl(fip->fi_wpipe, com, data, cred, td); + return (error); - return (0); + case FIONREAD: + /* + * FIONREAD will return 0 for non-readable descriptors, and + * the results of FIONREAD on the read socket for readable + * descriptors. + */ + if (!(fp->f_flag & FREAD)) { + *(int *)data = 0; + return (0); + } + return (generic_pipe_ioctl(fip->fi_rpipe, com, data, cred, td)); + + default: + return (ENOTTY); + } } static int ==== //depot/projects/soc2009/fifo/sys/kern/sys_pipe.c#11 (text+ko) ==== @@ -54,15 +54,15 @@ static fo_close_t pipe_close; static struct fileops pipeops = { - .fo_read = pipe_read, - .fo_write = pipe_write, - .fo_truncate = pipe_truncate, - .fo_ioctl = pipe_ioctl, - .fo_poll = pipe_poll, - .fo_kqfilter = pipe_kqfilter, - .fo_stat = pipe_stat, - .fo_close = pipe_close, - .fo_flags = DFLAG_PASSABLE + .fo_read = pipe_read, + .fo_write = pipe_write, + .fo_truncate = pipe_truncate, + .fo_ioctl = pipe_ioctl, + .fo_poll = pipe_poll, + .fo_kqfilter = pipe_kqfilter, + .fo_stat = pipe_stat, + .fo_close = pipe_close, + .fo_flags = DFLAG_PASSABLE }; /* @@ -77,8 +77,9 @@ struct pipe *rpipe, *wpipe; int fd, error; - if ((error = generic_pipe_create(td, &rpipe, &wpipe)) != 0) - return (error); + error = generic_pipe_create(td, &rpipe, &wpipe); + if (error) + return (error); error = falloc(td, &rf, &fd); if (error) { @@ -186,7 +187,7 @@ int error; error = generic_pipe_stat(pipe, ub, active_cred, td); - if (error != 0) + if (error) return (error); ub->st_uid = fp->f_cred->cr_uid; ub->st_gid = fp->f_cred->cr_gid;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906071242.n57CgxUM093068>