Author: aschnell
Date: Mon Apr 14 18:59:57 2008
New Revision: 46615
URL: http://svn.opensuse.org/viewcvs/yast?rev=46615&view=rev
Log:
- added getUnusedPartitionSlots
Modified:
branches/tmp/aschnell/part-redesign/libstorage/bindings/ycp/LibStorage.i
branches/tmp/aschnell/part-redesign/libstorage/src/Disk.cc
branches/tmp/aschnell/part-redesign/libstorage/src/Disk.h
branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc
branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h
branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h
branches/tmp/aschnell/part-redesign/package/yast2-storage.changes
branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp
Modified: branches/tmp/aschnell/part-redesign/libstorage/bindings/ycp/LibStorage.i
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/bindings/ycp/LibStorage.i?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/bindings/ycp/LibStorage.i (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/bindings/ycp/LibStorage.i Mon Apr 14 18:59:57 2008
@@ -32,6 +32,7 @@
specialize_sequence(storage::DmraidCoInfo, TO_PACK, FROM_PACK, CHECK)
specialize_sequence(storage::DmPartInfo, TO_PACK, FROM_PACK, CHECK)
specialize_sequence(storage::DmraidInfo, TO_PACK, FROM_PACK, CHECK)
+specialize_sequence(storage::PartitionSlotInfo, TO_PACK, FROM_PACK, CHECK)
%include "../../src/StorageInterface.h"
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Disk.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Disk.cc?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Disk.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Disk.cc Mon Apr 14 18:59:57 2008
@@ -1110,16 +1110,45 @@
return( make_pair(disk,nr) );
}
+
+static bool notDeletedPri( const Partition& p )
+{
+ return !p.deleted() && p.type()==PRIMARY;
+}
+
+static bool notDeletedExt( const Partition& p )
+{
+ return !p.deleted() && p.type()==EXTENDED;
+}
+
+static bool notDeletedLog( const Partition& p )
+{
+ return !p.deleted() && p.type()==LOGICAL;
+}
+
+
static bool isExtended( const Partition& p )
{
return( Volume::notDeleted(p) && p.type()==EXTENDED );
}
+
+unsigned int Disk::numPrimary() const
+{
+ return partPair(notDeletedPri).length();
+}
+
bool Disk::hasExtended() const
{
return( ext_possible && !partPair(isExtended).empty() );
}
+unsigned int Disk::numLogical() const
+{
+ return partPair(notDeletedLog).length();
+}
+
+
unsigned Disk::availablePartNumber( PartitionType type )
{
y2milestone( "begin name:%s type %d", name().c_str(), type );
@@ -1176,11 +1205,6 @@
return( ret );
}
-static bool notDeletedLog( const Partition& p )
- {
- return( !p.deleted() && p.type()==LOGICAL );
- }
-
static bool notDeletedNotLog( const Partition& p )
{
return( !p.deleted() && p.type()!=LOGICAL );
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Disk.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Disk.h?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Disk.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Disk.h Mon Apr 14 18:59:57 2008
@@ -41,6 +41,7 @@
unsigned long numMinor() const { return range; }
unsigned long cylSizeB() const { return byte_cyl; }
unsigned maxPrimary() const { return max_primary; }
+ bool extendedPossible() const { return ext_possible; };
unsigned maxLogical() const { return max_logical; }
const string& labelName() const { return label; }
const string& udevPath() const { return udev_path; }
@@ -90,7 +91,9 @@
int removeVolume( Volume* v );
void getUnusedSpace( std::list<Region>& free, bool all=true,
bool logical=false );
+ unsigned int numPrimary() const;
bool hasExtended() const;
+ unsigned int numLogical() const;
string setDiskLabelText( bool doing=true ) const;
unsigned long long cylinderToKb( unsigned long ) const;
unsigned long kbToCylinder( unsigned long long ) const;
@@ -198,7 +201,6 @@
virtual int doSetType( Volume* v );
virtual int doCreateLabel();
- //std::list<Region> getUnusedRegions();
void logData( const string& Dir );
bool haveBsdPart( const std::list& pl) const;
void setLabelData( const string& );
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc Mon Apr 14 18:59:57 2008
@@ -1703,6 +1703,66 @@
return( ret );
}
+
+int
+Storage::getUnusedPartitionSlots(const string& disk, deque<PartitionSlotInfo>& slots)
+{
+ int ret = 0;
+ slots.clear();
+ assertInit();
+ DiskIterator i = findDisk( disk );
+ if( i != dEnd() )
+ {
+ // maxPrimary() and maxLogical() include limits from partition table type and
+ // minor number range
+
+ // TODO: check these restrictions
+
+ bool primaryPossible = i->numPrimary() + (i->hasExtended() ? 1 : 0) < i->maxPrimary();
+ bool extendedPossible = primaryPossible && i->extendedPossible() && !i->hasExtended();
+ bool logicalPossible = i->hasExtended() && i->numLogical() < (i->maxLogical() - i->maxPrimary());
+
+ list<Region> regions;
+
+ i->getUnusedSpace(regions, false, false);
+ for( list<Region>::const_iterator region=regions.begin(); region!=regions.end(); region++ )
+ {
+ PartitionSlotInfo slot;
+ slot.cylStart = region->start();
+ slot.cylSize = region->len();
+ slot.primarySlot = true;
+ slot.primaryPossible = primaryPossible;
+ slot.extendedSlot = true;
+ slot.extendedPossible = extendedPossible;
+ slot.logicalSlot = false;
+ slot.logicalPossible = false;
+ slots.push_back(slot);
+ }
+
+ i->getUnusedSpace(regions, false, true);
+ for( list<Region>::const_iterator region=regions.begin(); region!=regions.end(); region++ )
+ {
+ PartitionSlotInfo slot;
+ slot.cylStart = region->start();
+ slot.cylSize = region->len();
+ slot.primarySlot = false;
+ slot.primaryPossible = false;
+ slot.extendedSlot = false;
+ slot.extendedPossible = false;
+ slot.logicalSlot = true;
+ slot.logicalPossible = logicalPossible;
+ slots.push_back(slot);
+ }
+ }
+ else
+ {
+ ret = STORAGE_DISK_NOT_FOUND;
+ }
+ y2milestone( "ret:%d", ret );
+ return ret;
+}
+
+
int
Storage::destroyPartitionTable( const string& disk, const string& label )
{
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h Mon Apr 14 18:59:57 2008
@@ -314,6 +314,7 @@
int removePartition( const string& partition );
int changePartitionId( const string& partition, unsigned id );
int forgetChangePartitionId( const string& partition );
+ int getUnusedPartitionSlots(const string& disk, deque<PartitionSlotInfo> &slots);
int destroyPartitionTable( const string& disk, const string& label );
int initializeDisk( const string& disk, bool value );
string defaultDiskLabel() const;
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h Mon Apr 14 18:59:57 2008
@@ -409,6 +409,22 @@
};
/**
+ * Contains info about a partition slot.
+ */
+ struct PartitionSlotInfo
+ {
+ PartitionSlotInfo() {}
+ unsigned long cylStart;
+ unsigned long cylSize;
+ bool primarySlot;
+ bool primaryPossible;
+ bool extendedSlot;
+ bool extendedPossible;
+ bool logicalSlot;
+ bool logicalPossible;
+ };
+
+ /**
* preliminary list of error codes, must have negative values
*/
enum ErrorCodes
@@ -1040,6 +1056,15 @@
virtual int forgetChangePartitionId (const string& partition ) = 0;
/**
+ * Query unused slots on a disk suitable for creating partitions.
+ *
+ * @param partition name of partition, e.g. /dev/hda1
+ * @param slots list of records that get filled with partition slot specific info
+ * @return zero if all is ok, a negative number to indicate an error
+ */
+ virtual int getUnusedPartitionSlots(const string& disk, deque<PartitionSlotInfo> &slots) = 0;
+
+ /**
* Destroys the partition table of a disk. An empty disk label
* of the given type without any partition is created.
*
Modified: branches/tmp/aschnell/part-redesign/package/yast2-storage.changes
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/package/yast2-storage.changes?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/package/yast2-storage.changes (original)
+++ branches/tmp/aschnell/part-redesign/package/yast2-storage.changes Mon Apr 14 18:59:57 2008
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
+Mon Apr 14 18:57:35 CEST 2008 - aschnell@suse.de
+
+- added function getUnusedPartitionSlots to libstorage
+
+-------------------------------------------------------------------
Thu Feb 7 19:17:31 CET 2008 - fehr@suse.de
- add key sb_ver with version of raid superblock to md maps (#357897)
Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp?rev=46615&r1=46614&r2=46615&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp Mon Apr 14 18:59:57 2008
@@ -65,6 +65,7 @@
import "LibStorage::PartitionAddInfo";
import "LibStorage::DmPartCoInfo";
import "LibStorage::DmraidCoInfo";
+ import "LibStorage::PartitionSlotInfo";
map conv_ctype =
$[ "def_sym" : `CT_UNKNOWN,
@@ -892,6 +893,34 @@
return( ret );
};
+
+global integer GetUnusedPartitionSlots(string device, list<map> &slots)
+{
+ list<any> swig_slots = [];
+
+ integer ret = LibStorage::StorageInterface::getUnusedPartitionSlots(sint, device, swig_slots);
+
+ foreach(any swig_slot, swig_slots, {
+
+ map slot = $[
+ "cyl_start" : LibStorage::PartitionSlotInfo::swig_cylStart_get(swig_slot),
+ "cyl_size" : LibStorage::PartitionSlotInfo::swig_cylSize_get(swig_slot),
+ "primary_slot" : LibStorage::PartitionSlotInfo::swig_primarySlot_get(swig_slot),
+ "primary_possible" : LibStorage::PartitionSlotInfo::swig_primaryPossible_get(swig_slot),
+ "extended_slot" : LibStorage::PartitionSlotInfo::swig_extendedSlot_get(swig_slot),
+ "extended_possible" : LibStorage::PartitionSlotInfo::swig_extendedPossible_get(swig_slot),
+ "logical_Slot" : LibStorage::PartitionSlotInfo::swig_logicalSlot_get(swig_slot),
+ "logical_possible" : LibStorage::PartitionSlotInfo::swig_logicalPossible_get(swig_slot)
+ ];
+
+ slots = add(slots, slot);
+
+ });
+
+ return ret;
+}
+
+
/**
* Adds ... and returns the changed map
*
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org