-
Notifications
You must be signed in to change notification settings - Fork 5
/
FileSystem.lua
121 lines (93 loc) · 2.35 KB
/
FileSystem.lua
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
local ffi = require "ffi"
require "WTypes"
require "WinBase"
local Kernel32 = require "Kernel32"
ffi.cdef[[
struct IODevice {
HANDLE Handle;
};
]]
local IODevice = ffi.typeof("struct IODevice")
local IODevice_mt = {
__gc = function(self)
end,
__index = {
CancelIo = function(self)
end,
Lock = function(self)
end,
},
}
ffi.metatype(IODevice, IODevice_mt);
local modes = {
["r"] = GENERIC_READ,
["r+"] = bor(GENERIC_READ, GENERIC_WRITE),
["w"] = GENERIC_WRITE,
["w+"] = bor(GENERIC_WRITE, GENERIC_READ),
["a"] = bor(APPEND, CREAT, GENERIC_WRITE),
["a+"] = APPEND
}
local function string_to_access(mode)
return modes[mode] or bor(GENERIC_READ, GENERIC_WRITE);
--[[
if (strcmp(string, "w") == 0)
return O_CREAT | O_TRUNC | O_WRONLY;
if (strcmp(string, "w+") == 0)
return O_CREAT | O_TRUNC | O_RDWR;
if (strcmp(string, "a") == 0)
return O_APPEND | O_CREAT | O_WRONLY;
if (strcmp(string, "a+") == 0)
return O_APPEND | O_CREAT | O_RDWR;
#ifndef _WIN32
if (strcmp(string, "rs") == 0)
return O_RDONLY | O_SYNC;
if (strcmp(string, "rs+") == 0)
return O_RDWR | O_SYNC;
#endif
--]]
end
local FileSystem = {
CopyFile = function(src, dest, progress)
end,
CreateFile = function(filename, access)
local access, mode = string_to_access(access)
local handle, err = Kernel32.CreateFile(filename,
_In_ DWORD dwDesiredAccess,
_In_ DWORD dwShareMode,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
_In_ DWORD dwCreationDisposition,
_In_ DWORD dwFlagsAndAttributes,
_In_opt_ HANDLE hTemplateFile
);
end,
}
-- mode_t
function open()
end
function close()
end
function read()
end
function write()
end
int luv_fs_mkdir(lua_State* L);
int luv_fs_rmdir(lua_State* L);
int luv_fs_readdir(lua_State* L);
int luv_fs_stat(lua_State* L);
int luv_fs_fstat(lua_State* L);
int luv_fs_lstat(lua_State* L);
int luv_fs_rename(lua_State* L);
int luv_fs_fsync(lua_State* L);
int luv_fs_fdatasync(lua_State* L);
int luv_fs_ftruncate(lua_State* L);
int luv_fs_sendfile(lua_State* L);
int luv_fs_chmod(lua_State* L);
int luv_fs_fchmod(lua_State* L);
int luv_fs_utime(lua_State* L);
int luv_fs_futime(lua_State* L);
int luv_fs_symlink(lua_State* L);
int luv_fs_readlink(lua_State* L);
int luv_fs_chown(lua_State* L);
int luv_fs_fchown(lua_State* L);
int luv_fs_link(lua_State* L);
int luv_fs_unlink(lua_State* L);