From 3d43a90508c52f94749a3ace29bdb88b2d1d5550 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 30 Aug 2020 17:58:47 -0400 Subject: [PATCH] bfs: Enable logging on DEBUG build Fix DEBUG build errors by using B_PRI macros in BlockAllocator.cpp, CheckVisitor.cpp, Inode.cpp, Journal.cpp, and kernel_interface.cpp Add optional type parameter from BlockAllocator::IsValidBlockRun() and actually PRINT it, type parameter is already optional on BlockAllocator::CheckBlockRun(). Remove a couple of casts as we are printing the expected type, int32. Cast mode_t to (unsigned int) and use %u because 32-bit Haiku didn't like B_PRIu32. Verified to compile on both regular and DEBUG builds on both 32-bit and 64-bit. Change-Id: I8bb39afd400768b7f69d36384974f0b91b3ef48c Reviewed-on: https://review.haiku-os.org/c/haiku/+/3184 Reviewed-by: Adrien Destugues Reviewed-by: John Scipione --- .../file_systems/bfs/BlockAllocator.cpp | 44 +++++++++++-------- .../kernel/file_systems/bfs/BlockAllocator.h | 3 +- .../kernel/file_systems/bfs/CheckVisitor.cpp | 7 +-- src/add-ons/kernel/file_systems/bfs/Debug.h | 2 +- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 14 +++--- .../kernel/file_systems/bfs/Journal.cpp | 8 ++-- .../file_systems/bfs/kernel_interface.cpp | 26 ++++++----- 7 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index 5f4fa0a70c..e78a35897e 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -49,8 +49,8 @@ public: virtual void AddDump(TraceOutput& out) { - out.Print("bfs:alloc %lu.%u.%u", fRun.AllocationGroup(), - fRun.Start(), fRun.Length()); + out.Print("bfs:alloc %" B_PRId32 ".%" B_PRIu16 ".%" B_PRIu16, + fRun.AllocationGroup(), fRun.Start(), fRun.Length()); } const block_run& Run() const { return fRun; } @@ -71,8 +71,8 @@ public: virtual void AddDump(TraceOutput& out) { - out.Print("bfs:free %lu.%u.%u", fRun.AllocationGroup(), - fRun.Start(), fRun.Length()); + out.Print("bfs:free %" B_PRId32 ".%" B_PRIu16 ".%" B_PRIu16, + fRun.AllocationGroup(), fRun.Start(), fRun.Length()); } const block_run& Run() const { return fRun; } @@ -730,7 +730,8 @@ BlockAllocator::AllocateBlocks(Transaction& transaction, int32 groupIndex, if (maximum == 0) return B_BAD_VALUE; - FUNCTION_START(("group = %ld, start = %u, maximum = %u, minimum = %u\n", + FUNCTION_START(("group = %" B_PRId32 ", start = %" B_PRIu16 + ", maximum = %" B_PRIu16 ", minimum = %" B_PRIu16 "\n", groupIndex, start, maximum, minimum)); AllocationBlock cached(fVolume); @@ -998,8 +999,8 @@ BlockAllocator::Free(Transaction& transaction, block_run run) uint16 start = run.Start(); uint16 length = run.Length(); - FUNCTION_START(("group = %ld, start = %u, length = %u\n", group, start, - length)); + FUNCTION_START(("group = %" B_PRId32 ", start = %" B_PRIu16 + ", length = %" B_PRIu16 "\n", group, start, length)) T(Free(run)); // doesn't use Volume::IsValidBlockRun() here because it can check better @@ -1008,8 +1009,9 @@ BlockAllocator::Free(Transaction& transaction, block_run run) || start > fGroups[group].NumBits() || uint32(start + length) > fGroups[group].NumBits() || length == 0) { - FATAL(("tried to free an invalid block_run (%d, %u, %u)\n", (int)group, - start, length)); + FATAL(("tried to free an invalid block_run" + " (%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")\n", + group, start, length)); DEBUGGER(("tried to free invalid block_run")); return B_BAD_VALUE; } @@ -1017,8 +1019,9 @@ BlockAllocator::Free(Transaction& transaction, block_run run) // drive if (group == 0 && start < uint32(fVolume->Log().Start() + fVolume->Log().Length())) { - FATAL(("tried to free a reserved block_run (%d, %u, %u)\n", (int)group, - start, length)); + FATAL(("tried to free a reserved block_run" + " (%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")\n", + group, start, length)); DEBUGGER(("tried to free reserved block")); return B_BAD_VALUE; } @@ -1244,8 +1247,9 @@ BlockAllocator::CheckBlocks(off_t start, off_t length, bool allocated, for (; blockOffset < cached.NumBlockBits() && length > 0; blockOffset++, length--, block++) { if (cached.IsUsed(blockOffset) != allocated) { - PRINT(("CheckBlocks: Erroneous block (group = %ld, " - "groupBlock = %ld, blockOffset = %ld)!\n", + PRINT(("CheckBlocks: Erroneous block (group = %" B_PRId32 + ", groupBlock = %" B_PRIu32 + ", blockOffset = %" B_PRIu32 ")!\n", group, groupBlock, blockOffset)); if (firstError) @@ -1268,15 +1272,16 @@ BlockAllocator::CheckBlocks(off_t start, off_t length, bool allocated, bool -BlockAllocator::IsValidBlockRun(block_run run) +BlockAllocator::IsValidBlockRun(block_run run, const char* type) { if (run.AllocationGroup() < 0 || run.AllocationGroup() >= fNumGroups || run.Start() > fGroups[run.AllocationGroup()].fNumBits || uint32(run.Start() + run.Length()) > fGroups[run.AllocationGroup()].fNumBits || run.length == 0) { - PRINT(("%s: block_run(%ld, %u, %u) is invalid!\n", type, - run.AllocationGroup(), run.Start(), run.Length())); + PRINT(("%s: block_run(%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")" + " is invalid!\n", type, run.AllocationGroup(), run.Start(), + run.Length())); return false; } return true; @@ -1286,14 +1291,15 @@ BlockAllocator::IsValidBlockRun(block_run run) status_t BlockAllocator::CheckBlockRun(block_run run, const char* type, bool allocated) { - if (!IsValidBlockRun(run)) + if (!IsValidBlockRun(run, type)) return B_BAD_DATA; status_t status = CheckBlocks(fVolume->ToBlock(run), run.Length(), allocated); if (status != B_OK) { - PRINT(("%s: block_run(%ld, %u, %u) is only partially allocated!\n", - type, run.AllocationGroup(), run.Start(), run.Length())); + PRINT(("%s: block_run(%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")" + " is only partially allocated!\n", type, run.AllocationGroup(), + run.Start(), run.Length())); } return status; diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h index 5f2748d068..7d81292e56 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h @@ -52,7 +52,8 @@ public: status_t CheckBlockRun(block_run run, const char* type = NULL, bool allocated = true); - bool IsValidBlockRun(block_run run); + bool IsValidBlockRun(block_run run, + const char* type = NULL); recursive_lock& Lock() { return fLock; } diff --git a/src/add-ons/kernel/file_systems/bfs/CheckVisitor.cpp b/src/add-ons/kernel/file_systems/bfs/CheckVisitor.cpp index 40b4635660..1bd71c27f3 100644 --- a/src/add-ons/kernel/file_systems/bfs/CheckVisitor.cpp +++ b/src/add-ons/kernel/file_systems/bfs/CheckVisitor.cpp @@ -608,7 +608,7 @@ CheckVisitor::_CheckAllocated(block_run run, const char* type) BlockAllocator& allocator = GetVolume()->Allocator(); // make sure the block run is valid - if (!allocator.IsValidBlockRun(run)) { + if (!allocator.IsValidBlockRun(run, type)) { Control().errors |= BFS_INVALID_BLOCK_RUN; return B_OK; } @@ -637,8 +637,9 @@ CheckVisitor::_CheckAllocated(block_run run, const char* type) else if (status != B_BAD_DATA) return status; - PRINT(("%s: block_run(%ld, %u, %u): blocks %Ld - %Ld are " - "not allocated!\n", type, run.AllocationGroup(), run.Start(), + PRINT(("%s: block_run(%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16 ")" + ": blocks %" B_PRIdOFF " - %" B_PRIdOFF " are not allocated!\n", + type, run.AllocationGroup(), run.Start(), run.Length(), firstMissing, afterLastMissing - 1)); Control().stats.missing += afterLastMissing - firstMissing; diff --git a/src/add-ons/kernel/file_systems/bfs/Debug.h b/src/add-ons/kernel/file_systems/bfs/Debug.h index 3c0936c84a..778d574c92 100644 --- a/src/add-ons/kernel/file_systems/bfs/Debug.h +++ b/src/add-ons/kernel/file_systems/bfs/Debug.h @@ -47,7 +47,7 @@ // D() // the statements in D() are only included if DEBUG is defined -#if 0//DEBUG +#if DEBUG #define PRINT(x) { __out("bfs: "); __out x; } #define REPORT_ERROR(status) \ __out("bfs: %s:%d: %s\n", __FUNCTION__, __LINE__, strerror(status)); diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index e8930a7950..28c1bbb0d0 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -346,7 +346,8 @@ Inode::Inode(Volume* volume, ino_t id) fCache(NULL), fMap(NULL) { - PRINT(("Inode::Inode(volume = %p, id = %Ld) @ %p\n", volume, id, this)); + PRINT(("Inode::Inode(volume = %p, id = %" B_PRIdINO ") @ %p\n", + volume, id, this)); rw_lock_init(&fLock, "bfs inode"); recursive_lock_init(&fSmallDataLock, "bfs inode small data"); @@ -379,8 +380,8 @@ Inode::Inode(Volume* volume, Transaction& transaction, ino_t id, mode_t mode, fCache(NULL), fMap(NULL) { - PRINT(("Inode::Inode(volume = %p, transaction = %p, id = %Ld) @ %p\n", - volume, &transaction, id, this)); + PRINT(("Inode::Inode(volume = %p, transaction = %p, id = %" B_PRIdINO + ") @ %p\n", volume, &transaction, id, this)); rw_lock_init(&fLock, "bfs inode"); recursive_lock_init(&fSmallDataLock, "bfs inode small data"); @@ -2152,8 +2153,9 @@ status_t Inode::_FreeStreamArray(Transaction& transaction, block_run* array, uint32 arrayLength, off_t size, off_t& offset, off_t& max) { - PRINT(("FreeStreamArray: arrayLength %lu, size %Ld, offset %Ld, max %Ld\n", - arrayLength, size, offset, max)); + PRINT(("FreeStreamArray: arrayLength %" B_PRId32 ", size %" B_PRIdOFF + ", offset %" B_PRIdOFF ", max %" B_PRIdOFF "\n", arrayLength, size, + offset, max)); off_t newOffset = offset; uint32 i = 0; @@ -2619,7 +2621,7 @@ Inode::Create(Transaction& transaction, Inode* parent, const char* name, int32 mode, int openMode, uint32 type, bool* _created, ino_t* _id, Inode** _inode, fs_vnode_ops* vnodeOps, uint32 publishFlags) { - FUNCTION_START(("name = %s, mode = %ld\n", name, mode)); + FUNCTION_START(("name = %s, mode = %" B_PRId32 "\n", name, mode)); block_run parentRun = parent ? parent->BlockRun() : block_run::Run(0, 0, 0); Volume* volume = transaction.GetVolume(); diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.cpp b/src/add-ons/kernel/file_systems/bfs/Journal.cpp index f37e687b84..33b91bbd67 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Journal.cpp @@ -465,7 +465,7 @@ Journal::_CheckRunArray(const run_array* array) return B_ERROR; } - PRINT(("Log entry has %ld entries\n", array->CountRuns())); + PRINT(("Log entry has %" B_PRId32 " entries\n", array->CountRuns())); return B_OK; } @@ -477,7 +477,7 @@ Journal::_CheckRunArray(const run_array* array) status_t Journal::_ReplayRunArray(int32* _start) { - PRINT(("ReplayRunArray(start = %ld)\n", *_start)); + PRINT(("ReplayRunArray(start = %" B_PRId32 ")\n", *_start)); off_t logOffset = fVolume->ToBlock(fVolume->Log()); off_t firstBlockNumber = *_start % fLogSize; @@ -645,8 +645,8 @@ Journal::_TransactionWritten(int32 transactionID, int32 event, void* _logEntry) { LogEntry* logEntry = (LogEntry*)_logEntry; - PRINT(("Log entry %p has been finished, transaction ID = %ld\n", logEntry, - transactionID)); + PRINT(("Log entry %p has been finished, transaction ID = %" B_PRId32 "\n", + logEntry, transactionID)); Journal* journal = logEntry->GetJournal(); disk_super_block& superBlock = journal->fVolume->SuperBlock(); diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index 699160b3b2..c91d0272f7 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -241,7 +241,7 @@ bfs_read_fs_stat(fs_volume* _volume, struct fs_info* info) static status_t bfs_write_fs_stat(fs_volume* _volume, const struct fs_info* info, uint32 mask) { - FUNCTION_START(("mask = %ld\n", mask)); + FUNCTION_START(("mask = %" B_PRId32 "\n", mask)); Volume* volume = (Volume*)_volume->private_volume; if (volume->IsReadOnly()) @@ -635,8 +635,8 @@ static status_t bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd, void* buffer, size_t bufferLength) { - FUNCTION_START(("node = %p, cmd = %lu, buf = %p, len = %ld\n", _node, cmd, - buffer, bufferLength)); + FUNCTION_START(("node = %p, cmd = %" B_PRIu32 ", buf = %p" + ", len = %" B_PRIuSIZE "\n", _node, cmd, buffer, bufferLength)); Volume* volume = (Volume*)_volume->private_volume; @@ -802,8 +802,10 @@ bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd, block_run run; while (allocator.AllocateBlocks(transaction, 8, 0, 64, 1, run) == B_OK) { - PRINT(("write block_run(%ld, %d, %d)\n", run.allocation_group, - run.start, run.length)); + PRINT(("write block_run(%" B_PRId32 ", %" B_PRIu16 + ", %" B_PRIu16 ")\n", run.allocation_group, run.start, + run.length)); + for (int32 i = 0;i < run.length;i++) { status_t status = cached.SetToWritable(transaction, run); if (status == B_OK) @@ -934,8 +936,8 @@ bfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat* stat, // only the user or root can do that if (!isOwnerOrRoot) RETURN_ERROR(B_NOT_ALLOWED); - PRINT(("original mode = %ld, stat->st_mode = %d\n", node.Mode(), - stat->st_mode)); + PRINT(("original mode = %u, stat->st_mode = %u\n", + (unsigned int)node.Mode(), (unsigned int)stat->st_mode)); node.mode = HOST_ENDIAN_TO_BFS_INT32((node.Mode() & ~S_IUMSK) | (stat->st_mode & S_IUMSK)); updateTime = true; @@ -2039,8 +2041,8 @@ bfs_create_special_node(fs_volume* _volume, fs_vnode* _directory, if (name == NULL) return B_UNSUPPORTED; - FUNCTION_START(("name = \"%s\", mode = %d, flags = 0x%lx, subVnode: %p\n", - name, mode, flags, subVnode)); + FUNCTION_START(("name = \"%s\", mode = %u, flags = 0x%" B_PRIx32 + ", subVnode: %p\n", name, (unsigned int)mode, flags, subVnode)); Volume* volume = (Volume*)_volume->private_volume; Inode* directory = (Inode*)_directory->private_node; @@ -2168,7 +2170,8 @@ static status_t bfs_create_index(fs_volume* _volume, const char* name, uint32 type, uint32 flags) { - FUNCTION_START(("name = \"%s\", type = %ld, flags = %ld\n", name, type, flags)); + FUNCTION_START(("name = \"%s\", type = %" B_PRIu32 + ", flags = %" B_PRIu32 "\n", name, type, flags)); Volume* volume = (Volume*)_volume->private_volume; @@ -2258,7 +2261,8 @@ static status_t bfs_open_query(fs_volume* _volume, const char* queryString, uint32 flags, port_id port, uint32 token, void** _cookie) { - FUNCTION_START(("bfs_open_query(\"%s\", flags = %lu, port_id = %ld, token = %ld)\n", + FUNCTION_START(("bfs_open_query(\"%s\", flags = %" B_PRIu32 + ", port_id = %" B_PRId32 ", token = %" B_PRIu32 ")\n", queryString, flags, port, token)); Volume* volume = (Volume*)_volume->private_volume;