Pull in r3828 from upstream (remove dead code, fix prototypes)
Import Apache apr-1.4.8 to vendor staging area.
Merge ^/head/usr.bin/mkimg@265546
Eliminate mkimg_seek() by moving the lseek(2) calls into fdcopy().
While here, minimize use of the global tmpfd by passing it as ofd
to mkimg.
Abstract the use of ftruncate(2) behind mkimg_set_size().
Add image.c and image.h. These files will contain functions to implement
the management of the raw image that's being created. The most notable of
the API is that there's no file descriptor argument. This is because the
image is managed in memory.

Once we have the in-memory (raw) image, we can write it out acording to
different formats. This two-pass approach shields schemes from formats
and formats from schemes.
Switch to the image API:
1.  Replace calls to mkimg_set_size() with calls to image_set_size()
2.  Remove the mkimg_set_size() function
3.  As above but for mkimg_write() and image_write()

Note that this breaks mkimg(1). The image API has no implementation.
Hence doing it on my branch :-)
Replace 2 instances of fdcopy() with image_copyin(). With this, the
mkimg() function does not need the ofd argument and all references
to an output file descriptor in the input phase are gone.
Provide a file-based implementation for the image API. This almost
copies the logic verbatim from mkimg.c to image.c. The difference
is that in image.c the temporary file is always created, whereas
before we only created a temporary file when writing to stdout.

Cleanup mkimg.c now that the song and dance of using a temporary
file is gone.
When write sparse files, make sure to truncate(2) the file. Otherwise
any hole at the end is lost and the file is not of the right size.
Add a linker set for output formats. This is mostly copied and trimmed
from the linker set for schemes. Add stubs for raw and vmdk output
formats so as to demonstrate that the usage message is correct.
Add the -f option for specifying the output format. Update the manpage
accordingly. Print the scheme and the format when running verbose.
Define the sparse extent header and document the steps to take
to create the VMDK file. Add some notes as well.

What I needed to know (roughly) is what interface the image API
is to provide and whether there are (knowledge) gaps that prevent
me from implementing it for real.
Have image_write() call sparse_write() so that we can use SEEK_HOLE
and SEEK_DATA to "quickly" find occupied sectors. This is all short-
lived, because the image should not be kept in a file, but in memory.
To be precise: the image API should be both efficient and scalable
and using a file is not efficient -- it works, which is what I need
right now.
Add format_write() that calls the write() function of the output
format. Have the raw format use image_copyout() for now.
Add image_get_size() so formats can query about the image size.
Create the VMDK (embedded) descriptor file and round its size
to a multiple of 512.

TODO: We need the name of the output file -- it's in the extent
description. For now, just use "mkimg.vmdk".
Interrupts need to be disabled on entry to cpu_sleep() for ARM.  Given
that and the need to be in a critical section when switching to idleclock
mode for event timers, use spinlock_enter()/exit() to achieve both needs.

The ARM WFI (wait for interrupt) instruction blocks until an interrupt is
asserted, and it will unblock even if interrupts are masked, and it will
unblock immediately if an interrupt is already pending.  It is necessary
to execute it with interrupts disabled, otherwise the interrupt that
should unblock it may occur and be serviced just prior to executing the
instruction.  At that point the system is inappropriately asleep until
the next timer tick or some other random interrupt happens.

In general, interrupts need to be disabled continuously from the time the
decision is made that there is no work to be done and sleeping is needed
until actually going to sleep, to avoid a race where handling a new
interrupt changes the basis for deciding there is no work to be done.

Submitted by:	hps@ (in slightly different form)
Cleanup some style nits.
Build modules in parallel.  This has been tested by several people at
various -j levels from 6 to 48 without problems.
Nuke a couple of unnecessary assigments.  Nothing uses the values of rstart
and rend after this point.

MFC after:	1 week