// Returns the number of data pages (low byte) and fat pages (high
// byte) written.
Returns the number of data pages (low byte) and fat pages (high
byte) written.
Returns the number of data pages ( low byte ) and fat pages ( high byte ) written .
fn write_filesystem(&mut self) -> Result<u16, Error> {
        let mut parent_id: u16 = 0;
        let mut section_id: u16 = (u16::from(self.dat_start) << 8) | 1;
        let mut fatptr: u32 = (u32::from(self.fat_start) + 1) * u32::from(PAGE_LENGTH);
        let fatptr_start: u32 = fatptr;
        /* Write the first DAT page's magic number */
        self.rom.seek(SeekFrom::Start(
            u64::from(self.dat_start) * u64::from(PAGE_LENGTH),
        ))?;
        self.rom.write_all(b"KFS")?;
        self.rom.flush()?;
        self.write_recursive(
            self.model.to_path_buf(),
            &mut parent_id,
            &mut section_id,
            &mut fatptr,
        )?;
        let (quot, rem) = div_rem(fatptr_start - fatptr, u32::from(PAGE_LENGTH));
        // Given that PAGE_LENGTH is sufficiently large, it's safe to
        // downgrade number size here.
        let mut result: u16 = quot.try_into().unwrap();
        if rem > 0 {
            result += 1;
        }
        result <<= 8;
        // sectionId's high byte is a page number
        result = if cfg!(feature = "c-undef") {
            // C original has undefined behavior:  result += (sectionId >> 8) - dat_start + 1;
            result.wrapping_add((section_id >> 8).wrapping_sub(u16::from(self.dat_start))) + 1
        } else {
            // Safe version
            result + (section_id >> 8) - u16::from(self.dat_start) + 1
        };
        Ok(result)
    }
fn write_filesystem ( & mut self ) -> Result < u16 , Error > { let mut parent_id : u16 = 0 ; let mut section_id : u16 = ( u16 :: from ( self . dat_start ) << 8 ) | 1 ; let mut fatptr : u32 = ( u32 :: from ( self . fat_start ) + 1 ) * u32 :: from ( PAGE_LENGTH ) ; let fatptr_start : u32 = fatptr ; /* Write the first DAT page's magic number */ self . rom . seek ( SeekFrom :: Start ( u64 :: from ( self . dat_start ) * u64 :: from ( PAGE_LENGTH ) , ) ) ? ; self . rom . write_all ( b" " ) ? ; self . rom . flush ( ) ? ; self . write_recursive ( self . model . to_path_buf ( ) , & mut parent_id , & mut section_id , & mut fatptr , ) ? ; let ( quot , rem ) = div_rem ( fatptr_start - fatptr , u32 :: from ( PAGE_LENGTH ) ) ; // Given that PAGE_LENGTH is sufficiently large, it's safe to // downgrade number size here. let mut result : u16 = quot . try_into ( ) . unwrap ( ) ; if rem > 0 { result += 1 ; } result <<= 8 ; // sectionId's high byte is a page number result = if cfg ! ( feature " " ) { // C original has undefined behavior:  result += (sectionId >> 8) - dat_start + 1; result . wrapping_add ( ( section_id >> 8 ) . wrapping_sub ( u16 :: from ( self . dat_start ) ) ) + 1 } else { // Safe version result + ( section_id >> 8 ) - u16 :: from ( self . dat_start ) + 1 } ; Ok ( result ) }
Returns the number of data pages (low byte) and fat pages (high
byte) written.
Returns the number of data pages ( low byte ) and fat pages ( high byte ) written .
&mut self