@@ -131,32 +131,32 @@ static blocknum_t file_block_to_fs_block(ext2_t *ext2, struct ext2_inode *inode,
131131 if (inode -> i_flags & 0x80000 ) { // inode is stored using extents
132132 ext4_extent_header * eh = (ext4_extent_header * )& inode -> i_block ;
133133 //printf("its an extent based object\n");
134- //printf("eh_magic: 0x%x\n", eh->eh_magic);
135- //printf("eh_entries: %d\n", eh->eh_entries);
136- //printf("eh_max: %d\n", eh->eh_max);
137- //printf("eh_depth: %d\n", eh->eh_depth);
138- //printf("eh_generation: %d\n", eh->eh_generation);
139- if (eh -> eh_magic != 0xf30a ) {
134+ //printf("eh_magic: 0x%x\n", LE16( eh->eh_magic) );
135+ //printf("eh_entries: %d\n", LE16( eh->eh_entries) );
136+ //printf("eh_max: %d\n", LE16( eh->eh_max) );
137+ //printf("eh_depth: %d\n", LE16( eh->eh_depth) );
138+ //printf("eh_generation: %d\n", LE32( eh->eh_generation) );
139+ if (LE16 ( eh -> eh_magic ) != 0xf30a ) {
140140 puts ("extent header magic invalid" );
141141 return 0 ;
142142 }
143143 block = 0 ; // TODO
144- if (eh -> eh_depth == 0 ) {
144+ if (LE16 ( eh -> eh_depth ) == 0 ) {
145145 ext4_extent * extents = (ext4_extent * )( ((uint32_t )& inode -> i_block ) + 12 );
146- for (int i = 0 ; i < eh -> eh_entries ; i ++ ) {
146+ for (int i = 0 ; i < LE16 ( eh -> eh_entries ) ; i ++ ) {
147147#if 0
148148 printf ("extent %d\n" , i );
149- printf (" ee_block: %d\n" , extents [i ].ee_block );
150- printf (" ee_len: %d\n" , extents [i ].ee_len );
151- printf (" ee_start_hi: %d\n" , extents [i ].ee_start_hi );
152- printf (" ee_start_lo: %d\n" , extents [i ].ee_start_lo );
149+ printf (" ee_block: %d\n" , LE32 ( extents [i ].ee_block ) );
150+ printf (" ee_len: %d\n" , LE16 ( extents [i ].ee_len ) );
151+ printf (" ee_start_hi: %d\n" , LE16 ( extents [i ].ee_start_hi ) );
152+ printf (" ee_start_lo: %d\n" , LE32 ( extents [i ].ee_start_lo ) );
153153#endif
154- if ((fileblock >= extents [i ].ee_block ) && (fileblock < (extents [i ].ee_block + extents [i ].ee_len ))) {
155- if (extents [i ].ee_start_hi != 0 ) {
154+ if ((fileblock >= LE32 ( extents [i ].ee_block )) && (fileblock < (LE32 ( extents [i ].ee_block ) + LE16 ( extents [i ].ee_len ) ))) {
155+ if (LE16 ( extents [i ].ee_start_hi ) != 0 ) {
156156 puts ("unsupported >32bit blocknr" );
157157 return 0 ;
158158 }
159- block = extents [i ].ee_start_lo + (fileblock - extents [i ].ee_block );
159+ block = LE32 ( extents [i ].ee_start_lo ) + (fileblock - LE32 ( extents [i ].ee_block ) );
160160 }
161161 }
162162 }
0 commit comments