summaryrefslogtreecommitdiffstats
path: root/fdisk/fdiskdoslabel.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2012-06-03 20:15:17 +0200
committerKarel Zak2012-06-06 10:30:07 +0200
commite53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf (patch)
treee18917c027cae4af05e2e5a4002ea6de7a5d7cf8 /fdisk/fdiskdoslabel.c
parentfdisk: sun: use sector_t (diff)
downloadkernel-qcow2-util-linux-e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf.tar.gz
kernel-qcow2-util-linux-e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf.tar.xz
kernel-qcow2-util-linux-e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf.zip
fdisk: add device topology to the API
This patch adds device topology discovery to the internal API. This functionality is static only to the API and therefore hidden from general fdisk code. Functionality itself doesn't really change, min_io_size, io_size, logical and physical sector sizes and alignment offset are added to the fdisk_context structure and elements are accessed from there. The logical sector size (sector_size) is now unsigned long instead of unsigned int, this as no effect otherwise. A few things to notice: - The patch is larger than I wanted but we need to modify function parameters across fdisk and its labels to use the topology data from cxt-> instances. Hopefully this will be pretty much it regarding this kind of modifications - perhaps geometry will need something of the like too. - The -b option must override internal discovery. - A new helper function has added to verify if the device provides topology information, this replaces the 'has_topology' global variable. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisk/fdiskdoslabel.c')
-rw-r--r--fdisk/fdiskdoslabel.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c
index 382909c45..8ee35666c 100644
--- a/fdisk/fdiskdoslabel.c
+++ b/fdisk/fdiskdoslabel.c
@@ -22,13 +22,13 @@
s |= (sector >> 2) & 0xc0; \
}
-#define alignment_required (grain != sector_size)
+#define alignment_required (grain != cxt->sector_size)
struct pte ptes[MAXIMUM_PARTS];
sector_t extended_offset;
int ext_index;
-static int get_nonexisting_partition(int warn, int max)
+static int get_nonexisting_partition(struct fdisk_context *cxt, int warn, int max)
{
int pno = -1;
int i;
@@ -54,7 +54,7 @@ static int get_nonexisting_partition(int warn, int max)
return -1;
not_unique:
- return get_partition_dflt(warn, max, dflt);
+ return get_partition_dflt(cxt, warn, max, dflt);
}
@@ -64,7 +64,7 @@ static void read_pte(struct fdisk_context *cxt, int pno, sector_t offset)
struct pte *pe = &ptes[pno];
pe->offset = offset;
- pe->sectorbuffer = xmalloc(sector_size);
+ pe->sectorbuffer = xmalloc(cxt->sector_size);
read_sector(cxt, offset, pe->sectorbuffer);
pe->changed = 0;
pe->part_table = pe->ext_pointer = NULL;
@@ -96,7 +96,7 @@ static void clear_partition(struct partition *p)
set_nr_sects(p,0);
}
-void dos_init(void)
+void dos_init(struct fdisk_context *cxt)
{
int i;
@@ -116,8 +116,8 @@ void dos_init(void)
}
warn_geometry();
- warn_limits();
- warn_alignment();
+ warn_limits(cxt);
+ warn_alignment(cxt);
}
static void read_extended(struct fdisk_context *cxt, int ext)
@@ -219,7 +219,7 @@ void dos_print_mbr_id(void)
printf(_("Disk identifier: 0x%08x\n"), dos_read_mbr_id(MBRbuffer));
}
-void create_doslabel(void)
+void create_doslabel(struct fdisk_context *cxt)
{
unsigned int id;
@@ -228,7 +228,7 @@ void create_doslabel(void)
fprintf(stderr, _("Building a new DOS disklabel with disk identifier 0x%08x.\n"), id);
- dos_init();
+ dos_init(cxt);
zeroize_mbr_buffer();
set_all_unchanged();
@@ -324,7 +324,7 @@ int check_dos_label(struct fdisk_context *cxt)
if (!valid_part_table_flag(MBRbuffer))
return 0;
- dos_init();
+ dos_init(cxt);
for (i = 0; i < 4; i++) {
struct pte *pe = &ptes[i];
@@ -368,7 +368,8 @@ int is_dos_partition(int t)
t == 0xc1 || t == 0xc4 || t == 0xc6);
}
-static void set_partition(int i, int doext, sector_t start,
+static void set_partition(struct fdisk_context *cxt,
+ int i, int doext, sector_t start,
sector_t stop, int sysid)
{
struct partition *p;
@@ -387,7 +388,7 @@ static void set_partition(int i, int doext, sector_t start,
set_nr_sects(p, stop - start + 1);
if (!doext)
- print_partition_size(i + 1, start, stop, sysid);
+ print_partition_size(cxt, i + 1, start, stop, sysid);
if (dos_compatible_flag && (start/(sectors*heads) > 1023))
start = heads*sectors*1024 - 1;
@@ -416,12 +417,13 @@ static sector_t get_unused_start(int part_n, sector_t start,
return start;
}
-static sector_t align_lba_in_range(sector_t lba, sector_t start, sector_t stop)
+static sector_t align_lba_in_range(struct fdisk_context *cxt,
+ sector_t lba, sector_t start, sector_t stop)
{
- start = align_lba(start, ALIGN_UP);
- stop = align_lba(stop, ALIGN_DOWN);
+ start = align_lba(cxt, start, ALIGN_UP);
+ stop = align_lba(cxt, stop, ALIGN_DOWN);
- lba = align_lba(lba, ALIGN_NEAREST);
+ lba = align_lba(cxt, lba, ALIGN_NEAREST);
if (lba < start)
return start;
@@ -430,7 +432,7 @@ static sector_t align_lba_in_range(sector_t lba, sector_t start, sector_t stop)
return lba;
}
-void dos_add_partition(int n, int sys)
+void dos_add_partition(struct fdisk_context *cxt, int n, int sys)
{
char mesg[256]; /* 48 does not suffice in Japanese */
int i, read = 0;
@@ -477,7 +479,7 @@ void dos_add_partition(int n, int sys)
/* the default sector should be aligned and unused */
do {
- aligned = align_lba_in_range(dflt, dflt, limit);
+ aligned = align_lba_in_range(cxt, dflt, dflt, limit);
dflt = get_unused_start(n, aligned, first, last);
} while (dflt != aligned && dflt > aligned && dflt < limit);
@@ -493,7 +495,7 @@ void dos_add_partition(int n, int sys)
if (!read && start == temp) {
sector_t i = start;
- start = read_int(cround(i), cround(dflt), cround(limit),
+ start = read_int(cxt, cround(i), cround(dflt), cround(limit),
0, mesg);
if (display_in_cyl_units) {
start = (start - 1) * units_per_sector;
@@ -536,8 +538,9 @@ void dos_add_partition(int n, int sys)
_("Last %1$s, +%2$s or +size{K,M,G}"),
str_units(SINGULAR), str_units(PLURAL));
- stop = read_int_with_suffix(cround(start), cround(limit), cround(limit),
- cround(start), mesg, &is_suffix_used);
+ stop = read_int_with_suffix(cxt,
+ cround(start), cround(limit), cround(limit),
+ cround(start), mesg, &is_suffix_used);
if (display_in_cyl_units) {
stop = stop * units_per_sector - 1;
if (stop >limit)
@@ -550,15 +553,15 @@ void dos_add_partition(int n, int sys)
* and align the end of the partition. The next
* partition will start at phy.block boundary.
*/
- stop = align_lba_in_range(stop, start, limit) - 1;
+ stop = align_lba_in_range(cxt, stop, start, limit) - 1;
if (stop > limit)
stop = limit;
}
}
- set_partition(n, 0, start, stop, sys);
+ set_partition(cxt, n, 0, start, stop, sys);
if (n > 4)
- set_partition(n - 1, 1, ptes[n].offset, stop, EXTENDED);
+ set_partition(cxt, n - 1, 1, ptes[n].offset, stop, EXTENDED);
if (IS_EXTENDED (sys)) {
struct pte *pe4 = &ptes[4];
@@ -567,7 +570,7 @@ void dos_add_partition(int n, int sys)
ext_index = n;
pen->ext_pointer = p;
pe4->offset = extended_offset = start;
- pe4->sectorbuffer = xcalloc(1, sector_size);
+ pe4->sectorbuffer = xcalloc(1, cxt->sector_size);
pe4->part_table = pt_offset(pe4->sectorbuffer, 0);
pe4->ext_pointer = pe4->part_table + 1;
pe4->changed = 1;
@@ -575,12 +578,12 @@ void dos_add_partition(int n, int sys)
}
}
-static void add_logical(void)
+static void add_logical(struct fdisk_context *cxt)
{
if (partitions > 5 || ptes[4].part_table->sys_ind) {
struct pte *pe = &ptes[partitions];
- pe->sectorbuffer = xcalloc(1, sector_size);
+ pe->sectorbuffer = xcalloc(1, cxt->sector_size);
pe->part_table = pt_offset(pe->sectorbuffer, 0);
pe->ext_pointer = pe->part_table + 1;
pe->offset = 0;
@@ -588,14 +591,14 @@ static void add_logical(void)
partitions++;
}
printf(_("Adding logical partition %d\n"), partitions);
- dos_add_partition(partitions - 1, LINUX_NATIVE);
+ dos_add_partition(cxt, partitions - 1, LINUX_NATIVE);
}
/*
* Ask the user for new partition type information (logical, extended).
* This function calls the actual partition adding logic - dos_add_partition.
*/
-void dos_new_partition(void)
+void dos_new_partition(struct fdisk_context *cxt)
{
int i, free_primary = 0;
@@ -610,14 +613,14 @@ void dos_new_partition(void)
if (!free_primary) {
if (extended_offset) {
printf(_("All primary partitions are in use\n"));
- add_logical();
+ add_logical(cxt);
} else
printf(_("If you want to create more than four partitions, you must replace a\n"
"primary partition with an extended partition first.\n"));
} else if (partitions >= MAXIMUM_PARTS) {
printf(_("All logical partitions are in use\n"));
printf(_("Adding a primary partition\n"));
- dos_add_partition(get_partition(0, 4), LINUX_NATIVE);
+ dos_add_partition(cxt, get_partition(cxt, 0, 4), LINUX_NATIVE);
} else {
char c, dflt, line[LINE_LENGTH];
@@ -637,17 +640,17 @@ void dos_new_partition(void)
printf(_("Using default response %c\n"), c);
}
if (c == 'p') {
- int i = get_nonexisting_partition(0, 4);
+ int i = get_nonexisting_partition(cxt, 0, 4);
if (i >= 0)
- dos_add_partition(i, LINUX_NATIVE);
+ dos_add_partition(cxt, i, LINUX_NATIVE);
return;
} else if (c == 'l' && extended_offset) {
- add_logical();
+ add_logical(cxt);
return;
} else if (c == 'e' && !extended_offset) {
- int i = get_nonexisting_partition(0, 4);
+ int i = get_nonexisting_partition(cxt, 0, 4);
if (i >= 0)
- dos_add_partition(i, EXTENDED);
+ dos_add_partition(cxt, i, EXTENDED);
return;
} else
printf(_("Invalid partition type `%c'\n"), c);