pub(crate) fn generate_label(&mut self) -> NexusLabel {
        let block_size: u32 = self.bdev.block_len();
        let num_blocks: u64 = self.min_num_blocks();

        //
        // (Protective) MBR
        let mut pmbr = Pmbr::default();

        pmbr.entries[0].ent_type = 0xee; // indicates this is a protective MBR partition
        pmbr.entries[0].attributes = 0x00;
        pmbr.entries[0].chs_start = [0x00, 0x02, 0x00];
        pmbr.entries[0].chs_last = [0xff, 0xff, 0xff];

        // the partition must accurately reflect the disk size where possible.
        // if the size (in blocks) is too large to fit into 32 bits,
        // we set the size to 0xffff_ffff

        pmbr.entries[0].lba_start = 1; // "partition" starts immediately after the MBR
        pmbr.entries[0].num_sectors = if num_blocks > u32::max_value().into() {
            u32::max_value()
        } else {
            (num_blocks as u32) - 1 // do not count the first block that
                                    // contains the MBR
        };

        pmbr.signature = [0x55, 0xaa];

        //
        // Primary GPT header
        let mut header = GPTHeader::new(
            block_size,
            num_blocks,
            Uuid::from_bytes(self.bdev.uuid().as_bytes()),
        );

        //
        // Partition table
        let mut entries =
            vec![GptEntry::default(); header.num_entries as usize];

        entries[0] = GptEntry {
            ent_type: GptGuid::from_str(Nexus::METADATA_PARTITION_TYPE_ID)
                .unwrap(),
            ent_guid: GptGuid::new_random(),
            // 1MB aligned
            ent_start: header.lba_start,
            // 4MB
            ent_end: header.lba_start + u64::from((4 << 20) / block_size) - 1,
            ent_attr: 0,
            ent_name: GptName {
                name: "MayaMeta".into(),
            },
        };

        entries[1] = GptEntry {
            ent_type: GptGuid::from_str(Nexus::METADATA_PARTITION_TYPE_ID)
                .unwrap(),
            ent_guid: GptGuid::new_random(),
            ent_start: entries[0].ent_end + 1,
            ent_end: header.lba_end,
            ent_attr: 0,
            ent_name: GptName {
                name: "MayaData".into(),
            },
        };

        header.table_crc = GptEntry::checksum(&entries);
        header.checksum();

        //
        // Secondary GPT header
        let backup = header.to_backup();

        NexusLabel {
            status: NexusLabelStatus::Neither,
            mbr: pmbr,
            primary: header,
            partitions: entries,
            secondary: backup,
        }
    }
/// Generate a new nexus label based on the nexus configuration.
/// The meta partition is fixed in size and aligned to a 1MB boundary.
Generate a new nexus label based on the nexus configuration.
The meta partition is fixed in size and aligned to a 1MB boundary.
Generate a new nexus label based on the nexus configuration . The meta partition is fixed in size and aligned to a 1MB boundary .
pub(crate) fn generate_label(&mut self) -> NexusLabel {
        let block_size: u32 = self.bdev.block_len();
        let num_blocks: u64 = self.min_num_blocks();
        //
        // (Protective) MBR
        let mut pmbr = Pmbr::default();
        pmbr.entries[0].ent_type = 0xee; // indicates this is a protective MBR partition
        pmbr.entries[0].attributes = 0x00;
        pmbr.entries[0].chs_start = [0x00, 0x02, 0x00];
        pmbr.entries[0].chs_last = [0xff, 0xff, 0xff];
        // the partition must accurately reflect the disk size where possible.
        // if the size (in blocks) is too large to fit into 32 bits,
        // we set the size to 0xffff_ffff
        pmbr.entries[0].lba_start = 1; // "partition" starts immediately after the MBR
        pmbr.entries[0].num_sectors = if num_blocks > u32::max_value().into() {
            u32::max_value()
        } else {
            (num_blocks as u32) - 1 // do not count the first block that
                                    // contains the MBR
        };
        pmbr.signature = [0x55, 0xaa];
        //
        // Primary GPT header
        let mut header = GPTHeader::new(
            block_size,
            num_blocks,
            Uuid::from_bytes(self.bdev.uuid().as_bytes()),
        );
        //
        // Partition table
        let mut entries =
            vec![GptEntry::default(); header.num_entries as usize];
        entries[0] = GptEntry {
            ent_type: GptGuid::from_str(Nexus::METADATA_PARTITION_TYPE_ID)
                .unwrap(),
            ent_guid: GptGuid::new_random(),
            // 1MB aligned
            ent_start: header.lba_start,
            // 4MB
            ent_end: header.lba_start + u64::from((4 << 20) / block_size) - 1,
            ent_attr: 0,
            ent_name: GptName {
                name: "MayaMeta".into(),
            },
        };
        entries[1] = GptEntry {
            ent_type: GptGuid::from_str(Nexus::METADATA_PARTITION_TYPE_ID)
                .unwrap(),
            ent_guid: GptGuid::new_random(),
            ent_start: entries[0].ent_end + 1,
            ent_end: header.lba_end,
            ent_attr: 0,
            ent_name: GptName {
                name: "MayaData".into(),
            },
        };
        header.table_crc = GptEntry::checksum(&entries);
        header.checksum();
        //
        // Secondary GPT header
        let backup = header.to_backup();
        NexusLabel {
            status: NexusLabelStatus::Neither,
            mbr: pmbr,
            primary: header,
            partitions: entries,
            secondary: backup,
        }
    }
