Lua装载文件系统
我想使用Lua在Linux上挂载一个文件系统,但是我还没有在或库中找到任何功能。是否有某种方法可以在Lua中或使用现有库装载文件系统?与大多数依赖于平台的系统调用一样,Lua不会提供这种现成的映射。 因此,您需要一些C-API模块来实现这一点。 看起来像是通用的“但是”专注于LuaJIT,不提供Lua装载文件系统,lua,filesystems,mount,Lua,Filesystems,Mount,我想使用Lua在Linux上挂载一个文件系统,但是我还没有在或库中找到任何功能。是否有某种方法可以在Lua中或使用现有库装载文件系统?与大多数依赖于平台的系统调用一样,Lua不会提供这种现成的映射。 因此,您需要一些C-API模块来实现这一点。 看起来像是通用的“但是”专注于LuaJIT,不提供mount 我最近也有类似的需求,我结束了C模块的学习: static int l_mount(lua_State* L) { int res = 0; // TODO add more
mount
我最近也有类似的需求,我结束了C模块的学习:
static int l_mount(lua_State* L)
{
int res = 0;
// TODO add more checks on args!
const char *source = luaL_checkstring(L, 1);
const char *target = luaL_checkstring(L, 2);
const char *type = luaL_checkstring(L, 3);
lua_Integer flags = luaL_checkinteger(L, 4);
const char *data = luaL_checkstring(L, 5);
res = mount(source, target, type, flags, data);
if ( res != 0)
{
int err = errno;
lua_pushnil(L);
lua_pushfstring(L, "mount failed: errno[%s]", strerror(err));
return 2;
}
else
{
lua_pushfstring(L, "ok");
return 1;
}
}
#define register_constant(s)\
lua_pushinteger(L, s);\
lua_setfield(L, -2, #s);
// Module functions
static const luaL_Reg R[] =
{
{ "mount", l_mount },
{ NULL, NULL }
};
int luaopen_sysutils(lua_State* L)
{
luaL_newlib(L, R);
// do more mount defines mapping, maybe in some table.
register_constant(MS_RDONLY);
//...
return 1;
}
将其编译为一个C Lua模块,不要忘记需要
CAP\u SYS\u ADMIN
调用mount
syscall。pipe('mount…')
或FFI.C.mount(…)
?对于后者,我不记得确切的语法。您需要一种方法来请求用户密码,可能是使用fltk4lua,然后os.execute('echo'..password..'| sudo-S'..command)
我实际上不担心密码,我不想使用管道或执行。