[haiku-commits] haiku: hrev45218 - in src: kits/storage/disk_device apps/drivesetup add-ons/kernel/partitioning_systems/gpt

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 29 Jan 2013 01:16:25 +0100 (CET)

hrev45218 adds 5 changesets to branch 'master'
old head: 7775bfeb6bb0d4b71d9436a6e33e112d53878ee4
new head: 8317edb3504120db3ddff0c3270a7ae9a55719f6
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=8317edb+%5E7775bfe

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

2dd0a26: gpt: Fixed off by one error.
  
  * The backup header would have been written one block behind the actual
    last block. Well, at least it would have tried to do so :-)

5a81662: DriveSetup: Added column for the partition type.
  
  * This implements ticket #4235.

d0ecb6d: BPartition::CanInitialize() now returns false if the size is 0.
  
  * This should fix #9405; I cannot test it right now due to a missing
    CD-ROM.

856f538: Minor cleanup.

8317edb: DriveSetup: Removed (some) knowledge about initialization.
  
  * Instead of guessing whether or not to show the InitParamsPanel, the panel
    will now no longer show itself if the disk system does not have an editor,
    and silently succeed.
  * This also fixed a potential crash if the editor could not be created for
    some reason.
  * Minor cleanup.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

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

5 files changed, 152 insertions(+), 229 deletions(-)
.../kernel/partitioning_systems/gpt/efi_gpt.cpp  |   9 +-
src/apps/drivesetup/InitParamsPanel.cpp          |  15 +-
src/apps/drivesetup/MainWindow.cpp               |  85 ++++---
src/apps/drivesetup/PartitionList.cpp            |  42 ++--
src/kits/storage/disk_device/Partition.cpp       | 230 ++++++-------------

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

Commit:      2dd0a26ac04939442c9db2dfb76c28b6d3c78aaf
URL:         http://cgit.haiku-os.org/haiku/commit/?id=2dd0a26
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Jan 28 23:02:31 2013 UTC

gpt: Fixed off by one error.

* The backup header would have been written one block behind the actual
  last block. Well, at least it would have tried to do so :-)

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

