* 1: I/O error
*/
static int get_boot(struct fdisk_context *cxt, int try_only) {
-
- disklabel = ANY_LABEL;
- update_units(cxt);
-
- if (!check_dos_label(cxt))
- if (check_sun_label(cxt) || check_sgi_label(cxt) || check_aix_label(cxt)
- || check_mac_label(cxt))
- return 0;
-
- if (check_osf_label(cxt)) {
- /* intialize partitions for BSD as well */
- dos_init(cxt);
- if (!valid_part_table_flag(cxt->mbr)) {
- disklabel = OSF_LABEL;
- return 0;
- }
- printf(_("This disk has both DOS and BSD magic.\n"
- "Give the 'b' command to go to BSD mode.\n"));
- return 0;
- }
-
if (disklabel == ANY_LABEL) {
if (try_only)
return -1;
#define FDISK_DEBUG_CONTEXT (1 << 2)
#define FDISK_DEBUG_TOPOLOGY (1 << 3)
#define FDISK_DEBUG_GEOMETRY (1 << 4)
+#define FDISK_DEBUG_LABEL (1 << 5)
#define FDISK_DEBUG_ALL 0xFFFF
# define ON_DBG(m, x) do { \
struct fdisk_geometry geom;
};
+/*
+ * Label specific operations
+ */
+struct fdisk_label {
+ const char *name;
+ int (*probe)(struct fdisk_context *cxt);
+};
+
+/*
+ * labels
+ */
+extern const struct fdisk_label aix_label;
+extern const struct fdisk_label dos_label;
+extern const struct fdisk_label bsd_label;
+extern const struct fdisk_label mac_label;
+extern const struct fdisk_label sun_label;
+extern const struct fdisk_label sgi_label;
+
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_sectsz_is_default(struct fdisk_context *cxt);
return;
}
-int check_aix_label(struct fdisk_context *cxt)
+static int check_aix_label(struct fdisk_context *cxt)
{
if (aixlabel->magic != AIX_LABEL_MAGIC &&
aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) {
aix_nolabel(cxt); /* %% */
return 1;
}
+
+const struct fdisk_label aix_label =
+{
+ .name = "aix",
+ .probe = check_aix_label
+};
/* fdiskaixlabel.c */
extern struct systypes aix_sys_types[];
-extern int check_aix_label(struct fdisk_context *cxt);
-
#endif /* FDISK_AIX_LABEL_H */
* Note: often reformatting with DOS-type label leaves the BSD magic,
* so this does not mean that there is a BSD disk label.
*/
-int
+static int
check_osf_label(struct fdisk_context *cxt) {
if (xbsd_readlabel (cxt, NULL, &xbsd_dlabel) == 0)
return 0;
dp[63] = sum;
}
#endif /* __alpha__ */
+
+const struct fdisk_label bsd_label =
+{
+ .name = "bsd",
+ .probe = check_osf_label
+};
#define BSD_D_DOSPART 0x20 /* within MSDOS partition */
extern void bsd_command_prompt(struct fdisk_context *cxt);
-extern int check_osf_label(struct fdisk_context *cxt);
extern int btrydev(struct fdisk_context *cxt);
extern void xbsd_print_disklabel(struct fdisk_context *cxt, int);
}
}
-int check_dos_label(struct fdisk_context *cxt)
+static int check_dos_label(struct fdisk_context *cxt)
{
int i;
}
}
}
+
+const struct fdisk_label dos_label =
+{
+ .name = "dos",
+ .probe = check_dos_label,
+};
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);
-extern int check_dos_label(struct fdisk_context *cxt);
extern int is_dos_partition(int t);
extern void dos_init(struct fdisk_context *cxt);
extern void dos_add_partition(struct fdisk_context *cxt, int n, int sys);
return;
}
-int
+static int
check_mac_label(struct fdisk_context *cxt)
{
/*
mac_nolabel(cxt); /* %% */
return 1;
}
+
+const struct fdisk_label mac_label =
+{
+ .name = "mac",
+ .probe = check_mac_label
+};
/* fdiskmaclabel.c */
extern struct systypes mac_sys_types[];
extern void mac_nolabel(struct fdisk_context *cxt);
-extern int check_mac_label(struct fdisk_context *cxt);
#endif /* FDISK_MAC_LABEL_H */
return sum;
}
-int
+static int
check_sgi_label(struct fdisk_context *cxt) {
if (sizeof(sgilabel) > 512) {
fprintf(stderr,
strcpy((char *) info->installer, "Sfx version 5.3, Oct 18, 1994");
return info;
}
+
+const struct fdisk_label sgi_label =
+{
+ .name = "sgi",
+ .probe = check_sgi_label
+};
/* fdisksgilabel.c */
extern struct systypes sgi_sys_types[];
-extern int check_sgi_label(struct fdisk_context *cxt);
extern void sgi_list_table( struct fdisk_context *cxt, int xtra );
extern int sgi_change_sysid(struct fdisk_context *cxt, int i, int sys);
extern unsigned int sgi_get_start_sector(struct fdisk_context *cxt, int i );
partitions = SUN_NUM_PARTITIONS;
}
-int check_sun_label(struct fdisk_context *cxt)
+static int check_sun_label(struct fdisk_context *cxt)
{
unsigned short *ush;
int csum;
{
return SSWAP16(sunlabel->part_tags[i].tag);
}
+
+const struct fdisk_label sun_label =
+{
+ .name = "sun",
+ .probe = check_sun_label,
+};
/* fdisksunlabel.c */
extern struct systypes sun_sys_types[];
-extern int check_sun_label(struct fdisk_context *cxt);
extern void 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);
int fdisk_debug_mask;
+/*
+ * label probing functions
+ */
+static const struct fdisk_label *labels[] =
+{
+ &bsd_label,
+ &dos_label,
+ &sgi_label,
+ &sun_label,
+ &aix_label,
+ &mac_label,
+};
+
+static int __probe_labels(struct fdisk_context *cxt)
+{
+ int i, rc = 0;
+
+ disklabel = ANY_LABEL;
+ update_units(cxt);
+
+ for (i = 0; i < ARRAY_SIZE(labels); i++) {
+ rc = labels[i]->probe(cxt);
+ if (rc) {
+ DBG(LABEL, dbgprint("detected a %s label\n",
+ labels[i]->name));
+ goto done;
+ }
+ }
+
+done:
+ return rc;
+}
+
static int __init_mbr_buffer(struct fdisk_context *cxt)
{
DBG(TOPOLOGY, dbgprint("initialize MBR buffer"));
__discover_topology(cxt);
__discover_geometry(cxt);
+ __probe_labels(cxt);
+
DBG(CONTEXT, dbgprint("context initialized for %s [%s]",
fname, readonly ? "READ-ONLY" : "READ-WRITE"));
return cxt;