lib: Add map_unix_error_from_tdb
authorVolker Lendecke <vl@samba.org>
Sun, 14 Sep 2014 11:10:58 +0000 (13:10 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 16 Dec 2014 17:56:03 +0000 (18:56 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/util_tdb.c
lib/util/util_tdb.h

index 811c2a40f79527893170ec132dedf34de46aa185..f84ab3314e5c7abfef088430fb057ebe89d4c853 100644 (file)
@@ -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;
+}
index 12c472c36d637eaa3367f31a4799f0b4e9b966ff..7a457f736fd9a32498c8418580c94a5745fd8bdb 100644 (file)
@@ -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__ */