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
/
key.h
185 lines (162 loc) · 4.41 KB
/
key.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* SPDX-License-Identifier: GPL-2.0 */
/*
* linux/fs/apfs/key.h
*
* Copyright (C) 2018 Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
*/
#ifndef _APFS_KEY_H
#define _APFS_KEY_H
#include <linux/types.h>
struct super_block;
/*
* Structure of a key in an object map B-tree
*/
struct apfs_omap_key {
__le64 ok_oid;
__le64 ok_xid;
} __packed;
/* Catalog records types */
enum {
APFS_TYPE_ANY = 0,
APFS_TYPE_SNAP_METADATA = 1,
APFS_TYPE_EXTENT = 2,
APFS_TYPE_INODE = 3,
APFS_TYPE_XATTR = 4,
APFS_TYPE_SIBLING_LINK = 5,
APFS_TYPE_DSTREAM_ID = 6,
APFS_TYPE_CRYPTO_STATE = 7,
APFS_TYPE_FILE_EXTENT = 8,
APFS_TYPE_DIR_REC = 9,
APFS_TYPE_DIR_STATS = 10,
APFS_TYPE_SNAP_NAME = 11,
APFS_TYPE_SIBLING_MAP = 12,
APFS_TYPE_MAX_VALID = 12,
APFS_TYPE_MAX = 15,
APFS_TYPE_INVALID = 15,
};
/* Bit masks for the 'obj_id_and_type' field of a key header */
#define APFS_OBJ_ID_MASK 0x0fffffffffffffffULL
#define APFS_OBJ_TYPE_MASK 0xf000000000000000ULL
#define APFS_OBJ_TYPE_SHIFT 60
/* Key header for filesystem-object keys */
struct apfs_key_header {
__le64 obj_id_and_type;
} __packed;
/*
* Structure of the key for an inode record
*/
struct apfs_inode_key {
struct apfs_key_header hdr;
} __packed;
/*
* Structure of the key for a file extent record
*/
struct apfs_file_extent_key {
struct apfs_key_header hdr;
__le64 logical_addr;
} __packed;
/*
* Structure of the key for a data stream record
*/
struct apfs_dstream_id_key {
struct apfs_key_header hdr;
} __packed;
/* Bit masks for the 'name_len_and_hash' field of a directory entry */
#define APFS_DREC_LEN_MASK 0x000003ff
#define APFS_DREC_HASH_MASK 0xfffffc00
#define APFS_DREC_HASH_SHIFT 10
/* The name length in the catalog key counts the terminating null byte. */
#define APFS_NAME_LEN (APFS_DREC_LEN_MASK - 1)
/* Bit masks for the 'type' field of a directory entry */
enum {
APFS_DREC_TYPE_MASK = 0x000f,
APFS_DREC_RESERVED_10 = 0x0010
};
/*
* Structure of the key for a directory entry, including a precomputed
* hash of its name
*/
struct apfs_drec_hashed_key {
struct apfs_key_header hdr;
__le32 name_len_and_hash;
u8 name[0];
} __packed;
/*
* Structure of the key for an extended attributes record
*/
struct apfs_xattr_key {
struct apfs_key_header hdr;
__le16 name_len;
u8 name[0];
} __packed;
/*
* In-memory representation of a key, as relevant for a b-tree query.
*/
struct apfs_key {
u64 id;
u64 number; /* Extent offset, name hash or transaction id */
const char *name; /* On-disk name string */
u8 type; /* Record type (0 for the omap) */
};
/**
* apfs_init_omap_key - Initialize an in-memory key for an omap query
* @oid: object id
* @xid: latest transaction id
* @key: apfs_key structure to initialize
*/
static inline void apfs_init_omap_key(u64 oid, u64 xid, struct apfs_key *key)
{
key->id = oid;
key->type = 0;
key->number = xid;
key->name = NULL;
}
/**
* apfs_init_inode_key - Initialize an in-memory key for an inode query
* @ino: inode number
* @key: apfs_key structure to initialize
*/
static inline void apfs_init_inode_key(u64 ino, struct apfs_key *key)
{
key->id = ino;
key->type = APFS_TYPE_INODE;
key->number = 0;
key->name = NULL;
}
/**
* apfs_init_file_extent_key - Initialize an in-memory key for an extent query
* @id: extent id
* @offset: logical address (0 for a multiple query)
* @key: apfs_key structure to initialize
*/
static inline void apfs_init_file_extent_key(u64 id, u64 offset,
struct apfs_key *key)
{
key->id = id;
key->type = APFS_TYPE_FILE_EXTENT;
key->number = offset;
key->name = NULL;
}
extern void apfs_init_drec_hashed_key(struct super_block *sb, u64 ino,
const char *name, struct apfs_key *key);
/**
* apfs_init_xattr_key - Initialize an in-memory key for a xattr query
* @ino: inode number of the parent file
* @name: xattr name (NULL for a multiple query)
* @key: apfs_key structure to initialize
*/
static inline void apfs_init_xattr_key(u64 ino, const char *name,
struct apfs_key *key)
{
key->id = ino;
key->type = APFS_TYPE_XATTR;
key->number = 0;
key->name = name;
}
extern int apfs_filename_cmp(struct super_block *sb,
const char *name1, const char *name2);
extern int apfs_keycmp(struct super_block *sb,
struct apfs_key *k1, struct apfs_key *k2);
extern int apfs_read_cat_key(void *raw, int size, struct apfs_key *key);
extern int apfs_read_omap_key(void *raw, int size, struct apfs_key *key);
#endif /* _APFS_KEY_H */