Dave Miner wrote:
J?rgen Keil wrote:
6626043 create_ramdisk could be faster needs a sponsor;
my suggested performance enhancements can be found in the
workaround section of the bug:
http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6626043
My contributor agreement # is OS0003.
I'll sponsor this fix.
Erm... are you interested in a cleanup patch, too ? I just did a quick
look at the script and saw some stuff which could be done better+faster
(most stuff is based on
http://www.opensolaris.org/os/project/shell/shellstyle/), e.g. (the list
is incomplete)
snip
[snip]
28 format=ufs
29 ALT_ROOT=
30 compress=yes
31 SPLIT=unknown
32 ERROR=0
33 dirsize32=0
34 dirsize64=0
Erm... typed variables may be nice (e.g. integer dirsize=0 etc.) ...
35
36 BOOT_ARCHIVE=platform/i86pc/boot_archive
37 BOOT_ARCHIVE_64=platform/i86pc/amd64/boot_archive
38
39 export PATH=$PATH:/usr/sbin:/usr/bin:/sbin
AFAIK this is completely wrong. If $PATH gets added then it should be
after all the primary stuff, otherwise adding something unexpected
which supersets normal tools in /usr/bin/ may cause havoc...
BTW: The script needs to reset LC_NUMERIC to C to avoid that a locale
with a non-'.' decinal delimter blows the script up. AFAIK this sequence
should work:
-- snip --
if [[ ${LC_ALL} != ]] ; then
export \
LC_MONETARY=${LC_ALL} \
LC_MESSAGES=${LC_ALL} \
LC_COLLATE=${LC_ALL} \
LC_CTYPE=${LC_ALL}
unset LC_ALL
fi
export LC_NUMERIC=C
-- snip --
40
41 #
42 # Parse options
43 #
44 while [ $1 != ]
Please use [[ ]] instead of [ ] ... or maybe even better ks93's version
of getopts ...
45 do
46 case $1 in
47 -R) shift
48 ALT_ROOT=$1
49 if [ $ALT_ROOT != / ]; then
50 echo Creating ram disk for $ALT_ROOT
51 fi
52 ;;
53 -n|--nocompress) compress=no
54 ;;
55 *) echo Usage: ${0##*/}: [-R \root\]
[--nocompress]
56 exit
57 ;;
58 esac
59 shift
60 done
61
62 if [ -x /usr/bin/mkisofs -o -x /tmp/bfubin/mkisofs ] ; then
[[ -x /usr/bin/mkisofs || -x /tmp/bfubin/mkisofs ]] may be better...
63 format=isofs
64 fi
65
66 #
67 # mkisofs on s8 doesn't support functionality used by GRUB boot.
68 # Use ufs format for boot archive instead.
69 #
70 release=`uname -r`
Please use POSIX syntax, e.g. release=$(uname -r)
71 if [ $release = 5.8 ]; then
72 format=ufs
73 fi
74
75 shift `expr $OPTIND - 1`
Please use builtin math, e.g. shift $((OPTIND - 1))
76
77 if [ $# -eq 1 ]; then
Please use arthmetric expressions for ksh scripts, e.g.
-- snip --
if (( $# == 1 )); then
-- snip --
78 ALT_ROOT=$1
79 echo Creating ram disk for $ALT_ROOT
Please use print, not echo (or maybe...
-- snip --
printf Creating ram disk for %s\n $ALT_ROOT
-- snip --
... is better...
80 fi
81
82 rundir=`dirname $0`
Please use POSIX shell syntax, e.g.
-- snip --
rundir=$(dirname $0)
[snip - endless bickering removed]
109 function getsize
110 {
111 # Estimate image size and add 10% overhead for ufs stuff.
112 # Note, we can't use du here in case we're on a filesystem,
e.g. zfs,
113 # in which the disk usage is less than the sum of the file
sizes.
114 # The nawk code
115 #
116 # {t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
117 #
118 # below rounds up the size of a file/directory, in bytes, to
the
119 # next multiple of 1024. This mimics the behavior of ufs
especially
120 # with directories. This results in a total size that's
slightly
121 # bigger than if du was called on a ufs directory.
122 size32=$(cat $list32 | xargs -I {} ls -lLd {} | nawk '
123 {t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
124 END {print int(t * 1.10 / 1024)}')
125 (( size32 += dirsize32 ))
126 size64=$(cat $list64 | xargs -I {} ls -lLd {} | nawk '
127 {t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
128 END {print int(t * 1.10 / 1024)}')
129 (( size64 += dirsize64 ))
130 (( total_size = size32 + size64 ))
Erm... AFAIK the use of xargs/nawk/etc. could be replaced by ksh93
builtin math...
131 }
132
133 #
134 # Copies all desired files to a target directory. One argument
should be
135 # passed: the file containing the list of files to copy. This
function also
136 # depends on several variables that must be set