- off_t n = file_read (file, buffer, PGSIZE);
- if (n == 0)
- break;
-
- hex_dump (buffer, n, true);
+ int chunk_size = size > DISK_SECTOR_SIZE ? DISK_SECTOR_SIZE : size;
+ if (sector >= disk_size (dst))
+ PANIC ("%s: out of space on scratch disk", file_name);
+ if (file_read (src, buffer, chunk_size) != chunk_size)
+ PANIC ("%s: read failed with %"PROTd" bytes unread", file_name, size);
+ memset (buffer + chunk_size, 0, DISK_SECTOR_SIZE - chunk_size);
+ disk_write (dst, sector++, buffer);
+ size -= chunk_size;