summaryrefslogtreecommitdiff
path: root/util-linux/fdisk.c
diff options
context:
space:
mode:
authorKevin Cernekee <cernekee@gmail.com>2010-10-25 02:00:24 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-10-25 02:00:24 +0200
commitccb070450e79c33fb3f755dbea2fdd979f09d3fb (patch)
treeed842febd5fa0b19bbb7e42d2d98d59f6e3c5c8d /util-linux/fdisk.c
parent3b060528a26830ee26aab4e9829ac3a310f06218 (diff)
downloadbusybox-w32-ccb070450e79c33fb3f755dbea2fdd979f09d3fb.tar.gz
busybox-w32-ccb070450e79c33fb3f755dbea2fdd979f09d3fb.tar.bz2
busybox-w32-ccb070450e79c33fb3f755dbea2fdd979f09d3fb.zip
fdisk: initial stab at GPT partition support
Signed-off-by: Kevin Cernekee <cernekee@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/fdisk.c')
-rw-r--r--util-linux/fdisk.c79
1 files changed, 57 insertions, 22 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index b6417a355..3f2e0d3ae 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -107,12 +107,30 @@ struct partition {
107 unsigned char size4[4]; /* nr of sectors in partition */ 107 unsigned char size4[4]; /* nr of sectors in partition */
108} PACKED; 108} PACKED;
109 109
110/*
111 * per partition table entry data
112 *
113 * The four primary partitions have the same sectorbuffer (MBRbuffer)
114 * and have NULL ext_pointer.
115 * Each logical partition table entry has two pointers, one for the
116 * partition and one link to the next one.
117 */
118struct pte {
119 struct partition *part_table; /* points into sectorbuffer */
120 struct partition *ext_pointer; /* points into sectorbuffer */
121 sector_t offset_from_dev_start; /* disk sector number */
122 char *sectorbuffer; /* disk sector contents */
123#if ENABLE_FEATURE_FDISK_WRITABLE
124 char changed; /* boolean */
125#endif
126};
127
110#define unable_to_open "can't open '%s'" 128#define unable_to_open "can't open '%s'"
111#define unable_to_read "can't read from %s" 129#define unable_to_read "can't read from %s"
112#define unable_to_seek "can't seek on %s" 130#define unable_to_seek "can't seek on %s"
113 131
114enum label_type { 132enum label_type {
115 LABEL_DOS, LABEL_SUN, LABEL_SGI, LABEL_AIX, LABEL_OSF 133 LABEL_DOS, LABEL_SUN, LABEL_SGI, LABEL_AIX, LABEL_OSF, LABEL_GPT
116}; 134};
117 135
118#define LABEL_IS_DOS (LABEL_DOS == current_label_type) 136#define LABEL_IS_DOS (LABEL_DOS == current_label_type)
@@ -149,6 +167,14 @@ enum label_type {
149#define STATIC_OSF extern 167#define STATIC_OSF extern
150#endif 168#endif
151 169
170#if ENABLE_FEATURE_GPT_LABEL
171#define LABEL_IS_GPT (LABEL_GPT == current_label_type)
172#define STATIC_GPT static
173#else
174#define LABEL_IS_GPT 0
175#define STATIC_GPT extern
176#endif
177
152enum action { OPEN_MAIN, TRY_ONLY, CREATE_EMPTY_DOS, CREATE_EMPTY_SUN }; 178enum action { OPEN_MAIN, TRY_ONLY, CREATE_EMPTY_DOS, CREATE_EMPTY_SUN };
153 179
154static void update_units(void); 180static void update_units(void);
@@ -162,6 +188,7 @@ static sector_t read_int(sector_t low, sector_t dflt, sector_t high, sector_t ba
162#endif 188#endif
163static const char *partition_type(unsigned char type); 189static const char *partition_type(unsigned char type);
164static void get_geometry(void); 190static void get_geometry(void);
191static void read_pte(struct pte *pe, sector_t offset);
165#if ENABLE_FEATURE_SUN_LABEL || ENABLE_FEATURE_FDISK_WRITABLE 192#if ENABLE_FEATURE_SUN_LABEL || ENABLE_FEATURE_FDISK_WRITABLE
166static int get_boot(enum action what); 193static int get_boot(enum action what);
167#else 194#else
@@ -174,24 +201,6 @@ static int get_boot(void);
174static sector_t get_start_sect(const struct partition *p); 201static sector_t get_start_sect(const struct partition *p);
175static sector_t get_nr_sects(const struct partition *p); 202static sector_t get_nr_sects(const struct partition *p);
176 203
177/*
178 * per partition table entry data
179 *
180 * The four primary partitions have the same sectorbuffer (MBRbuffer)
181 * and have NULL ext_pointer.
182 * Each logical partition table entry has two pointers, one for the
183 * partition and one link to the next one.
184 */
185struct pte {
186 struct partition *part_table; /* points into sectorbuffer */
187 struct partition *ext_pointer; /* points into sectorbuffer */
188 sector_t offset_from_dev_start; /* disk sector number */
189 char *sectorbuffer; /* disk sector contents */
190#if ENABLE_FEATURE_FDISK_WRITABLE
191 char changed; /* boolean */
192#endif
193};
194
195/* DOS partition types */ 204/* DOS partition types */
196 205
197static const char *const i386_sys_types[] = { 206static const char *const i386_sys_types[] = {
@@ -653,6 +662,8 @@ STATIC_OSF void bsd_select(void);
653STATIC_OSF void xbsd_print_disklabel(int); 662STATIC_OSF void xbsd_print_disklabel(int);
654#include "fdisk_osf.c" 663#include "fdisk_osf.c"
655 664
665#include "fdisk_gpt.c"
666
656#if ENABLE_FEATURE_SGI_LABEL || ENABLE_FEATURE_SUN_LABEL 667#if ENABLE_FEATURE_SGI_LABEL || ENABLE_FEATURE_SUN_LABEL
657static uint16_t 668static uint16_t
658fdisk_swap16(uint16_t x) 669fdisk_swap16(uint16_t x)
@@ -833,6 +844,11 @@ menu(void)
833 puts("o\tcreate a new empty DOS partition table"); 844 puts("o\tcreate a new empty DOS partition table");
834 puts("q\tquit without saving changes"); 845 puts("q\tquit without saving changes");
835 puts("s\tcreate a new empty Sun disklabel"); /* sun */ 846 puts("s\tcreate a new empty Sun disklabel"); /* sun */
847 } else if (LABEL_IS_GPT) {
848 puts("o\tcreate a new empty DOS partition table");
849 puts("p\tprint the partition table");
850 puts("q\tquit without saving changes");
851 puts("s\tcreate a new empty Sun disklabel"); /* sun */
836 } else { 852 } else {
837 puts("a\ttoggle a bootable flag"); 853 puts("a\ttoggle a bootable flag");
838 puts("b\tedit bsd disklabel"); 854 puts("b\tedit bsd disklabel");
@@ -1308,7 +1324,18 @@ get_geometry(void)
1308 1324
1309/* 1325/*
1310 * Opens disk_device and optionally reads MBR. 1326 * Opens disk_device and optionally reads MBR.
1311 * FIXME: document what each 'what' value will do! 1327 * If what == OPEN_MAIN:
1328 * Open device, read MBR. Abort program on short read. Create empty
1329 * disklabel if the on-disk structure is invalid (WRITABLE mode).
1330 * If what == TRY_ONLY:
1331 * Open device, read MBR. Return an error if anything is out of place.
1332 * Do not create an empty disklabel. This is used for the "list"
1333 * operations: "fdisk -l /dev/sda" and "fdisk -l" (all devices).
1334 * If what == CREATE_EMPTY_*:
1335 * This means that get_boot() was called recursively from create_*label().
1336 * Do not re-open the device; just set up the ptes array and print
1337 * geometry warnings.
1338 *
1312 * Returns: 1339 * Returns:
1313 * -1: no 0xaa55 flag present (possibly entire disk BSD) 1340 * -1: no 0xaa55 flag present (possibly entire disk BSD)
1314 * 0: found or created label 1341 * 0: found or created label
@@ -1390,6 +1417,10 @@ static int get_boot(void)
1390 if (check_aix_label()) 1417 if (check_aix_label())
1391 return 0; 1418 return 0;
1392#endif 1419#endif
1420#if ENABLE_FEATURE_GPT_LABEL
1421 if (check_gpt_label())
1422 return 0;
1423#endif
1393#if ENABLE_FEATURE_OSF_LABEL 1424#if ENABLE_FEATURE_OSF_LABEL
1394 if (check_osf_label()) { 1425 if (check_osf_label()) {
1395 possibly_osf_label = 1; 1426 possibly_osf_label = 1;
@@ -1409,7 +1440,7 @@ static int get_boot(void)
1409 if (!valid_part_table_flag(MBRbuffer)) { 1440 if (!valid_part_table_flag(MBRbuffer)) {
1410 if (what == OPEN_MAIN) { 1441 if (what == OPEN_MAIN) {
1411 printf("Device contains neither a valid DOS " 1442 printf("Device contains neither a valid DOS "
1412 "partition table, nor Sun, SGI or OSF " 1443 "partition table, nor Sun, SGI, OSF or GPT "
1413 "disklabel\n"); 1444 "disklabel\n");
1414#ifdef __sparc__ 1445#ifdef __sparc__
1415 IF_FEATURE_SUN_LABEL(create_sunlabel();) 1446 IF_FEATURE_SUN_LABEL(create_sunlabel();)
@@ -2056,10 +2087,14 @@ list_table(int xtra)
2056 sun_list_table(xtra); 2087 sun_list_table(xtra);
2057 return; 2088 return;
2058 } 2089 }
2059 if (LABEL_IS_SUN) { 2090 if (LABEL_IS_SGI) {
2060 sgi_list_table(xtra); 2091 sgi_list_table(xtra);
2061 return; 2092 return;
2062 } 2093 }
2094 if (LABEL_IS_GPT) {
2095 gpt_list_table(xtra);
2096 return;
2097 }
2063 2098
2064 list_disk_geometry(); 2099 list_disk_geometry();
2065 2100