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): extract inode parsing helpers in squashfs (E005)

+55 -63
+55 -63
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 224 + sb_fragment_entry_count sb_compression_id sb_block_log sb_flags sb_id_count 225 + sb_version_major sb_version_minor sb_root_inode_ref sb_bytes_used 226 + sb_id_table_start sb_xattr_table_start sb_inode_table_start 227 + sb_directory_table_start sb_fragment_table_start sb_export_table_start = 228 + { 229 + sb_magic; 230 + sb_inode_count; 231 + sb_modification_time; 232 + sb_block_size; 233 + sb_fragment_entry_count; 234 + sb_compression_id; 235 + sb_block_log; 236 + sb_flags; 237 + sb_id_count; 238 + sb_version_major; 239 + sb_version_minor; 240 + sb_root_inode_ref; 241 + sb_bytes_used; 242 + sb_id_table_start; 243 + sb_xattr_table_start; 244 + sb_inode_table_start; 245 + sb_directory_table_start; 246 + sb_fragment_table_start; 247 + sb_export_table_start; 248 + } 249 + 223 250 let superblock_codec = 224 251 let open Wire.Codec in 225 - record "SquashfsSuperblock" 226 - (fun 227 - sb_magic 228 - sb_inode_count 229 - sb_modification_time 230 - sb_block_size 231 - sb_fragment_entry_count 232 - sb_compression_id 233 - sb_block_log 234 - sb_flags 235 - sb_id_count 236 - sb_version_major 237 - sb_version_minor 238 - sb_root_inode_ref 239 - sb_bytes_used 240 - sb_id_table_start 241 - sb_xattr_table_start 242 - sb_inode_table_start 243 - sb_directory_table_start 244 - sb_fragment_table_start 245 - sb_export_table_start 246 - -> 247 - { 248 - sb_magic; 249 - sb_inode_count; 250 - sb_modification_time; 251 - sb_block_size; 252 - sb_fragment_entry_count; 253 - sb_compression_id; 254 - sb_block_log; 255 - sb_flags; 256 - sb_id_count; 257 - sb_version_major; 258 - sb_version_minor; 259 - sb_root_inode_ref; 260 - sb_bytes_used; 261 - sb_id_table_start; 262 - sb_xattr_table_start; 263 - sb_inode_table_start; 264 - sb_directory_table_start; 265 - sb_fragment_table_start; 266 - sb_export_table_start; 267 - }) 252 + record "SquashfsSuperblock" make_superblock 268 253 |+ field "magic" Wire.uint32 (fun t -> t.sb_magic) 269 254 |+ field "inode_count" Wire.uint32 (fun t -> t.sb_inode_count) 270 255 |+ field "modification_time" Wire.uint32 (fun t -> t.sb_modification_time) ··· 746 731 in 747 732 (Inode_symlink { nlink = b.slb_nlink; target }, xattr_id) 748 733 734 + let parse_device_inode buf body_off data_len = 735 + if body_off + device_body_size > data_len then 736 + failwith "device inode truncated"; 737 + let b = Wire.Codec.decode device_body_codec buf body_off in 738 + (Inode_device { nlink = b.devb_nlink; rdev = b.devb_rdev }, no_xattr_id) 739 + 740 + let parse_ext_device_inode buf body_off data_len = 741 + if body_off + ext_device_body_size > data_len then 742 + failwith "extended device inode truncated"; 743 + let b = Wire.Codec.decode ext_device_body_codec buf body_off in 744 + (Inode_device { nlink = b.edevb_nlink; rdev = b.edevb_rdev }, b.edevb_xattr_id) 745 + 746 + let parse_ipc_inode buf body_off data_len = 747 + if body_off + ipc_body_size > data_len then failwith "IPC inode truncated"; 748 + let b = Wire.Codec.decode ipc_body_codec buf body_off in 749 + (Inode_ipc { nlink = b.ipcb_nlink }, no_xattr_id) 750 + 751 + let parse_ext_ipc_inode buf body_off data_len = 752 + if body_off + ext_ipc_body_size > data_len then 753 + failwith "extended IPC inode truncated"; 754 + let b = Wire.Codec.decode ext_ipc_body_codec buf body_off in 755 + (Inode_ipc { nlink = b.eipcb_nlink }, b.eipcb_xattr_id) 756 + 749 757 let parse_inode _t data offset = 750 758 let data_len = String.length data in 751 759 if offset + inode_header_size > data_len then Error "inode header truncated" ··· 768 776 | Symlink, _ -> 769 777 parse_symlink_inode data buf body_off data_len ~is_extended 770 778 | (Block_device | Char_device), false -> 771 - if body_off + device_body_size > data_len then 772 - failwith "device inode truncated"; 773 - let b = Wire.Codec.decode device_body_codec buf body_off in 774 - ( Inode_device { nlink = b.devb_nlink; rdev = b.devb_rdev }, 775 - no_xattr_id ) 779 + parse_device_inode buf body_off data_len 776 780 | (Block_device | Char_device), true -> 777 - if body_off + ext_device_body_size > data_len then 778 - failwith "extended device inode truncated"; 779 - let b = Wire.Codec.decode ext_device_body_codec buf body_off in 780 - ( Inode_device { nlink = b.edevb_nlink; rdev = b.edevb_rdev }, 781 - b.edevb_xattr_id ) 782 - | (Fifo | Socket), false -> 783 - if body_off + ipc_body_size > data_len then 784 - failwith "IPC inode truncated"; 785 - let b = Wire.Codec.decode ipc_body_codec buf body_off in 786 - (Inode_ipc { nlink = b.ipcb_nlink }, no_xattr_id) 787 - | (Fifo | Socket), true -> 788 - if body_off + ext_ipc_body_size > data_len then 789 - failwith "extended IPC inode truncated"; 790 - let b = Wire.Codec.decode ext_ipc_body_codec buf body_off in 791 - (Inode_ipc { nlink = b.eipcb_nlink }, b.eipcb_xattr_id) 781 + parse_ext_device_inode buf body_off data_len 782 + | (Fifo | Socket), false -> parse_ipc_inode buf body_off data_len 783 + | (Fifo | Socket), true -> parse_ext_ipc_inode buf body_off data_len 792 784 in 793 785 Ok 794 786 {