OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 #include "MemMount.h" | 6 #include "MemMount.h" |
7 | 7 |
8 MemMount::MemMount() { | 8 MemMount::MemMount() { |
9 // Don't use the zero slot | 9 // Don't use the zero slot |
10 slots_.Alloc(); | 10 slots_.Alloc(); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 294 } |
295 | 295 |
296 for (; it != children->end() && | 296 for (; it != children->end() && |
297 bytes_read + sizeof(struct dirent) <= count; | 297 bytes_read + sizeof(struct dirent) <= count; |
298 ++it) { | 298 ++it) { |
299 memset(dir, 0, sizeof(struct dirent)); | 299 memset(dir, 0, sizeof(struct dirent)); |
300 // We want d_ino to be non-zero because readdir() | 300 // We want d_ino to be non-zero because readdir() |
301 // will return null if d_ino is zero. | 301 // will return null if d_ino is zero. |
302 dir->d_ino = 0x60061E; | 302 dir->d_ino = 0x60061E; |
303 dir->d_reclen = sizeof(struct dirent); | 303 dir->d_reclen = sizeof(struct dirent); |
304 dir->d_reclen = sizeof(struct dirent); | |
305 strncpy(dir->d_name, slots_.At(*it)->name().c_str(), sizeof(dir->d_name)); | 304 strncpy(dir->d_name, slots_.At(*it)->name().c_str(), sizeof(dir->d_name)); |
306 ++dir; | 305 ++dir; |
307 ++pos; | 306 ++pos; |
308 bytes_read += sizeof(struct dirent); | 307 bytes_read += sizeof(struct dirent); |
309 } | 308 } |
310 return bytes_read; | 309 return bytes_read; |
311 } | 310 } |
312 | 311 |
313 ssize_t MemMount::Read(ino_t slot, off_t offset, void *buf, size_t count) { | 312 ssize_t MemMount::Read(ino_t slot, off_t offset, void *buf, size_t count) { |
314 MemNode *node = slots_.At(slot); | 313 MemNode *node = slots_.At(slot); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 350 } |
352 | 351 |
353 // Write out the block. | 352 // Write out the block. |
354 memcpy(node->data() + offset, buf, count); | 353 memcpy(node->data() + offset, buf, count); |
355 offset += count; | 354 offset += count; |
356 if (offset > static_cast<off_t>(node->len())) { | 355 if (offset > static_cast<off_t>(node->len())) { |
357 node->set_len(offset); | 356 node->set_len(offset); |
358 } | 357 } |
359 return count; | 358 return count; |
360 } | 359 } |
OLD | NEW |