From owner-svn-src-all@FreeBSD.ORG Tue May 12 09:28:46 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5AC78106566C; Tue, 12 May 2009 09:28:46 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3D6E48FC19; Tue, 12 May 2009 09:28:46 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4C9SkHx016938; Tue, 12 May 2009 09:28:46 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4C9SkX1016937; Tue, 12 May 2009 09:28:46 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200905120928.n4C9SkX1016937@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 12 May 2009 09:28:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192013 - head/sys/fs/fdescfs X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 May 2009 09:28:46 -0000 Author: kib Date: Tue May 12 09:28:45 2009 New Revision: 192013 URL: http://svn.freebsd.org/changeset/base/192013 Log: Report all fdescfs vnodes as VCHR for stat(2). Fake the unique major/minor numbers of the devices. Pretending that the vnodes are character devices prevents file tree walkers from descending into the directories opened by current process. Also, not doing stat on the filedescriptors prevents the recursive entry into the VFS. Requested by: kientzle Discussed with: Jilles Tjoelker Modified: head/sys/fs/fdescfs/fdesc_vnops.c Modified: head/sys/fs/fdescfs/fdesc_vnops.c ============================================================================== --- head/sys/fs/fdescfs/fdesc_vnops.c Tue May 12 09:22:33 2009 (r192012) +++ head/sys/fs/fdescfs/fdesc_vnops.c Tue May 12 09:28:45 2009 (r192013) @@ -389,78 +389,34 @@ fdesc_getattr(ap) { struct vnode *vp = ap->a_vp; struct vattr *vap = ap->a_vap; - struct thread *td = curthread; - struct file *fp; - struct stat stb; - u_int fd; - int error = 0; + + vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; + vap->va_fileid = VTOFDESC(vp)->fd_ix; + vap->va_uid = 0; + vap->va_gid = 0; + vap->va_blocksize = DEV_BSIZE; + vap->va_atime.tv_sec = boottime.tv_sec; + vap->va_atime.tv_nsec = 0; + vap->va_mtime = vap->va_atime; + vap->va_ctime = vap->va_mtime; + vap->va_gen = 0; + vap->va_flags = 0; + vap->va_bytes = 0; + vap->va_filerev = 0; switch (VTOFDESC(vp)->fd_type) { case Froot: - vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; vap->va_type = VDIR; vap->va_nlink = 2; vap->va_size = DEV_BSIZE; - vap->va_fileid = VTOFDESC(vp)->fd_ix; - vap->va_uid = 0; - vap->va_gid = 0; - vap->va_blocksize = DEV_BSIZE; - vap->va_atime.tv_sec = boottime.tv_sec; - vap->va_atime.tv_nsec = 0; - vap->va_mtime = vap->va_atime; - vap->va_ctime = vap->va_mtime; - vap->va_gen = 0; - vap->va_flags = 0; vap->va_rdev = NODEV; - vap->va_bytes = 0; - vap->va_filerev = 0; break; case Fdesc: - fd = VTOFDESC(vp)->fd_fd; - - if ((error = fget(td, fd, &fp)) != 0) - return (error); - - bzero(&stb, sizeof(stb)); - error = fo_stat(fp, &stb, td->td_ucred, td); - fdrop(fp, td); - if (error == 0) { - vap->va_type = IFTOVT(stb.st_mode); - vap->va_mode = stb.st_mode; - if (vap->va_type == VDIR) - vap->va_mode &= ~(S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); - vap->va_nlink = 1; - vap->va_flags = 0; - vap->va_bytes = stb.st_blocks * stb.st_blksize; - vap->va_fileid = VTOFDESC(vp)->fd_ix; - vap->va_size = stb.st_size; - vap->va_blocksize = stb.st_blksize; - vap->va_rdev = stb.st_rdev; - - /* - * If no time data is provided, use the current time. - */ - if (stb.st_atimespec.tv_sec == 0 && - stb.st_atimespec.tv_nsec == 0) - nanotime(&stb.st_atimespec); - - if (stb.st_ctimespec.tv_sec == 0 && - stb.st_ctimespec.tv_nsec == 0) - nanotime(&stb.st_ctimespec); - - if (stb.st_mtimespec.tv_sec == 0 && - stb.st_mtimespec.tv_nsec == 0) - nanotime(&stb.st_mtimespec); - - vap->va_atime = stb.st_atimespec; - vap->va_mtime = stb.st_mtimespec; - vap->va_ctime = stb.st_ctimespec; - vap->va_uid = stb.st_uid; - vap->va_gid = stb.st_gid; - vap->va_gen = 0; - vap->va_filerev = 0; - } + vap->va_type = VCHR; + vap->va_nlink = 1; + vap->va_size = 0; + vap->va_rdev = makedev(0, vap->va_fileid); break; default: @@ -468,9 +424,8 @@ fdesc_getattr(ap) break; } - if (error == 0) - vp->v_type = vap->va_type; - return (error); + vp->v_type = vap->va_type; + return (0); } static int