#!/bin/bash makelinks() { ( local volume=$1 local file=$2 # ignored in this version echostep Making as many links as possible on $volume # Iterate until the ln command fails set -e cd $volume mkdir -p links for a in 0 1 2 3 4 5 6 7 8 9 ; do for b in 0 1 2 3 4 5 6 7 8 9 ; do echo making 10,000 pairs of hard-linked files ... mkdir -p links/$a$b for c in 0 1 2 3 4 5 6 7 8 9 ; do for d in 0 1 2 3 4 5 6 7 8 9 ; do mkdir -p links/$a$b/$c$d for e in 0 1 2 3 4 5 6 7 8 9 ; do for f in 0 1 2 3 4 5 6 7 8 9 ; do file=links/$a$b/$c$d/$e$f touch ${file}a ln ${file}a ${file}b done done done done done done ) } makelinksAllToOneFile() { ( local volume=$1 local file=$2 echostep Making as many links as possible on $volume # Iterate until the ln command fails set -e cd $volume mkdir -p links for a in 0 1 2 3 4 5 6 7 8 9 ; do for b in 0 1 2 3 4 5 6 7 8 9 ; do echo making 10,000 hard links ... mkdir -p links/$a$b for c in 0 1 2 3 4 5 6 7 8 9 ; do for d in 0 1 2 3 4 5 6 7 8 9 ; do mkdir -p links/$a$b/$c$d for e in 0 1 2 3 4 5 6 7 8 9 ; do for f in 0 1 2 3 4 5 6 7 8 9 ; do ln -f $file links/$a$b/$c$d/$e$f done done done done done done ) } createRamVolume() { #!/bin/sh # Copyright 2008 DIGLLOYD INC # # constants for crd (create ram disk) # Copyright 2008 DIGLLOYD INC # # http://macperformanceguide.com/Mac-HowToUseARAMDisk.html # original name is crd; modify time 2010-01-19.12:19:59 # minimum allowed size MIN_MB=32 # maximum allowed size MAX_MB=60000 # base name for ram disks VOLUME_NAME_BASE=RamDisk echo "" echo "Copyright 2010, DIGLLOYD INC. All Rights Reserved" echo "See our performance tools at http://macperformanceguide.com/Software-Main.html" echo "" echo "This script is designed for Mac OS X Snow Leopard 10.6.x only!." echo "Do not use it with OS X Leopard (10.5) or earlier." echo "..." echo "" PROG_NAME=$0 EXAMPLE="${PROG_NAME} 4096 RamDisk1" if [ -n "$3" ]; then echo Too many arguments. Specify size in MB then volume name. Example: echo $EXAMPLE exit fi if [ -z "$2" ]; then echo Specify size in MB then volume name. Example: echo $EXAMPLE exit fi if [ -z "$1" ]; then echo Specify size in MB then volume name. Example: echo $EXAMPLE exit fi MB_SIZE=$1 DISK_NAME=$2 if [ ${MB_SIZE} -lt ${MIN_MB} ]; then echo RAM disk size minimum ${MIN_MB}MB, maximum ${MAX_MB}MB. echo $EXAMPLE exit fi if [ ${MB_SIZE} -gt ${MAX_MB} ]; then echo RAM disk size minimum ${MIN_MB}MB, maximum ${MAX_MB}MB. echo $EXAMPLE exit fi if [ -e /Volumes/$DISK_NAME ]; then echo Volume \"$DISK_NAME\" already exists, to unmount use: hdiutil detach /Volumes/$DISK_NAME exit fi BLOCKS=${MB_SIZE} let "BLOCKS *= 2048" echo Creating ${MB_SIZE} MB ram disk named ${DISK_NAME} echo hdid -nomount ram://$BLOCKS CREATED_RAMDISK=`hdid -nomount ram://$BLOCKS` echo New block device: ${CREATED_RAMDISK} #DISK_NAME=`basename ${CREATED_RAMDISK}` echo Creating volume named: ${DISK_NAME} newfs_hfs -v ${DISK_NAME} /dev/$CREATED_RAMDISK echo Mounting in /Volumes/${DISK_NAME} #mkdir /Volumes/${DISK_NAME} diskutil mount ${CREATED_RAMDISK} open -a Finder /Volumes/$DISK_NAME echo "" echo "RamDisk '${DISK_NAME}' created, ${MB_SIZE}MB" } createVolume() { ( local name=$1 local volume=/Volumes/$name echostep Creating and mounting $volume if [[ ! -e $volume ]] ; then createRamVolume 32 $name return 1 else echo $volume already exists. return 0 fi ) } clearVolume() { local name=$1 if [[ -z $name ]] ; then echo dangerous bug, exiting exit 2 fi local volume=/Volumes/$name shopt -u nullglob files=$(echo $volume/*) if [[ "$files" != $volume/'*' ]] ; then echo "Removing $volume/*" rm -rf $volume/* fi } numberOfFiles() { local volume=$1 echostep "Number of files on $volume: " find $volume -type f | lines } lines() { wc | awk '{ print $1}' } echodo() { eval "echo-command $@" eval "$@" } echo-command() { echo -n "[ " echo -n $@ echo " ]" } echostep() { echo echo '========' "$@" } #=============================================================================== sourceName=LottaLinks ; source=/Volumes/$sourceName destName=Copy ; dest=/Volumes/$destName echostep "Test copying lots of hard links" echo " Make two minimal-sized ram disks, '$source' and '$dest'. Populate $source with as many hard links sharing a single file as possible. Copy $source to $dest. See if it worked properly." if ! createVolume $sourceName ; then echostep Populate the source volume filename=sleep rsync -a /bin/$filename $source makelinks $source $filename fi createVolume $destName numberOfFiles $source for x in \ "/usr/bin/rsync -a --hard-links" # "/Local/Software/CCC/rsync -a --hard-links" \ # "/usr/local/bin/rsync -a --hard-links" # ditto do echostep "Clear volume $dest" clearVolume $destName echostep Copy using $x echodo $x $source/ $dest numberOfFiles $dest done