+(* File type tests.
+ *
+ * Note these have to be on Linux ABI modes. We cannot use the
+ * OCaml (ie. host) equivalents here.
+ *)
+let rec file_type mask mode = Int64.logand mode 0o170000L = mask
+
+and is_socket mode = file_type 0o140000L mode
+and is_symlink mode = file_type 0o120000L mode
+and is_regular_file mode = file_type 0o100000L mode
+and is_block mode = file_type 0o060000L mode
+and is_directory mode = file_type 0o040000L mode
+and is_char mode = file_type 0o020000L mode
+and is_fifo mode = file_type 0o010000L mode
+
+and is_suid mode = test_bit 0o4000L mode
+and is_sgid mode = test_bit 0o2000L mode
+and is_svtx mode = test_bit 0o1000L mode
+
+and is_ru mode = test_bit 0o400L mode
+and is_wu mode = test_bit 0o200L mode
+and is_xu mode = test_bit 0o100L mode
+and is_rg mode = test_bit 0o040L mode
+and is_wg mode = test_bit 0o020L mode
+and is_xg mode = test_bit 0o010L mode
+and is_ro mode = test_bit 0o004L mode
+and is_wo mode = test_bit 0o002L mode
+and is_xo mode = test_bit 0o001L mode
+
+and test_bit mask mode = Int64.logand mode mask = mask