Whamcloud - gitweb
e2fsck: add support for dirdata feature
[tools/e2fsprogs.git] / lib / ext2fs / ext2_fs.h
index d31891c..313f8e1 100644 (file)
@@ -238,6 +238,7 @@ struct ext2_dx_root_info {
 #define EXT2_HASH_LEGACY_UNSIGNED      3 /* reserved for userspace lib */
 #define EXT2_HASH_HALF_MD4_UNSIGNED    4 /* reserved for userspace lib */
 #define EXT2_HASH_TEA_UNSIGNED         5 /* reserved for userspace lib */
+#define EXT2_HASH_SIPHASH              6
 
 #define EXT2_HASH_FLAG_INCOMPAT        0x1
 
@@ -268,8 +269,7 @@ struct ext2_dx_tail {
 #define EXT2_MIN_DESC_SIZE_64BIT       64
 #define EXT2_MAX_DESC_SIZE             EXT2_MIN_BLOCK_SIZE
 #define EXT2_DESC_SIZE(s)                                                \
-       ((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \
-       (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
+       (ext2fs_has_feature_64bit(s) ? (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
 
 #define EXT2_BLOCKS_PER_GROUP(s)       (EXT2_SB(s)->s_blocks_per_group)
 #define EXT2_INODES_PER_GROUP(s)       (EXT2_SB(s)->s_inodes_per_group)
@@ -335,6 +335,7 @@ struct ext2_dx_tail {
 /* EXT4_EOFBLOCKS_FL 0x00400000 was here */
 #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
 #define EXT4_SNAPFILE_FL               0x01000000  /* Inode is a snapshot */
+#define FS_DAX_FL                      0x02000000 /* Inode is DAX */
 #define EXT4_SNAPFILE_DELETED_FL       0x04000000  /* Snapshot is being deleted */
 #define EXT4_SNAPFILE_SHRUNK_FL                0x08000000  /* Snapshot shrink has completed */
 #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data */
@@ -503,6 +504,12 @@ struct ext2_inode_large {
        (size >= (sizeof(((struct ext2_inode_large *)0)->field) + \
                  offsetof(struct ext2_inode_large, field)))
 
+#define EXT2_FITS_IN_INODE(inode, field)             \
+       ((offsetof(struct ext2_inode_large, field) +    \
+        sizeof((inode)->field)) <=                  \
+                        (EXT2_GOOD_OLD_INODE_SIZE +    \
+                         (inode)->i_extra_isize))      \
+
 #if defined(__KERNEL__) || defined(__linux__)
 #define i_reserved1    osd1.linux1.l_i_reserved1
 #define i_frag         osd2.linux2.l_i_frag
@@ -542,6 +549,7 @@ struct ext2_inode *EXT2_INODE(struct ext2_inode_large *large_inode)
 #define EXT2_VALID_FS                  0x0001  /* Unmounted cleanly */
 #define EXT2_ERROR_FS                  0x0002  /* Errors detected */
 #define EXT3_ORPHAN_FS                 0x0004  /* Orphans being recovered */
+#define EXT4_FC_REPLAY                 0x0020  /* Ext4 fast commit replay ongoing */
 
 /*
  * Misc. filesystem flags
@@ -742,7 +750,7 @@ struct ext2_super_block {
 /*200*/        __u8    s_mount_opts[64];       /* default mount options, no NUL? */
 /*240*/        __u32   s_usr_quota_inum;       /* inode number of user quota file */
        __u32   s_grp_quota_inum;       /* inode number of group quota file */
-       __u32   s_overhead_blocks;      /* overhead blocks/clusters in fs */
+       __u32   s_overhead_clusters;    /* overhead blocks/clusters in fs */
 /*24c*/        __u32   s_backup_bgs[2];        /* If sparse_super2 enabled */
 /*254*/        __u8    s_encrypt_algos[4];     /* Encryption algorithms in use  */
 /*258*/        __u8    s_encrypt_pw_salt[16];  /* Salt used for string2key algorithm */
@@ -755,7 +763,8 @@ struct ext2_super_block {
        __u8    s_lastcheck_hi;
        __u8    s_first_error_time_hi;
        __u8    s_last_error_time_hi;
-       __u8    s_pad[2];
+       __u8    s_first_error_errcode;
+       __u8    s_last_error_errcode;
 /*27c*/ __le16 s_encoding;             /* Filename charset encoding */
        __le16  s_encoding_flags;       /* Filename charset encoding flags */
        __le32  s_reserved[95];         /* Padding to the end of the block */
@@ -812,6 +821,7 @@ struct ext2_super_block {
 #define EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP     0x0100
 #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2      0x0200
 #define EXT4_FEATURE_COMPAT_FAST_COMMIT                0x0400
+#define EXT4_FEATURE_COMPAT_STABLE_INODES      0x0800
 
 
 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER    0x0001
@@ -914,6 +924,7 @@ EXT4_FEATURE_COMPAT_FUNCS(lazy_bg,          2, LAZY_BG)
 EXT4_FEATURE_COMPAT_FUNCS(exclude_bitmap,      2, EXCLUDE_BITMAP)
 EXT4_FEATURE_COMPAT_FUNCS(sparse_super2,       4, SPARSE_SUPER2)
 EXT4_FEATURE_COMPAT_FUNCS(fast_commit,         4, FAST_COMMIT)
+EXT4_FEATURE_COMPAT_FUNCS(stable_inodes,       4, STABLE_INODES)
 
 EXT4_FEATURE_RO_COMPAT_FUNCS(sparse_super,     2, SPARSE_SUPER)
 EXT4_FEATURE_RO_COMPAT_FUNCS(large_file,       2, LARGE_FILE)
@@ -952,12 +963,14 @@ EXT4_FEATURE_INCOMPAT_FUNCS(casefold,             4, CASEFOLD)
 #define EXT2_FEATURE_INCOMPAT_SUPP    (EXT2_FEATURE_INCOMPAT_FILETYPE| \
                                       EXT4_FEATURE_INCOMPAT_MMP| \
                                       EXT4_FEATURE_INCOMPAT_LARGEDIR| \
-                                      EXT4_FEATURE_INCOMPAT_EA_INODE)
+                                      EXT4_FEATURE_INCOMPAT_EA_INODE| \
+                                      EXT4_FEATURE_INCOMPAT_DIRDATA)
 #define EXT2_FEATURE_RO_COMPAT_SUPP    (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
                                         EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
                                         EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \
                                         EXT2_FEATURE_RO_COMPAT_BTREE_DIR| \
-                                        EXT4_FEATURE_RO_COMPAT_VERITY)
+                                        EXT4_FEATURE_RO_COMPAT_VERITY| \
+                                        EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
 
 /*
  * Default values for user and/or group using reserved blocks
@@ -982,6 +995,12 @@ EXT4_FEATURE_INCOMPAT_FUNCS(casefold,              4, CASEFOLD)
 #define EXT4_DEFM_DISCARD      0x0400
 #define EXT4_DEFM_NODELALLOC   0x0800
 
+static inline int ext4_hash_in_dirent(const struct ext2_inode *inode)
+{
+       return (inode->i_flags & EXT4_ENCRYPT_FL) &&
+               (inode->i_flags & EXT4_CASEFOLD_FL);
+}
+
 /*
  * Structure of a directory entry
  */
@@ -1017,6 +1036,25 @@ struct ext2_dir_entry_2 {
 };
 
 /*
+ * Hashes for ext4_dir_entry for casefolded and ecrypted directories.
+ * This is located at the first 4 bit aligned location after the name.
+ */
+
+struct ext2_dir_entry_hash {
+       __le32 hash;
+       __le32 minor_hash;
+};
+
+#define EXT2_DIRENT_HASHES(entry) \
+       ((struct ext2_dir_entry_hash *) &entry->name[\
+               (ext2fs_dirent_name_len(entry) + \
+                       EXT2_DIR_ROUND) & ~EXT2_DIR_ROUND])
+#define EXT2_DIRENT_HASH(entry) \
+               ext2fs_le32_to_cpu(EXT2_DIRENT_HASHES(entry)->hash)
+#define EXT2_DIRENT_MINOR_HASH(entry) \
+               ext2fs_le32_to_cpu(EXT2_DIRENT_HASHES(entry)->minor_hash)
+
+/*
  * This is a bogus directory entry at the end of each leaf block that
  * records checksums.
  */
@@ -1041,6 +1079,7 @@ struct ext2_dir_entry_tail {
 #define EXT2_FT_SYMLINK                7
 
 #define EXT2_FT_MAX            8
+#define EXT2_FT_MASK           0x0f
 
 /*
  * Annoyingly, e2fsprogs always swab16s ext2_dir_entry.name_len, so we
@@ -1050,18 +1089,50 @@ struct ext2_dir_entry_tail {
  */
 #define EXT2_DIR_NAME_LEN_CSUM 0xDE00
 
+int ext2_get_dirdata_field_size(struct ext2_dir_entry *de, char dirdata_flags);
+int ext2_get_dirdata_size(struct ext2_dir_entry *de);
+
 /*
  * EXT2_DIR_PAD defines the directory entries boundaries
  *
  * NOTE: It must be a multiple of 4
  */
 #define EXT2_DIR_ENTRY_HEADER_LEN      8
+#define EXT2_DIR_ENTRY_HASH_LEN                8
 #define EXT2_DIR_PAD                   4
 #define EXT2_DIR_ROUND                 (EXT2_DIR_PAD - 1)
-#define EXT2_DIR_REC_LEN(name_len)     (((name_len) + \
+#define EXT2_DIR_NAME_LEN(name_len)    (((name_len) + \
                                          EXT2_DIR_ENTRY_HEADER_LEN + \
                                          EXT2_DIR_ROUND) & \
                                         ~EXT2_DIR_ROUND)
+#define EXT2_DIR_REC_LEN(de)   (EXT2_DIR_NAME_LEN(((de)->name_len &         \
+                                                    EXT2_NAME_LEN) +         \
+                                                   ext2_get_dirdata_size(de)))
+
+static inline unsigned int ext2fs_dir_rec_len(__u8 name_len,
+                                               int extended)
+{
+       int rec_len = (name_len + EXT2_DIR_ENTRY_HEADER_LEN + EXT2_DIR_ROUND);
+
+       rec_len &= ~EXT2_DIR_ROUND;
+       if (extended)
+               rec_len += EXT2_DIR_ENTRY_HASH_LEN;
+       return rec_len;
+}
+
+static inline unsigned int ext2fs_dirdata_rec_len(struct ext2_dir_entry *de,
+                                               int extended)
+{
+       int rec_len = EXT2_DIR_REC_LEN(de);
+
+       if (extended)
+               rec_len += EXT2_DIR_ENTRY_HASH_LEN;
+       return rec_len;
+}
+
+/* lu_fid size and NUL char */
+#define EXT2_DIRENT_LUFID_SIZE         16
+#define EXT2_DIRENT_LUFID              0x10
 
 /*
  * Constants for ext4's extended time encoding
@@ -1135,4 +1206,6 @@ struct mmp_struct {
 
 #define EXT4_ENC_STRICT_MODE_FL                        (1 << 0) /* Reject invalid sequences */
 
+#define EXT2_NEXT_DIRENT(d)    ((void *)((char *)(d) + (d)->rec_len))
+
 #endif /* _LINUX_EXT2_FS_H */