diff --git a/src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.cpp 
b/src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.cpp
index 7b87a29..8dbf7ad 100644
--- a/src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.cpp
+++ b/src/add-ons/kernel/partitioning_systems/gpt/efi_gpt.cpp
@@ -73,7 +73,7 @@ static float
 efi_gpt_identify_partition(int fd, partition_data* partition, void** _cookie)
 {
        EFI::Header* header = new (std::nothrow) EFI::Header(fd,
-               partition->size / partition->block_size, partition->block_size);
+               (partition->size - 1) / partition->block_size, 
partition->block_size);
        status_t status = header->InitCheck();
        if (status != B_OK) {
                delete header;
@@ -110,9 +110,8 @@ efi_gpt_scan_partition(int fd, partition_data* partition, 
void* _cookie)
 
                if (entry.EndBlock() * partition->block_size
                                > (uint64)partition->size) {
-                       TRACE(("efi_gpt: child partition exceeds existing space 
(%Ld MB)\n",
-                               (entry.EndBlock() - entry.StartBlock()) * 
partition->block_size
-                               / 1024 / 1024));
+                       TRACE(("efi_gpt: child partition exceeds existing space 
(ends at "
+                               "block %" B_PRIu64 ")\n", entry.EndBlock()));
                        continue;
                }
 
@@ -699,7 +698,7 @@ efi_gpt_initialize(int fd, partition_id partitionID, const 
char* name,
 
        update_disk_device_job_progress(job, 0.0);
 
-       EFI::Header header(partitionSize / partition->block_size,
+       EFI::Header header((partitionSize - 1) / partition->block_size,
                partition->block_size);
        status_t result = header.InitCheck();
        if (result != B_OK)

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

Commit:      5a816626427fe3f2680f6b80432e881bb00ff587
URL:         http://cgit.haiku-os.org/haiku/commit/?id=5a81662
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Jan 28 23:12:31 2013 UTC

Ticket:      https://dev.haiku-os.org/ticket/4235

DriveSetup: Added column for the partition type.

* This implements ticket #4235.

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

diff --git a/src/apps/drivesetup/PartitionList.cpp 
b/src/apps/drivesetup/PartitionList.cpp
index f2cc4fe..378e289 100644
--- a/src/apps/drivesetup/PartitionList.cpp
+++ b/src/apps/drivesetup/PartitionList.cpp
@@ -1,13 +1,15 @@
 /*
- * Copyright 2006-2013 Haiku Inc. All rights reserved.
+ * Copyright 2006-2013, Haiku Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
  *             Ithamar R. Adema <ithamar@xxxxxxx>
  *             James Urquhart
  *             Stephan Aßmus <superstippi@xxxxxx>
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
  */
 
+
 #include "PartitionList.h"
 
 #include <Catalog.h>
@@ -24,6 +26,19 @@
 #define B_TRANSLATION_CONTEXT "PartitionList"
 
 
+static const char* kUnavailableString = "";
+
+enum {
+       kDeviceColumn,
+       kFilesystemColumn,
+       kVolumeNameColumn,
+       kMountedAtColumn,
+       kSizeColumn,
+       kParametersColumn,
+       kPartitionTypeColumn,
+};
+
+
 // #pragma mark - BBitmapStringField
 
 
@@ -179,18 +194,6 @@ PartitionColumn::InitTextMargin(BView* parent)
 // #pragma mark - PartitionListRow
 
 
-static const char* kUnavailableString = "";
-
-enum {
-       kDeviceColumn,
-       kFilesystemColumn,
-       kVolumeNameColumn,
-       kMountedAtColumn,
-       kSizeColumn,
-       kParametersColumn
-};
-
-
 PartitionListRow::PartitionListRow(BPartition* partition)
        :
        Inherited(),
@@ -218,6 +221,8 @@ PartitionListRow::PartitionListRow(BPartition* partition)
 
        // File system & volume name
 
+       BString partitionType(partition->Type());
+
        if (partition->ContainsFileSystem()) {
                SetField(new BStringField(partition->ContentType()), 
kFilesystemColumn);
                SetField(new BStringField(partition->ContentName()), 
kVolumeNameColumn);
@@ -231,7 +236,6 @@ PartitionListRow::PartitionListRow(BPartition* partition)
                SetField(new BStringField(kUnavailableString), 
kFilesystemColumn);
                SetField(new BStringField(kUnavailableString), 
kVolumeNameColumn);
        } else {
-               BString partitionType(partition->Type());
                if (!partitionType.IsEmpty()) {
                        partitionType.Prepend("(");
                        partitionType.Append(")");
@@ -278,6 +282,10 @@ PartitionListRow::PartitionListRow(BPartition* partition)
        } else {
                SetField(new BStringField(kUnavailableString), 
kParametersColumn);
        }
+
+       // Partition type
+
+       SetField(new BStringField(partitionType), kPartitionTypeColumn);
 }
 
 
@@ -333,8 +341,10 @@ PartitionListView::PartitionListView(const BRect& frame, 
uint32 resizeMode)
                B_TRUNCATE_MIDDLE), kMountedAtColumn);
        AddColumn(new PartitionColumn(B_TRANSLATE("Size"), 100, 50, 500,
                B_TRUNCATE_END, B_ALIGN_RIGHT), kSizeColumn);
-       AddColumn(new PartitionColumn(B_TRANSLATE("Parameters"), 150, 50, 500,
-               B_TRUNCATE_MIDDLE), kParametersColumn);
+       AddColumn(new PartitionColumn(B_TRANSLATE("Parameters"), 200, 50, 500,
+               B_TRUNCATE_END), kParametersColumn);
+       AddColumn(new PartitionColumn(B_TRANSLATE("Partition type"), 100, 50, 
500,
+               B_TRUNCATE_END), kPartitionTypeColumn);
 
        SetSortingEnabled(false);
 }

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

Commit:      d0ecb6dafc8f108f62bd63655c27ff970ff24d32
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d0ecb6d
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Jan 28 23:20:01 2013 UTC

Ticket:      https://dev.haiku-os.org/ticket/9405

BPartition::CanInitialize() now returns false if the size is 0.

* This should fix #9405; I cannot test it right now due to a missing
  CD-ROM.

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

diff --git a/src/kits/storage/disk_device/Partition.cpp 
b/src/kits/storage/disk_device/Partition.cpp
index 3dbcadd..8633d9e 100644
--- a/src/kits/storage/disk_device/Partition.cpp
+++ b/src/kits/storage/disk_device/Partition.cpp
@@ -1177,6 +1177,8 @@ BPartition::BPartition::IsSubSystem(const char* 
diskSystem) const
 bool
 BPartition::CanInitialize(const char* diskSystem) const
 {
+       if (Size() == 0 || BlockSize() == 0)
+               return false;
        return fDelegate && fDelegate->CanInitialize(diskSystem);
 }
 

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

Commit:      856f538b793ffb866576bdc3469aa813669d4268
URL:         http://cgit.haiku-os.org/haiku/commit/?id=856f538
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Tue Jan 29 00:12:06 2013 UTC

Minor cleanup.

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

diff --git a/src/kits/storage/disk_device/Partition.cpp 
b/src/kits/storage/disk_device/Partition.cpp
index 8633d9e..c1bb3d6 100644
--- a/src/kits/storage/disk_device/Partition.cpp
+++ b/src/kits/storage/disk_device/Partition.cpp
@@ -3,6 +3,7 @@
  * Distributed under the terms of the MIT License.
  */
 
+
 #include <errno.h>
 #include <new>
 #include <unistd.h>
@@ -44,6 +45,7 @@ using std::nothrow;
 
 static const char *skAutoCreatePrefix = "_HaikuAutoCreated";
 
+
 /*!    \class BPartition
        \brief A BPartition object represent a partition and provides a lot of
                   methods to retrieve information about it and some to 
manipulate it.
@@ -55,7 +57,6 @@ static const char *skAutoCreatePrefix = "_HaikuAutoCreated";
 */
 
 
-// compare_string
 /*!    \brief \c NULL aware strcmp().
 
        \c NULL is considered the least of all strings. \c NULL equals \c NULL.
@@ -73,23 +74,26 @@ compare_string(const char* str1, const char* str2)
                if (str2 == NULL)
                        return 0;
                return 1;
-       } else if (str2 == NULL)
+       }
+       if (str2 == NULL)
                return -1;
        return strcmp(str1, str2);
 }
 
 
-// constructor
+// #pragma mark -
+
+
 BPartition::BPartition()
-       : fDevice(NULL),
-         fParent(NULL),
-         fPartitionData(NULL),
-         fDelegate(NULL)
+       :
+       fDevice(NULL),
+       fParent(NULL),
+       fPartitionData(NULL),
+       fDelegate(NULL)
 {
 }
 
 
-// destructor
 /*!    \brief Frees all resources associated with this object.
 */
 BPartition::~BPartition()
@@ -98,7 +102,6 @@ BPartition::~BPartition()
 }
 
 
