aboutsummaryrefslogtreecommitdiff
r->start_sector = p[2] & 0x3f; r->system = p[4]; r->end_head = p
s="hl opt">] | ((p[6] << 2) & 0x300); r->end_sector = p[6] & 0x3f; r->start_sector_abs = p[8] | p[9] << 8 | p[10] << 16 | p[11] << 24; r->nb_sectors_abs = p[12] | p[13] << 8 | p[14] << 16 | p[15] << 24; } static int find_partition(BlockDriverState *bs, int partition, off_t *offset, off_t *size) { struct partition_record mbr[4]; uint8_t data[512]; int i; int ext_partnum = 4; int ret; if ((ret = bdrv_read(bs, 0, data, 1)) < 0) { errno = -ret; err(EXIT_FAILURE, "error while reading"); } if (data[510] != 0x55 || data[511] != 0xaa) { errno = -EINVAL; return -1; } for (i = 0; i < 4; i++) { read_partition(&data[446 + 16 * i], &mbr[i]); if (!mbr[i].nb_sectors_abs) continue; if (mbr[i].system == 0xF || mbr[i].system == 0x5) { struct partition_record ext[4]; uint8_t data1[512]; int j; if ((ret = bdrv_read(bs, mbr[i].start_sector_abs, data1, 1)) < 0) { errno = -ret; err(EXIT_FAILURE, "error while reading"); } for (j = 0; j < 4; j++) { read_partition(&data1[446 + 16 * j], &ext[j]); if (!ext[j].nb_sectors_abs) continue; if ((ext_partnum + j + 1) == partition) { *offset = (uint64_t)ext[j].start_sector_abs << 9; *size = (uint64_t)ext[j].nb_sectors_abs << 9; return 0; } } ext_partnum += 4; } else if ((i + 1) == partition) { *offset = (uint64_t)mbr[i].start_sector_abs << 9; *size = (uint64_t)mbr[i].nb_sectors_abs << 9; return 0; } } errno = -ENOENT; return -1; } static void termsig_handler(int signum) { sigterm_reported = true; qemu_notify_event(); } static void *show_parts(void *arg) { int nbd; /* linux just needs an open() to trigger * the partition table update * but remember to load the module with max_part != 0 : * modprobe nbd max_part=63 */ nbd = open(device, O_RDWR); if (nbd != -1) { close(nbd); } return NULL; } static void *nbd_client_thread(void *arg) { int fd = *(int *)arg; off_t size; size_t blocksize; uint32_t nbdflags; int sock; int ret; pthread_t show_parts_thread; sock = unix_socket_outgoing(sockpath); if (sock == -1) { goto out; }