| 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_mem.h" | 5 #include "nacl_mounts/mount_mem.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 return (bool) (root_ != NULL); | 32 return (bool) (root_ != NULL); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void MountMem::Destroy() { | 35 void MountMem::Destroy() { |
| 36 if (root_) | 36 if (root_) |
| 37 root_->Release(); | 37 root_->Release(); |
| 38 root_ = NULL; | 38 root_ = NULL; |
| 39 } | 39 } |
| 40 | 40 |
| 41 MountNode* MountMem::AllocatePath(int mode) { | 41 MountNode* MountMem::AllocatePath(int mode) { |
| 42 ino_t ino = AllocateINO(); | 42 MountNode *ptr = new MountNodeDir(this); |
| 43 | 43 if (!ptr->Init(mode)) { |
| 44 MountNode *ptr = new MountNodeDir(this, ino, dev_); | |
| 45 if (!ptr->Init(mode, USR_ID, GRP_ID)) { | |
| 46 ptr->Release(); | 44 ptr->Release(); |
| 47 FreeINO(ino); | |
| 48 return NULL; | 45 return NULL; |
| 49 } | 46 } |
| 50 return ptr; | 47 return ptr; |
| 51 } | 48 } |
| 52 | 49 |
| 53 MountNode* MountMem::AllocateData(int mode) { | 50 MountNode* MountMem::AllocateData(int mode) { |
| 54 ino_t ino = AllocateINO(); | 51 MountNode* ptr = new MountNodeMem(this); |
| 55 | 52 if (!ptr->Init(mode)) { |
| 56 MountNode* ptr = new MountNodeMem(this, ino, dev_); | |
| 57 //if (!ptr->Init(mode, getuid(), getgid())) { | |
| 58 if (!ptr->Init(mode, USR_ID, GRP_ID)) { | |
| 59 ptr->Release(); | 53 ptr->Release(); |
| 60 FreeINO(ino); | |
| 61 return NULL; | 54 return NULL; |
| 62 } | 55 } |
| 63 return ptr; | 56 return ptr; |
| 64 } | 57 } |
| 65 | 58 |
| 66 int MountMem::AllocateINO() { | |
| 67 const int INO_CNT = 8; | |
| 68 | |
| 69 // If we run out of INO numbers, then allocate 8 more | |
| 70 if (inos_.size() == 0) { | |
| 71 max_ino_ += INO_CNT; | |
| 72 // Add eight more to the stack in reverse order, offset by 1 | |
| 73 // since '0' refers to no INO. | |
| 74 for (int a = 0; a < INO_CNT; a++) { | |
| 75 inos_.push_back(max_ino_ - a); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 // Return the INO at the top of the stack. | |
| 80 int val = inos_.back(); | |
| 81 inos_.pop_back(); | |
| 82 return val; | |
| 83 } | |
| 84 | |
| 85 void MountMem::FreeINO(int ino) { | |
| 86 inos_.push_back(ino); | |
| 87 } | |
| 88 | |
| 89 MountNode* MountMem::FindNode(const Path& path, int type) { | 59 MountNode* MountMem::FindNode(const Path& path, int type) { |
| 90 MountNode* node = root_; | 60 MountNode* node = root_; |
| 91 | 61 |
| 92 // If there is no root there, we have an error. | 62 // If there is no root there, we have an error. |
| 93 if (node == NULL) { | 63 if (node == NULL) { |
| 94 errno = ENOTDIR; | 64 errno = ENOTDIR; |
| 95 return NULL; | 65 return NULL; |
| 96 } | 66 } |
| 97 | 67 |
| 98 // We are expecting an "absolute" path from this mount point. | 68 // We are expecting an "absolute" path from this mount point. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 if (file_only && child->IsaDir()) { | 242 if (file_only && child->IsaDir()) { |
| 273 errno = EISDIR; | 243 errno = EISDIR; |
| 274 return -1; | 244 return -1; |
| 275 } | 245 } |
| 276 if (remove_dir && child->ChildCount() > 0) { | 246 if (remove_dir && child->ChildCount() > 0) { |
| 277 errno = ENOTEMPTY; | 247 errno = ENOTEMPTY; |
| 278 return -1; | 248 return -1; |
| 279 } | 249 } |
| 280 return parent->RemoveChild(path.Basename()); | 250 return parent->RemoveChild(path.Basename()); |
| 281 } | 251 } |
| OLD | NEW |