-// Offset
 /*!    \brief Returns the partition's offset relative to the beginning of the
                   device it resides on.
        \return The partition's offset in bytes relative to the beginning of the
@@ -111,7 +114,6 @@ BPartition::Offset() const
 }
 
 
-// Size
 /*!    \brief Returns the size of the partition.
        \return The size of the partition in bytes.
 */
@@ -122,14 +124,13 @@ BPartition::Size() const
 }
 
 
-// ContentSize
 off_t
 BPartition::ContentSize() const
 {
        return _PartitionData()->content_size;
 }
 
-// BlockSize
+
 /*!    \brief Returns the block size of the device.
        \return The block size of the device in bytes.
 */
@@ -140,7 +141,6 @@ BPartition::BlockSize() const
 }
 
 
-// Index
 /*!    \brief Returns the index of the partition in its session's list of
                   partitions.
        \return The index of the partition in its session's list of partitions.
@@ -152,7 +152,6 @@ BPartition::Index() const
 }
 
 
-// Status
 uint32
 BPartition::Status() const
 {
@@ -160,7 +159,6 @@ BPartition::Status() const
 }
 
 
-// ContainsFileSystem
 bool
 BPartition::ContainsFileSystem() const
 {
@@ -168,7 +166,6 @@ BPartition::ContainsFileSystem() const
 }
 
 
-// ContainsPartitioningSystem
 bool
 BPartition::ContainsPartitioningSystem() const
 {
@@ -176,7 +173,6 @@ BPartition::ContainsPartitioningSystem() const
 }
 
 
-// IsDevice
 bool
 BPartition::IsDevice() const
 {
@@ -184,7 +180,6 @@ BPartition::IsDevice() const
 }
 
 
-// IsReadOnly
 bool
 BPartition::IsReadOnly() const
 {
@@ -192,7 +187,6 @@ BPartition::IsReadOnly() const
 }
 
 
-// IsMounted
 /*!    \brief Returns whether the volume is mounted.
        \return \c true, if the volume is mounted, \c false otherwise.
 */
@@ -205,7 +199,6 @@ BPartition::IsMounted() const
 }
 
 
-// IsBusy
 bool
 BPartition::IsBusy() const
 {
@@ -213,7 +206,6 @@ BPartition::IsBusy() const
 }
 
 
-// SupportsChildName
 bool
 BPartition::SupportsChildName() const
 {
@@ -221,7 +213,6 @@ BPartition::SupportsChildName() const
 }
 
 
-// Flags
 /*!    \brief Returns the flags for this partitions.
 
        The partition flags are a bitwise combination of:
@@ -242,7 +233,6 @@ BPartition::Flags() const
 }
 
 
-// Name
 /*!    \brief Returns the name of the partition.
 
        Note, that not all partitioning system support names. The method returns
@@ -258,7 +248,6 @@ BPartition::Name() const
 }
 
 
-// ContentName
 const char*
 BPartition::ContentName() const
 {
@@ -266,7 +255,6 @@ BPartition::ContentName() const
 }
 
 
-// Type
 /*!    \brief Returns a human readable string for the type of the partition.
        \return A human readable string for the type of the partition.
 */
@@ -277,7 +265,6 @@ BPartition::Type() const
 }
 
 
-// ContentType
 const char*
 BPartition::ContentType() const
 {
@@ -285,7 +272,6 @@ BPartition::ContentType() const
 }
 
 
