[haiku-commits] haiku: hrev45191 - in src: add-ons/kernel/partitioning_systems/gpt add-ons/kernel/partitioning_systems/efi add-ons/disk_systems/gpt apps/drivesetup

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 23 Jan 2013 23:22:16 +0100 (CET)

hrev45191 adds 4 changesets to branch 'master'
old head: 5e081035a745c3fe49713d308115352da9e96b37
new head: 61ba12594bf9f447b1384bda0bcd8e4b1e56e315
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=61ba125+%5E5e08103

----------------------------------------------------------------------------

b039ee6: Minor cleanup.
  
  * Renamed *MI members to *MenuItem.

3478d6a: gpt: moved type map into its own header.

b44f928: gpt: early work in progress of a disk system add-on.
  
  * It currently allows to initialize a disk using GPT. However, this then
    fails somewhere in the kernel.

61ba125: Renamed partitioning system "efi" directory to "gpt".

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

21 files changed, 580 insertions(+), 86 deletions(-)
src/add-ons/disk_systems/Jamfile                 |   1 +
src/add-ons/disk_systems/gpt/GPTDiskAddOn.cpp    | 155 +++++++++++++++++++
src/add-ons/disk_systems/gpt/GPTDiskAddOn.h      |  35 +++++
src/add-ons/disk_systems/gpt/GPTDiskAddOn.rdef   |  15 ++
src/add-ons/disk_systems/gpt/GPTDiskSystem.cpp   |  24 +++
.../disk_systems/gpt/GPTPartitionHandle.cpp      | 155 +++++++++++++++++++
.../disk_systems/gpt/GPTPartitionHandle.h        |  45 ++++++
src/add-ons/disk_systems/gpt/Jamfile             |  17 ++
src/add-ons/disk_systems/gpt/Utility.h           |  26 ++++
src/add-ons/kernel/partitioning_systems/Jamfile  |   2 +-
.../partitioning_systems/{efi => gpt}/Jamfile    |   2 +-
.../{efi => gpt}/PartitionLocker.cpp             |   0
.../{efi => gpt}/PartitionLocker.h               |   0
.../{efi => gpt}/efi_gpt.cpp                     |  33 +---
.../partitioning_systems/{efi => gpt}/efi_gpt.h  |   0
.../partitioning_systems/gpt/gpt_known_guids.h   |  47 ++++++
.../partitioning_systems/{efi => gpt}/guid.h     |   0
src/apps/drivesetup/MainWindow.cpp               |  81 +++++-----
src/apps/drivesetup/MainWindow.h                 |  20 +--
src/system/boot/loader/Jamfile                   |   4 +-
src/tests/system/boot/loader/Jamfile             |   4 +-

############################################################################

Commit:      b039ee6572e456ad87d7240fe9e79bada2917105
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b039ee6
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 23 20:44:13 2013 UTC

Minor cleanup.

* Renamed *MI members to *MenuItem.

----------------------------------------------------------------------------

diff --git a/src/apps/drivesetup/MainWindow.cpp 
b/src/apps/drivesetup/MainWindow.cpp
index f97a869..8850b59 100644
--- a/src/apps/drivesetup/MainWindow.cpp
+++ b/src/apps/drivesetup/MainWindow.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2010 Haiku Inc. All rights reserved.
+ * Copyright 2002-2013 Haiku Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
@@ -170,59 +170,60 @@ MainWindow::MainWindow(BRect frame)
        BMenuBar* menuBar = new BMenuBar(Bounds(), "root menu");
 
        // create all the menu items
