From owner-p4-projects@FreeBSD.ORG Sun Jun 7 12:43:00 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 773B61065674; Sun, 7 Jun 2009 12:42:59 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 373791065670 for ; Sun, 7 Jun 2009 12:42:59 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 24E5D8FC35 for ; Sun, 7 Jun 2009 12:42:59 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n57Cgxq9093070 for ; Sun, 7 Jun 2009 12:42:59 GMT (envelope-from zhaoshuai@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n57CgxUM093068 for perforce@freebsd.org; Sun, 7 Jun 2009 12:42:59 GMT (envelope-from zhaoshuai@FreeBSD.org) Date: Sun, 7 Jun 2009 12:42:59 GMT Message-Id: <200906071242.n57CgxUM093068@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zhaoshuai@FreeBSD.org using -f From: Zhao Shuai To: Perforce Change Reviews Cc: Subject: PERFORCE change 163706 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2009 12:43:01 -0000 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 #include #include +#include #include #include +#include #include #include @@ -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;