-// ID
 /*!    \brief Returns a unique identifier for this partition.
 
        The ID is not persistent, i.e. in general won't be the same after
@@ -302,7 +288,6 @@ BPartition::ID() const
 }
 
 
-// Parameters
 const char*
 BPartition::Parameters() const
 {
@@ -310,7 +295,6 @@ BPartition::Parameters() const
 }
 
 
-// ContentParameters
 const char*
 BPartition::ContentParameters() const
 {
@@ -318,12 +302,11 @@ BPartition::ContentParameters() const
 }
 
 
-// GetDiskSystem
 status_t
 BPartition::GetDiskSystem(BDiskSystem* diskSystem) const
 {
        const user_partition_data* data = _PartitionData();
-       if (!data || !diskSystem)
+       if (data == NULL || diskSystem == NULL)
                return B_BAD_VALUE;
 
        if (data->disk_system < 0)
@@ -333,7 +316,6 @@ BPartition::GetDiskSystem(BDiskSystem* diskSystem) const
 }
 
 
-// GetPath
 status_t
 BPartition::GetPath(BPath* path) const
 {
@@ -369,7 +351,6 @@ BPartition::GetPath(BPath* path) const
 }
 
 
-// GetVolume
 /*!    \brief Returns a BVolume for the partition.
 
        This can only succeed, if the partition is mounted.
@@ -382,14 +363,13 @@ BPartition::GetPath(BPath* path) const
 status_t
 BPartition::GetVolume(BVolume* volume) const
 {
-       if (!volume)
+       if (volume == NULL)
                return B_BAD_VALUE;
 
        return volume->SetTo(_PartitionData()->volume);
 }
 
 
-// GetIcon
 /*!    \brief Returns an icon for this partition.
 
        Note, that currently there are only per-device icons, i.e. the method
@@ -460,7 +440,6 @@ BPartition::GetIcon(uint8** _data, size_t* _size, 
type_code* _type) const
 }
 
 
-// GetMountPoint
 /*!    \brief Returns the mount point for the partition.
 
        If the partition is mounted this is the actual mount point. If it is not
@@ -477,7 +456,7 @@ BPartition::GetIcon(uint8** _data, size_t* _size, 
type_code* _type) const
 status_t
 BPartition::GetMountPoint(BPath* mountPoint) const
 {
-       if (!mountPoint || !ContainsFileSystem())
+       if (mountPoint == NULL || !ContainsFileSystem())
                return B_BAD_VALUE;
 
        // if the partition is mounted, return the actual mount point
@@ -493,9 +472,9 @@ BPartition::GetMountPoint(BPath* mountPoint) const
        // partition not mounted
        // get the volume name
        const char* volumeName = ContentName();
-       if (!volumeName || strlen(volumeName) == 0)
+       if (volumeName == NULL || strlen(volumeName) == 0)
                volumeName = Name();
-       if (!volumeName || strlen(volumeName) == 0)
+       if (volumeName == NULL || strlen(volumeName) == 0)
                volumeName = "unnamed volume";
 
        // construct a path name from the volume name
@@ -524,7 +503,6 @@ BPartition::GetMountPoint(BPath* mountPoint) const
 }
 
 
-// Mount
 /*!    \brief Mounts the volume.
 
        The volume can only be mounted, if the partition contains a recognized
@@ -598,7 +576,6 @@ BPartition::Mount(const char* mountPoint, uint32 mountFlags,
 }
 
 
-// Unmount
 /*!    \brief Unmounts the volume.
 
        The volume can of course only be unmounted, if it currently is mounted.
@@ -643,7 +620,6 @@ BPartition::Unmount(uint32 unmountFlags)
 }
 
 
-// Device
 /*!    \brief Returns the device this partition resides on.
        \return The device this partition resides on.
 */
@@ -654,7 +630,6 @@ BPartition::Device() const
 }
 
 
-// Parent
 BPartition*
 BPartition::Parent() const
 {
@@ -662,11 +637,10 @@ BPartition::Parent() const
 }
 
 
