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