1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
9 * This file is part of Lustre, http://www.lustre.org/
11 * iam user level library
13 * Author: Wang Di <wangdi@clusterfs.com>
14 * Author: Nikita Danilov <nikita@clusterfs.com>
15 * Author: Fan Yong <fanyong@clusterfs.com>
19 #ifndef __IAM_ULIB_H__
20 #define __IAM_ULIB_H__
22 #define DX_FMT_NAME_LEN 16
24 #define IAM_LFIX_ROOT_MAGIC 0xbedabb1edULL
25 #define IAM_LVAR_ROOT_MAGIC 0xb01dfaceULL
28 IAM_LEAF_HEADER_MAGIC = 0x1976,
29 IAM_LVAR_LEAF_MAGIC = 0x1973,
30 IAM_IDLE_HEADER_MAGIC = 0x7903
38 struct dx_countlimit {
41 } __attribute__((packed));
43 struct iam_lfix_root {
48 __u8 ilr_indirect_levels;
52 struct iam_leaf_head {
55 } __attribute__((packed));
57 struct lvar_leaf_header {
58 u_int16_t vlh_magic; /* magic number IAM_LVAR_LEAF_MAGIC */
59 u_int16_t vlh_used; /* used bytes, including header */
60 } __attribute__((packed));
63 * Header structure to record idle blocks.
65 struct iam_idle_head {
67 __le16 iih_count; /* how many idle blocks in this head */
68 __le32 iih_next; /* next head for idle blocks */
70 } __attribute__((packed));
72 struct iam_index_head {
73 struct dx_countlimit limit;
74 u_int8_t paddingdd[16];
75 unsigned char entries[];
76 } __attribute__((packed));
78 typedef __u32 lvar_hash_t;
84 u_int8_t vr_indirect_levels;
86 u_int16_t vr_padding1;
87 } __attribute__((packed));
90 struct lvar_leaf_entry {
92 u_int16_t vle_keysize;
94 } __attribute__((packed));
99 } __attribute__ ((packed));
104 LVAR_ROUND = LVAR_PAD - 1
107 static inline unsigned int node_limit(unsigned int node_gap,
108 unsigned int block_size,
111 return (block_size - node_gap) / size;
114 static inline unsigned int root_limit(unsigned int root_gap,
115 unsigned int node_gap,
116 unsigned int block_size,
121 limit = (block_size - root_gap) / size;
122 if (limit == node_limit(node_gap, block_size, size))
127 struct iam_uapi_info {
132 char iui_fmt_name[DX_FMT_NAME_LEN];
136 * Creat an iam file, but do NOT open it.
137 * Return 0 if success, else -1.
139 int iam_creat(char *filename, enum iam_fmt_t fmt,
140 int blocksize, int keysize, int recsize, int ptrsize);
143 * Open an iam file, but do NOT creat it if the file doesn't exist.
144 * Please use iam_creat for creating the file before use iam_open.
145 * Return file id (fd) if success, else -1.
147 int iam_open(char *filename, struct iam_uapi_info *ua);
150 * Close file opened by iam_open.
152 int iam_close(int fd);
155 * Please use iam_open before use this function.
157 int iam_insert(int fd, struct iam_uapi_info *ua, int key_need_convert,
158 char *keybuf, int rec_need_convert, char *recbuf);
161 * Please use iam_open before use this function.
163 int iam_lookup(int fd, struct iam_uapi_info *ua,
164 int key_need_convert, char *key_buf, int *keysize,
165 char *save_key, int rec_need_convert, char *rec_buf,
166 int *recsize, char *save_rec);
169 * Please use iam_open before use this function.
171 int iam_delete(int fd, struct iam_uapi_info *ua, int key_need_convert,
172 char *keybuf, int rec_need_convert, char *recbuf);
175 * Please use iam_open before use this function.
177 int iam_it_start(int fd, struct iam_uapi_info *ua, int key_need_convert,
178 char *key_buf, int *keysize, char *save_key,
179 int rec_need_convert, char *rec_buf, int *recsize,
183 * Please use iam_open before use this function.
185 int iam_it_next(int fd, struct iam_uapi_info *ua, int key_need_convert,
186 char *key_buf, int *keysize, char *save_key,
187 int rec_need_convert, char *rec_buf, int *recsize,
191 * Please use iam_open before use this function.
193 int iam_it_stop(int fd, struct iam_uapi_info *ua, int key_need_convert,
194 char *keybuf, int rec_need_convert, char *recbuf);
197 * Change iam file mode.
199 int iam_polymorph(char *filename, unsigned long mode);