2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef BOOT_LOADER_FILE_SYSTEMS_PACKAGEFS_PACKAGE_SETTINGS_ITEM_H
6 #define BOOT_LOADER_FILE_SYSTEMS_PACKAGEFS_PACKAGE_SETTINGS_ITEM_H
11 #include <util/OpenHashTable.h>
12 #include <util/StringHash.h>
15 struct driver_parameter
;
22 class PackageSettingsItem
{
30 fIsBlackListed(false),
40 bool SetName(const char* name
, size_t nameLength
)
42 fName
= (char*)malloc(nameLength
+ 1);
46 memcpy(fName
, name
, nameLength
);
47 fName
[nameLength
] = '\0';
56 const char* Name() const
61 bool IsBlackListed() const
63 return fIsBlackListed
;
66 void SetBlackListed(bool blackListed
)
68 fIsBlackListed
= blackListed
;
85 EntryKey(Entry
* parent
, const char* name
, size_t nameLength
)
89 fNameLength(nameLength
)
93 EntryKey(Entry
* parent
, const char* name
)
97 fNameLength(strlen(name
))
101 Entry
* Parent() const
106 const char* Name() const
111 size_t NameLength() const
118 return (addr_t
)fParent
/ 8
119 ^ hash_hash_string_part(fName
, fNameLength
);
129 PackageSettingsItem();
130 ~PackageSettingsItem();
132 static PackageSettingsItem
* Load(::Directory
* systemDirectory
,
135 status_t
Init(const driver_parameter
& parameter
);
137 void AddEntry(Entry
* entry
);
138 status_t
AddEntry(const char* path
, Entry
*& _entry
);
139 Entry
* FindEntry(Entry
* parent
, const char* name
)
141 Entry
* FindEntry(Entry
* parent
, const char* name
,
142 size_t nameLength
) const;
144 PackageSettingsItem
*& HashNext()
145 { return fHashNext
; }
148 struct EntryHashDefinition
{
149 typedef EntryKey KeyType
;
150 typedef Entry ValueType
;
152 size_t HashKey(const EntryKey
& key
) const
157 size_t Hash(const Entry
* value
) const
159 return HashKey(EntryKey(value
->Parent(), value
->Name()));
162 bool Compare(const EntryKey
& key
, const Entry
* value
) const
164 const char* name
= value
->Name();
165 return key
.Parent() == value
->Parent()
166 && strncmp(key
.Name(), name
, key
.NameLength()) == 0
167 && name
[key
.NameLength()] == '\0';
170 Entry
*& GetLink(Entry
* value
) const
172 return value
->HashNext();
176 typedef BOpenHashTable
<EntryHashDefinition
> EntryTable
;
179 status_t
_AddBlackListedEntries(
180 const driver_parameter
& parameter
);
184 PackageSettingsItem
* fHashNext
;
188 } // namespace PackageFS
191 #endif // BOOT_LOADER_FILE_SYSTEMS_PACKAGEFS_PACKAGE_SETTINGS_ITEM_H