1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2010 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#ifndef _FDB_ERRORS_H
19#define _FDB_ERRORS_H
20
21#include <stdint.h>
22#include <stddef.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
29 * Status values returned by calling ForestDB APIs.
30 */
31typedef enum {
32    /**
33     * ForestDB operation success.
34     */
35    FDB_RESULT_SUCCESS = 0,
36    /**
37     * Invalid parameters to ForestDB APIs.
38     */
39    FDB_RESULT_INVALID_ARGS = -1,
40    /**
41     * Database open operation fails.
42     */
43    FDB_RESULT_OPEN_FAIL = -2,
44    /**
45     * Database file not found.
46     */
47    FDB_RESULT_NO_SUCH_FILE = -3,
48    /**
49     * Database write operation fails.
50     */
51    FDB_RESULT_WRITE_FAIL = -4,
52    /**
53     * Database read operation fails.
54     */
55    FDB_RESULT_READ_FAIL = -5,
56    /**
57     * Database close operation fails.
58     */
59    FDB_RESULT_CLOSE_FAIL = -6,
60    /**
61     * Database commit operation fails.
62     */
63    FDB_RESULT_COMMIT_FAIL = -7,
64    /**
65     * Memory allocation fails.
66     */
67    FDB_RESULT_ALLOC_FAIL = -8,
68    /**
69     * A key not found in database.
70     */
71    FDB_RESULT_KEY_NOT_FOUND = -9,
72    /**
73     * Read-only access violation.
74     */
75    FDB_RESULT_RONLY_VIOLATION = -10,
76    /**
77     * Database compaction fails.
78     */
79    FDB_RESULT_COMPACTION_FAIL = -11,
80    /**
81     * Database iterator operation fails.
82     */
83    FDB_RESULT_ITERATOR_FAIL = -12,
84    /**
85     * ForestDB I/O seek failure.
86     */
87    FDB_RESULT_SEEK_FAIL = -13,
88    /**
89     * ForestDB I/O fsync failure.
90     */
91    FDB_RESULT_FSYNC_FAIL = -14,
92    /**
93     * ForestDB I/O checksum error.
94     */
95    FDB_RESULT_CHECKSUM_ERROR = -15,
96    /**
97     * ForestDB I/O file corruption.
98     */
99    FDB_RESULT_FILE_CORRUPTION = -16,
100    /**
101     * ForestDB I/O compression error.
102     */
103    FDB_RESULT_COMPRESSION_FAIL = -17,
104    /**
105     * A database instance with a given sequence number was not found.
106     */
107    FDB_RESULT_NO_DB_INSTANCE = -18,
108    /**
109     * Requested FDB operation failed as rollback is currently being executed.
110     */
111    FDB_RESULT_FAIL_BY_ROLLBACK = -19,
112    /**
113     * ForestDB config value is invalid.
114     */
115    FDB_RESULT_INVALID_CONFIG = -20,
116    /**
117     * Try to perform manual compaction when compaction daemon is enabled.
118     */
119    FDB_RESULT_MANUAL_COMPACTION_FAIL = -21,
120    /**
121     * Open a file with invalid compaction mode.
122     */
123    FDB_RESULT_INVALID_COMPACTION_MODE = -22,
124    /**
125     * Operation cannot be performed as file handle has not been closed.
126     */
127    FDB_RESULT_FILE_IS_BUSY = -23,
128    /**
129     * Database file remove operation fails.
130     */
131    FDB_RESULT_FILE_REMOVE_FAIL = -24,
132    /**
133     * Database file rename operation fails.
134     */
135    FDB_RESULT_FILE_RENAME_FAIL = -25,
136    /**
137     * Transaction operation fails.
138     */
139    FDB_RESULT_TRANSACTION_FAIL = -26,
140    /**
141     * Requested FDB operation failed due to active transactions.
142     */
143    FDB_RESULT_FAIL_BY_TRANSACTION = -27,
144    /**
145     * Requested FDB operation failed due to an active compaction task.
146     */
147    FDB_RESULT_FAIL_BY_COMPACTION = -28,
148    /**
149     * Filename is too long.
150     */
151    FDB_RESULT_TOO_LONG_FILENAME = -29,
152    /**
153     * Passed ForestDB handle is Invalid.
154     */
155    FDB_RESULT_INVALID_HANDLE = -30,
156    /**
157     * A KV store not found in database.
158     */
159    FDB_RESULT_KV_STORE_NOT_FOUND = -31,
160    /**
161     * There is an opened handle of the KV store.
162     */
163    FDB_RESULT_KV_STORE_BUSY = -32,
164    /**
165     * Same KV instance name already exists.
166     */
167    FDB_RESULT_INVALID_KV_INSTANCE_NAME = -33,
168    /**
169     * Custom compare function is assigned incorrectly.
170     */
171    FDB_RESULT_INVALID_CMP_FUNCTION = -34,
172    /**
173     * DB file can't be destroyed as the file is being compacted.
174     * Please retry in sometime.
175     */
176    FDB_RESULT_IN_USE_BY_COMPACTOR = -35,
177    /**
178     * DB file used in this operation has not been opened
179     */
180    FDB_RESULT_FILE_NOT_OPEN = -36,
181    /**
182     * Buffer cache is too big to be configured because it is greater than
183     * the physical memory available.
184     */
185    FDB_RESULT_TOO_BIG_BUFFER_CACHE = -37,
186    /**
187     * No commit headers in a database file.
188     */
189    FDB_RESULT_NO_DB_HEADERS = -38,
190    /**
191     * DB handle is being used by another thread. Forestdb handles must not be
192     * shared among multiple threads.
193     */
194    FDB_RESULT_HANDLE_BUSY = -39,
195    /**
196     * Asynchronous I/O is not supported in the current OS version.
197     */
198    FDB_RESULT_AIO_NOT_SUPPORTED = -40,
199    /**
200     * Asynchronous I/O init fails.
201     */
202    FDB_RESULT_AIO_INIT_FAIL = -41,
203    /**
204     * Asynchronous I/O submit fails.
205     */
206    FDB_RESULT_AIO_SUBMIT_FAIL = -42,
207    /**
208     * Fail to read asynchronous I/O events from the completion queue.
209     */
210    FDB_RESULT_AIO_GETEVENTS_FAIL = -43,
211    /**
212     * Error encrypting or decrypting data, or unsupported encryption algorithm.
213     */
214    FDB_RESULT_CRYPTO_ERROR = -44,
215    /**
216     * Compaction task is aborted due to compaction cancellation request
217     * from the application.
218     */
219    FDB_RESULT_COMPACTION_CANCELLATION = -45,
220    /**
221     * Fail to initialize superblock.
222     */
223    FDB_RESULT_SB_INIT_FAIL = -46,
224    /**
225     * Other writer interfered during superblock is being written. This happens when
226     * write operation is invoked before the initialization of the file.
227     */
228    FDB_RESULT_SB_RACE_CONDITION = -47,
229    /**
230     * Fail to read superblock.
231     */
232    FDB_RESULT_SB_READ_FAIL = -48,
233    /**
234     * Fail to read old version database file.
235     */
236    FDB_RESULT_FILE_VERSION_NOT_SUPPORTED = -49,
237
238
239    // All the error codes below correspond to errno values in Linux, OSX,
240    // and Windows, which can happen in file opeations.
241
242    /**
243     * EPERM errno
244     * A file operation is not permitted.
245     */
246    FDB_RESULT_EPERM = -50,
247    /**
248     * EIO errno
249     * A physical I/O error has occurred.
250     */
251    FDB_RESULT_EIO = -51,
252    /**
253     * ENXIO errno
254     * No such device or address error.
255     */
256    FDB_RESULT_ENXIO = -52,
257    /**
258     * EBADF errno
259     * Not a valid file descriptor.
260     */
261    FDB_RESULT_EBADF = -53,
262    /**
263     * ENOMEM errno
264     * Insufficient memory was available.
265     */
266    FDB_RESULT_ENOMEM = -54,
267    /**
268     * EACCES errno
269     * File access permission was denied.
270     */
271    FDB_RESULT_EACCESS = -55,
272    /**
273     * EFAULT errno
274     * Outside the process's accessible address space.
275     */
276    FDB_RESULT_EFAULT = -56,
277    /**
278     * EEXIST errno
279     * A file name already exists in the file system.
280     */
281    FDB_RESULT_EEXIST = -57,
282    /**
283     * ENODEV errno
284     * No corresponding device exists.
285     */
286    FDB_RESULT_ENODEV = -58,
287    /**
288     * ENOTDIR errno
289     * A directory component in a file path name is not a directory.
290     */
291    FDB_RESULT_ENOTDIR = -59,
292    /**
293     * EISDIR errno
294     * A file path name refers to a directory.
295     */
296    FDB_RESULT_EISDIR = -60,
297    /**
298     * EINVAL errno
299     * Arguments to a file operation are not valid.
300     */
301    FDB_RESULT_EINVAL = -61,
302    /**
303     * ENFILE errno
304     * The system-wide limit on the total number of open files has been reached.
305     */
306    FDB_RESULT_ENFILE = -62,
307    /**
308     * EMFILE errno
309     * The per-process limit on the number of open file descriptors has been reached.
310     */
311    FDB_RESULT_EMFILE = -63,
312    /**
313     * EFBIG errno
314     * A file is too large to be opened.
315     */
316    FDB_RESULT_EFBIG = -64,
317    /**
318     * ENOSPC errno
319     * No space left on device.
320     */
321    FDB_RESULT_ENOSPC = -65,
322    /**
323     * EROFS errno
324     * A file on a read-only filesystem and write access was requested.
325     */
326    FDB_RESULT_EROFS = -66,
327    /**
328     * EOPNOTSUPP errno
329     * A file operation is not supported.
330     */
331    FDB_RESULT_EOPNOTSUPP = -67,
332    /**
333     * ENOBUFS errno
334     * Insufficient buffer space was available in the system to perform a operation.
335     */
336    FDB_RESULT_ENOBUFS = -68,
337    /**
338     * ELOOP errno
339     * Too many symbolic links were encountered in resolving a file path name.
340     */
341    FDB_RESULT_ELOOP = -69,
342    /**
343     * ENAMETOOLONG errno
344     * A file path name was too long.
345     */
346    FDB_RESULT_ENAMETOOLONG = -70,
347    /**
348     * EOVERFLOW errno
349     * A file is too large to be opened.
350     */
351    FDB_RESULT_EOVERFLOW = -71,
352    /**
353     * EAGAIN errno
354     * Resource temporarily unavailable.
355     */
356    FDB_RESULT_EAGAIN = -72,
357    /**
358     * Recoverable error
359     * File found to be corrupted but will be recovered to a previous stable
360     * state.
361     */
362    FDB_RECOVERABLE_ERR = -73,
363    /**
364     * Nonrecoverable error
365     * Max number of recovery attempts have been tried.
366     */
367    FDB_NONRECOVERABLE_ERR = -74,
368
369    // Any new error codes can be added here.
370
371    FDB_RESULT_LAST = FDB_NONRECOVERABLE_ERR// Last (minimum) fdb_status value
372} fdb_status;
373
374#ifdef __cplusplus
375}
376#endif
377
378#endif
379