| 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_handle.h" | 5 #include "nacl_io/kernel_handle.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 | 10 |
| 11 #include "nacl_io/mount.h" | 11 #include "nacl_io/mount.h" |
| 12 #include "nacl_io/mount_node.h" | 12 #include "nacl_io/mount_node.h" |
| 13 #include "nacl_io/osunistd.h" | 13 #include "nacl_io/osunistd.h" |
| 14 | 14 |
| 15 #include "sdk_util/auto_lock.h" | 15 #include "sdk_util/auto_lock.h" |
| 16 | 16 |
| 17 // It is only legal to construct a handle while the kernel lock is held. | 17 // It is only legal to construct a handle while the kernel lock is held. |
| 18 KernelHandle::KernelHandle() | 18 KernelHandle::KernelHandle() |
| 19 : mount_(NULL), node_(NULL), offs_(0) {} | 19 : mount_(NULL), node_(NULL), offs_(0) {} |
| 20 | 20 |
| 21 KernelHandle::KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node) | 21 KernelHandle::KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node) |
| 22 : mount_(mnt), node_(node), offs_(0) {} | 22 : mount_(mnt), node_(node), offs_(0) {} |
| 23 | 23 |
| 24 KernelHandle::~KernelHandle() { |
| 25 // Force release order, so that mount persists beyond node |
| 26 node_.reset(NULL); |
| 27 mount_.reset(NULL); |
| 28 } |
| 29 |
| 24 Error KernelHandle::Init(int open_mode) { | 30 Error KernelHandle::Init(int open_mode) { |
| 25 if (open_mode & O_APPEND) { | 31 if (open_mode & O_APPEND) { |
| 26 size_t node_size; | 32 size_t node_size; |
| 27 Error error = node_->GetSize(&offs_); | 33 Error error = node_->GetSize(&offs_); |
| 28 if (error) | 34 if (error) |
| 29 return error; | 35 return error; |
| 30 } | 36 } |
| 31 | 37 |
| 32 return 0; | 38 return 0; |
| 33 } | 39 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 Error KernelHandle::GetDents(struct dirent* pdir, size_t nbytes, int* cnt) { | 99 Error KernelHandle::GetDents(struct dirent* pdir, size_t nbytes, int* cnt) { |
| 94 AUTO_LOCK(offs_lock_); | 100 AUTO_LOCK(offs_lock_); |
| 95 Error error = node_->GetDents(offs_, pdir, nbytes, cnt); | 101 Error error = node_->GetDents(offs_, pdir, nbytes, cnt); |
| 96 if (0 == error) | 102 if (0 == error) |
| 97 offs_ += *cnt; | 103 offs_ += *cnt; |
| 98 return error; | 104 return error; |
| 99 } | 105 } |
| 100 | 106 |
| 101 const ScopedRef<MountNode>& KernelHandle::node() { return node_; } | 107 const ScopedRef<MountNode>& KernelHandle::node() { return node_; } |
| 102 const ScopedRef<Mount>& KernelHandle::mount() { return mount_; } | 108 const ScopedRef<Mount>& KernelHandle::mount() { return mount_; } |
| OLD | NEW |