| 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 #ifndef LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ |
| 6 #define LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ |
| 7 | 7 |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 | 9 |
| 10 #include "nacl_io/error.h" | 10 #include "nacl_io/error.h" |
| 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/ostypes.h" | 13 #include "nacl_io/ostypes.h" |
| 14 | 14 |
| 15 #include "sdk_util/macros.h" | 15 #include "sdk_util/macros.h" |
| 16 #include "sdk_util/ref_object.h" | 16 #include "sdk_util/ref_object.h" |
| 17 #include "sdk_util/scoped_ref.h" | 17 #include "sdk_util/scoped_ref.h" |
| 18 #include "sdk_util/simple_lock.h" | 18 #include "sdk_util/simple_lock.h" |
| 19 | 19 |
| 20 // KernelHandle provides a reference counted container for the open | 20 // KernelHandle provides a reference counted container for the open |
| 21 // file information, such as it's mount, node, access type and offset. | 21 // file information, such as it's mount, node, access type and offset. |
| 22 // KernelHandle can only be referenced when the KernelProxy lock is held. | 22 // KernelHandle can only be referenced when the KernelProxy lock is held. |
| 23 class KernelHandle : public RefObject { | 23 class KernelHandle : public RefObject { |
| 24 public: | 24 public: |
| 25 KernelHandle(); | 25 KernelHandle(); |
| 26 KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node); | 26 KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node); |
| 27 virtual ~KernelHandle(); |
| 27 | 28 |
| 28 Error Init(int open_flags); | 29 Error Init(int open_flags); |
| 29 | 30 |
| 30 // Assumes |out_offset| is non-NULL. | 31 // Assumes |out_offset| is non-NULL. |
| 31 Error Seek(off_t offset, int whence, off_t* out_offset); | 32 Error Seek(off_t offset, int whence, off_t* out_offset); |
| 32 | 33 |
| 33 // Dispatches Read, Write, GetDents to atomically update offs_. | 34 // Dispatches Read, Write, GetDents to atomically update offs_. |
| 34 Error Read(void* buf, size_t nbytes, int* bytes_read); | 35 Error Read(void* buf, size_t nbytes, int* bytes_read); |
| 35 Error Write(const void* buf, size_t nbytes, int* bytes_written); | 36 Error Write(const void* buf, size_t nbytes, int* bytes_written); |
| 36 Error GetDents(struct dirent* pdir, size_t count, int* bytes_written); | 37 Error GetDents(struct dirent* pdir, size_t count, int* bytes_written); |
| 37 | 38 |
| 38 const ScopedRef<MountNode>& node(); | 39 const ScopedRef<MountNode>& node(); |
| 39 const ScopedRef<Mount>& mount(); | 40 const ScopedRef<Mount>& mount(); |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 ScopedRef<MountNode> node_; | 43 ScopedRef<MountNode> node_; |
| 43 ScopedRef<Mount> mount_; | 44 ScopedRef<Mount> mount_; |
| 44 SimpleLock offs_lock_; | 45 SimpleLock offs_lock_; |
| 45 size_t offs_; | 46 size_t offs_; |
| 46 | 47 |
| 47 friend class KernelProxy; | 48 friend class KernelProxy; |
| 48 DISALLOW_COPY_AND_ASSIGN(KernelHandle); | 49 DISALLOW_COPY_AND_ASSIGN(KernelHandle); |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 typedef ScopedRef<KernelHandle> ScopedKernelHandle; | 52 typedef ScopedRef<KernelHandle> ScopedKernelHandle; |
| 52 | 53 |
| 53 #endif // LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ | 54 #endif // LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ |
| OLD | NEW |