Author: axeld Date: 2011-01-04 20:14:39 +0100 (Tue, 04 Jan 2011) New Revision: 40113 Changeset: http://dev.haiku-os.org/changeset/40113 Modified: haiku/trunk/src/apps/bootman/BootDrive.h haiku/trunk/src/apps/bootman/BootManagerWindow.cpp haiku/trunk/src/apps/bootman/DefaultPartitionPage.cpp haiku/trunk/src/apps/bootman/DefaultPartitionPage.h haiku/trunk/src/apps/bootman/DescriptionPage.cpp haiku/trunk/src/apps/bootman/DescriptionPage.h haiku/trunk/src/apps/bootman/EntryPage.cpp haiku/trunk/src/apps/bootman/EntryPage.h haiku/trunk/src/apps/bootman/FileSelectionPage.cpp haiku/trunk/src/apps/bootman/FileSelectionPage.h haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp haiku/trunk/src/apps/bootman/LegacyBootDrive.h haiku/trunk/src/apps/bootman/MakeArray.cpp haiku/trunk/src/apps/bootman/PartitionsPage.cpp haiku/trunk/src/apps/bootman/PartitionsPage.h haiku/trunk/src/apps/bootman/TestBootDrive.cpp haiku/trunk/src/apps/bootman/TestBootDrive.h haiku/trunk/src/apps/bootman/UninstallPage.cpp haiku/trunk/src/apps/bootman/UninstallPage.h haiku/trunk/src/apps/bootman/WizardController.cpp haiku/trunk/src/apps/bootman/WizardController.h haiku/trunk/src/apps/bootman/WizardPageView.cpp haiku/trunk/src/apps/bootman/WizardPageView.h haiku/trunk/src/apps/bootman/WizardView.cpp haiku/trunk/src/apps/bootman/WizardView.h Log: * Cleanup. Modified: haiku/trunk/src/apps/bootman/BootDrive.h =================================================================== --- haiku/trunk/src/apps/bootman/BootDrive.h 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/BootDrive.h 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,19 +1,20 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Michael Pfeiffer <laplace@xxxxxxxxxxxxxxxxxxxxx> */ #ifndef BOOT_DRIVE_H #define BOOT_DRIVE_H + #include <File.h> #include <Message.h> -/* - Setting BMessage Format: +/* Setting BMessage Format: + "disk" String (path to boot disk) "partition" array of BMessage: @@ -22,27 +23,33 @@ "type" String (short name of file system: bfs, dos) "path" String (path to partition in /dev/...) "size" long (size of partition in bytes) - */ +*/ + enum { // Not enough space free before first partition for boot loader kErrorBootSectorTooSmall = B_ERRORS_END + 1, }; -class BootDrive -{ + +class BootDrive { public: - BootDrive() {} - virtual ~BootDrive() {} + BootDrive() {} + virtual ~BootDrive() {} - virtual bool IsBootMenuInstalled(BMessage* settings) = 0; - virtual status_t ReadPartitions(BMessage* settings) = 0; - virtual status_t WriteBootMenu(BMessage* settings) = 0; - virtual status_t SaveMasterBootRecord(BMessage* settings, BFile* file) = 0; - virtual status_t RestoreMasterBootRecord(BMessage* settings, BFile* file) = 0; + virtual bool IsBootMenuInstalled(BMessage* settings) = 0; + virtual status_t ReadPartitions(BMessage* settings) = 0; + virtual status_t WriteBootMenu(BMessage* settings) = 0; + virtual status_t SaveMasterBootRecord(BMessage* settings, + BFile* file) = 0; + virtual status_t RestoreMasterBootRecord(BMessage* settings, + BFile* file) = 0; + // Converts the specified text into a text as it will be shown // in the boot menu. - virtual status_t GetDisplayText(const char* text, BString& displayText) = 0; + virtual status_t GetDisplayText(const char* text, + BString& displayText) = 0; }; + #endif // BOOT_DRIVE_H Modified: haiku/trunk/src/apps/bootman/BootManagerWindow.cpp =================================================================== --- haiku/trunk/src/apps/bootman/BootManagerWindow.cpp 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/BootManagerWindow.cpp 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,5 +1,5 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,28 +9,23 @@ #include "BootManagerWindow.h" -#include "WizardView.h" - -#include "EntryPage.h" -#include "PartitionsPage.h" -#include "DefaultPartitionPage.h" - #include <Application.h> #include <Catalog.h> -#include <Locale.h> #include <Roster.h> #include <Screen.h> -#include <math.h> +#include <tracker_private.h> -#include "tracker_private.h" +#include "DefaultPartitionPage.h" +#include "EntryPage.h" +#include "PartitionsPage.h" +#include "WizardView.h" #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "BootManagerWindow" - BootManagerWindow::BootManagerWindow() : BWindow(BRect(100, 100, 500, 400), B_TRANSLATE_COMMENT("BootManager", Modified: haiku/trunk/src/apps/bootman/DefaultPartitionPage.cpp =================================================================== --- haiku/trunk/src/apps/bootman/DefaultPartitionPage.cpp 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/DefaultPartitionPage.cpp 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,5 +1,5 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -39,13 +39,12 @@ const int32 kTimeoutIndefinitely = -1; const int32 kDefaultTimeout = kTimeoutIndefinitely; -typedef struct { +struct TimeoutOption { int32 timeout; const char* label; -} TimeoutOption; +}; -static const TimeoutOption gTimeoutOptions[] = -{ +static const TimeoutOption gTimeoutOptions[] = { { 0, B_TRANSLATE_MARK("Immediately")}, { 1, B_TRANSLATE_MARK("After one second")}, { 2, B_TRANSLATE_MARK("After two seconds")}, @@ -95,8 +94,13 @@ } -DefaultPartitionPage::DefaultPartitionPage(BMessage* settings, BRect frame, const char* name) - : WizardPageView(settings, frame, name, B_FOLLOW_ALL, +// #pragma mark - + + +DefaultPartitionPage::DefaultPartitionPage(BMessage* settings, BRect frame, + const char* name) + : + WizardPageView(settings, frame, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) { _BuildUI(); @@ -129,34 +133,34 @@ { switch (msg->what) { case kMsgPartition: - { - int32 index; - msg->FindInt32("index", &index); - fSettings->ReplaceInt32("defaultPartition", index); - } + { + int32 index; + msg->FindInt32("index", &index); + fSettings->ReplaceInt32("defaultPartition", index); break; + } case kMsgTimeout: - { - int32 sliderValue = fTimeoutSlider->Value(); - int32 timeout = get_timeout_for_index(sliderValue); - fSettings->ReplaceInt32("timeout", timeout); + { + int32 sliderValue = fTimeoutSlider->Value(); + int32 timeout = get_timeout_for_index(sliderValue); + fSettings->ReplaceInt32("timeout", timeout); - BString label; - _GetTimeoutLabel(timeout, label); - fTimeoutSlider->SetLabel(label.String()); - } + BString label; + _GetTimeoutLabel(timeout, label); + fTimeoutSlider->SetLabel(label.String()); break; + } + default: WizardPageView::MessageReceived(msg); } } -#define kTextDistance be_control_look->DefaultItemSpacing(); - void DefaultPartitionPage::_BuildUI() { + const float kTextDistance = be_control_look->DefaultItemSpacing(); BRect rect(Bounds()); BString text; @@ -223,8 +227,7 @@ "Pop up menu title")); BMessage message; for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK; - i ++) { - + i++) { bool show; if (message.FindBool("show", &show) != B_OK || !show) continue; @@ -261,6 +264,7 @@ { LayoutDescriptionVertically(fDescription); + const float kTextDistance = be_control_look->DefaultItemSpacing(); float left = fDefaultPartition->Frame().left; float top = fDescription->Frame().bottom + kTextDistance; @@ -269,4 +273,3 @@ fTimeoutSlider->MoveTo(left, top); } - Modified: haiku/trunk/src/apps/bootman/DefaultPartitionPage.h =================================================================== --- haiku/trunk/src/apps/bootman/DefaultPartitionPage.h 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/DefaultPartitionPage.h 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,7 +1,7 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Michael Pfeiffer <laplace@xxxxxxxxxxxxxxxxxxxxx> */ @@ -20,27 +20,28 @@ class BTextView; -class DefaultPartitionPage : public WizardPageView -{ +class DefaultPartitionPage : public WizardPageView { public: - DefaultPartitionPage(BMessage* settings, BRect frame, const char* name); - virtual ~DefaultPartitionPage(); - - virtual void FrameResized(float width, float height); + DefaultPartitionPage(BMessage* settings, + BRect frame, const char* name); + virtual ~DefaultPartitionPage(); - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage* msg); + virtual void FrameResized(float width, float height); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* msg); + private: + void _BuildUI(); + BPopUpMenu* _CreatePopUpMenu(); + void _GetTimeoutLabel(int32 timeout, BString& label); + void _Layout(); - void _BuildUI(); - BPopUpMenu* _CreatePopUpMenu(); - void _GetTimeoutLabel(int32 timeout, BString& label); - void _Layout(); - - BTextView* fDescription; - BMenuField* fDefaultPartition; - BSlider* fTimeoutSlider; +private: + BTextView* fDescription; + BMenuField* fDefaultPartition; + BSlider* fTimeoutSlider; }; + #endif // DEFAULT_PARTITON_PAGE_H Modified: haiku/trunk/src/apps/bootman/DescriptionPage.cpp =================================================================== --- haiku/trunk/src/apps/bootman/DescriptionPage.cpp 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/DescriptionPage.cpp 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,7 +1,7 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Michael Pfeiffer <laplace@xxxxxxxxxxxxxxxxxxxxx> */ @@ -9,16 +9,16 @@ #include "DescriptionPage.h" +#include <string.h> #include <RadioButton.h> #include <TextView.h> -#include <string.h> - DescriptionPage::DescriptionPage(BRect frame, const char* name, const char* description, bool hasHeading) - : WizardPageView(NULL, frame, name, B_FOLLOW_ALL, + : + WizardPageView(NULL, frame, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) { _BuildUI(description, hasHeading); @@ -38,19 +38,17 @@ } -static const float kTextDistance = 10; - void DescriptionPage::_BuildUI(const char* description, bool hasHeading) { BRect rect(Bounds()); - + fDescription = CreateDescription(rect, "description", description); if (hasHeading) MakeHeading(fDescription); fDescription->SetTabWidth(85); AddChild(fDescription); - + _Layout(); } @@ -58,6 +56,6 @@ void DescriptionPage::_Layout() { - LayoutDescriptionVertically(fDescription); + LayoutDescriptionVertically(fDescription); } Modified: haiku/trunk/src/apps/bootman/DescriptionPage.h =================================================================== --- haiku/trunk/src/apps/bootman/DescriptionPage.h 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/DescriptionPage.h 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,7 +1,7 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Michael Pfeiffer <laplace@xxxxxxxxxxxxxxxxxxxxx> */ @@ -14,20 +14,22 @@ class BTextView; -class DescriptionPage : public WizardPageView -{ +class DescriptionPage : public WizardPageView { public: - DescriptionPage(BRect frame, const char* name, const char* description, bool hasHeading); - virtual ~DescriptionPage(); - - virtual void FrameResized(float width, float height); + DescriptionPage(BRect frame, const char* name, + const char* description, bool hasHeading); + virtual ~DescriptionPage(); + virtual void FrameResized(float width, float height); + private: + void _BuildUI(const char* description, + bool hasHeading); + void _Layout(); - void _BuildUI(const char* description, bool hasHeading); - void _Layout(); - - BTextView* fDescription; +private: + BTextView* fDescription; }; + #endif // DESCRIPTION_PAGE_H Modified: haiku/trunk/src/apps/bootman/EntryPage.cpp =================================================================== --- haiku/trunk/src/apps/bootman/EntryPage.cpp 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/EntryPage.cpp 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,21 +9,21 @@ #include "EntryPage.h" +#include <string.h> #include <Catalog.h> -#include <Locale.h> +#include <ControlLook.h> #include <RadioButton.h> #include <TextView.h> -#include <string.h> - #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "EntryPage" EntryPage::EntryPage(BMessage* settings, BRect frame, const char* name) - : WizardPageView(settings, frame, name, B_FOLLOW_ALL, + : + WizardPageView(settings, frame, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) { _BuildUI(); @@ -49,7 +49,6 @@ fSettings->ReplaceBool("install", fInstall->Value() != 0); } -static const float kTextDistance = 10; void EntryPage::_BuildUI() @@ -63,7 +62,8 @@ fInstall->ResizeToPreferred(); BRect textRect(rect); - textRect.left = fInstall->Frame().right + kTextDistance; + textRect.left = fInstall->Frame().right + + be_control_look->DefaultItemSpacing(); BString text; text << Modified: haiku/trunk/src/apps/bootman/EntryPage.h =================================================================== --- haiku/trunk/src/apps/bootman/EntryPage.h 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/EntryPage.h 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,7 +1,7 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Michael Pfeiffer <laplace@xxxxxxxxxxxxxxxxxxxxx> */ @@ -15,25 +15,27 @@ class BRadioButton; class BTextView; -class EntryPage : public WizardPageView -{ + +class EntryPage : public WizardPageView { public: - EntryPage(BMessage* settings, BRect frame, const char* name); - virtual ~EntryPage(); - - virtual void FrameResized(float width, float height); - - virtual void PageCompleted(); + EntryPage(BMessage* settings, BRect frame, + const char* name); + virtual ~EntryPage(); + virtual void FrameResized(float width, float height); + + virtual void PageCompleted(); + private: + void _BuildUI(); + void _Layout(); - void _BuildUI(); - void _Layout(); - - BRadioButton* fInstall; - BTextView* fInstallText; - BRadioButton* fUninstall; - BTextView* fUninstallText; +private: + BRadioButton* fInstall; + BTextView* fInstallText; + BRadioButton* fUninstall; + BTextView* fUninstallText; }; + #endif // ENTRY_PAGE_H Modified: haiku/trunk/src/apps/bootman/FileSelectionPage.cpp =================================================================== --- haiku/trunk/src/apps/bootman/FileSelectionPage.cpp 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/FileSelectionPage.cpp 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,5 +1,5 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,19 +9,17 @@ #include "FileSelectionPage.h" +#include <string.h> #include <Button.h> #include <Catalog.h> -#include <Locale.h> +#include <ControlLook.h> #include <Path.h> #include <RadioButton.h> #include <TextControl.h> #include <TextView.h> -#include <string.h> -#include <String.h> - #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "FileSelectionPage" @@ -29,12 +27,13 @@ const uint32 kMsgOpenFilePanel = 'open'; -FileSelectionPage::FileSelectionPage(BMessage* settings, BRect frame, const char* name, - const char* description, file_panel_mode mode) - : WizardPageView(settings, frame, name, B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) - , fMode(mode) - , fFilePanel(NULL) +FileSelectionPage::FileSelectionPage(BMessage* settings, BRect frame, + const char* name, const char* description, file_panel_mode mode) + : + WizardPageView(settings, frame, name, B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), + fMode(mode), + fFilePanel(NULL) { _BuildUI(description); } @@ -87,12 +86,12 @@ } -const float kTextDistance = 10; const float kFileButtonDistance = 10; void FileSelectionPage::_BuildUI(const char* description) { + const float kSpacing = be_control_look->DefaultItemSpacing(); BRect rect(Bounds()); fDescription = CreateDescription(rect, "description", description); @@ -110,7 +109,7 @@ fSelect->ResizeToPreferred(); float selectLeft = rect.right - fSelect->Bounds().Width(); - rect.right = selectLeft - kFileButtonDistance; + rect.right = selectLeft - kSpacing; fFile = new BTextControl(rect, "file", B_TRANSLATE_COMMENT("File:", "Text control label"), file.String(), new BMessage()); @@ -127,10 +126,11 @@ void FileSelectionPage::_Layout() { + const float kSpacing = be_control_look->DefaultItemSpacing(); LayoutDescriptionVertically(fDescription); float left = fFile->Frame().left; - float top = fDescription->Frame().bottom + kTextDistance; + float top = fDescription->Frame().bottom + kSpacing; // center "file" text field and "select" button vertically float selectTop = top; @@ -147,7 +147,7 @@ fFile->MoveTo(left, fileTop); - float width = fSelect->Frame().left - kFileButtonDistance - left; + float width = fSelect->Frame().left - kSpacing - left; fFile->ResizeTo(width, fileHeight); left = fSelect->Frame().left; @@ -172,11 +172,7 @@ BMessenger messenger(this); fFilePanel = new BFilePanel(fMode, &messenger, directory, - B_FILE_NODE, - false, - NULL, - NULL, - true); + B_FILE_NODE, false, NULL, NULL, true); if (fMode == B_SAVE_PANEL && file.Leaf() != NULL) fFilePanel->SetSaveText(file.Leaf()); fFilePanel->Show(); Modified: haiku/trunk/src/apps/bootman/FileSelectionPage.h =================================================================== --- haiku/trunk/src/apps/bootman/FileSelectionPage.h 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/FileSelectionPage.h 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,7 +1,7 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Michael Pfeiffer <laplace@xxxxxxxxxxxxxxxxxxxxx> */ @@ -18,33 +18,36 @@ class BTextControl; class BTextView; -class FileSelectionPage : public WizardPageView -{ + +class FileSelectionPage : public WizardPageView { public: - FileSelectionPage(BMessage* settings, BRect frame, const char* name, const char* description, - file_panel_mode mode); - virtual ~FileSelectionPage(); - - virtual void FrameResized(float width, float height); - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage* message); - - virtual void PageCompleted(); + FileSelectionPage(BMessage* settings, + BRect frame, const char* name, + const char* description, + file_panel_mode mode); + virtual ~FileSelectionPage(); + virtual void FrameResized(float width, float height); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); + + virtual void PageCompleted(); + private: + void _BuildUI(const char* description); + void _Layout(); + void _OpenFilePanel(); + void _SetFileFromFilePanelMessage(BMessage* message); + void _FilePanelCanceled(); - void _BuildUI(const char* description); - void _Layout(); - void _OpenFilePanel(); - void _SetFileFromFilePanelMessage(BMessage* message); - void _FilePanelCanceled(); - - file_panel_mode fMode; - BFilePanel* fFilePanel; +private: + file_panel_mode fMode; + BFilePanel* fFilePanel; - BTextView* fDescription; - BTextControl* fFile; - BButton* fSelect; + BTextView* fDescription; + BTextControl* fFile; + BButton* fSelect; }; + #endif // FILE_SELECTION_PAGE_H Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp =================================================================== --- haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2011-01-04 18:57:24 UTC (rev 40112) +++ haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2011-01-04 19:14:39 UTC (rev 40113) @@ -1,5 +1,5 @@ /* - * Copyright 2008, Haiku, Inc. All rights reserved. + * Copyright 2008-2010, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,30 +9,18 @@ #include "LegacyBootDrive.h" +#include <new> +#include <stdio.h> #include <Catalog.h> -#include <Drivers.h> +#include <DataIO.h> #include <DiskDevice.h> #include <DiskDeviceRoster.h> #include <DiskDeviceVisitor.h> -#include <Locale.h> +#include <File.h> #include <Partition.h> #include <Path.h> #include <String.h> - -#include <errno.h> -#include <fcntl.h> -#include <memory> -#include <new> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <ByteOrder.h> -#include <DataIO.h> -#include <File.h> -#include <String.h> #include <UTF8.h> #include "BootLoader.h" @@ -44,29 +32,68 @@ #define GET_FIRST_BIOS_DRIVE 1 -class Buffer : public BMallocIO -{ +struct MasterBootRecord { + uint8 bootLoader[440]; + uint8 diskSignature[4]; + uint8 reserved[2]; + uint8 partition[64]; + uint8 signature[2]; +}; + + +class LittleEndianMallocIO : public BMallocIO { public: - Buffer() : BMallocIO() {} - bool WriteInt8(int8 value); - bool WriteInt16(int16 value); - bool WriteInt32(int32 value); - bool WriteInt64(int64 value); - bool WriteString(const char* value); - bool Align(int16 alignment); - bool Fill(int16 size, int8 fillByte); + bool WriteInt8(int8 value); + bool WriteInt16(int16 value); + bool WriteInt32(int32 value); + bool WriteInt64(int64 value); + bool WriteString(const char* value); + bool Align(int16 alignment); + bool Fill(int16 size, int8 fillByte); }; +class PartitionRecorder : public BDiskDeviceVisitor { +public: + PartitionRecorder(BMessage* settings, + int8 drive); + + virtual bool Visit(BDiskDevice* device); + virtual bool Visit(BPartition* partition, int32 level); + + bool HasPartitions() const; + off_t FirstOffset() const; + +private: + bool _Record(BPartition* partition); + +private: + BMessage* fSettings; + int8 fDrive; + int32 fIndex; + off_t fFirstOffset; +}; + + +static const uint32 kBlockSize = 512; +static const uint32 kNumberOfBootLoaderBlocks = 4; + // The number of blocks required to store the + // MBR including the Haiku boot loader. + +static const uint32 kMBRSignature = 0xAA55; + +static const int32 kMaxBootMenuItemLength = 70; + + bool -Buffer::WriteInt8(int8 value) +LittleEndianMallocIO::WriteInt8(int8 value) { return Write(&value, sizeof(value)) == sizeof(value); } bool -Buffer::WriteInt16(int16 value) +LittleEndianMallocIO::WriteInt16(int16 value) { return WriteInt8(value & 0xff) && WriteInt8(value >> 8); @@ -74,7 +101,7 @@ bool -Buffer::WriteInt32(int32 value) +LittleEndianMallocIO::WriteInt32(int32 value) { return WriteInt8(value & 0xff) && WriteInt8(value >> 8) @@ -84,14 +111,14 @@ bool -Buffer::WriteInt64(int64 value) +LittleEndianMallocIO::WriteInt64(int64 value) { return WriteInt32(value) && WriteInt32(value >> 32); } bool -Buffer::WriteString(const char* value) +LittleEndianMallocIO::WriteString(const char* value) { int len = strlen(value) + 1; return WriteInt8(len) @@ -100,7 +127,7 @@ bool -Buffer::Align(int16 alignment) +LittleEndianMallocIO::Align(int16 alignment) { if ((Position() % alignment) == 0) return true; @@ -109,7 +136,7 @@ bool -Buffer::Fill(int16 size, int8 fillByte) +LittleEndianMallocIO::Fill(int16 size, int8 fillByte) { for (int i = 0; i < size; i ++) { if (!WriteInt8(fillByte)) @@ -119,32 +146,15 @@ } -class PartitionRecorder : public BDiskDeviceVisitor -{ -public: - PartitionRecorder(BMessage* settings, int8 drive); +// #pragma mark - - virtual bool Visit(BDiskDevice* device); - virtual bool Visit(BPartition* partition, int32 level); - bool HasPartitions() const; - off_t FirstOffset() const; - -private: - bool _Record(BPartition* partition); - - BMessage* fSettings; - int8 fDrive; - int32 fIndex; - off_t fFirstOffset; -}; - - PartitionRecorder::PartitionRecorder(BMessage* settings, int8 drive) - : fSettings(settings) - , fDrive(drive) - , fIndex(0) - , fFirstOffset(LONGLONG_MAX) + : + fSettings(settings), + fDrive(drive), + fIndex(0), + fFirstOffset(LONGLONG_MAX) { } @@ -225,6 +235,9 @@ } +// #pragma mark - + + LegacyBootDrive::LegacyBootDrive() { } @@ -323,21 +336,22 @@ return B_BAD_VALUE; } - Buffer newBootLoader; + LittleEndianMallocIO newBootLoader; ssize_t size = sizeof(kBootLoader); if (newBootLoader.Write(kBootLoader, size) != size) { close(fd); return B_NO_MEMORY; } - MasterBootRecord* newMBR = (MasterBootRecord*)newBootLoader.BMallocIO::Buffer(); + MasterBootRecord* newMBR = (MasterBootRecord*)newBootLoader.Buffer(); _CopyPartitionTable(newMBR, &oldMBR); int menuEntries = 0; int defaultMenuEntry = 0; BMessage partition; int32 index; - for (index = 0; settings->FindMessage("partition", index, &partition) == B_OK; index ++) { + for (index = 0; settings->FindMessage("partition", index, + &partition) == B_OK; index ++) { bool show; partition.FindBool("show", &show); if (!show) @@ -351,8 +365,8 @@ newBootLoader.WriteInt16(defaultMenuEntry); newBootLoader.WriteInt16(timeout); - - for (index = 0; settings->FindMessage("partition", index, &partition) == B_OK; index ++) { + for (index = 0; settings->FindMessage("partition", index, + &partition) == B_OK; index ++) { bool show; BString name; BString path; @@ -381,7 +395,7 @@ } lseek(fd, 0, SEEK_SET); - const uint8* buffer = (uint8*)newBootLoader.BMallocIO::Buffer(); + const uint8* buffer = (const uint8*)newBootLoader.Buffer(); status_t status = _WriteBlocks(fd, buffer, newBootLoader.Position()); close(fd); return status; @@ -593,14 +607,14 @@ const MasterBootRecord* source) { memcpy(destination->diskSignature, source->diskSignature, - sizeof(source->diskSignature) + sizeof(source->reserved) + - sizeof(source->partition)); + sizeof(source->diskSignature) + sizeof(source->reserved) + + sizeof(source->partition)); } bool LegacyBootDrive::_IsValid(const MasterBootRecord* mbr) { - return mbr->signature[0] == (kMBRSignature & 0xff) && - mbr->signature[1] == (kMBRSignature >> 8); + return mbr->signature[0] == (kMBRSignature & 0xff) + && mbr->signature[1] == (kMBRSignature >> 8); } Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.h =================================================================== [... truncated: 1113 lines follow ...]