From owner-freebsd-bugs Wed Apr 11 10:20:11 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id AAF0737B42C for ; Wed, 11 Apr 2001 10:20:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f3BHK1X72843; Wed, 11 Apr 2001 10:20:01 -0700 (PDT) (envelope-from gnats) Received: from lurza.secnetix.de (lurza.secnetix.de [212.66.1.130]) by hub.freebsd.org (Postfix) with ESMTP id E430037B422 for ; Wed, 11 Apr 2001 10:15:29 -0700 (PDT) (envelope-from olli@secnetix.de) Received: from monos.secnetix.net (monos.secnetix.net [172.20.20.5]) by lurza.secnetix.de (8.9.3/8.9.3) with ESMTP id TAA77865 for ; Wed, 11 Apr 2001 19:15:28 +0200 (CEST) (envelope-from olli@secnetix.de) Received: (from olli@localhost) by monos.secnetix.net (8.11.1/8.9.3) id f3BHFST88472; Wed, 11 Apr 2001 19:15:28 +0200 (CEST) (envelope-from olli@secnetix.de) Message-Id: <200104111715.f3BHFST88472@monos.secnetix.net> Date: Wed, 11 Apr 2001 19:15:28 +0200 (CEST) From: olli@fromme.com Reply-To: olli@fromme.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/26498: Fix for bug in union mounts (mout -o union) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 26498 >Category: bin >Synopsis: Fix for bug in union mounts (mout -o union) >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Apr 11 10:20:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Oliver Fromme >Release: FreeBSD 4.3-RC2-LEHMANNS >Organization: My head is still at the top, and the feets are at the bottom. >Environment: The fix presented in this PR applies to 4-stable as well as 5-current. >Description: When you mount a directory on top of another, using the "union" option to the mount command (I'm NOT talking about UNIONFS!), then all entries which are present in both directories appear twice, like this: $ ls -a . .. bar bar1 baz baz1 foo foo1 . .. bar bar2 baz baz2 foo foo2 It is particularly disturbing that "." and ".." appear twice, even if the directories are otherwise disjunct. Same problem with /usr/bin/find, /bin/sh (``echo *'') and all other tools that read and traverse directories. The culprit is in src/lib/libc/gen/opendir.c in the function __opendir2(). Look at the variable "unionstack" (near line 110). It is correctly set to 1 in the case of a UNIONFS -- in this case the code removes duplicates. However, it doesn't handle the case of a union mount. >How-To-Repeat: /* Create two small vnode filesystems, /bin/sh syntax: */ for i in 0 1; do dd if=/dev/zero of=fs$i.vn bs=1m count=1 vnconfig -s labels -c vn$i fs$i.vn disklabel -r -w vn$i auto newfs /dev/vn${i}c done /* Mount them over each other: */ mkdir fs mount /dev/vn0c fs mount -o union /dev/vn1c fs ls -a . . .. .. /* Note that "." and ".." appear twice. */ >Fix: The following patch fixes the problem by simply checking if the MNT_UNION flag is set in the statfs struct. The patch is against rev. 1.10 (4-stable as of 2000-04-10). I have had a look at the code in current, and the fix should be applicable there, too. I haven't actually tested it, due to lack of a -current machine, but the fix is trivial enough for me to be sure that it should work. :-) I have this code in production on a box with several jails, all of them containing union-mounted filesystems, and everything works fine. *phew* Such a long PR for a one-line fix ... --- src/lib/libc/gen/opendir.c.orig Fri Jan 28 00:06:18 2000 +++ src/lib/libc/gen/opendir.c Wed Apr 11 18:44:26 2001 @@ -110,7 +110,8 @@ if (fstatfs(fd, &sfb) < 0) goto fail; - unionstack = !strcmp(sfb.f_fstypename, "union"); + unionstack = !strcmp(sfb.f_fstypename, "union") + || (sfb.f_flags & MNT_UNION); } else { unionstack = 0; } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message