Skip to contentSkip to conversation

nilfs2: introduce xanode's entry related declarations

RFC PATCH In review Vyacheslav Dubeyko 1 participant 1 message Jan 10, 2014 NILFS2 filesystem

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 4/17 nilfs2: introduce xanode's entry related declarations

From: Vyacheslav Dubeyko <[email protected]>
Subject: [RFC][STEP 1][PATCH v2 04/17] nilfs2: introduce xanode's entry related declarations

This patch adds declaration of structures, macros and auxiliary functions for xanode's entries processing.

---
 fs/nilfs2/xafile.h |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
fs/nilfs2/xafile.h +97 -0
index 34e4bb9..cee7b03 100644
@@ -147,6 +147,20 @@ union nilfs_xattr_key {
 	nilfs_xattr_leaf_key leaf_key;
 };
 
+/*
+ * struct nilfs_xanode_entry - xanode's entry
+ * @name: xattr's name
+ * @value: xattr's value
+ * @value_hash: complex hash of xattr's value
+ */
+struct nilfs_xanode_entry {
+	union {
+		char name[0];
+		char value[0];
+		struct nilfs_xattr_value_hash value_hash;
+	} __packed;
+} __packed;
+
 /* Xanode related declarations */
 #define BH_DATA(bh) \
 	((char *)(((struct buffer_head *)(bh))->b_data))
@@ -320,4 +334,87 @@ NILFS_XANODE_LAST_NOT_INDEX_KEY(union nilfs_xanode_header *hdr_ptr)
 	BUG();
 }
 
+/* Entry related declarations */
+#define NILFS_XANODE_ENTRY_PTR(ptr) ((struct nilfs_xanode_entry *)(ptr))
+
+static inline
+__u16 NILFS_XANODE_ENTRY_OFFSET(union nilfs_xattr_key *key)
+{
+	if (IS_END_KEY(key))
+		return 0;
+
+	switch (NILFS_XANODE_KEY_TYPE(key)) {
+	case NILFS_XATTR_TREE_LEAF_KEY_TYPE:
+		return le16_to_cpu(key->leaf_key.entry_offset);
+	};
+	BUG();
+}
+
+static inline
+void NILFS_XANODE_ADD_ENTRY_OFFSET(__u16 val, union nilfs_xattr_key *key)
+{
+	switch (NILFS_XANODE_KEY_TYPE(key)) {
+	case NILFS_XATTR_TREE_LEAF_KEY_TYPE:
+		le16_add_cpu(&key->leaf_key.entry_offset, val);
+		return;
+	};
+	BUG();
+}
+
+#define NILFS_XATTR_ENTRY_OFFSET(hdr_ptr, entry_ptr) \
+	((char *)hdr_ptr + NILFS_XANODE_SIZE - (char *)entry_ptr)
+
+static inline
+__u16 NILFS_XANODE_ENTRY_SIZE(union nilfs_xattr_key *key)
+{
+	if (IS_END_KEY(key))
+		return 0;
+
+	switch (NILFS_XANODE_KEY_TYPE(key)) {
+	case NILFS_XATTR_TREE_LEAF_KEY_TYPE:
+		return le16_to_cpu(key->leaf_key.entry_size);
+	};
+	BUG();
+}
+
+#define NILFS_XATTR_ENTRY_SIZE(name, value_size) \
+	(strlen((const char *)(name)) + value_size)
+
+static inline
+struct nilfs_xattr_name_hash *NILFS_XANODE_NAME_HASH(union nilfs_xattr_key *key)
+{
+	switch (NILFS_XANODE_KEY_TYPE(key)) {
+	case NILFS_XATTR_TREE_LEAF_KEY_TYPE:
+		return &key->leaf_key.name_hash;
+	};
+	BUG();
+}
+
+#define NILFS_XANODE_ENTRY(key, hdr_ptr) \
+	(NILFS_XANODE_ENTRY_PTR((char *)(hdr_ptr) + \
+	 NILFS_XANODE_SIZE - NILFS_XANODE_ENTRY_OFFSET(key)))
+
+static inline
+struct nilfs_xanode_entry *
+NILFS_XANODE_LAST_ENTRY(union nilfs_xanode_header *hdr)
+{
+	switch (NILFS_XANODE_TYPE(hdr)) {
+	case NILFS_XATTR_TREE_XANODE_TYPE: {
+			nilfs_xattr_leaf_key *key;
+
+			key = NILFS_XANODE_LAST_LEAF_KEY(hdr);
+			if (IS_END_KEY(key))
+				return NILFS_XANODE_ENTRY_PTR((char *)(hdr) +
+							     NILFS_XANODE_SIZE);
+			else
+				return NILFS_XANODE_ENTRY(NILFS_XANODE_KEY(key),
+							  hdr);
+		}
+	};
+	BUG();
+}
+
+#define NILFS_XATTR_VALUE(entry, key) \
+	((char *)(entry) + NILFS_XANODE_NAME_HASH(key)->name_len)
+
 #endif /* _NILFS_XAFILE_H */
Signature · 8 lines
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html