New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fdisk: Add support for fixing MBR partitions CHS values #1394
Conversation
It seems like a good idea and it's a completely independent change with a new API function. Maybe split it into two patches, 1st for libfdisk and 2nd for fdisk. |
BTW, libfdisk/src/dos.c uses on many places dos_partition_set_start() and dos_partition_set_size() but it does not update CHS. The nice example is fdisk_dos_move_begin() (fdisk expert menu and 'b' command), it does not update CHS at all. What about to add to include/pt-mbr.h a new function dos_partition_sync_chs() to update CHS according to the current start and size? So, in the library we will use dos_partition_set_start(p, start);
dos_partition_set_size(p, size);
dos_partition_sync_chs(p, cxt->geom.sectors, cxt->geom.head); and int will internally do what we now do in libfdisk/src/dos.c:set_partition(), it means if (start/(cxt->geom.sectors*cxt->geom.heads) > 1023)
start = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
set_hsc(p->bh, p->bs, p->bc, start);
if (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023)
stop = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
set_hsc(p->eh, p->es, p->ec, stop); but Your previous changes fixed add-partition use-case where we update on-disk stuff by set_partition(), but many other use-cases ignore CHS at all. |
Ok, seems that |
Well, now I see one problem with this
Therefore in |
What about to add |
…S values Call this function everytime after changing either relative LBA partition offset or LBA partition size to ensure that CHS values are in sync with LBA. This should fix partition CHS values after moving or deleting partition. Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Updated. But |
This pull request introduces 1 alert when merging 8c1c35f into 37c6c57 - view on LGTM.com new alerts:
|
…s for all partitions This function fixes beginning and ending CHS values for every partition according to LBA relative offset, relative beginning and size and fdisk idea of disk geometry (sectors per track and number of heads). This function may be used for repairing existing partitions to be compatible with CHS addressing. Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Add a new extended option 'F' to fdisk which recalculates and fixes CHS values for each partition in MBR table according to current fdisk settings for number of heads and sectors per track. This allows in interactive mode to repair existing partitions to be compatible with CHS addressing after changing extended option 'h' (number of heads) or 's' (sectors per track) as these options do not modify content of existing partitions. Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Thanks! |
Anyway, I see that in debug log output are partitions sometimes indexed from zero and sometimes from one. Not sure how big it is issue, but sometimes it can be misleading when debugging if in debug log is written that modifying partition 1 and then modifying partition 2 (and it still modifies second MBR partition)... |
References: #1394 Signed-off-by: Karel Zak <kzak@redhat.com>
It would be better to index it from zero for DBG(), for normal user output it uses I did a small change to two debug messages. |
Add a new extended option 'F' to fdisk which recalculates and fixes CHS
values for each partition in MBR table according to current fdisk settings
for number of heads and sectors per track.
This allows in interactive mode to repair existing partitions to be
compatible with CHS addressing after changing extended option 'h' (number
of heads) or 's' (sectors per track) as these options do not modify content
of existing partitions.