]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: print a message with size and type of created partition
authorFrancesco Cosoleto <cosoleto@gmail.com>
Wed, 17 Aug 2011 11:21:12 +0000 (13:21 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 30 Aug 2011 08:53:22 +0000 (10:53 +0200)
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
fdisk/Makefile.am
fdisk/fdisk.c
fdisk/fdisk.h
fdisk/fdisksgilabel.c
fdisk/fdisksunlabel.c

index 7cad805d1a000a749195677967bcc25c6ed40e8c..4409db55c81d4f637ee6c7a77aef01f83e4117e5 100644 (file)
@@ -4,7 +4,7 @@ EXTRA_DIST = README.fdisk README.cfdisk sfdisk.examples partitiontype.c
 
 fdisk_common = i386_sys_types.c common.h gpt.c gpt.h \
        $(top_srcdir)/lib/blkdev.c $(top_srcdir)/lib/wholedisk.c \
-       $(top_srcdir)/lib/mbsalign.c
+       $(top_srcdir)/lib/mbsalign.c $(top_srcdir)/lib/strutils.c
 
 if LINUX
 fdisk_common += $(top_srcdir)/lib/linux_version.c
index 038536db26f92b96d50a6e0be16fd5d9ec3c8e35..a08a4d413aa8efbb04a847ed583710e3ea0d9529 100644 (file)
@@ -32,6 +32,7 @@
 #include "wholedisk.h"
 #include "pathnames.h"
 #include "canonicalize.h"
+#include "strutils.h"
 
 #include "fdisksunlabel.h"
 #include "fdisksgilabel.h"
@@ -614,6 +615,10 @@ set_partition(int i, int doext, unsigned long long start,
        p->sys_ind = sysid;
        set_start_sect(p, start - offset);
        set_nr_sects(p, stop - start + 1);
+
+       if (!doext)
+               print_partition_size(i + 1, start, stop, sysid);
+
        if (dos_compatible_flag && (start/(sectors*heads) > 1023))
                start = heads*sectors*1024 - 1;
        set_hsc(p->head, p->sector, p->cyl, start);
@@ -2319,6 +2324,14 @@ get_unused_start(int part_n,
        return start;
 }
 
+void print_partition_size(int num, unsigned long long start, unsigned long long stop, int sysid)
+{
+       char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
+                                    (stop - start + 1) * sector_size);
+       printf(_("Partition %d of type %s and of size %s is set\n"), num, partition_type(sysid), str);
+       free(str);
+}
+
 static void
 add_partition(int n, int sys) {
        char mesg[256];         /* 48 does not suffice in Japanese */
index 9b7f4c759ced14d26b3455ab319771b45f81cad3..e2890439f4b5d5017e9e8206ee2faaa884a228f4 100644 (file)
@@ -75,6 +75,7 @@ extern struct partition *get_part_table(int);
 extern int valid_part_table_flag(unsigned char *b);
 extern unsigned int read_int(unsigned int low, unsigned int dflt,
                             unsigned int high, unsigned int base, char *mesg);
+extern void print_partition_size(int num, unsigned long long start, unsigned long long stop, int sysid);
 
 extern unsigned char *MBRbuffer;
 extern void zeroize_mbr_buffer(void);
index 8179bc155cf9099e26707f7a880639e7c7c03ed3..35959091658321658fead02d126c06304fc176a7 100644 (file)
@@ -570,6 +570,8 @@ sgi_set_partition(int i, unsigned int start, unsigned int length, int sys) {
        set_changed(i);
        if (sgi_gaps() < 0)     /* rebuild freelist */
                printf(_("Do You know, You got a partition overlap on the disk?\n"));
+       if (length)
+               print_partition_size(i + 1, start, start + length, sys);
 }
 
 static void
@@ -733,7 +735,6 @@ create_sgilabel(void)
                                old[i].sysid = get_part_table(i)->sys_ind;
                                old[i].start = get_start_sect(get_part_table(i));
                                old[i].nsect = get_nr_sects(get_part_table(i));
-                               printf(_("Trying to keep parameters of partition %d.\n"), i);
                                if (debug)
                                        printf(_("ID=%02x\tSTART=%d\tLENGTH=%d\n"),
                                               old[i].sysid, old[i].start, old[i].nsect);
@@ -741,6 +742,12 @@ create_sgilabel(void)
                }
        }
 
+       for (i = 0; i < 4; i++)
+               if (old[i].sysid) {
+                       printf(_("Trying to keep parameters of partitions already set.\n"));
+                       break;
+               }
+
        zeroize_mbr_buffer();
        sgilabel->magic = SSWAP32(SGI_LABEL_MAGIC);
        sgilabel->boot_part = SSWAP16(0);
index 9335e75e24c032af869a5615389f4215a029a1ed..7d3aa09e1e040303181aaa36d5a81ba2e9d9d15e 100644 (file)
@@ -106,6 +106,7 @@ static void set_sun_partition(int i, uint32_t start, uint32_t stop, uint16_t sys
        sunlabel->partitions[i].num_sectors =
                SSWAP32(stop - start);
        set_changed(i);
+       print_partition_size(i + 1, start, stop, sysid);
 }
 
 void sun_nolabel(void)
@@ -250,6 +251,9 @@ void create_sunlabel(void)
        } else
                ndiv = cylinders * 2 / 3;
 
+       /* Make sure print_partition_size() uses correct sysid names */
+       disklabel = SUN_LABEL;
+
        set_sun_partition(0, 0, ndiv * heads * sectors,
                          SUN_TAG_LINUX_NATIVE);
        set_sun_partition(1, ndiv * heads * sectors,