From unknown Fri Aug 15 02:02:41 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#10293 <10293@debbugs.gnu.org> To: bug#10293 <10293@debbugs.gnu.org> Subject: Status: [PATCH] du -x should not count files in other file systems Reply-To: bug#10293 <10293@debbugs.gnu.org> Date: Fri, 15 Aug 2025 09:02:41 +0000 retitle 10293 [PATCH] du -x should not count files in other file systems reassign 10293 coreutils submitter 10293 Paul Eggert severity 10293 normal tag 10293 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 13 14:22:18 2011 Received: (at submit) by debbugs.gnu.org; 13 Dec 2011 19:22:18 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RaXve-0003H5-2q for submit@debbugs.gnu.org; Tue, 13 Dec 2011 14:22:18 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RaXva-0003Gx-O3 for submit@debbugs.gnu.org; Tue, 13 Dec 2011 14:22:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaXuI-0007T3-0n for submit@debbugs.gnu.org; Tue, 13 Dec 2011 14:20:54 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([140.186.70.17]:58156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaXuH-0007Su-VR for submit@debbugs.gnu.org; Tue, 13 Dec 2011 14:20:53 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaXuG-0005Np-LT for bug-coreutils@gnu.org; Tue, 13 Dec 2011 14:20:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaXuD-0007Rz-9J for bug-coreutils@gnu.org; Tue, 13 Dec 2011 14:20:52 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:36425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaXuC-0007Ra-VN for bug-coreutils@gnu.org; Tue, 13 Dec 2011 14:20:49 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id DE07F39E800A for ; Tue, 13 Dec 2011 11:20:46 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TMLUl2BvXVM7 for ; Tue, 13 Dec 2011 11:20:44 -0800 (PST) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 92A6139E8006 for ; Tue, 13 Dec 2011 11:20:44 -0800 (PST) Message-ID: <4EE7A53F.8070909@cs.ucla.edu> Date: Tue, 13 Dec 2011 11:19:27 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 MIME-Version: 1.0 To: Bug-coreutils Subject: [PATCH] du -x should not count files in other file systems Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -4.7 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) While looking into Bug#10282 I noticed that 'du' is mishandling the -x option. It relies on FTS_XDEV to not cross file system boundaries, but FTS_XDEV visits the root of the other file system, causing 'du' to output a line "0 X" where X is the mount point of the other file system. This doesn't sound right, since X is in a different file system and du -x is supposed to ignore files in other file systems. Also, it disagrees with Solaris 10 du (at least). Here's a proposed patch. The bug is absent from coreutils 5.0 and present in 5.2.0. I'm guessing from the NEWS files that it was introduced in 5.1.0 but 5.1.0 is no longer available at ftp.gnu.org so this isn't trivial for me to check. du: -x should not count files in other file systems * NEWS: Document fix. * src/du.c (process_file): Don't count files in different file systems if -x is given. * tests/du/one-file-system: Test for this bug. diff --git a/NEWS b/NEWS index 0d4c83b..51c44c7 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*- ** Bug fixes + du -x no longer counts root directories of other file systems. + [bug introduced in coreutils-5.1.0] + ls --color many-entry-directory was uninterruptible for too long [bug introduced in coreutils-5.2.1] diff --git a/src/du.c b/src/du.c index fba7f7d..a8dfd28 100644 --- a/src/du.c +++ b/src/du.c @@ -443,6 +443,9 @@ process_file (FTS *fts, FTSENT *ent) error (0, ent->fts_errno, _("cannot access %s"), quote (file)); return false; } + + if (fts->fts_options & FTS_XDEV && fts->fts_dev != sb->st_dev) + excluded = true; } if (excluded diff --git a/tests/du/one-file-system b/tests/du/one-file-system index 7195838..2ec9865 100755 --- a/tests/du/one-file-system +++ b/tests/du/one-file-system @@ -1,6 +1,5 @@ #!/bin/sh -# Test for a bug in fts's handling of FTS_XDEV, the flag behind -# du's --one-file-system (-x) option. +# Test for bugs in du's --one-file-system (-x) option. # Copyright (C) 2006-2011 Free Software Foundation, Inc. @@ -19,9 +18,11 @@ . "${srcdir=.}/init.sh"; path_prepend_ ../src print_ver_ du +cleanup_() { rm -rf "$other_partition_tmpdir"; } +. "$abs_srcdir/other-fs-tmpdir" -mkdir -p b/c y/z || framework_failure_ - +mkdir -p b/c y/z d "$other_partition_tmpdir/x" || framework_failure_ +ln -s "$other_partition_tmpdir/x" d || framework_failure_ # Due to a used-uninitialized variable, the "du -x" from coreutils-6.6 # would not traverse into second and subsequent directories listed @@ -37,4 +38,14 @@ EOF compare exp out || fail=1 +# "du -xL" reported a zero count for a file in a different file system, +# instead of ignoring it. +du -xL d > u || fail=1 +sed 's/^[0-9][0-9]* //' u > out1 +cat <<\EOF > exp1 || fail=1 +d +EOF + +compare exp1 out1 || fail=1 + Exit $fail From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 13 14:59:20 2011 Received: (at 10293) by debbugs.gnu.org; 13 Dec 2011 19:59:20 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RaYVU-0004Af-B7 for submit@debbugs.gnu.org; Tue, 13 Dec 2011 14:59:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RaYVQ-0004AV-VS for 10293@debbugs.gnu.org; Tue, 13 Dec 2011 14:59:19 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pBDJvtvF006263 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Dec 2011 14:57:55 -0500 Received: from [10.3.113.112] (ovpn-113-112.phx2.redhat.com [10.3.113.112]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pBDJvsdH015347; Tue, 13 Dec 2011 14:57:54 -0500 Message-ID: <4EE7AE42.40307@redhat.com> Date: Tue, 13 Dec 2011 12:57:54 -0700 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#10293: [PATCH] du -x should not count files in other file systems References: <4EE7A53F.8070909@cs.ucla.edu> In-Reply-To: <4EE7A53F.8070909@cs.ucla.edu> X-Enigmail-Version: 1.3.4 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig2B5C829C857F6F18E468F101" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Spam-Score: -10.3 (----------) X-Debbugs-Envelope-To: 10293 Cc: 10293@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.3 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2B5C829C857F6F18E468F101 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 12/13/2011 12:19 PM, Paul Eggert wrote: > Here's a proposed patch. The bug is absent from coreutils 5.0 > and present in 5.2.0. I'm guessing from the NEWS files that > it was introduced in 5.1.0 but 5.1.0 is no longer available > at ftp.gnu.org so this isn't trivial for me to check. $ git log --pretty=3Doneline COREUTILS-5_0..COREUTILS-5_2_0 \ src/du.c | wc -l 29 only 29 commits to search from. You can also git bisect on a particular file, if needed. But my guess is commit 95c948b06a, given the changelog line: (process_file, du_files): Rewrite to use fts. which 'git describe' puts after 5.0.91 but before 5.1.0. I think your guess was right. (And I spent more time on this email than I did on searching git - such a change from the CVS days, where I have no idea how long it would have taken to do the same sort of search for a culprit)= =2E --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig2B5C829C857F6F18E468F101 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJO565CAAoJEKeha0olJ0NqPmAH/3VDALJgXFOwEq6HsCtYvRZd cSzSzUksWX/tDBhcbAQnSiqawk8cT2vDkQ3Jrbi8r0etPkUICU3rKqsqFJCB02kp p+07IqSW0aDlup7NNnr5GTcO83Mf7mDiHRN6reD4jD7m2TUFMJmpLwpjBP8s0JwC 7gY8kCLXsW/ovNJSQVWZqiQYG95a6VTkFoTxuGtBfkk+z8JdjhL/OQOo0yYExZGg rd1nHIVxfJEhNdz/e7R/cmqt5EX6H/WU+5GwBHzM1GyKjl2pWxalC1EnRCkOLipX BKuhtavSDQvrS6CIZrhamDamRD6Q5y97j9+oOtD2MlITS6wtzpug72T02B4uaVY= =64Y9 -----END PGP SIGNATURE----- --------------enig2B5C829C857F6F18E468F101-- From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 14 05:49:52 2011 Received: (at 10293) by debbugs.gnu.org; 14 Dec 2011 10:49:52 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RamPI-0007bC-D9 for submit@debbugs.gnu.org; Wed, 14 Dec 2011 05:49:52 -0500 Received: from mx.meyering.net ([88.168.87.75]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RamPG-0007b5-3g for 10293@debbugs.gnu.org; Wed, 14 Dec 2011 05:49:51 -0500 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 2D78E60075; Wed, 14 Dec 2011 11:48:26 +0100 (CET) From: Jim Meyering To: Paul Eggert Subject: Re: bug#10293: [PATCH] du -x should not count files in other file systems In-Reply-To: <4EE7A53F.8070909@cs.ucla.edu> (Paul Eggert's message of "Tue, 13 Dec 2011 11:19:27 -0800") References: <4EE7A53F.8070909@cs.ucla.edu> Date: Wed, 14 Dec 2011 11:48:26 +0100 Message-ID: <874nx3qvid.fsf@rho.meyering.net> Lines: 44 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 10293 Cc: 10293@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) Paul Eggert wrote: > While looking into Bug#10282 I noticed that 'du' is mishandling > the -x option. It relies on FTS_XDEV to not cross file system boundaries, > but FTS_XDEV visits the root of the other file system, causing > 'du' to output a line "0 X" where X is the mount point of the > other file system. This doesn't sound right, since X is in a > different file system and du -x is supposed to ignore files in > other file systems. Also, it disagrees with Solaris 10 du > (at least). > > Here's a proposed patch. The bug is absent from coreutils 5.0 > and present in 5.2.0. I'm guessing from the NEWS files that > it was introduced in 5.1.0 but 5.1.0 is no longer available > at ftp.gnu.org so this isn't trivial for me to check. > > du: -x should not count files in other file systems > * NEWS: Document fix. > * src/du.c (process_file): Don't count files in different file > systems if -x is given. > * tests/du/one-file-system: Test for this bug. Thanks for noticing/fixing that. The fix looks fine. Please include in the commit log the SHA1 that probably induced the bug. Also, a small improvement to the test script below: > diff --git a/NEWS b/NEWS ... > diff --git a/tests/du/one-file-system b/tests/du/one-file-system ... > +# "du -xL" reported a zero count for a file in a different file system, > +# instead of ignoring it. > +du -xL d > u || fail=1 > +sed 's/^[0-9][0-9]* //' u > out1 > +cat <<\EOF > exp1 || fail=1 > +d > +EOF The three lines above can be replaced by this one: echo d > exp1 || fail=1 > +compare exp1 out1 || fail=1 > + > Exit $fail From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 14 21:06:22 2011 Received: (at 10293-done) by debbugs.gnu.org; 15 Dec 2011 02:06:22 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Rb0iD-000776-R9 for submit@debbugs.gnu.org; Wed, 14 Dec 2011 21:06:22 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Rb0iC-000770-9U for 10293-done@debbugs.gnu.org; Wed, 14 Dec 2011 21:06:20 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id E2926A60002; Wed, 14 Dec 2011 18:04:52 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NO1ENEY7bHNt; Wed, 14 Dec 2011 18:04:52 -0800 (PST) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 9007DA60001; Wed, 14 Dec 2011 18:04:52 -0800 (PST) Message-ID: <4EE955C4.3060403@cs.ucla.edu> Date: Wed, 14 Dec 2011 18:04:52 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 MIME-Version: 1.0 To: Jim Meyering Subject: Re: bug#10293: [PATCH] du -x should not count files in other file systems References: <4EE7A53F.8070909@cs.ucla.edu> <874nx3qvid.fsf@rho.meyering.net> In-Reply-To: <874nx3qvid.fsf@rho.meyering.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 10293-done Cc: 10293-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.9 (--) Thanks for the review; I pushed the patch with your suggestions. From unknown Fri Aug 15 02:02:41 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 12 Jan 2012 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator