aboutsummaryrefslogtreecommitdiff
path: root/libexec/flua
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2021-01-24 01:32:38 +0000
committerKyle Evans <kevans@FreeBSD.org>2021-01-29 18:47:29 +0000
commite25ee296c919d6567aa76058a7049eac974797fb (patch)
treed4bdac024242eced85fb80d9932b5052d9aa796c /libexec/flua
parent80a840b8ba03bafe299112e2364959d937a87fe1 (diff)
Diffstat (limited to 'libexec/flua')
-rw-r--r--libexec/flua/modules/lfs.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/libexec/flua/modules/lfs.c b/libexec/flua/modules/lfs.c
index 52a30c1515a9..e36c78d3b35b 100644
--- a/libexec/flua/modules/lfs.c
+++ b/libexec/flua/modules/lfs.c
@@ -123,6 +123,27 @@ __FBSDID("$FreeBSD$");
#define DIR_METATABLE "directory iterator metatable"
static int
+lua_dir_iter_pushtype(lua_State *L __unused, const struct dirent *ent __unused)
+{
+
+ /*
+ * This is a non-standard extension to luafilesystem for loader's
+ * benefit. The extra stat() calls to determine the entry type can
+ * be quite expensive on some systems, so this speeds up enumeration of
+ * /boot greatly by providing the type up front.
+ *
+ * This extension is compatible enough with luafilesystem, in that we're
+ * just using an extra return value for the iterator.
+ */
+#ifdef _STANDALONE
+ lua_pushinteger(L, ent->d_type);
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+static int
lua_dir_iter_next(lua_State *L)
{
struct dirent *entry;
@@ -144,7 +165,7 @@ lua_dir_iter_next(lua_State *L)
}
lua_pushstring(L, entry->d_name);
- return 1;
+ return 1 + lua_dir_iter_pushtype(L, entry);
}
static int
@@ -420,5 +441,10 @@ luaopen_lfs(lua_State *L)
{
register_metatable(L);
luaL_newlib(L, fslib);
+#ifdef _STANDALONE
+ /* Non-standard extension for loader, used with lfs.dir(). */
+ lua_pushinteger(L, DT_DIR);
+ lua_setfield(L, -2, "DT_DIR");
+#endif
return 1;
}