1 /* 2 * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "Directory.h" 8 9 #include "DebugSupport.h" 10 #include "UnpackingAttributeCookie.h" 11 #include "UnpackingAttributeDirectoryCookie.h" 12 #include "Utils.h" 13 14 15 Directory::Directory(ino_t id) 16 : 17 Node(id) 18 { 19 } 20 21 22 Directory::~Directory() 23 { 24 Node* child = fChildTable.Clear(true); 25 while (child != NULL) { 26 Node* next = child->NameHashTableNext(); 27 child->ReleaseReference(); 28 child = next; 29 } 30 } 31 32 33 status_t 34 Directory::Init(Directory* parent, const String& name) 35 { 36 status_t error = Node::Init(parent, name); 37 if (error != B_OK) 38 return error; 39 40 return fChildTable.Init(); 41 } 42 43 44 mode_t 45 Directory::Mode() const 46 { 47 return S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 48 } 49 50 51 off_t 52 Directory::FileSize() const 53 { 54 return 0; 55 } 56 57 58 status_t 59 Directory::Read(off_t offset, void* buffer, size_t* bufferSize) 60 { 61 return B_IS_A_DIRECTORY; 62 } 63 64 65 status_t 66 Directory::Read(io_request* request) 67 { 68 return B_IS_A_DIRECTORY; 69 } 70 71 72 status_t 73 Directory::ReadSymlink(void* buffer, size_t* bufferSize) 74 { 75 return B_IS_A_DIRECTORY; 76 } 77 78 79 void 80 Directory::AddChild(Node* node) 81 { 82 ASSERT_WRITE_LOCKED_RW_LOCK(&fLock); 83 fChildTable.Insert(node); 84 fChildList.Add(node); 85 node->AcquireReference(); 86 } 87 88 89 void 90 Directory::RemoveChild(Node* node) 91 { 92 Node* nextNode = fChildList.GetNext(node); 93 94 fChildTable.Remove(node); 95 fChildList.Remove(node); 96 node->ReleaseReference(); 97 98 // adjust directory iterators pointing to the removed child 99 for (DirectoryIteratorList::Iterator it = fIterators.GetIterator(); 100 DirectoryIterator* iterator = it.Next();) { 101 if (iterator->node == node) 102 iterator->node = nextNode; 103 } 104 } 105 106 107 Node* 108 Directory::FindChild(const StringKey& name) 109 { 110 return fChildTable.Lookup(name); 111 } 112 113 114 void 115 Directory::AddDirectoryIterator(DirectoryIterator* iterator) 116 { 117 fIterators.Add(iterator); 118 } 119 120 121 void 122 Directory::RemoveDirectoryIterator(DirectoryIterator* iterator) 123 { 124 fIterators.Remove(iterator); 125 } 126