-// ChildAt
 BPartition*
 BPartition::ChildAt(int32 index) const
 {
-       if (fDelegate) {
+       if (fDelegate != NULL) {
                Delegate* child = fDelegate->ChildAt(index);
                return child ? child->Partition() : NULL;
        }
@@ -675,18 +649,16 @@ BPartition::ChildAt(int32 index) const
 }
 
 
-// CountChildren
 int32
 BPartition::CountChildren() const
 {
-       if (fDelegate)
+       if (fDelegate != NULL)
                return fDelegate->CountChildren();
 
        return _CountChildren();
 }
 
 
-// CountDescendants
 int32
 BPartition::CountDescendants() const
 {
@@ -697,7 +669,6 @@ BPartition::CountDescendants() const
 }
 
 
-// FindDescendant
 BPartition*
 BPartition::FindDescendant(partition_id id) const
 {
@@ -706,24 +677,22 @@ BPartition::FindDescendant(partition_id id) const
 }
 
 
-// GetPartitioningInfo
 status_t
 BPartition::GetPartitioningInfo(BPartitioningInfo* info) const
 {
        if (!info)
                return B_BAD_VALUE;
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->GetPartitioningInfo(info);
 }
 
 
-// VisitEachChild
 BPartition*
 BPartition::VisitEachChild(BDiskDeviceVisitor* visitor) const
 {
-       if (visitor) {
+       if (visitor != NULL) {
                int32 level = _Level();
                for (int32 i = 0; BPartition* child = ChildAt(i); i++) {
                        if (child->_AcceptVisitor(visitor, level))
@@ -734,17 +703,15 @@ BPartition::VisitEachChild(BDiskDeviceVisitor* visitor) 
const
 }
 
 
-// VisitEachDescendant
 BPartition*
 BPartition::VisitEachDescendant(BDiskDeviceVisitor* visitor) const
 {
-       if (visitor)
+       if (visitor != NULL)
                return 
const_cast<BPartition*>(this)->_VisitEachDescendant(visitor);
        return NULL;
 }
 
 
-// CanDefragment
 bool
 BPartition::CanDefragment(bool* whileMounted) const
 {
@@ -753,18 +720,16 @@ BPartition::CanDefragment(bool* whileMounted) const
 }
 
 
-// Defragment
 status_t
 BPartition::Defragment() const
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->Defragment();
 }
 
 
-// CanRepair
 bool
 BPartition::CanRepair(bool checkOnly, bool* whileMounted) const
 {
@@ -782,23 +747,21 @@ BPartition::CanRepair(bool checkOnly, bool* whileMounted) 
const
 }
 
 
-// Repair
 status_t
 BPartition::Repair(bool checkOnly) const
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->Repair(checkOnly);
 }
 
 
-// CanResize
 bool
 BPartition::CanResize(bool* canResizeContents, bool* whileMounted) const
 {
        BPartition* parent = Parent();
-       if (!parent)
+       if (parent == NULL)
                return false;
 
        if (!parent->_SupportsChildOperation(this,
@@ -814,12 +777,11 @@ BPartition::CanResize(bool* canResizeContents, bool* 
whileMounted) const
 }
 
 
-// ValidateResize
 status_t
 BPartition::ValidateResize(off_t* size) const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        status_t error = parent->fDelegate->ValidateResizeChild(fDelegate, 
size);
@@ -827,7 +789,7 @@ BPartition::ValidateResize(off_t* size) const
                return error;
 
        if (_HasContent()) {
-// TODO: We would actually need the parameter for the content size.
+               // TODO: We would actually need the parameter for the content 
size.
                off_t contentSize = *size;
                error = fDelegate->ValidateResize(&contentSize);
                if (error != B_OK)
@@ -841,7 +803,6 @@ BPartition::ValidateResize(off_t* size) const
 }
 
 
-// Resize
 status_t
 BPartition::Resize(off_t size)
 {
@@ -861,7 +822,7 @@ BPartition::Resize(off_t size)
        }
 
        // If shrinking the partition, resize content first, otherwise last.
-       bool shrink = (Size() > size);
+       bool shrink = Size() > size;
 
        if (shrink && ContentType() != NULL) {
                error = fDelegate->Resize(contentSize);
@@ -883,13 +844,12 @@ BPartition::Resize(off_t size)
 }
 
 
-// CanMove
 bool
 BPartition::CanMove(BObjectList<BPartition>* unmovableDescendants,
        BObjectList<BPartition>* movableOnlyIfUnmounted) const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return false;
 
        if (!parent->_SupportsChildOperation(this,
@@ -916,12 +876,11 @@ BPartition::CanMove(BObjectList<BPartition>* 
unmovableDescendants,
 }
 
 
-// ValidateMove
 status_t
 BPartition::ValidateMove(off_t* offset) const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        status_t error = parent->fDelegate->ValidateMoveChild(fDelegate, 
offset);
@@ -942,12 +901,11 @@ BPartition::ValidateMove(off_t* offset) const
 }
 
 
-// Move
 status_t
 BPartition::Move(off_t offset)
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        status_t error = parent->fDelegate->MoveChild(fDelegate, offset);
@@ -964,12 +922,11 @@ BPartition::Move(off_t offset)
 }
 
 
-// CanSetName
 bool
 BPartition::CanSetName() const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return false;
 
        return parent->_SupportsChildOperation(this,
@@ -977,31 +934,28 @@ BPartition::CanSetName() const
 }
 
 
-// ValidateSetName
 status_t
 BPartition::ValidateSetName(BString* name) const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        return parent->fDelegate->ValidateSetName(fDelegate, name);
 }
 
 
-// SetName
 status_t
 BPartition::SetName(const char* name)
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        return parent->fDelegate->SetName(fDelegate, name);
 }
 
 
-// CanSetContentName
 bool
 BPartition::CanSetContentName(bool* whileMounted) const
 {
@@ -1011,34 +965,31 @@ BPartition::CanSetContentName(bool* whileMounted) const
 }
 
 
-// ValidateSetContentName
 status_t
 BPartition::ValidateSetContentName(BString* name) const
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->ValidateSetContentName(name);
 }
 
 
-// SetContentName
 status_t
 BPartition::SetContentName(const char* name)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->SetContentName(name);
 }
 
 
-// CanSetType
 bool
 BPartition::CanSetType() const
 {
        BPartition* parent = Parent();
-       if (!parent)
+       if (parent == NULL)
                return false;
 
        return parent->_SupportsChildOperation(this,
@@ -1046,36 +997,33 @@ BPartition::CanSetType() const
 }
 
 
-// ValidateSetType
 status_t
 BPartition::ValidateSetType(const char* type) const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        return parent->fDelegate->ValidateSetType(fDelegate, type);
 }
 
 
-// SetType
 status_t
 BPartition::SetType(const char* type)
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        return parent->fDelegate->SetType(fDelegate, type);
 }
 
 
-// CanEditParameters
 bool
 BPartition::CanEditParameters() const
 {
        BPartition* parent = Parent();
-       if (!parent)
+       if (parent == NULL)
                return false;
 
        return parent->_SupportsChildOperation(this,
@@ -1083,31 +1031,28 @@ BPartition::CanEditParameters() const
 }
 
 
-// GetParameterEditor
 status_t
 BPartition::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
        BPartitionParameterEditor** editor)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->GetParameterEditor(type, editor);
 }
 
 
-// SetParameters
 status_t
 BPartition::SetParameters(const char* parameters)
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return B_NO_INIT;
 
        return parent->fDelegate->SetParameters(fDelegate, parameters);
 }
 
 
-// CanEditContentParameters
 bool
 BPartition::CanEditContentParameters(bool* whileMounted) const
 {
@@ -1117,25 +1062,23 @@ BPartition::CanEditContentParameters(bool* 
whileMounted) const
 }
 
 
-// SetContentParameters
 status_t
 BPartition::SetContentParameters(const char* parameters)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->SetContentParameters(parameters);
 }
 
 
