Multiple style fixes in ext4_fs
[lwext4.git] / lwext4 / ext4_types.h
index 4346d233309c3241893a4156c1cbf47f80d03d25..6a81b444f0a41e58d01db873972f6d52b6db9d36 100644 (file)
 #include "ext4_blockdev.h"
 #include "tree.h"
 
+#include <stddef.h>
 #include <stdint.h>
 
+#define EXT4_CHECKSUM_CRC32C 1
+
 /*
  * Structure of the super block
  */
@@ -126,7 +129,7 @@ struct ext4_sblock {
        uint64_t mmp_block;       /* Block for multi-mount protection */
        uint32_t raid_stripe_width;  /* Blocks on all data disks (N * stride) */
        uint8_t log_groups_per_flex; /* FLEX_BG group size */
-       uint8_t reserved_char_pad;
+       uint8_t checksum_type;
        uint16_t reserved_pad;
        uint64_t kbytes_written; /* Number of lifetime kilobytes written */
        uint32_t snapshot_inum;  /* I-node number of active snapshot */
@@ -149,7 +152,15 @@ struct ext4_sblock {
        uint64_t last_error_block;    /* Block involved of last error */
        uint8_t last_error_func[32];  /* Function where the error happened */
        uint8_t mount_opts[64];
-       uint32_t padding[112]; /* Padding to the end of the block */
+       uint32_t usr_quota_inum;        /* inode for tracking user quota */
+       uint32_t grp_quota_inum;        /* inode for tracking group quota */
+       uint32_t overhead_clusters;     /* overhead blocks/clusters in fs */
+       uint32_t backup_bgs[2]; /* groups with sparse_super2 SBs */
+       uint8_t  encrypt_algos[4];      /* Encryption algorithms in use  */
+       uint8_t  encrypt_pw_salt[16];   /* Salt used for string2key algorithm */
+       uint32_t lpf_ino;               /* Location of the lost+found inode */
+       uint32_t padding[100];  /* Padding to the end of the block */
+       uint32_t checksum;              /* crc32c(superblock) */
 } __attribute__((packed));
 
 #define EXT4_SUPERBLOCK_MAGIC 0xEF53
@@ -183,104 +194,102 @@ struct ext4_sblock {
 /*
  * Compatible features
  */
-#define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
-#define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
-#define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
-#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
-#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
-#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
+#define EXT4_FCOM_DIR_PREALLOC 0x0001
+#define EXT4_FCOM_IMAGIC_INODES 0x0002
+#define EXT4_FCOM_HAS_JOURNAL 0x0004
+#define EXT4_FCOM_EXT_ATTR 0x0008
+#define EXT4_FCOM_RESIZE_INODE 0x0010
+#define EXT4_FCOM_DIR_INDEX 0x0020
 
 /*
  * Read-only compatible features
  */
-#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
-#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
-#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
-#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
-#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
-#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
-#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
-#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
-#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200
-#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
+#define EXT4_FRO_COM_SPARSE_SUPER 0x0001
+#define EXT4_FRO_COM_LARGE_FILE 0x0002
+#define EXT4_FRO_COM_BTREE_DIR 0x0004
+#define EXT4_FRO_COM_HUGE_FILE 0x0008
+#define EXT4_FRO_COM_GDT_CSUM 0x0010
+#define EXT4_FRO_COM_DIR_NLINK 0x0020
+#define EXT4_FRO_COM_EXTRA_ISIZE 0x0040
+#define EXT4_FRO_COM_QUOTA 0x0100
+#define EXT4_FRO_COM_BIGALLOC 0x0200
+#define EXT4_FRO_COM_METADATA_CSUM 0x0400
 
 /*
  * Incompatible features
  */
-#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
-#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
-#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004     /* Needs recovery */
-#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
-#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
-#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
-#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
-#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
-#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
-#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400   /* EA in inode */
-#define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000     /* data in dirent */
-#define EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM 0x2000 /* use crc32c for bg */
-#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000   /* >2GB or 3-lvl htree */
-#define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000      /* data in inode */
+#define EXT4_FINCOM_COMPRESSION 0x0001
+#define EXT4_FINCOM_FILETYPE 0x0002
+#define EXT4_FINCOM_RECOVER 0x0004     /* Needs recovery */
+#define EXT4_FINCOM_JOURNAL_DEV 0x0008 /* Journal device */
+#define EXT4_FINCOM_META_BG 0x0010
+#define EXT4_FINCOM_EXTENTS 0x0040 /* extents support */
+#define EXT4_FINCOM_64BIT 0x0080
+#define EXT4_FINCOM_MMP 0x0100
+#define EXT4_FINCOM_FLEX_BG 0x0200
+#define EXT4_FINCOM_EA_INODE 0x0400     /* EA in inode */
+#define EXT4_FINCOM_DIRDATA 0x1000       /* data in dirent */
+#define EXT4_FINCOM_BG_USE_META_CSUM 0x2000 /* use crc32c for bg */
+#define EXT4_FINCOM_LARGEDIR 0x4000     /* >2GB or 3-lvl htree */
+#define EXT4_FINCOM_INLINE_DATA 0x8000      /* data in inode */
 
 /*
  * EXT2 supported feature set
  */
-#define EXT2_FEATURE_COMPAT_SUPP 0x0000
+#define EXT2_SUPPORTED_FCOM 0x0000
 
-#define EXT2_FEATURE_INCOMPAT_SUPP                                             \
-       (EXT4_FEATURE_INCOMPAT_FILETYPE | EXT4_FEATURE_INCOMPAT_META_BG)
+#define EXT2_SUPPORTED_FINCOM                                   \
+       (EXT4_FINCOM_FILETYPE | EXT4_FINCOM_META_BG)
 
-#define EXT2_FEATURE_RO_COMPAT_SUPP                                            \
-       (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER |                                 \
-        EXT4_FEATURE_RO_COMPAT_LARGE_FILE | EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
+#define EXT2_SUPPORTED_FRO_COM                                  \
+       (EXT4_FRO_COM_SPARSE_SUPER |                            \
+        EXT4_FRO_COM_LARGE_FILE)
 
 /*
  * EXT3 supported feature set
  */
-#define EXT3_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_DIR_INDEX)
+#define EXT3_SUPPORTED_FCOM (EXT4_FCOM_DIR_INDEX)
 
-#define EXT3_FEATURE_INCOMPAT_SUPP                                             \
-       (EXT4_FEATURE_INCOMPAT_FILETYPE | EXT4_FEATURE_INCOMPAT_META_BG)
+#define EXT3_SUPPORTED_FINCOM                                 \
+       (EXT4_FINCOM_FILETYPE | EXT4_FINCOM_META_BG)
 
-#define EXT3_FEATURE_RO_COMPAT_SUPP                                            \
-       (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER |                                 \
-        EXT4_FEATURE_RO_COMPAT_LARGE_FILE | EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
+#define EXT3_SUPPORTED_FRO_COM                                \
+       (EXT4_FRO_COM_SPARSE_SUPER | EXT4_FRO_COM_LARGE_FILE)
 
 /*
  * EXT4 supported feature set
  */
-#define EXT4_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_DIR_INDEX)
+#define EXT4_SUPPORTED_FCOM (EXT4_FCOM_DIR_INDEX)
 
-#define EXT4_FEATURE_INCOMPAT_SUPP                                             \
-       (EXT4_FEATURE_INCOMPAT_FILETYPE | EXT4_FEATURE_INCOMPAT_META_BG |      \
-        EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_FLEX_BG |       \
-        EXT4_FEATURE_INCOMPAT_64BIT)
+#define EXT4_SUPPORTED_FINCOM                              \
+       (EXT4_FINCOM_FILETYPE | EXT4_FINCOM_META_BG |      \
+        EXT4_FINCOM_EXTENTS | EXT4_FINCOM_FLEX_BG |       \
+        EXT4_FINCOM_64BIT)
 
-#define EXT4_FEATURE_RO_COMPAT_SUPP                                            \
-       (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER |                                 \
-        EXT4_FEATURE_RO_COMPAT_LARGE_FILE | EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \
-        EXT4_FEATURE_RO_COMPAT_DIR_NLINK |                                    \
-        EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE |                                  \
-        EXT4_FEATURE_RO_COMPAT_BTREE_DIR | EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
+#define EXT4_SUPPORTED_FRO_COM                             \
+       (EXT4_FRO_COM_SPARSE_SUPER |                       \
+        EXT4_FRO_COM_METADATA_CSUM |                      \
+        EXT4_FRO_COM_LARGE_FILE | EXT4_FRO_COM_GDT_CSUM | \
+        EXT4_FRO_COM_DIR_NLINK |                          \
+        EXT4_FRO_COM_EXTRA_ISIZE | EXT4_FRO_COM_HUGE_FILE)
 
 /*Ignored features:
  * RECOVER - journaling in lwext4 is not supported
  *           (probably won't be ever...)
  * MMP - multi-mout protection (impossible scenario)
  * */
-#define FEATURE_INCOMPAT_IGNORED                                               \
-       EXT4_FEATURE_INCOMPAT_RECOVER | EXT4_FEATURE_INCOMPAT_MMP
+#define EXT_FINCOM_IGNORED                                 \
+       EXT4_FINCOM_RECOVER | EXT4_FINCOM_MMP
 
 #if 0
 /*TODO: Features incompatible to implement*/
-#define EXT4_FEATURE_INCOMPAT_SUPP
-                     (EXT4_FEATURE_INCOMPAT_INLINE_DATA)
+#define EXT4_SUPPORTED_FINCOM
+                     (EXT4_FINCOM_INLINE_DATA)
 
 /*TODO: Features read only to implement*/
-#define EXT4_FEATURE_RO_COMPAT_SUPP
-                     EXT4_FEATURE_RO_COMPAT_BIGALLOC |\
-                     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\
-                     EXT4_FEATURE_RO_COMPAT_QUOTA)
+#define EXT4_SUPPORTED_FRO_COM
+                     EXT4_FRO_COM_BIGALLOC |\
+                     EXT4_FRO_COM_QUOTA)
 #endif
 
 struct ext4_fs {
@@ -383,7 +392,8 @@ struct ext4_inode {
                        uint16_t file_acl_high;
                        uint16_t uid_high;
                        uint16_t gid_high;
-                       uint32_t reserved2;
+                       uint16_t checksum_lo; /* crc32c(uuid+inum+inode) LE */
+                       uint16_t reserved2;
                } linux2;
                struct {
                        uint16_t reserved1;
@@ -395,7 +405,7 @@ struct ext4_inode {
        } __attribute__((packed)) osd2;
 
        uint16_t extra_isize;
-       uint16_t pad1;
+       uint16_t checksum_hi;   /* crc32c(uuid+inum+inode) BE */
        uint32_t ctime_extra; /* Extra change time (nsec << 2 | epoch) */
        uint32_t mtime_extra; /* Extra Modification time (nsec << 2 | epoch) */
        uint32_t atime_extra; /* Extra Access time (nsec << 2 | epoch) */
@@ -469,7 +479,9 @@ enum { EXT4_DIRENTRY_UNKNOWN = 0,
        EXT4_DIRENTRY_SOCK,
        EXT4_DIRENTRY_SYMLINK };
 
-union ext4_directory_entry_ll_internal {
+#define EXT4_DIRENTRY_DIR_CSUM 0xDE
+
+union ext4_dir_entry_ll_internal {
        uint8_t name_length_high; /* Higher 8 bits of name length */
        uint8_t inode_type;       /* Type of referenced inode (in rev >= 0.5) */
 } __attribute__((packed));
@@ -477,36 +489,36 @@ union ext4_directory_entry_ll_internal {
 /**
  * Linked list directory entry structure
  */
-struct ext4_directory_entry_ll {
+struct ext4_dir_entry_ll {
        uint32_t inode; /* I-node for the entry */
        uint16_t entry_length; /* Distance to the next directory entry */
        uint8_t name_length;   /* Lower 8 bits of name length */
 
-       union ext4_directory_entry_ll_internal in;
+       union ext4_dir_entry_ll_internal in;
 
        uint8_t name[EXT4_DIRECTORY_FILENAME_LEN]; /* Entry name */
 } __attribute__((packed));
 
-struct ext4_directory_iterator {
+struct ext4_dir_iterator {
        struct ext4_inode_ref *inode_ref;
        struct ext4_block current_block;
        uint64_t current_offset;
-       struct ext4_directory_entry_ll *current;
+       struct ext4_dir_entry_ll *current;
 };
 
-struct ext4_directory_search_result {
+struct ext4_dir_search_result {
        struct ext4_block block;
-       struct ext4_directory_entry_ll *dentry;
+       struct ext4_dir_entry_ll *dentry;
 };
 
 /* Structures for indexed directory */
 
-struct ext4_directory_dx_countlimit {
+struct ext4_dir_idx_countlimit {
        uint16_t limit;
        uint16_t count;
 };
 
-struct ext4_directory_dx_dot_entry {
+struct ext4_dir_idx_dot_entry {
        uint32_t inode;
        uint16_t entry_length;
        uint8_t name_length;
@@ -514,7 +526,7 @@ struct ext4_directory_dx_dot_entry {
        uint8_t name[4];
 };
 
-struct ext4_directory_dx_root_info {
+struct ext4_dir_idx_root_info {
        uint32_t reserved_zero;
        uint8_t hash_version;
        uint8_t info_length;
@@ -522,39 +534,72 @@ struct ext4_directory_dx_root_info {
        uint8_t unused_flags;
 };
 
-struct ext4_directory_dx_entry {
+struct ext4_dir_idx_entry {
        uint32_t hash;
        uint32_t block;
 };
 
-struct ext4_directory_dx_root {
-       struct ext4_directory_dx_dot_entry dots[2];
-       struct ext4_directory_dx_root_info info;
-       struct ext4_directory_dx_entry entries[];
+struct ext4_dir_idx_root {
+       struct ext4_dir_idx_dot_entry dots[2];
+       struct ext4_dir_idx_root_info info;
+       struct ext4_dir_idx_entry entries[];
 };
 
-struct ext4_fake_directory_entry {
+struct ext4_fake_dir_entry {
        uint32_t inode;
        uint16_t entry_length;
        uint8_t name_length;
        uint8_t inode_type;
 };
 
-struct ext4_directory_dx_node {
-       struct ext4_fake_directory_entry fake;
-       struct ext4_directory_dx_entry entries[];
+struct ext4_dir_idx_node {
+       struct ext4_fake_dir_entry fake;
+       struct ext4_dir_idx_entry entries[];
 };
 
-struct ext4_directory_dx_block {
+struct ext4_dir_idx_block {
        struct ext4_block block;
-       struct ext4_directory_dx_entry *entries;
-       struct ext4_directory_dx_entry *position;
+       struct ext4_dir_idx_entry *entries;
+       struct ext4_dir_idx_entry *position;
+};
+
+/*
+ * This goes at the end of each htree block.
+ */
+struct ext4_dir_idx_tail {
+       uint32_t reserved;
+       uint32_t checksum;      /* crc32c(uuid+inum+dirblock) */
 };
 
+/*
+ * This is a bogus directory entry at the end of each leaf block that
+ * records checksums.
+ */
+struct ext4_dir_entry_tail {
+       uint32_t reserved_zero1;        /* Pretend to be unused */
+       uint16_t rec_len;               /* 12 */
+       uint8_t reserved_zero2; /* Zero name length */
+       uint8_t reserved_ft;    /* 0xDE, fake file type */
+       uint32_t checksum;              /* crc32c(uuid+inum+dirblock) */
+};
+
+#define EXT4_DIRENT_TAIL(block, blocksize) \
+       ((struct ext4_dir_entry_tail *)(((char *)(block)) + ((blocksize) - \
+                                       sizeof(struct ext4_dir_entry_tail))))
+
 #define EXT4_ERR_BAD_DX_DIR (-25000)
 
 #define EXT4_LINK_MAX 65000
 
+#define EXT4_BAD_INO 1
+#define EXT4_ROOT_INO 2
+#define EXT4_BOOT_LOADER_INO 5
+#define EXT4_UNDEL_DIR_INO 6
+#define EXT4_RESIZE_INO 7
+#define EXT4_JOURNAL_INO 8
+
+#define EXT4_GOOD_OLD_FIRST_INO 11
+
 #define EXT4_EXT_UNWRITTEN_MASK (1L << 15)
 
 #define EXT4_EXT_MAX_LEN_WRITTEN (1L << 15)
@@ -573,6 +618,17 @@ struct ext4_directory_dx_block {
        ((ex)->block_count |= to_le16(EXT4_EXT_UNWRITTEN_MASK))
 #define EXT4_EXT_SET_WRITTEN(ex) \
        ((ex)->block_count &= ~(to_le16(EXT4_EXT_UNWRITTEN_MASK)))
+/*
+ * This is the extent tail on-disk structure.
+ * All other extent structures are 12 bytes long.  It turns out that
+ * block_size % 12 >= 4 for at least all powers of 2 greater than 512, which
+ * covers all valid ext4 block sizes.  Therefore, this tail structure can be
+ * crammed into the end of the block without having to rebalance the tree.
+ */
+struct ext4_extent_tail
+{
+       uint32_t et_checksum; /* crc32c(uuid+inum+extent_block) */
+};
 
 /*
  * This is the extent on-disk structure.
@@ -609,18 +665,34 @@ struct ext4_extent_header {
        uint16_t magic;
        uint16_t entries_count;     /* Number of valid entries */
        uint16_t max_entries_count; /* Capacity of store in entries */
-       uint16_t depth;             /* Has tree real underlying blocks? */
-       uint32_t generation;    /* generation of the tree */
+       uint16_t depth;             /* Has tree real underlying blocks? */
+       uint32_t generation;    /* generation of the tree */
 };
 
+
+/*
+ * Types of blocks.
+ */
+typedef uint32_t ext4_lblk_t;
+typedef uint64_t ext4_fsblk_t;
+
+/*
+ * Array of ext4_ext_path contains path to some extent.
+ * Creation/lookup routines use it for traversal/splitting/etc.
+ * Truncate uses it to simulate recursive walking.
+ */
 struct ext4_extent_path {
+       ext4_fsblk_t p_block;
        struct ext4_block block;
-       uint16_t depth;
+       int32_t depth;
+       int32_t maxdepth;
        struct ext4_extent_header *header;
        struct ext4_extent_index *index;
        struct ext4_extent *extent;
+
 };
 
+
 #define EXT4_EXTENT_MAGIC 0xF30A
 
 #define EXT4_EXTENT_FIRST(header)                                              \
@@ -631,6 +703,64 @@ struct ext4_extent_path {
        ((struct ext4_extent_index *)(((char *)(header)) +                     \
                                      sizeof(struct ext4_extent_header)))
 
+/*
+ * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
+ * initialized extent. This is 2^15 and not (2^16 - 1), since we use the
+ * MSB of ee_len field in the extent datastructure to signify if this
+ * particular extent is an initialized extent or an uninitialized (i.e.
+ * preallocated).
+ * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
+ * uninitialized extent.
+ * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
+ * uninitialized one. In other words, if MSB of ee_len is set, it is an
+ * uninitialized extent with only one special scenario when ee_len = 0x8000.
+ * In this case we can not have an uninitialized extent of zero length and
+ * thus we make it as a special case of initialized extent with 0x8000 length.
+ * This way we get better extent-to-group alignment for initialized extents.
+ * Hence, the maximum number of blocks we can have in an *initialized*
+ * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
+ */
+#define EXT_INIT_MAX_LEN (1L << 15)
+#define EXT_UNWRITTEN_MAX_LEN (EXT_INIT_MAX_LEN - 1)
+
+#define EXT_EXTENT_SIZE sizeof(struct ext4_extent)
+#define EXT_INDEX_SIZE sizeof(struct ext4_extent_idx)
+
+#define EXT_FIRST_EXTENT(__hdr__)                                              \
+       ((struct ext4_extent *)(((char *)(__hdr__)) +                          \
+                               sizeof(struct ext4_extent_header)))
+#define EXT_FIRST_INDEX(__hdr__)                                               \
+       ((struct ext4_extent_index *)(((char *)(__hdr__)) +                    \
+                                   sizeof(struct ext4_extent_header)))
+#define EXT_HAS_FREE_INDEX(__path__)                                           \
+       ((__path__)->header->entries_count < (__path__)->header->max_entries_count)
+#define EXT_LAST_EXTENT(__hdr__)                                               \
+       (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->entries_count - 1)
+#define EXT_LAST_INDEX(__hdr__)                                                \
+       (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->entries_count - 1)
+#define EXT_MAX_EXTENT(__hdr__)                                                \
+       (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->max_entries_count - 1)
+#define EXT_MAX_INDEX(__hdr__)                                                 \
+       (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->max_entries_count - 1)
+
+#define EXT4_EXTENT_TAIL_OFFSET(hdr)                                           \
+       (sizeof(struct ext4_extent_header) +                                   \
+        (sizeof(struct ext4_extent) * (hdr)->max_entries_count))
+
+/*
+ * ext4_ext_next_allocated_block:
+ * returns allocated block in subsequent extent or EXT_MAX_BLOCKS.
+ * NOTE: it considers block number from index entry as
+ * allocated block. Thus, index entries have to be consistent
+ * with leaves.
+ */
+#define EXT_MAX_BLOCKS (ext4_lblk_t) (-1)
+
+#define IN_RANGE(b, first, len)        ((b) >= (first) && (b) <= (first) + (len) - 1)
+
+
+/******************************************************************************/
+
 /* EXT3 HTree directory indexing */
 #define EXT2_HTREE_LEGACY 0
 #define EXT2_HTREE_HALF_MD4 1
@@ -691,6 +821,9 @@ struct ext4_xattr_entry {
 } __attribute__((packed));
 
 struct ext4_xattr_item {
+       /* This attribute should be stored in inode body */
+       bool in_inode;
+
        uint8_t name_index;
        char  *name;
        size_t name_len;
@@ -756,6 +889,9 @@ struct ext4_xattr_ref {
 
 /*****************************************************************************/
 
+#define EXT4_CRC32_INIT (0xFFFFFFFFUL)
+
+/*****************************************************************************/
 #ifdef CONFIG_BIG_ENDIAN
 static inline uint64_t to_le64(uint64_t n)
 {
@@ -801,6 +937,18 @@ static inline uint16_t to_le16(uint16_t n)
        (s, f, v) do { (s)->f = (v); }                                         \
        while (0)
 
+
+#ifdef __GNUC__
+#ifndef __unused
+#define __unused __attribute__ ((__unused__))
+#endif
+#endif
+
+#ifndef offsetof
+#define offsetof(type, field)          \
+       ((size_t)(&(((type *)0)->field)))
+#endif
+
 #endif /* EXT4_TYPES_H_ */
 
 /**