summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fdisk/Makefile.am4
-rw-r--r--fdisk/fdisk.c26
-rw-r--r--fdisk/fdisk.h1
-rw-r--r--fdisk/fdiskmaclabel.c86
-rw-r--r--fdisk/fdiskmaclabel.h39
5 files changed, 148 insertions, 8 deletions
diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am
index c407bbfda..9561fef20 100644
--- a/fdisk/Makefile.am
+++ b/fdisk/Makefile.am
@@ -9,9 +9,9 @@ if !M68K
sbin_PROGRAMS = fdisk
man_MANS = fdisk.8
fdisk_SOURCES = fdisk.c fdiskbsdlabel.c fdisksgilabel.c \
- fdisksunlabel.c fdiskaixlabel.c partname.c \
+ fdisksunlabel.c fdiskaixlabel.c fdiskmaclabel.c partname.c \
fdisk.h fdisksunlabel.h fdisksgilabel.h fdiskaixlabel.h \
- fdiskbsdlabel.h $(fdisk_common)
+ fdiskbsdlabel.h fdiskmaclabel.h $(fdisk_common)
if !SPARC
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index ecaac90eb..c4ab6d569 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -26,6 +26,7 @@
#include "fdisksunlabel.h"
#include "fdisksgilabel.h"
#include "fdiskaixlabel.h"
+#include "fdiskmaclabel.h"
#ifdef HAVE_LINUX_COMPILER_H
#include <linux/compiler.h>
@@ -168,11 +169,12 @@ unsigned int heads,
unsigned long long total_number_of_sectors;
-#define dos_label (!sun_label && !sgi_label && !aix_label && !osf_label)
-int sun_label = 0; /* looking at sun disklabel */
+#define dos_label (!sun_label && !sgi_label && !aix_label && !mac_label && !osf_label)
+int sun_label = 0; /* looking at sun disklabel */
int sgi_label = 0; /* looking at sgi disklabel */
int aix_label = 0; /* looking at aix disklabel */
int osf_label = 0; /* looking at OSF/1 disklabel */
+int mac_label = 0; /* looking at mac disklabel */
int possibly_osf_label = 0;
jmp_buf listingbuf;
@@ -366,7 +368,7 @@ menu(void) {
puts(_(" v verify the partition table"));
puts(_(" w write table to disk and exit"));
}
- else if (aix_label) {
+ else if (aix_label || mac_label) {
puts(_("Command action"));
puts(_(" m print this menu"));
puts(_(" o create a new empty DOS partition table"));
@@ -430,7 +432,7 @@ xmenu(void) {
puts(_(" v verify the partition table"));
puts(_(" w write table to disk and exit"));
}
- else if (aix_label) {
+ else if (aix_label || mac_label) {
puts(_("Command action"));
puts(_(" b move beginning of data in a partition")); /* !sun */
puts(_(" c change number of cylinders"));
@@ -727,7 +729,7 @@ create_doslabel(void) {
"content won't be recoverable.\n\n"));
sun_nolabel(); /* otherwise always recognised as sun */
sgi_nolabel(); /* otherwise always recognised as sgi */
- aix_label = osf_label = possibly_osf_label = 0;
+ mac_label = aix_label = osf_label = possibly_osf_label = 0;
partitions = 4;
for (i = 510-64; i < 510; i++)
@@ -926,6 +928,9 @@ get_boot(enum action what) {
if (check_aix_label())
return 0;
+ if (check_mac_label())
+ return 0;
+
if (check_osf_label()) {
possibly_osf_label = 1;
if (!valid_part_table_flag(MBRbuffer)) {
@@ -2059,6 +2064,15 @@ new_partition(void) {
return;
}
+ if (mac_label) {
+ printf(_("\tSorry - this fdisk cannot handle Mac disk labels."
+ "\n\tIf you want to add DOS-type partitions, create"
+ "\n\ta new empty DOS partition table first. (Use o.)"
+ "\n\tWARNING: "
+ "This will destroy the present disk contents.\n"));
+ return;
+ }
+
for (i = 0; i < 4; i++)
free_primary += !ptes[i].part_table->sys_ind;
@@ -2397,7 +2411,7 @@ try(char *device, int user_specified) {
if (gb > 0) { /* I/O error */
} else if (gb < 0) { /* no DOS signature */
list_disk_geometry();
- if (!aix_label && btrydev(device) < 0)
+ if (!aix_label && !mac_label && btrydev(device) < 0)
fprintf(stderr,
_("Disk %s doesn't contain a valid "
"partition table\n"), device);
diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h
index 781c5050f..75dd88ecd 100644
--- a/fdisk/fdisk.h
+++ b/fdisk/fdisk.h
@@ -96,6 +96,7 @@ extern int osf_label;
extern int sun_label;
extern int sgi_label;
extern int aix_label;
+extern int mac_label;
/* prototypes for fdiskbsdlabel.c */
extern void bselect(void);
diff --git a/fdisk/fdiskmaclabel.c b/fdisk/fdiskmaclabel.c
new file mode 100644
index 000000000..06d4a6ed2
--- /dev/null
+++ b/fdisk/fdiskmaclabel.c
@@ -0,0 +1,86 @@
+/*
+ Changes:
+ Sat Mar 20 09:51:38 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
+ Internationalization
+*/
+#include <stdio.h> /* stderr */
+#include <string.h> /* strstr */
+#include <unistd.h> /* write */
+
+#include <endian.h>
+
+#include "common.h"
+#include "fdisk.h"
+#include "fdiskmaclabel.h"
+#include "nls.h"
+
+#define MAC_BITMASK 0xffff0000
+
+
+static int other_endian = 0;
+static short volumes=1;
+
+/*
+ * only dealing with free blocks here
+ */
+
+static void
+mac_info( void ) {
+ puts(
+ _("\n\tThere is a valid Mac label on this disk.\n"
+ "\tUnfortunately fdisk(1) cannot handle these disks.\n"
+ "\tUse either pdisk or parted to modify the partition table.\n"
+ "\tNevertheless some advice:\n"
+ "\t1. fdisk will destroy its contents on write.\n"
+ "\t2. Be sure that this disk is NOT a still vital\n"
+ "\t part of a volume group. (Otherwise you may\n"
+ "\t erase the other disks as well, if unmirrored.)\n")
+ );
+}
+
+void
+mac_nolabel( void )
+{
+ maclabel->magic = 0;
+ mac_label = 0;
+ partitions = 4;
+ memset( MBRbuffer, 0, sizeof(MBRbuffer) ); /* avoid fdisk cores */
+ return;
+}
+
+int
+check_mac_label( void )
+{
+ /*
+ Conversion: only 16 bit should compared
+ e.g.: HFS Label is only 16bit long
+ */
+ int magic_masked = 0 ;
+ magic_masked = maclabel->magic & MAC_BITMASK ;
+
+ switch (magic_masked) {
+ case MAC_LABEL_MAGIC :
+ case MAC_LABEL_MAGIC_2:
+ case MAC_LABEL_MAGIC_3:
+ goto IS_MAC;
+ break;
+ default:
+ mac_label = 0;
+ other_endian = 0;
+ return 0;
+
+
+ }
+
+IS_MAC:
+ other_endian = (maclabel->magic == MAC_LABEL_MAGIC_SWAPPED); // =?
+ update_units();
+ mac_label = 1;
+ partitions= 1016; // =?
+ volumes = 15; // =?
+ mac_info();
+ mac_nolabel(); /* %% */
+ mac_label = 1; /* %% */
+ return 1;
+}
+
diff --git a/fdisk/fdiskmaclabel.h b/fdisk/fdiskmaclabel.h
new file mode 100644
index 000000000..a13900ddc
--- /dev/null
+++ b/fdisk/fdiskmaclabel.h
@@ -0,0 +1,39 @@
+#ifndef FDISK_MAC_LABEL_H
+#define FDISK_MAC_LABEL_H
+
+#include <linux/types.h> /* for __u32 etc */
+/*
+ * Copyright (C) Andreas Neuper, Sep 1998.
+ * This file may be redistributed under
+ * the terms of the GNU Public License.
+ */
+
+typedef struct {
+ unsigned int magic; /* expect MAC_LABEL_MAGIC */
+ unsigned int fillbytes1[124];
+ unsigned int physical_volume_id;
+ unsigned int fillbytes2[124];
+} mac_partition;
+
+/* MAC magic number only 16bits, do I always know that there are 0200
+ * following? Problem, after magic the uint16_t res1; follows, I donnno know
+ * about the 200k */
+#define MAC_LABEL_MAGIC 0x45520000
+#define MAC_LABEL_MAGIC_2 0x50530000
+#define MAC_LABEL_MAGIC_3 0x504d0000
+
+#define MAC_LABEL_MAGIC_SWAPPED 0x00002554
+
+#define MAC_LABEL_MAGIC_2_SWAPPED 0x00003505
+#define MAC_LABEL_MAGIC_3_SWAPPED 0x0000d405
+
+/* fdisk.c */
+#define maclabel ((mac_partition *)MBRbuffer)
+
+/* fdiskmaclabel.c */
+extern struct systypes mac_sys_types[];
+extern void mac_nolabel( void );
+extern int check_mac_label( void );
+
+#endif /* FDISK_MAC_LABEL_H */
+