]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (dos) move 'move begin' code to fdiskdoslabe.c
authorKarel Zak <kzak@redhat.com>
Mon, 21 Jan 2013 11:11:43 +0000 (12:11 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 11:47:30 +0000 (12:47 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdiskdoslabel.c
fdisks/fdiskdoslabel.h

index cb655117bb64d9f61ee41c291081fe1df46c5a83..9322dad53b62ba4961a5b12cb2497306c85f6ad8 100644 (file)
@@ -1024,55 +1024,6 @@ static void print_raw(struct fdisk_context *cxt)
                     print_buffer(cxt, ptes[i].sectorbuffer);
 }
 
-static void
-move_begin(struct fdisk_context *cxt, int i) {
-       struct pte *pe = &ptes[i];
-       struct partition *p = pe->part_table;
-       unsigned int new, free_start, curr_start, last;
-       int x;
-
-       if (warn_geometry(cxt))
-               return;
-       if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED (p->sys_ind)) {
-               printf(_("Partition %d has no data area\n"), i + 1);
-               return;
-       }
-
-       /* the default start is at the second sector of the disk or at the
-        * second sector of the extended partition
-        */
-       free_start = pe->offset ? pe->offset + 1 : 1;
-
-       curr_start = get_partition_start(pe);
-
-       /* look for a free space before the current start of the partition */
-       for (x = 0; x < partitions; x++) {
-               unsigned int end;
-               struct pte *prev_pe = &ptes[x];
-               struct partition *prev_p = prev_pe->part_table;
-
-               if (!prev_p)
-                       continue;
-               end = get_partition_start(prev_pe) + get_nr_sects(prev_p);
-
-               if (!is_cleared_partition(prev_p) &&
-                   end > free_start && end <= curr_start)
-                       free_start = end;
-       }
-
-       last = get_partition_start(pe) + get_nr_sects(p) - 1;
-
-       new = read_int(cxt, free_start, curr_start, last, free_start,
-                      _("New beginning of data")) - pe->offset;
-
-       if (new != get_nr_sects(p)) {
-               unsigned int sects = get_nr_sects(p) + get_start_sect(p) - new;
-               set_nr_sects(p, sects);
-               set_start_sect(p, new);
-               pe->changed = 1;
-       }
-}
-
 static void __attribute__ ((__noreturn__)) handle_quit(struct fdisk_context *cxt)
 {
        fdisk_free_context(cxt);
@@ -1095,7 +1046,7 @@ expert_command_prompt(struct fdisk_context *cxt)
                        break;
                case 'b':
                        if (fdisk_is_disklabel(cxt, DOS))
-                               move_begin(cxt, get_partition(cxt, 0, partitions));
+                               dos_move_begin(cxt, get_partition(cxt, 0, partitions));
                        break;
                case 'c':
                        user_cylinders = read_int(cxt, 1, cxt->geom.cylinders, 1048576, 0,
index d174c735ab23359955f5e6b89dcf2e82cbadd9d7..b9b2a4e2bca9df3299dc724f9219999aa4a39020 100644 (file)
@@ -1181,6 +1181,57 @@ void dos_fix_partition_table_order(void)
 
 }
 
+void dos_move_begin(struct fdisk_context *cxt, int i)
+{
+       struct pte *pe = &ptes[i];
+       struct partition *p = pe->part_table;
+       unsigned int new, free_start, curr_start, last;
+       int x;
+
+       assert(cxt);
+       assert(fdisk_is_disklabel(cxt, DOS));
+
+       if (warn_geometry(cxt))
+               return;
+       if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED (p->sys_ind)) {
+               printf(_("Partition %d has no data area\n"), i + 1);
+               return;
+       }
+
+       /* the default start is at the second sector of the disk or at the
+        * second sector of the extended partition
+        */
+       free_start = pe->offset ? pe->offset + 1 : 1;
+
+       curr_start = get_partition_start(pe);
+
+       /* look for a free space before the current start of the partition */
+       for (x = 0; x < partitions; x++) {
+               unsigned int end;
+               struct pte *prev_pe = &ptes[x];
+               struct partition *prev_p = prev_pe->part_table;
+
+               if (!prev_p)
+                       continue;
+               end = get_partition_start(prev_pe) + get_nr_sects(prev_p);
+
+               if (!is_cleared_partition(prev_p) &&
+                   end > free_start && end <= curr_start)
+                       free_start = end;
+       }
+
+       last = get_partition_start(pe) + get_nr_sects(p) - 1;
+
+       new = read_int(cxt, free_start, curr_start, last, free_start,
+                      _("New beginning of data")) - pe->offset;
+
+       if (new != get_nr_sects(p)) {
+               unsigned int sects = get_nr_sects(p) + get_start_sect(p) - new;
+               set_nr_sects(p, sects);
+               set_start_sect(p, new);
+               pe->changed = 1;
+       }
+}
 
 static const struct fdisk_label_operations dos_operations =
 {
index 2737c9e689f6227ca04c62713f2687f3239848ae..62d1a1efa6b229c25c541603bdd4229c1af5abf5 100644 (file)
@@ -43,6 +43,7 @@ extern void dos_init(struct fdisk_context *cxt);
 extern int dos_list_table(struct fdisk_context *cxt, int xtra);
 
 extern void dos_fix_partition_table_order(void);
+extern void dos_move_begin(struct fdisk_context *cxt, int i);
 
 extern int mbr_is_valid_magic(unsigned char *b);