1#! /bin/sh 2 3# Copyright (C) 2002 by Martin Pool <mbp@samba.org> 4 5# This program is distributable under the terms of the GNU GPL (see 6# COPYING). 7 8# Test rsync handling of devices. This can only run if you're root. 9 10. "$suitedir/rsync.fns" 11 12chkfile="$scratchdir/rsync.chk" 13outfile="$scratchdir/rsync.out" 14 15# Build some hardlinks 16 17case $0 in 18*fake*) 19 $RSYNC --version | grep "[, ] xattrs" >/dev/null || test_skipped "Rsync needs xattrs for fake device tests" 20 RSYNC="$RSYNC --fake-super" 21 TLS_ARGS="$TLS_ARGS --fake-super" 22 case "$HOST_OS" in 23 darwin*) 24 mknod() { 25 fn="$1" 26 case "$2" in 27 p) mode=10644 ;; 28 c) mode=20644 ;; 29 b) mode=60644 ;; 30 esac 31 maj="${3:-0}" 32 min="${4:-0}" 33 touch "$fn" 34 xattr -s 'rsync.%stat' "$mode $maj,$min 0:0" "$fn" 35 } 36 ;; 37 solaris*) 38 mknod() { 39 fn="$1" 40 case "$2" in 41 p) mode=10644 ;; 42 c) mode=20644 ;; 43 b) mode=60644 ;; 44 esac 45 maj="${3:-0}" 46 min="${4:-0}" 47 touch "$fn" 48 runat "$fn" "$SHELL_PATH" <<EOF 49echo "$mode $maj,$min 0:0" > rsync.%stat 50EOF 51 } 52 ;; 53 freebsd*) 54 mknod() { 55 fn="$1" 56 case "$2" in 57 p) mode=10644 ;; 58 c) mode=20644 ;; 59 b) mode=60644 ;; 60 esac 61 maj="${3:-0}" 62 min="${4:-0}" 63 touch "$fn" 64 setextattr -h user "rsync.%stat" "$mode $maj,$min 0:0" "$fn" 65 } 66 ;; 67 *) 68 mknod() { 69 fn="$1" 70 case "$2" in 71 p) mode=10644 ;; 72 c) mode=20644 ;; 73 b) mode=60644 ;; 74 esac 75 maj="${3:-0}" 76 min="${4:-0}" 77 touch "$fn" 78 setfattr -n 'user.rsync.%stat' -v "$mode $maj,$min 0:0" "$fn" 79 } 80 ;; 81 esac 82 ;; 83*) 84 my_uid=`get_testuid` 85 root_uid=`get_rootuid` 86 if test x"$my_uid" = x; then 87 : # If "id" failed, try to continue... 88 elif test x"$my_uid" != x"$root_uid"; then 89 if [ -e "$FAKEROOT_PATH" ]; then 90 echo "Let's try re-running the script under fakeroot..." 91 exec "$FAKEROOT_PATH" "$SHELL_PATH" $RUNSHFLAGS "$0" 92 fi 93 test_skipped "Rsync needs root/fakeroot for device tests" 94 fi 95 ;; 96esac 97 98# TODO: Need to test whether hardlinks are possible on this OS/filesystem 99 100$RSYNC --version | grep "[, ] hardlink-special" >/dev/null && CAN_HLINK_SPECIAL=yes || CAN_HLINK_SPECIAL=no 101 102mkdir "$fromdir" 103mkdir "$todir" 104mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node" 105mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node" 106mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node" 107mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node" 108mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node" 109mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node" 110if test "$CAN_HLINK_SPECIAL" = yes; then 111 ln "$fromdir/block3" "$fromdir/block3.5" 112else 113 echo "Skipping hard-linked device test..." 114fi 115mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo" 116# Work around time rounding/truncating issue by touching both files. 117touch -r "$fromdir/block" "$fromdir/block" "$fromdir/block2" 118 119$RSYNC -ai "$fromdir/block" "$todir/block2" \ 120 | tee "$outfile" 121cat <<EOT >"$chkfile" 122cD$all_plus block 123EOT 124diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" 125 126$RSYNC -ai "$fromdir/block2" "$todir/block" \ 127 | tee "$outfile" 128cat <<EOT >"$chkfile" 129cD$all_plus block2 130EOT 131diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" 132 133sleep 1 134 135$RSYNC -Di "$fromdir/block3" "$todir/block" \ 136 | tee "$outfile" 137cat <<EOT >"$chkfile" 138cDc.T.$dots block3 139EOT 140diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" 141 142$RSYNC -aiHvv "$fromdir/" "$todir/" \ 143 | tee "$outfile" 144filter_outfile 145cat <<EOT >"$chkfile" 146.d..t.$dots ./ 147cDc.t.$dots block 148cDc...$dots block2 149cD$all_plus block3 150hD$all_plus block3.5 => block3 151cD$all_plus char 152cD$all_plus char2 153cD$all_plus char3 154cS$all_plus fifo 155EOT 156if test "$CAN_HLINK_SPECIAL" = no; then 157 grep -v block3.5 <"$chkfile" >"$chkfile.new" 158 mv "$chkfile.new" "$chkfile" 159fi 160diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" 161 162echo "check how the directory listings compare with diff:" 163echo "" 164( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from" 165( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to" 166diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" 167 168if test "$CAN_HLINK_SPECIAL" = yes; then 169 set -x 170 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \ 171 | tee "$outfile" 172 cat <<EOT >"$chkfile" 173cd$allspace ./ 174hD$allspace block 175hD$allspace block2 176hD$allspace block3 177hD$allspace block3.5 178hD$allspace char 179hD$allspace char2 180hD$allspace char3 181hS$allspace fifo 182EOT 183 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed" 184fi 185 186# The script would have aborted on error, so getting here means we've won. 187exit 0 188