-// GetNextSupportedType
 status_t
 BPartition::GetNextSupportedType(int32* cookie, BString* type) const
 {
        TRACE("%p->BPartition::GetNextSupportedType(%ld)\n", this, *cookie);
 
        BPartition* parent = Parent();
-       if (!parent || !fDelegate) {
+       if (parent == NULL || fDelegate == NULL) {
                TRACE("  not prepared (parent: %p, fDelegate: %p)!\n", parent,
                        fDelegate);
                return B_NO_INIT;
@@ -1146,13 +1089,12 @@ BPartition::GetNextSupportedType(int32* cookie, 
BString* type) const
 }
 
 
-// GetNextSupportedChildType
 status_t
 BPartition::GetNextSupportedChildType(int32* cookie, BString* type) const
 {
        TRACE("%p->BPartition::GetNextSupportedChildType(%ld)\n", this, 
*cookie);
 
-       if (!fDelegate) {
+       if (fDelegate == NULL) {
                TRACE("  not prepared!\n");
                return B_NO_INIT;
        }
@@ -1161,53 +1103,49 @@ BPartition::GetNextSupportedChildType(int32* cookie, 
BString* type) const
 }
 
 
-// IsSubSystem
 bool
 BPartition::BPartition::IsSubSystem(const char* diskSystem) const
 {
        BPartition* parent = Parent();
-       if (!parent || !fDelegate)
+       if (parent == NULL || fDelegate == NULL)
                return false;
 
        return parent->fDelegate->IsSubSystem(fDelegate, diskSystem);
 }
 
 
-// CanInitialize
 bool
 BPartition::CanInitialize(const char* diskSystem) const
 {
-       if (Size() == 0 || BlockSize() == 0)
+       if (Size() == 0 || BlockSize() == 0 || fDelegate == NULL)
                return false;
-       return fDelegate && fDelegate->CanInitialize(diskSystem);
+
+       return fDelegate->CanInitialize(diskSystem);
 }
 
 
-// ValidateInitialize
 status_t
 BPartition::ValidateInitialize(const char* diskSystem, BString* name,
        const char* parameters)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->ValidateInitialize(diskSystem, name, parameters);
 }
 
 
-// Initialize
 status_t
 BPartition::Initialize(const char* diskSystem, const char* name,
        const char* parameters)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->Initialize(diskSystem, name, parameters);
 }
 
 
-// Uninitialize
 status_t
 BPartition::Uninitialize()
 {
@@ -1216,7 +1154,6 @@ BPartition::Uninitialize()
 }
 
 
-// CanCreateChild
 bool
 BPartition::CanCreateChild() const
 {
@@ -1224,36 +1161,33 @@ BPartition::CanCreateChild() const
 }
 
 
-// ValidateCreateChild
 status_t
 BPartition::ValidateCreateChild(off_t* offset, off_t* size, const char* type,
        BString* name, const char* parameters) const
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->ValidateCreateChild(offset, size, type, name, 
parameters);
 }
 
 
-// CreateChild
 status_t
 BPartition::CreateChild(off_t offset, off_t size, const char* type,
        const char* name, const char* parameters, BPartition** child)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
 
        return fDelegate->CreateChild(offset, size, type, name, parameters, 
child);
 }
 
 
-// CanDeleteChild
 bool
 BPartition::CanDeleteChild(int32 index) const
 {
        BPartition* child = ChildAt(index);
-       if (!fDelegate || !child)
+       if (fDelegate == NULL || child == NULL)
                return false;
 
        return _SupportsChildOperation(child,
@@ -1261,21 +1195,20 @@ BPartition::CanDeleteChild(int32 index) const
 }
 
 
-// DeleteChild
 status_t
 BPartition::DeleteChild(int32 index)
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_INIT;
+
        BPartition* child = ChildAt(index);
-       if (!child || child->Parent() != this)
+       if (child == NULL || child->Parent() != this)
                return B_BAD_VALUE;
 
        return fDelegate->DeleteChild(child->fDelegate);
 }
 
 
-// constructor
 /*!    \brief Privatized copy constructor to avoid usage.
 */
 BPartition::BPartition(const BPartition &)
@@ -1283,7 +1216,6 @@ BPartition::BPartition(const BPartition &)
 }
 
 
-// =
 /*!    \brief Privatized assignment operator to avoid usage.
 */
 BPartition &
@@ -1293,14 +1225,14 @@ BPartition::operator=(const BPartition &)
 }
 
 
