From 7be1dfa05c6b3c9077f09fd29f6ffdd8ea4011ec Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 14 Sep 2014 13:10:58 +0200 Subject: [PATCH] lib: Add map_unix_error_from_tdb Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/util/util_tdb.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/util/util_tdb.h | 7 ++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c index 811c2a40f79..f84ab3314e5 100644 --- a/lib/util/util_tdb.c +++ b/lib/util/util_tdb.c @@ -426,3 +426,60 @@ NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err) }; return result; } + +int map_unix_error_from_tdb(enum TDB_ERROR err) +{ + int result = EINVAL; + + switch (err) { + case TDB_SUCCESS: + result = 0; + break; + case TDB_ERR_CORRUPT: + result = EILSEQ; + break; + case TDB_ERR_IO: + result = EIO; + break; + case TDB_ERR_OOM: + result = ENOMEM; + break; + case TDB_ERR_EXISTS: + result = EEXIST; + break; + + case TDB_ERR_LOCK: + /* + * TDB_ERR_LOCK is very broad, we could for example + * distinguish between fcntl locks and invalid lock + * sequences. EWOULDBLOCK is wrong, but there is no real + * generic lock error code in errno.h + */ + result = EWOULDBLOCK; + break; + + case TDB_ERR_NOLOCK: + case TDB_ERR_LOCK_TIMEOUT: + /* + * These two ones in the enum are not actually used + */ + result = ENOLCK; + break; + case TDB_ERR_NOEXIST: + result = ENOENT; + break; + case TDB_ERR_EINVAL: + result = EINVAL; + break; + case TDB_ERR_RDONLY: + result = EROFS; + break; + case TDB_ERR_NESTING: + /* + * Well, this db is already busy... + */ + result = EBUSY; + break; + }; + return result; +} diff --git a/lib/util/util_tdb.h b/lib/util/util_tdb.h index 12c472c36d6..7a457f736fd 100644 --- a/lib/util/util_tdb.h +++ b/lib/util/util_tdb.h @@ -139,5 +139,10 @@ int tdb_traverse_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA d NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err); -#endif /* _____LIB_UTIL_UTIL_TDB_H__ */ +/**************************************************************************** + Return an errno from a TDB_ERROR +****************************************************************************/ +int map_unix_error_from_tdb(enum TDB_ERROR err); + +#endif /* _____LIB_UTIL_UTIL_TDB_H__ */ -- 2.11.4.GIT