pub ( crate ) fn generate_label ( & mut self ) -> NexusLabel { let block_size : u32 = self . bdev . block_len ( ) ; let num_blocks : u64 = self . min_num_blocks ( ) ; // // (Protective) MBR let mut pmbr = Pmbr :: default ( ) ; pmbr . entries [ 0 ] . ent_type = 0xee ; // indicates this is a protective MBR partition pmbr . entries [ 0 ] . attributes = 0x00 ; pmbr . entries [ 0 ] . chs_start = [ 0x00 , 0x02 , 0x00 ] ; pmbr . entries [ 0 ] . chs_last = [ 0xff , 0xff , 0xff ] ; // the partition must accurately reflect the disk size where possible. // if the size (in blocks) is too large to fit into 32 bits, // we set the size to 0xffff_ffff pmbr . entries [ 0 ] . lba_start = 1 ; // "partition" starts immediately after the MBR pmbr . entries [ 0 ] . num_sectors = if num_blocks > u32 :: max_value ( ) . into ( ) { u32 :: max_value ( ) } else { ( num_blocks as u32 ) - 1 // do not count the first block that // contains the MBR } ; pmbr . signature = [ 0x55 , 0xaa ] ; // // Primary GPT header let mut header = GPTHeader :: new ( block_size , num_blocks , Uuid :: from_bytes ( self . bdev . uuid ( ) . as_bytes ( ) ) , ) ; // // Partition table let mut entries = vec ! [ GptEntry default ( ) header num_entries as usize ] ; entries [ 0 ] = GptEntry { ent_type : GptGuid :: from_str ( Nexus :: METADATA_PARTITION_TYPE_ID ) . unwrap ( ) , ent_guid : GptGuid :: new_random ( ) , // 1MB aligned ent_start : header . lba_start , // 4MB ent_end : header . lba_start + u64 :: from ( ( 4 << 20 ) / block_size ) - 1 , ent_attr : 0 , ent_name : GptName { name : " " . into ( ) , } , } ; entries [ 1 ] = GptEntry { ent_type : GptGuid :: from_str ( Nexus :: METADATA_PARTITION_TYPE_ID ) . unwrap ( ) , ent_guid : GptGuid :: new_random ( ) , ent_start : entries [ 0 ] . ent_end + 1 , ent_end : header . lba_end , ent_attr : 0 , ent_name : GptName { name : " " . into ( ) , } , } ; header . table_crc = GptEntry :: checksum ( & entries ) ; header . checksum ( ) ; // // Secondary GPT header let backup = header . to_backup ( ) ; NexusLabel { status : NexusLabelStatus :: Neither , mbr : pmbr , primary : header , partitions : entries , secondary : backup , } }
Generate a new nexus label based on the nexus configuration.
Generate a new nexus label based on the nexus configuration .
&mut self