ochs2 = *(uint32_t *)dp->end;
*(uint32_t *)dp->start =
- lba2chs(di, lba1) |
+ lba2chs(di, lba1, l2c_cadd) |
(*(uint32_t *)dp->start & 0xFF000000);
*(uint32_t *)dp->end =
- lba2chs(di, lba1 + dp->length - 1) |
+ lba2chs(di, lba1 + dp->length - 1, l2c_cadd) |
(*(uint32_t *)dp->end & 0xFF000000);
return
if (opt.hide < 2 && !opt.mbrchs)
break; /* don't walk unnecessarily */
if (wb && !werr) {
- werr |= disk_write_sector(&iter->di, cebr_lba, &mbr);
+ werr |= disk_write_sectors(&iter->di, cebr_lba, &mbr, 1);
wb = false;
}
memcpy(&mbr, iter->data, sizeof(struct disk_dos_mbr));
}
/* last write */
if (wb && !werr)
- werr |= disk_write_sector(&_iter->di, cebr_lba, &mbr);
+ werr |= disk_write_sectors(&_iter->di, cebr_lba, &mbr, 1);
bail:
pi_del(&iter);
error("Could not build GPT hand-over record!\n");
goto bail;
}
- *(uint32_t *)ha->start = lba2chs(&iter->di, gp->lba_first);
- *(uint32_t *)ha->end = lba2chs(&iter->di, gp->lba_last);
+ *(uint32_t *)ha->start = lba2chs(&iter->di, gp->lba_first, l2c_cadd);
+ *(uint32_t *)ha->end = lba2chs(&iter->di, gp->lba_last, l2c_cadd);
ha->active_flag = 0x80;
ha->ostype = 0xED;
/* All bits set by default */
goto bail;
}
if (!iter->index) {
- *(uint32_t *)ha->start = lba2chs(&iter->di, 0);
- *(uint32_t *)ha->end = lba2chs(&iter->di, 2879);
+ *(uint32_t *)ha->start = lba2chs(&iter->di, 0, l2c_cadd);
+ *(uint32_t *)ha->end = lba2chs(&iter->di, 2879, l2c_cadd);
ha->active_flag = 0x80;
ha->ostype = 0xDA;
ha->start_lba = 0;
} else if (iter->type == typedos) {
dp = (const struct disk_dos_part_entry *)iter->record;
- *(uint32_t *)ha->start = lba2chs(&iter->di, iter->start_lba);
- *(uint32_t *)ha->end = lba2chs(&iter->di, iter->start_lba + dp->length - 1);
+ *(uint32_t *)ha->start = lba2chs(&iter->di, iter->start_lba, l2c_cadd);
+ *(uint32_t *)ha->end = lba2chs(&iter->di, iter->start_lba + dp->length - 1, l2c_cadd);
ha->active_flag = dp->active_flag;
ha->ostype = dp->ostype;
ha->start_lba = (uint32_t)iter->start_lba; /* fine, we iterate over legacy scheme */
memcpy(data + ndata++, &hdat, sizeof(hdat));
#ifdef DEBUG
- printf("iter dsk: %d\n", iter->di.disk);
+ printf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %llu, %u\n"
+ "iter->di C, H, S: %u, %u, %u\n",
+ iter->di.disk, iter->di.bps,
+ iter->di.lbacnt, iter->di.cyl * iter->di.head * iter->di.spt,
+ iter->di.cyl, iter->di.head, iter->di.spt);
printf("iter idx: %d\n", iter->index);
printf("iter lba: %llu\n", iter->start_lba);
if (opt.hand)
/* BPB: legacy geometry */
if (type >= bpbV30) {
if (iter->di.cbios)
- *(uint32_t *)((char *)data->data + 0x18) = (uint32_t)((iter->di.head << 16) | iter->di.sect);
+ *(uint32_t *)((char *)data->data + 0x18) = (uint32_t)((iter->di.head << 16) | iter->di.spt);
else {
if (iter->di.disk & 0x80)
*(uint32_t *)((char *)data->data + 0x18) = 0x00FF003F;
return 0;
if (memcmp(org, data->data, data->size)) {
- if (disk_write_sector(&iter->di, iter->start_lba, data->data)) {
+ if (disk_write_sectors(&iter->di, iter->start_lba, data->data, 1)) {
error("Cannot write the updated sector.\n");
goto bail;
}
int guid_is0(const struct guid *guid)
{
- return !*(const uint64_t *)guid && !*((const uint64_t *)guid+1);
+ return !*(const uint64_t *)guid && !*((const uint64_t *)guid + 1);
}
void wait_key(void)
} while (!cnt || (cnt < 0 && errno == EAGAIN));
}
-uint32_t lba2chs(const struct disk_info *di, uint64_t lba)
+uint32_t lba2chs(const struct disk_info *di, uint64_t lba, uint32_t mode)
{
uint32_t c, h, s, t;
uint32_t cs, hs, ss;
/*
- * Not much reason here, but if we have no valid chs geometry, we assume
+ * Not much reason here, but if we have no valid CHS geometry, we assume
* "typical" ones to have something to return.
*/
if (di->cbios) {
cs = di->cyl;
hs = di->head;
- ss = di->sect;
+ ss = di->spt;
+ if (mode == l2c_cadd && cs < 1024 && di->lbacnt > cs*hs*ss)
+ cs++;
+ else if (mode == l2c_cmax)
+ cs = 1024;
} else {
if (di->disk & 0x80) {
cs = 1024;