line_buffer[LINE_LENGTH];
int nowarn = 0, /* no warnings for fdisk -l/-s */
- dos_compatible_flag = 0, /* disabled by default */
partitions = 4; /* maximum partition + 1 */
unsigned int user_cylinders, user_heads, user_sectors;
pe->changed = 1;
}
-static void
-toggle_dos_compatibility_flag(struct fdisk_context *cxt) {
- dos_compatible_flag = ~dos_compatible_flag;
- if (dos_compatible_flag)
+static void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
+{
+ struct fdisk_label *lb = fdisk_context_get_label(cxt, "dos");
+ int flag;
+
+ if (!lb)
+ return;
+
+ flag = !fdisk_dos_is_compatible(lb);
+
+ if (flag)
printf(_("DOS Compatibility flag is set (DEPRECATED!)\n"));
else
printf(_("DOS Compatibility flag is not set\n"));
- fdisk_reset_alignment(cxt);
+ fdisk_dos_enable_compatible(lb, flag);
+
+ if (fdisk_is_disklabel(cxt, DOS))
+ fdisk_reset_alignment(cxt);
}
static void delete_partition(struct fdisk_context *cxt, int partnum)
unsigned int lbc, lbh, lbs; /* logical beginning c, h, s */
unsigned int lec, leh, les; /* logical ending c, h, s */
- if (!dos_compatible_flag)
+ if (!is_dos_compatible(cxt))
return;
if (!cxt->geom.heads || !cxt->geom.sectors || (partition >= 4))
cxt->dev_path, hectomega / 10, hectomega % 10, bytes);
}
printf(_(", %llu sectors\n"), cxt->total_sectors);
- if (dos_compatible_flag)
+ if (is_dos_compatible(cxt))
printf(_("%d heads, %llu sectors/track, %llu cylinders\n"),
cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);
printf(_("Units = %s of %d * %ld = %ld bytes\n"),
case 's':
user_sectors = read_int(cxt, 1, cxt->geom.sectors, 63, 0,
_("Number of sectors"));
- if (dos_compatible_flag)
+ if (is_dos_compatible(cxt))
fprintf(stderr, _("Warning: setting "
"sector offset for DOS "
"compatibility\n"));
int c, optl = 0, opts = 0;
unsigned long sector_size = 0;
struct fdisk_context *cxt;
+ struct fdisk_label *lb;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
user_cylinders = strtou32_or_err(optarg, _("invalid cylinders argument"));
break;
case 'c':
- dos_compatible_flag = 0; /* default */
-
- if (optarg && !strcmp(optarg, "=dos"))
- dos_compatible_flag = ~0;
- else if (optarg && strcmp(optarg, "=nondos"))
- usage(stderr);
+ if (optarg) {
+ lb = fdisk_context_get_label(cxt, "dos");
+ if (!lb)
+ err(EXIT_FAILURE, _("not found DOS label driver"));
+ if (strcmp(optarg, "=dos") == 0)
+ fdisk_dos_enable_compatible(lb, TRUE);
+ else if (strcmp(optarg, "=nondos") == 0)
+ fdisk_dos_enable_compatible(lb, FALSE);
+ else
+ usage(stderr);
+ }
+ /* use default if no optarg specified */
break;
case 'H':
user_heads = strtou32_or_err(optarg, _("invalid heads argument"));
*/
struct fdisk_dos_label {
struct fdisk_label head; /* generic part */
+
+ unsigned int compatible : 1; /* is DOS compatible? */
};
/*
"the physical sector size. Aligning to a physical sector (or optimal\n"
"I/O) size boundary is recommended, or performance may be impacted.\n"));
- if (dos_compatible_flag)
+ if (is_dos_compatible(cxt))
fprintf(stderr, _("\n"
"WARNING: DOS-compatible mode is deprecated. It's strongly recommended to\n"
" switch off the mode (with command 'c')."));
static int dos_reset_alignment(struct fdisk_context *cxt)
{
/* overwrite necessary stuff by DOS deprecated stuff */
- if (dos_compatible_flag) {
+ if (is_dos_compatible(cxt)) {
if (cxt->geom.sectors)
cxt->first_lba = cxt->geom.sectors; /* usually 63 */
if (!doext)
print_partition_size(cxt, i + 1, start, stop, sysid);
- if (dos_compatible_flag && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
+ if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
start = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
set_hsc(p->head, p->sector, p->cyl, start);
- if (dos_compatible_flag && (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023))
+ if (is_dos_compatible(cxt) && (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023))
stop = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
set_hsc(p->end_head, p->end_sector, p->end_cyl, stop);
ptes[i].changed = 1;
return lb;
}
+
+/*
+ * Public label specific functions
+ */
+
+int fdisk_dos_enable_compatible(struct fdisk_label *lb, int enable)
+{
+ struct fdisk_dos_label *dos = (struct fdisk_dos_label *) lb;
+
+ if (!lb)
+ return -EINVAL;
+
+ dos->compatible = enable;
+ return 0;
+}
+
+int fdisk_dos_is_compatible(struct fdisk_label *lb)
+{
+ return ((struct fdisk_dos_label *) lb)->compatible;
+}