+#define PUSHBUF 104857600
+/**
+ * Write data from overlay to source.
+ */
+static void push_oly(off_t beg, off_t end) {
+ static char * buffer = 0;
+ // Pretend that there isn't an overlay
+ char *filename = overlay.source.filename;
+ if ( buffer == 0 ) {
+ buffer = malloc( PUSHBUF );
+ if ( buffer == 0 ) {
+ fprintf( stderr, "** OOM!!\n" );
+ exit( 1 );
+ }
+ }
+ overlay.source.filename = 0;
+ while ( beg < end ) {
+ off_t size = end - beg;
+ if ( size > PUSHBUF ) {
+ size = PUSHBUF;
+ }
+ if ( lseek( overlay.source.fd, beg, SEEK_SET ) < 0 ) {
+ fprintf( stderr, "** Cannot seek overlay at %ld\n", beg );
+ break;
+ }
+ size = read( overlay.source.fd, buffer, size );
+ if ( write_block( beg, buffer, size ) < 0 ) {
+ fprintf( stderr, "** Cannot push %ld bytes at %ld\n", size, beg );
+ }
+ beg += size;
+ }
+ overlay.source.filename = filename;
+}
+