aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/module/zfs/zcp_global.c
blob: 8e166e0736d6b3f5c339e48f57440b7267133443 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * CDDL HEADER START
 *
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
 */

#include <sys/zcp_global.h>

#include <sys/lua/lua.h>
#include <sys/lua/lauxlib.h>

typedef struct zcp_errno_global {
	const char *zeg_name;
	int zeg_errno;
} zcp_errno_global_t;

static const zcp_errno_global_t errno_globals[] = {
	{"EPERM", EPERM},
	{"ENOENT", ENOENT},
	{"ESRCH", ESRCH},
	{"EINTR", EINTR},
	{"EIO", EIO},
	{"ENXIO", ENXIO},
	{"E2BIG", E2BIG},
	{"ENOEXEC", ENOEXEC},
	{"EBADF", EBADF},
	{"ECHILD", ECHILD},
	{"EAGAIN", EAGAIN},
	{"ENOMEM", ENOMEM},
	{"EACCES", EACCES},
	{"EFAULT", EFAULT},
	{"ENOTBLK", ENOTBLK},
	{"EBUSY", EBUSY},
	{"EEXIST", EEXIST},
	{"EXDEV", EXDEV},
	{"ENODEV", ENODEV},
	{"ENOTDIR", ENOTDIR},
	{"EISDIR", EISDIR},
	{"EINVAL", EINVAL},
	{"ENFILE", ENFILE},
	{"EMFILE", EMFILE},
	{"ENOTTY", ENOTTY},
	{"ETXTBSY", ETXTBSY},
	{"EFBIG", EFBIG},
	{"ENOSPC", ENOSPC},
	{"ESPIPE", ESPIPE},
	{"EROFS", EROFS},
	{"EMLINK", EMLINK},
	{"EPIPE", EPIPE},
	{"EDOM", EDOM},
	{"ERANGE", ERANGE},
	{"EDEADLK", EDEADLK},
	{"ENOLCK", ENOLCK},
	{"ECANCELED", ECANCELED},
	{"ENOTSUP", ENOTSUP},
	{"EDQUOT", EDQUOT},
	{"ENAMETOOLONG", ENAMETOOLONG},
	{0, 0}
};

static void
zcp_load_errno_globals(lua_State *state)
{
	const zcp_errno_global_t *global = errno_globals;
	while (global->zeg_name != NULL) {
		lua_pushnumber(state, (lua_Number)global->zeg_errno);
		lua_setglobal(state, global->zeg_name);
		global++;
	}
}

void
zcp_load_globals(lua_State *state)
{
	zcp_load_errno_globals(state);
}