forked from includeos/IncludeOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen.cpp
More file actions
46 lines (41 loc) · 1015 Bytes
/
Copy pathopen.cpp
File metadata and controls
46 lines (41 loc) · 1015 Bytes
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
#include "common.hpp"
#include <sys/types.h>
#include <fs/vfs.hpp>
#include <posix/fd_map.hpp>
#include <posix/file_fd.hpp>
static long sys_open(const char *pathname, int /*flags*/, mode_t /*mode = 0*/) {
if (UNLIKELY(pathname == nullptr))
return -EFAULT;
if (UNLIKELY(pathname[0] == 0))
return -ENOENT;
try {
auto& entry = fs::VFS::get<FD_compatible>(pathname);
auto& fd = entry.open_fd();
return fd.get_id();
}
// Not FD_compatible, try dirent
catch(const fs::VFS_err& err)
{
try {
auto ent = fs::VFS::stat_sync(pathname);
if (ent.is_valid())
{
auto& fd = FD_map::_open<File_FD>(ent);
return fd.get_id();
}
return -ENOENT;
}
catch(...)
{
return -ENOENT;
}
}
catch(const std::bad_function_call&) {
// Open fd delegate not set
}
return -ENOENT;
}
extern "C"
long syscall_SYS_open(const char *pathname, int flags, mode_t mode = 0) {
return strace(sys_open, "open", pathname, flags, mode);
}