fn write_extents_overflow_file(source: &mut Write, extents: &[(ExtentKey, HFSPlusExtentRecord)]) -> io::Result<()> {
    assert!(extents.len() < 256, "Only a maximum of 255 extents can be provided");
    let num_records = extents.len() as u8;

    let raw_header_data: [u8; 14] = [
        0, 0, 0, 0,             // fLink = 0
        0, 0, 0, 0,             // bLink = 0
        kBTHeaderNode as u8,    // kind = header node
        0,                      // height = 0
        0, 3,                   // numRecords = 3
        0, 0,                   // reserved
    ];

    let header_record: [u8; 106] = [
        0, 1,                   // treeDepth = 1
        0, 0, 0, 1,             // rootNode = 1
        0, 0, 0, num_records,   // leafRecords = number of extent records
        0, 0, 0, 1,             // firstLeafNode = 1
        0, 0, 0, 1,             // lastLeafNode = 1
        2, 0,                   // nodeSize = 512
        0, 10,                  // maxKeyLength = kHFSPlusExtentKeyMaximumLength
        0, 0, 0, 2,             // totalNodes = 2
        0, 0, 0, 0,             // freeNodes = 0
        0, 0,                   // reserved1
        0, 0, 2, 0,             // clumpSize = 512
        0,                      // btreeType = kHFSBTreeType
        0,                      // keyCompareType = 0
        0, 0, 0, 2,             // attributes = kBTBigKeysMask
        0, 0, 0, 0,             // reserved3[16]
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
    ];
    let user_data_record = [0u8; 128];
    let map_record = [0u8; 256];

    source.write_all(&raw_header_data)?;
    source.write_all(&header_record)?;
    source.write_all(&user_data_record)?;
    source.write_all(&map_record)?;
    //// First record always starts at offset 14
    //// The Header record is always 106 bytes in length
    //// The User Data is always 128 bytes
    //// 4 16-bit record pointers are needed at the end (one for next free location)
    //// Making the Map Record 256 bytes rounds out the node to 512 bytes
    source.write_u16::<BigEndian>(14+106+128+256).unwrap();
    source.write_u16::<BigEndian>(14+106+128).unwrap();
    source.write_u16::<BigEndian>(14+106).unwrap();
    source.write_u16::<BigEndian>(14).unwrap();
    //assert_eq!(raw_header_data.len(), 512);

    let mut raw_data: Vec<u8> = vec![
        0, 0, 0, 0,         // fLink = 0
        0, 0, 0, 0,         // bLink = 0
        kBTLeafNode as u8,  // kind = leaf node
        1,                  // height = 1
        0, num_records,     // numRecords = number of extent records
        0, 0,               // reserved
    ];
    let mut positions = Vec::new();
    for (key, record) in extents {
        positions.push(raw_data.len() as u16);
        key.export(&mut raw_data)?;
        export_record(&record[..], &mut raw_data).unwrap();
    }
    positions.push(raw_data.len() as u16);
    assert!(raw_data.len() <= 512 - 2*positions.len(), "Overflowed extents leaf record");
    raw_data.resize(512 - 2*positions.len(), 0);
    for position in positions.iter().rev() {
        raw_data.write_u16::<BigEndian>(*position).unwrap();
    }
    assert_eq!(raw_data.len(), 512);
    source.write_all(&raw_data)?;
    
    Ok(())
}
/// write_extents_overflow_file(source, extents);
///
/// Helper function for creating a simple extents overflow file
/// This is a very simple function just used for constructing a test vector
/// for a small filesystem. It assumes that the provided key/records are
/// pre-sorted, less than 256, and all fit in one leaf node. It also assumes
/// a small node size of 512 bytes which is not typical, but easier for
/// testing.
///
/// This is written to hand-craft the data and avoid relying on much of the
/// normal filesystem code that will be ultimately tested.
///
write_extents_overflow_file(source, extents);
Helper function for creating a simple extents overflow file
This is a very simple function just used for constructing a test vector
for a small filesystem. It assumes that the provided key/records are
pre-sorted, less than 256, and all fit in one leaf node. It also assumes
a small node size of 512 bytes which is not typical, but easier for
testing.

