ramfs: Lots of fixes to the build.

* Store pointers in an addr_t instead of int32, for 64-bit's sake
 * Use DebugSupport.h instead of userlandfs Debug.h and remove extra parentheses
 * Create a header-only String class based on the userlandfs String and use it
 * RecursiveLock instead of Locker.
 * Jamfile cleanups and other misc. changes.

It isn't yet adapted to the new VFS API, so the build is still somewhat
broken.
This commit is contained in:
Augustin Cavalier
2018-08-22 19:19:56 -04:00
parent c7919fc71a
commit a41d815c67
27 changed files with 340 additions and 147 deletions
+1 -1
View File
@@ -570,7 +570,7 @@ rule ArchitectureSetupWarnings architecture
EnableWerror src add-ons kernel file_systems nfs4 ;
# EnableWerror src add-ons kernel file_systems ntfs ;
EnableWerror src add-ons kernel file_systems packagefs ;
EnableWerror src add-ons kernel file_systems ramfs ;
# EnableWerror src add-ons kernel file_systems ramfs ;
# EnableWerror src add-ons kernel file_systems reiserfs ;
EnableWerror src add-ons kernel file_systems udf ;
EnableWerror src add-ons kernel file_systems userlandfs ;
@@ -1,7 +1,7 @@
// AllocationInfo.cpp
#include "AllocationInfo.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Attribute.h"
#include "Directory.h"
@@ -28,7 +28,7 @@
#include <OS.h>
#include "AreaUtils.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Misc.h"
#ifndef USE_STANDARD_FUNCTIONS
@@ -79,8 +79,8 @@ AreaUtils::free(void *ptr)
// everything is fine, delete the area
delete_area(info.area);
} else {
INFORM(("WARNING: AreaUtils::free(%p): area begin is %p."
"Ignored.\n", ptr, info.address));
INFORM("WARNING: AreaUtils::free(%p): area begin is %p."
"Ignored.\n", ptr, info.address);
}
}
}
@@ -149,8 +149,8 @@ AreaUtils::realloc(void * ptr, size_t size)
}
}
} else {
INFORM(("WARNING: AreaUtils::realloc(%p): area begin is %p."
"Ignored.\n", ptr, info.address));
INFORM("WARNING: AreaUtils::realloc(%p): area begin is %p."
"Ignored.\n", ptr, info.address);
}
}
}
@@ -3,7 +3,7 @@
#include <TypeConstants.h>
#include "AttributeIndexImpl.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Entry.h"
#include "EntryListener.h"
#include "IndexImpl.h"
@@ -377,16 +377,16 @@ AttributeIndexImpl::Iterator::GetCurrent(uint8 *buffer, size_t *keyLength)
if ((*attribute)->GetNode() == entry->GetNode()) {
(*attribute)->GetKey(buffer, keyLength);
} else {
FATAL(("Node of current attribute and node of current entry "
FATAL("Node of current attribute and node of current entry "
"differ: %Ld vs. %Ld\n",
(*attribute)->GetNode()->GetID(),
entry->GetNode()->GetID()));
entry->GetNode()->GetID());
entry = NULL;
}
} else {
FATAL(("We have a current entry (`%s', node: %Ld), but no current "
FATAL("We have a current entry (`%s', node: %Ld), but no current "
"attribute.\n", entry->GetName(),
entry->GetNode()->GetID()));
entry->GetNode()->GetID());
entry = NULL;
}
}
@@ -7,7 +7,7 @@
#include "BlockAllocator.h"
#include "BlockAllocatorArea.h"
#include "BlockAllocatorAreaBucket.h"
#include "Debug.h"
#include "DebugSupport.h"
// BlockAllocator
@@ -175,15 +175,15 @@ BlockAllocator::SanityCheck(bool deep) const
}
// area count
if (areaCount != fAreaCount) {
FATAL(("fAreaCount is %ld, but should be %ld\n", fAreaCount,
areaCount));
FATAL("fAreaCount is %ld, but should be %ld\n", fAreaCount,
areaCount);
BA_PANIC("BlockAllocator: Bad free bytes.");
return false;
}
// free bytes
if (fFreeBytes != freeBytes) {
FATAL(("fFreeBytes is %lu, but should be %lu\n", fFreeBytes,
freeBytes));
FATAL("fFreeBytes is %lu, but should be %lu\n", fFreeBytes,
freeBytes);
BA_PANIC("BlockAllocator: Bad free bytes.");
return false;
}
@@ -203,7 +203,7 @@ BlockAllocator::CheckArea(Area *checkArea)
return true;
}
}
FATAL(("Area %p is not a valid Area!\n", checkArea));
FATAL("Area %p is not a valid Area!\n", checkArea);
BA_PANIC("Invalid Area.");
return false;
}
@@ -7,7 +7,7 @@
#include "Block.h"
#include "BlockReferenceManager.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "List.h"
#define ENABLE_BA_PANIC 1
@@ -1,7 +1,7 @@
// BlockAllocatorArea.cpp
#include "BlockAllocatorArea.h"
#include "Debug.h"
#include "DebugSupport.h"
// constructor
BlockAllocator::Area::Area(area_id id, size_t size)
@@ -58,8 +58,8 @@ Block *
BlockAllocator::Area::AllocateBlock(size_t usableSize, bool dontDefragment)
{
if (kMinBlockSize != block_align_ceil(sizeof(TFreeBlock))) {
FATAL(("kMinBlockSize is not correctly initialized! Is %lu, but should be: "
"%lu\n", kMinBlockSize, block_align_ceil(sizeof(TFreeBlock))));
FATAL("kMinBlockSize is not correctly initialized! Is %lu, but should be: "
"%lu\n", kMinBlockSize, block_align_ceil(sizeof(TFreeBlock)));
BA_PANIC("kMinBlockSize not correctly initialized.");
return NULL;
}
@@ -80,9 +80,9 @@ return NULL;
// Our data structures seem to be corrupted, since
// _GetBlockFreeBytes() promised that we would have enough
// free space.
FATAL(("Couldn't find free block of min size %lu after "
FATAL("Couldn't find free block of min size %lu after "
"defragmenting, although we should have %lu usable free "
"bytes!\n", size, _GetBlockFreeBytes()));
"bytes!\n", size, _GetBlockFreeBytes());
BA_PANIC("Bad area free bytes.");
}
}
@@ -247,22 +247,22 @@ BlockAllocator::Area::SanityCheck() const
{
// area ID
if (fID < 0) {
FATAL(("Area ID < 0: %lx\n", fID));
FATAL("Area ID < 0: %lx\n", fID);
BA_PANIC("Bad area ID.");
return false;
}
// size
size_t areaHeaderSize = block_align_ceil(sizeof(Area));
if (fSize < areaHeaderSize + sizeof(TFreeBlock)) {
FATAL(("Area too small to contain area header and at least one free "
"block: %lu bytes\n", fSize));
FATAL("Area too small to contain area header and at least one free "
"block: %lu bytes\n", fSize);
BA_PANIC("Bad area size.");
return false;
}
// free bytes
if (fFreeBytes > fSize) {
FATAL(("Free size greater than area size: %lu vs %lu\n", fFreeBytes,
fSize));
FATAL("Free size greater than area size: %lu vs %lu\n", fFreeBytes,
fSize);
BA_PANIC("Bad area free bytes.");
return false;
}
@@ -277,8 +277,8 @@ BlockAllocator::Area::SanityCheck() const
uint32 freeBlockCount = 0;
size_t freeBytes = 0;
if (!fFirstBlock || !fLastBlock) {
FATAL(("Invalid block list: first or last block NULL: first: %p, "
"last: %p\n", fFirstBlock, fLastBlock));
FATAL("Invalid block list: first or last block NULL: first: %p, "
"last: %p\n", fFirstBlock, fLastBlock);
BA_PANIC("Bad area block list.");
return false;
} else {
@@ -292,42 +292,42 @@ BlockAllocator::Area::SanityCheck() const
for (int32 i = 0; i < blockCount; i++) {
blockListOK = false;
if (!block) {
FATAL(("Encountered NULL in block list at index %ld, although "
"list should have %ld blocks\n", i, blockCount));
FATAL("Encountered NULL in block list at index %ld, although "
"list should have %ld blocks\n", i, blockCount);
BA_PANIC("Bad area block list.");
return false;
}
uint64 address = (uint32)block;
uint64 address = (addr_t)block;
// block within area?
if (address < (uint32)this + areaHeaderSize
|| address + sizeof(TFreeBlock) > (uint32)this + fSize) {
FATAL(("Utterly mislocated block: %p, area: %p, "
"size: %lu\n", block, this, fSize));
if (address < (addr_t)this + areaHeaderSize
|| address + sizeof(TFreeBlock) > (addr_t)this + fSize) {
FATAL("Utterly mislocated block: %p, area: %p, "
"size: %lu\n", block, this, fSize);
BA_PANIC("Bad area block.");
return false;
}
// block too large for area?
size_t blockSize = block->GetSize();
if (blockSize < sizeof(TFreeBlock)
|| address + blockSize > (uint32)this + fSize) {
FATAL(("Mislocated block: %p, size: %lu, area: %p, "
"size: %lu\n", block, blockSize, this, fSize));
|| address + blockSize > (addr_t)this + fSize) {
FATAL("Mislocated block: %p, size: %lu, area: %p, "
"size: %lu\n", block, blockSize, this, fSize);
BA_PANIC("Bad area block.");
return false;
}
// alignment
if (block_align_floor(address) != address
|| block_align_floor(blockSize) != blockSize) {
FATAL(("Block %ld not properly aligned: %p, size: %lu\n",
i, block, blockSize));
FATAL("Block %ld not properly aligned: %p, size: %lu\n",
i, block, blockSize);
BA_PANIC("Bad area block.");
return false;
}
// previous block
if (block->GetPreviousBlock() != prevBlock) {
FATAL(("Previous block of block %ld was not the previous "
FATAL("Previous block of block %ld was not the previous "
"block in list: %p vs %p\n", i,
block->GetPreviousBlock(), prevBlock));
block->GetPreviousBlock(), prevBlock);
BA_PANIC("Bad area block list.");
return false;
}
@@ -341,16 +341,16 @@ BlockAllocator::Area::SanityCheck() const
freeBytes += freeBlock->GetUsableSize();
// block == next free block of previous free block
if (freeBlock != nextFree) {
FATAL(("Free block %ld is not the next block in free "
"list: %p vs %p\n", i, freeBlock, nextFree));
FATAL("Free block %ld is not the next block in free "
"list: %p vs %p\n", i, freeBlock, nextFree);
BA_PANIC("Bad area free list.");
return false;
}
// previous free block
if (freeBlock->GetPreviousFreeBlock() != prevFree) {
FATAL(("Previous free block of block %ld was not the "
FATAL("Previous free block of block %ld was not the "
" previous block in free list: %p vs %p\n", i,
freeBlock->GetPreviousFreeBlock(), prevFree));
freeBlock->GetPreviousFreeBlock(), prevFree);
BA_PANIC("Bad area free list.");
return false;
}
@@ -365,37 +365,37 @@ BlockAllocator::Area::SanityCheck() const
// final checks on block list
if (blockListOK) {
if (block) {
FATAL(("More blocks in block list than expected\n"));
FATAL("More blocks in block list than expected\n");
BA_PANIC("Bad area block count.");
return false;
} else if (fLastBlock != prevBlock) {
FATAL(("last block in block list was %p, but should be "
"%p\n", fLastBlock, prevBlock));
FATAL("last block in block list was %p, but should be "
"%p\n", fLastBlock, prevBlock);
BA_PANIC("Bad area last block.");
return false;
} else if (prevFree != fLastFree) {
FATAL(("last block in free list was %p, but should be %p\n",
fLastFree, prevFree));
FATAL("last block in free list was %p, but should be %p\n",
fLastFree, prevFree);
BA_PANIC("Bad area last free block.");
return false;
}
// block counts (a bit reduntant)
if (freeBlockCount != fFreeBlockCount) {
FATAL(("Free block count is %ld, but should be %ld\n",
fFreeBlockCount, freeBlockCount));
FATAL("Free block count is %ld, but should be %ld\n",
fFreeBlockCount, freeBlockCount);
BA_PANIC("Bad area free block count.");
return false;
}
if (usedBlockCount != fUsedBlockCount) {
FATAL(("Used block count is %ld, but should be %ld\n",
fUsedBlockCount, usedBlockCount));
FATAL("Used block count is %ld, but should be %ld\n",
fUsedBlockCount, usedBlockCount);
BA_PANIC("Bad area used block count.");
return false;
}
// free bytes
if (fFreeBytes != freeBytes) {
FATAL(("Free bytes is %lu, but should be %lu\n",
fFreeBytes, freeBytes));
FATAL("Free bytes is %lu, but should be %lu\n",
fFreeBytes, freeBytes);
BA_PANIC("Bad area free bytes.");
return false;
}
@@ -412,7 +412,7 @@ BlockAllocator::Area::CheckBlock(Block *checkBlock, size_t minSize)
if (block == checkBlock)
return (block->GetUsableSize() >= minSize);
}
FATAL(("Block %p is not in area %p!\n", checkBlock, this));
FATAL("Block %p is not in area %p!\n", checkBlock, this);
BA_PANIC("Invalid Block.");
return false;
}
@@ -441,7 +441,7 @@ BlockAllocator::Area::_InsertFreeBlock(TFreeBlock *block)
for (nextFree = GetFirstFreeBlock();
nextFree;
nextFree = nextFree->GetNextFreeBlock()) {
if ((uint32)nextFree > (uint32)block)
if ((addr_t)nextFree > (addr_t)block)
break;
}
// get the previous block and insert the block between the two
@@ -32,16 +32,16 @@ BlockAllocator::AreaBucket::SanityCheck(bool deep) const
}
// bucket
if (area->GetBucket() != this) {
FATAL(("Area %p is in bucket %p, but thinks it is in bucket %p\n",
area, this, area->GetBucket()));
FATAL("Area %p is in bucket %p, but thinks it is in bucket %p\n",
area, this, area->GetBucket());
BA_PANIC("Wrong area bucket.");
return false;
}
// size
size_t areaSize = area->GetFreeBytes();
if (areaSize < fMinSize || areaSize >= fMaxSize) {
FATAL(("Area is in wrong bucket: free: %lu, min: %lu, max: %lu\n",
areaSize, fMinSize, fMaxSize));
FATAL("Area is in wrong bucket: free: %lu, min: %lu, max: %lu\n",
areaSize, fMinSize, fMaxSize);
BA_PANIC("Area in wrong bucket.");
return false;
}
@@ -7,7 +7,7 @@
#include "BlockAllocator.h"
#include "BlockAllocatorArea.h"
#include "Debug.h"
#include "DebugSupport.h"
class BlockAllocator::AreaBucket {
@@ -4,7 +4,7 @@
#include "Block.h"
#include "BlockAllocator.h" // only for BA_PANIC
#include "BlockReferenceManager.h"
#include "Debug.h"
#include "DebugSupport.h"
static const int kBlockReferenceTableSize = 128;
@@ -49,17 +49,17 @@ bool
BlockReferenceManager::CheckReference(BlockReference *reference)
{
if (reference) {
uint32 address = (uint32)reference;
uint32 address = (addr_t)reference;
int32 tableCount = fTables.CountItems();
for (int32 i = 0; i < tableCount; i++) {
Table *table = &fTables.ItemAt(i);
uint32 first = (uint32)table->GetReferences();
uint32 last = (uint32)(table->GetReferences() + table->GetSize());
uint32 first = (addr_t)table->GetReferences();
uint32 last = (addr_t)(table->GetReferences() + table->GetSize());
if (first <= address && address < last)
return true;
}
}
FATAL(("BlockReference %p does not exist!\n", reference));
FATAL("BlockReference %p does not exist!\n", reference);
BA_PANIC("BlockReference doesn't exist.");
return false;
}
@@ -4,7 +4,7 @@
#include "Attribute.h" // for debugging only
#include "Block.h"
#include "DataContainer.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Misc.h"
#include "Node.h" // for debugging only
#include "Volume.h"
@@ -405,7 +405,7 @@ DataContainer::_SwitchToSmallBufferMode(size_t newSize)
// remove the first (and only) block
BlockList *blocks = _GetBlockList();
BlockReference *block = blocks->ItemAt(0);
blocks->RemoveItem(0L);
blocks->RemoveItem((int32)0L);
// destroy the block list and copy the data into the small buffer
blocks->~BlockList();
if (newSize > 0)
@@ -1,7 +1,7 @@
// Directory.cpp
#include "AllocationInfo.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Directory.h"
#include "Entry.h"
#include "EntryIterator.h"
@@ -231,8 +231,8 @@ Directory::DeleteEntry(Entry *entry)
if (error == B_OK)
delete entry;
else {
FATAL(("Failed to Unlink() entry %p from node %Ld!\n", entry,
entry->GetNode()->GetID()));
FATAL("Failed to Unlink() entry %p from node %Ld!\n", entry,
entry->GetNode()->GetID());
AddEntry(entry);
}
}
@@ -1,7 +1,7 @@
// Entry.cpp
#include "AllocationInfo.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Entry.h"
#include "EntryIterator.h"
#include "Node.h"
@@ -1,6 +1,6 @@
// Index.cpp
#include "Debug.h"
#include "DebugSupport.h"
#include "Directory.h"
#include "Entry.h"
#include "Index.h"
@@ -3,7 +3,7 @@
#include <TypeConstants.h>
#include "AttributeIndexImpl.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "IndexDirectory.h"
#include "LastModifiedIndex.h"
#include "NameIndex.h"
+30 -40
View File
@@ -1,48 +1,38 @@
SubDir HAIKU_TOP src add-ons kernel file_systems ramfs ;
local userlandFSTop = [ FDirName $(HAIKU_TOP) src add-ons kernel
file_systems userlandfs ] ;
local userlandFSIncludes = [ PrivateHeaders userlandfs ] ;
UsePrivateHeaders shared ;
UsePrivateKernelHeaders ;
SubDirHdrs [ FDirName $(userlandFSIncludes) shared ] ;
SEARCH_SOURCE += [ FDirName $(userlandFSTop) shared ] ;
UsePrivateHeaders file_systems ;
DEFINES += DEBUG_APP="\\\"ramfs\\\"" ;
KernelAddon ramfs
: Debug.cpp
String.cpp
AllocationInfo.cpp
AreaUtils.cpp
Attribute.cpp
AttributeIndex.cpp
AttributeIndexImpl.cpp
AttributeIterator.cpp
BlockAllocator.cpp
BlockAllocatorArea.cpp
BlockAllocatorAreaBucket.cpp
BlockReferenceManager.cpp
DataContainer.cpp
Directory.cpp
Entry.cpp
EntryIterator.cpp
EntryListener.cpp
File.cpp
Index.cpp
IndexDirectory.cpp
kernel_interface.cpp
LastModifiedIndex.cpp
NameIndex.cpp
Node.cpp
NodeListener.cpp
NodeTable.cpp
Query.cpp
SizeIndex.cpp
SymLink.cpp
Volume.cpp
:
AllocationInfo.cpp
AreaUtils.cpp
Attribute.cpp
AttributeIndex.cpp
AttributeIndexImpl.cpp
AttributeIterator.cpp
BlockAllocator.cpp
BlockAllocatorArea.cpp
BlockAllocatorAreaBucket.cpp
BlockReferenceManager.cpp
DataContainer.cpp
Directory.cpp
Entry.cpp
EntryIterator.cpp
EntryListener.cpp
File.cpp
Index.cpp
IndexDirectory.cpp
kernel_interface.cpp
LastModifiedIndex.cpp
NameIndex.cpp
Node.cpp
NodeListener.cpp
NodeTable.cpp
Query.cpp
SizeIndex.cpp
SymLink.cpp
Volume.cpp
;
@@ -2,7 +2,7 @@
#include <TypeConstants.h>
#include "Debug.h"
#include "DebugSupport.h"
#include "Entry.h"
#include "EntryListener.h"
#include "IndexImpl.h"
@@ -2,7 +2,7 @@
#include <TypeConstants.h>
#include "Debug.h"
#include "DebugSupport.h"
#include "Entry.h"
#include "IndexImpl.h"
#include "NameIndex.h"
@@ -1,7 +1,7 @@
// Node.cpp
#include "AllocationInfo.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "EntryIterator.h"
#include "LastModifiedIndex.h"
#include "Node.h"
@@ -4,7 +4,7 @@
#define NODE_CHILD_TABLE_H
#include "AllocationInfo.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Misc.h"
#include "Node.h"
#include "OpenHashTable.h"
@@ -1,6 +1,6 @@
// NodeTable.cpp
#include "Debug.h"
#include "DebugSupport.h"
#include "NodeTable.h"
// constructor
@@ -12,7 +12,7 @@
#include "Query.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Directory.h"
#include "Entry.h"
#include "Misc.h"
@@ -874,7 +874,7 @@ Equation::ConvertValue(type_code type)
fSize = sizeof(double);
break;
default:
FATAL(("query value conversion to 0x%lx requested!\n", type));
FATAL("query value conversion to 0x%lx requested!\n", type);
// should we fail here or just do a safety int32 conversion?
return B_ERROR;
}
@@ -921,7 +921,7 @@ Equation::CompareTo(const uint8 *value, uint16 size)
case OP_GREATER_THAN_OR_EQUAL:
return compare >= 0;
}
FATAL(("Unknown/Unsupported operation: %d\n", fOp));
FATAL("Unknown/Unsupported operation: %d\n", fOp);
return false;
}
@@ -1202,7 +1202,7 @@ Equation::GetNextMatching(Volume *volume, IndexIterator *iterator,
other = parent->Left();
if (other == NULL) {
FATAL(("&&-operator has only one child... (parent = %p)\n", parent));
FATAL("&&-operator has only one child... (parent = %p)\n", parent);
break;
}
status = other->Match(entry, entry->GetNode());
@@ -0,0 +1,203 @@
// String.h
#ifndef STRING_H
#define STRING_H
#include <SupportDefs.h>
#include <string.h>
#include <new>
// string_hash
//
// from the Dragon Book: a slightly modified hashpjw()
static inline
uint32
string_hash(const char *name)
{
uint32 h = 0;
if (name) {
for (; *name; name++) {
uint32 g = h & 0xf0000000;
if (g)
h ^= g >> 24;
h = (h << 4) + *name;
}
}
return h;
}
#ifdef __cplusplus
// String
class String {
public:
inline String();
inline String(const String &string);
inline String(const char *string, int32 length = -1);
inline ~String();
inline bool SetTo(const char *string, int32 maxLength = -1);
inline void Unset();
inline void Truncate(int32 newLength);
inline const char *GetString() const;
inline int32 GetLength() const { return fLength; }
inline uint32 GetHashCode() const { return string_hash(GetString()); }
inline String &operator=(const String &string);
inline bool operator==(const String &string) const;
inline bool operator!=(const String &string) const { return !(*this == string); }
private:
inline bool _SetTo(const char *string, int32 length);
private:
int32 fLength;
char *fString;
};
// strnlen
size_t
strnlen(const char *str, size_t maxLen)
{
if (str) {
size_t origMaxLen = maxLen;
while (maxLen > 0 && *str != '\0') {
maxLen--;
str++;
}
return origMaxLen - maxLen;
}
return 0;
}
/*!
\class String
\brief A very simple string class.
*/
// constructor
String::String()
: fLength(0),
fString(NULL)
{
}
// copy constructor
String::String(const String &string)
: fLength(0),
fString(NULL)
{
*this = string;
}
// constructor
String::String(const char *string, int32 length)
: fLength(0),
fString(NULL)
{
SetTo(string, length);
}
// destructor
String::~String()
{
Unset();
}
// SetTo
bool
String::SetTo(const char *string, int32 maxLength)
{
if (string) {
if (maxLength > 0)
maxLength = strnlen(string, maxLength);
else if (maxLength < 0)
maxLength = strlen(string);
}
return _SetTo(string, maxLength);
}
// Unset
void
String::Unset()
{
if (fString) {
delete[] fString;
fString = NULL;
}
fLength = 0;
}
// Truncate
void
String::Truncate(int32 newLength)
{
if (newLength < 0)
newLength = 0;
if (newLength < fLength) {
char *string = fString;
int32 len = fLength;
fString = NULL;
len = 0;
if (!_SetTo(string, newLength)) {
fString = string;
fLength = newLength;
fString[fLength] = '\0';
} else
delete[] string;
}
}
// GetString
const char *
String::GetString() const
{
if (fString)
return fString;
return "";
}
// =
String &
String::operator=(const String &string)
{
if (&string != this)
_SetTo(string.fString, string.fLength);
return *this;
}
// ==
bool
String::operator==(const String &string) const
{
return (fLength == string.fLength
&& (fLength == 0 || !strcmp(fString, string.fString)));
}
// _SetTo
bool
String::_SetTo(const char *string, int32 length)
{
bool result = true;
Unset();
if (string && length > 0) {
fString = new(std::nothrow) char[length + 1];
if (fString) {
memcpy(fString, string, length);
fString[length] = '\0';
fLength = length;
} else
result = false;
}
return result;
}
#endif // __cplusplus
#endif // STRING_H
@@ -3,7 +3,7 @@
#include <limits.h>
#include "AllocationInfo.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "SizeIndex.h"
#include "SymLink.h"
#include "Volume.h"
@@ -28,7 +28,7 @@
#include "Block.h"
#include "BlockAllocator.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Directory.h"
#include "Entry.h"
#include "EntryListener.h"
@@ -754,7 +754,7 @@ Volume::FindAttributeIndex(const char *name, uint32 type)
void
Volume::AddQuery(Query *query)
{
AutoLocker<Locker> _(fQueryLocker);
AutoLocker<RecursiveLock> _(fQueryLocker);
if (query)
fQueries.Insert(query);
@@ -764,7 +764,7 @@ Volume::AddQuery(Query *query)
void
Volume::RemoveQuery(Query *query)
{
AutoLocker<Locker> _(fQueryLocker);
AutoLocker<RecursiveLock> _(fQueryLocker);
if (query)
fQueries.Remove(query);
@@ -776,7 +776,7 @@ Volume::UpdateLiveQueries(Entry *entry, Node* node, const char *attribute,
int32 type, const uint8 *oldKey, size_t oldLength, const uint8 *newKey,
size_t newLength)
{
AutoLocker<Locker> _(fQueryLocker);
AutoLocker<RecursiveLock> _(fQueryLocker);
for (Query* query = fQueries.First();
query;
@@ -25,11 +25,11 @@
#include <fs_interface.h>
#include <SupportDefs.h>
#include <userlandfs/shared/RecursiveLock.h>
#include <util/DoublyLinkedList.h>
#include "Entry.h"
#include "List.h"
#include "Locker.h"
#include "Query.h"
#include "String.h"
@@ -191,9 +191,9 @@ private:
IndexDirectory *fIndexDirectory;
Directory *fRootDirectory;
String fName;
Locker fLocker;
Locker fIteratorLocker;
Locker fQueryLocker;
RecursiveLock fLocker;
RecursiveLock fIteratorLocker;
RecursiveLock fQueryLocker;
NodeListenerTree *fNodeListeners;
NodeListenerList fAnyNodeListeners;
EntryListenerTree *fEntryListeners;
@@ -45,7 +45,7 @@
#include "AllocationInfo.h"
#include "AttributeIndex.h"
#include "AttributeIterator.h"
#include "Debug.h"
#include "DebugSupport.h"
#include "Directory.h"
#include "Entry.h"
#include "EntryIterator.h"
@@ -376,8 +376,8 @@ ramfs_read_symlink(fs_volume* _volume, fs_vnode* _node, char *buffer,
memcpy(buffer, symLink->GetLinkedPath(), toRead);
*bufferSize = toRead;
} else {
FATAL(("Node %Ld pretends to be a SymLink, but isn't!\n",
node->GetID()));
FATAL("Node %Ld pretends to be a SymLink, but isn't!\n",
node->GetID());
error = B_BAD_VALUE;
}
}
@@ -957,8 +957,8 @@ ramfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
if (File *file = dynamic_cast<File*>(node))
error = file->ReadAt(pos, buffer, *bufferSize, bufferSize);
else {
FATAL(("Node %Ld pretends to be a File, but isn't!\n",
node->GetID()));
FATAL("Node %Ld pretends to be a File, but isn't!\n",
node->GetID());
error = B_BAD_VALUE;
}
}
@@ -999,8 +999,8 @@ ramfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
error = file->WriteAt(pos, buffer, *bufferSize,
bufferSize);
} else {
FATAL(("Node %Ld pretends to be a File, but isn't!\n",
node->GetID()));
FATAL("Node %Ld pretends to be a File, but isn't!\n",
node->GetID());
error = B_BAD_VALUE;
}
}
@@ -1217,8 +1217,8 @@ ramfs_open_dir(fs_volume* /*fs*/, fs_vnode* _node, void** _cookie)
if (error == B_OK) {
dir = dynamic_cast<Directory*>(node);
if (!dir) {
FATAL(("Node %Ld pretends to be a Directory, but isn't!\n",
node->GetID()));
FATAL("Node %Ld pretends to be a Directory, but isn't!\n",
node->GetID());
error = B_NOT_A_DIRECTORY;
}
}