meta_bg feature helper functions
[lwext4.git] / lwext4 / ext4_types.h
index 8d1502476e9f7fde1b5d422a830d16ce09f0f7b1..07727955e4d5cafa9d35f4c888adfafb14c2593f 100644 (file)
@@ -59,7 +59,7 @@ struct ext4_sblock {
     uint32_t free_inodes_count;         /* Free inodes count */
     uint32_t first_data_block;          /* First Data Block */
     uint32_t log_block_size;            /* Block size */
-    uint32_t log_frag_size;             /* Obsoleted fragment size */
+    uint32_t log_cluster_size;          /* Obsoleted fragment size */
     uint32_t blocks_per_group;          /* Number of blocks per group */
     uint32_t frags_per_group;           /* Obsoleted fragments per group */
     uint32_t inodes_per_group;          /* Number of inodes per group */
@@ -188,6 +188,7 @@ struct ext4_sblock {
 #define EXT4_FEATURE_COMPAT_RESIZE_INODE   0x0010
 #define EXT4_FEATURE_COMPAT_DIR_INDEX      0x0020
 
+
 /*
  * Read-only compatible features
  */
@@ -198,6 +199,9 @@ struct ext4_sblock {
 #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
 
 /*
  * Incompatible features
@@ -213,21 +217,83 @@ struct ext4_sblock {
 #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 */
+
+
+/*
+ * EXT2 supported feature set
+ */
+#define EXT2_FEATURE_COMPAT_SUPP    0x0000
+
+#define EXT2_FEATURE_INCOMPAT_SUPP                    \
+            (EXT4_FEATURE_INCOMPAT_FILETYPE         | \
+             EXT4_FEATURE_INCOMPAT_META_BG)
 
-#define EXT4_FEATURE_COMPAT_SUPP  (EXT4_FEATURE_COMPAT_DIR_INDEX)
+#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 EXT4_FEATURE_INCOMPAT_SUPP \
-        (EXT4_FEATURE_INCOMPAT_FILETYPE | \
-                EXT4_FEATURE_INCOMPAT_EXTENTS | \
-                EXT4_FEATURE_INCOMPAT_64BIT)
+/*
+ * EXT3 supported feature set
+ */
+#define EXT3_FEATURE_COMPAT_SUPP                      \
+            (EXT4_FEATURE_COMPAT_DIR_INDEX)
 
-#define EXT4_FEATURE_RO_COMPAT_SUPP \
-        (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
-                EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
-                EXT4_FEATURE_RO_COMPAT_HUGE_FILE | \
-                EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
-                EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \
-                EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
+#define EXT3_FEATURE_INCOMPAT_SUPP                    \
+            (EXT4_FEATURE_INCOMPAT_FILETYPE         | \
+             EXT4_FEATURE_INCOMPAT_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)
+
+/*
+ * EXT4 supported feature set
+ */
+#define EXT4_FEATURE_COMPAT_SUPP                      \
+            (EXT4_FEATURE_COMPAT_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_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)
+
+
+/*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
+
+#if 0
+/*TODO: Features incompatible to implement*/
+#define EXT4_FEATURE_INCOMPAT_SUPP
+                     (EXT4_FEATURE_INCOMPAT_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)
+#endif
 
 struct ext4_fs {
     struct ext4_blockdev*bdev;
@@ -255,7 +321,9 @@ struct ext4_bgroup {
     uint16_t free_inodes_count_lo;        /* Free inodes count */
     uint16_t used_dirs_count_lo;          /* Directories count */
     uint16_t flags;                       /* EXT4_BG_flags (INODE_UNINIT, etc) */
-    uint32_t reserved[2];                 /* Likely block/inode bitmap checksum */
+    uint32_t exclude_bitmap_lo;           /* Exclude bitmap for snapshots */
+       uint16_t block_bitmap_csum_lo;        /* crc32c(s_uuid+grp_num+bbitmap) LE */
+       uint16_t inode_bitmap_csum_lo;        /* crc32c(s_uuid+grp_num+ibitmap) LE */
     uint16_t itable_unused_lo;            /* Unused inodes count */
     uint16_t checksum;                    /* crc16(sb_uuid+group+desc) */
 
@@ -266,7 +334,10 @@ struct ext4_bgroup {
     uint16_t free_inodes_count_hi;        /* Free i-nodes count MSB */
     uint16_t used_dirs_count_hi;          /* Directories count MSB */
     uint16_t itable_unused_hi;            /* Unused inodes count MSB */
-    uint32_t reserved2[3];                /* Padding */
+    uint32_t exclude_bitmap_hi;           /* Exclude bitmap block MSB */
+       uint16_t block_bitmap_csum_hi;        /* crc32c(s_uuid+grp_num+bbitmap) BE */
+       uint16_t inode_bitmap_csum_hi;        /* crc32c(s_uuid+grp_num+ibitmap) BE */
+       uint32_t reserved;                    /* Padding */
 } ;
 
 struct ext4_block_group_ref {
@@ -403,6 +474,11 @@ struct ext4_inode_ref {
 #define EXT4_DIRECTORY_FILETYPE_SOCK      6
 #define EXT4_DIRECTORY_FILETYPE_SYMLINK   7
 
+union ext4_directory_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));
+
 /**
  * Linked list directory entry structure
  */
@@ -411,10 +487,7 @@ struct ext4_directory_entry_ll {
     uint16_t entry_length;  /* Distance to the next directory entry */
     uint8_t name_length;    /* Lower 8 bits of name length */
 
-    union {
-        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));
+    union ext4_directory_entry_ll_internal in;
 
     uint8_t name[EXT4_DIRECTORY_FILENAME_LEN];  /* Entry name */
 } __attribute__((packed)) ;
@@ -462,7 +535,7 @@ struct ext4_directory_dx_entry {
 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[0];
+    struct ext4_directory_dx_entry entries[];
 };
 
 struct ext4_fake_directory_entry {
@@ -474,7 +547,7 @@ struct ext4_fake_directory_entry {
 
 struct ext4_directory_dx_node {
     struct ext4_fake_directory_entry fake;
-    struct ext4_directory_dx_entry entries[0];
+    struct ext4_directory_dx_entry entries[];
 };
 
 struct ext4_directory_dx_block {
@@ -483,8 +556,9 @@ struct ext4_directory_dx_block {
     struct ext4_directory_dx_entry *position;
 } ;
 
-#define EXT4_ERR_BAD_DX_DIR       (-75000)
+#define EXT4_ERR_BAD_DX_DIR       (-25000)
 
+#define EXT4_LINK_MAX       65000
 
 /*
  * This is the extent on-disk structure.
@@ -536,10 +610,10 @@ struct ext4_extent_path {
 #define EXT4_EXTENT_MAGIC  0xF30A
 
 #define EXT4_EXTENT_FIRST(header) \
-        ((struct ext4_extent *) (((void *) (header)) + sizeof(struct ext4_extent_header)))
+        ((struct ext4_extent *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
 
 #define EXT4_EXTENT_FIRST_INDEX(header) \
-        ((struct ext4_extent_index *) (((void *) (header)) + sizeof(struct ext4_extent_header)))
+        ((struct ext4_extent_index *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
 
 
 /* EXT3 HTree directory indexing */
@@ -550,7 +624,7 @@ struct ext4_extent_path {
 #define EXT2_HTREE_HALF_MD4_UNSIGNED        4
 #define EXT2_HTREE_TEA_UNSIGNED             5
 
-#define EXT2_HTREE_EOF                      0x7FFFFFFF
+#define EXT2_HTREE_EOF                      0x7FFFFFFFUL
 
 
 struct ext4_hash_info {