summaryrefslogtreecommitdiff
path: root/sbin/pdisk/partition_map.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-01-28 01:00:54 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-01-28 01:00:54 +0000
commit3d389b75bc6840c1eeee0481081b3156df324791 (patch)
tree286d8274ea04b5c007e2196fd29b7bae760c7d41 /sbin/pdisk/partition_map.c
parent5d13d4d479282db326d085ca24fcf56f3db6fc2a (diff)
Make 'r' (reorder, a.k.a. swap) command work with any two existing
partitions. Do NOT allow partition 1 to be moved!
Diffstat (limited to 'sbin/pdisk/partition_map.c')
-rw-r--r--sbin/pdisk/partition_map.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c
index 496d018a64b..39d2a7e4768 100644
--- a/sbin/pdisk/partition_map.c
+++ b/sbin/pdisk/partition_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: partition_map.c,v 1.72 2016/01/27 23:59:12 krw Exp $ */
+/* $OpenBSD: partition_map.c,v 1.73 2016/01/28 01:00:53 krw Exp $ */
/*
* partition_map.c - partition map routines
@@ -780,20 +780,39 @@ find_entry_by_base(uint32_t base, struct partition_map_header *map)
void
-move_entry_in_map(long old_index, long ix, struct partition_map_header *map)
+move_entry_in_map(long index1, long index2, struct partition_map_header *map)
{
- struct partition_map *cur;
+ struct partition_map *p1, *p2;
- cur = find_entry_by_disk_address(old_index, map);
- if (cur == NULL) {
- printf("No such partition\n");
- } else {
- remove_from_disk_order(cur);
- cur->disk_address = ix;
- insert_in_disk_order(cur);
- renumber_disk_addresses(map);
- map->changed = 1;
+ if (index1 == index2)
+ return;
+
+ if (index1 == 1 || index2 == 1) {
+ printf("Partition #1 cannot be moved\n");
+ return;
+ }
+ p1 = find_entry_by_disk_address(index1, map);
+ if (p1 == NULL) {
+ printf("Partition #%ld not found\n", index1);
+ return;
}
+ p2 = find_entry_by_disk_address(index2, map);
+ if (p2 == NULL) {
+ printf("Partition #%ld not found\n", index2);
+ return;
+ }
+
+ remove_from_disk_order(p1);
+ remove_from_disk_order(p2);
+
+ p1->disk_address = index2;
+ p2->disk_address = index1;
+
+ insert_in_disk_order(p1);
+ insert_in_disk_order(p2);
+
+ renumber_disk_addresses(map);
+ map->changed = 1;
}