if (disklabel == ANY_LABEL) {
if (try_only)
return -1;
-
- fprintf(stderr,
- _("Device does not contain a recognized partition table\n"));
-#ifdef __sparc__
- create_sunlabel(cxt);
-#else
- create_doslabel(cxt);
-#endif
}
return 0;
}
cxt->sector_size, DEFAULT_SECTOR_SIZE);
gpt_warning(cxt->dev_path);
- get_boot(cxt, 0);
+
+ if (!fdisk_dev_has_disklabel(cxt)) {
+ fprintf(stderr,
+ _("Device does not contain a recognized partition table\n"));
+ fdisk_create_default_disklabel(cxt);
+ }
command_prompt(cxt);
extern struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int readonly);
extern int fdisk_dev_has_topology(struct fdisk_context *cxt);
+extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
extern int fdisk_dev_sectsz_is_default(struct fdisk_context *cxt);
extern void fdisk_free_context(struct fdisk_context *cxt);
extern void fdisk_mbr_zeroize(struct fdisk_context *cxt);
extern int fdisk_context_set_user_geometry(struct fdisk_context *cxt,
unsigned int cylinders, unsigned int heads,
unsigned int sectors);
+extern int fdisk_create_default_disklabel(struct fdisk_context *cxt);
/* prototypes for fdisk.c */
extern char *disk_device, *line_ptr;
printf(_("Disk identifier: 0x%08x\n"), dos_read_mbr_id(cxt->mbr));
}
-void create_doslabel(struct fdisk_context *cxt)
+int create_doslabel(struct fdisk_context *cxt)
{
unsigned int id;
/* Put MBR signature */
write_part_table_flag(cxt->mbr);
+ return 0;
}
void dos_set_mbr_id(struct fdisk_context *cxt)
return pe->offset + get_start_sect(pe->part_table);
}
-extern void create_doslabel(struct fdisk_context *cxt);
+extern int create_doslabel(struct fdisk_context *cxt);
extern void dos_print_mbr_id(struct fdisk_context *cxt);
extern void dos_set_mbr_id(struct fdisk_context *cxt);
extern void dos_delete_partition(int i);
return 1;
}
-void create_sunlabel(struct fdisk_context *cxt)
+int create_sunlabel(struct fdisk_context *cxt)
{
struct hd_geometry geometry;
sector_t llsectors, llcyls;
set_all_unchanged();
set_changed(0);
+
+ return 0;
}
void toggle_sunflags(struct fdisk_context *cxt, int i, uint16_t mask)
/* fdisksunlabel.c */
extern struct systypes sun_sys_types[];
-extern void create_sunlabel(struct fdisk_context *cxt);
+extern int create_sunlabel(struct fdisk_context *cxt);
extern void sun_delete_partition(struct fdisk_context *cxt, int i);
extern int sun_change_sysid(struct fdisk_context *cxt, int i, uint16_t sys);
extern void sun_list_table(struct fdisk_context *cxt, int xtra);
#include "common.h"
#include "fdisk.h"
+#include "fdiskdoslabel.h"
+#include "fdisksunlabel.h"
+
int fdisk_debug_mask;
/*
return 0;
}
+/**
+ * fdisk_dev_has_disklabel:
+ * @cxt: fdisk context
+ *
+ * Returns: return 1 if there is label on the device.
+ */
+int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
+{
+ return cxt && disklabel != ANY_LABEL;
+}
+
+/**
+ * fdisk_create_default_disklabel:
+ * @cxt: fdisk context
+ *
+ * Creates (in memory) disk label which is usual default for the system. For
+ * example sun label on sparcs, gpt on UEFI machines (TODO), DOS on another
+ * machines, ...etc.
+ *
+ * Returns: 0 on sucess, < 0 on error.
+ */
+int fdisk_create_default_disklabel(struct fdisk_context *cxt)
+{
+ if (!cxt)
+ return -EINVAL;
+#ifdef __sparc__
+ return create_sunlabel(cxt);
+#else
+ return create_doslabel(cxt);
+#endif
+}
+
/**
* fdisk_init_debug:
* @mask: debug mask (0xffff to enable full debuging)