}
-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;
-
- if (!(valid_part_table_flag(bufp)))
- return;
-
- 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;
- }
-}
-
/*
* Sets LBA of the first partition
*/
if (sector_size) /* passed -b option, override autodiscovery */
fdisk_context_force_sector_size(cxt, sector_size);
- fdisk_context_set_user_geometry(cxt, user_cylinders,
+ if (user_cylinders || user_heads || user_sectors)
+ fdisk_context_set_user_geometry(cxt, user_cylinders,
user_heads, user_sectors);
gpt_warning(device);
if (sector_size) /* passed -b option, override autodiscovery */
fdisk_context_force_sector_size(cxt, sector_size);
- fdisk_context_set_user_geometry(cxt, user_cylinders,
- user_heads, user_sectors);
+ if (user_cylinders || user_heads || user_sectors)
+ fdisk_context_set_user_geometry(cxt, user_cylinders,
+ user_heads, user_sectors);
print_welcome();
extern sector_t align_lba(struct fdisk_context *cxt, sector_t lba, int direction);
extern int get_partition_dflt(struct fdisk_context *cxt, int warn, int max, int dflt);
extern void update_sector_offset(struct fdisk_context *cxt);
-extern void get_partition_table_geometry(struct fdisk_context *cxt,
- unsigned int *ph, unsigned int *ps);
#define PLURAL 0
#define SINGULAR 1
}
}
+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];
return -EINVAL;
cxt->phy_sector_size = cxt->sector_size = s;
+ cxt->min_io_size = cxt->io_size = s;
+
+ update_sector_offset(cxt);
return 0;
}
if (sectors)
cxt->geom.sectors = sectors;
- recount_geometry(cxt);
-
- if (!cxt->geom.cylinders)
- /* use the user defined cylinders only as fillback */
+ if (cylinders)
cxt->geom.cylinders = cylinders;
+ else
+ recount_geometry(cxt);
+ update_sector_offset(cxt);
return 0;
}
-
-static int __discover_geometry(struct fdisk_context *cxt)
+/*
+ * Generic (label independent) geometry
+ */
+static int __discover_system_geometry(struct fdisk_context *cxt)
{
sector_t nsects;
unsigned int h = 0, s = 0;
if (!blkdev_get_sectors(cxt->dev_fd, &nsects))
cxt->total_sectors = (nsects / (cxt->sector_size >> 9));
- get_partition_table_geometry(cxt, &h, &s);
- if (h && s)
- goto hs_ok;
-
/* what the kernel/bios thinks the geometry is */
blkdev_get_geometry(cxt->dev_fd, &h, &s);
- if (h && s)
- goto hs_ok;
-
- /* unable to discover geometry, use default values */
- s = 63;
- h = 255;
+ if (!h && !s) {
+ /* unable to discover geometry, use default values */
+ s = 63;
+ h = 255;
+ }
-hs_ok: /* obtained heads and sectors */
+ /* obtained heads and sectors */
cxt->geom.heads = h;
cxt->geom.sectors = s;
recount_geometry(cxt);
- update_sector_offset(cxt);
-
DBG(GEOMETRY, dbgprint("geometry discovered for %s: C/H/S: %lld/%d/%lld",
cxt->dev_path, cxt->geom.cylinders,
cxt->geom.heads, cxt->geom.sectors));
goto fail;
__discover_topology(cxt);
- __discover_geometry(cxt);
+ __discover_system_geometry(cxt);
+ /* detect labels and apply labes specific stuff (e.g geomery)
+ * to the context */
__probe_labels(cxt);
+ update_sector_offset(cxt);
+
DBG(CONTEXT, dbgprint("context initialized for %s [%s]",
fname, readonly ? "READ-ONLY" : "READ-WRITE"));
return cxt;