1 /* 2 * Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "PackageNode.h" 8 9 #include <stdlib.h> 10 #include <string.h> 11 12 #include "DebugSupport.h" 13 #include "Package.h" 14 15 16 PackageNode::PackageNode(Package* package, mode_t mode) 17 : 18 fPackage(package), 19 fParent(NULL), 20 fName(), 21 fMode(mode), 22 fUserID(0), 23 fGroupID(0) 24 { 25 } 26 27 28 PackageNode::~PackageNode() 29 { 30 while (PackageNodeAttribute* attribute = fAttributes.RemoveHead()) 31 delete attribute; 32 } 33 34 35 status_t 36 PackageNode::Init(PackageDirectory* parent, const String& name) 37 { 38 fParent = parent; 39 fName = name; 40 return B_OK; 41 } 42 43 44 status_t 45 PackageNode::VFSInit(dev_t deviceID, ino_t nodeID) 46 { 47 // open the package 48 int fd = fPackage->Open(); 49 if (fd < 0) 50 RETURN_ERROR(fd); 51 52 fPackage->AcquireReference(); 53 return B_OK; 54 } 55 56 57 void 58 PackageNode::VFSUninit() 59 { 60 fPackage->Close(); 61 fPackage->ReleaseReference(); 62 } 63 64 65 off_t 66 PackageNode::FileSize() const 67 { 68 return 0; 69 } 70 71 72 void 73 PackageNode::AddAttribute(PackageNodeAttribute* attribute) 74 { 75 fAttributes.Add(attribute); 76 } 77 78 79 void 80 PackageNode::RemoveAttribute(PackageNodeAttribute* attribute) 81 { 82 fAttributes.Remove(attribute); 83 } 84 85 86 PackageNodeAttribute* 87 PackageNode::FindAttribute(const StringKey& name) const 88 { 89 for (PackageNodeAttributeList::ConstIterator it = fAttributes.GetIterator(); 90 PackageNodeAttribute* attribute = it.Next();) { 91 if (name == attribute->Name()) 92 return attribute; 93 } 94 95 return NULL; 96 } 97 98 99 void 100 PackageNode::UnsetIndexCookie(void* attributeCookie) 101 { 102 ((PackageNodeAttribute*)attributeCookie)->SetIndexCookie(NULL); 103 } 104