@@ -144,13 +144,13 @@ bfc_parse_index_entry(const uint8_t *buf, size_t buflen, size_t *offset,
144144 size_t remaining = buflen - * offset ;
145145 uint32_t path_len ;
146146
147- /* Need at least 4 bytes for path_len */
148- if (remaining < 4 )
147+ /* Need at least BFC_PATH_LEN_SIZE bytes for path_len */
148+ if (remaining < BFC_PATH_LEN_SIZE )
149149 return (EINVAL );
150150
151151 /* Read path length (32-bit) */
152152 READ_LE32 (p , path_len );
153- remaining -= 4 ;
153+ remaining -= BFC_PATH_LEN_SIZE ;
154154
155155 /* Sanity check path length */
156156 if (path_len == 0 || path_len > BFC_MAX_PATH_LEN || path_len > remaining )
191191bfc_read_index (struct bfcfs_mount * bmp , struct thread * td )
192192{
193193 uint8_t * index_buf = NULL ;
194+ uint8_t * p ;
195+ uint32_t version , count ;
194196 size_t offset = 0 ;
195197 int error , i ;
196198
@@ -222,13 +224,13 @@ bfc_read_index(struct bfcfs_mount *bmp, struct thread *td)
222224 }
223225
224226 /* Parse index header (version and count) */
225- uint32_t version , count ;
226- uint8_t * p = index_buf ;
227+ p = index_buf ;
227228 READ_LE32 (p , version );
228229 READ_LE32 (p , count );
229230
230- if (version != 1 ) {
231- BFCFS_ERR ("unsupported index version: %u" , version );
231+ if (version != BFC_INDEX_VERSION ) {
232+ BFCFS_ERR ("unsupported index version: %u (expected %u)" ,
233+ version , BFC_INDEX_VERSION );
232234 free (index_buf , M_BFCFS );
233235 return (EINVAL );
234236 }
@@ -247,11 +249,11 @@ bfc_read_index(struct bfcfs_mount *bmp, struct thread *td)
247249 bmp -> index = malloc (bmp -> num_entries * sizeof (struct bfcfs_index_entry ),
248250 M_BFCFS , M_WAITOK | M_ZERO );
249251
250- /* Parse all entries (starting after 8-byte header) */
251- offset = 8 ;
252+ /* Parse all entries (starting after index header) */
253+ offset = BFC_INDEX_HEADER_SIZE ;
252254 for (i = 0 ; i < (int )bmp -> num_entries ; i ++ ) {
253255 error = bfc_parse_index_entry (index_buf , bmp -> footer .index_size ,
254- & offset , & bmp -> index [i ], i + 1 ); /* inode numbers start at 1 */
256+ & offset , & bmp -> index [i ], i + BFC_INODE_START );
255257 if (error ) {
256258 BFCFS_ERR ("failed to parse index entry %d: %d" , i , error );
257259 goto fail ;
0 commit comments