From: Michael McMaster Date: Tue, 10 Sep 2013 02:12:36 +0000 (+1000) Subject: Incorporated Debian patches from mac-fdisk 0.1-16 X-Git-Tag: Debian-0.1-16 X-Git-Url: http://git.codesrc.com/gitweb.cgi?a=commitdiff_plain;h=24597d76571fc4cf0a7b6b8a31815dc8c1aeb955;p=hfdisk.git Incorporated Debian patches from mac-fdisk 0.1-16 --- diff --git a/Makefile b/Makefile index f26608f..0adf886 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,14 @@ pdisk: pdisk.o dump.o partition_map.o convert.o io.o errors.o bitfield.o fdisk: fdisk.o fdisklabel.o clean: - rm -f *.o pdisk fdisk + rm -f *.o pdisk fdisk mac-fdisk pmac-fdisk + +install: pdisk fdisk + -rm -f pmac-fdisk mac-fdisk + ln pdisk mac-fdisk + ln fdisk pmac-fdisk + install -o root -g root -m 0755 mac-fdisk ${DESTDIR}/sbin + install -o root -g root -m 0755 pmac-fdisk ${DESTDIR}/sbin distribution: cd ..; tar cvf pdisk.src.tar.`date +%y%m%d` --files-from pdisk/list.src diff --git a/dpme.h b/dpme.h index 2994266..c2a9958 100644 --- a/dpme.h +++ b/dpme.h @@ -61,7 +61,7 @@ // typedef unsigned char u8; typedef unsigned short u16; -typedef unsigned long u32; +typedef unsigned int u32; // Physical block zero of the disk has this format @@ -113,10 +113,17 @@ struct dpme { #endif u32 dpme_boot_block ; u32 dpme_boot_bytes ; +#ifdef __linux__ + u32 dpme_load_addr ; + u32 dpme_load_addr_2 ; + u32 dpme_goto_addr ; + u32 dpme_goto_addr_2 ; +#else u8 *dpme_load_addr ; u8 *dpme_load_addr_2 ; u8 *dpme_goto_addr ; u8 *dpme_goto_addr_2 ; +#endif u32 dpme_checksum ; char dpme_process_id[16] ; u32 dpme_boot_args[32] ; @@ -124,6 +131,7 @@ struct dpme { }; typedef struct dpme DPME; +#define dpme_automount_set(p, v) bitfield_set(&p->dpme_flags, 30, 1, v) /* MSch */ #define dpme_os_specific_1_set(p, v) bitfield_set(&p->dpme_flags, 8, 1, v) #define dpme_os_specific_2_set(p, v) bitfield_set(&p->dpme_flags, 7, 1, v) #define dpme_os_pic_code_set(p, v) bitfield_set(&p->dpme_flags, 6, 1, v) @@ -134,6 +142,7 @@ typedef struct dpme DPME; #define dpme_allocated_set(p, v) bitfield_set(&p->dpme_flags, 1, 1, v) #define dpme_valid_set(p, v) bitfield_set(&p->dpme_flags, 0, 1, v) +#define dpme_automount_get(p) bitfield_get(p->dpme_flags, 30, 1) /* MSch */ #define dpme_os_specific_1_get(p) bitfield_get(p->dpme_flags, 8, 1) #define dpme_os_specific_2_get(p) bitfield_get(p->dpme_flags, 7, 1) #define dpme_os_pic_code_get(p) bitfield_get(p->dpme_flags, 6, 1) diff --git a/dump.c b/dump.c index 61ad91b..4153dc5 100644 --- a/dump.c +++ b/dump.c @@ -3,7 +3,11 @@ // // Written by Eryk Vershen (eryk@apple.com) // - +/* + * Linux/m68k version by Christiaan Welvaart + * minor fixes and glibc change by Michael Schmitz + */ + /* * Copyright 1996,1997 by Apple Computer, Inc. * All Rights Reserved @@ -60,6 +64,7 @@ typedef struct names { // NAMES plist[] = { "Drvr", "Apple_Driver", + "Dr43", "Apple_Driver43", "Free", "Apple_Free", " HFS", "Apple_HFS", " MFS", "Apple_MFS", @@ -83,7 +88,7 @@ const char * kStringNot = " not"; // Forward declarations // void dump_block_zero(partition_map_header *map); -void dump_partition_entry(partition_map *entry, int digits); +void dump_partition_entry(partition_map *entry, int digits, char *dev); // @@ -119,6 +124,7 @@ dump_block_zero(partition_map_header *map) } printf("\nBlock size=%u, Number of Blocks=%u\n", p->sbBlkSize, p->sbBlkCount); +#ifndef __mc68000__ printf("DeviceType=0x%x, DeviceId=0x%x\n", p->sbDevType, p->sbDevId); if (p->sbDrvrCount > 0) { @@ -130,6 +136,7 @@ dump_block_zero(partition_map_header *map) } } printf("\n"); +#endif } @@ -138,31 +145,50 @@ dump_partition_map(partition_map_header *map, int disk_order) { partition_map * entry; int j; + size_t len; + char *buf; if (map == NULL) { bad_input("No partition map exists"); return; } +#ifdef __mc68000__ + printf("Disk %s\n", map->name); +#else printf("%s\n", map->name); +#endif j = number_of_digits(map->media_size); if (j < 7) { j = 7; } - printf(" #: type name " - "%*s %-*s ( size )\n", j, "length", j, "base"); +#ifdef __mc68000__ + printf("%*s type name " + "%*s %-*s ( size ) system\n", strlen(map->name)+1, "#", j, "length", j, "base"); +#else + printf("%*s type name " + "%*s %-*s ( size ) system\n", strlen(map->name)+1, "#", j, "length", j, "base"); +#endif + + /* Grok devfs names. (courtesy Colin Walters)*/ + + len = strlen(map->name); + buf = strdup(map->name); + if (len >= 4 && !strcmp(buf+len-4, "disc")) { + strcpy(buf+len-4, "part"); + } if (disk_order) { for (entry = map->disk_order; entry != NULL; entry = entry->next_on_disk) { - dump_partition_entry(entry, j); + dump_partition_entry(entry, j, buf); } } else { for (entry = map->base_order; entry != NULL; entry = entry->next_by_base) { - dump_partition_entry(entry, j); + dump_partition_entry(entry, j, buf); } } dump_block_zero(map); @@ -170,18 +196,23 @@ dump_partition_map(partition_map_header *map, int disk_order) void -dump_partition_entry(partition_map *entry, int digits) +dump_partition_entry(partition_map *entry, int digits, char *dev) { partition_map_header *map; int j; DPME *p; BZB *bp; char *s; +#ifdef __mc68000__ + int aflag = 1; +#else int aflag = 0; +#endif int pflag = 1; u32 size; double bytes; + map = entry->the_map; p = entry->data; if (aflag) { @@ -192,9 +223,13 @@ dump_partition_entry(partition_map *entry, int digits) break; } } - printf("%4d: %.4s %-18.32s ", entry->disk_address, s, p->dpme_name); +#ifdef __mc68000__ + printf("%s%-2d %.4s %-12.12s ", dev, entry->disk_address, s, p->dpme_name); +#else + printf("%s%-4d %.4s %-18.32s ", dev, entry->disk_address, s, p->dpme_name); +#endif } else { - printf("%4d: %20.32s %-18.32s ", + printf("%s%-4d %20.32s %-18.32s ", dev, entry->disk_address, p->dpme_type, p->dpme_name); } @@ -217,7 +252,10 @@ dump_partition_entry(partition_map *entry, int digits) printf("@~%-*u", digits, p->dpme_pblock_start + p->dpme_lblock_start); } + j = 's'; + bytes = size / ONE_KILOBYTE_IN_BLOCKS; + j = 'k'; if (bytes >= 1024.0) { bytes = bytes / 1024.0; if (bytes < 1024.0) { @@ -226,58 +264,45 @@ dump_partition_entry(partition_map *entry, int digits) bytes = bytes / 1024.0; j = 'G'; } - printf(" (%#5.1f%c)", bytes, j); } - -#if 0 - // Old A/UX fields that no one pays attention to anymore. - bp = (BZB *) (p->dpme_bzb); - j = -1; - if (bp->bzb_magic == BZBMAGIC) { - switch (bp->bzb_type) { - case FSTEFS: - s = "EFS"; - break; - case FSTSFS: - s = "SFS"; - j = 1; - break; - case FST: - default: - if (bzb_root_get(bp) != 0) { - if (bzb_usr_get(bp) != 0) { - s = "RUFS"; - } else { - s = "RFS"; - } - j = 0; - } else if (bzb_usr_get(bp) != 0) { - s = "UFS"; - j = 2; - } else { - s = "FS"; - } - break; - } - if (bzb_slice_get(bp) != 0) { - printf(" s%1d %4s", bzb_slice_get(bp)-1, s); - } else if (j >= 0) { - printf(" S%1d %4s", j, s); - } else { - printf(" %4s", s); - } - if (bzb_crit_get(bp) != 0) { - printf(" K%1d", bp->bzb_cluster); - } else if (j < 0) { - printf(" "); - } else { - printf(" k%1d", bp->bzb_cluster); - } - if (bp->bzb_mount_point[0] != 0) { - printf(" %.64s", bp->bzb_mount_point); - } + printf(" (%#5.1f%c) ", bytes, j); + + if (!strcmp(p->dpme_type, "Apple_UNIX_SVR2")) + { + if (!strcmp(p->dpme_name, "Swap") || !strcmp(p->dpme_name, "swap")) + printf("Linux swap"); + else + printf("Linux native"); } -#endif + else + if (!strcmp(p->dpme_type, "Apple_Bootstrap")) + printf("NewWorld bootblock"); + else + if (!strcmp(p->dpme_type, "Apple_Scratch")) + printf("Linux swap"); //not just linux, but who cares + else + if (!strcmp(p->dpme_type, "Apple_HFS")) + printf("HFS"); + else + if (!strcmp(p->dpme_type, "Apple_MFS")) + printf("MFS"); + else + if (!strcmp(p->dpme_type, "Apple_Driver")) + printf("Driver"); + else + if (!strcmp(p->dpme_type, "Apple_Driver43")) + printf("Driver 4.3"); + else + if (!strcmp(p->dpme_type, "Apple_partition_map")) + printf("Partition map"); + else + if (!strcmp(p->dpme_type, "Apple_PRODOS")) + printf("ProDOS"); + else + if (!strcmp(p->dpme_type, "Apple_Free")) + printf("Free space"); + else + printf("Unknown"); printf("\n"); } @@ -316,6 +341,24 @@ list_all_disks() dump(name); } +#ifdef __linux__ + for (i = 0; i < 4; i++) { + sprintf(name, "/dev/hd%c", 'a'+i); + if ((fd = open_device(name, O_RDONLY)) < 0) { + if (errno == EACCES) { + error(errno, "can't open file '%s'", name); + } + continue; + } + if (read_block(fd, 1, (char *)data, 1) == 0) { + close_device(fd); + continue; + } + close_device(fd); + + dump(name); + } +#endif free(data); } @@ -385,7 +428,7 @@ u32 dpme_reserved_3[62] ; printf("%2d: %20.32s ", entry->disk_address, p->dpme_type); printf("%7u @ %-7u ", p->dpme_pblocks, p->dpme_pblock_start); - printf("%c%c%c%c%c%c%c%c%c ", + printf("%c%c%c%c%c%c%c%c%c%c ", (dpme_valid_get(p))?'V':'v', (dpme_allocated_get(p))?'A':'a', (dpme_in_use_get(p))?'I':'i', @@ -394,7 +437,8 @@ u32 dpme_reserved_3[62] ; (dpme_writable_get(p))?'W':'w', (dpme_os_pic_code_get(p))?'P':'p', (dpme_os_specific_1_get(p))?'1':'.', - (dpme_os_specific_2_get(p))?'2':'.'); + (dpme_os_specific_2_get(p))?'2':'.', + (dpme_automount_get(p))?'M':'m'); if (p->dpme_lblock_start != 0 || p->dpme_pblocks != p->dpme_lblocks) { printf("(%u @ %u)", p->dpme_lblocks, p->dpme_lblock_start); } diff --git a/fdisk.c b/fdisk.c index 11e92db..d77619b 100644 --- a/fdisk.c +++ b/fdisk.c @@ -62,7 +62,6 @@ #include #include #include -#include #include #include #include @@ -71,9 +70,9 @@ #include -#include -#include -#include +typedef unsigned short kdev_t; /* BAD hack; kdev_t is not exported */ + +#include "kernel-defs.h" #include "fdisk.h" @@ -428,7 +427,7 @@ void read_extended(struct partition *p) offsets[partitions] = extended_offset + SWAP32(p->start_sect); if (!extended_offset) extended_offset = SWAP32(p->start_sect); - if (llseek(fd, (loff_t)offsets[partitions] + if (lseek64(fd, (loff_t)offsets[partitions] * SECTOR_SIZE, SEEK_SET) < 0) fatal(unable_to_seek); if (!(buffers[partitions] = (char *) malloc(SECTOR_SIZE))) @@ -438,14 +437,14 @@ void read_extended(struct partition *p) part_table[partitions] = ext_pointers[partitions] = NULL; q = p = offset(buffers[partitions], 0); for (i = 0; i < 4; i++, p++) { - if (p->sys_ind == EXTENDED) + if (p->sys_ind == EXTENDED) { if (ext_pointers[partitions]) fprintf(stderr, "Warning: extra link " "pointer in partition table " "%d\n", partitions + 1); else ext_pointers[partitions] = p; - else if (p->sys_ind) + } else if (p->sys_ind) { if (part_table[partitions]) fprintf(stderr, "Warning: ignoring extra data " @@ -453,15 +452,18 @@ void read_extended(struct partition *p) partitions + 1); else part_table[partitions] = p; + } } - if (!part_table[partitions]) + if (!part_table[partitions]) { if (q != ext_pointers[partitions]) part_table[partitions] = q; else part_table[partitions] = q + 1; - if (!ext_pointers[partitions]) + } + if (!ext_pointers[partitions]) { if (q != part_table[partitions]) ext_pointers[partitions] = q; else ext_pointers[partitions] = q + 1; + } p = ext_pointers[partitions++]; } } @@ -497,11 +499,12 @@ void get_boot(void) warn_geometry(); for (i = 0; i < 4; i++) - if(part_table[i]->sys_ind == EXTENDED) + if(part_table[i]->sys_ind == EXTENDED) { if (partitions != 4) fprintf(stderr, "Ignoring extra extended " "partition %d\n", i + 1); else read_extended(part_table[ext_index = i]); + } for (i = 3; i < partitions; i++) if (SWAP16(*table_check(buffers[i])) != PART_TABLE_FLAG) { @@ -621,6 +624,7 @@ uint read_int(uint low, uint dflt, uint high, enum offset base, char *mesg) case lower: i += low; break; case upper: i += high; break; case deflt: i += dflt; break; + default: break; } } else @@ -844,12 +848,12 @@ static void check_consistency(struct partition *p, int partition) return; /* do not check extended partitions */ /* physical beginning c, h, s */ - pbc = p->cyl & 0xff | (p->sector << 2) & 0x300; + pbc = (p->cyl & 0xff) | ((p->sector << 2) & 0x300); pbh = p->head; pbs = p->sector & 0x3f; /* physical ending c, h, s */ - pec = p->end_cyl & 0xff | (p->end_sector << 2) & 0x300; + pec = (p->end_cyl & 0xff) | ((p->end_sector << 2) & 0x300); peh = p->end_head; pes = p->end_sector & 0x3f; @@ -941,7 +945,7 @@ void x_list_table(int extend) disk_device, heads, sectors, cylinders); printf("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n"); for (i = 0 ; i < partitions; i++) - if (p = q[i]) { + if ((p = q[i])) { printf("%2d %02x%4d%4d%5d%4d%4d%5d%8d%8d %02x\n", i + 1, p->boot_ind, p->head, sector(p->sector), @@ -1026,7 +1030,7 @@ void verify(void) last[i]); total += last[i] + 1 - first[i]; for (j = 0; j < i; j++) - if (first[i] >= first[j] && first[i] <= last[j] + if ((first[i] >= first[j] && first[i] <= last[j]) || (last[i] <= last[j] && last[i] >= first[j])) { printf("Warning: partition %d overlaps " @@ -1060,11 +1064,11 @@ void verify(void) if (total > heads * sectors * cylinders) printf("Total allocated sectors %d greater than the maximum " "%d\n", total, heads * sectors * cylinders); - else if (total = heads * sectors * cylinders - total) + else if ((total = heads * sectors * cylinders - total)) printf("%d unallocated sectors\n", total); } -void add_partition(int n, int sys) +static void add_partition(int n, int sys) { char mesg[48]; int i, read = 0; @@ -1100,11 +1104,12 @@ void add_partition(int n, int sys) for (i = 0; i < partitions; i++) { if (start == offsets[i]) start += sector_offset; - if (start >= first[i] && start <= last[i]) + if (start >= first[i] && start <= last[i]) { if (n < 4) start = last[i] + 1; else start = last[i] + sector_offset; + } } if (start > limit) break; @@ -1249,7 +1254,7 @@ void write_table(void) for (i = 3; i < partitions; i++) if (changed[i]) { *table_check(buffers[i]) = SWAP16(PART_TABLE_FLAG); - if (llseek(fd, (loff_t)offsets[i] + if (lseek64(fd, (loff_t)offsets[i] * SECTOR_SIZE, SEEK_SET) < 0) fatal(unable_to_seek); if (write(fd, buffers[i], SECTOR_SIZE) != SECTOR_SIZE) @@ -1262,7 +1267,7 @@ void write_table(void) "(Reboot to ensure the partition table has been updated.)\n"); sync(); sleep(2); - if (i = ioctl(fd, BLKRRPART)) { + if ((i = ioctl(fd, BLKRRPART))) { error = errno; } else { /* some kernel versions (1.2.x) seem to have trouble @@ -1270,7 +1275,7 @@ void write_table(void) twice, the second time works. - biro@yggdrasil.com */ sync(); sleep(2); - if(i = ioctl(fd, BLKRRPART)) + if((i = ioctl(fd, BLKRRPART))) error = errno; } @@ -1391,7 +1396,7 @@ void xselect(void) void try(char *device) { disk_device = device; - if (!setjmp(listingbuf)) + if (!setjmp(listingbuf)) { if ((fd = open(disk_device, type_open)) >= 0) { close(fd); get_boot(); @@ -1407,6 +1412,7 @@ void try(char *device) exit(1); } } + } } void main(int argc, char **argv) diff --git a/fdisklabel.c b/fdisklabel.c index 9344339..70c3cfa 100644 --- a/fdisklabel.c +++ b/fdisklabel.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -47,9 +46,7 @@ #include #include -#include -#include -#include +#include "kernel-defs.h" #include "fdisk.h" #define DKTYPENAMES @@ -377,7 +374,7 @@ bsd_create_disklabel (void) { #if defined (i386) if (bsd_initlabel (bsd_part, &bsd_dlabel, bsd_part_index) == 1) -#elif defined (__alpha__) || defined (__powerpc__) +#elif defined (__alpha__) || defined (__powerpc__) || defined (__mc68000__) if (bsd_initlabel (NULL, &bsd_dlabel, 0) == 1) #endif { @@ -515,7 +512,7 @@ bsd_write_bootstrap (void) alpha_bootblock_checksum (buffer); #endif - if (llseek (fd, sector * SECTOR_SIZE, SEEK_SET) == -1) + if (lseek64 (fd, sector * SECTOR_SIZE, SEEK_SET) == -1) fatal (unable_to_seek); if (BSD_BBSIZE != write (fd, buffer, BSD_BBSIZE)) fatal (unable_to_write); @@ -679,7 +676,7 @@ bsd_readlabel (struct partition *p, struct disklabel *d) sector = 0; #endif - if (llseek (fd, sector * SECTOR_SIZE, SEEK_SET) == -1) + if (lseek64 (fd, sector * SECTOR_SIZE, SEEK_SET) == -1) fatal (unable_to_seek); if (BSD_BBSIZE != read (fd, buffer, BSD_BBSIZE)) fatal (unable_to_read); @@ -724,12 +721,12 @@ bsd_writelabel (struct partition *p, struct disklabel *d) #if defined (__alpha__) && BSD_LABELSECTOR == 0 alpha_bootblock_checksum (buffer); - if (llseek (fd, 0, SEEK_SET) == -1) + if (lseek64 (fd, 0, SEEK_SET) == -1) fatal (unable_to_seek); if (BSD_BBSIZE != write (fd, buffer, BSD_BBSIZE)) fatal (unable_to_write); #else - if (llseek (fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1) + if (lseek64 (fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1) fatal (unable_to_seek); if (sizeof (struct disklabel) != write (fd, d, sizeof (struct disklabel))) fatal (unable_to_write); diff --git a/fdisklabel.h b/fdisklabel.h index 0b5227c..a9c4d2e 100644 --- a/fdisklabel.h +++ b/fdisklabel.h @@ -52,6 +52,12 @@ #define BSD_LABELOFFSET 0 #define BSD_BBSIZE 0 #define BSD_SBSIZE 0 +#elif defined (__mc68000__) +/* LABELSECTOR, LABELOFFSET, BBSIZE & SBSIZE are undefined for __powerpc__ */ +#define BSD_LABELSECTOR 0 +#define BSD_LABELOFFSET 0 +#define BSD_BBSIZE 0 +#define BSD_SBSIZE 0 #else #error unknown architecture #endif diff --git a/io.c b/io.c index 0c99d94..0937e29 100644 --- a/io.c +++ b/io.c @@ -30,6 +30,10 @@ #include #include #include +#else +#ifdef __GLIBC__ +#include +#endif #endif #include #include @@ -51,6 +55,8 @@ #define SCSI_FD 8 #define loff_t long #define llseek lseek +#else +#define llseek lseek64 #endif @@ -435,8 +441,8 @@ read_block(int fd, unsigned long num, char *buf, int quiet) #else { #endif - x = num * PBLOCK_SIZE; - if ((x = llseek(fd, x, 0)) < 0) { + x = ((long long) num * PBLOCK_SIZE); /* cast to ll to work around compiler bug */ + if ((x = lseek64(fd, x, 0)) < 0) { if (quiet == 0) { error(errno, "Can't seek on file"); } diff --git a/partition_map.c b/partition_map.c index 113f66b..6ca2c16 100644 --- a/partition_map.c +++ b/partition_map.c @@ -30,14 +30,12 @@ #include #include #endif -#include #include #include #ifdef __linux__ #include -#include -#include +#include "kernel-defs.h" #include #endif @@ -65,6 +63,8 @@ const char * kFreeType = "Apple_Free"; const char * kMapType = "Apple_partition_map"; const char * kUnixType = "Apple_UNIX_SVR2"; +const char * kBootstrapType = "Apple_Bootstrap"; +const char * kBootstrapName = "bootstrap"; const char * kFreeName = "Extra"; @@ -288,15 +288,17 @@ write_partition_map(partition_map_header *map) free(block); } } - printf("The partition table has been altered!\n\n"); + printf("The partition map has been saved successfully!\n\n"); #ifdef __linux__ if (map->regular_file) { close_device(map->fd); } else { - // printf("Calling ioctl() to re-read partition table.\n" - // "(Reboot to ensure the partition table has been updated.)\n"); - sync(); + // printf("Calling ioctl() to re-read partition table.\n"); + if ((i = ioctl(fd, BLKFLSBUF)) != 0) { + perror("ioctl(BLKFLSBUF)"); + sync(); + } sleep(2); if ((i = ioctl(fd, BLKRRPART)) != 0) { saved_errno = errno; @@ -304,20 +306,26 @@ write_partition_map(partition_map_header *map) // some kernel versions (1.2.x) seem to have trouble // rereading the partition table, but if asked to do it // twice, the second time works. - biro@yggdrasil.com */ - sync(); + // printf("Again calling ioctl() to re-read partition table.\n"); + if ((i = ioctl(fd, BLKFLSBUF)) != 0) { + perror("ioctl(BLKFLSBUF)"); + sync(); + } sleep(2); if ((i = ioctl(fd, BLKRRPART)) != 0) { saved_errno = errno; } } + printf("Syncing disks.\n"); + if ((i = ioctl(fd, BLKFLSBUF)) != 0) { + perror("ioctl(BLKFLSBUF)"); + sync(); + } close_device(map->fd); - - // printf("Syncing disks.\n"); - sync(); sleep(4); /* for sync() */ if (i < 0) { - error(saved_errno, "Re-read of partition table failed"); + error(saved_errno, "Re-read of partition map failed"); printf("Reboot your system to ensure the " "partition table is updated.\n"); } @@ -692,9 +700,9 @@ compute_device_size(int fd) geometry.heads*geometry.sectors*geometry.cylinders); } - if ((pos = llseek(fd, 0, SEEK_END)) < 0) { + if ((pos = lseek64(fd, 0, SEEK_END)) < 0) { printf("llseek to end of device failed\n"); - } else if ((pos = llseek(fd, 0, SEEK_CUR)) < 0) { + } else if ((pos = lseek64(fd, 0, SEEK_CUR)) < 0) { printf("llseek to end of device failed on second try\n"); } else { printf("llseek: pos = %d, blocks=%d\n", pos, pos/PBLOCK_SIZE); @@ -895,6 +903,7 @@ move_entry_in_map(long old_index, long index, partition_map_header *map) printf("No such partition\n"); } else { remove_from_disk_order(cur); + if (old_index < index) index++; /* renumber_disk_addresses(map); */ cur->disk_address = index; insert_in_disk_order(cur); renumber_disk_addresses(map); diff --git a/partition_map.h b/partition_map.h index 90f2210..526f605 100644 --- a/partition_map.h +++ b/partition_map.h @@ -69,6 +69,8 @@ typedef struct partition_map partition_map; extern const char * kFreeType; extern const char * kMapType; extern const char * kUnixType; +extern const char * kBootstrapType; +extern const char * kBootstrapName; extern const char * kFreeName; diff --git a/pdisk.c b/pdisk.c index 52f98c7..a9bc629 100644 --- a/pdisk.c +++ b/pdisk.c @@ -30,18 +30,17 @@ #include #ifdef __linux__ #include +#include #else #include #include #include #endif -#include #include #ifdef __linux__ #include -#include -#include +#include "kernel-defs.h" #endif #include "pdisk.h" @@ -94,6 +93,7 @@ int rflag; void do_add_intel_partition(partition_map_header *map); void do_change_map_size(partition_map_header *map); void do_create_partition(partition_map_header *map, int get_type); +void do_create_bootstrap_partition(partition_map_header *map); void do_delete_partition(partition_map_header *map); int do_expert(partition_map_header *map); void do_reorder(partition_map_header *map); @@ -114,6 +114,7 @@ int main(int argc, char **argv) { int name_index; + int err=0; if (sizeof(DPME) != PBLOCK_SIZE) { fatal(-1, "Size of partion map entry (%d) " @@ -150,7 +151,9 @@ main(int argc, char **argv) } else if (!vflag) { usage("no device argument"); do_help(); + err=-EINVAL; // debatable } + exit(err); } #else main() @@ -351,7 +354,8 @@ edit(char *name) printf(" P (print ordered by base address)\n"); printf(" i initialize partition map\n"); printf(" s change size of partition map\n"); - printf(" c create new partition\n"); + printf(" b create new 800K bootstrap partition\n"); + printf(" c create new Linux partition\n"); printf(" C (create with type also specified)\n"); printf(" d delete a partition\n"); printf(" r reorder partition entry in map\n"); @@ -378,6 +382,10 @@ edit(char *name) case 'i': map = init_partition_map(name, map); break; + case 'B': + case 'b': + do_create_bootstrap_partition(map); + break; case 'C': get_type = 1; // fall through @@ -471,6 +479,30 @@ do_create_partition(partition_map_header *map, int get_type) } +void +do_create_bootstrap_partition(partition_map_header *map) +{ + long base; + + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + + if (!rflag && map->writeable == 0) { + printf("The map is not writeable.\n"); + } + + // XXX add help feature (i.e. '?' in any argument routine prints help string) + if (get_base_argument(&base, map) == 0) { + return; + } + + // create 800K type Apple_Bootstrap partition named `bootstrap' + add_partition_to_map(kBootstrapName, kBootstrapType, base, 1600, map); +} + + int get_base_argument(long *number, partition_map_header *map) { @@ -508,7 +540,7 @@ get_size_argument(long *number, partition_map_header *map) int result = 0; long multiple; - if (get_number_argument("Length in blocks: ", number, kDefault) == 0) { + if (get_number_argument("Length (in blocks, kB (k), MB (M) or GB (G)): ", number, kDefault) == 0) { bad_input("Bad length"); } else { result = 1; @@ -605,13 +637,22 @@ do_write_partition_map(partition_map_header *map) bad_input("The map is not writeable."); return; } - printf("Writing the map destroys what was there before. "); - if (get_okay("Is that okay? [n/y]: ", 0) != 1) { +// printf("Writing the map destroys what was there before. "); + printf("IMPORTANT: You are about to write a changed partition map to disk. \n"); + printf("For any partition you changed the start or size of, writing out \n"); + printf("the map causes all data on that partition to be LOST FOREVER. \n"); + printf("Make sure you have a backup of any data on such partitions you \n"); + printf("want to keep before answering 'yes' to the question below! \n\n"); + if (get_okay("Write partition map? [n/y]: ", 0) != 1) { return; } write_partition_map(map); + printf("\nPartition map written to disk. If any partitions on this disk \n"); + printf("were still in use by the system (see messages above), you will need \n"); + printf("to reboot in order to utilize the new partition map.\n\n"); + // exit(0); }