-// _SetTo
 status_t
 BPartition::_SetTo(BDiskDevice* device, BPartition* parent,
        user_partition_data* data)
 {
        _Unset();
-       if (!device || !data)
+       if (device == NULL || data == NULL)
                return B_BAD_VALUE;
+
        fPartitionData = data;
        fDevice = device;
        fParent = parent;
@@ -1325,12 +1257,11 @@ BPartition::_SetTo(BDiskDevice* device, BPartition* 
parent,
 }
 
 
-// _Unset
 void
 BPartition::_Unset()
 {
        // delete children
-       if (fPartitionData) {
+       if (fPartitionData != NULL) {
                for (int32 i = 0; i < fPartitionData->child_count; i++) {
                        if (BPartition* child = ChildAt(i))
                                delete child;
@@ -1345,7 +1276,6 @@ BPartition::_Unset()
 }
 
 
-// _RemoveObsoleteDescendants
 status_t
 BPartition::_RemoveObsoleteDescendants(user_partition_data* data, bool* 
updated)
 {
@@ -1384,7 +1314,6 @@ 
BPartition::_RemoveObsoleteDescendants(user_partition_data* data, bool* updated)
 }
 
 
-// _Update
 status_t
 BPartition::_Update(user_partition_data* data, bool* updated)
 {
@@ -1404,7 +1333,7 @@ BPartition::_Update(user_partition_data* data, bool* 
updated)
                || compare_string(data->content_type, oldData->content_type)
                || compare_string(data->parameters, oldData->parameters)
                || compare_string(data->content_parameters,
-                                                 oldData->content_parameters)) 
{
+                               oldData->content_parameters)) {
                *updated = true;
        }
 
@@ -1438,7 +1367,6 @@ BPartition::_Update(user_partition_data* data, bool* 
updated)
 }
 
 
-// _RemoveChild
 void
 BPartition::_RemoveChild(int32 index)
 {
@@ -1456,7 +1384,6 @@ BPartition::_RemoveChild(int32 index)
 }
 
 
-// _ChildAt
 BPartition*
 BPartition::_ChildAt(int32 index) const
 {
@@ -1466,7 +1393,6 @@ BPartition::_ChildAt(int32 index) const
 }
 
 
-// _CountChildren
 int32
 BPartition::_CountChildren() const
 {
@@ -1474,7 +1400,6 @@ BPartition::_CountChildren() const
 }
 
 
-// _CountDescendants
 int32
 BPartition::_CountDescendants() const
 {
@@ -1485,7 +1410,6 @@ BPartition::_CountDescendants() const
 }
 
 
-// _Level
 int32
 BPartition::_Level() const
 {
@@ -1497,7 +1421,6 @@ BPartition::_Level() const
 }
 
 
-// _AcceptVisitor
 bool
 BPartition::_AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level)
 {
@@ -1505,7 +1428,6 @@ BPartition::_AcceptVisitor(BDiskDeviceVisitor* visitor, 
int32 level)
 }
 
 
-// _VisitEachDescendant
 BPartition*
 BPartition::_VisitEachDescendant(BDiskDeviceVisitor* visitor, int32 level)
 {
@@ -1523,7 +1445,6 @@ BPartition::_VisitEachDescendant(BDiskDeviceVisitor* 
visitor, int32 level)
 }
 
 
-// _PartitionData
 const user_partition_data*
 BPartition::_PartitionData() const
 {
@@ -1531,20 +1452,18 @@ BPartition::_PartitionData() const
 }
 
 
-// _HasContent
 bool
 BPartition::_HasContent() const
 {
-       return (ContentType() != NULL);
+       return ContentType() != NULL;
 }
 
 
-// _SupportsOperation
 bool
 BPartition::_SupportsOperation(uint32 flag, uint32 whileMountedFlag,
        bool* whileMounted) const
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return false;
 
        uint32 supported = fDelegate->SupportedOperations(flag | 
whileMountedFlag);
@@ -1552,38 +1471,36 @@ BPartition::_SupportsOperation(uint32 flag, uint32 
whileMountedFlag,
        if (whileMounted)
                *whileMounted = supported & whileMountedFlag;
 
-       return supported & flag;
+       return (supported & flag) != 0;
 }
 
 
-// _SupportsChildOperation
 bool
 BPartition::_SupportsChildOperation(const BPartition* child, uint32 flag) const
 {
-       if (!fDelegate || (child && !child->fDelegate))
+       if (fDelegate == NULL || (child != NULL && child->fDelegate == NULL))
                return false;
 
        uint32 supported = fDelegate->SupportedChildOperations(
-               child ? child->fDelegate : NULL, flag);
+               child != NULL ? child->fDelegate : NULL, flag);
 
-       return supported & flag;
+       return (supported & flag) != 0;
 }
 
 
-// _CreateDelegates
 status_t
 BPartition::_CreateDelegates()
 {
-       if (fDelegate || !fPartitionData)
+       if (fDelegate != NULL || fPartitionData == NULL)
                return B_NO_INIT;
 
        // create and init delegate
        fDelegate = new(nothrow) Delegate(this);
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return B_NO_MEMORY;
 
        status_t error = fDelegate->InitHierarchy(fPartitionData,
-               fParent ? fParent->fDelegate : NULL);
+               fParent != NULL ? fParent->fDelegate : NULL);
        if (error != B_OK)
                return error;
 
@@ -1600,7 +1517,6 @@ BPartition::_CreateDelegates()
 }
 
 
-// _InitDelegates
 status_t
 BPartition::_InitDelegates()
 {
@@ -1621,7 +1537,6 @@ BPartition::_InitDelegates()
 }
 
 
-// _DeleteDelegates
 void
 BPartition::_DeleteDelegates()
 {
@@ -1641,11 +1556,10 @@ BPartition::_DeleteDelegates()
 }
 
 
