Chromium Code Reviews| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 ScopedKernelHandle handle(new KernelHandle(fs, node)); | 168 ScopedKernelHandle handle(new KernelHandle(fs, node)); |
| 169 error = handle->Init(O_RDONLY); | 169 error = handle->Init(O_RDONLY); |
| 170 if (error) { | 170 if (error) { |
| 171 errno = error; | 171 errno = error; |
| 172 return -1; | 172 return -1; |
| 173 } | 173 } |
| 174 | 174 |
| 175 return AllocateFD(handle); | 175 int fd = AllocateFD(handle); |
| 176 fd_paths_[fd] = GetAbsParts(path).Join(); | |
|
binji
2014/01/06 19:32:04
this probably should be handled in AllocateFD. fd_
Matthew Turk
2014/01/07 20:33:11
It does -- and I've gone through and put path as a
| |
| 177 return fd; | |
| 176 } | 178 } |
| 177 | 179 |
| 178 int KernelProxy::open(const char* path, int open_flags) { | 180 int KernelProxy::open(const char* path, int open_flags) { |
| 179 ScopedFilesystem fs; | 181 ScopedFilesystem fs; |
| 180 ScopedNode node; | 182 ScopedNode node; |
| 181 | 183 |
| 182 Error error = AcquireFsAndNode(path, open_flags, &fs, &node); | 184 Error error = AcquireFsAndNode(path, open_flags, &fs, &node); |
| 183 if (error) { | 185 if (error) { |
| 184 errno = error; | 186 errno = error; |
| 185 return -1; | 187 return -1; |
| 186 } | 188 } |
| 187 | 189 |
| 188 ScopedKernelHandle handle(new KernelHandle(fs, node)); | 190 ScopedKernelHandle handle(new KernelHandle(fs, node)); |
| 189 error = handle->Init(open_flags); | 191 error = handle->Init(open_flags); |
| 190 if (error) { | 192 if (error) { |
| 191 errno = error; | 193 errno = error; |
| 192 return -1; | 194 return -1; |
| 193 } | 195 } |
| 194 | 196 |
| 195 return AllocateFD(handle); | 197 int fd = AllocateFD(handle); |
| 198 fd_paths_[fd] = GetAbsParts(path).Join(); | |
| 199 return fd; | |
| 196 } | 200 } |
| 197 | 201 |
| 198 int KernelProxy::pipe(int pipefds[2]) { | 202 int KernelProxy::pipe(int pipefds[2]) { |
| 199 PipeNode* pipe = new PipeNode(stream_mount_.get()); | 203 PipeNode* pipe = new PipeNode(stream_mount_.get()); |
| 200 ScopedNode node(pipe); | 204 ScopedNode node(pipe); |
| 201 | 205 |
| 202 if (pipe->Init(O_RDWR) == 0) { | 206 if (pipe->Init(O_RDWR) == 0) { |
| 203 ScopedKernelHandle handle0(new KernelHandle(stream_mount_, node)); | 207 ScopedKernelHandle handle0(new KernelHandle(stream_mount_, node)); |
| 204 ScopedKernelHandle handle1(new KernelHandle(stream_mount_, node)); | 208 ScopedKernelHandle handle1(new KernelHandle(stream_mount_, node)); |
| 205 | 209 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 221 int KernelProxy::close(int fd) { | 225 int KernelProxy::close(int fd) { |
| 222 ScopedKernelHandle handle; | 226 ScopedKernelHandle handle; |
| 223 Error error = AcquireHandle(fd, &handle); | 227 Error error = AcquireHandle(fd, &handle); |
| 224 if (error) { | 228 if (error) { |
| 225 errno = error; | 229 errno = error; |
| 226 return -1; | 230 return -1; |
| 227 } | 231 } |
| 228 | 232 |
| 229 // Remove the FD from the process open file descriptor map | 233 // Remove the FD from the process open file descriptor map |
| 230 FreeFD(fd); | 234 FreeFD(fd); |
| 235 // Remove the FD from the map of fd to absolute path | |
| 236 fd_paths_.erase(fd); | |
|
Sam Clegg
2014/01/06 18:52:50
Would this be better done as part of FreeFD()?
binji
2014/01/06 19:32:04
agreed.
| |
| 231 return 0; | 237 return 0; |
| 232 } | 238 } |
| 233 | 239 |
| 234 int KernelProxy::dup(int oldfd) { | 240 int KernelProxy::dup(int oldfd) { |
| 235 ScopedKernelHandle handle; | 241 ScopedKernelHandle handle; |
| 236 Error error = AcquireHandle(oldfd, &handle); | 242 Error error = AcquireHandle(oldfd, &handle); |
| 237 if (error) { | 243 if (error) { |
| 238 errno = error; | 244 errno = error; |
| 239 return -1; | 245 return -1; |
| 240 } | 246 } |
| 241 | 247 |
| 242 return AllocateFD(handle); | 248 int fd = AllocateFD(handle); |
| 249 fd_paths_[fd] = fd_paths_[oldfd]; | |
| 250 return fd; | |
| 243 } | 251 } |
| 244 | 252 |
| 245 int KernelProxy::dup2(int oldfd, int newfd) { | 253 int KernelProxy::dup2(int oldfd, int newfd) { |
| 246 // If it's the same file handle, just return | 254 // If it's the same file handle, just return |
| 247 if (oldfd == newfd) | 255 if (oldfd == newfd) |
| 248 return newfd; | 256 return newfd; |
| 249 | 257 |
| 250 ScopedKernelHandle old_handle; | 258 ScopedKernelHandle old_handle; |
| 251 Error error = AcquireHandle(oldfd, &old_handle); | 259 Error error = AcquireHandle(oldfd, &old_handle); |
| 252 if (error) { | 260 if (error) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 | 515 |
| 508 int cnt = 0; | 516 int cnt = 0; |
| 509 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt); | 517 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt); |
| 510 if (error) | 518 if (error) |
| 511 errno = error; | 519 errno = error; |
| 512 | 520 |
| 513 return cnt; | 521 return cnt; |
| 514 } | 522 } |
| 515 | 523 |
| 516 int KernelProxy::fchdir(int fd) { | 524 int KernelProxy::fchdir(int fd) { |
| 517 errno = ENOSYS; | 525 ScopedKernelHandle handle; |
| 518 return -1; | 526 Error error = AcquireHandle(fd, &handle); |
| 527 if (error) { | |
| 528 errno = error; | |
| 529 return -1; | |
| 530 } | |
| 531 | |
| 532 if (!handle->node()->IsaDir()) { | |
| 533 errno = ENOTDIR; | |
| 534 return -1; | |
| 535 } | |
| 536 | |
| 537 FdPathMap_t::iterator iter = fd_paths_.find(fd); | |
| 538 if (iter == fd_paths_.end()) { | |
| 539 errno = EBADF; | |
| 540 return -1; | |
| 541 } | |
| 542 | |
| 543 error = SetCWD(iter->second); | |
| 544 if (error) { | |
| 545 // errno set by SetCWD | |
|
Sam Clegg
2014/01/06 18:52:50
Are you sure? I don't see SetCWD setting errno.
binji
2014/01/06 19:32:04
Only the KernelProxy sets errno. KernelObject::Set
| |
| 546 return -1; | |
| 547 } | |
| 548 return 0; | |
| 519 } | 549 } |
| 520 | 550 |
| 521 int KernelProxy::ftruncate(int fd, off_t length) { | 551 int KernelProxy::ftruncate(int fd, off_t length) { |
| 522 ScopedKernelHandle handle; | 552 ScopedKernelHandle handle; |
| 523 Error error = AcquireHandle(fd, &handle); | 553 Error error = AcquireHandle(fd, &handle); |
| 524 if (error) { | 554 if (error) { |
| 525 errno = error; | 555 errno = error; |
| 526 return -1; | 556 return -1; |
| 527 } | 557 } |
| 528 | 558 |
| (...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1601 errno = ENOTSOCK; | 1631 errno = ENOTSOCK; |
| 1602 return -1; | 1632 return -1; |
| 1603 } | 1633 } |
| 1604 | 1634 |
| 1605 return 0; | 1635 return 0; |
| 1606 } | 1636 } |
| 1607 | 1637 |
| 1608 #endif // PROVIDES_SOCKET_API | 1638 #endif // PROVIDES_SOCKET_API |
| 1609 | 1639 |
| 1610 } // namespace_nacl_io | 1640 } // namespace_nacl_io |
| OLD | NEW |