OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "nacl_io/kernel_proxy.h" | 5 #include "nacl_io/kernel_proxy.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 rtn = CreateFsNode(root_fs); | 97 rtn = CreateFsNode(root_fs); |
98 if (rtn != 0) | 98 if (rtn != 0) |
99 assert(false); | 99 assert(false); |
100 | 100 |
101 rtn = CreateFsNode(dev_fs_); | 101 rtn = CreateFsNode(dev_fs_); |
102 if (rtn != 0) | 102 if (rtn != 0) |
103 assert(false); | 103 assert(false); |
104 | 104 |
105 // Open the first three in order to get STDIN, STDOUT, STDERR | 105 // Open the first three in order to get STDIN, STDOUT, STDERR |
106 int fd; | 106 int fd; |
107 fd = open("/dev/stdin", O_RDONLY); | 107 fd = open("/dev/stdin", O_RDONLY, 0777); |
binji
2014/09/11 23:51:40
0 for these, since they are not being created?
bradn
2014/09/12 06:17:03
Done.
| |
108 assert(fd == 0); | 108 assert(fd == 0); |
109 if (fd < 0) | 109 if (fd < 0) |
110 rtn = errno; | 110 rtn = errno; |
111 | 111 |
112 fd = open("/dev/stdout", O_WRONLY); | 112 fd = open("/dev/stdout", O_WRONLY, 0777); |
113 assert(fd == 1); | 113 assert(fd == 1); |
114 if (fd < 0) | 114 if (fd < 0) |
115 rtn = errno; | 115 rtn = errno; |
116 | 116 |
117 fd = open("/dev/stderr", O_WRONLY); | 117 fd = open("/dev/stderr", O_WRONLY, 0777); |
118 assert(fd == 2); | 118 assert(fd == 2); |
119 if (fd < 0) | 119 if (fd < 0) |
120 rtn = errno; | 120 rtn = errno; |
121 | 121 |
122 #ifdef PROVIDES_SOCKET_API | 122 #ifdef PROVIDES_SOCKET_API |
123 host_resolver_.Init(ppapi_); | 123 host_resolver_.Init(ppapi_); |
124 #endif | 124 #endif |
125 | 125 |
126 FsInitArgs args; | 126 FsInitArgs args; |
127 args.dev = dev_++; | 127 args.dev = dev_++; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 ScopedKernelHandle handle(new KernelHandle(fs, node)); | 192 ScopedKernelHandle handle(new KernelHandle(fs, node)); |
193 error = handle->Init(O_RDONLY); | 193 error = handle->Init(O_RDONLY); |
194 if (error) { | 194 if (error) { |
195 errno = error; | 195 errno = error; |
196 return -1; | 196 return -1; |
197 } | 197 } |
198 | 198 |
199 return AllocateFD(handle, path); | 199 return AllocateFD(handle, path); |
200 } | 200 } |
201 | 201 |
202 int KernelProxy::open(const char* path, int open_flags) { | 202 int KernelProxy::open(const char* path, int open_flags, mode_t mode_flags) { |
Sam Clegg
2014/09/11 23:47:08
Just call this mode?
bradn
2014/09/12 06:17:03
Done.
| |
203 ScopedFilesystem fs; | 203 ScopedFilesystem fs; |
204 ScopedNode node; | 204 ScopedNode node; |
205 | 205 |
206 Error error = AcquireFsAndNode(path, open_flags, &fs, &node); | 206 Error error = AcquireFsAndNode(path, open_flags, mode_flags, &fs, &node); |
207 if (error) { | 207 if (error) { |
208 errno = error; | 208 errno = error; |
209 return -1; | 209 return -1; |
210 } | 210 } |
211 | 211 |
212 ScopedKernelHandle handle(new KernelHandle(fs, node)); | 212 ScopedKernelHandle handle(new KernelHandle(fs, node)); |
213 error = handle->Init(open_flags); | 213 error = handle->Init(open_flags); |
214 if (error) { | 214 if (error) { |
215 errno = error; | 215 errno = error; |
216 return -1; | 216 return -1; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 317 |
318 char* KernelProxy::getwd(char* buf) { | 318 char* KernelProxy::getwd(char* buf) { |
319 if (NULL == buf) { | 319 if (NULL == buf) { |
320 errno = EFAULT; | 320 errno = EFAULT; |
321 return NULL; | 321 return NULL; |
322 } | 322 } |
323 return getcwd(buf, MAXPATHLEN); | 323 return getcwd(buf, MAXPATHLEN); |
324 } | 324 } |
325 | 325 |
326 int KernelProxy::chmod(const char* path, mode_t mode) { | 326 int KernelProxy::chmod(const char* path, mode_t mode) { |
327 int fd = KernelProxy::open(path, O_RDONLY); | 327 int fd = KernelProxy::open(path, O_RDONLY, mode); |
328 if (-1 == fd) | 328 if (-1 == fd) |
329 return -1; | 329 return -1; |
330 | 330 |
331 int result = fchmod(fd, mode); | 331 int result = fchmod(fd, mode); |
332 close(fd); | 332 close(fd); |
333 return result; | 333 return result; |
334 } | 334 } |
335 | 335 |
336 int KernelProxy::chown(const char* path, uid_t owner, gid_t group) { | 336 int KernelProxy::chown(const char* path, uid_t owner, gid_t group) { |
337 return 0; | 337 return 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 error = fs->Rmdir(rel); | 381 error = fs->Rmdir(rel); |
382 if (error) { | 382 if (error) { |
383 errno = error; | 383 errno = error; |
384 return -1; | 384 return -1; |
385 } | 385 } |
386 | 386 |
387 return 0; | 387 return 0; |
388 } | 388 } |
389 | 389 |
390 int KernelProxy::stat(const char* path, struct stat* buf) { | 390 int KernelProxy::stat(const char* path, struct stat* buf) { |
391 int fd = open(path, O_RDONLY); | 391 int fd = open(path, O_RDONLY, 0); |
392 if (-1 == fd) | 392 if (-1 == fd) |
393 return -1; | 393 return -1; |
394 | 394 |
395 int result = fstat(fd, buf); | 395 int result = fstat(fd, buf); |
396 close(fd); | 396 close(fd); |
397 return result; | 397 return result; |
398 } | 398 } |
399 | 399 |
400 int KernelProxy::mount(const char* source, | 400 int KernelProxy::mount(const char* source, |
401 const char* target, | 401 const char* target, |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 error = fs->Unlink(rel); | 711 error = fs->Unlink(rel); |
712 if (error) { | 712 if (error) { |
713 errno = error; | 713 errno = error; |
714 return -1; | 714 return -1; |
715 } | 715 } |
716 | 716 |
717 return 0; | 717 return 0; |
718 } | 718 } |
719 | 719 |
720 int KernelProxy::truncate(const char* path, off_t len) { | 720 int KernelProxy::truncate(const char* path, off_t len) { |
721 int fd = KernelProxy::open(path, O_WRONLY); | 721 int fd = KernelProxy::open(path, O_WRONLY, 0); |
722 if (-1 == fd) | 722 if (-1 == fd) |
723 return -1; | 723 return -1; |
724 | 724 |
725 int result = ftruncate(fd, len); | 725 int result = ftruncate(fd, len); |
726 close(fd); | 726 close(fd); |
727 return result; | 727 return result; |
728 } | 728 } |
729 | 729 |
730 int KernelProxy::lstat(const char* path, struct stat* buf) { | 730 int KernelProxy::lstat(const char* path, struct stat* buf) { |
731 return stat(path, buf); | 731 return stat(path, buf); |
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1717 errno = ENOTSOCK; | 1717 errno = ENOTSOCK; |
1718 return -1; | 1718 return -1; |
1719 } | 1719 } |
1720 | 1720 |
1721 return 0; | 1721 return 0; |
1722 } | 1722 } |
1723 | 1723 |
1724 #endif // PROVIDES_SOCKET_API | 1724 #endif // PROVIDES_SOCKET_API |
1725 | 1725 |
1726 } // namespace_nacl_io | 1726 } // namespace_nacl_io |
OLD | NEW |