From 16e35dcc39fe1cd89160ffb26caefebf6382f0dd Mon Sep 17 00:00:00 2001 From: Doug White Date: Wed, 9 Nov 2005 22:03:50 +0000 Subject: This is a workaround for a complicated issue involving VFS cookies and devfs. The PR and patch have the details. The ultimate fix requires architectural changes and clarifications to the VFS API, but this will prevent the system from panicking when someone does "ls /dev" while running in a shell under the linuxulator. This issue affects HEAD and RELENG_6 only. PR: 88249 Submitted by: "Devon H. O'Dell" MFC after: 3 days --- sys/fs/devfs/devfs_vnops.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'sys/fs/devfs') diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 7fbcad0281a34..d567ea5fff3f2 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -797,6 +797,7 @@ devfs_readdir(struct vop_readdir_args *ap) struct devfs_dirent *de; struct devfs_mount *dmp; off_t off, oldoff; + int *tmp_ncookies = NULL; if (ap->a_vp->v_type != VDIR) return (ENOTDIR); @@ -805,6 +806,21 @@ devfs_readdir(struct vop_readdir_args *ap) if (uio->uio_offset < 0) return (EINVAL); + /* + * XXX: This is a temporary hack to get around this filesystem not + * supporting cookies. We store the location of the ncookies pointer + * in a temporary variable before calling vfs_subr.c:vfs_read_dirent() + * and set the number of cookies to 0. We then set the pointer to + * NULL so that vfs_read_dirent doesn't try to call realloc() on + * ap->a_cookies. Later in this function, we restore the ap->a_ncookies + * pointer to its original location before returning to the caller. + */ + if (ap->a_ncookies != NULL) { + tmp_ncookies = ap->a_ncookies; + *ap->a_ncookies = 0; + ap->a_ncookies = NULL; + } + dmp = VFSTODEVFS(ap->a_vp->v_mount); sx_xlock(&dmp->dm_lock); devfs_populate(dmp); @@ -833,6 +849,14 @@ devfs_readdir(struct vop_readdir_args *ap) } sx_xunlock(&dmp->dm_lock); uio->uio_offset = off; + + /* + * Restore ap->a_ncookies if it wasn't originally NULL in the first + * place. + */ + if (tmp_ncookies != NULL) + ap->a_ncookies = tmp_ncookies; + return (error); } -- cgit v1.3