| OLD | NEW |
| (Empty) |
| 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 | |
| 3 * found in the LICENSE file. | |
| 4 */ | |
| 5 #include "nacl_mounts/mount_node.h" | |
| 6 | |
| 7 #include <errno.h> | |
| 8 #include <fcntl.h> | |
| 9 #include <string.h> | |
| 10 #include <sys/stat.h> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "nacl_mounts/mount.h" | |
| 14 #include "utils/auto_lock.h" | |
| 15 | |
| 16 static const int USR_ID = 1001; | |
| 17 static const int GRP_ID = 1002; | |
| 18 | |
| 19 MountNode::MountNode(Mount* mount) | |
| 20 : mount_(mount) { | |
| 21 memset(&stat_, 0, sizeof(stat_)); | |
| 22 stat_.st_gid = GRP_ID; | |
| 23 stat_.st_uid = USR_ID; | |
| 24 | |
| 25 // Mount should normally never be NULL, but may be null in tests. | |
| 26 if (mount_) | |
| 27 mount_->OnNodeCreated(this); | |
| 28 } | |
| 29 | |
| 30 MountNode::~MountNode() { | |
| 31 } | |
| 32 | |
| 33 bool MountNode::Init(int perm) { | |
| 34 stat_.st_mode |= perm; | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 void MountNode::Destroy() { | |
| 39 if (mount_) { | |
| 40 mount_->OnNodeDestroyed(this); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 int MountNode::FSync() { | |
| 45 return 0; | |
| 46 } | |
| 47 | |
| 48 int MountNode::GetDents(size_t offs, struct dirent* pdir, size_t count) { | |
| 49 errno = ENOTDIR; | |
| 50 return -1; | |
| 51 } | |
| 52 | |
| 53 int MountNode::GetStat(struct stat* pstat) { | |
| 54 AutoLock lock(&lock_); | |
| 55 memcpy(pstat, &stat_, sizeof(stat_)); | |
| 56 return 0; | |
| 57 } | |
| 58 | |
| 59 int MountNode::Ioctl(int request, char* arg) { | |
| 60 errno = EINVAL; | |
| 61 return -1; | |
| 62 } | |
| 63 | |
| 64 int MountNode::Read(size_t offs, void* buf, size_t count) { | |
| 65 errno = EINVAL; | |
| 66 return -1; | |
| 67 } | |
| 68 | |
| 69 int MountNode::Truncate(size_t size) { | |
| 70 errno = EINVAL; | |
| 71 return -1; | |
| 72 } | |
| 73 | |
| 74 int MountNode::Write(size_t offs, const void* buf, size_t count) { | |
| 75 errno = EINVAL; | |
| 76 return -1; | |
| 77 } | |
| 78 | |
| 79 int MountNode::GetLinks() { | |
| 80 return stat_.st_nlink; | |
| 81 } | |
| 82 | |
| 83 int MountNode::GetMode() { | |
| 84 return stat_.st_mode & ~S_IFMT; | |
| 85 } | |
| 86 | |
| 87 size_t MountNode::GetSize() { | |
| 88 return stat_.st_size; | |
| 89 } | |
| 90 | |
| 91 int MountNode::GetType() { | |
| 92 return stat_.st_mode & S_IFMT; | |
| 93 } | |
| 94 | |
| 95 bool MountNode::IsaDir() { | |
| 96 return (stat_.st_mode & S_IFDIR) != 0; | |
| 97 } | |
| 98 | |
| 99 bool MountNode::IsaFile() { | |
| 100 return (stat_.st_mode & S_IFREG) != 0; | |
| 101 } | |
| 102 | |
| 103 bool MountNode::IsaTTY() { | |
| 104 return (stat_.st_mode & S_IFCHR) != 0; | |
| 105 } | |
| 106 | |
| 107 | |
| 108 int MountNode:: AddChild(const std::string& name, MountNode* node) { | |
| 109 errno = ENOTDIR; | |
| 110 return -1; | |
| 111 } | |
| 112 | |
| 113 int MountNode::RemoveChild(const std::string& name) { | |
| 114 errno = ENOTDIR; | |
| 115 return -1; | |
| 116 } | |
| 117 | |
| 118 MountNode* MountNode::FindChild(const std::string& name) { | |
| 119 errno = ENOTDIR; | |
| 120 return NULL; | |
| 121 } | |
| 122 | |
| 123 int MountNode::ChildCount() { | |
| 124 errno = ENOTDIR; | |
| 125 return -1; | |
| 126 } | |
| 127 | |
| 128 void MountNode::Link() { | |
| 129 Acquire(); | |
| 130 stat_.st_nlink++; | |
| 131 } | |
| 132 | |
| 133 void MountNode::Unlink() { | |
| 134 stat_.st_nlink--; | |
| 135 Release(); | |
| 136 } | |
| OLD | NEW |