chmod -h 000x against symlink has bizarre results on ZFS

Trent Nelson trent at snakebite.org
Fri Aug 24 07:43:12 UTC 2012


On Thu, Aug 23, 2012 at 06:15:17PM -0700, Trent Nelson wrote:
>     Here's the output from the attached test_readlink.sh, also available
>     at http://bugs.python.org/file26979/test_readlink.sh:

    Looks like the attachment got stripped.  I've pasted it below.

        Trent.

-- test_readlink.sh --

#!/bin/sh

# If /tmp isn't backed by a ZFS file system, change it to something that is.
_base=/tmp
if [ -z "$(zfs list -H -o mountpoint | grep ^$_base)" ]; then
    echo error: \'$_base\' is not backed by ZFS
    exit 1
fi
_python=$(which python 2> /dev/null)

_test() {
    local _file _symlink _py
    _file=$1
    _mode=$2
    if [ -z "$_mode" ]; then
        _mode=0007
    fi
    _symlink=$_file.lnk
    _py="import os; print(repr(os.readlink('$_symlink')))"
    rm -rf $_file $_symlink

    echo file > $_file
    ln -s $_file $_symlink
    echo before chmod -h $_mode:
    ls -l $_file | awk '{ print $1 " " $9 };'
    ls -l $_symlink | awk '{ print $1 " " $9 $10 $11 };'
    if [ -f "$_python" ]; then
        echo "python os.readlink($_symlink): "
        eval "$_python" -c \""$_py"\"
    fi

    chmod -h $_mode $_symlink
    echo after chmod -h $_mode:
    ls -l $_file | awk '{ print $1 " " $9 };'
    ls -l $_symlink | awk '{ print $1 " " $9 $10 $11 };'
    if [ -f "$_python" ]; then
        echo "python os.readlink($_symlink): "
        eval "$_python" -c \""$_py"\"
    fi
}

_quick_test() {
    local _file _symlink
    _file=$1
    _mode=$2
    if [ -z "$_mode" ]; then
        _mode=0007
    fi
    _symlink=$_file.lnk
    rm -rf $_file $_symlink

    echo file > $_file
    ln -s $_file $_symlink
    chmod -h $_mode $_symlink
    echo after chmod -h $_mode:
    ls -l $_symlink | awk '{ print $1 " " $9 $10 $11 };'
}

echo
echo "****** TEST 1: link/target length less than 24 ******"
_test $_base/lt24
echo " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
echo "target is padded out with NULLs to 24"
echo; echo
for _ in 1 2 ; do echo; done

echo "****** TEST 2: link/target length longer than 24 ******"
_test $_base/definitelywaylongerthantwentyfour
echo " ^^^^^^^^^^^^^^^^^^^^^^^^"
echo "target gets truncated to 24"
echo; echo

echo
echo "****** Other modes... ******"
_quick_test $_base/definitelywaylongerthantwentyfour 0006
_quick_test $_base/definitelywaylongerthantwentyfour 0005
_quick_test $_base/definitelywaylongerthantwentyfour 0004
_quick_test $_base/definitelywaylongerthantwentyfour 0000
echo; echo


# vim:set ts=8 sw=4 sts=4 tw=78 et:



More information about the freebsd-fs mailing list