-// _IsModified
 bool
 BPartition::_IsModified() const
 {
-       if (!fDelegate)
+       if (fDelegate == NULL)
                return false;
 
        return fDelegate->IsModified();

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

Revision:    hrev45218
Commit:      8317edb3504120db3ddff0c3270a7ae9a55719f6
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8317edb
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Tue Jan 29 00:13:42 2013 UTC

DriveSetup: Removed (some) knowledge about initialization.

* Instead of guessing whether or not to show the InitParamsPanel, the panel
  will now no longer show itself if the disk system does not have an editor,
  and silently succeed.
* This also fixed a potential crash if the editor could not be created for
  some reason.
* Minor cleanup.

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

diff --git a/src/apps/drivesetup/InitParamsPanel.cpp 
b/src/apps/drivesetup/InitParamsPanel.cpp
index 6c2f9de..6d03f83 100644
--- a/src/apps/drivesetup/InitParamsPanel.cpp
+++ b/src/apps/drivesetup/InitParamsPanel.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008-2010 Haiku Inc. All rights reserved.
+ * Copyright 2008-2013 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
@@ -104,15 +104,16 @@ InitParamsPanel::InitParamsPanel(BWindow* window, const 
BString& diskSystem,
                // put the add-on
                manager->PutAddOn(addOn);
 
-               status_t err = 
addOn->GetParameterEditor(B_INITIALIZE_PARAMETER_EDITOR, &fEditor);
-               if (err != B_OK) {
+               status_t err = 
addOn->GetParameterEditor(B_INITIALIZE_PARAMETER_EDITOR,
+                       &fEditor);
+               if (err != B_OK)
                        fEditor = NULL;
-               }
        } else {
                fEditor = NULL;
        }
+       if (fEditor == NULL)
+               return;
 
-       // TODO: fEditor should be checked for NULL before adding.
        SetLayout(new BGroupLayout(B_HORIZONTAL));
        const float spacing = be_control_look->DefaultItemSpacing();
        AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing)
@@ -188,6 +189,10 @@ InitParamsPanel::MessageReceived(BMessage* message)
 int32
 InitParamsPanel::Go(BString& name, BString& parameters)
 {
+       // Without an editor, we cannot change anything, anyway
+       if (fEditor == NULL)
+               return GO_SUCCESS;
+
        // run the window thread, to get an initial layout of the controls
        Hide();
        Show();
diff --git a/src/apps/drivesetup/MainWindow.cpp 
b/src/apps/drivesetup/MainWindow.cpp
index e6ebcc0..2cd67d7 100644
--- a/src/apps/drivesetup/MainWindow.cpp
+++ b/src/apps/drivesetup/MainWindow.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2013 Haiku Inc. All rights reserved.
+ * Copyright 2002-2013 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
@@ -7,8 +7,10 @@
  *             Ithamar R. Adema <ithamar@xxxxxxx>
  *             Ingo Weinhold <ingo_weinhold@xxxxxx>
  *             Stephan Aßmus <superstippi@xxxxxx>
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  */
 
+
 #include "MainWindow.h"
 
 #include <stdio.h>
@@ -140,6 +142,38 @@ private:
 };
 
 
+class ModificationPreparer {
+public:
+       ModificationPreparer(BDiskDevice* disk)
+               :
+               fDisk(disk),
+               fModificationStatus(fDisk->PrepareModifications())
+       {
+       }
+       ~ModificationPreparer()
+       {
+               if (fModificationStatus == B_OK)
+                       fDisk->CancelModifications();
+       }
+       status_t ModificationStatus() const
+       {
+               return fModificationStatus;
+       }
+       status_t CommitModifications()
+       {
+               status_t ret = fDisk->CommitModifications();
+               if (ret == B_OK)
+                       fModificationStatus = B_ERROR;
+
+               return ret;
+       }
+
+private:
+       BDiskDevice*    fDisk;
+       status_t                fModificationStatus;
+};
+
+
 enum {
        MSG_MOUNT_ALL                           = 'mnta',
        MSG_MOUNT                                       = 'mnts',
@@ -747,38 +781,6 @@ MainWindow::_MountAll()
 // #pragma mark -
 
 
-class ModificationPreparer {
-public:
-       ModificationPreparer(BDiskDevice* disk)
-               :
-               fDisk(disk),
-               fModificationStatus(fDisk->PrepareModifications())
-       {
-       }
-       ~ModificationPreparer()
-       {
-               if (fModificationStatus == B_OK)
-                       fDisk->CancelModifications();
-       }
-       status_t ModificationStatus() const
-       {
-               return fModificationStatus;
-       }
-       status_t CommitModifications()
-       {
-               status_t ret = fDisk->CommitModifications();
-               if (ret == B_OK)
-                       fModificationStatus = B_ERROR;
-
-               return ret;
-       }
-
-private:
-       BDiskDevice*    fDisk;
-       status_t                fModificationStatus;
-};
-
-
 void
 MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
        const BString& diskSystemName)
@@ -871,19 +873,10 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id 
selectedPartition,
 
        BString name;
        BString parameters;
-
-       // TODO: diskSystem.IsFileSystem() seems like a better fit here?
-       if (diskSystemName == "Be File System"
-               || diskSystemName == "NT File System") {
-               InitParamsPanel* panel = new InitParamsPanel(this, 
diskSystemName,
-                       partition);
-               if (panel->Go(name, parameters) == GO_CANCELED)
-                       return;
-       } else if (diskSystemName == "Intel Partition Map") {
-               // TODO: parameters?
-       } else if (diskSystemName == "Intel Extended Partition") {
-               // TODO: parameters?
-       }
+       InitParamsPanel* panel = new InitParamsPanel(this, diskSystemName,
+               partition);
+       if (panel->Go(name, parameters) == GO_CANCELED)
+               return;
 
        bool supportsName = diskSystem.SupportsContentName();
        BString validatedName(name);


Other related posts: