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
|
/*
* Copyright (C) 2019 Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
*/
#ifndef _KEY_H
#define _KEY_H
#include <apfs/types.h>
struct super_block;
/*
* In-memory representation of a key, as relevant for a b-tree query.
*/
struct key {
u64 id;
u64 number; /* Extent offset or name hash */
const char *name; /* On-disk name string */
u8 type; /* Record type (0 for the omap) */
};
/**
* init_omap_key - Initialize an in-memory key for an omap query
* @oid: object id
* @xid: current transaction id
* @key: apfs_key structure to initialize
*/
static inline void init_omap_key(u64 oid, u64 xid, struct key *key)
{
key->id = oid;
key->type = 0;
key->number = xid;
key->name = NULL;
}
/**
* init_extref_key - Initialize an in-memory key for an extentref query
* @bno: first block number
* @key: apfs_key structure to initialize
*/
static inline void init_extref_key(u64 bno, struct key *key)
{
key->id = bno;
key->type = APFS_TYPE_EXTENT;
key->number = 0;
key->name = NULL;
}
/**
* init_fext_key - Initialize an in-memory key for a fext query
* @id: dstream id
* @addr: logical address
* @key: apfs_key structure to initialize
*/
static inline void init_fext_key(u64 id, u64 addr, struct key *key)
{
key->id = id;
key->type = 0;
key->number = addr;
key->name = NULL;
}
/**
* init_inode_key - Initialize an in-memory key for an inode query
* @ino: inode number
* @key: key structure to initialize
*/
static inline void init_inode_key(u64 ino, struct key *key)
{
key->id = ino;
key->type = APFS_TYPE_INODE;
key->number = 0;
key->name = NULL;
}
/**
* 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: key structure to initialize
*/
static inline void init_file_extent_key(u64 id, u64 offset, struct key *key)
{
key->id = id;
key->type = APFS_TYPE_FILE_EXTENT;
key->number = offset;
key->name = NULL;
}
/**
* 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: key structure to initialize
*/
static inline void init_xattr_key(u64 ino, const char *name, struct key *key)
{
key->id = ino;
key->type = APFS_TYPE_XATTR;
key->number = 0;
key->name = name;
}
/**
* cat_type - Read the record type of a catalog key
* @key: the raw catalog key
*
* The record type is stored in the last byte of the cnid field; this function
* returns that value.
*/
static inline int cat_type(struct apfs_key_header *key)
{
return (le64_to_cpu(key->obj_id_and_type) & APFS_OBJ_TYPE_MASK)
>> APFS_OBJ_TYPE_SHIFT;
}
/**
* cat_cnid - Read the cnid value on a catalog key
* @key: the raw catalog key
*
* The cnid value shares the its field with the record type. This function
* masks that part away and returns the result.
*/
static inline u64 cat_cnid(struct apfs_key_header *key)
{
return le64_to_cpu(key->obj_id_and_type) & APFS_OBJ_ID_MASK;
}
extern int keycmp(struct key *k1, struct key *k2);
extern void read_cat_key(void *raw, int size, struct key *key);
extern void read_omap_key(void *raw, int size, struct key *key);
extern void read_extentref_key(void *raw, int size, struct key *key);
extern void read_free_queue_key(void *raw, int size, struct key *key);
extern void read_snap_key(void *raw, int size, struct key *key);
extern void read_omap_snap_key(void *raw, int size, struct key *key);
extern void read_fext_key(void *raw, int size, struct key *key);
#endif /* _KEY_H */
|