DF-2462 / gen.sh
#!/bin/sh # gen.sh -- run ON THE GUEST. Concatenates the DF-2462 harness around # VERBATIM copies of the iscsi initiator sources: # # df_pre.c # + <verbatim dev/disk/iscsi/initiator/isc_sm.c> (whole file) # + <verbatim isc_cam.c: ic_lost_target> (by function name) # + <verbatim isc_cam.c: _inq> # + <verbatim isc_cam.c: _scsi_encap> # + <verbatim isc_cam.c: ic_action> # + <verbatim iscsi_subr.c: dwl> # + <verbatim iscsi_subr.c: scsi_encap> # + <verbatim isc_subr.c: i_freeopt> # + df_post.c # # -> dev/disk/iscsi/initiator/dfiscsi_harness.c, registered in # conf/files as "standard" (the X86_64_GENERIC kernel does not # configure "device iscsi_initiator"; conf/files marks all iscsi # initiator files "optional iscsi_initiator scbus", so the verbatim # copies inside the harness TU are the only compiled instances). # # Functions are extracted BY NAME (line ranges shift between the # baseline and fix.diff-patched sources; the names do not). The # driver text is byte-for-byte from the source file -- build.sh's # sha256 gate pins the pristine tree (via the .orig copies made by # the first gen.sh run); make_fixed.sh pins the patched tree. set -e cd /usr/src/sys/dev/disk/iscsi/initiator # keep pristine originals (build.sh gates their sha256) for f in isc_sm.c isc_cam.c iscsi_subr.c isc_subr.c iscsi.c iscsi.h iscsivar.h; do [ -f "$f.orig" ] || cp -n "$f" "$f.orig" done # the empty option header the kernel build would normally generate [ -f opt_iscsi_initiator.h ] || : > opt_iscsi_initiator.h # getfn <file> <funcname>: prints the function definition, starting # at its preceding type line ("void", "int", "static void", ...), # through its column-0 closing brace. Driver style keeps nested # braces indented, so a col-0 "}" only closes the function. getfn() { # match the function NAME at column 0 followed by '(' -- no regex # (DF awk's -v mangles backslashes) awk -v fn="$2" ' substr($0, 1, length(fn)) == fn && substr($0, length(fn)+1, 1) == "(" \ && !printing { printing = 1; print prev; print; next } { if (!printing) prev = $0 } printing { print; if ($0 == "}") exit } ' "$1" } { cat df_pre.c cat isc_sm.c getfn isc_cam.c ic_lost_target getfn isc_cam.c _inq getfn isc_cam.c _scsi_encap getfn isc_cam.c ic_action getfn iscsi_subr.c dwl getfn iscsi_subr.c scsi_encap getfn isc_subr.c i_freeopt cat df_post.c } > dfiscsi_harness.c cd /usr/src/sys grep -q 'dfiscsi_harness' conf/files || \ printf 'dev/disk/iscsi/initiator/dfiscsi_harness.c\t\tstandard\n' >> conf/files echo "generated dev/disk/iscsi/initiator/dfiscsi_harness.c" \ "($(wc -l < dev/disk/iscsi/initiator/dfiscsi_harness.c) lines)" echo " slices (lines): ic_lost_target=$(getfn isc_cam.c ic_lost_target | wc -l)" \ "_inq=$(getfn isc_cam.c _inq | wc -l)" \ "_scsi_encap=$(getfn isc_cam.c _scsi_encap | wc -l)" \ "ic_action=$(getfn isc_cam.c ic_action | wc -l)" \ "dwl=$(getfn iscsi_subr.c dwl | wc -l)" \ "scsi_encap=$(getfn iscsi_subr.c scsi_encap | wc -l)" \ "i_freeopt=$(getfn isc_subr.c i_freeopt | wc -l)" grep -n 'dfiscsi_harness' conf/files |