This is written to hand-craft the data and avoid relying on much of the
normal filesystem code that will be ultimately tested.
write_extents_overflow_file ( source extents ) ; Helper function for creating a simple extents overflow file This is a very simple function just used for constructing a test vector for a small filesystem . It assumes that the provided key / records are pre - sorted less than 256 and all fit in one leaf node . It also assumes a small node size of 512 bytes which is not typical but easier for testing . This is written to hand - craft the data and avoid relying on much of the normal filesystem code that will be ultimately tested .
fn write_extents_overflow_file(source: &mut Write, extents: &[(ExtentKey, HFSPlusExtentRecord)]) -> io::Result<()> {
    assert!(extents.len() < 256, "Only a maximum of 255 extents can be provided");
    let num_records = extents.len() as u8;
    let raw_header_data: [u8; 14] = [
        0, 0, 0, 0,             // fLink = 0
        0, 0, 0, 0,             // bLink = 0
        kBTHeaderNode as u8,    // kind = header node
        0,                      // height = 0
        0, 3,                   // numRecords = 3
        0, 0,                   // reserved
    ];
    let header_record: [u8; 106] = [
        0, 1,                   // treeDepth = 1
        0, 0, 0, 1,             // rootNode = 1
        0, 0, 0, num_records,   // leafRecords = number of extent records
        0, 0, 0, 1,             // firstLeafNode = 1
        0, 0, 0, 1,             // lastLeafNode = 1
        2, 0,                   // nodeSize = 512
        0, 10,                  // maxKeyLength = kHFSPlusExtentKeyMaximumLength
        0, 0, 0, 2,             // totalNodes = 2
        0, 0, 0, 0,             // freeNodes = 0
        0, 0,                   // reserved1
        0, 0, 2, 0,             // clumpSize = 512
        0,                      // btreeType = kHFSBTreeType
        0,                      // keyCompareType = 0
        0, 0, 0, 2,             // attributes = kBTBigKeysMask
        0, 0, 0, 0,             // reserved3[16]
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
    ];
    let user_data_record = [0u8; 128];
    let map_record = [0u8; 256];
    source.write_all(&raw_header_data)?;
    source.write_all(&header_record)?;
    source.write_all(&user_data_record)?;
    source.write_all(&map_record)?;
    //// First record always starts at offset 14
    //// The Header record is always 106 bytes in length
    //// The User Data is always 128 bytes
    //// 4 16-bit record pointers are needed at the end (one for next free location)
    //// Making the Map Record 256 bytes rounds out the node to 512 bytes
    source.write_u16::<BigEndian>(14+106+128+256).unwrap();
    source.write_u16::<BigEndian>(14+106+128).unwrap();
    source.write_u16::<BigEndian>(14+106).unwrap();
    source.write_u16::<BigEndian>(14).unwrap();
    //assert_eq!(raw_header_data.len(), 512);
    let mut raw_data: Vec<u8> = vec![
        0, 0, 0, 0,         // fLink = 0
        0, 0, 0, 0,         // bLink = 0
        kBTLeafNode as u8,  // kind = leaf node
        1,                  // height = 1
        0, num_records,     // numRecords = number of extent records
        0, 0,               // reserved
    ];
    let mut positions = Vec::new();
    for (key, record) in extents {
        positions.push(raw_data.len() as u16);
        key.export(&mut raw_data)?;
        export_record(&record[..], &mut raw_data).unwrap();
    }
    positions.push(raw_data.len() as u16);
    assert!(raw_data.len() <= 512 - 2*positions.len(), "Overflowed extents leaf record");
    raw_data.resize(512 - 2*positions.len(), 0);
    for position in positions.iter().rev() {
        raw_data.write_u16::<BigEndian>(*position).unwrap();
    }
    assert_eq!(raw_data.len(), 512);
    source.write_all(&raw_data)?;
    Ok(())
}
fn write_extents_overflow_file ( source : & mut Write , extents : & [ ( ExtentKey , HFSPlusExtentRecord ) ] ) -> io :: Result < ( ) > { assert ! ( extents len ( ) 256 " " ) ; let num_records = extents . len ( ) as u8 ; let raw_header_data : [ u8 ; 14 ] = [ 0 , 0 , 0 , 0 , // fLink = 0 0 , 0 , 0 , 0 , // bLink = 0 kBTHeaderNode as u8 , // kind = header node 0 , // height = 0 0 , 3 , // numRecords = 3 0 , 0 , // reserved ] ; let header_record : [ u8 ; 106 ] = [ 0 , 1 , // treeDepth = 1 0 , 0 , 0 , 1 , // rootNode = 1 0 , 0 , 0 , num_records , // leafRecords = number of extent records 0 , 0 , 0 , 1 , // firstLeafNode = 1 0 , 0 , 0 , 1 , // lastLeafNode = 1 2 , 0 , // nodeSize = 512 0 , 10 , // maxKeyLength = kHFSPlusExtentKeyMaximumLength 0 , 0 , 0 , 2 , // totalNodes = 2 0 , 0 , 0 , 0 , // freeNodes = 0 0 , 0 , // reserved1 0 , 0 , 2 , 0 , // clumpSize = 512 0 , // btreeType = kHFSBTreeType 0 , // keyCompareType = 0 0 , 0 , 0 , 2 , // attributes = kBTBigKeysMask 0 , 0 , 0 , 0 , // reserved3[16] 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ] ; let user_data_record = [ 0u8 ; 128 ] ; let map_record = [ 0u8 ; 256 ] ; source . write_all ( & raw_header_data ) ? ; source . write_all ( & header_record ) ? ; source . write_all ( & user_data_record ) ? ; source . write_all ( & map_record ) ? ; //// First record always starts at offset 14 //// The Header record is always 106 bytes in length //// The User Data is always 128 bytes //// 4 16-bit record pointers are needed at the end (one for next free location) //// Making the Map Record 256 bytes rounds out the node to 512 bytes source . write_u16 :: < BigEndian > ( 14 + 106 + 128 + 256 ) . unwrap ( ) ; source . write_u16 :: < BigEndian > ( 14 + 106 + 128 ) . unwrap ( ) ; source . write_u16 :: < BigEndian > ( 14 + 106 ) . unwrap ( ) ; source . write_u16 :: < BigEndian > ( 14 ) . unwrap ( ) ; //assert_eq!(raw_header_data.len(), 512); let mut raw_data : Vec < u8 > = vec ! [ 0 0 0 0 // fLink = 0 0 0 0 0 // bLink = 0 kBTLeafNode as u8 // kind = leaf node 1 // height = 1 0 num_records // numRecords = number of extent records 0 0 // reserved ] ; let mut positions = Vec :: new ( ) ; for ( key , record ) in extents { positions . push ( raw_data . len ( ) as u16 ) ; key . export ( & mut raw_data ) ? ; export_record ( & record [ .. ] , & mut raw_data ) . unwrap ( ) ; } positions . push ( raw_data . len ( ) as u16 ) ; assert ! ( raw_data len ( ) 512 2 positions len ( ) " " ) ; raw_data . resize ( 512 - 2 * positions . len ( ) , 0 ) ; for position in positions . iter ( ) . rev ( ) { raw_data . write_u16 :: < BigEndian > ( * position ) . unwrap ( ) ; } assert_eq ! ( raw_data len ( ) 512 ) ; source . write_all ( & raw_data ) ? ; Ok ( ( ) ) }
write_extents_overflow_file(source, extents);
Helper function for creating a simple extents overflow file
This is a very simple function just used for constructing a test vector
for a small filesystem.
write_extents_overflow_file ( source extents ) ; Helper function for creating a simple extents overflow file This is a very simple function just used for constructing a test vector for a small filesystem .
source
&mut Write
extents
&[(ExtentKey, HFSPlusExtentRecord)]
source
&mut Write
extents
&[(ExtentKey, HFSPlusExtentRecord)]