From a1209343884e1b6d0c1bfa79c30e40fdc52bd28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 10 Jul 2008 10:06:17 +0000 Subject: [PATCH] * Moved KMessage field printing from vfs_boot.cpp::get_boot_partitions() into KMessage::Dump(). * Improved message dump output a bit (more concise). * get_boot_partitions() now simply calls KMessage::Dump() instead. * Added a KMessage::IsEmpty() method. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26365 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/util/KMessage.h | 3 +- src/system/kernel/fs/vfs_boot.cpp | 52 ++----------------- src/system/kernel/messaging/KMessage.cpp | 63 ++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 55 deletions(-) diff --git a/headers/private/kernel/util/KMessage.h b/headers/private/kernel/util/KMessage.h index a94490e943..7ea170854b 100644 --- a/headers/private/kernel/util/KMessage.h +++ b/headers/private/kernel/util/KMessage.h @@ -55,6 +55,7 @@ public: status_t FindField(const char *name, type_code type, KMessageField *field) const; status_t GetNextField(KMessageField *field) const; + bool IsEmpty() const; status_t AddData(const char *name, type_code type, const void *data, int32 numBytes, bool isFixedSize = true); @@ -135,7 +136,7 @@ public: status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1, port_message_info* messageInfo = NULL); - void Dump(void (*printFunc)(const char*,...)) const; + void Dump(void (*printFunc)(const char*, ...)) const; private: friend class KMessageField; diff --git a/src/system/kernel/fs/vfs_boot.cpp b/src/system/kernel/fs/vfs_boot.cpp index 6254a74680..4d96865938 100644 --- a/src/system/kernel/fs/vfs_boot.cpp +++ b/src/system/kernel/fs/vfs_boot.cpp @@ -85,7 +85,7 @@ compare_image_boot(const void *_a, const void *_b) if (!strncmp(b->ContentName(), "System", 6)) return -1; - return compare; + return compare; } @@ -278,7 +278,7 @@ DiskBootMethod::SortPartitions(KPartition** partitions, int32 count) // #pragma mark - -/*! Make the boot partition (and probably others) available. +/*! Make the boot partition (and probably others) available. The partitions that are a boot candidate a put into the /a partitions stack. If the user selected a boot device, there is will only be one entry in this stack; if not, the most likely is put up first. @@ -290,53 +290,7 @@ get_boot_partitions(kernel_args *args, PartitionStack &partitions) const KMessage& bootVolume = args->boot_volume; dprintf("get_boot_partitions(): boot volume message:\n"); - KMessageField field; - while (bootVolume.GetNextField(&field) == B_OK) { - type_code type = field.TypeCode(); - uint32 bigEndianType = B_HOST_TO_BENDIAN_INT32(type); - dprintf("field: \"%s\", type: %.4s (0x%lx):\n", field.Name(), - (char*)&bigEndianType, type); - - if (field.CountElements() == 0) - dprintf("\n"); - - int32 size; - for (int i = 0; const void* data = field.ElementAt(i, &size); i++) { - dprintf(" [%2d] ", i); - bool isIntType = false; - int64 intData = 0; - switch (type) { - case B_BOOL_TYPE: - dprintf("%s\n", (*(bool*)data ? "true" : "false")); - break; - case B_INT8_TYPE: - isIntType = true; - intData = *(int8*)data; - break; - case B_INT16_TYPE: - isIntType = true; - intData = *(int16*)data; - break; - case B_INT32_TYPE: - isIntType = true; - intData = *(int32*)data; - break; - case B_INT64_TYPE: - isIntType = true; - intData = *(int64*)data; - break; - case B_STRING_TYPE: - dprintf("\"%s\"\n", (char*)data); - break; - default: - dprintf("data: \"%p\", %ld bytes\n", (char*)data, size); - break; - } - if (isIntType) - dprintf("%lld (0x%llx)\n", intData, intData); - } - } - + bootVolume.Dump(&dprintf); // create boot method int32 bootMethodType = bootVolume.GetInt32(BOOT_METHOD, diff --git a/src/system/kernel/messaging/KMessage.cpp b/src/system/kernel/messaging/KMessage.cpp index 1854ba104a..b0e828e385 100644 --- a/src/system/kernel/messaging/KMessage.cpp +++ b/src/system/kernel/messaging/KMessage.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -300,6 +301,14 @@ KMessage::GetNextField(KMessageField *field) const return B_OK; } + +bool +KMessage::IsEmpty() const +{ + return _LastFieldHeader() == NULL; +} + + // AddData status_t KMessage::AddData(const char *name, type_code type, const void *data, @@ -601,7 +610,7 @@ KMessage::ReceiveFrom(port_id fromPort, bigtime_t timeout, void -KMessage::Dump(void (*printFunc)(const char*,...)) const +KMessage::Dump(void (*printFunc)(const char*, ...)) const { Header* header = _Header(); printFunc("KMessage: buffer: %p (size/capacity: %ld/%ld), flags: 0x0lx\n", @@ -610,10 +619,54 @@ KMessage::Dump(void (*printFunc)(const char*,...)) const KMessageField field; while (GetNextField(&field) == B_OK) { type_code type = field.TypeCode(); - int32 count = field.CountElements(); - printFunc(" field: %-20s: type: 0x%lx ('%c%c%c%c'), %ld element%s\n", - field.Name(), type, (char)(type >> 24), (char)(type >> 16), - (char)(type >> 8), (char)type, count, count == 1 ? "" : "s"); + uint32 bigEndianType = B_HOST_TO_BENDIAN_INT32(type); + int nameSpacing = 17 - strlen(field.Name()); + if (nameSpacing < 0) + nameSpacing = 0; + + printFunc(" field: \"%s\"%*s (%.4s): ", field.Name(), nameSpacing, "", + (char*)&bigEndianType); + + if (field.CountElements() != 1) + printFunc("\n"); + + int32 size; + for (int i = 0; const void* data = field.ElementAt(i, &size); i++) { + if (field.CountElements() != 1) + printFunc(" [%2d] ", i); + + bool isIntType = false; + int64 intData = 0; + switch (type) { + case B_BOOL_TYPE: + printFunc("%s\n", (*(bool*)data ? "true" : "false")); + break; + case B_INT8_TYPE: + isIntType = true; + intData = *(int8*)data; + break; + case B_INT16_TYPE: + isIntType = true; + intData = *(int16*)data; + break; + case B_INT32_TYPE: + isIntType = true; + intData = *(int32*)data; + break; + case B_INT64_TYPE: + isIntType = true; + intData = *(int64*)data; + break; + case B_STRING_TYPE: + printFunc("\"%s\"\n", (char*)data); + break; + default: + printFunc("data at %p, %ld bytes\n", (char*)data, size); + break; + } + if (isIntType) + printFunc("%lld (0x%llx)\n", intData, intData); + } } }