diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-07-19 18:35:18 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-07-19 18:35:18 +0300 |
commit | 1aedc2c9df369f8683b2ba78b17c677996a2d815 (patch) | |
tree | b18c2fbe8cae5ee40b18f638ab627d241ddf1453 /doc | |
parent | 85f1e72da83e3078e2ae1f78093ef0966e43cec1 (diff) | |
download | gdbm-1aedc2c9df369f8683b2ba78b17c677996a2d815.tar.gz gdbm-1aedc2c9df369f8683b2ba78b17c677996a2d815.tar.bz2 |
Improve docs. Minor changes.
* NEWS: Document new features.
* doc/gdbm.texi: Likewise.
* src/gdbm.h.in (gdbm_last_errno): Fix return value.
(gdbm_check_syserr): New proto.
* src/gdbmdefs.h (gdbm_file_info) <last_error>: Fix data type.
* src/gdbmerrno.c (gdbm_last_errno): Fix return value.
(gdbm_check_syserr): New function.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/gdbm.texi | 229 |
1 files changed, 223 insertions, 6 deletions
diff --git a/doc/gdbm.texi b/doc/gdbm.texi index c823ee9..866a672 100644 --- a/doc/gdbm.texi +++ b/doc/gdbm.texi | |||
@@ -109,7 +109,8 @@ Functions: | |||
109 | * Reorganization:: Database reorganization. | 109 | * Reorganization:: Database reorganization. |
110 | * Sync:: Insure all writes to disk have competed. | 110 | * Sync:: Insure all writes to disk have competed. |
111 | * Flat files:: Export and import to Flat file format. | 111 | * Flat files:: Export and import to Flat file format. |
112 | * Errors:: Convert internal error codes into English. | 112 | * Errors:: Error handling. |
113 | * Recovery:: Recovery from fatal errors. | ||
113 | * Options:: Setting internal options. | 114 | * Options:: Setting internal options. |
114 | * Locking:: File locking. | 115 | * Locking:: File locking. |
115 | * Variables:: Useful global variables. | 116 | * Variables:: Useful global variables. |
@@ -343,6 +344,22 @@ In all of the following calls, the parameter @var{dbf} refers to the pointer | |||
343 | returned from @code{gdbm_open}. | 344 | returned from @code{gdbm_open}. |
344 | @end deftypefn | 345 | @end deftypefn |
345 | 346 | ||
347 | @deftypefn {gdbm interface} GDBM_FILE gdbm_fd_open (int @var{fd},@ | ||
348 | const char *@var{name}, int @var{block_size}, @ | ||
349 | int @var{flags}, int @var{mode}, void (*fatal_func)(const char *)) | ||
350 | |||
351 | Alternative function for opening a GDBM database. The @var{fd} | ||
352 | argument is the file descriptor of the database file obtained by a | ||
353 | call to @code{open}(2), @code{creat}(2) or similar funcionss. The | ||
354 | descriptor is not dup'ed, and will be closed when the returned | ||
355 | GDBM_FILE is closed. Use @code{dup}(2) if that is not desirable. | ||
356 | @end deftypefn | ||
357 | |||
358 | @deftypefn {gdbm interface} int gdbm_copy_meta (GDBM_FILE @var{dst},@ | ||
359 | GDBM_FILE @var{src}) | ||
360 | Copy file ownership and mode from @var{src} to @var{dst}. | ||
361 | @end deftypefn | ||
362 | |||
346 | @node Close | 363 | @node Close |
347 | @chapter Closing the database. | 364 | @chapter Closing the database. |
348 | @cindex closing database | 365 | @cindex closing database |
@@ -918,19 +935,204 @@ gdbm_load_from_file (@var{dbf}, @var{fp}, @var{flag}, 0, NULL); | |||
918 | @end deftypefn | 935 | @end deftypefn |
919 | 936 | ||
920 | @node Errors | 937 | @node Errors |
921 | @chapter Error strings. | 938 | @chapter Error handling. |
939 | @cindex gdbm_errno | ||
922 | @cindex error strings | 940 | @cindex error strings |
941 | @cindex global error state | ||
942 | The global variable @code{gdbm_errno} (@pxref{Variables, gdbm_errno}) | ||
943 | keeps the error code of the most recent error encountered by GDBM | ||
944 | functions. | ||
923 | 945 | ||
924 | To convert a @code{gdbm} error code into English text, use this | 946 | To convert this code to human-readable string, use the following function: |
925 | routine: | ||
926 | 947 | ||
927 | @deftypefn {gdbm interface} {const char *} gdbm_strerror (gdbm_error @var{errno}) | 948 | @deftypefn {gdbm interface} {const char *} gdbm_strerror (gdbm_error @var{errno}) |
928 | Converts @var{errno} (which is an integer value) into a human-readable | 949 | Converts @var{errno} (which is an integer value) into a human-readable |
929 | descriptive text. Returns a pointer to a static string. The caller | 950 | descriptive text. Returns a pointer to a static string. The caller |
930 | must not alter or free the returned pointer. | 951 | must not alter or free the returned pointer. |
952 | @end deftypefn | ||
953 | |||
954 | Detailed information about the most recent error that occurred while | ||
955 | operating on a GDBM file is stored in the @code{GDBM_FILE} object | ||
956 | itself. To retrieve it, the following functions are provided: | ||
931 | 957 | ||
932 | The @var{errno} argument is usually the value of the global variable | 958 | @cindex error code, most recent |
933 | @code{gdbm_errno}. @xref{Variables, gdbm_errno}. | 959 | @cindex most recent error code |
960 | @deftypefn {gdbm interface} {gdbm_error} gdbm_last_errno (GDBM_FILE @var{dbf}) | ||
961 | Returns the code of the most recent error encountered when operating | ||
962 | on @var{dbf}. | ||
963 | @end deftypefn | ||
964 | |||
965 | @deftypefn {gdbm interface} {int} gdbm_last_syserr (GDBM_FILE @var{dbf}) | ||
966 | Returns the value of the system @code{errno} variable associated with | ||
967 | the most recent error. | ||
968 | |||
969 | Notice, that not all GDBM errors have an associated system error | ||
970 | code. The following are the ones that have: | ||
971 | |||
972 | @itemize @bullet | ||
973 | @item GDBM_FILE_OPEN_ERROR | ||
974 | @item GDBM_FILE_WRITE_ERROR | ||
975 | @item GDBM_FILE_SEEK_ERROR | ||
976 | @item GDBM_FILE_READ_ERROR | ||
977 | @item GDBM_FILE_STAT_ERROR | ||
978 | @item GDBM_BACKUP_FAILED | ||
979 | @end itemize | ||
980 | |||
981 | For other errors, @code{gdbm_last_syserr} will return 0. | ||
982 | @end deftypefn | ||
983 | |||
984 | @anchor{gdbm_check_syserr} | ||
985 | @deftypefn {gdbm interface} {int} gdbm_check_syserr (gdbm_errno @var{err}) | ||
986 | Returns @code{1}, if system errno value should be checked to get more | ||
987 | info on the error described by GDBM code @var{err}. | ||
988 | @end deftypefn | ||
989 | |||
990 | To get a human-readable description of the recent error for a | ||
991 | particular database file, use the @code{gdbm_db_strerror} function: | ||
992 | |||
993 | @deftypefn {gdbm interface} {const char *} gdbm_db_strerror (GDBM_FILE @var{dbf}) | ||
994 | Returns textual description of the most recent error encountered when | ||
995 | operating on the database @var{dbf}. The resulting string is often | ||
996 | more informative than what would be returned by | ||
997 | @samp{gdbm_strerror(gdbm_last_errno(@var{dbf}))}. In particular, if | ||
998 | there is a system error associated with the recent failure, it will be | ||
999 | described as well. | ||
1000 | @end deftypefn | ||
1001 | |||
1002 | @deftypefn {gdbm interface} void gdbm_clear_error (GDBM_FILE @var{dbf}) | ||
1003 | Clears the error state for the database @var{dbf}. Normally, this | ||
1004 | function is called upon the entry to any GDBM function. | ||
1005 | @end deftypefn | ||
1006 | |||
1007 | Certain errors (such as write error when saving stored key) can leave | ||
1008 | database file in inconistent state. When such a critical error | ||
1009 | occurs, the database file is marked as needing recovery. Subsequent | ||
1010 | calls to any GDBM functions for that database file (except | ||
1011 | @code{gdbm_recover}), will return immediately with GDBM error value | ||
1012 | @code{GDBM_NEED_RECOVERY}. Additionally, the following | ||
1013 | function can be used to check the state of the database file: | ||
1014 | |||
1015 | @deftypefn {gdbm interface} int gdbm_needs_recovery (GDBM_FILE @var{dbf}) | ||
1016 | Returns @code{1} if the database file @var{dbf} is in inconsistent | ||
1017 | state and needs recovery. | ||
1018 | @end deftypefn | ||
1019 | |||
1020 | The only way to bring the database back to operational state is to | ||
1021 | call the @code{gdbm_recover} function (@pxref{Recovery}). | ||
1022 | |||
1023 | @node Recovery | ||
1024 | @chapter Recovery | ||
1025 | |||
1026 | Certain errors (such as write error when saving stored key) can leave | ||
1027 | database file in @dfn{inconistent state}. When such a critical error | ||
1028 | occurs, the database file is marked as needing recovery. Subsequent | ||
1029 | calls to any GDBM functions for that database file (except | ||
1030 | @code{gdbm_recover}), will return immediately with GDBM error value | ||
1031 | @code{GDBM_NEED_RECOVERY}. | ||
1032 | |||
1033 | To escape from this state and bring the database back to operational | ||
1034 | state, use the following function: | ||
1035 | |||
1036 | @deftypefn {gdbm interface} int gdbm_recover (GDBM_FILE @var{dbf},@ | ||
1037 | gdbm_recovery *@var{rcvr}, int @var{flags}) | ||
1038 | Check the database file @var{dbf} and fix eventual errors. The | ||
1039 | @var{rcvr} argument points to a structure that has @dfn{input | ||
1040 | members}, providing additional information to alter the behavior of | ||
1041 | @code{gdbm_recover}, and @dfn{output members}, used to return | ||
1042 | additional statistics about the recovery process (@var{rcvr} can be | ||
1043 | @code{NULL} if no such information is needed). | ||
1044 | |||
1045 | Each input member has a corresponding flag bit, which must be set in | ||
1046 | the @var{flags} in order to instruct the function to use it. | ||
1047 | |||
1048 | The @code{gdbm_recover} type is defined as: | ||
1049 | |||
1050 | @example | ||
1051 | typedef struct gdbm_recovery_s | ||
1052 | @{ | ||
1053 | /* Input members. | ||
1054 | These are initialized before call to gdbm_recover. | ||
1055 | The flags argument specifies which of them are initialized. */ | ||
1056 | void (*errfun) (void *data, char const *fmt, ...); | ||
1057 | void *data; | ||
1058 | size_t max_failed_keys; | ||
1059 | size_t max_failed_buckets; | ||
1060 | size_t max_failures; | ||
1061 | |||
1062 | /* Output members. | ||
1063 | The gdbm_recover function fills these before returning. */ | ||
1064 | size_t recovered_keys; | ||
1065 | size_t recovered_buckets; | ||
1066 | size_t failed_keys; | ||
1067 | size_t failed_buckets; | ||
1068 | char *backup_name; | ||
1069 | @} gdbm_recovery; | ||
1070 | @end example | ||
1071 | |||
1072 | The @dfn{input members} modify the behavior of @code{gdbm_recover}: | ||
1073 | |||
1074 | @deftypeop {input member} gdbm_recovery void (*errfun) (void *@var{data},@ | ||
1075 | char const *@var{fmt}, ...) | ||
1076 | @kwindex GDBM_RCVR_ERRFUN | ||
1077 | If the @code{GDBM_RCVR_ERRFUN} flag bit is set, @code{errfun} points | ||
1078 | to a function that will be called upon each recoverable or non-fatal | ||
1079 | error that occurred during the recovery. | ||
1080 | @end deftypeop | ||
1081 | |||
1082 | @deftypecv {input member} gdbm_recovery {void *} data | ||
1083 | Supplies first argument for the @code{errfun} invocations. | ||
1084 | @end deftypecv | ||
1085 | |||
1086 | @deftypecv {input member} gdbm_recovery size_t max_failed_keys | ||
1087 | @kwindex GDBM_RCVR_MAX_FAILED_KEYS | ||
1088 | If @code{GDBM_RCVR_MAX_FAILED_KEYS} is set, this member sets the limit | ||
1089 | on the number of keys that cannot be retrieved. If the number of | ||
1090 | failed keys grows bigger than @code{max_failed_keys}, recovery is | ||
1091 | aborted and error is returned. | ||
1092 | @end deftypecv | ||
1093 | |||
1094 | @deftypecv {input member} gdbm_recovery size_t max_failed_buckets | ||
1095 | @kwindex GDBM_RCVR_MAX_FAILED_BUCKETS | ||
1096 | If @code{GDBM_RCVR_MAX_FAILED_BUCKETS} is set, this member sets the limit | ||
1097 | on the number of buckets that cannot be retrieved or that contain | ||
1098 | bogus information. If the number of failed buckets grows bigger than | ||
1099 | @code{max_failed_buckets}, recovery is aborted and error is returned. | ||
1100 | @end deftypecv | ||
1101 | |||
1102 | @deftypecv {output member} gdbm_recovery size_t max_failures | ||
1103 | @kwindex GDBM_RCVR_MAX_FAILURES | ||
1104 | If @code{GDBM_RCVR_MAX_FAILURES} is set, this member sets the limit | ||
1105 | of failures that are tolerated during recovery. If the number of | ||
1106 | errors grows bigger than @code{max_failures}, recovery is aborted and | ||
1107 | error is returned. | ||
1108 | @end deftypecv | ||
1109 | |||
1110 | The following members are filled on output, upon successful return | ||
1111 | from the function: | ||
1112 | |||
1113 | @deftypecv {output member} gdbm_recovery size_t recovered_keys | ||
1114 |