xref: /freebsd/sys/contrib/openzfs/module/zfs/zcp_global.c (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * This file and its contents are supplied under the terms of the
6  * Common Development and Distribution License ("CDDL"), version 1.0.
7  * You may only use this file in accordance with the terms of version
8  * 1.0 of the CDDL.
9  *
10  * A full copy of the text of the CDDL should have accompanied this
11  * source.  A copy of the CDDL is also available via the Internet at
12  * http://www.illumos.org/license/CDDL.
13  *
14  * CDDL HEADER END
15  */
16 
17 /*
18  * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
19  */
20 
21 #include <sys/zcp_global.h>
22 
23 #include <sys/lua/lua.h>
24 #include <sys/lua/lauxlib.h>
25 
26 typedef struct zcp_errno_global {
27 	const char *zeg_name;
28 	int zeg_errno;
29 } zcp_errno_global_t;
30 
31 static const zcp_errno_global_t errno_globals[] = {
32 	{"EPERM", EPERM},
33 	{"ENOENT", ENOENT},
34 	{"ESRCH", ESRCH},
35 	{"EINTR", EINTR},
36 	{"EIO", EIO},
37 	{"ENXIO", ENXIO},
38 	{"E2BIG", E2BIG},
39 	{"ENOEXEC", ENOEXEC},
40 	{"EBADF", EBADF},
41 	{"ECHILD", ECHILD},
42 	{"EAGAIN", EAGAIN},
43 	{"ENOMEM", ENOMEM},
44 	{"EACCES", EACCES},
45 	{"EFAULT", EFAULT},
46 	{"ENOTBLK", ENOTBLK},
47 	{"EBUSY", EBUSY},
48 	{"EEXIST", EEXIST},
49 	{"EXDEV", EXDEV},
50 	{"ENODEV", ENODEV},
51 	{"ENOTDIR", ENOTDIR},
52 	{"EISDIR", EISDIR},
53 	{"EINVAL", EINVAL},
54 	{"ENFILE", ENFILE},
55 	{"EMFILE", EMFILE},
56 	{"ENOTTY", ENOTTY},
57 	{"ETXTBSY", ETXTBSY},
58 	{"EFBIG", EFBIG},
59 	{"ENOSPC", ENOSPC},
60 	{"ESPIPE", ESPIPE},
61 	{"EROFS", EROFS},
62 	{"EMLINK", EMLINK},
63 	{"EPIPE", EPIPE},
64 	{"EDOM", EDOM},
65 	{"ERANGE", ERANGE},
66 	{"EDEADLK", EDEADLK},
67 	{"ENOLCK", ENOLCK},
68 	{"ECANCELED", ECANCELED},
69 	{"ENOTSUP", ENOTSUP},
70 	{"EDQUOT", EDQUOT},
71 	{"ENAMETOOLONG", ENAMETOOLONG},
72 	{0, 0}
73 };
74 
75 static void
zcp_load_errno_globals(lua_State * state)76 zcp_load_errno_globals(lua_State *state)
77 {
78 	const zcp_errno_global_t *global = errno_globals;
79 	while (global->zeg_name != NULL) {
80 		lua_pushnumber(state, (lua_Number)global->zeg_errno);
81 		lua_setglobal(state, global->zeg_name);
82 		global++;
83 	}
84 }
85 
86 void
zcp_load_globals(lua_State * state)87 zcp_load_globals(lua_State *state)
88 {
89 	zcp_load_errno_globals(state);
90 }
91