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