Line 103... |
Line 103... |
fseek(disk, 1 * SECTOR_SIZE, SEEK_SET);
|
fseek(disk, 1 * SECTOR_SIZE, SEEK_SET);
|
if (fread(ptr, 1, SECTOR_SIZE, disk) != SECTOR_SIZE) {
|
if (fread(ptr, 1, SECTOR_SIZE, disk) != SECTOR_SIZE) {
|
error("cannot read partition table from disk image '%s'", diskName);
|
error("cannot read partition table from disk image '%s'", diskName);
|
}
|
}
|
convertPartitionTable(ptr, NPE);
|
convertPartitionTable(ptr, NPE);
|
/* get partition number, start and size of partition */
|
/* get partition number, determine start and size of partition */
|
partno = strtol(partNmbr, &endp, 10);
|
partno = strtol(partNmbr, &endp, 10);
|
if (*endp != '\0') {
|
if (*endp != '\0') {
|
error("cannot read partition number");
|
error("cannot read partition number");
|
}
|
}
|
if (partno < 0 || partno > 15) {
|
if (partno < 0 || partno > 15) {
|
Line 122... |
Line 122... |
partno, partStart, partStart, partSize, partSize);
|
partno, partStart, partStart, partSize, partSize);
|
if (partStart >= diskSize || partStart + partSize > diskSize) {
|
if (partStart >= diskSize || partStart + partSize > diskSize) {
|
error("partition %d is larger than the disk", partno);
|
error("partition %d is larger than the disk", partno);
|
}
|
}
|
fseek(disk, partStart * SECTOR_SIZE, SEEK_SET);
|
fseek(disk, partStart * SECTOR_SIZE, SEEK_SET);
|
/* open partition image, check size */
|
/* open partition image, check size (rounded up to whole sectors) */
|
image = fopen(partName, "rb");
|
image = fopen(partName, "rb");
|
if (image == NULL) {
|
if (image == NULL) {
|
error("cannot open partition image '%s'", partName);
|
error("cannot open partition image '%s'", partName);
|
}
|
}
|
fseek(image, 0, SEEK_END);
|
fseek(image, 0, SEEK_END);
|
imageSize = (ftell(image) + SECTOR_SIZE - 1) / SECTOR_SIZE;
|
imageSize = (ftell(image) + SECTOR_SIZE - 1) / SECTOR_SIZE;
|
printf("partition image '%s' occupies %d (0x%X) sectors\n",
|
printf("partition image '%s' occupies %d (0x%X) sectors\n",
|
partName, imageSize, imageSize);
|
partName, imageSize, imageSize);
|
if (imageSize >= partSize) {
|
if (imageSize > partSize) {
|
error("partition image (%d sectors) too big for partition (%d sectors)",
|
error("partition image (%d sectors) too big for partition (%d sectors)",
|
imageSize, partSize);
|
imageSize, partSize);
|
}
|
}
|
fseek(image, 0, SEEK_SET);
|
fseek(image, 0, SEEK_SET);
|
/* copy partition image to partition on disk */
|
/* copy partition image to partition on disk */
|