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 fChildTable.Insert(node); 83 fChildList.Add(node); 84 node->AcquireReference(); 85 } 86 87 88 void 89 Directory::RemoveChild(Node* node) 90 { 91 Node* nextNode = fChildList.GetNext(node); 92 93 fChildTable.Remove(node); 94 fChildList.Remove(node); 95 node->ReleaseReference(); 96 97 // adjust directory iterators pointing to the removed child 98 for (DirectoryIteratorList::Iterator it = fIterators.GetIterator(); 99 DirectoryIterator* iterator = it.Next();) { 100 if (iterator->node == node) 101 iterator->node = nextNode; 102 } 103 } 104 105 106 Node* 107 Directory::FindChild(const StringKey& name) 108 { 109 return fChildTable.Lookup(name); 110 } 111 112 113 void 114 Directory::AddDirectoryIterator(DirectoryIterator* iterator) 115 { 116 fIterators.Add(iterator); 117 } 118 119 120 void 121 Directory::RemoveDirectoryIterator(DirectoryIterator* iterator) 122 { 123 fIterators.Remove(iterator); 124 } 125