SquashFS compressed filesystem reader in pure OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lint): remove redundant make_ prefixes (E331)

Rename make_superblock → superblock, make_inode_buf → inode_buf,
make_image → image, make_key → key in squashfs and streaming-aead.

+16 -24
+2 -2
lib/squashfs.ml
··· 220 220 sb_export_table_start : int64; 221 221 } 222 222 223 - let make_superblock sb_magic sb_inode_count sb_modification_time sb_block_size 223 + let superblock sb_magic sb_inode_count sb_modification_time sb_block_size 224 224 sb_fragment_entry_count sb_compression_id sb_block_log sb_flags sb_id_count 225 225 sb_version_major sb_version_minor sb_root_inode_ref sb_bytes_used 226 226 sb_id_table_start sb_xattr_table_start sb_inode_table_start ··· 249 249 250 250 let superblock_codec = 251 251 let open Wire.Codec in 252 - record "SquashfsSuperblock" make_superblock 252 + record "SquashfsSuperblock" superblock 253 253 |+ field "magic" Wire.uint32 (fun t -> t.sb_magic) 254 254 |+ field "inode_count" Wire.uint32 (fun t -> t.sb_inode_count) 255 255 |+ field "modification_time" Wire.uint32 (fun t -> t.sb_modification_time)
+8 -11
lib/squashfs_writer.ml
··· 261 261 sb_export_table_start : int64; 262 262 } 263 263 264 - let make_superblock sb_magic sb_inode_count sb_modification_time sb_block_size 264 + let superblock sb_magic sb_inode_count sb_modification_time sb_block_size 265 265 sb_fragment_entry_count sb_compression_id sb_block_log sb_flags sb_id_count 266 266 sb_version_major sb_version_minor sb_root_inode_ref sb_bytes_used 267 267 sb_id_table_start sb_xattr_table_start sb_inode_table_start ··· 290 290 291 291 let superblock_codec = 292 292 let open Wire.Codec in 293 - record "SquashfsSuperblock" make_superblock 293 + record "SquashfsSuperblock" superblock 294 294 |+ field "magic" Wire.uint32 (fun t -> t.sb_magic) 295 295 |+ field "inode_count" Wire.uint32 (fun t -> t.sb_inode_count) 296 296 |+ field "modification_time" Wire.uint32 (fun t -> t.sb_modification_time) ··· 580 580 | _ -> None 581 581 582 582 (* Encode an inode header + body into a fresh buffer *) 583 - let make_inode_buf t inode_type mode inode_number body_size encode_body = 583 + let inode_buf t inode_type mode inode_number body_size encode_body = 584 584 let buf = Bytes.create (inode_header_size + body_size) in 585 585 encode_inode_header buf 0 inode_type mode 0 0 t.mtime inode_number; 586 586 encode_body buf inode_header_size; ··· 592 592 List.fold_left (fun acc (n, _) -> acc + 8 + String.length n) 3 children 593 593 in 594 594 let buf = 595 - make_inode_buf t Basic_directory mode inode_number dir_body_size 596 - (fun buf off -> 595 + inode_buf t Basic_directory mode inode_number dir_body_size (fun buf off -> 597 596 Wire.Codec.encode dir_body_codec 598 597 { 599 598 db_start_block = 0; ··· 609 608 let write_file_inode_buf t inode_table inode_number mode data = 610 609 let fragment_unsigned = 0xFFFFFFFF in 611 610 let buf = 612 - make_inode_buf t Basic_file mode inode_number file_body_size (fun buf off -> 611 + inode_buf t Basic_file mode inode_number file_body_size (fun buf off -> 613 612 Wire.Codec.encode file_body_codec 614 613 { 615 614 fb_start_block = 0; ··· 637 636 minor = 638 637 let rdev = (major lsl 8) lor minor in 639 638 let buf = 640 - make_inode_buf t inode_type mode inode_number device_body_size 641 - (fun buf off -> 639 + inode_buf t inode_type mode inode_number device_body_size (fun buf off -> 642 640 Wire.Codec.encode device_body_codec 643 641 { devb_nlink = 1; devb_rdev = rdev } 644 642 buf off) ··· 647 645 648 646 let write_ipc_inode_buf t inode_table inode_number inode_type mode = 649 647 let buf = 650 - make_inode_buf t inode_type mode inode_number ipc_body_size (fun buf off -> 648 + inode_buf t inode_type mode inode_number ipc_body_size (fun buf off -> 651 649 Wire.Codec.encode ipc_body_codec { ipcb_nlink = 1 } buf off) 652 650 in 653 651 Buffer.add_bytes inode_table buf ··· 700 698 List.fold_left (fun acc (n, _) -> acc + 8 + String.length n) 3 t.root 701 699 in 702 700 let buf = 703 - make_inode_buf t Basic_directory 0o755 inode_number dir_body_size 704 - (fun buf off -> 701 + inode_buf t Basic_directory 0o755 inode_number dir_body_size (fun buf off -> 705 702 Wire.Codec.encode dir_body_codec 706 703 { 707 704 db_start_block = 0;
+6 -11
test/test_squashfs.ml
··· 271 271 (* ---- xattr tests ---- *) 272 272 273 273 (* Helper: build a minimal SquashFS image using the writer *) 274 - let make_image f = 274 + let image f = 275 275 let fs = Squashfs.Writer.v () in 276 276 f fs; 277 277 match Squashfs.of_string (Squashfs.Writer.finalize fs) with ··· 281 281 (* has_xattrs returns false for a plain image (no xattr table) *) 282 282 let test_has_xattrs_false () = 283 283 let t = 284 - make_image (fun fs -> 285 - Squashfs.Writer.add_file fs "hello.txt" ~mode:0o644 "hi") 284 + image (fun fs -> Squashfs.Writer.add_file fs "hello.txt" ~mode:0o644 "hi") 286 285 in 287 286 Alcotest.(check bool) "no xattrs" false (Squashfs.has_xattrs t) 288 287 289 288 (* xattr returns Ok None for inode with no xattrs (xattr_id = 0xFFFFFFFF) *) 290 289 let test_xattr_no_xattr_table () = 291 290 let t = 292 - make_image (fun fs -> Squashfs.Writer.add_file fs "f" ~mode:0o644 "data") 291 + image (fun fs -> Squashfs.Writer.add_file fs "f" ~mode:0o644 "data") 293 292 in 294 293 let root = Squashfs.root t in 295 294 match Squashfs.xattr t root "user.foo" with ··· 299 298 300 299 (* list_xattrs returns Ok [] for inode with no xattrs *) 301 300 let test_list_xattrs_empty () = 302 - let t = 303 - make_image (fun fs -> Squashfs.Writer.add_directory fs "d" ~mode:0o755) 304 - in 301 + let t = image (fun fs -> Squashfs.Writer.add_directory fs "d" ~mode:0o755) in 305 302 let root = Squashfs.root t in 306 303 match Squashfs.list_xattrs t root with 307 304 | Ok [] -> () ··· 311 308 (* xattr on a symlink inode with no xattrs returns Ok None *) 312 309 let test_xattr_symlink_no_xattrs () = 313 310 let t = 314 - make_image (fun fs -> 311 + image (fun fs -> 315 312 Squashfs.Writer.add_file fs "target" ~mode:0o644 "x"; 316 313 Squashfs.Writer.add_symlink fs "link" "target") 317 314 in ··· 494 491 let test_xattr_bad_table_start () = 495 492 (* A valid image normally has xattr_table_start = 0xFFFFFFFFFFFFFFFF (no xattrs). 496 493 We can't easily craft one with a bad table, but we can test the has_xattrs path. *) 497 - let t = 498 - make_image (fun fs -> Squashfs.Writer.add_file fs "f" ~mode:0o644 "x") 499 - in 494 + let t = image (fun fs -> Squashfs.Writer.add_file fs "f" ~mode:0o644 "x") in 500 495 (* has_xattrs is false for writer-generated images *) 501 496 Alcotest.(check bool) "has_xattrs false" false (Squashfs.has_xattrs t); 502 497 (* xattr on root (no xattr_id) is Ok None *)