fdisk: print a message with size and type of created partition
PATCH 1/5 fdisk: print a message with size and type of created partition
Signed-off-by Francesco Cosoleto <[email protected]>
--- fdisk/Makefile.am | 2 +- fdisk/fdisk.c | 13 +++++++++++++ fdisk/fdisk.h | 1 + fdisk/fdisksgilabel.c | 8 +++++++- fdisk/fdisksunlabel.c | 4 ++++ 5 files changed, 26 insertions(+), 2 deletions(-)
fdisk/Makefile.am +1 -1
@@ -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
fdisk/fdisk.c +13 -0
@@ -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 */
fdisk/fdisk.h +1 -0
@@ -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 );
fdisk/fdisksgilabel.c +7 -1
@@ -570,6 +570,7 @@ 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" )); +print_partition_size (i +1 , start, start + length, sys); } static void
@@ -733,7 +734,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 +741,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 );
fdisk/fdisksunlabel.c +4 -0
@@ -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,
Signature · 1 line
1.7.3.4
PATCH 2/5 fdisk: print partition deleted message
Signed-off-by Francesco Cosoleto <[email protected]>
--- fdisk/fdisk.c | 18 +++++------------- 1 files changed, 5 insertions(+), 13 deletions(-)
fdisk/fdisk.c +5 -13
@@ -1676,27 +1676,18 @@ delete_partition(int i) {return ;/* C/H/S not set */ pe->changed =1 ; -if (disklabel ==SUN_LABEL ) { +if (disklabel ==SUN_LABEL )sun_delete_partition (i); -return ; - } - -if (disklabel ==SGI_LABEL ) { +else if (disklabel ==SGI_LABEL )sgi_delete_partition (i); -return ; - } - -if (i <4 ) { +else if (i <4 ) {if (IS_EXTENDED (p->sys_ind) && i == ext_index) { partitions =4 ; ptes[ext_index].ext_pointer =NULL ; extended_offset =0 ; }clear_partition (p); -return ; - } - -if (!q->sys_ind && i >4 ) { + }else if (!q->sys_ind && i >4 ) {/* the last one in the chain - just delete */ --partitions; --i;
@@ -1733,6 +1724,7 @@ delete_partition(int i) {/* the only logical: clear only */ clear_partition (ptes[i].part_table); } +printf (_ ("Partition %d is deleted\n" ), i +1 ); } static void
Signature · 1 line
1.7.3.4
PATCH 3/5 fdisk: print welcome message
In reply to Francesco CosoletoThis adds a welcome message with util-linux version number, information about fdisk behaviour that doesn't write to disk after a command (unlike gparted) and a warning about possible data loss.
The message appears just before the first command prompt.
Signed-off-by Francesco Cosoleto <[email protected]>
--- fdisk/fdisk.c | 10 +++++----- fdisk/fdisksgilabel.c | 4 +--- fdisk/fdisksunlabel.c | 4 +--- 3 files changed, 7 insertions(+), 11 deletions(-)
fdisk/fdisk.c +5 -5
@@ -932,11 +932,7 @@ static voidcreate_doslabel (void) {unsigned int id =get_random_id (); -fprintf (stderr, -_ ("Building a new DOS disklabel with disk identifier 0x%08x.\n" -"Changes will remain in memory only, until you decide to write them.\n" -"After that, of course, the previous content won't be recoverable.\n\n" ), - id); +fprintf (stderr,_ ("Building a new DOS disklabel with disk identifier 0x%08x.\n" ), id);sun_nolabel ();/* otherwise always recognised as sun */ sgi_nolabel ();/* otherwise always recognised as sgi */ disklabel =DOS_LABEL ;
@@ -3093,6 +3089,10 @@ main(int argc, char **argv) { disklabel =DOS_LABEL ; } +fprintf (stderr,_ ("Welcome to fdisk (%s).\n\n" +"Changes will remain in memory only, until you decide to write them.\n" +"Be careful before using the write command.\n" ),PACKAGE_STRING ); +while (1 ) {putchar ('\n' ); c =tolower (read_char (_ ("Command (m for help): " )));
fdisk/fdisksgilabel.c +1 -3
@@ -697,9 +697,7 @@ create_sgilabel(void) sec_fac = sector_size /512 ;/* determine the sector factor */ fprintf (stderr, -_ ("Building a new SGI disklabel. Changes will remain in memory only,\n" -"until you decide to write them. After that, of course, the previous\n" -"content will be unrecoverably lost.\n\n" )); +_ ("Building a new SGI disklabel.\n" )); other_endian = (BYTE_ORDER ==LITTLE_ENDIAN );
fdisk/fdisksunlabel.c +1 -3
@@ -189,9 +189,7 @@ void create_sunlabel(void)int res;fprintf (stderr, -_ ("Building a new sun disklabel. Changes will remain in memory only,\n" -"until you decide to write them. After that, of course, the previous\n" -"content won't be recoverable.\n\n" )); +_ ("Building a new Sun disklabel.\n" ));#if BYTE_ORDER ==LITTLE_ENDIAN other_endian =1 ;#else
Signature · 1 line
1.7.3.4
PATCH 4/5 tests: add ts_fdisk_clean function to make fdisk output comparable
In reply to Francesco CosoletoSigned-off-by Francesco Cosoleto <[email protected]>
--- tests/functions.sh | 7 +++++++ tests/ts/blkid/md-raid0-whole | 5 ++--- tests/ts/blkid/md-raid1-part | 6 ++---- tests/ts/blkid/md-raid1-whole | 5 ++--- tests/ts/fdisk/align-512-4K | 5 +---- tests/ts/fdisk/align-512-4K-63 | 5 +---- tests/ts/fdisk/align-512-4K-md | 5 +---- tests/ts/fdisk/align-512-512 | 4 +--- tests/ts/fdisk/align-512-512-topology | 5 +---- 9 files changed, 18 insertions(+), 29 deletions(-)
tests/functions.sh +7 -0
@@ -393,3 +393,10 @@ s/# <!-- util-linux.*-->//; /^$/d" /etc/fstab } +function ts_fdisk_clean { + # remove non comparable parts of fdisk output + [ x"${DEVNAME}" != x"" ] && sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT + sed -i -e 's/Disk identifier:.*//g' \ + -e 's/Building a new.*//g' \ + $TS_OUTPUT +}
tests/ts/blkid/md-raid0-whole +2 -3
@@ -78,9 +78,8 @@ ts_log "Deinitialize devices" ts_device_deinit $DEVICE1 ts_device_deinit $DEVICE2 -# remove disk ID and generated UUIDs -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean +# remove generated UUIDs sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT ts_finalize
tests/ts/blkid/md-raid1-part +2 -4
@@ -82,10 +82,8 @@ $TS_CMD_BLKID -p -o udev ${DEVICE}2 2>&1 | sort >> $TS_OUTPUT sleep 3 rmmod scsi_debug -# remove device name used, disk ID and generated UUIDs -sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean +# remove generated UUIDs sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT ts_finalize
tests/ts/blkid/md-raid1-whole +2 -3
@@ -78,9 +78,8 @@ ts_log "Deinitialize devices" ts_device_deinit $DEVICE1 ts_device_deinit $DEVICE2 -# remove disk ID and generated UUIDs -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean +# remove generated UUIDs sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT ts_finalize
tests/ts/fdisk/align-512-4K +1 -4
@@ -82,9 +82,6 @@ cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTP sleep 3 rmmod scsi_debug -# remove device name used and disk ID -sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean ts_finalize
tests/ts/fdisk/align-512-4K-63 +1 -4
@@ -82,9 +82,6 @@ cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTP sleep 3 rmmod scsi_debug -# remove device name used and disk ID -sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean ts_finalize
tests/ts/fdisk/align-512-4K-md +1 -4
@@ -94,9 +94,6 @@ sleep 3 /sbin/mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>&1 rmmod scsi_debug -# remove device name used and disk ID -sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean ts_finalize
tests/ts/fdisk/align-512-512 +1 -3
@@ -65,8 +65,6 @@ EOF ts_device_deinit $DEVICE -# remove disk ID -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean ts_finalize
tests/ts/fdisk/align-512-512-topology +1 -4
@@ -82,9 +82,6 @@ cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTP sleep 3 rmmod scsi_debug -# remove device name used and disk ID -sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT -sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT -sed -i -e 's/Building a new.*//g' $TS_OUTPUT +ts_fdisk_clean ts_finalize
Signature · 1 line
1.7.3.4
PATCH 5/5 tests: update fdisk and blkid MD tests
In reply to Francesco CosoletoSigned-off-by Francesco Cosoleto <[email protected]>
--- tests/expected/blkid/md-raid0-whole | 11 +++++++---- tests/expected/blkid/md-raid1-part | 11 +++++++---- tests/expected/blkid/md-raid1-whole | 13 ++++++++----- tests/expected/fdisk/align-512-4K | 24 ++++++++++++++++-------- tests/expected/fdisk/align-512-4K-63 | 24 ++++++++++++++++-------- tests/expected/fdisk/align-512-4K-md | 24 +++++++++++++++--------- tests/expected/fdisk/align-512-512 | 24 ++++++++++++++++-------- tests/expected/fdisk/align-512-512-topology | 24 ++++++++++++++++-------- tests/functions.sh | 1 + 9 files changed, 102 insertions(+), 54 deletions(-)
tests/expected/blkid/md-raid0-whole +7 -4
@@ -3,21 +3,24 @@ Create RAID device Create partitions on RAID device Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-204543, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-204543, default 204543): +Last sector, +sectors or +size{K,M,G} (2048-204543, default 204543): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (22528-204543, default 22528): Using default value 22528 Last sector, +sectors or +size{K,M,G} (22528-204543, default 204543): Using default value 204543 +Partition 2 of type Linux and of size 88.9 MiB is set Command (m for help): Disk /dev/md8: 104 MB, 104726528 bytes
tests/expected/blkid/md-raid1-part +7 -4
@@ -1,21 +1,24 @@ Create partitions Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-104447, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-104447, default 104447): +Last sector, +sectors or +size{K,M,G} (2048-104447, default 104447): Partition 1 of type Linux and of size 25 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (53248-104447, default 53248): Using default value 53248 Last sector, +sectors or +size{K,M,G} (53248-104447, default 104447): Using default value 104447 +Partition 2 of type Linux and of size 25 MiB is set Command (m for help): Disk /dev/...: 53 MB, 53477376 bytes
tests/expected/blkid/md-raid1-whole +8 -5
@@ -3,21 +3,24 @@ Create RAID device Create partitions on RAID device Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-102271, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-102271, default 102271): +Last sector, +sectors or +size{K,M,G} (2048-102271, default 102271): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (22528-102271, default 22528): Using default value 22528 -Last sector, +sectors or +size{K,M,G} (22528-102271, default 102271): +Last sector, +sectors or +size{K,M,G} (22528-102271, default 102271): Partition 2 of type Linux and of size 10 MiB is set + Command (m for help): Disk /dev/md8: 52 MB, 52363264 bytes 2 heads, 4 sectors/track, 12784 cylinders, total 102272 sectors
tests/expected/fdisk/align-512-4K +16 -8
@@ -1,49 +1,57 @@ Create partitions Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-102399, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (22528-102399, default 22528): Using default value 22528 -Last sector, +sectors or +size{K,M,G} (22528-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (22528-102399, default 102399): Partition 2 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): Partition number (1-4, default 3): First sector (43008-102399, default 43008): Using default value 43008 -Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): Partition 3 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): Selected partition 4 First sector (63488-102399, default 63488): Using default value 63488 Last sector, +sectors or +size{K,M,G} (63488-102399, default 102399): Using default value 102399 +Partition 4 of type Extended and of size 19 MiB is set Command (m for help): All primary partitions are in use Adding logical partition 5 First sector (65536-102399, default 65536): Using default value 65536 -Last sector, +sectors or +size{K,M,G} (65536-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (65536-102399, default 102399): Partition 5 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 6 First sector (77824-102399, default 77824): Using default value 77824 -Last sector, +sectors or +size{K,M,G} (77824-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (77824-102399, default 102399): Partition 6 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 7 First sector (90112-102399, default 90112): Using default value 90112 Last sector, +sectors or +size{K,M,G} (90112-102399, default 102399): Using default value 102399 +Partition 7 of type Linux and of size 6 MiB is set Command (m for help): Disk /dev/...: 52 MB, 52428800 bytes
tests/expected/fdisk/align-512-4K-63 +16 -8
@@ -1,49 +1,57 @@ Create partitions Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (7-102399, default 7): Using default value 7 -Last sector, +sectors or +size{K,M,G} (7-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (7-102399, default 102399): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (20487-102399, default 20487): Using default value 20487 -Last sector, +sectors or +size{K,M,G} (20487-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (20487-102399, default 102399): Partition 2 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): Partition number (1-4, default 3): First sector (40967-102399, default 40967): Using default value 40967 -Last sector, +sectors or +size{K,M,G} (40967-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (40967-102399, default 102399): Partition 3 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): Selected partition 4 First sector (61447-102399, default 61447): Using default value 61447 Last sector, +sectors or +size{K,M,G} (61447-102399, default 102399): Using default value 102399 +Partition 4 of type Extended and of size 20 MiB is set Command (m for help): All primary partitions are in use Adding logical partition 5 First sector (61454-102399, default 63487): Using default value 63487 -Last sector, +sectors or +size{K,M,G} (63487-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (63487-102399, default 102399): Partition 5 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 6 First sector (61454-102399, default 75775): Using default value 75775 -Last sector, +sectors or +size{K,M,G} (75775-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (75775-102399, default 102399): Partition 6 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 7 First sector (61454-102399, default 88063): Using default value 88063 Last sector, +sectors or +size{K,M,G} (88063-102399, default 102399): Using default value 102399 +Partition 7 of type Linux and of size 7 MiB is set Command (m for help): Disk /dev/...: 52 MB, 52428800 bytes
tests/expected/fdisk/align-512-4K-md +15 -9
@@ -1,25 +1,28 @@ Create partitions Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-102399, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): Partition 1 of type Linux and of size 20 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (43008-102399, default 43008): Using default value 43008 Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): Using default value 102399 +Partition 2 of type Linux and of size 29 MiB is set Command (m for help): Disk /dev/...: 52 MB, 52428800 bytes
@@ -43,25 +46,28 @@ Alignment offsets: Create partitions (MD) Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-100095, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-100095, default 100095): +Last sector, +sectors or +size{K,M,G} (2048-100095, default 100095): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (22528-100095, default 22528): Using default value 22528 -Last sector, +sectors or +size{K,M,G} (22528-100095, default 100095): +Last sector, +sectors or +size{K,M,G} (22528-100095, default 100095): Partition 2 of type Linux and of size 10 MiB is set + Command (m for help): Disk /dev/md8: 51 MB, 51249152 bytes 2 heads, 4 sectors/track, 12512 cylinders, total 100096 sectors
tests/expected/fdisk/align-512-512 +16 -8
@@ -1,45 +1,53 @@ Create partitions Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-102399, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (22528-102399, default 22528): Using default value 22528 -Last sector, +sectors or +size{K,M,G} (22528-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (22528-102399, default 102399): Partition 2 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): Partition number (1-4, default 3): First sector (43008-102399, default 43008): Using default value 43008 -Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): Partition 3 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): Selected partition 4 First sector (63488-102399, default 63488): Using default value 63488 Last sector, +sectors or +size{K,M,G} (63488-102399, default 102399): Using default value 102399 +Partition 4 of type Extended and of size 19 MiB is set Command (m for help): All primary partitions are in use Adding logical partition 5 First sector (65536-102399, default 65536): Using default value 65536 -Last sector, +sectors or +size{K,M,G} (65536-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (65536-102399, default 102399): Partition 5 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 6 First sector (77824-102399, default 77824): Using default value 77824 -Last sector, +sectors or +size{K,M,G} (77824-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (77824-102399, default 102399): Partition 6 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 7 First sector (90112-102399, default 90112): Using default value 90112 Last sector, +sectors or +size{K,M,G} (90112-102399, default 102399): Using default value 102399 +Partition 7 of type Linux and of size 6 MiB is set Command (m for help): Disk /dev/loop0: 52 MB, 52428800 bytes
tests/expected/fdisk/align-512-512-topology +16 -8
@@ -1,45 +1,53 @@ Create partitions Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel -Changes will remain in memory only, until you decide to write them. -After that, of course, the previous content won't be recoverable. - Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) + +Changes will remain in memory only, until you decide to write them. +Be careful before using the write command. + Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 1): First sector (2048-102399, default 2048): Using default value 2048 -Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (2048-102399, default 102399): Partition 1 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Partition number (1-4, default 2): First sector (22528-102399, default 22528): Using default value 22528 -Last sector, +sectors or +size{K,M,G} (22528-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (22528-102399, default 102399): Partition 2 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): Partition number (1-4, default 3): First sector (43008-102399, default 43008): Using default value 43008 -Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): Partition 3 of type Linux and of size 10 MiB is set + Command (m for help): Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): Selected partition 4 First sector (63488-102399, default 63488): Using default value 63488 Last sector, +sectors or +size{K,M,G} (63488-102399, default 102399): Using default value 102399 +Partition 4 of type Extended and of size 19 MiB is set Command (m for help): All primary partitions are in use Adding logical partition 5 First sector (65536-102399, default 65536): Using default value 65536 -Last sector, +sectors or +size{K,M,G} (65536-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (65536-102399, default 102399): Partition 5 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 6 First sector (77824-102399, default 77824): Using default value 77824 -Last sector, +sectors or +size{K,M,G} (77824-102399, default 102399): +Last sector, +sectors or +size{K,M,G} (77824-102399, default 102399): Partition 6 of type Linux and of size 5 MiB is set + Command (m for help): All primary partitions are in use Adding logical partition 7 First sector (90112-102399, default 90112): Using default value 90112 Last sector, +sectors or +size{K,M,G} (90112-102399, default 102399): Using default value 102399 +Partition 7 of type Linux and of size 6 MiB is set Command (m for help): Disk /dev/...: 52 MB, 52428800 bytes
tests/functions.sh +1 -0
@@ -398,5 +398,6 @@ function ts_fdisk_clean { [ x"${DEVNAME}" != x"" ] && sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT sed -i -e 's/Disk identifier:.*//g' \ -e 's/Building a new.*//g' \ + -e 's/Welcome to fdisk.*//g' \ $TS_OUTPUT }
Signature · 1 line
1.7.3.4
PATCH 1/1 fdisk: print a message with size and type of created partition
In reply to Francesco CosoletoSigned-off-by Francesco Cosoleto <[email protected]>
--- fdisk/Makefile.am | 2 +- fdisk/fdisk.c | 13 +++++++++++++ fdisk/fdisk.h | 1 + fdisk/fdisksgilabel.c | 9 ++++++++- fdisk/fdisksunlabel.c | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-)
fdisk/Makefile.am +1 -1
@@ -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
fdisk/fdisk.c +13 -0
@@ -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 */
fdisk/fdisk.h +1 -0
@@ -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 );
fdisk/fdisksgilabel.c +8 -1
@@ -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 );
fdisk/fdisksunlabel.c +4 -0
@@ -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,
Signature · 1 line
1.7.3.4
Karel Zak
maintainerQuoted 6 lines · Francesco Cosoleto
fdisk/Makefile.am | 2 +- fdisk/fdisk.c | 13 +++++++++++++ fdisk/fdisk.h | 1 + fdisk/fdisksgilabel.c | 9 ++++++++- fdisk/fdisksunlabel.c | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-)
Applied (all 5 patches), thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com