Permalink
Browse files

use find|cpio instead of gen_init_cpio

This is a substantial change in direction which trades off some disk
usage in /tmp for a large increase in speed. This also removes the
add_device API which shouldn't be necessary anyways. It further
simplifies the rest of the API because directories are created via
install, and creation order becomes less relevant.
  • Loading branch information...
1 parent b02ebb9 commit 61ed3b4b8bd347cc7c0a2a5afc297274a1596ab3 @falconindy committed Apr 29, 2011
Showing with 46 additions and 112 deletions.
  1. +34 −73 geninit
  2. +12 −39 geninit.api
View
@@ -28,7 +28,7 @@ EINVAL=22
# globals
declare -i automods=0
-declare -i savefilelist=0
+declare -i savebuildroot=0
declare basedir=
declare config=
declare imagename=
@@ -73,7 +73,11 @@ kmodinfo() { # {{{
} # }}}
cleanup() { # {{{
- rm -rf "$tmpdir"
+ if (( savebuildroot )); then
+ info "buildroot preserved at: $buildroot"
+ else
+ rm -rf "$tmpdir"
+ fi
exit $1
} # }}}
@@ -90,7 +94,7 @@ Usage: geninit [options]
-k <kver> Specify a different kernel version (default: $(uname -r))
-p <preset> Build using a preset file
-S <names> Skip the specified builders during the build process
- -v Output more
+ -s Preserve buildroot after image creation
-z <method> Override compression method
USAGE
@@ -102,74 +106,48 @@ USAGE
# --------------- #
__add_file() { # {{{
- # add a file to cpio_filelist
+ # add a file to $buildroot
# $1: pathname on initcpio
# $2: source on disk
# $3: mode
- # file <dest> <src> <mode> <uid> <gid> [<hard links>]
-
(( $# == 3 )) || return $EINVAL
+ [[ -e $buildroot$1 ]] && return $EEXIST
- qgrep "^file $1 " "$cpio_filelist" && return $EEXIST
- printf 'file %s %s %s 0 0\n' "$@" >>"$cpio_filelist"
+ install -Dm$3 "$2" "$buildroot$1"
} # }}}
__add_dir() { # {{{
- # add a directory to cpio_filelist (no knowledge of parents, use add_path instead)
+ # add a directory (with parents) to $buildroot
# $1: pathname on initcpio
# $2: mode
- # dir <name> <mode> <uid> <gid>
-
(( $# == 2 )) || [[ $1 == /?* ]] || return $EINVAL
+ [[ -e $buildroot$1 ]] && return $EEXIST
- local name=$1 mode=$2
-
- qgrep "^dir $name " "$cpio_filelist" && return $EEXIST
- printf 'dir %s %s 0 0\n' "$@" >>"$cpio_filelist"
+ install -dm$2 "$buildroot$1"
} # }}}
__add_slink() { # {{{
- # add a symlink to cpio_filelist
+ # add a symlink to $buildroot
# $1: name on initcpio
# $2: target of $1
- # slink <name> <target> <mode> <uid> <gid>
-
(( $# == 2 )) || return $EINVAL
+ [[ -L $buildroot$1 ]] && return $EEXIST
- local name=$1 target=$2
-
- qgrep "^slink $name " "$cpio_filelist" && return $EEXIST
- printf 'slink %s %s 777 0 0\n' "$name" "$target" >> "$cpio_filelist"
+ ln -s "$2" "$buildroot$1"
} # }}}
__add_pipe() { # {{{
- # add a pipe to cpio_filelist
+ # add a pipe to $buildroot
# $1: pathname on initcpio
# $2: mode
- # pipe <name> <mode> <uid> <gid>
-
(( $# == 2 )) || return $EINVAL
+ [[ -e $buildroot$1 ]] && return $EEXIST
- local name=$1 mode=$2
-
- qgrep "^pipe $name " "$cpio_filelist" && return $EEXIST
- printf 'pipe %s %s 0 0\n' "$name" "$mode" >> "$cpio_filelist"
-} # }}}
-
-__add_sock() { # {{{
- # add a socket to cpio_filelist
- # $1: pathname on initcpio
- # $2: mode
-
- # sock <name> <mode> <uid> <gid>
- local name=$1 mode=$2
-
- qgrep "^sock $name " "$cpio_filelist" && return $EEXIST
- printf 'sock %s %s 0 0\n' "$name" "$mode" >> "$cpio_filelist"
+ mkfifo -m$2 "$buildroot$1"
} # }}}
__build_image() { # {{{
@@ -193,7 +171,7 @@ __build_image() { # {{{
continue
fi
- info "Processing buildstep: [$builder]"
+ info "Building: [$builder]"
build
done
@@ -207,35 +185,15 @@ __build_image() { # {{{
add_file "$file"
done
- # generate depmod files
info "Generating module dependencies"
- while read line; do
- if [[ $line =~ /lib/modules/[^[:space:]]+\.ko?(.gz) ]]; then
- module=${BASH_REMATCH[0]}
- install -Dm644 "$basedir$module" "$tmpdir$module"
- (( ++modcount ))
- fi
- done < "$cpio_filelist"
+ depmod -b "$buildroot" "$kernver"
- if (( modcount )); then
- depmod -b "$tmpdir" "$kernver"
- for file in modules.{dep,alias,symbols}; do
- add_file "${tmpdir}${moduledir}/$file" "/lib/modules/$kernver/$file"
- done
- fi
-
- if (( savefilelist )); then
- imagename=${imagename:-image} # set during a dry-run
- if cp "$cpio_filelist" "/tmp/${imagename##*/}.filelist"; then
- info "image filelist saved to /tmp/${imagename##*/}.filelist"
- else
- err "failed to save filelist to /tmp" # should never happen
- fi
- fi
+ # this must be resolved to an absolute path
+ imagename=$(readlink -f "$imagename")
if (( dryrun )); then
info "Dry run complete. Use -g <path> to create an initramfs."
- cleanup 0
+ return
fi
if [[ $compress != cat ]]; then
@@ -244,14 +202,18 @@ __build_image() { # {{{
fi
info "Creating$([[ $compress = cat ]] || printf " $compress") initramfs: $imagename"
- gen_init_cpio $cpio_filelist | "$compress" "${zopts[@]}" > "$imagename"
+
+ pushd "$buildroot" &>/dev/null
+ find . -print0 | cpio -0oH newc | "$compress" "${zopts[@]}" > "$imagename"
+ popd &>/dev/null
+
pipesave=("${PIPESTATUS[@]}") # save immediately
+ (( pipesave[0] )) && die "failed to create filelist (find reported error)"
+ (( pipesave[1] )) && die "failed to create cpio archive (cpio reported error)"
+ (( pipesave[2] )) && die "$compress reported error compressing image"
- (( pipesave[0] )) && die "failed to create initramfs image"
- (( pipesave[1] )) && die "error compressing initramfs image"
info "Image creation completed successfully"
- return $(( !!(pipesave[0] + pipesave[1]) ))
} # }}}
__build_preset() { # {{{
@@ -338,7 +300,7 @@ while getopts ':b:c:g:hk:Mp:S:sz:' flag; do
M) automods=1 ;;
p) preset=$OPTARG ;;
S) skipbuilders=(${OPTARG//,/ }) ;;
- s) savefilelist=1 ;;
+ s) savebuildroot=1 ;;
z) ocompress=$OPTARG ;; # named differently to allow overriding
:) die "option requires an argument -- '$OPTARG'" ;;
\?) die "invalid option -- '$OPTARG'" ;;
@@ -391,8 +353,7 @@ fi
# define a few paths for convenience
tmpdir=$(mktemp -d /tmp/${0##*/}.XXXXXX)
-moduletmp=$tmpdir/modules
-cpio_filelist=$tmpdir/cpiofilelist.$$
+buildroot=$tmpdir/root
autodetect_cache=$tmpdir/autodetect.cache
moduledir=/lib/modules/$kernver
View
@@ -11,26 +11,8 @@
shopt -s extglob
-add_dirpath() { # {{{
- # add all elements of a path (equivalent of mkdir -p)
- # $1: an absolute path
-
- [[ $1 == /?* ]] || return 1 # must be an absolute path, but not root itself
-
- local path=
- local -a pieces
-
- IFS='/' read -ra pathparts <<< "$1"
-
- for part in "${pathparts[@]}"; do
- [[ $part ]] || continue
- path+=/$part
- add_dir "$path"
- done
-} # }}}
-
add_dir() { # {{{
- # add a directory (equivalent of mkdir *without* -p)
+ # add a directory (with parents)
# $1: absolute path on initcpio
# $2: mode (optional, defaults to 755)
@@ -62,7 +44,7 @@ add_file() { # {{{
return 1
fi
- add_path_to_file "$dest"
+ #add_path_to_file "$dest"
__add_file "$dest" "$src" "$mode"
} # }}}
@@ -81,7 +63,7 @@ add_symlink() { # {{{
add_path_to_file() { # {{{
# add the path leading up to a file
# $1: filename with full path
- [[ $1 ]] && add_dirpath "${1%/*}"
+ [[ $1 ]] && add_dir "${1%/*}"
} # }}}
add_module() { # {{{
@@ -130,7 +112,7 @@ add_binary() { # {{{
[[ -f $basedir$1 ]] || { err "$1 not found"; return 1; }
local -a sodeps
- local binary=$basedir$1 sodep=
+ local binary=$basedir$1 sodep= resolved=
if ! "$ld_so" --verify "$binary"; then
# this isn't a binary!
@@ -148,8 +130,10 @@ add_binary() { # {{{
if [[ ! -L $sodep ]]; then
add_file "$sodep"
else
- add_symlink "$sodep" "$(readlink -e "$sodep")"
- add_file "$(readlink -e "$sodep")"
+ resolved="$(readlink -e "$sodep")"
+ __add_dir "${resolved%/*}" 755
+ __add_slink "$sodep" "$resolved"
+ add_file "$resolved"
fi
fi
done
@@ -162,21 +146,10 @@ add_binary() { # {{{
add_file "$(readlink -e "$ld_so")"
} # }}}
-add_device() { # {{{
- # add a device node to cpio_filelist
- # $1: pathname on initcpio
- # $2: device type (b=block or c=character)
- # $3: device major
- # $4: device minor
- # $5: mode (optional, defaults to 644)
-
- # nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
- (( $# == 4 )) || (( $# == 5 )) || return 1
- [[ $2 = [bc] ]] || return 1
-
- qgrep "^nod $1 " "$cpio_filelist" && return 1
- printf 'nod %s %s 0 0 %s %s %s\n' "$1" "${5:-644}" "${@:2:3}" >> "$cpio_filelist"
-} # }}}
+add_pipe() {
+ # IOU: one pipe adding function
+ :
+}
use_hookscript() { # {{{
# specifies that a builder should install a hookscript

0 comments on commit 61ed3b4

Please sign in to comment.