[gparted] Add clearing of SWRaid metadata 0.90 and 1.0 super blocks (#756829)



commit 743968ef68085f6043e8fd569384c0747c8fc9e2
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Oct 30 16:21:36 2015 +0000

    Add clearing of SWRaid metadata 0.90 and 1.0 super blocks (#756829)
    
    The super blocks for Linux Software RAID arrays using metadata types
    0.90 and 1.0 are stored at the end of the partition and not currently
    cleared by GParted.
    
    Create a SWRaid array, stop it and format it to cleared using GParted.
    The signature remains.
    
        # mdadm --create /dev/md1 --level=linear --raid-devices=1 --force --metadata=1.0 /dev/sdb1
        # mdadm --stop /dev/md1
        [In GParted format to cleared /dev/sdb1]
        # blkid /dev/sdb1
        /dev/sdb1: UUID="8ac947a7-063f-2266-5f2a-e5d178198139" 
UUID_SUB="49bd51d4-4c54-fb16-a45e-bd795f783f59" LABEL="rockover:1" TYPE="linux_raid_member"
    
    As fixed in other cases before [1][2] it is necessary to clear all
    signatures before formatting as a new file system to prevent recognition
    issues.  For example now format the partition as a FAT32 file system.
    Now there are two signatures and libparted reports one type and blkid
    reports another.
    
        # mkdosfs -F 32 /dev/sdb1
        # blkid /dev/sdb1
        /dev/sdb1: UUID="8ac947a7-063f-2266-5f2a-e5d178198139" 
UUID_SUB="49bd51d4-4c54-fb16-a45e-bd795f783f59" LABEL="rockover:1" TYPE="linux_raid_member"
        # parted /dev/sdb print
        Model: ATA SAMSUNG SSD UM41 (scsi)
        Disk /dev/sdb: 8012MB
        Sector size (logical/physical): 512B/512B
        Partition Table: msdos
    
        Number  Start   End     Size    Type      File system  Flags
         1      1049kB  538MB   537MB   primary   fat32
    
    (Deliberately avoided btrfs, ext2/3/4 and xfs as recent versions of
    their mkfs tools clear other signatures first for the same reason).
    
    [1] Bug 688882 - Improve clearing of file system signatures
    [2] 3c75f3f5b103bc158b0f70ea63459aa362b0bab8
        Use wipefs to clear old signatures before creating new file systems (#688882)
    
    Update erase_filesystem_signatures() to also zero the necessary sectors
    to clear SWRaid metadata 0.90 and 1.0 super blocks.
    
    Bug 756829 - SWRaid member detection enhancements

 src/GParted_Core.cc |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index b9bb9e3..7616e24 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3625,14 +3625,25 @@ bool GParted_Core::erase_filesystem_signatures( const Partition & partition, Ope
        //
        //  First byte range from offset 0 of length 68 KiB covers the primary super block
        //  of all currently supported file systems and is also likely to include future
-       //  file system super blocks too.  Only a few file systems have additional super
-       //  blocks and signatures.  Overwrite the btrfs super block mirror copies and the
-       //  nilfs2 secondary super block.
+       //  file system super blocks too.  Only a few file systems have super blocks and
+       //  signatures located elsewhere.
        //
        //  Btrfs super blocks are located at: 64 KiB, 64 MiB, 256 GiB and 1 PiB.
        //  https://btrfs.wiki.kernel.org/index.php/On-disk_Format#Superblock
        //
-       //  Nilfs2 secondary super block is located at at the last whole 4 KiB block.
+       //  Linux Software RAID metadata 0.90 stores it's super block at 64 KiB before the
+       //  end of the device, aligned to 64 KiB boundary.  Length 4 KiB.
+       //  Ref: mdadm/super0.c load_super0()
+       //       mdadm/md_p.h   #define MD_NEW_SIZE_SECTORS(x) ...
+       //
+       //  Linux Software RAID metadata 1.0 stores it's super block at 8 KiB before the
+       //  end of the device, aligned to 4 KiB boundary.  Length 4 KiB.  (Metadata 1.1
+       //  and 1.2 store their super blocks at 0 KiB and 4 KiB respectively so will be
+       //  erased by the zeroing from offset 0).
+       //  Ref: mdadm/super1.c load_super1()
+       //                      #define MAX_SB_SIZE 4096
+       //
+       //  Nilfs2 secondary super block is located at the last whole 4 KiB block.
        //  Ref: nilfs-utils-2.1.4/include/nilfs2_fs.h
        //  #define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
        struct {
@@ -3640,12 +3651,14 @@ bool GParted_Core::erase_filesystem_signatures( const Partition & partition, Ope
                Byte_Value rounding;  //Minimum desired rounding for offset
                Byte_Value length;
        } ranges[] = {
-               //offset          , rounding      , length
-               {   0LL           , 1LL           , 68LL * KIBIBYTE },  //All primary super blocks
-               {  64LL * MEBIBYTE, 1LL           ,  4LL * KIBIBYTE },  //Btrfs super block mirror copy
-               { 256LL * GIBIBYTE, 1LL           ,  4LL * KIBIBYTE },  //Btrfs super block mirror copy
-               {   1LL * PEBIBYTE, 1LL           ,  4LL * KIBIBYTE },  //Btrfs super block mirror copy
-               {  -4LL * KIBIBYTE, 4LL * KIBIBYTE,  4LL * KIBIBYTE }   //Nilfs2 secondary super block
+               //offset          , rounding       , length
+               {   0LL           ,  1LL           , 68LL * KIBIBYTE },  // All primary super blocks
+               {  64LL * MEBIBYTE,  1LL           ,  4LL * KIBIBYTE },  // Btrfs super block mirror copy
+               { 256LL * GIBIBYTE,  1LL           ,  4LL * KIBIBYTE },  // Btrfs super block mirror copy
+               {   1LL * PEBIBYTE,  1LL           ,  4LL * KIBIBYTE },  // Btrfs super block mirror copy
+               { -64LL * KIBIBYTE, 64LL * KIBIBYTE,  4LL * KIBIBYTE },  // SWRaid metadata 0.90 super block
+               {  -8LL * KIBIBYTE,  4LL * KIBIBYTE,  8LL * KIBIBYTE }   // @-8K SWRaid metadata 1.0 super 
block
+                                                                        // and @-4K Nilfs2 secondary super 
block
        } ;
        for ( unsigned int i = 0 ; overall_success && i < sizeof( ranges ) / sizeof( ranges[0] ) ; i ++ )
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]