-       fWipeMI = new BMenuItem(B_TRANSLATE("Wipe (not implemented)"),
+       fWipeMenuItem = new BMenuItem(B_TRANSLATE("Wipe (not implemented)"),
                new BMessage(MSG_FORMAT));
-       fEjectMI = new BMenuItem(B_TRANSLATE("Eject"),
+       fEjectMenuItem = new BMenuItem(B_TRANSLATE("Eject"),
                new BMessage(MSG_EJECT), 'E');
-       fSurfaceTestMI = new BMenuItem(
+       fSurfaceTestMenuItem = new BMenuItem(
                B_TRANSLATE("Surface test (not implemented)"),
                new BMessage(MSG_SURFACE_TEST));
-       fRescanMI = new BMenuItem(B_TRANSLATE("Rescan"), new 
BMessage(MSG_RESCAN));
+       fRescanMenuItem = new BMenuItem(B_TRANSLATE("Rescan"),
+               new BMessage(MSG_RESCAN));
 
-       fCreateMI = new BMenuItem(B_TRANSLATE("Create" B_UTF8_ELLIPSIS),
+       fCreateMenuItem = new BMenuItem(B_TRANSLATE("Create" B_UTF8_ELLIPSIS),
                new BMessage(MSG_CREATE), 'C');
-       fDeleteMI = new BMenuItem(B_TRANSLATE("Delete"),
+       fDeleteMenuItem = new BMenuItem(B_TRANSLATE("Delete"),
                new BMessage(MSG_DELETE), 'D');
 
-       fMountMI = new BMenuItem(B_TRANSLATE("Mount"),
+       fMountMenuItem = new BMenuItem(B_TRANSLATE("Mount"),
                new BMessage(MSG_MOUNT), 'M');
-       fUnmountMI = new BMenuItem(B_TRANSLATE("Unmount"),
+       fUnmountMenuItem = new BMenuItem(B_TRANSLATE("Unmount"),
                new BMessage(MSG_UNMOUNT), 'U');
-       fMountAllMI = new BMenuItem(B_TRANSLATE("Mount all"),
+       fMountAllMenuItem = new BMenuItem(B_TRANSLATE("Mount all"),
                new BMessage(MSG_MOUNT_ALL), 'M', B_SHIFT_KEY);
 
        // Disk menu
        fDiskMenu = new BMenu(B_TRANSLATE("Disk"));
 
-       // fDiskMenu->AddItem(fWipeMI);
+       // fDiskMenu->AddItem(fWipeMenuItem);
        fDiskInitMenu = new BMenu(B_TRANSLATE("Initialize"));
        fDiskMenu->AddItem(fDiskInitMenu);
 
        fDiskMenu->AddSeparatorItem();
 
-       fDiskMenu->AddItem(fEjectMI);
-       // fDiskMenu->AddItem(fSurfaceTestMI);
-       fDiskMenu->AddItem(fRescanMI);
+       fDiskMenu->AddItem(fEjectMenuItem);
+       // fDiskMenu->AddItem(fSurfaceTestMenuItem);
+       fDiskMenu->AddItem(fRescanMenuItem);
 
        menuBar->AddItem(fDiskMenu);
 
        // Parition menu
        fPartitionMenu = new BMenu(B_TRANSLATE("Partition"));
-       fPartitionMenu->AddItem(fCreateMI);
+       fPartitionMenu->AddItem(fCreateMenuItem);
 
        fFormatMenu = new BMenu(B_TRANSLATE("Format"));
        fPartitionMenu->AddItem(fFormatMenu);
 
-       fPartitionMenu->AddItem(fDeleteMI);
+       fPartitionMenu->AddItem(fDeleteMenuItem);
 
        fPartitionMenu->AddSeparatorItem();
 
-       fPartitionMenu->AddItem(fMountMI);
-       fPartitionMenu->AddItem(fUnmountMI);
+       fPartitionMenu->AddItem(fMountMenuItem);
+       fPartitionMenu->AddItem(fUnmountMenuItem);
 
        fPartitionMenu->AddSeparatorItem();
 
-       fPartitionMenu->AddItem(fMountAllMI);
+       fPartitionMenu->AddItem(fMountAllMenuItem);
        menuBar->AddItem(fPartitionMenu);
 
        AddChild(menuBar);
@@ -523,21 +524,21 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
        while (BMenuItem* item = fDiskInitMenu->RemoveItem((int32)0))
                delete item;
 
-       fCreateMI->SetEnabled(false);
-       fUnmountMI->SetEnabled(false);
+       fCreateMenuItem->SetEnabled(false);
+       fUnmountMenuItem->SetEnabled(false);
        fDiskInitMenu->SetEnabled(false);
        fFormatMenu->SetEnabled(false);
 
        if (!disk) {
-               fWipeMI->SetEnabled(false);
-               fEjectMI->SetEnabled(false);
-               fSurfaceTestMI->SetEnabled(false);
+               fWipeMenuItem->SetEnabled(false);
+               fEjectMenuItem->SetEnabled(false);
+               fSurfaceTestMenuItem->SetEnabled(false);
        } else {
-//             fWipeMI->SetEnabled(true);
-               fWipeMI->SetEnabled(false);
-               fEjectMI->SetEnabled(disk->IsRemovableMedia());
-//             fSurfaceTestMI->SetEnabled(true);
-               fSurfaceTestMI->SetEnabled(false);
+//             fWipeMenuItem->SetEnabled(true);
+               fWipeMenuItem->SetEnabled(false);
+               fEjectMenuItem->SetEnabled(disk->IsRemovableMedia());
+//             fSurfaceTestMenuItem->SetEnabled(true);
+               fSurfaceTestMenuItem->SetEnabled(false);
 
                // Create menu and items
                BPartition* parentPartition = NULL;
@@ -547,11 +548,11 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
                }
 
                if (parentPartition && 
parentPartition->ContainsPartitioningSystem())
-                       fCreateMI->SetEnabled(true);
+                       fCreateMenuItem->SetEnabled(true);
 
                bool prepared = disk->PrepareModifications() == B_OK;
                fFormatMenu->SetEnabled(prepared);
-               fDeleteMI->SetEnabled(prepared);
+               fDeleteMenuItem->SetEnabled(prepared);
 
                BPartition* partition = disk->FindDescendant(selectedPartition);
 
@@ -584,7 +585,7 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
                }
 
                // Mount items
-               if (partition) {
+               if (partition != NULL) {
                        fFormatMenu->SetEnabled(!partition->IsMounted()
                                && !partition->IsReadOnly()
                                && partition->Device()->HasMedia()
@@ -596,10 +597,10 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
                                && partition->IsDevice()
                                && fDiskInitMenu->CountItems() > 0);
 
-                       fDeleteMI->SetEnabled(!partition->IsMounted()
+                       fDeleteMenuItem->SetEnabled(!partition->IsMounted()
                                && !partition->IsDevice());
 
-                       fMountMI->SetEnabled(!partition->IsMounted());
+                       fMountMenuItem->SetEnabled(!partition->IsMounted());
 
                        bool unMountable = false;
                        if (partition->IsMounted()) {
@@ -612,10 +613,10 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
                                } else
                                        unMountable = true;
                        }
-                       fUnmountMI->SetEnabled(unMountable);
+                       fUnmountMenuItem->SetEnabled(unMountable);
                } else {
-                       fDeleteMI->SetEnabled(false);
-                       fMountMI->SetEnabled(false);
+                       fDeleteMenuItem->SetEnabled(false);
+                       fMountMenuItem->SetEnabled(false);
                        fFormatMenu->SetEnabled(false);
                        fDiskInitMenu->SetEnabled(false);
                }
@@ -623,11 +624,11 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
                if (prepared)
                        disk->CancelModifications();
 
-               fMountAllMI->SetEnabled(true);
+               fMountAllMenuItem->SetEnabled(true);
        }
        if (selectedPartition < 0) {
-               fDeleteMI->SetEnabled(false);
-               fMountMI->SetEnabled(false);
+               fDeleteMenuItem->SetEnabled(false);
+               fMountMenuItem->SetEnabled(false);
        }
 }
 
diff --git a/src/apps/drivesetup/MainWindow.h b/src/apps/drivesetup/MainWindow.h
index 24d0e44..048ac27 100644
--- a/src/apps/drivesetup/MainWindow.h
+++ b/src/apps/drivesetup/MainWindow.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2008 Haiku Inc. All rights reserved.
+ * Copyright 2002-2013 Haiku Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
@@ -88,16 +88,16 @@ private:
                        BMenu*                          fPartitionMenu;
                        BMenu*                          fFormatMenu;
 
-                       BMenuItem*                      fWipeMI;
-                       BMenuItem*                      fEjectMI;
-                       BMenuItem*                      fSurfaceTestMI;
-                       BMenuItem*                      fRescanMI;
+                       BMenuItem*                      fWipeMenuItem;
+                       BMenuItem*                      fEjectMenuItem;
+                       BMenuItem*                      fSurfaceTestMenuItem;
+                       BMenuItem*                      fRescanMenuItem;
 
-                       BMenuItem*                      fCreateMI;
-                       BMenuItem*                      fDeleteMI;
-                       BMenuItem*                      fMountMI;
-                       BMenuItem*                      fUnmountMI;
-                       BMenuItem*                      fMountAllMI;
+                       BMenuItem*                      fCreateMenuItem;
+                       BMenuItem*                      fDeleteMenuItem;
+                       BMenuItem*                      fMountMenuItem;
+                       BMenuItem*                      fUnmountMenuItem;
+                       BMenuItem*                      fMountAllMenuItem;
 };
 
 

############################################################################

Commit:      3478d6ab2d7e5b4e6af36c410b49a9f693310033
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3478d6a
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 23 22:15:48 2013 UTC

gpt: moved type map into its own header.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/partitioning_systems/efi/efi_gpt.cpp 
b/src/add-ons/kernel/partitioning_systems/efi/efi_gpt.cpp
index 6ab4665..4041cfe1 100644
--- a/src/add-ons/kernel/partitioning_systems/efi/efi_gpt.cpp
+++ b/src/add-ons/kernel/partitioning_systems/efi/efi_gpt.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Michael Lotz, mmlr@xxxxxxxx. All rights reserved.
- * Copyright 2007-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2007-2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  *
  * Distributed under the terms of the MIT License.
  */
@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "gpt_known_guids.h"
+
 
 #define TRACE_EFI_GPT
 #ifdef TRACE_EFI_GPT
@@ -36,35 +38,6 @@
 #define EFI_PARTITION_MODULE_NAME "partitioning_systems/efi_gpt/v1"
 
 
-struct static_guid {
-       uint32  data1;
-       uint16  data2;
-       uint16  data3;
-       uint64  data4;
-
-       inline bool operator==(const guid &other) const;
-} _PACKED;
-
-const static struct type_map {
-       static_guid     guid;
-       const char      *type;
-} kTypeMap[] = {
-       {{0xC12A7328, 0xF81F, 0x11D2, 0xBA4B00A0C93EC93BLL}, "EFI System Data"},
-       {{0x21686148, 0x6449, 0x6E6F, 0x744E656564454649LL}, "BIOS Boot Data"},
-       {{0x024DEE41, 0x33E7, 0x11D3, 0x9D690008C781F39FLL}, "MBR Partition 
Nest"},
-       {{0x42465331, 0x3BA3, 0x10F1, 0x802A4861696B7521LL}, "Haiku BFS"},
-       {{0x0FC63DAF, 0x8483, 0x4772, 0x8E793D69D8477DE4LL}, "Linux File 
System"},
-       {{0xA19D880F, 0x05FC, 0x4D3B, 0xA006743F0F84911ELL}, "Linux RAID"},
-       {{0x0657FD6D, 0xA4AB, 0x43C4, 0x84E50933C84B4F4FLL}, "Linux Swap"},
-       {{0xE6D6D379, 0xF507, 0x44C2, 0xA23C238F2A3DF928LL}, "Linux LVM"},
-       {{0xEBD0A0A2, 0xB9E5, 0x4433, 0x87C068B6B72699C7LL}, "Windows Data"},
-       {{0x48465300, 0x0000, 0x11AA, 0xAA1100306543ECACLL}, "HFS+ File 
System"},
-       {{0x55465300, 0x0000, 0x11AA, 0xAA1100306543ECACLL}, "UFS File System"},
-       {{0x52414944, 0x0000, 0x11AA, 0xAA1100306543ECACLL}, "Apple RAID"},
-       {{0x52414944, 0x5F4F, 0x11AA, 0xAA1100306543ECACLL}, "Apple RAID, 
offline"}
-};
-
-
 namespace EFI {
 
 class Header {
diff --git a/src/add-ons/kernel/partitioning_systems/efi/gpt_known_guids.h 
b/src/add-ons/kernel/partitioning_systems/efi/gpt_known_guids.h
new file mode 100644
index 0000000..6f450a2
--- /dev/null
+++ b/src/add-ons/kernel/partitioning_systems/efi/gpt_known_guids.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2009, Michael Lotz, mmlr@xxxxxxxx. All rights reserved.
+ * Copyright 2007-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ *
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef GPT_KNOWN_GUIDS_H
+#define GPT_KNOWN_GUIDS_H
+
+
+#include <disk_device_types.h>
+
+
+struct guid;
+
+
+struct static_guid {
+       uint32  data1;
+       uint16  data2;
+       uint16  data3;
+       uint64  data4;
+
+       inline bool operator==(const guid &other) const;
+} _PACKED;
+
+
+const static struct type_map {
+       static_guid     guid;
+       const char      *type;
+} kTypeMap[] = {
+       {{0xC12A7328, 0xF81F, 0x11D2, 0xBA4B00A0C93EC93BLL}, "EFI System Data"},
+       {{0x21686148, 0x6449, 0x6E6F, 0x744E656564454649LL}, "BIOS Boot Data"},
+       {{0x024DEE41, 0x33E7, 0x11D3, 0x9D690008C781F39FLL}, "MBR Partition 
Nest"},
+       {{0x42465331, 0x3BA3, 0x10F1, 0x802A4861696B7521LL}, BFS_NAME},
+       {{0x0FC63DAF, 0x8483, 0x4772, 0x8E793D69D8477DE4LL}, "Linux File 
System"},
+       {{0xA19D880F, 0x05FC, 0x4D3B, 0xA006743F0F84911ELL}, "Linux RAID"},
+       {{0x0657FD6D, 0xA4AB, 0x43C4, 0x84E50933C84B4F4FLL}, "Linux Swap"},
+       {{0xE6D6D379, 0xF507, 0x44C2, 0xA23C238F2A3DF928LL}, "Linux LVM"},
+       {{0xEBD0A0A2, 0xB9E5, 0x4433, 0x87C068B6B72699C7LL}, "Windows Data"},
+       {{0x48465300, 0x0000, 0x11AA, 0xAA1100306543ECACLL}, "HFS+ File 
System"},
+       {{0x55465300, 0x0000, 0x11AA, 0xAA1100306543ECACLL}, "UFS File System"},
+       {{0x52414944, 0x0000, 0x11AA, 0xAA1100306543ECACLL}, "Apple RAID"},
+       {{0x52414944, 0x5F4F, 0x11AA, 0xAA1100306543ECACLL}, "Apple RAID, 
offline"}
+};
+
+
+#endif // GPT_KNOWN_GUIDS_H

############################################################################

Commit:      b44f9282b7bc551e4aaf72acc467742f82c10a5c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b44f928
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 23 22:16:30 2013 UTC

gpt: early work in progress of a disk system add-on.

* It currently allows to initialize a disk using GPT. However, this then
  fails somewhere in the kernel.

----------------------------------------------------------------------------

diff --git a/src/add-ons/disk_systems/Jamfile b/src/add-ons/disk_systems/Jamfile
index 6262e19..9ef53ba 100644
--- a/src/add-ons/disk_systems/Jamfile
+++ b/src/add-ons/disk_systems/Jamfile
@@ -1,5 +1,6 @@
 SubDir HAIKU_TOP src add-ons disk_systems ;
 
 SubInclude HAIKU_TOP src add-ons disk_systems bfs ;
+SubInclude HAIKU_TOP src add-ons disk_systems gpt ;
 SubInclude HAIKU_TOP src add-ons disk_systems intel ;
 SubInclude HAIKU_TOP src add-ons disk_systems ntfs ;
diff --git a/src/add-ons/disk_systems/gpt/GPTDiskAddOn.cpp 
b/src/add-ons/disk_systems/gpt/GPTDiskAddOn.cpp
new file mode 100644
index 0000000..5fc79e0
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/GPTDiskAddOn.cpp
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include "GPTDiskAddOn.h"
+
+#include <new>
+#include <stdio.h>
+
+#include <DiskDeviceTypes.h>
+#include <MutablePartition.h>
+#include <PartitioningInfo.h>
+#include <PartitionParameterEditor.h>
+
+#include <AutoDeleter.h>
+#include <disk_device_types.h>
+
+#include "efi_gpt.h"
+
+#include "GPTPartitionHandle.h"
+#include "Utility.h"
+
+
+//#define TRACE_GPT_DISK_ADD_ON
+#undef TRACE
+#ifdef TRACE_GPT_DISK_ADD_ON
+#      define TRACE(x...) printf(x)
+#else
+#      define TRACE(x...) do {} while (false)
+#endif
+
+
+static const uint32 kDiskSystemFlags =
+       0
+//     | B_DISK_SYSTEM_SUPPORTS_CHECKING
+//     | B_DISK_SYSTEM_SUPPORTS_REPAIRING
+//     | B_DISK_SYSTEM_SUPPORTS_RESIZING
+//     | B_DISK_SYSTEM_SUPPORTS_MOVING
+//     | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME
+//     | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS
+       | B_DISK_SYSTEM_SUPPORTS_INITIALIZING
+//     | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
+
+//     | B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD
+//     | B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD
+//     | B_DISK_SYSTEM_SUPPORTS_SETTING_NAME
+       | B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE
+//     | B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS
+       | B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD
+       | B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD
+//     | B_DISK_SYSTEM_SUPPORTS_NAME
+;
+
+
+// #pragma mark - GPTDiskAddOn
+
+
+GPTDiskAddOn::GPTDiskAddOn()
+       :
+       BDiskSystemAddOn(EFI_PARTITION_NAME, kDiskSystemFlags)
+{
+}
+
+
+GPTDiskAddOn::~GPTDiskAddOn()
+{
+}
+
+
+status_t
+GPTDiskAddOn::CreatePartitionHandle(BMutablePartition* partition,
+       BPartitionHandle** _handle)
+{
+       GPTPartitionHandle* handle
+               = new(std::nothrow) GPTPartitionHandle(partition);
+       if (handle == NULL)
+               return B_NO_MEMORY;
+
+       status_t error = handle->Init();
+       if (error != B_OK) {
+               delete handle;
+               return error;
+       }
+
+       *_handle = handle;
+       return B_OK;
+}
+
+
+bool
+GPTDiskAddOn::CanInitialize(const BMutablePartition* partition)
+{
+       // If it's big enough, we can initialize it.
+       return partition->Size() >= round_up(partition->BlockSize()
+                       + EFI_PARTITION_ENTRY_COUNT * EFI_PARTITION_ENTRY_SIZE,
+               partition->BlockSize());
+}
+
+
+status_t
+GPTDiskAddOn::GetInitializationParameterEditor(
+       const BMutablePartition* partition, BPartitionParameterEditor** editor)
+{
+       // Nothing to edit, really.
+       *editor = NULL;
+       return B_OK;
+}
+
+
+status_t
+GPTDiskAddOn::ValidateInitialize(const BMutablePartition* partition,
+       BString* name, const char* parameters)
+{
+       if (!CanInitialize(partition)
+               || (parameters != NULL && parameters[0] != '\0'))
+               return B_BAD_VALUE;
+
+       // we don't support a content name
+       if (name != NULL)
+               name->Truncate(0);
+
+       return B_OK;
+}
+
+
+status_t
+GPTDiskAddOn::Initialize(BMutablePartition* partition, const char* name,
+       const char* parameters, BPartitionHandle** _handle)
+{
+       if (!CanInitialize(partition)
+               || (name != NULL && name[0] != '\0')
+               || (parameters != NULL && parameters[0] != '\0'))
+               return B_BAD_VALUE;
+
+       GPTPartitionHandle* handle
+               = new(std::nothrow) GPTPartitionHandle(partition);
+       if (handle == NULL)
+               return B_NO_MEMORY;
+
+       status_t status = partition->SetContentType(Name());
+       if (status != B_OK) {
+               delete handle;
+               return status;
+       }
+
+       partition->SetContentName(NULL);
+       partition->SetContentParameters(NULL);
+       partition->SetContentSize(
+               round_down(partition->Size(), partition->BlockSize()));
+
+       *_handle = handle;
+       return B_OK;
+}
diff --git a/src/add-ons/disk_systems/gpt/GPTDiskAddOn.h 
b/src/add-ons/disk_systems/gpt/GPTDiskAddOn.h
new file mode 100644
index 0000000..40349b7
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/GPTDiskAddOn.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef GPT_DISK_ADD_ON_H
+#define GPT_DISK_ADD_ON_H
+
+
+#include <DiskSystemAddOn.h>
+
+
+class GPTDiskAddOn : public BDiskSystemAddOn {
+public:
+                                                               GPTDiskAddOn();
+       virtual                                         ~GPTDiskAddOn();
+
+       virtual status_t                        CreatePartitionHandle(
+                                                                       
BMutablePartition* partition,
+                                                                       
BPartitionHandle** handle);
+
+       virtual bool                            CanInitialize(
+                                                                       const 
BMutablePartition* partition);
+       virtual status_t                        
GetInitializationParameterEditor(
+                                                                       const 
BMutablePartition* partition,
+                                                                       
BPartitionParameterEditor** editor);
+       virtual status_t                        ValidateInitialize(
+                                                                       const 
BMutablePartition* partition,
+                                                                       
BString* name, const char* parameters);
+       virtual status_t                        Initialize(BMutablePartition* 
partition,
+                                                                       const 
char* name, const char* parameters,
+                                                                       
BPartitionHandle** handle);
+};
+
+
+#endif // GPT_DISK_ADD_ON_H
diff --git a/src/add-ons/disk_systems/gpt/GPTDiskAddOn.rdef 
b/src/add-ons/disk_systems/gpt/GPTDiskAddOn.rdef
new file mode 100644
index 0000000..18ca93a
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/GPTDiskAddOn.rdef
@@ -0,0 +1,15 @@
+/*
+ * IntelDiskAddOn.rdef
+ */
+
+resource app_signature "application/x-vnd.Haiku-IntelDiskAddOn";
+
+resource app_version {
+       major  = 1,
+       middle = 0,
+       minor  = 0,
+       variety = 0,
+       internal = 0,
+       short_info = "1.0.0",
+       long_info = "Haiku Intel disk add-on."
+};
diff --git a/src/add-ons/disk_systems/gpt/GPTDiskSystem.cpp 
b/src/add-ons/disk_systems/gpt/GPTDiskSystem.cpp
new file mode 100644
index 0000000..a40b840
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/GPTDiskSystem.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <new>
+
+#include <List.h>
+
+#include "GPTDiskAddOn.h"
+
+
+status_t
+get_disk_system_add_ons(BList* addOns)
+{
+       GPTDiskAddOn* addOn = new(std::nothrow) GPTDiskAddOn();
+       if (!addOns->AddItem(addOn)) {
+               delete addOn;
+               return B_NO_MEMORY;
+       }
+
+       return B_OK;
+}
diff --git a/src/add-ons/disk_systems/gpt/GPTPartitionHandle.cpp 
b/src/add-ons/disk_systems/gpt/GPTPartitionHandle.cpp
new file mode 100644
index 0000000..abff127
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/GPTPartitionHandle.cpp
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include "GPTPartitionHandle.h"
+
+#include <new>
+#include <stdio.h>
+
+#include <DiskDeviceTypes.h>
+#include <MutablePartition.h>
+#include <PartitioningInfo.h>
+#include <PartitionParameterEditor.h>
+
+#include <AutoDeleter.h>
+
+#include "gpt_known_guids.h"
+
+
+//#define TRACE_GPT_PARTITION_HANDLE
+#undef TRACE
+#ifdef TRACE_GPT_PARTITION_HANDLE
+#      define TRACE(x...) printf(x)
+#else
+#      define TRACE(x...) do {} while (false)
+#endif
+
+
+GPTPartitionHandle::GPTPartitionHandle(BMutablePartition* partition)
+       :
+       BPartitionHandle(partition)
+{
+}
+
+
+GPTPartitionHandle::~GPTPartitionHandle()
+{
+}
+
+
+status_t
+GPTPartitionHandle::Init()
+{
+       return B_OK;
+}
+
+
+uint32
+GPTPartitionHandle::SupportedOperations(uint32 mask)
+{
+       uint32 flags = B_DISK_SYSTEM_SUPPORTS_RESIZING
+               | B_DISK_SYSTEM_SUPPORTS_MOVING
+               | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS
+               | B_DISK_SYSTEM_SUPPORTS_INITIALIZING;
+
+       // creating child
+       if ((mask & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD) != 0) {
+               BPartitioningInfo info;
+               if (GetPartitioningInfo(&info) == B_OK
+                       && info.CountPartitionableSpaces() > 1) {
+                       flags |= B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD;
+               }
+       }
+
+       return flags;
+}
+
+
+uint32
+GPTPartitionHandle::SupportedChildOperations(const BMutablePartition* child,
+       uint32 mask)
+{
+       return B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD
+               | B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD
+               | B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE
+               | B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD;
+}
+
+
+status_t
+GPTPartitionHandle::GetNextSupportedType(const BMutablePartition* child,
+       int32* cookie, BString* type)
+{
+       int32 index = *cookie;
+       TRACE("GPTPartitionHandle::GetNextSupportedType(child: %p, cookie: 
%ld)\n",
+               child, index);
+
+       if (index >= int32(sizeof(kTypeMap) / sizeof(kTypeMap[0])))
+               return B_ENTRY_NOT_FOUND;
+
+       type->SetTo(kTypeMap[index].type);
+       *cookie = index + 1;
+
+       return B_OK;
+}
+
+
+status_t
+GPTPartitionHandle::GetPartitioningInfo(BPartitioningInfo* info)
+{
+       // init to the full size (minus the first sector)
+       off_t size = Partition()->ContentSize();
+       status_t error = info->SetTo(Partition()->BlockSize(),
+               size - Partition()->BlockSize());
+       if (error != B_OK)
+               return error;
+
+       // TODO: exclude the space of the existing partitions
+
+       return B_OK;
+}
+
+
+status_t
+GPTPartitionHandle::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
+       BPartitionParameterEditor** editor)
+{
+       *editor = NULL;
+       if (type == B_CREATE_PARAMETER_EDITOR) {
+               try {
+                       *editor = new BPartitionParameterEditor();
+               } catch (std::bad_alloc) {
+                       return B_NO_MEMORY;
+               }
+               return B_OK;
+       }
+       return B_NOT_SUPPORTED;
+}
+
+
+status_t
+GPTPartitionHandle::ValidateCreateChild(off_t* _offset, off_t* _size,
+       const char* typeString, BString* name, const char* parameters)
+{
+       return B_BAD_VALUE;
+}
+
+
+status_t
+GPTPartitionHandle::CreateChild(off_t offset, off_t size,
+       const char* typeString, const char* name, const char* parameters,
+       BMutablePartition** _child)
+{
+       return B_BAD_VALUE;
+}
+
+
+status_t
+GPTPartitionHandle::DeleteChild(BMutablePartition* child)
+{
+       BMutablePartition* parent = child->Parent();
+       return parent->DeleteChild(child);
+}
diff --git a/src/add-ons/disk_systems/gpt/GPTPartitionHandle.h 
b/src/add-ons/disk_systems/gpt/GPTPartitionHandle.h
new file mode 100644
index 0000000..23fbf14
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/GPTPartitionHandle.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef GPT_PARTITION_HANDLE_H
+#define GPT_PARTITION_HANDLE_H
+
+
+#include <DiskSystemAddOn.h>
+
+
+class GPTPartitionHandle : public BPartitionHandle {
+public:
+                                                               
GPTPartitionHandle(
+                                                                       
BMutablePartition* partition);
+       virtual                                         ~GPTPartitionHandle();
+
+                       status_t                        Init();
+
+       virtual uint32                          SupportedOperations(uint32 
mask);
+       virtual uint32                          SupportedChildOperations(
+                                                                       const 
BMutablePartition* child,
+                                                                       uint32 
mask);
+
+       virtual status_t                        GetNextSupportedType(
+                                                                       const 
BMutablePartition* child,
+                                                                       int32* 
cookie, BString* type);
+
+       virtual status_t                        
GetPartitioningInfo(BPartitioningInfo* info);
+
+       virtual status_t                        GetParameterEditor(
+                                                                       
B_PARAMETER_EDITOR_TYPE type,
+                                                                       
BPartitionParameterEditor** editor);
+       virtual status_t                        ValidateCreateChild(off_t* 
offset,
+                                                                       off_t* 
size, const char* type,
+                                                                       
BString* name, const char* parameters);
+       virtual status_t                        CreateChild(off_t offset, off_t 
size,
+                                                                       const 
char* type, const char* name,
+                                                                       const 
char* parameters,
+                                                                       
BMutablePartition** child);
+       virtual status_t                        DeleteChild(BMutablePartition* 
child);
+};
+
+
+#endif // GPT_PARTITION_HANDLE_H
diff --git a/src/add-ons/disk_systems/gpt/Jamfile 
b/src/add-ons/disk_systems/gpt/Jamfile
new file mode 100644
index 0000000..2c26d45
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/Jamfile
@@ -0,0 +1,17 @@
+SubDir HAIKU_TOP src add-ons disk_systems gpt ;
+
+UsePrivateHeaders shared storage ;
+UsePrivateSystemHeaders ;
+
+SEARCH_SOURCE
+       += [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems efi 
] ;
+
+AddResources <disk_system>gpt : GPTDiskAddOn.rdef ;
+
+Addon <disk_system>gpt :
+       GPTDiskSystem.cpp
+       GPTDiskAddOn.cpp
+       GPTPartitionHandle.cpp
+
+       : be $(TARGET_LIBSUPC++)
+;
diff --git a/src/add-ons/disk_systems/gpt/Utility.h 
b/src/add-ons/disk_systems/gpt/Utility.h
new file mode 100644
index 0000000..2c2ad1a
--- /dev/null
+++ b/src/add-ons/disk_systems/gpt/Utility.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef UTILITY_H
+#define UTILITY_H
+
+
+#include <SupportDefs.h>
+
+
+static inline off_t
+round_down(off_t a, uint32 b)
+{
+       return a / b * b;
+}
+
+
+static inline off_t
+round_up(off_t a, uint32 b)
+{
+       return round_down(a + b - 1, b);
+}
+
+
+#endif // UTILITY_H

############################################################################

Revision:    hrev45191
Commit:      61ba12594bf9f447b1384bda0bcd8e4b1e56e315
URL:         http://cgit.haiku-os.org/haiku/commit/?id=61ba125
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 23 22:21:25 2013 UTC

Renamed partitioning system "efi" directory to "gpt".

----------------------------------------------------------------------------

diff --git a/src/add-ons/disk_systems/gpt/Jamfile 
b/src/add-ons/disk_systems/gpt/Jamfile
index 2c26d45..2083ced 100644
--- a/src/add-ons/disk_systems/gpt/Jamfile
+++ b/src/add-ons/disk_systems/gpt/Jamfile
@@ -4,7 +4,7 @@ UsePrivateHeaders shared storage ;
 UsePrivateSystemHeaders ;
 
 SEARCH_SOURCE
-       += [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems efi 
] ;
+       += [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt 
] ;
 
 AddResources <disk_system>gpt : GPTDiskAddOn.rdef ;
 
diff --git a/src/add-ons/kernel/partitioning_systems/Jamfile 
b/src/add-ons/kernel/partitioning_systems/Jamfile
index 353620f..77c050c 100644
--- a/src/add-ons/kernel/partitioning_systems/Jamfile
+++ b/src/add-ons/kernel/partitioning_systems/Jamfile
@@ -3,7 +3,7 @@ SubDir HAIKU_TOP src add-ons kernel partitioning_systems ;
 HaikuSubInclude amiga ;
 HaikuSubInclude apple ;
 HaikuSubInclude atari ;
-HaikuSubInclude efi ;
+HaikuSubInclude gpt ;
 HaikuSubInclude intel ;
 HaikuSubInclude session ;
 HaikuSubInclude vmdk ;
diff --git a/src/add-ons/kernel/partitioning_systems/efi/Jamfile 
b/src/add-ons/kernel/partitioning_systems/gpt/Jamfile
similarity index 67%
rename from src/add-ons/kernel/partitioning_systems/efi/Jamfile
rename to src/add-ons/kernel/partitioning_systems/gpt/Jamfile
index 431a677..11fbc69 100644
--- a/src/add-ons/kernel/partitioning_systems/efi/Jamfile
+++ b/src/add-ons/kernel/partitioning_systems/gpt/Jamfile
@@ -1,4 +1,4 @@
-SubDir HAIKU_TOP src add-ons kernel partitioning_systems efi ;
+SubDir HAIKU_TOP src add-ons kernel partitioning_systems gpt ;
 
 UsePrivateHeaders interface kernel storage ;
 UsePrivateSystemHeaders ;
diff --git a/src/add-ons/kernel/partitioning_systems/efi/PartitionLocker.cpp 
b/src/add-ons/kernel/partitioning_systems/gpt/PartitionLocker.cpp
similarity index 100%
rename from src/add-ons/kernel/partitioning_systems/efi/PartitionLocker.cpp
rename to src/add-ons/kernel/partitioning_systems/gpt/PartitionLocker.cpp
diff --git a/src/add-ons/kernel/partitioning_systems/efi/PartitionLocker.h 
b/src/add-ons/kernel/partitioning_systems/gpt/PartitionLocker.h
similarity index 100%
rename from src/add-ons/kernel/partitioning_systems/efi/PartitionLocker.h
rename to src/add-ons/kernel/partitioning_systems/gpt/PartitionLocker.h
diff --git a/src/add-ons/kernel/partitioning_systems/efi/efi_gpt.cpp 
b/src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.cpp
similarity index 100%
rename from src/add-ons/kernel/partitioning_systems/efi/efi_gpt.cpp
rename to src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.cpp
diff --git a/src/add-ons/kernel/partitioning_systems/efi/efi_gpt.h 
b/src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.h
similarity index 100%
rename from src/add-ons/kernel/partitioning_systems/efi/efi_gpt.h
rename to src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.h
diff --git a/src/add-ons/kernel/partitioning_systems/efi/gpt_known_guids.h 
b/src/add-ons/kernel/partitioning_systems/gpt/gpt_known_guids.h
similarity index 100%
rename from src/add-ons/kernel/partitioning_systems/efi/gpt_known_guids.h
rename to src/add-ons/kernel/partitioning_systems/gpt/gpt_known_guids.h
diff --git a/src/add-ons/kernel/partitioning_systems/efi/guid.h 
b/src/add-ons/kernel/partitioning_systems/gpt/guid.h
similarity index 100%
rename from src/add-ons/kernel/partitioning_systems/efi/guid.h
rename to src/add-ons/kernel/partitioning_systems/gpt/guid.h
diff --git a/src/system/boot/loader/Jamfile b/src/system/boot/loader/Jamfile
index 089f0de..a739155 100644
--- a/src/system/boot/loader/Jamfile
+++ b/src/system/boot/loader/Jamfile
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src system boot loader ;
 
 SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems amiga ;
 SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ;
-SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems efi ;
+SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ;
 SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems intel ;
 UsePrivateKernelHeaders ;
 UsePrivateHeaders [ FDirName kernel disk_device_manager ] ;
@@ -115,7 +115,7 @@ SEARCH on [ FGristFiles apple.cpp ]
     = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ] ;
 
 SEARCH on [ FGristFiles efi_gpt.cpp ]
-    = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems efi ] ;
+    = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ] ;
 
 SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ]
     = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems intel ] ;
diff --git a/src/tests/system/boot/loader/Jamfile 
b/src/tests/system/boot/loader/Jamfile
index aec23cc..5d9c06d 100644
--- a/src/tests/system/boot/loader/Jamfile
+++ b/src/tests/system/boot/loader/Jamfile
@@ -11,7 +11,7 @@ SubDirSysHdrs $(HAIKU_TOP) src tests system boot loader ;
 SubDirHdrs $(HAIKU_TOP) src system boot loader ;
 SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems amiga ;
 SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ;
-SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems efi ;
+SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ;
 SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems intel ;
 
 if $(TARGET_PLATFORM) != haiku {
@@ -150,7 +150,7 @@ SEARCH on [ FGristFiles apple.cpp ]
        = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems apple 
] ;
 
 SEARCH on [ FGristFiles efi_gpt.cpp ]
-       = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems efi ] 
;
+       = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ] 
;
 
 SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ]
        = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems intel 
] ;


Other related posts:

  • » [haiku-commits] haiku: hrev45191 - in src: add-ons/kernel/partitioning_systems/gpt add-ons/kernel/partitioning_systems/efi add-ons/disk_systems/gpt apps/drivesetup - axeld