4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
29 * lustre/include/lustre/libiam.h
31 * iam user level library
33 * Author: Wang Di <wangdi@clusterfs.com>
34 * Author: Nikita Danilov <nikita@clusterfs.com>
35 * Author: Fan Yong <fanyong@clusterfs.com>
39 #ifndef __IAM_ULIB_H__
40 #define __IAM_ULIB_H__
42 #define DX_FMT_NAME_LEN 16
44 #define IAM_LFIX_ROOT_MAGIC 0xbedabb1edULL
45 #define IAM_LVAR_ROOT_MAGIC 0xb01dfaceULL
48 IAM_LEAF_HEADER_MAGIC = 0x1976,
49 IAM_LVAR_LEAF_MAGIC = 0x1973,
50 IAM_IDLE_HEADER_MAGIC = 0x7903
58 struct dx_countlimit {
61 } __attribute__((packed));
63 struct iam_lfix_root {
65 u_int16_t ilr_keysize;
66 u_int16_t ilr_recsize;
67 u_int16_t ilr_ptrsize;
68 u_int8_t ilr_indirect_levels;
70 struct dx_countlimit limit;
71 u_int32_t idle_blocks;
72 u_int8_t ilr_paddingdd2[12];
73 unsigned char entries[0];
74 } __attribute__((packed));
76 struct iam_leaf_head {
79 } __attribute__((packed));
81 struct lvar_leaf_header {
82 u_int16_t vlh_magic; /* magic number IAM_LVAR_LEAF_MAGIC */
83 u_int16_t vlh_used; /* used bytes, including header */
84 } __attribute__((packed));
87 * Header structure to record idle blocks.
89 struct iam_idle_head {
91 __le16 iih_count; /* how many idle blocks in this head */
92 __le32 iih_next; /* next head for idle blocks */
94 } __attribute__((packed));
96 struct iam_index_head {
97 struct dx_countlimit limit;
98 u_int8_t paddingdd[16];
99 unsigned char entries[0];
100 } __attribute__((packed));
104 u_int16_t vr_recsize;
105 u_int16_t vr_ptrsize;
106 u_int8_t vr_indirect_levels;
107 u_int8_t vr_padding0;
108 u_int16_t vr_padding1;
109 } __attribute__((packed));
112 struct lvar_leaf_entry {
114 u_int16_t vle_keysize;
116 } __attribute__((packed));
118 struct osd_inode_id {
121 } __attribute__ ((packed));
126 LVAR_ROUND = LVAR_PAD - 1
129 static inline unsigned int node_limit(unsigned int node_gap,
130 unsigned int block_size,
133 return (block_size - node_gap) / size;
136 static inline unsigned int root_limit(unsigned int root_gap,
137 unsigned int node_gap,
138 unsigned int block_size,
143 limit = (block_size - root_gap) / size;
144 if (limit == node_limit(node_gap, block_size, size))
149 struct iam_uapi_info {
154 char iui_fmt_name[DX_FMT_NAME_LEN];
158 * Creat an iam file, but do NOT open it.
159 * Return 0 if success, else -1.
161 int iam_creat(char *filename, enum iam_fmt_t fmt,
162 int blocksize, int keysize, int recsize, int ptrsize);
165 * Open an iam file, but do NOT creat it if the file doesn't exist.
166 * Please use iam_creat for creating the file before use iam_open.
167 * Return file id (fd) if success, else -1.
169 int iam_open(char *filename, struct iam_uapi_info *ua);
172 * Close file opened by iam_open.
174 int iam_close(int fd);
177 * Please use iam_open before use this function.
179 int iam_insert(int fd, struct iam_uapi_info *ua, int key_need_convert,
180 char *keybuf, int rec_need_convert, char *recbuf);
183 * Please use iam_open before use this function.
185 int iam_lookup(int fd, struct iam_uapi_info *ua,
186 int key_need_convert, char *key_buf, int *keysize,
187 char *save_key, int rec_need_convert, char *rec_buf,
188 int *recsize, char *save_rec);
191 * Please use iam_open before use this function.
193 int iam_delete(int fd, struct iam_uapi_info *ua, int key_need_convert,
194 char *keybuf, int rec_need_convert, char *recbuf);
197 * Please use iam_open before use this function.
199 int iam_it_start(int fd, struct iam_uapi_info *ua, int key_need_convert,
200 char *key_buf, int *keysize, char *save_key,
201 int rec_need_convert, char *rec_buf, int *recsize,
205 * Please use iam_open before use this function.
207 int iam_it_next(int fd, struct iam_uapi_info *ua, int key_need_convert,
208 char *key_buf, int *keysize, char *save_key,
209 int rec_need_convert, char *rec_buf, int *recsize,
213 * Please use iam_open before use this function.
215 int iam_it_stop(int fd, struct iam_uapi_info *ua, int key_need_convert,
216 char *keybuf, int rec_need_convert, char *recbuf);
219 * Change iam file mode.
221 int iam_polymorph(char *filename, unsigned long mode);