summaryrefslogtreecommitdiff
path: root/fdisks/fdiskdoslabel.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2012-07-23 13:57:58 +0200
committerKarel Zak <kzak@redhat.com>2012-07-23 13:57:58 +0200
commit9a5e29e94b60b4733a1e4432b00b1a139fafb255 (patch)
tree1ba1fcdf2d3377c68702961da615d805d721b85e /fdisks/fdiskdoslabel.c
parent6123d1dd135d045799ea1e48af7c2eee8b86b438 (diff)
downloadutil-linux-9a5e29e94b60b4733a1e4432b00b1a139fafb255.tar.gz
fdisk: move DOS geometry code from generic part to label specific
get_partition_table_geometry() should be called from DOS code Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdiskdoslabel.c')
-rw-r--r--fdisks/fdiskdoslabel.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c
index 1d1a47c3..76798ef1 100644
--- a/fdisks/fdiskdoslabel.c
+++ b/fdisks/fdiskdoslabel.c
@@ -323,15 +323,53 @@ void dos_delete_partition(int i)
}
}
+static void get_partition_table_geometry(struct fdisk_context *cxt,
+ unsigned int *ph, unsigned int *ps)
+{
+ unsigned char *bufp = cxt->mbr;
+ struct partition *p;
+ int i, h, s, hh, ss;
+ int first = 1;
+ int bad = 0;
+
+ hh = ss = 0;
+ for (i=0; i<4; i++) {
+ p = pt_offset(bufp, i);
+ if (p->sys_ind != 0) {
+ h = p->end_head + 1;
+ s = (p->end_sector & 077);
+ if (first) {
+ hh = h;
+ ss = s;
+ first = 0;
+ } else if (hh != h || ss != s)
+ bad = 1;
+ }
+ }
+
+ if (!first && !bad) {
+ *ph = hh;
+ *ps = ss;
+ }
+}
+
+
static int dos_probe_label(struct fdisk_context *cxt)
{
int i;
+ unsigned int h = 0, s = 0;
if (!valid_part_table_flag(cxt->mbr))
return 0;
dos_init(cxt);
+ get_partition_table_geometry(cxt, &h, &s);
+ if (h && s) {
+ cxt->geom.heads = h;
+ cxt->geom.sectors = s;
+ }
+
for (i = 0; i < 4; i++) {
struct pte *pe = &ptes[i];