util-linux/util-linux-2.11q-fs_mac.diff

251 lines
7.1 KiB
Diff

--- util-linux-2.12q/fdisk/fdiskmaclabel.c
+++ util-linux-2.12q/fdisk/fdiskmaclabel.c
@@ -0,0 +1,87 @@
+/*
+ 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;
+}
--- util-linux-2.12q/fdisk/fdiskmaclabel.h
+++ util-linux-2.12q/fdisk/fdiskmaclabel.h
@@ -0,0 +1,40 @@
+#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;
+
+#define MAC_LABEL_MAGIC 0x45520000 // 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_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)
+extern char MBRbuffer[MAX_SECTOR_SIZE];
+extern char changed[MAXIMUM_PARTS];
+extern unsigned int heads, sectors, cylinders;
+extern int show_begin;
+extern int mac_label;
+extern char *partition_type(unsigned char type);
+extern void update_units(void);
+extern char read_chars(char *mesg);
+
+/* fdiskmaclabel.c */
+extern struct systypes mac_sys_types[];
+extern void mac_nolabel( void );
+extern int check_mac_label( void );
--- util-linux-2.12q/fdisk/Makefile
+++ util-linux-2.12q/fdisk/Makefile
@@ -39,7 +39,7 @@
endif
endif
-cfdisk: cfdisk.o llseek.o disksize.o i386_sys_types.o $(LIB)/xstrncpy.o
+cfdisk: cfdisk.o llseek.o disksize.o i386_sys_types.o $(LIB)/xstrncpy.o
ifeq "$(HAVE_SLANG)" "yes"
$(CC) $(LDFLAGS) $^ -o $@ $(LIBSLANG)
else
@@ -55,15 +55,17 @@
rm -f activate
ln -s sfdisk activate
-fdisk: fdisk.o llseek.o disksize.o fdiskbsdlabel.o fdisksgilabel.o \
- fdisksunlabel.o fdiskaixlabel.o i386_sys_types.o partname.o
+fdisk: fdisk.o llseek.o disksize.o fdiskbsdlabel.o fdisksgilabel.o fdisksunlabel.o \
+ fdiskmaclabel.o fdiskaixlabel.o i386_sys_types.o partname.o
fdisk.o: fdisk.c fdisk.h
fdiskbsdlabel.o: fdiskbsdlabel.c fdisk.h fdiskbsdlabel.h
fdisksunlabel.o: fdisksunlabel.c fdisksunlabel.h fdisk.h
fdiskaixlabel.o: fdiskaixlabel.c fdiskaixlabel.h fdisk.h
+fdiskmaclabel.o: fdiskmaclabel.c fdiskmaclabel.h fdisk.h
+
fdisk.o cfdisk.o sfdisk.o fdiskbsdlabel.o fdisksunlabel.o \
- fdisksgilabel.o fdiskaixlabel.o i386_sys_types.o partname.o: common.h
-sfdisk: sfdisk.o disksize.o i386_sys_types.o partname.o
+ fdisksgilabel.o fdiskaixlabel.o fdiskmaclabel.o i386_sys_types.o partname.o: common.h
+sfdisk: sfdisk.o disksize.o i386_sys_types.o partname.o
install: all
$(INSTALLDIR) $(SBINDIR)
--- util-linux-2.12q/fdisk/fdisk.c
+++ util-linux-2.12q/fdisk/fdisk.c
@@ -26,6 +26,7 @@
#include "fdisksunlabel.h"
#include "fdisksgilabel.h"
#include "fdiskaixlabel.h"
+#include "fdiskmaclabel.h"
#include "../defines.h"
#ifdef HAVE_blkpg_h
@@ -165,11 +166,12 @@
unsigned long long total_number_of_sectors;
-#define dos_label (!sun_label && !sgi_label && !aix_label && !osf_label)
+#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;
@@ -363,6 +365,10 @@
puts(_(" v verify the partition table"));
puts(_(" w write table to disk and exit"));
}
+ else if (mac_label) {
+ puts(_("no Commands available"));
+
+ }
else if (aix_label) {
puts(_("Command action"));
puts(_(" m print this menu"));
@@ -443,6 +449,9 @@
puts(_(" v verify the partition table"));
puts(_(" w write table to disk and exit"));
}
+ else if (mac_label) {
+ puts(_("no Commands available"));
+ }
else {
puts(_("Command action"));
puts(_(" b move beginning of data in a partition")); /* !sun */
@@ -943,6 +952,9 @@
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)) {
@@ -2074,6 +2086,15 @@
"This will destroy the present disk contents.\n"));
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;
@@ -2404,7 +2425,11 @@
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)
+ return;
+ if (mac_label)
+ return;
+ if (btrydev(device) < 0)
fprintf(stderr,
_("Disk %s doesn't contain a valid "
"partition table\n"), device);