| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/memfs/mem_fs_node.h" | 5 #include "nacl_io/memfs/mem_fs_node.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "nacl_io/kernel_handle.h" | 12 #include "nacl_io/kernel_handle.h" |
| 13 #include "nacl_io/osstat.h" | 13 #include "nacl_io/osstat.h" |
| 14 #include "sdk_util/auto_lock.h" | 14 #include "sdk_util/auto_lock.h" |
| 15 | 15 |
| 16 namespace nacl_io { | 16 namespace nacl_io { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // The maximum size to reserve in addition to the requested size. Resize() will | 20 // The maximum size to reserve in addition to the requested size. Resize() will |
| 21 // allocate twice as much as requested, up to this value. | 21 // allocate twice as much as requested, up to this value. |
| 22 const size_t kMaxResizeIncrement = 16 * 1024 * 1024; | 22 const size_t kMaxResizeIncrement = 16 * 1024 * 1024; |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 MemFsNode::MemFsNode(Filesystem* filesystem) : Node(filesystem) { | 26 MemFsNode::MemFsNode(Filesystem* filesystem) : Node(filesystem) { |
| 27 SetType(S_IFREG); | 27 SetType(S_IFREG); |
| 28 } | 28 } |
| 29 | 29 |
| 30 MemFsNode::~MemFsNode() {} | 30 MemFsNode::~MemFsNode() { |
| 31 } |
| 31 | 32 |
| 32 Error MemFsNode::Read(const HandleAttr& attr, | 33 Error MemFsNode::Read(const HandleAttr& attr, |
| 33 void* buf, | 34 void* buf, |
| 34 size_t count, | 35 size_t count, |
| 35 int* out_bytes) { | 36 int* out_bytes) { |
| 36 *out_bytes = 0; | 37 *out_bytes = 0; |
| 37 | 38 |
| 38 AUTO_LOCK(node_lock_); | 39 AUTO_LOCK(node_lock_); |
| 39 if (count == 0) | 40 if (count == 0) |
| 40 return 0; | 41 return 0; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } else if (new_size < stat_.st_size) { | 86 } else if (new_size < stat_.st_size) { |
| 86 // Shrink to fit. std::vector usually doesn't reduce allocation size, so | 87 // Shrink to fit. std::vector usually doesn't reduce allocation size, so |
| 87 // use the swap trick. | 88 // use the swap trick. |
| 88 std::vector<char>(data_).swap(data_); | 89 std::vector<char>(data_).swap(data_); |
| 89 } | 90 } |
| 90 data_.resize(new_size); | 91 data_.resize(new_size); |
| 91 stat_.st_size = new_size; | 92 stat_.st_size = new_size; |
| 92 } | 93 } |
| 93 | 94 |
| 94 } // namespace nacl_io | 95 } // namespace nacl_io |
| OLD | NEW |