From owner-freebsd-emulation@FreeBSD.ORG Wed Nov 8 22:00:15 2006 Return-Path: X-Original-To: freebsd-emulation@FreeBSD.org Delivered-To: freebsd-emulation@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 317AE16A49E for ; Wed, 8 Nov 2006 22:00:15 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from anuket.mj.niksun.com (gwnew.niksun.com [65.115.46.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8438A43D46 for ; Wed, 8 Nov 2006 22:00:12 +0000 (GMT) (envelope-from jkim@FreeBSD.org) Received: from niksun.com (anuket [10.70.0.5]) by anuket.mj.niksun.com (8.13.1/8.13.1) with ESMTP id kA8Lx9VW033239; Wed, 8 Nov 2006 16:59:10 -0500 (EST) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim To: freebsd-emulation@FreeBSD.org Date: Wed, 8 Nov 2006 16:58:55 -0500 User-Agent: KMail/1.6.2 References: <20061106174033.GA70360@stud.fit.vutbr.cz> <200611071237.11856.jkim@FreeBSD.org> <20061108070258.GA61393@stud.fit.vutbr.cz> In-Reply-To: <20061108070258.GA61393@stud.fit.vutbr.cz> MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_hMlUFgRyAHZ0+qz" Message-Id: <200611081658.57145.jkim@FreeBSD.org> X-Virus-Scanned: ClamAV 0.88.6/2177/Wed Nov 8 11:10:40 2006 on anuket.mj.niksun.com X-Virus-Status: Clean Cc: Subject: Re: [PATCH]: possible fix for the fifoor problem X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Nov 2006 22:00:15 -0000 --Boundary-00=_hMlUFgRyAHZ0+qz Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wednesday 08 November 2006 02:02 am, Divacky Roman wrote: > bde knows obviously more about it. but I personally dont object > to the patch The attached patch is what I came up with after reading bde's comment. I was not able to get rid of kern_open() but it is only used for char/block special files. I think this is less evil than what we have now in the tree. ;-) Jung-uk Kim --Boundary-00=_hMlUFgRyAHZ0+qz Content-Type: text/x-diff; charset="iso-8859-1"; name="linux_stats.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="linux_stats.diff" --- src/sys/compat/linux/linux_stats.c.orig Wed Nov 8 16:13:37 2006 +++ src/sys/compat/linux/linux_stats.c Wed Nov 8 16:29:31 2006 @@ -100,23 +100,16 @@ translate_fd_major_minor(struct thread *td, int fd, struct stat *buf) { struct file *fp; - int error; int major, minor; - if ((error = fget(td, fd, &fp)) != 0) + if ((!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) || + fget(td, fd, &fp) != 0) return; - if (fp->f_vnode) { - if (fp->f_vnode->v_type == VCHR - || fp->f_vnode->v_type == VBLK) { - if (fp->f_vnode->v_un.vu_cdev) { - if (linux_driver_get_major_minor( - fp->f_vnode->v_un.vu_cdev->si_name, - &major, &minor) == 0) { - buf->st_rdev = (major << 8 | minor); - } - } - } - } + if (fp->f_vnode != NULL && + fp->f_vnode->v_un.vu_cdev != NULL && + linux_driver_get_major_minor(fp->f_vnode->v_un.vu_cdev->si_name, + &major, &minor) == 0) + buf->st_rdev = (major << 8 | minor); fdrop(fp, td); } @@ -129,6 +122,8 @@ int fd; int temp; + if (!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) + return; temp = td->td_retval[0]; if (kern_open(td, path, UIO_SYSSPACE, O_RDONLY, 0) != 0) return; @@ -179,18 +174,19 @@ #endif error = kern_stat(td, path, UIO_SYSSPACE, &buf); - if (!error && strlen(path) > strlen("/dev/pts/") && - !strncmp(path, "/dev/pts/", strlen("/dev/pts/")) - && path[9] >= '0' && path[9] <= '9') { - /* - * Linux checks major and minors of the slave device to make - * sure it's a pty device, so let's make him believe it is. - */ - buf.st_rdev = (136 << 8); - } - - translate_path_major_minor(td, path, &buf); - + if (!error) { + if (strlen(path) > strlen("/dev/pts/") && + !strncmp(path, "/dev/pts/", strlen("/dev/pts/")) && + path[9] >= '0' && path[9] <= '9') { + /* + * Linux checks major and minors of the slave device to + * make sure it's a pty device, so let's make him + * believe it is. + */ + buf.st_rdev = (136 << 8); + } else + translate_path_major_minor(td, path, &buf); + } LFREEPATH(path); if (error) return (error); @@ -212,7 +208,8 @@ #endif error = kern_lstat(td, path, UIO_SYSSPACE, &sb); - translate_path_major_minor(td, path, &sb); + if (!error) + translate_path_major_minor(td, path, &sb); LFREEPATH(path); if (error) return (error); @@ -524,18 +521,19 @@ #endif error = kern_stat(td, filename, UIO_SYSSPACE, &buf); - if (!error && strlen(filename) > strlen("/dev/pts/") && - !strncmp(filename, "/dev/pts/", strlen("/dev/pts/")) - && filename[9] >= '0' && filename[9] <= '9') { - /* - * Linux checks major and minors of the slave device to make - * sure it's a pty deivce, so let's make him believe it is. - */ - buf.st_rdev = (136 << 8); + if (!error) { + if (strlen(filename) > strlen("/dev/pts/") && + !strncmp(filename, "/dev/pts/", strlen("/dev/pts/")) && + filename[9] >= '0' && filename[9] <= '9') { + /* + * Linux checks major and minors of the slave device to + * make sure it's a pty deivce, so let's make him + * believe it is. + */ + buf.st_rdev = (136 << 8); + } else + translate_path_major_minor(td, filename, &buf); } - - translate_path_major_minor(td, filename, &buf); - LFREEPATH(filename); if (error) return (error); @@ -557,7 +555,8 @@ #endif error = kern_lstat(td, filename, UIO_SYSSPACE, &sb); - translate_path_major_minor(td, filename, &sb); + if (!error) + translate_path_major_minor(td, filename, &sb); LFREEPATH(filename); if (error) return (error); --Boundary-00=_hMlUFgRyAHZ0+qz--