@@ -38,9 +38,9 @@ bfc_read_header(struct bfcfs_mount *bmp, struct thread *td)
3838 }
3939
4040 /* Validate magic string */
41- if (strncmp (hdr -> magic , "BFCFv1" , 6 ) != 0 ) {
42- BFCFS_ERR ("invalid magic: expected 'BFCFv1 ', got '%.8s'" ,
43- hdr -> magic );
41+ if (strncmp (hdr -> magic , BFC_MAGIC_STR , strlen ( BFC_MAGIC_STR ) ) != 0 ) {
42+ BFCFS_ERR ("invalid magic: expected '%s ', got '%.8s'" ,
43+ BFC_MAGIC_STR , hdr -> magic );
4444 return (EINVAL );
4545 }
4646
@@ -91,7 +91,7 @@ bfc_read_footer(struct bfcfs_mount *bmp, struct thread *td)
9191 }
9292
9393 /* Validate footer magic */
94- if (strncmp (footer -> magic_start , "BFCFIDX" , 7 ) != 0 ) {
94+ if (strncmp (footer -> magic_start , BFC_INDEX_MAGIC , strlen ( BFC_INDEX_MAGIC ) ) != 0 ) {
9595 BFCFS_ERR ("invalid footer magic" );
9696 return (EINVAL );
9797 }
@@ -149,9 +149,7 @@ bfc_parse_index_entry(const uint8_t *buf, size_t buflen, size_t *offset,
149149 return (EINVAL );
150150
151151 /* Read path length (32-bit) */
152- bcopy (p , & path_len , 4 );
153- path_len = LE32 (path_len );
154- p += 4 ;
152+ READ_LE32 (p , path_len );
155153 remaining -= 4 ;
156154
157155 /* Sanity check path length */
@@ -170,37 +168,14 @@ bfc_parse_index_entry(const uint8_t *buf, size_t buflen, size_t *offset,
170168 return (EINVAL );
171169
172170 /* Parse metadata fields (all little-endian) */
173- bcopy (p , & entry -> obj_offset , 8 );
174- entry -> obj_offset = LE64 (entry -> obj_offset );
175- p += 8 ;
176-
177- bcopy (p , & entry -> obj_size , 8 );
178- entry -> obj_size = LE64 (entry -> obj_size );
179- p += 8 ;
180-
181- bcopy (p , & entry -> mode , 4 );
182- entry -> mode = LE32 (entry -> mode );
183- p += 4 ;
184-
185- bcopy (p , & entry -> mtime_ns , 8 );
186- entry -> mtime_ns = LE64 (entry -> mtime_ns );
187- p += 8 ;
188-
189- bcopy (p , & entry -> comp , 4 );
190- entry -> comp = LE32 (entry -> comp );
191- p += 4 ;
192-
193- bcopy (p , & entry -> enc , 4 );
194- entry -> enc = LE32 (entry -> enc );
195- p += 4 ;
196-
197- bcopy (p , & entry -> size , 8 ); /* orig_size */
198- entry -> size = LE64 (entry -> size );
199- p += 8 ;
200-
201- bcopy (p , & entry -> crc32c , 4 );
202- entry -> crc32c = LE32 (entry -> crc32c );
203- p += 4 ;
171+ READ_LE64 (p , entry -> obj_offset );
172+ READ_LE64 (p , entry -> obj_size );
173+ READ_LE32 (p , entry -> mode );
174+ READ_LE64 (p , entry -> mtime_ns );
175+ READ_LE32 (p , entry -> comp );
176+ READ_LE32 (p , entry -> enc );
177+ READ_LE64 (p , entry -> size ); /* orig_size */
178+ READ_LE32 (p , entry -> crc32c );
204179
205180 entry -> ino = ino ;
206181
@@ -240,17 +215,17 @@ bfc_read_index(struct bfcfs_mount *bmp, struct thread *td)
240215 }
241216
242217 /* Parse index header (8 bytes: version + count) */
243- if (bmp -> footer .index_size < 8 ) {
218+ if (bmp -> footer .index_size < BFC_INDEX_HEADER_SIZE ) {
244219 BFCFS_ERR ("index too small for header" );
245220 free (index_buf , M_BFCFS );
246221 return (EINVAL );
247222 }
248223
224+ /* Parse index header (version and count) */
249225 uint32_t version , count ;
250- bcopy (index_buf , & version , 4 );
251- version = LE32 (version );
252- bcopy (index_buf + 4 , & count , 4 );
253- count = LE32 (count );
226+ uint8_t * p = index_buf ;
227+ READ_LE32 (p , version );
228+ READ_LE32 (p , count );
254229
255230 if (version != 1 ) {
256231 BFCFS_ERR ("unsupported index version: %u" , version );
0 commit comments