Date: Wed, 8 Nov 2006 16:58:55 -0500 From: Jung-uk Kim <jkim@FreeBSD.org> To: freebsd-emulation@FreeBSD.org Subject: Re: [PATCH]: possible fix for the fifoor problem Message-ID: <200611081658.57145.jkim@FreeBSD.org> In-Reply-To: <20061108070258.GA61393@stud.fit.vutbr.cz> References: <20061106174033.GA70360@stud.fit.vutbr.cz> <200611071237.11856.jkim@FreeBSD.org> <20061108070258.GA61393@stud.fit.vutbr.cz>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611081658.57145.jkim>