| 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_mounts/mount_node_mem.h" | 5 #include "nacl_mounts/mount_node_mem.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "nacl_mounts/osstat.h" | 10 #include "nacl_mounts/osstat.h" |
| 11 #include "utils/auto_lock.h" | 11 #include "utils/auto_lock.h" |
| 12 | 12 |
| 13 #define BLOCK_SIZE (1 << 16) | 13 #define BLOCK_SIZE (1 << 16) |
| 14 #define BLOCK_MASK (BLOCK_SIZE - 1) | 14 #define BLOCK_MASK (BLOCK_SIZE - 1) |
| 15 | 15 |
| 16 MountNodeMem::MountNodeMem(Mount *mount, int ino, int dev) | 16 MountNodeMem::MountNodeMem(Mount *mount) |
| 17 : MountNode(mount, ino, dev), | 17 : MountNode(mount), |
| 18 data_(NULL), | 18 data_(NULL), |
| 19 capacity_(0) { | 19 capacity_(0) { |
| 20 stat_.st_mode |= S_IFREG; |
| 20 } | 21 } |
| 21 | 22 |
| 22 MountNodeMem::~MountNodeMem() { | 23 MountNodeMem::~MountNodeMem() { |
| 23 free(data_); | 24 free(data_); |
| 24 } | 25 } |
| 25 | 26 |
| 26 bool MountNodeMem::Init(int mode, short uid, short gid) { | |
| 27 bool ok = MountNode::Init(mode, uid, gid); | |
| 28 stat_.st_mode |= S_IFREG; | |
| 29 return ok; | |
| 30 } | |
| 31 | |
| 32 int MountNodeMem::Read(size_t offs, void *buf, size_t count) { | 27 int MountNodeMem::Read(size_t offs, void *buf, size_t count) { |
| 33 AutoLock lock(&lock_); | 28 AutoLock lock(&lock_); |
| 34 if (count == 0) return 0; | 29 if (count == 0) return 0; |
| 35 if (offs + count > GetSize()) { | 30 if (offs + count > GetSize()) { |
| 36 count = GetSize() - offs; | 31 count = GetSize() - offs; |
| 37 } | 32 } |
| 38 | 33 |
| 39 memcpy(buf, &data_[offs], count); | 34 memcpy(buf, &data_[offs], count); |
| 40 return static_cast<int>(count); | 35 return static_cast<int>(count); |
| 41 } | 36 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 72 } |
| 78 | 73 |
| 79 // If we failed, then adjust size according to what we keep | 74 // If we failed, then adjust size according to what we keep |
| 80 if (size > capacity_) size = capacity_; | 75 if (size > capacity_) size = capacity_; |
| 81 | 76 |
| 82 // Update the size and return the new size | 77 // Update the size and return the new size |
| 83 stat_.st_size = static_cast<off_t>(size); | 78 stat_.st_size = static_cast<off_t>(size); |
| 84 errno = EIO; | 79 errno = EIO; |
| 85 return -1; | 80 return -1; |
| 86 } | 81 } |
| OLD | NEW |