Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
|
Mark Seaborn
2014/02/07 22:53:43
Can you leave out the implementation of irt_filena
| |
| 5 #include <errno.h> | |
| 6 #include <sys/types.h> | |
| 7 #include <sys/stat.h> | |
| 8 #include <fcntl.h> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "components/nacl/loader/nonsfi/abi_conversion.h" | |
| 12 #include "components/nacl/loader/nonsfi/irt_interfaces.h" | |
| 13 #include "components/nacl/loader/nonsfi/irt_util.h" | |
| 14 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | |
| 15 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" | |
| 16 | |
| 17 namespace nacl { | |
| 18 namespace nonsfi { | |
| 19 namespace { | |
| 20 | |
| 21 int IrtOpen( | |
| 22 const char* pathname, int oflag, nacl_abi_mode_t cmode, int* new_fd) { | |
| 23 // Some flags are ignored. Please see also NaClSysOpen | |
| 24 // native_client/src/trusted/service_runtime/sys_filename.c. | |
| 25 int flags; | |
| 26 switch(oflag & NACL_ABI_O_ACCMODE) { | |
| 27 case NACL_ABI_O_RDONLY: | |
| 28 flags = O_RDONLY; | |
| 29 break; | |
| 30 case NACL_ABI_O_WRONLY: | |
| 31 flags = O_WRONLY; | |
| 32 break; | |
| 33 case NACL_ABI_O_RDWR: | |
| 34 flags = O_RDWR; | |
| 35 break; | |
| 36 default: | |
| 37 LOG(WARNING) << "Unknown accmode: " << (oflag & NACL_ABI_O_ACCMODE); | |
| 38 flags = O_RDONLY; | |
| 39 } | |
| 40 if (oflag & NACL_ABI_O_CREAT) | |
| 41 flags |= O_CREAT; | |
| 42 if (oflag & NACL_ABI_O_TRUNC) | |
| 43 flags |= O_TRUNC; | |
| 44 if (oflag & NACL_ABI_O_APPEND) | |
| 45 flags |= O_APPEND; | |
| 46 | |
| 47 mode_t mode = 0; | |
| 48 if (cmode & NACL_ABI_S_IRUSR) | |
| 49 mode |= S_IRUSR; | |
| 50 if (cmode & NACL_ABI_S_IWUSR) | |
| 51 mode |= S_IWUSR; | |
| 52 if (cmode & NACL_ABI_S_IXUSR) | |
| 53 mode |= S_IXUSR; | |
| 54 | |
| 55 int fd = ::open(pathname, flags, mode); | |
| 56 if (fd < 0) | |
| 57 return errno; | |
| 58 | |
| 59 *new_fd = fd; | |
| 60 return 0; | |
| 61 } | |
| 62 | |
| 63 int IrtStat(const char* pathname, struct nacl_abi_stat* st) { | |
| 64 struct stat host_st; | |
| 65 if (::stat(pathname, &host_st) < 0) | |
| 66 return errno; | |
| 67 | |
| 68 StatToNaClAbiStat(host_st, st); | |
| 69 return 0; | |
| 70 } | |
| 71 | |
| 72 #if 1 | |
| 73 int IrtGetCwd(char* pathname, size_t len) { | |
| 74 if (getcwd(pathname, len) == NULL) | |
| 75 return errno; | |
| 76 return 0; | |
| 77 } | |
| 78 | |
| 79 int IrtUnlink(const char* pathname) { | |
| 80 return CheckError(unlink(pathname)); | |
| 81 } | |
| 82 | |
| 83 // TODO | |
| 84 int IrtOpenResource(const char* name, int* fd) { | |
| 85 return ENOSYS; | |
| 86 } | |
| 87 | |
| 88 #endif | |
| 89 } // namespace | |
| 90 | |
| 91 // Both open and stat should use nacl_abi_X for their argument types, rather | |
| 92 // than host type, such as struct stat or mode_t. However, the definition | |
| 93 // of nacl_irt_filename uses host types, so here we need to cast them. | |
| 94 const nacl_irt_filename kIrtFileName = { | |
| 95 reinterpret_cast<int(*)(const char*, int, mode_t, int*)>(IrtOpen), | |
| 96 reinterpret_cast<int(*)(const char*, struct stat*)>(IrtStat), | |
| 97 }; | |
| 98 | |
| 99 const nacl_irt_dev_filename kIrtDevFileName = { | |
| 100 reinterpret_cast<int(*)(const char*, int, mode_t, int*)>(IrtOpen), | |
| 101 reinterpret_cast<int(*)(const char*, struct stat*)>(IrtStat), | |
| 102 NULL, // mkdir | |
| 103 NULL, // rmdir | |
| 104 NULL, // chdir | |
| 105 IrtGetCwd, | |
| 106 IrtUnlink, | |
| 107 NULL, // truncate | |
| 108 NULL, // lstat | |
| 109 NULL, // link | |
| 110 NULL, // rename | |
| 111 NULL, // symlink | |
| 112 NULL, // chmod | |
| 113 NULL, // access | |
| 114 NULL, // readlink | |
| 115 NULL, // utimes | |
| 116 }; | |
| 117 | |
| 118 const nacl_irt_resource_open kIrtResourceOpen = { | |
| 119 IrtOpenResource, | |
| 120 }; | |
| 121 | |
| 122 } // namespace nonsfi | |
| 123 } // namespace nacl | |
| OLD | NEW |