]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/tokyocabinet/tchdb.h
ebl Add tokyocabinet source to bacula
[bacula/bacula] / bacula / src / lib / tokyocabinet / tchdb.h
1 /*************************************************************************************************
2  * The hash database API of Tokyo Cabinet
3  *                                                      Copyright (C) 2006-2008 Mikio Hirabayashi
4  * This file is part of Tokyo Cabinet.
5  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
6  * the GNU Lesser General Public License as published by the Free Software Foundation; either
7  * version 2.1 of the License or any later version.  Tokyo Cabinet is distributed in the hope
8  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
10  * License for more details.
11  * You should have received a copy of the GNU Lesser General Public License along with Tokyo
12  * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
13  * Boston, MA 02111-1307 USA.
14  *************************************************************************************************/
15
16
17 #ifndef _TCHDB_H                         /* duplication check */
18 #define _TCHDB_H
19
20 #if defined(__cplusplus)
21 #define __TCHDB_CLINKAGEBEGIN extern "C" {
22 #define __TCHDB_CLINKAGEEND }
23 #else
24 #define __TCHDB_CLINKAGEBEGIN
25 #define __TCHDB_CLINKAGEEND
26 #endif
27 __TCHDB_CLINKAGEBEGIN
28
29
30 #include <stdlib.h>
31 #include <stdbool.h>
32 #include <stdint.h>
33 #include <time.h>
34 #include <tcutil.h>
35
36
37
38 /*************************************************************************************************
39  * API
40  *************************************************************************************************/
41
42
43 typedef struct {                         /* type of structure for a hash database */
44   void *mmtx;                            /* mutex for method */
45   void *dmtx;                            /* mutex for DRP */
46   void *eckey;                           /* key for thread specific error code */
47   uint8_t type;                          /* database type */
48   uint8_t flags;                         /* additional flags */
49   uint64_t bnum;                         /* number of the bucket array */
50   uint8_t apow;                          /* power of record alignment */
51   uint8_t fpow;                          /* power of free block pool number */
52   uint8_t opts;                          /* options */
53   char *path;                            /* path of the database file */
54   int fd;                                /* file descriptor of the database file */
55   uint32_t omode;                        /* connection mode */
56   uint64_t rnum;                         /* number of the records */
57   uint64_t fsiz;                         /* size of the database file */
58   uint64_t frec;                         /* offset of the first record */
59   uint64_t lrec;                         /* offset of the last record */
60   uint64_t iter;                         /* offset of the iterator */
61   char *map;                             /* pointer to the mapped memory */
62   uint64_t msiz;                         /* size of the mapped memory */
63   uint32_t *ba32;                        /* 32-bit bucket array */
64   uint64_t *ba64;                        /* 64-bit bucket array */
65   uint32_t align;                        /* record alignment */
66   uint32_t runit;                        /* record reading unit */
67   bool zmode;                            /* whether compression is used */
68   int32_t fbpmax;                        /* maximum number of the free block pool */
69   int32_t fbpsiz;                        /* size of the free block pool */
70   void *fbpool;                          /* free block pool */
71   int32_t fbpnum;                        /* number of the free block pool */
72   int32_t fbpmis;                        /* number of missing retrieval of the free block pool */
73   bool async;                            /* whether asynchronous storing is called */
74   TCXSTR *drpool;                        /* delayed record pool */
75   TCXSTR *drpdef;                        /* deferred records of the delayed record pool */
76   uint64_t drpoff;                       /* offset of the delayed record pool */
77   TCMDB *recc;                           /* cache for records */
78   uint32_t rcnum;                        /* max number of cached records */
79   int ecode;                             /* last happened error code */
80   bool fatal;                            /* whether a fatal error occured */
81   uint64_t inode;                        /* inode number */
82   time_t mtime;                          /* modification time */
83   int dbgfd;                             /* file descriptor for debugging */
84   int64_t cnt_writerec;                  /* tesing counter for record write times */
85   int64_t cnt_reuserec;                  /* tesing counter for record reuse times */
86   int64_t cnt_moverec;                   /* tesing counter for record move times */
87   int64_t cnt_readrec;                   /* tesing counter for record read times */
88   int64_t cnt_searchfbp;                 /* tesing counter for FBP search times */
89   int64_t cnt_insertfbp;                 /* tesing counter for FBP insert times */
90   int64_t cnt_splicefbp;                 /* tesing counter for FBP splice times */
91   int64_t cnt_dividefbp;                 /* tesing counter for FBP divide times */
92   int64_t cnt_mergefbp;                  /* tesing counter for FBP merge times */
93   int64_t cnt_reducefbp;                 /* tesing counter for FBP reduce times */
94   int64_t cnt_appenddrp;                 /* tesing counter for DRP append times */
95   int64_t cnt_deferdrp;                  /* tesing counter for DRP defer times */
96   int64_t cnt_flushdrp;                  /* tesing counter for DRP flush times */
97   int64_t cnt_adjrecc;                   /* tesing counter for record cache adjust times */
98 } TCHDB;
99
100 enum {                                   /* enumeration for error codes */
101   TCESUCCESS,                            /* success */
102   TCETHREAD,                             /* threading error */
103   TCEINVALID,                            /* invalid operation */
104   TCENOFILE,                             /* file not found */
105   TCENOPERM,                             /* no permission */
106   TCEMETA,                               /* invalid meta data */
107   TCERHEAD,                              /* invalid record header */
108   TCEOPEN,                               /* open error */
109   TCECLOSE,                              /* close error */
110   TCETRUNC,                              /* trunc error */
111   TCESYNC,                               /* sync error */
112   TCESTAT,                               /* stat error */
113   TCESEEK,                               /* seek error */
114   TCEREAD,                               /* read error */
115   TCEWRITE,                              /* write error */
116   TCEMMAP,                               /* mmap error */
117   TCELOCK,                               /* lock error */
118   TCEUNLINK,                             /* unlink error */
119   TCERENAME,                             /* rename error */
120   TCEMKDIR,                              /* mkdir error */
121   TCERMDIR,                              /* rmdir error */
122   TCEKEEP,                               /* existing record */
123   TCENOREC,                              /* no record found */
124   TCEMISC = 9999                         /* miscellaneous error */
125 };
126
127 enum {                                   /* enumeration for database type */
128   HDBTHASH,                              /* hash table */
129   HDBTBTREE                              /* B+ tree */
130 };
131
132 enum {                                   /* enumeration for additional flags */
133   HDBFOPEN = 1 << 0,                     /* whether opened */
134   HDBFFATAL = 1 << 1                     /* whetehr with fatal error */
135 };
136
137 enum {                                   /* enumeration for tuning options */
138   HDBTLARGE = 1 << 0,                    /* use 64-bit bucket array */
139   HDBTDEFLATE = 1 << 1,                  /* compress each record with Deflate */
140   HDBTTCBS = 1 << 2                      /* compress each record with TCBS */
141 };
142
143 enum {                                   /* enumeration for open modes */
144   HDBOREADER = 1 << 0,                   /* open as a reader */
145   HDBOWRITER = 1 << 1,                   /* open as a writer */
146   HDBOCREAT = 1 << 2,                    /* writer creating */
147   HDBOTRUNC = 1 << 3,                    /* writer truncating */
148   HDBONOLCK = 1 << 4,                    /* open without locking */
149   HDBOLCKNB = 1 << 5                     /* lock without blocking */
150 };
151
152
153 /* Get the message string corresponding to an error code.
154    `ecode' specifies the error code.
155    The return value is the message string of the error code. */
156 const char *tchdberrmsg(int ecode);
157
158
159 /* Create a hash database object.
160    The return value is the new hash database object. */
161 TCHDB *tchdbnew(void);
162
163
164 /* Delete a hash database object.
165    `hdb' specifies the hash database object.
166    If the database is not closed, it is closed implicitly.  Note that the deleted object and its
167    derivatives can not be used anymore. */
168 void tchdbdel(TCHDB *hdb);
169
170
171 /* Get the last happened error code of a hash database object.
172    `hdb' specifies the hash database object.
173    The return value is the last happened error code.
174    The following error code is defined: `TCESUCCESS' for success, `TCETHREAD' for threading
175    error, `TCEINVALID' for invalid operation, `TCENOFILE' for file not found, `TCENOPERM' for no
176    permission, `TCEMETA' for invalid meta data, `TCERHEAD' for invalid record header, `TCEOPEN'
177    for open error, `TCECLOSE' for close error, `TCETRUNC' for trunc error, `TCESYNC' for sync
178    error, `TCESTAT' for stat error, `TCESEEK' for seek error, `TCEREAD' for read error,
179    `TCEWRITE' for write error, `TCEMMAP' for mmap error, `TCELOCK' for lock error, `TCEUNLINK'
180    for unlink error, `TCERENAME' for rename error, `TCEMKDIR' for mkdir error, `TCERMDIR' for
181    rmdir error, `TCEKEEP' for existing record, `TCENOREC' for no record found, and `TCEMISC' for
182    miscellaneous error. */
183 int tchdbecode(TCHDB *hdb);
184
185
186 /* Set mutual exclusion control of a hash database object for threading.
187    `hdb' specifies the hash database object which is not opened.
188    If successful, the return value is true, else, it is false.
189    Note that the mutual exclusion control is needed if the object is shared by plural threads and
190    this function should should be called before the database is opened. */
191 bool tchdbsetmutex(TCHDB *hdb);
192
193
194 /* Set the tuning parameters of a hash database object.
195    `hdb' specifies the hash database object which is not opened.
196    `bnum' specifies the number of elements of the bucket array.  If it is not more than 0, the
197    default value is specified.  The default value is 16381.  Suggested size of the bucket array
198    is about from 0.5 to 4 times of the number of all records to be stored.
199    `apow' specifies the size of record alignment by power of 2.  If it is negative, the default
200    value is specified.  The default value is 4 standing for 2^4=16.
201    `fpow' specifies the maximum number of elements of the free block pool by power of 2.  If it
202    is negative, the default value is specified.  The default value is 10 standing for 2^10=1024.
203    `opts' specifies options by bitwise or: `HDBTLARGE' specifies that the size of the database
204    can be larger than 2GB by using 64-bit bucket array, `HDBTDEFLATE' specifies that each record
205    is compressed with Deflate encoding, `HDBTTCBS' specifies that each record is compressed with
206    TCBS encoding.
207    If successful, the return value is true, else, it is false.
208    Note that the tuning parameters should be set before the database is opened. */
209 bool tchdbtune(TCHDB *hdb, int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);
210
211
212 /* Set the caching parameters of a hash database object.
213    `hdb' specifies the hash database object which is not opened.
214    `rcnum' specifies the maximum number of records to be cached.  If it is not more than 0, the
215    record cache is disabled.  It is disabled by default.
216    If successful, the return value is true, else, it is false.
217    Note that the caching parameters should be set before the database is opened. */
218 bool tchdbsetcache(TCHDB *hdb, int32_t rcnum);
219
220
221 /* Open a database file and connect a hash database object.
222    `hdb' specifies the hash database object which is not opened.
223    `path' specifies the path of the database file.
224    `omode' specifies the connection mode: `HDBOWRITER' as a writer, `HDBOREADER' as a reader.
225    If the mode is `HDBOWRITER', the following may be added by bitwise or: `HDBOCREAT', which
226    means it creates a new database if not exist, `HDBOTRUNC', which means it creates a new
227    database regardless if one exists.  Both of `HDBOREADER' and `HDBOWRITER' can be added to by
228    bitwise or: `HDBONOLCK', which means it opens the database file without file locking, or
229    `HDBOLCKNB', which means locking is performed without blocking.
230    If successful, the return value is true, else, it is false. */
231 bool tchdbopen(TCHDB *hdb, const char *path, int omode);
232
233
234 /* Close a hash database object.
235    `hdb' specifies the hash database object.
236    If successful, the return value is true, else, it is false.
237    Update of a database is assured to be written when the database is closed.  If a writer opens
238    a database but does not close it appropriately, the database will be broken. */
239 bool tchdbclose(TCHDB *hdb);
240
241
242 /* Store a record into a hash database object.
243    `hdb' specifies the hash database object connected as a writer.
244    `kbuf' specifies the pointer to the region of the key.
245    `ksiz' specifies the size of the region of the key.
246    `vbuf' specifies the pointer to the region of the value.
247    `vsiz' specifies the size of the region of the value.
248    If successful, the return value is true, else, it is false.
249    If a record with the same key exists in the database, it is overwritten. */
250 bool tchdbput(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
251
252
253 /* Store a string record into a hash database object.
254    `hdb' specifies the hash database object connected as a writer.
255    `kstr' specifies the string of the key.
256    `vstr' specifies the string of the value.
257    If successful, the return value is true, else, it is false.
258    If a record with the same key exists in the database, it is overwritten. */
259 bool tchdbput2(TCHDB *hdb, const char *kstr, const char *vstr);
260
261
262 /* Store a new record into a hash database object.
263    `hdb' specifies the hash database object connected as a writer.
264    `kbuf' specifies the pointer to the region of the key.
265    `ksiz' specifies the size of the region of the key.
266    `vbuf' specifies the pointer to the region of the value.
267    `vsiz' specifies the size of the region of the value.
268    If successful, the return value is true, else, it is false.
269    If a record with the same key exists in the database, this function has no effect. */
270 bool tchdbputkeep(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
271
272
273 /* Store a new string record into a hash database object.
274    `hdb' specifies the hash database object connected as a writer.
275    `kstr' specifies the string of the key.
276    `vstr' specifies the string of the value.
277    If successful, the return value is true, else, it is false.
278    If a record with the same key exists in the database, this function has no effect. */
279 bool tchdbputkeep2(TCHDB *hdb, const char *kstr, const char *vstr);
280
281
282 /* Concatenate a value at the end of the existing record in a hash database object.
283    `hdb' specifies the hash database object connected as a writer.
284    `kbuf' specifies the pointer to the region of the key.
285    `ksiz' specifies the size of the region of the key.
286    `vbuf' specifies the pointer to the region of the value.
287    `vsiz' specifies the size of the region of the value.
288    If successful, the return value is true, else, it is false.
289    If there is no corresponding record, a new record is created. */
290 bool tchdbputcat(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
291
292
293 /* Concatenate a string value at the end of the existing record in a hash database object.
294    `hdb' specifies the hash database object connected as a writer.
295    `kstr' specifies the string of the key.
296    `vstr' specifies the string of the value.
297    If successful, the return value is true, else, it is false.
298    If there is no corresponding record, a new record is created. */
299 bool tchdbputcat2(TCHDB *hdb, const char *kstr, const char *vstr);
300
301
302 /* Store a record into a hash database object in asynchronous fashion.
303    `hdb' specifies the hash database object connected as a writer.
304    `kbuf' specifies the pointer to the region of the key.
305    `ksiz' specifies the size of the region of the key.
306    `vbuf' specifies the pointer to the region of the value.
307    `vsiz' specifies the size of the region of the value.
308    If successful, the return value is true, else, it is false.
309    If a record with the same key exists in the database, it is overwritten.  Records passed to
310    this function are accumulated into the inner buffer and wrote into the file at a blast. */
311 bool tchdbputasync(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
312
313
314 /* Store a string record into a hash database object in asynchronous fashion.
315    `hdb' specifies the hash database object connected as a writer.
316    `kstr' specifies the string of the key.
317    `vstr' specifies the string of the value.
318    If successful, the return value is true, else, it is false.
319    If a record with the same key exists in the database, it is overwritten.  Records passed to
320    this function are accumulated into the inner buffer and wrote into the file at a blast. */
321 bool tchdbputasync2(TCHDB *hdb, const char *kstr, const char *vstr);
322
323
324 /* Remove a record of a hash database object.
325    `hdb' specifies the hash database object connected as a writer.
326    `kbuf' specifies the pointer to the region of the key.
327    `ksiz' specifies the size of the region of the key.
328    If successful, the return value is true, else, it is false. */
329 bool tchdbout(TCHDB *hdb, const void *kbuf, int ksiz);
330
331
332 /* Remove a string record of a hash database object.
333    `hdb' specifies the hash database object connected as a writer.
334    `kstr' specifies the string of the key.
335    If successful, the return value is true, else, it is false. */
336 bool tchdbout2(TCHDB *hdb, const char *kstr);
337
338
339 /* Retrieve a record in a hash database object.
340    `hdb' specifies the hash database object.
341    `kbuf' specifies the pointer to the region of the key.
342    `ksiz' specifies the size of the region of the key.
343    `sp' specifies the pointer to the variable into which the size of the region of the return
344    value is assigned.
345    If successful, the return value is the pointer to the region of the value of the corresponding
346    record.  `NULL' is returned if no record corresponds.
347    Because an additional zero code is appended at the end of the region of the return value,
348    the return value can be treated as a character string.  Because the region of the return
349    value is allocated with the `malloc' call, it should be released with the `free' call when
350    it is no longer in use. */
351 void *tchdbget(TCHDB *hdb, const void *kbuf, int ksiz, int *sp);
352
353
354 /* Retrieve a string record in a hash database object.
355    `hdb' specifies the hash database object.
356    `kstr' specifies the string of the key.
357    If successful, the return value is the string of the value of the corresponding record.
358    `NULL' is returned if no record corresponds.
359    Because the region of the return value is allocated with the `malloc' call, it should be
360    released with the `free' call when it is no longer in use. */
361 char *tchdbget2(TCHDB *hdb, const char *kstr);
362
363
364 /* Retrieve a record in a hash database object and write the value into a buffer.
365    `hdb' specifies the hash database object.
366    `kbuf' specifies the pointer to the region of the key.
367    `ksiz' specifies the size of the region of the key.
368    `vbuf' specifies the pointer to the buffer into which the value of the corresponding record is
369    written.
370    `max' specifies the size of the buffer.
371    If successful, the return value is the size of the written data, else, it is -1.  -1 is
372    returned if no record corresponds to the specified key.
373    Note that an additional zero code is not appended at the end of the region of the writing
374    buffer. */
375 int tchdbget3(TCHDB *hdb, const void *kbuf, int ksiz, void *vbuf, int max);
376
377
378 /* Get the size of the value of a record in a hash database object.
379    `hdb' specifies the hash database object.
380    `kbuf' specifies the pointer to the region of the key.
381    `ksiz' specifies the size of the region of the key.
382    If successful, the return value is the size of the value of the corresponding record, else,
383    it is -1. */
384 int tchdbvsiz(TCHDB *hdb, const void *kbuf, int ksiz);
385
386
387 /* Get the size of the value of a string record in a hash database object.
388    `hdb' specifies the hash database object.
389    `kstr' specifies the string of the key.
390    If successful, the return value is the size of the value of the corresponding record, else,
391    it is -1. */
392 int tchdbvsiz2(TCHDB *hdb, const char *kstr);
393
394
395 /* Initialize the iterator of a hash database object.
396    `hdb' specifies the hash database object.
397    If successful, the return value is true, else, it is false.
398    The iterator is used in order to access the key of every record stored in a database. */
399 bool tchdbiterinit(TCHDB *hdb);
400
401
402 /* Get the next key of the iterator of a hash database object.
403    `hdb' specifies the hash database object.
404    `sp' specifies the pointer to the variable into which the size of the region of the return
405    value is assigned.
406    If successful, the return value is the pointer to the region of the next key, else, it is
407    `NULL'.  `NULL' is returned when no record is to be get out of the iterator.
408    Because an additional zero code is appended at the end of the region of the return value, the
409    return value can be treated as a character string.  Because the region of the return value is
410    allocated with the `malloc' call, it should be released with the `free' call when it is no
411    longer in use.  It is possible to access every record by iteration of calling this function.
412    It is allowed to update or remove records whose keys are fetched while the iteration.
413    However, it is not assured if updating the database is occurred while the iteration.  Besides,
414    the order of this traversal access method is arbitrary, so it is not assured that the order of
415    storing matches the one of the traversal access. */
416 void *tchdbiternext(TCHDB *hdb, int *sp);
417
418
419 /* Get the next key string of the iterator of a hash database object.
420    `hdb' specifies the hash database object.
421    If successful, the return value is the string of the next key, else, it is `NULL'.  `NULL' is
422    returned when no record is to be get out of the iterator.
423    Because the region of the return value is allocated with the `malloc' call, it should be
424    released with the `free' call when it is no longer in use.  It is possible to access every
425    record by iteration of calling this function.  However, it is not assured if updating the
426    database is occurred while the iteration.  Besides, the order of this traversal access method
427    is arbitrary, so it is not assured that the order of storing matches the one of the traversal
428    access. */
429 char *tchdbiternext2(TCHDB *hdb);
430
431
432 /* Get the next extensible objects of the iterator of a hash database object.
433    `hdb' specifies the hash database object.
434    `kxstr' specifies the object into which the next key is wrote down.
435    `vxstr' specifies the object into which the next value is wrote down.
436    If successful, the return value is true, else, it is false.  False is returned when no record
437    is to be get out of the iterator. */
438 bool tchdbiternext3(TCHDB *hdb, TCXSTR *kxstr, TCXSTR *vxstr);
439
440
441 /* Get forward matching keys in a hash database object.
442    `hdb' specifies the hash database object.
443    `pbuf' specifies the pointer to the region of the prefix.
444    `psiz' specifies the size of the region of the prefix.
445    `max' specifies the maximum number of keys to be fetched.  If it is negative, no limit is
446    specified.
447    The return value is a list object of the corresponding keys.  This function does never fail
448    and return an empty list even if no key corresponds.
449    Because the object of the return value is created with the function `tclistnew', it should be
450    deleted with the function `tclistdel' when it is no longer in use.  Note that this function
451    may be very slow because every key in the database is scanned. */
452 TCLIST *tchdbfwmkeys(TCHDB *hdb, const void *pbuf, int psiz, int max);
453
454
455 /* Get forward matching string keys in a hash database object.
456    `hdb' specifies the hash database object.
457    `pstr' specifies the string of the prefix.
458    `max' specifies the maximum number of keys to be fetched.  If it is negative, no limit is
459    specified.
460    The return value is a list object of the corresponding keys.  This function does never fail
461    and return an empty list even if no key corresponds.
462    Because the object of the return value is created with the function `tclistnew', it should be
463    deleted with the function `tclistdel' when it is no longer in use.  Note that this function
464    may be very slow because every key in the database is scanned. */
465 TCLIST *tchdbfwmkeys2(TCHDB *hdb, const char *pstr, int max);
466
467
468 /* Synchronize updated contents of a hash database object with the file and the device.
469    `hdb' specifies the hash database object connected as a writer.
470    If successful, the return value is true, else, it is false.
471    This function is useful when another process connects the same database file. */
472 bool tchdbsync(TCHDB *hdb);
473
474
475 /* Optimize the file of a hash database object.
476    `hdb' specifies the hash database object connected as a writer.
477    `bnum' specifies the number of elements of the bucket array.  If it is not more than 0, the
478    default value is specified.  The default value is two times of the number of records.
479    `apow' specifies the size of record alignment by power of 2.  If it is negative, the current
480    setting is not changed.
481    `fpow' specifies the maximum number of elements of the free block pool by power of 2.  If it
482    is negative, the current setting is not changed.
483    `opts' specifies options by bitwise or: `HDBTLARGE' specifies that the size of the database
484    can be larger than 2GB by using 64-bit bucket array, `HDBTDEFLATE' specifies that each record
485    is compressed with Deflate encoding, `HDBTTCBS' specifies that each record is compressed with
486    TCBS encoding.  If it is `UINT8_MAX', the current setting is not changed.
487    If successful, the return value is true, else, it is false.
488    This function is useful to reduce the size of the database file with data fragmentation by
489    successive updating. */
490 bool tchdboptimize(TCHDB *hdb, int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);
491
492
493 /* Remove all records of a hash database object.
494    `hdb' specifies the hash database object connected as a writer.
495    If successful, the return value is true, else, it is false. */
496 bool tchdbvanish(TCHDB *hdb);
497
498
499 /* Copy the database file of a hash database object.
500    `hdb' specifies the hash database object.
501    `path' specifies the path of the destination file.  If it begins with `@', the trailing
502    substring is executed as a command line.
503    If successful, the return value is true, else, it is false.  False is returned if the executed
504    command returns non-zero code.
505    The database file is assured to be kept synchronized and not modified while the copying or
506    executing operation is in progress.  So, this function is useful to create a backup file of
507    the database file. */
508 bool tchdbcopy(TCHDB *hdb, const char *path);
509
510
511 /* Get the file path of a hash database object.
512    `hdb' specifies the hash database object.
513    The return value is the path of the database file or `NULL' if the object does not connect to
514    any database file. */
515 const char *tchdbpath(TCHDB *hdb);
516
517
518 /* Get the number of records of a hash database object.
519    `hdb' specifies the hash database object.
520    The return value is the number of records or 0 if the object does not connect to any database
521    file. */
522 uint64_t tchdbrnum(TCHDB *hdb);
523
524
525 /* Get the size of the database file of a hash database object.
526    `hdb' specifies the hash database object.
527    The return value is the size of the database file or 0 if the object does not connect to any
528    database file. */
529 uint64_t tchdbfsiz(TCHDB *hdb);
530
531
532
533 /*************************************************************************************************
534  * features for experts
535  *************************************************************************************************/
536
537
538 /* Set the error code of a hash database object.
539    `hdb' specifies the hash database object.
540    `ecode' specifies the error code.
541    `file' specifies the file name of the code.
542    `line' specifies the line number of the code.
543    `func' specifies the function name of the code. */
544 void tchdbsetecode(TCHDB *hdb, int ecode, const char *filename, int line, const char *func);
545
546
547 /* Set the type of a hash database object.
548    `hdb' specifies the hash database object.
549    `type' specifies the database type. */
550 void tchdbsettype(TCHDB *hdb, uint8_t type);
551
552
553 /* Set the file descriptor for debugging output.
554    `hdb' specifies the hash database object.
555    `fd' specifies the file descriptor for debugging output. */
556 void tchdbsetdbgfd(TCHDB *hdb, int fd);
557
558
559 /* Get the file descriptor for debugging output.
560    `hdb' specifies the hash database object.
561    The return value is the file descriptor for debugging output. */
562 int tchdbdbgfd(TCHDB *hdb);
563
564
565 /* Synchronize updating contents on memory.
566    `hdb' specifies the hash database object connected as a writer.
567    `phys' specifies whether to synchronize physically.
568    If successful, the return value is true, else, it is false. */
569 bool tchdbmemsync(TCHDB *hdb, bool phys);
570
571
572 /* Get the number of elements of the bucket array of a hash database object.
573    `hdb' specifies the hash database object.
574    The return value is the number of elements of the bucket array or 0 if the object does not
575    connect to any database file. */
576 uint64_t tchdbbnum(TCHDB *hdb);
577
578
579 /* Get the record alignment of a hash database object.
580    `hdb' specifies the hash database object.
581    The return value is the record alignment or 0 if the object does not connect to any database
582    file. */
583 uint32_t tchdbalign(TCHDB *hdb);
584
585
586 /* Get the maximum number of the free block pool of a a hash database object.
587    `hdb' specifies the hash database object.
588    The return value is the maximum number of the free block pool or 0 if the object does not
589    connect to any database file. */
590 uint32_t tchdbfbpmax(TCHDB *hdb);
591
592
593 /* Get the inode number of the database file of a hash database object.
594    `hdb' specifies the hash database object.
595    The return value is the inode number of the database file or 0 the object does not connect to
596    any database file. */
597 uint64_t tchdbinode(TCHDB *hdb);
598
599
600 /* Get the modification time of the database file of a hash database object.
601    `hdb' specifies the hash database object.
602    The return value is the inode number of the database file or 0 the object does not connect to
603    any database file. */
604 time_t tchdbmtime(TCHDB *hdb);
605
606
607 /* Get the connection mode of a hash database object.
608    `hdb' specifies the hash database object.
609    The return value is the connection mode. */
610 int tchdbomode(TCHDB *hdb);
611
612
613 /* Get the database type of a hash database object.
614    `hdb' specifies the hash database object.
615    The return value is the database type. */
616 uint8_t tchdbtype(TCHDB *hdb);
617
618
619 /* Get the additional flags of a hash database object.
620    `hdb' specifies the hash database object.
621    The return value is the additional flags. */
622 uint8_t tchdbflags(TCHDB *hdb);
623
624
625 /* Get the options of a hash database object.
626    `hdb' specifies the hash database object.
627    The return value is the options. */
628 uint8_t tchdbopts(TCHDB *hdb);
629
630
631 /* Get the pointer to the opaque field of a hash database object.
632    `hdb' specifies the hash database object.
633    The return value is the pointer to the opaque field whose size is 128 bytes. */
634 char *tchdbopaque(TCHDB *hdb);
635
636
637 /* Get the number of used elements of the bucket array of a hash database object.
638    `hdb' specifies the hash database object.
639    The return value is the number of used elements of the bucket array or 0 if the object does not
640    connect to any database file. */
641 uint64_t tchdbbnumused(TCHDB *hdb);
642
643
644
645 __TCHDB_CLINKAGEEND
646 #endif                                   /* duplication check */
647
648
649 /* END OF FILE */