From owner-freebsd-fs@FreeBSD.ORG Thu Nov 1 22:25:06 2012 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6809B50D for ; Thu, 1 Nov 2012 22:25:06 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 213168FC0A for ; Thu, 1 Nov 2012 22:25:05 +0000 (UTC) Received: by mail-ob0-f182.google.com with SMTP id wc20so3854772obb.13 for ; Thu, 01 Nov 2012 15:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=X49ZvcS8i5JacVUYMB9VPpDIdJL8qf3xuYFByPIWDfg=; b=GZZ6r7K0BxEvVWmSUV2kS/LPEc4EEOD5SFaHGLEuKhKhtw50740mrOCq601OfEtAcU 5cwatRfY5nmJ6OmkdPzGenRD7PLbQ0Yk2HiyHvdI/VUadDf6J91t8+EdK+aiUdKGAs48 JPj4JhDxlagAjuOJZDSh5dXJGWCVSx+XB7CbZ48bMDZCVUst6UGHLpkb13PFdofuf4Je xgPTntl///tZ13WZN3fDzKVtj2JeeSmy4H5GhkM2wDqMbg56b43yrEzcbOBbFU6C3QPd ydiLCIgu+Q7SaqPBRT0WI1KbW5tUF3xVCxsLhVLcLlfxK0BMOTSUH3f0K8pyLAya1kYf 191w== MIME-Version: 1.0 Received: by 10.182.172.74 with SMTP id ba10mr34627427obc.83.1351808705432; Thu, 01 Nov 2012 15:25:05 -0700 (PDT) Received: by 10.76.143.33 with HTTP; Thu, 1 Nov 2012 15:25:05 -0700 (PDT) Date: Thu, 1 Nov 2012 15:25:05 -0700 Message-ID: Subject: Inconsistent/potentially incorrect behavior with relative lookups via chdir(2) on UFS/ZFS From: Garrett Cooper To: FreeBSD FS Content-Type: multipart/mixed; boundary=e89a8f839f6fb10b5f04cd767d72 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Nov 2012 22:25:06 -0000 --e89a8f839f6fb10b5f04cd767d72 Content-Type: text/plain; charset=ISO-8859-1 Hi, Just doing some interop testing on UFS/ZFS to develop a baseline for filesystem behavior, and I noticed some inconsistencies with the ENOENT requirement in chdir(2) when dealing with relative ".." paths (dot-dot lookups). In particular... 1. I would have expected chdir('.') to have failed in UFS/ZFS with ENOENT if '.' wasn't present, but it didn't. 2. I would have expected chdir('..') to have failed in ZFS with ENOENT if '..' wasn't present, but it didn't. Sidenote: python doesn't do any special handling with os.chdir, per Modules/posixmodule.c (I checked). The full test I ran is included below. Thoughts? Thanks, -Garrett # uname -a FreeBSD forza.west.isilon.com 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r240770: Thu Sep 20 19:28:45 PDT 2012 gcooper@forza.west.isilon.com:/usr/obj/usr/src/sys/FORZA amd64 UFS: # (set -x; rm -Rf *; for mc in '' 1; do export MUSICAL_CHAIRS=$mc; for d in '' parent/child; do export BASEDIR=$d; python ~gcooper/pull_rug.py; env CHROOT=1 python ~gcooper/pull_rug.py; done; done) + cd /tmp/foo/bar/baz/ + rm -Rf child parent + for mc in ''\'''\''' 1 + export MUSICAL_CHAIRS= + MUSICAL_CHAIRS= + for d in ''\'''\''' parent/child + export BASEDIR= + BASEDIR= + python /home/gcooper/pull_rug.py did not fail with chdir(.) cwd after is indeterminate + env CHROOT=1 python /home/gcooper/pull_rug.py did not fail with chdir(.) cwd after is indeterminate + for d in ''\'''\''' parent/child + export BASEDIR=parent/child + BASEDIR=parent/child + python /home/gcooper/pull_rug.py did not fail with chdir(.) cwd after is indeterminate + env CHROOT=1 python /home/gcooper/pull_rug.py did not fail with chdir(.) cwd after is indeterminate + for mc in ''\'''\''' 1 + export MUSICAL_CHAIRS=1 + MUSICAL_CHAIRS=1 + for d in ''\'''\''' parent/child + export BASEDIR= + BASEDIR= + python /home/gcooper/pull_rug.py [parent,before] inode is: 9985 [parent,after] inode is: 9988 [child] inode from fstat is: 9985 [child] inode from stat is: 9988 did not fail with chdir(.) cwd after is indeterminate + env CHROOT=1 python /home/gcooper/pull_rug.py [parent,before] inode is: 9989 [parent,after] inode is: 9985 [child] inode from fstat is: 4 did not fail with chdir(.) cwd after is indeterminate + for d in ''\'''\''' parent/child + export BASEDIR=parent/child + BASEDIR=parent/child + python /home/gcooper/pull_rug.py [parent,before] inode is: 5 [parent,after] inode is: 8 [child] inode from fstat is: 5 [child] inode from stat is: 8 did not fail with chdir(.) cwd after is indeterminate + env CHROOT=1 python /home/gcooper/pull_rug.py [parent,before] inode is: 10 [parent,after] inode is: 6 [child] inode from fstat is: 4 did not fail with chdir(.) cwd after is indeterminate ZFS: # (set -x; rm -Rf *; for mc in '' 1; do export MUSICAL_CHAIRS=$mc; for d in '' parent/child; do export BASEDIR=$d; python ~gcooper/pull_rug.py; env CHROOT=1 python ~gcooper/pull_rug.py; done; done) + cd /root/foo/bar/baz/ + rm -Rf child parent + for mc in ''\'''\''' 1 + export MUSICAL_CHAIRS= + MUSICAL_CHAIRS= + for d in ''\'''\''' parent/child + export BASEDIR= + BASEDIR= + python /home/gcooper/pull_rug.py did not fail with chdir(.) did not fail with chdir(../..) cwd after is /root/foo/bar + env CHROOT=1 python /home/gcooper/pull_rug.py did not fail with chdir(.) did not fail with chdir(../..) cwd after is / + for d in ''\'''\''' parent/child + export BASEDIR=parent/child + BASEDIR=parent/child + python /home/gcooper/pull_rug.py did not fail with chdir(.) cwd after is indeterminate + env CHROOT=1 python /home/gcooper/pull_rug.py did not fail with chdir(.) cwd after is indeterminate + for mc in ''\'''\''' 1 + export MUSICAL_CHAIRS=1 + MUSICAL_CHAIRS=1 + for d in ''\'''\''' parent/child + export BASEDIR= + BASEDIR= + python /home/gcooper/pull_rug.py [parent,before] inode is: 3688787 [parent,after] inode is: 3688789 [child] inode from fstat is: 3688787 [child] inode from stat is: 3688789 did not fail with chdir(.) did not fail with chdir(../..) cwd after is /root/foo/bar + env CHROOT=1 python /home/gcooper/pull_rug.py [parent,before] inode is: 3688790 [parent,after] inode is: 3688792 [child] inode from fstat is: 4 did not fail with chdir(.) did not fail with chdir(../..) cwd after is / + for d in ''\'''\''' parent/child + export BASEDIR=parent/child + BASEDIR=parent/child + python /home/gcooper/pull_rug.py [parent,before] inode is: 3688794 [parent,after] inode is: 3688797 [child] inode from fstat is: 3688794 [child] inode from stat is: 3688797 did not fail with chdir(.) cwd after is indeterminate + env CHROOT=1 python /home/gcooper/pull_rug.py [parent,before] inode is: 3688799 [parent,after] inode is: 3688802 [child] inode from fstat is: 4 did not fail with chdir(.) cwd after is indeterminate --e89a8f839f6fb10b5f04cd767d72 Content-Type: application/octet-stream; name="pull_rug.py" Content-Disposition: attachment; filename="pull_rug.py" Content-Transfer-Encoding: base64 X-Attachment-Id: f_h90fv7kp0 IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgppbXBvcnQgZXJybm8KaW1wb3J0IG9zCmltcG9ydCBzaHV0 aWwKaW1wb3J0IHNpZ25hbAppbXBvcnQgc3lzCmltcG9ydCB0cmFjZWJhY2sKaW1wb3J0IHRpbWUK CkNIUk9PVCA9IG9zLmdldGVudignQ0hST09UJykKCmJhc2VkaXIgPSBvcy5lbnZpcm9uLmdldCgn QkFTRURJUicpIG9yICdjaGlsZCcKc3RhcnRpbmdfcHQgPSBDSFJPT1QgYW5kICcvJyBvciBvcy5w YXRoLmpvaW4ob3MuZ2V0Y3dkKCksIGJhc2VkaXIpCmZpbmFsX2Rlc3RpbmF0aW9uID0gb3MucGF0 aC5qb2luKGJhc2VkaXIsICdjaGlsZDEnKQppZiBvcy5wYXRoLmV4aXN0cyhiYXNlZGlyKToKICAg IHNodXRpbC5ybXRy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9zLnBhdGgue2FicyxyZWx9cGF0aC9v cy5zdGF0IGZhaWxzCiAgICAgICAgIyBpZiB0aGUgcGF0aCBpcyBtaXNzaW5nIDspLgogICAgICAg IHByaW50ICdbY2hpbGRdIGlub2RlIGZyb20gZnN0YXQgaXM6Jywgb3MuZnN0YXQoZmQpLnN0X2lu bwogICAgICAgIG9zLnN5c3RlbSgnZWNobyBcW2NoaWxkXF0gaW5vZGUgZnJvbSBzdGF0IGlzOiBg c3RhdCAtZiAlJWkgJXNgJwogICAgICAgICAgICAgICAgICAlIChzdGFydGluZ19wdCwgKSkKCiAg ICBzaWduYWwuYWxhcm0oNSkKICAgIHRyeToKICAgICAgICBwcmludCBvcy5nZXRjd2QoKQogICAg ICAgIHByaW50ICdkaWQgbm90IGZhaWwgd2hlbiBjYWxsaW5nIGdldGN3ZCgpJwogICAgZXhjZXB0 IE9TRXJyb3IgYXMgb3NlOgogICAgICAgIGlmIG9zZS5lcnJubyAhPSBlcnJuby5FTk9FTlQ6CiAg ICAgICAgICAgIHJhaXNlCiAgICB0cnk6CiAgICAgICAgb3MuY2hkaXIoJy4nKQogICAgICAgIHBy aW50ICdkaWQgbm90IGZhaWwgd2l0aCBjaGRpciguKScKICAgIGV4Y2VwdCBPU0Vycm9yIGFzIG9z ZToKICAgICAgICBpZiBvc2UuZXJybm8gIT0gZXJybm8uRU5PRU5UOgogICAgICAgICAgICByYWlz ZQogICAgdHJ5OgogICAgICAgIG9zLmNoZGlyKCcuLi8uLicpCiAgICAgICAgcHJpbnQgJ2RpZCBu b3QgZmFpbCB3aXRoIGNoZGlyKC4uLy4uKScKICAgIGV4Y2VwdCBPU0Vycm9yIGFzIG9zZToKICAg ICAgICBpZiBvc2UuZXJybm8gIT0gZXJybm8uRU5PRU5UOgogICAgICAgICAgICByYWlzZQogICAg dHJ5OgogICAgICAgIHByaW50ICdjd2QgYWZ0ZXIgaXMnLCBvcy5nZXRjd2QoKQogICAgZXhjZXB0 IE9TRXJyb3IgYXMgb3NlOgogICAgICAgIHByaW50ICdpbmRldGVybWluYXRlJwogICAgc2lnbmFs LmFsYXJtKDApCiAgICBvcy5fZXhpdCgwKQoKc3lzLmV4aXQob3Mud2FpdHBpZChjaGlsZF9waWQs IDApWzFdKQo= --e89a8f839f6fb10b5f04cd767d72--