]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/sys/decmpfs.h
xnu-4903.221.2.tar.gz
[apple/xnu.git] / bsd / sys / decmpfs.h
index 72e99ee18e854599a9078d76f2348302ca165cc3..1f57e93bf4ccddaa36c0b2079bddfd1a513a9d15 100644 (file)
 #ifndef _SYS_DECMPFS_H_
 #define _SYS_DECMPFS_H_ 1
 
+#include <stdbool.h>
+#include <sys/kdebug.h>
+#include <sys/kernel_types.h>
+#include <sys/vnode.h>
+
+/*
+ * Please switch on @DECMPFS_ENABLE_KDEBUG_TRACES to enable tracepoints.
+ * Tracepoints are compiled out by default to eliminate any overhead due to
+ * kernel tracing.
+ *
+ * #define DECMPFS_ENABLE_KDEBUG_TRACES 1
+ */
+#if DECMPFS_ENABLE_KDEBUG_TRACES
+#define DECMPFS_EMIT_TRACE_ENTRY(D, ...)\
+        KDBG_FILTERED((D) | DBG_FUNC_START, ## __VA_ARGS__)
+#define DECMPFS_EMIT_TRACE_RETURN(D, ...)\
+        KDBG_FILTERED((D) | DBG_FUNC_END, ##__VA_ARGS__)
+#else
+#define DECMPFS_EMIT_TRACE_ENTRY(D, ...) do {} while (0)
+#define DECMPFS_EMIT_TRACE_RETURN(D, ...) do {} while (0)
+#endif /* DECMPFS_ENABLE_KDEBUG_TRACES */
+
+/*
+ * KERNEL_DEBUG related definitions for decmpfs.
+ *
+ * Please NOTE: The Class DBG_FSYSTEM = 3, and Subclass DBG_DECMP = 0x12, so
+ * these debug codes are of the form 0x0312nnnn.
+ */
+#define DECMPDBG_CODE(code)  FSDBG_CODE(DBG_DECMP, code)
+
+enum {
+    DECMPDBG_DECOMPRESS_FILE            = DECMPDBG_CODE(0), /* 0x03120000 */
+    DECMPDBG_FETCH_COMPRESSED_HEADER    = DECMPDBG_CODE(1), /* 0x03120004 */
+    DECMPDBG_FETCH_UNCOMPRESSED_DATA    = DECMPDBG_CODE(2), /* 0x03120008 */
+    DECMPDBG_FREE_COMPRESSED_DATA       = DECMPDBG_CODE(4), /* 0x03120010 */
+    DECMPDBG_FILE_IS_COMPRESSED         = DECMPDBG_CODE(5), /* 0x03120014 */
+};
+
 #define MAX_DECMPFS_XATTR_SIZE 3802
 
 /*
@@ -61,7 +99,7 @@ enum {
     
     /* additional types defined in AppleFSCompression project */
     
-    CMP_MAX         = 255
+    CMP_MAX         = 255 /* Highest compression_type supported */
 };
 
 typedef struct {
@@ -69,28 +107,26 @@ typedef struct {
     user_ssize_t size;
 } decmpfs_vector;
 
-#if KERNEL
+#ifdef KERNEL
+
+#ifdef XNU_KERNEL_PRIVATE
 
 #include <kern/locks.h>
 
-#if defined(__i386__) || defined(__x86_64__)
-#define DECMPFS_SUPPORTS_SWAP64 1
-/* otherwise, no OSCompareAndSwap64, so use a mutex */
-#endif
-
-typedef struct decmpfs_cnode {
-       uint8_t cmp_state;
-       uint8_t cmp_minimal_xattr;       /* if non-zero, this file's com.apple.decmpfs xattr contained only the minimal decmpfs_disk_header */
-       uint32_t cmp_type;
-       uint32_t lockcount;
-       void    *lockowner;              /* cnode's lock owner (if a thread is currently holding an exclusive lock) */
-    uint64_t uncompressed_size;
+struct decmpfs_cnode {
+    uint8_t cmp_state;
+    uint8_t cmp_minimal_xattr;       /* if non-zero, this file's com.apple.decmpfs xattr contained only the minimal decmpfs_disk_header */
+    uint32_t cmp_type;
+    uint32_t lockcount;
+    void    *lockowner;              /* cnode's lock owner (if a thread is currently holding an exclusive lock) */
+    uint64_t uncompressed_size __attribute__((aligned(8)));
+    uint64_t decompression_flags;
     lck_rw_t compressed_data_lock;
-#if !DECMPFS_SUPPORTS_SWAP64
-    /* we need a lock since we can't atomically fetch/set 64 bits */
-    lck_mtx_t uncompressed_size_mtx;
-#endif /* !DECMPFS_SUPPORTS_SWAP64 */
-} decmpfs_cnode;
+};
+
+#endif // XNU_KERNEL_PRIVATE
+
+typedef struct decmpfs_cnode decmpfs_cnode;
 
 /* return values from decmpfs_file_is_compressed */
 enum {
@@ -105,19 +141,22 @@ extern vfs_context_t decmpfs_ctx;
 
 /* client filesystem entrypoints */
 void decmpfs_init(void);
+decmpfs_cnode *decmpfs_cnode_alloc(void);
+void decmpfs_cnode_free(decmpfs_cnode *dp);
 void decmpfs_cnode_init(decmpfs_cnode *cp);
 void decmpfs_cnode_destroy(decmpfs_cnode *cp);
 
 int decmpfs_hides_rsrc(vfs_context_t ctx, decmpfs_cnode *cp);
 int decmpfs_hides_xattr(vfs_context_t ctx, decmpfs_cnode *cp, const char *xattr);
 
-boolean_t decmpfs_trylock_compressed_data(decmpfs_cnode *cp, int exclusive);
+bool decmpfs_trylock_compressed_data(decmpfs_cnode *cp, int exclusive);
 void decmpfs_lock_compressed_data(decmpfs_cnode *cp, int exclusive);
 void decmpfs_unlock_compressed_data(decmpfs_cnode *cp, int exclusive);
 
 uint32_t decmpfs_cnode_get_vnode_state(decmpfs_cnode *cp);
 void decmpfs_cnode_set_vnode_state(decmpfs_cnode *cp, uint32_t state, int skiplock);
 uint64_t decmpfs_cnode_get_vnode_cached_size(decmpfs_cnode *cp);
+uint32_t decmpfs_cnode_cmp_type(decmpfs_cnode *cp);
 
 int decmpfs_file_is_compressed(vnode_t vp, decmpfs_cnode *cp);
 errno_t decmpfs_validate_compressed_file(vnode_t vp, decmpfs_cnode *cp);
@@ -133,18 +172,29 @@ typedef int (*decmpfs_validate_compressed_file_func)(vnode_t vp, vfs_context_t c
 typedef void (*decmpfs_adjust_fetch_region_func)(vnode_t vp, vfs_context_t ctx, decmpfs_header *hdr, off_t *offset, user_ssize_t *size);
 typedef int (*decmpfs_fetch_uncompressed_data_func)(vnode_t vp, vfs_context_t ctx, decmpfs_header *hdr, off_t offset, user_ssize_t size, int nvec, decmpfs_vector *vec, uint64_t *bytes_read);
 typedef int (*decmpfs_free_compressed_data_func)(vnode_t vp, vfs_context_t ctx, decmpfs_header *hdr);
+typedef uint64_t (*decmpfs_get_decompression_flags_func)(vnode_t vp, vfs_context_t ctx, decmpfs_header *hdr); // returns flags from the DECMPFS_FLAGS enumeration below
+
+enum {
+    DECMPFS_FLAGS_FORCE_FLUSH_ON_DECOMPRESS = 1 << 0,
+};
+
+/* Versions that are supported for binary compatibility */
+#define DECMPFS_REGISTRATION_VERSION_V1 1
+#define DECMPFS_REGISTRATION_VERSION_V3 3
+
+#define DECMPFS_REGISTRATION_VERSION (DECMPFS_REGISTRATION_VERSION_V3)
 
-#define DECMPFS_REGISTRATION_VERSION 1
 typedef struct {
     int                                   decmpfs_registration;
     decmpfs_validate_compressed_file_func validate;
     decmpfs_adjust_fetch_region_func      adjust_fetch;
     decmpfs_fetch_uncompressed_data_func  fetch;
     decmpfs_free_compressed_data_func     free_data;
+    decmpfs_get_decompression_flags_func  get_flags;
 } decmpfs_registration;
 
 /* hooks for kexts to call */
-errno_t register_decmpfs_decompressor(uint32_t compression_type, decmpfs_registration *registration);
+errno_t register_decmpfs_decompressor(uint32_t compression_type, const decmpfs_registration *registration);
 errno_t unregister_decmpfs_decompressor(uint32_t compression_type, decmpfs_registration *registration);
 
 #endif /* KERNEL */