From 72497a44d734e09b6149745559bd7cd823b53dc1 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Tue, 1 Apr 2008 18:45:30 +0000 Subject: [PATCH] Read partition table using BDiskDevice from first disk. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24725 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bootman/BootManagerController.cpp | 8 +- src/apps/bootman/Jamfile | 4 +- src/apps/bootman/LegacyBootDrive.cpp | 155 +++++++++++++++++++++ src/apps/bootman/LegacyBootDrive.h | 23 +++ 4 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 src/apps/bootman/LegacyBootDrive.cpp create mode 100644 src/apps/bootman/LegacyBootDrive.h diff --git a/src/apps/bootman/BootManagerController.cpp b/src/apps/bootman/BootManagerController.cpp index fd74de6e81..0c85877924 100644 --- a/src/apps/bootman/BootManagerController.cpp +++ b/src/apps/bootman/BootManagerController.cpp @@ -13,9 +13,10 @@ #include "DefaultPartitionPage.h" #include "DescriptionPage.h" #include "FileSelectionPage.h" +#include "LegacyBootDrive.h" -// TODO remove -#define USE_TEST_BOOT_DRIVE 1 + +#define USE_TEST_BOOT_DRIVE 0 #if USE_TEST_BOOT_DRIVE #include "TestBootDrive.h" @@ -35,8 +36,7 @@ BootManagerController::BootManagerController() #if USE_TEST_BOOT_DRIVE fBootDrive = new TestBootDrive(); #else - // TODO implement - fBootDrive = NULL; + fBootDrive = new LegacyBootDrive(); #endif // set defaults diff --git a/src/apps/bootman/Jamfile b/src/apps/bootman/Jamfile index 01ec1b6e6b..e035569d17 100644 --- a/src/apps/bootman/Jamfile +++ b/src/apps/bootman/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src apps bootman ; -SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders shared ; +UsePrivateHeaders storage ; Application bootman : BootManager.cpp @@ -10,6 +11,7 @@ Application bootman : DescriptionPage.cpp EntryPage.cpp FileSelectionPage.cpp + LegacyBootDrive.cpp PartitionsPage.cpp TestBootDrive.cpp UninstallPage.cpp diff --git a/src/apps/bootman/LegacyBootDrive.cpp b/src/apps/bootman/LegacyBootDrive.cpp new file mode 100644 index 0000000000..4ba1363d40 --- /dev/null +++ b/src/apps/bootman/LegacyBootDrive.cpp @@ -0,0 +1,155 @@ +/* + * Copyright 2008, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include "LegacyBootDrive.h" + + +#include +#include +#include +#include +#include +#include + +#include + + +class PartitionRecorder : public BDiskDeviceVisitor +{ +public: + PartitionRecorder(BMessage* settings); + + virtual bool Visit(BDiskDevice* device); + virtual bool Visit(BPartition* partition, int32 level); + +private: + bool _Record(BPartition* partition); + + BMessage* fSettings; + int32 fIndex; +}; + + +PartitionRecorder::PartitionRecorder(BMessage* settings) + : fSettings(settings) +{ +} + + +bool +PartitionRecorder::Visit(BDiskDevice* device) +{ + return false; +} + + +bool +PartitionRecorder::Visit(BPartition* partition, int32 level) +{ + return _Record(partition); +} + + +bool +PartitionRecorder::_Record(BPartition* partition) +{ + BPath partitionPath; + partition->GetPath(&partitionPath); + + BString buffer; + const char* name = partition->ContentName(); + if (name == NULL) { + fIndex ++; + buffer << "Unnamed " << fIndex; + name = buffer.String(); + } + + const char* type = partition->Type(); + if (type == NULL) + type = "Unknown"; + + BMessage message; + message.AddBool("show", true); + message.AddString("name", name); + message.AddString("type", type); + message.AddString("path", partitionPath.Path()); + message.AddInt64("size", partition->ContentSize()); + fSettings->AddMessage("partition", &message); + + return false; +} + + +LegacyBootDrive::LegacyBootDrive() +{ +} + + +LegacyBootDrive::~LegacyBootDrive() +{ +} + + +bool +LegacyBootDrive::IsBootMenuInstalled() +{ + return false; +} + + +status_t +LegacyBootDrive::ReadPartitions(BMessage *message) +{ + BDiskDeviceRoster diskDeviceRoster; + BDiskDevice device; + // first disk only + if (diskDeviceRoster.GetNextDevice(&device) == B_OK) { + BPath path; + if (device.GetPath(&path) != B_OK) + return B_ERROR; + + message->AddString("disk", path.Path()); + + + PartitionRecorder recorder(message); + device.VisitEachDescendant(&recorder); + } + return B_OK; +} + + +status_t +LegacyBootDrive::WriteBootMenu(BMessage *message) +{ + // TODO + printf("WriteBootMenu:\n"); + message->PrintToStream(); + + BMessage partition; + int32 index = 0; + for (; message->FindMessage("partition", index, &partition) == B_OK; index ++) { + printf("Partition %d:\n", (int)index); + partition.PrintToStream(); + } + + return B_OK; +} + + +status_t +LegacyBootDrive::SaveMasterBootRecord(BFile *file) +{ + // TODO implement + return B_OK; +} + + +status_t +LegacyBootDrive::RestoreMasterBootRecord(BFile *file) +{ + // TODO implement + return B_OK; +} diff --git a/src/apps/bootman/LegacyBootDrive.h b/src/apps/bootman/LegacyBootDrive.h new file mode 100644 index 0000000000..c57ba947c1 --- /dev/null +++ b/src/apps/bootman/LegacyBootDrive.h @@ -0,0 +1,23 @@ +/* + * Copyright 2008, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef LEGACY_BOOT_DRIVE_H +#define LEGACY_BOOT_DRIVE_H + +#include "BootDrive.h" + +class LegacyBootDrive : public BootDrive +{ +public: + LegacyBootDrive(); + virtual ~LegacyBootDrive(); + + virtual bool IsBootMenuInstalled(); + virtual status_t ReadPartitions(BMessage *message); + virtual status_t WriteBootMenu(BMessage *message); + virtual status_t SaveMasterBootRecord(BFile *file); + virtual status_t RestoreMasterBootRecord(BFile *file); +}; + +#endif // LEGACY_BOOT_DRIVE_H