META file
[ocaml-bitstring.git] / tests / 70_ext3_sb.ml
1 (* Parse an ext3 superblock.
2  * $Id: 70_ext3_sb.ml,v 1.1 2008-04-01 19:10:45 rjones Exp $
3  *)
4
5 open Printf
6
7 (*let () = Bitmatch.debug := true*)
8
9 let bits = Bitmatch.bitstring_of_file "tests/ext3_sb"
10
11 (* The structure is straight from /usr/include/linux/ext3_fs.h *)
12
13 let () =
14   bitmatch bits with
15   | s_inodes_count : 32 : littleendian;         (* Inodes count *)
16     s_blocks_count : 32 : littleendian;         (* Blocks count *)
17     s_r_blocks_count : 32 : littleendian;       (* Reserved blocks count *)
18     s_free_blocks_count : 32 : littleendian;    (* Free blocks count *)
19     s_free_inodes_count : 32 : littleendian;    (* Free inodes count *)
20     s_first_data_block : 32 : littleendian;     (* First Data Block *)
21     s_log_block_size : 32 : littleendian;       (* Block size *)
22     s_log_frag_size : 32 : littleendian;        (* Fragment size *)
23     s_blocks_per_group : 32 : littleendian;     (* # Blocks per group *)
24     s_frags_per_group : 32 : littleendian;      (* # Fragments per group *)
25     s_inodes_per_group : 32 : littleendian;     (* # Inodes per group *)
26     s_mtime : 32 : littleendian;                (* Mount time *)
27     s_wtime : 32 : littleendian;                (* Write time *)
28     s_mnt_count : 16 : littleendian;            (* Mount count *)
29     s_max_mnt_count : 16 : littleendian;        (* Maximal mount count *)
30     0xef53 : 16 : littleendian;                 (* Magic signature *)
31     s_state : 16 : littleendian;                (* File system state *)
32     s_errors : 16 : littleendian;               (* Behaviour when detecting errors *)
33     s_minor_rev_level : 16 : littleendian;      (* minor revision level *)
34     s_lastcheck : 32 : littleendian;            (* time of last check *)
35     s_checkinterval : 32 : littleendian;        (* max. time between checks *)
36     s_creator_os : 32 : littleendian;           (* OS *)
37     s_rev_level : 32 : littleendian;            (* Revision level *)
38     s_def_resuid : 16 : littleendian;           (* Default uid for reserved blocks *)
39     s_def_resgid : 16 : littleendian;           (* Default gid for reserved blocks *)
40     s_first_ino : 32 : littleendian;            (* First non-reserved inode *)
41     s_inode_size : 16 : littleendian;           (* size of inode structure *)
42     s_block_group_nr : 16 : littleendian;       (* block group # of this superblock *)
43     s_feature_compat : 32 : littleendian;       (* compatible feature set *)
44     s_feature_incompat : 32 : littleendian;     (* incompatible feature set *)
45     s_feature_ro_compat : 32 : littleendian;    (* readonly-compatible feature set *)
46     s_uuid : 128 : bitstring;                   (* 128-bit uuid for volume *)
47     s_volume_name : 128 : bitstring;            (* volume name XXX string *)
48     s_last_mounted : 512 : bitstring;           (* directory where last mounted XXX string *)
49     s_algorithm_usage_bitmap : 32 : littleendian; (* For compression *)
50     s_prealloc_blocks : 8;                      (* Nr of blocks to try to preallocate*)
51     s_prealloc_dir_blocks : 8;                  (* Nr to preallocate for dirs *)
52     s_reserved_gdt_blocks : 16 : littleendian;  (* Per group desc for online growth *)
53     s_journal_uuid : 128 : bitstring;           (* uuid of journal superblock *)
54     s_journal_inum : 32 : littleendian;         (* inode number of journal file *)
55     s_journal_dev : 32 : littleendian;          (* device number of journal file *)
56     s_last_orphan : 32 : littleendian;          (* start of list of inodes to delete *)
57     s_hash_seed0 : 32 : littleendian;           (* HTREE hash seed *)
58     s_hash_seed1 : 32 : littleendian;
59     s_hash_seed2 : 32 : littleendian;
60     s_hash_seed3 : 32 : littleendian;
61     s_def_hash_version : 8;                     (* Default hash version to use *)
62     s_reserved_char_pad : 8;
63     s_reserved_word_pad : 16 : littleendian;
64     s_default_mount_opts : 32 : littleendian;
65     s_first_meta_bg : 32 : littleendian;        (* First metablock block group *)
66     s_reserved : 6080 : bitstring ->            (* Padding to the end of the block *)
67
68     printf "ext3 superblock:\n";
69     printf "  s_inodes_count = %ld\n" s_inodes_count;
70     printf "  s_blocks_count = %ld\n" s_blocks_count;
71     printf "  s_free_inodes_count = %ld\n" s_free_inodes_count;
72     printf "  s_free_blocks_count = %ld\n" s_free_blocks_count
73
74   | _ ->
75     eprintf "not an ext3 superblock!\n%!";
76     exit 2