From owner-svn-src-all@FreeBSD.ORG Fri Mar 14 02:10:30 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D8C94A0E; Fri, 14 Mar 2014 02:10:30 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AC13DC74; Fri, 14 Mar 2014 02:10:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2E2AUbd016018; Fri, 14 Mar 2014 02:10:30 GMT (envelope-from bdrewery@svn.freebsd.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2E2AUgZ016017; Fri, 14 Mar 2014 02:10:30 GMT (envelope-from bdrewery@svn.freebsd.org) Message-Id: <201403140210.s2E2AUgZ016017@svn.freebsd.org> From: Bryan Drewery Date: Fri, 14 Mar 2014 02:10:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r263131 - head/sys/fs/tmpfs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 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: Fri, 14 Mar 2014 02:10:30 -0000 Author: bdrewery Date: Fri Mar 14 02:10:30 2014 New Revision: 263131 URL: http://svnweb.freebsd.org/changeset/base/263131 Log: Cleanup redundant logic and add some comments to help explain how it works in lieu of potentially less clear code. Sponsored by: EMC / Isilon Storage Division Discussed with: Russell Cattelan Modified: head/sys/fs/tmpfs/tmpfs_subr.c Modified: head/sys/fs/tmpfs/tmpfs_subr.c ============================================================================== --- head/sys/fs/tmpfs/tmpfs_subr.c Fri Mar 14 01:43:55 2014 (r263130) +++ head/sys/fs/tmpfs/tmpfs_subr.c Fri Mar 14 02:10:30 2014 (r263131) @@ -348,6 +348,9 @@ tmpfs_dirent_hash(const char *name, u_in static __inline off_t tmpfs_dirent_cookie(struct tmpfs_dirent *de) { + if (de == NULL) + return (TMPFS_DIRCOOKIE_EOF); + MPASS(de->td_cookie >= TMPFS_DIRCOOKIE_MIN); return (de->td_cookie); @@ -1155,6 +1158,15 @@ tmpfs_dir_getdents(struct tmpfs_node *no TMPFS_VALIDATE_DIR(node); off = 0; + + /* + * Lookup the node from the current offset. The starting offset of + * 0 will lookup both '.' and '..', and then the first real entry, + * or EOF if there are none. Then find all entries for the dir that + * fit into the buffer. Once no more entries are found (de == NULL), + * the offset is set to TMPFS_DIRCOOKIE_EOF, which will cause the next + * call to return 0. + */ switch (uio->uio_offset) { case TMPFS_DIRCOOKIE_DOT: error = tmpfs_dir_getdotdent(node, uio); @@ -1168,12 +1180,10 @@ tmpfs_dir_getdents(struct tmpfs_node *no if (error != 0) return (error); de = tmpfs_dir_first(node, &dc); - if (de == NULL) - uio->uio_offset = TMPFS_DIRCOOKIE_EOF; - else - uio->uio_offset = tmpfs_dirent_cookie(de); + uio->uio_offset = tmpfs_dirent_cookie(de); if (cnt != 0) cookies[(*ncookies)++] = off = uio->uio_offset; + /* EOF. */ if (de == NULL) return (0); break; @@ -1252,10 +1262,7 @@ tmpfs_dir_getdents(struct tmpfs_node *no if (error == 0) { de = tmpfs_dir_next(node, &dc); if (cnt != 0) { - if (de == NULL) - off = TMPFS_DIRCOOKIE_EOF; - else - off = tmpfs_dirent_cookie(de); + off = tmpfs_dirent_cookie(de); MPASS(*ncookies < cnt); cookies[(*ncookies)++] = off; } @@ -1263,12 +1270,8 @@ tmpfs_dir_getdents(struct tmpfs_node *no } while (error == 0 && uio->uio_resid > 0 && de != NULL); /* Update the offset and cache. */ - if (cnt == 0) { - if (de == NULL) - off = TMPFS_DIRCOOKIE_EOF; - else - off = tmpfs_dirent_cookie(de); - } + if (cnt == 0) + off = tmpfs_dirent_cookie(de); uio->uio_offset = off; node->tn_dir.tn_readdir_lastn = off;