This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnode.h
165 lines (142 loc) · 3.74 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* SPDX-License-Identifier: GPL-2.0 */
/*
* linux/fs/apfs/node.h
*
* Copyright (C) 2018 Ernesto A. Fernández <[email protected]>
*/
#ifndef _APFS_NODE_H
#define _APFS_NODE_H
#include <linux/kref.h>
#include <linux/types.h>
#include "object.h"
struct apfs_query;
/*
* On-disk representation of an object map
*/
struct apfs_omap_phys {
/*00*/ struct apfs_obj_phys om_o;
/*20*/ __le32 om_flags;
__le32 om_snap_count;
__le32 om_tree_type;
__le32 om_snapshot_tree_type;
/*30*/ __le64 om_tree_oid;
__le64 om_snapshot_tree_oid;
/*40*/ __le64 om_most_recent_snap;
__le64 om_pending_revert_min;
__le64 om_pending_revert_max;
} __packed;
/*
* Structure of a value in an object map B-tree
*/
struct apfs_omap_val {
__le32 ov_flags;
__le32 ov_size;
__le64 ov_paddr;
} __packed;
/* B-tree node flags */
#define APFS_BTNODE_ROOT 0x0001
#define APFS_BTNODE_LEAF 0x0002
#define APFS_BTNODE_FIXED_KV_SIZE 0x0004
#define APFS_BTNODE_CHECK_KOFF_INVAL 0x8000
/* B-tree location constants */
#define APFS_BTOFF_INVALID 0xffff
/*
* Structure storing a location inside a B-tree node
*/
struct apfs_nloc {
__le16 off;
__le16 len;
} __packed;
/*
* Structure storing the location of a key/value pair within a B-tree node
*/
struct apfs_kvloc {
struct apfs_nloc k;
struct apfs_nloc v;
} __packed;
/*
* Structure storing the location of a key/value pair within a B-tree node
* having fixed-size key and value (flag APFS_BTNODE_FIXED_KV_SIZE is present)
*/
struct apfs_kvoff {
__le16 k;
__le16 v;
} __packed;
/*
* On-disk representation of a B-tree node
*/
struct apfs_btree_node_phys {
/*00*/ struct apfs_obj_phys btn_o;
/*20*/ __le16 btn_flags;
__le16 btn_level;
__le32 btn_nkeys;
/*28*/ struct apfs_nloc btn_table_space;
struct apfs_nloc btn_free_space;
struct apfs_nloc btn_key_free_list;
struct apfs_nloc btn_val_free_list;
/*38*/ __le64 btn_data[];
} __packed;
/*
* Structure used to store information about a B-tree that won't change
* over time
*/
struct apfs_btree_info_fixed {
__le32 bt_flags;
__le32 bt_node_size;
__le32 bt_key_size;
__le32 bt_val_size;
} __packed;
/*
* Structure used to store information about a B-tree (located at the end of
* a B-tree root node block)
*/
struct apfs_btree_info {
struct apfs_btree_info_fixed bt_fixed;
__le32 bt_longest_key;
__le32 bt_longest_val;
__le64 bt_key_count;
__le64 bt_node_count;
} __packed;
/*
* In-memory representation of an APFS node
*/
struct apfs_node {
u16 flags; /* Node flags */
u32 records; /* Number of records in the node */
int key; /* Offset of the key area in the block */
int free; /* Offset of the free area in the block */
int data; /* Offset of the data area in the block */
struct apfs_object object; /* Object holding the node */
struct kref refcount;
};
/**
* apfs_node_is_leaf - Check if a b-tree node is a leaf
* @node: the node to check
*/
static inline bool apfs_node_is_leaf(struct apfs_node *node)
{
return (node->flags & APFS_BTNODE_LEAF) != 0;
}
/**
* apfs_node_is_root - Check if a b-tree node is the root
* @node: the node to check
*/
static inline bool apfs_node_is_root(struct apfs_node *node)
{
return (node->flags & APFS_BTNODE_ROOT) != 0;
}
/**
* apfs_node_has_fixed_kv_size - Check if a b-tree node has fixed key/value
* sizes
* @node: the node to check
*/
static inline bool apfs_node_has_fixed_kv_size(struct apfs_node *node)
{
return (node->flags & APFS_BTNODE_FIXED_KV_SIZE) != 0;
}
extern struct apfs_node *apfs_read_node(struct super_block *sb, u64 block);
extern int apfs_node_query(struct super_block *sb, struct apfs_query *query);
extern int apfs_bno_from_query(struct apfs_query *query, u64 *bno);
extern void apfs_node_get(struct apfs_node *node);
extern void apfs_node_put(struct apfs_node *node);
#endif /* _APFS_NODE_H */