+ /* Open target disk. */
+ dst = disk_get (1, 0);
+ if (dst == NULL)
+ PANIC ("couldn't open target disk (hdc or hd1:0)");
+
+ /* Write size to sector 0. */
+ memset (buffer, 0, DISK_SECTOR_SIZE);
+ memcpy (buffer, "GET", 4);
+ ((int32_t *) buffer)[1] = size;
+ disk_write (dst, sector++, buffer);
+
+ /* Do copy. */
+ while (size > 0)
+ {
+ int chunk_size = size > DISK_SECTOR_SIZE ? DISK_SECTOR_SIZE : size;
+ if (sector >= disk_size (dst))
+ PANIC ("%s: out of space on scratch disk", filename);
+ if (file_read (src, buffer, chunk_size) != chunk_size)
+ PANIC ("%s: read failed with %"PROTd" bytes unread", filename, size);
+ memset (buffer + chunk_size, 0, DISK_SECTOR_SIZE - chunk_size);
+ disk_write (dst, sector++, buffer);
+ size -= chunk_size;