summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--autopart.py50
-rw-r--r--bootloader.py5
-rw-r--r--fsset.py9
-rw-r--r--iw/partition_gui.py1
-rw-r--r--partErrors.py35
-rw-r--r--partedUtils.py272
-rw-r--r--partitioning.py292
-rw-r--r--raid.py5
-rw-r--r--textw/partition_text.py1
9 files changed, 383 insertions, 287 deletions
diff --git a/autopart.py b/autopart.py
index 6364183af..02351115f 100644
--- a/autopart.py
+++ b/autopart.py
@@ -19,8 +19,10 @@ import copy
import string, sys
import fsset
from partitioning import *
+import partedUtils
from constants import *
from translate import _, N_
+from partErrors import *
PARTITION_FAIL = -1
PARTITION_SUCCESS = 0
@@ -35,7 +37,7 @@ def bootRequestCheck(requests, diskset):
dev = requests.getBootableRequest()
if not dev or not dev.device or dev.ignoreBootConstraints:
return PARTITION_SUCCESS
- part = get_partition_by_name(diskset.disks, dev.device)
+ part = partedUtils.get_partition_by_name(diskset.disks, dev.device)
if not part:
return PARTITION_SUCCESS
@@ -45,7 +47,7 @@ def bootRequestCheck(requests, diskset):
return BOOTEFI_NOT_VFAT
pass
elif iutil.getArch() == "i386":
- if end_sector_to_cyl(part.geom.disk.dev, part.geom.end) >= 1024:
+ if partedUtils.end_sector_to_cyl(part.geom.disk.dev, part.geom.end) >= 1024:
return BOOT_ABOVE_1024
return PARTITION_SUCCESS
@@ -55,13 +57,13 @@ def printNewRequestsCyl(diskset, newRequest):
if req.type != REQUEST_NEW:
continue
- part = get_partition_by_name(diskset.disks, req.device)
+ part = partedUtils.get_partition_by_name(diskset.disks, req.device)
print req
- print "Start Cyl:%s End Cyl: %s" % (start_sector_to_cyl(part.geom.disk.dev, part.geom.start),
- end_sector_to_cyl(part.geom.disk.dev, part.geom.end))
+ print "Start Cyl:%s End Cyl: %s" % (partedUtils.start_sector_to_cyl(part.geom.disk.dev, part.geom.start),
+ partedUtils.end_sector_to_cyl(part.geom.disk.dev, part.geom.end))
def printFreespaceitem(part):
- return get_partition_name(part), part.geom.start, part.geom.end, getPartSizeMB(part)
+ return partedUtils.get_partition_name(part), part.geom.start, part.geom.end, partedUtils.getPartSizeMB(part)
def printFreespace(free):
print "Free Space Summary:"
@@ -85,7 +87,7 @@ def findFreespace(diskset):
def bestPartType(disk, request):
- numPrimary = len(get_primary_partitions(disk))
+ numPrimary = len(partedUtils.get_primary_partitions(disk))
maxPrimary = disk.max_primary_partition_count
if numPrimary == maxPrimary:
raise PartitioningError, "Unable to create additional primary partitions on /dev/%s" % (disk.dev.path[5:])
@@ -102,7 +104,7 @@ class partlist:
def __str__(self):
retval = ""
for p in self.parts:
- retval = retval + "\t%s %s %s\n" % (get_partition_name(p), get_partition_file_system_type(p), getPartSizeMB(p))
+ retval = retval + "\t%s %s %s\n" % (partedUtils.get_partition_name(p), partedUtils.get_partition_file_system_type(p), partedUtils.getPartSizeMB(p))
return retval
@@ -140,14 +142,14 @@ def fitConstrained(diskset, requests, primOnly=0, newParts = None):
if not disk: # this shouldn't happen
raise PartitioningError, "Selected to put partition on non-existent disk!"
- startSec = start_cyl_to_sector(disk.dev, request.start)
+ startSec = partedUtils.start_cyl_to_sector(disk.dev, request.start)
if request.end:
endCyl = request.end
elif request.size:
- endCyl = end_sector_to_cyl(disk.dev, ((1024L * 1024L * request.size) / disk.dev.sector_size) + startSec)
+ endCyl = partedUtils.end_sector_to_cyl(disk.dev, ((1024L * 1024L * request.size) / disk.dev.sector_size) + startSec)
- endSec = end_cyl_to_sector(disk.dev, endCyl)
+ endSec = partedUtils.end_cyl_to_sector(disk.dev, endCyl)
if endSec > disk.dev.length:
raise PartitioningError, "Unable to create partition which extends beyond the end of the disk."
@@ -271,7 +273,7 @@ def fitSized(diskset, requests, primOnly = 0, newParts = None):
for part in free[drive]:
# print "Trying partition", printFreespaceitem(part)
- partSize = getPartSizeMB(part)
+ partSize = partedUtils.getPartSizeMB(part)
# print "partSize %s request %s" % (partSize, request.requestSize)
if partSize >= request.requestSize and partSize > largestPart[0]:
if not request.primary or (not part.type & parted.PARTITION_LOGICAL):
@@ -385,7 +387,7 @@ def growParts(diskset, requests, newParts):
continue
freeSize[key] = 0
for part in free[key]:
- freeSize[key] = freeSize[key] + getPartSize(part)
+ freeSize[key] = freeSize[key] + partedUtils.getPartSize(part)
return (free, freeSize)
@@ -496,8 +498,8 @@ def growParts(diskset, requests, newParts):
donegrowing = 0
# get amount of space actually used by current allocation
- part = get_partition_by_name(diskset.disks, request.device)
- startSize = getPartSize(part)
+ part = partedUtils.get_partition_by_name(diskset.disks, request.device)
+ startSize = partedUtils.getPartSize(part)
# compute fraction of freespace which to give to this
# request. Weight by original request size
@@ -611,7 +613,7 @@ def setPreexistParts(diskset, requests, newParts):
part = disk.next_partition()
while part:
if part.geom.start == request.start and part.geom.end == request.end:
- request.device = get_partition_name(part)
+ request.device = partedUtils.get_partition_name(part)
if request.fstype:
if request.fstype.getName() != request.origfstype.getName():
if request.fstype.getName() == "software RAID":
@@ -624,7 +626,7 @@ def setPreexistParts(diskset, requests, newParts):
else:
part.set_flag(parted.PARTITION_LVM, 0)
- set_partition_file_system_type(part, request.fstype)
+ partedUtils.set_partition_file_system_type(part, request.fstype)
break
part = disk.next_partition(part)
@@ -666,7 +668,7 @@ def processPartitioning(diskset, requests, newParts):
# the disks. We'll start again from there.
for part in newParts.parts:
disk = part.geom.disk
-# disk = diskset.disks[get_partition_drive(part)]
+# disk = diskset.disks[partedUtils.get_partition_drive(part)]
disk.delete_partition(part)
newParts.reset()
@@ -797,19 +799,19 @@ def doClearPartAction(partitions, diskset):
part = disk.next_partition(part)
continue
if part.fs_type:
- ptype = get_partition_file_system_type(part)
+ ptype = partedUtils.get_partition_file_system_type(part)
else:
ptype = None
if (linuxOnly == 0) or (ptype and ptype.isLinuxNativeFS()) or \
(not ptype and query_is_linux_native_by_numtype(part.native_type)):
- old = partitions.getRequestByDeviceName(get_partition_name(part))
+ old = partitions.getRequestByDeviceName(partedUtils.get_partition_name(part))
if old.type == REQUEST_PROTECTED:
part = disk.next_partition(part)
continue
partitions.removeRequest(old)
- drive = get_partition_drive(part)
+ drive = partedUtils.get_partition_drive(part)
delete = DeleteSpec(drive, part.geom.start, part.geom.end)
partitions.addDelete(delete)
@@ -823,7 +825,7 @@ def doClearPartAction(partitions, diskset):
part.is_flag_available(parted.PARTITION_BOOT)):
if part.fs_type and part.fs_type.name == "FAT":
if part.get_flag(parted.PARTITION_BOOT):
- req = partitions.getRequestByDeviceName(get_partition_name(part))
+ req = partitions.getRequestByDeviceName(partedUtils.get_partition_name(part))
req.mountpoint = "/boot/efi"
req.format = 0
@@ -845,9 +847,9 @@ def doClearPartAction(partitions, diskset):
disk = diskset.disks[drive]
ext = disk.extended_partition
- if ext and len(get_logical_partitions(disk)) == 0:
+ if ext and len(partedUtils.get_logical_partitions(disk)) == 0:
delete = DeleteSpec(drive, ext.geom.start, ext.geom.end)
- old = partitions.getRequestByDeviceName(get_partition_name(ext))
+ old = partitions.getRequestByDeviceName(partedUtils.get_partition_name(ext))
partitions.removeRequest(old)
partitions.addDelete(delete)
deletePart(diskset, delete)
diff --git a/bootloader.py b/bootloader.py
index e8cb8f182..f5186e984 100644
--- a/bootloader.py
+++ b/bootloader.py
@@ -16,6 +16,7 @@
import isys
import partitioning
+import partedUtils
import os
import crypt
import whrandom
@@ -64,9 +65,9 @@ def bootloaderSetupChoices(dispatch, bl, fsset, diskSet, dir):
bootDev = fsset.getEntryByMountPoint("/")
if not bootDev:
bootDev = fsset.getEntryByMountPoint("/boot")
- part = partitioning.get_partition_by_name(diskSet.disks,
+ part = partedUtils.get_partition_by_name(diskSet.disks,
bootDev.device.getDevice())
- if part and partitioning.end_sector_to_cyl(part.geom.disk.dev,
+ if part and partedUtils.end_sector_to_cyl(part.geom.disk.dev,
part.geom.end) >= 1024:
bl.above1024 = 1
diff --git a/fsset.py b/fsset.py
index c264328a0..d9aa86ef9 100644
--- a/fsset.py
+++ b/fsset.py
@@ -22,6 +22,7 @@ import parted
import sys
import struct
import partitioning
+import partedUtils
import types
from log import log
from translate import _, N_
@@ -828,7 +829,7 @@ class FileSystemSet:
# stupid itanium
if iutil.getArch() == "ia64":
- part = partitioning.get_partition_by_name(diskset.disks, bootDev)
+ part = partedUtils.get_partition_by_name(diskset.disks, bootDev)
if part and part.is_flag_available(parted.PARTITION_BOOT):
part.set_flag(parted.PARTITION_BOOT, 1)
return
@@ -856,7 +857,7 @@ class FileSystemSet:
if not bootPart:
bootPart = part
- if partitioning.get_partition_name(part) == bootDev:
+ if partedUtils.get_partition_name(part) == bootDev:
bootPart = part
part = disk.next_partition(part)
@@ -1497,7 +1498,7 @@ class PartedPartitionDevice(PartitionDevice):
if not self.partition:
return self.device
- return partitioning.get_partition_name(self.partition)
+ return partedUtils.get_partition_name(self.partition)
def solidify(self):
# drop reference on the parted partition object and note
@@ -1598,7 +1599,7 @@ def readFstab (path):
f = open (path, "r")
lines = f.readlines ()
- f.close
+ f.close()
for line in lines:
fields = string.split (line)
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index 3658cab22..dcf37b838 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -28,6 +28,7 @@ import checklist
from iw_gui import *
from translate import _, N_
from partitioning import *
+from partedUtils import *
from fsset import *
STRIPE_HEIGHT = 32.0
diff --git a/partErrors.py b/partErrors.py
new file mode 100644
index 000000000..ed05bda35
--- /dev/null
+++ b/partErrors.py
@@ -0,0 +1,35 @@
+#
+# partErrors.py: partitioning error exceptions
+#
+# Matt Wilson <msw@redhat.com>
+# Jeremy Katz <katzj@redhat.com>
+# Mike Fulbright <msf@redhat.com>
+#
+# Copyright 2001 Red Hat, Inc.
+#
+# This software may be freely redistributed under the terms of the GNU
+# library public license.
+#
+# You should have received a copy of the GNU Library Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+"""Exceptions for use in partitioning."""
+
+
+class PartitioningError:
+ """A critical error which must be resolved to continue the installation."""
+ def __init__ (self, value):
+ self.value = value
+
+ def __str__ (self):
+ return self.value
+
+class PartitioningWarning:
+ """A warning which may be ignored and still complete the installation."""
+ def __init__ (self, value):
+ self.value = value
+
+ def __str__ (self):
+ return self.value
+
diff --git a/partedUtils.py b/partedUtils.py
new file mode 100644
index 000000000..5b4cd7631
--- /dev/null
+++ b/partedUtils.py
@@ -0,0 +1,272 @@
+#
+# partedUtils.py: helper functions for use with parted objects
+#
+# Matt Wilson <msw@redhat.com>
+# Jeremy Katz <katzj@redhat.com>
+# Mike Fulbright <msf@redhat.com>
+#
+# Copyright 2002 Red Hat, Inc.
+#
+# This software may be freely redistributed under the terms of the GNU
+# library public license.
+#
+# You should have received a copy of the GNU Library Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+"""Helper functions for use when dealing with parted objects."""
+
+import parted
+import fsset
+import math
+
+from partErrors import *
+from translate import _
+
+fsTypes = {}
+
+fs_type = parted.file_system_type_get_next ()
+while fs_type:
+ fsTypes[fs_type.name] = fs_type
+ fs_type = parted.file_system_type_get_next (fs_type)
+
+
+
+def get_flags (part):
+ """Retrieve a list of strings representing the flags on the partition."""
+ string=""
+ if not part.is_active ():
+ return string
+ first=1
+ flag = parted.partition_flag_next (0)
+ while flag:
+ if part.get_flag (flag):
+ string = string + parted.partition_flag_get_name (flag)
+ if first:
+ first = 0
+ else:
+ string = string + ", "
+ flag = parted.partition_flag_next (flag)
+ return string
+
+def start_sector_to_cyl(device, sector):
+ """Return the closest cylinder (round down) to sector on device."""
+ return int(math.floor((float(sector)
+ / (device.heads * device.sectors)) + 1))
+
+def end_sector_to_cyl(device, sector):
+ """Return the closest cylinder (round up) to sector on device."""
+ return int(math.ceil(float((sector + 1))
+ / (device.heads * device.sectors)))
+
+def start_cyl_to_sector(device, cyl):
+ "Return the sector corresponding to cylinder as a starting cylinder."
+ return long((cyl - 1) * (device.heads * device.sectors))
+
+def end_cyl_to_sector(device, cyl):
+ "Return the sector corresponding to cylinder as a ending cylinder."
+ return long(((cyl) * (device.heads * device.sectors)) - 1)
+
+def getPartSize(partition):
+ """Return the size of partition in sectors."""
+ return partition.geom.length
+
+def getPartSizeMB(partition):
+ """Return the size of partition in megabytes."""
+ return (partition.geom.length * partition.geom.disk.dev.sector_size
+ / 1024.0 / 1024.0)
+
+def getDeviceSizeMB(dev):
+ """Return the size of dev in megabytes."""
+ return (float(dev.heads * dev.cylinders * dev.sectors) / (1024 * 1024)
+ * dev.sector_size)
+
+def get_partition_by_name(disks, partname):
+ """Return the parted part object associated with partname.
+
+ Arguments:
+ disks -- Dictionary of diskname->PedDisk objects
+ partname -- Name of partition to find
+
+ Return:
+ PedPartition object with name partname. None if no such partition.
+ """
+ for diskname in disks.keys():
+ disk = disks[diskname]
+ part = disk.next_partition()
+ while part:
+ if get_partition_name(part) == partname:
+ return part
+
+ part = disk.next_partition(part)
+
+ return None
+
+def get_partition_name(partition):
+ """Return the device name for the PedPartition partition."""
+ if (partition.geom.disk.dev.type == parted.DEVICE_DAC960
+ or partition.geom.disk.dev.type == parted.DEVICE_CPQARRAY):
+ return "%sp%d" % (partition.geom.disk.dev.path[5:],
+ partition.num)
+ return "%s%d" % (partition.geom.disk.dev.path[5:],
+ partition.num)
+
+
+def get_partition_file_system_type(part):
+ """Return the file system type of the PedPartition part.
+
+ Arguments:
+ part -- PedPartition object
+
+ Return:
+ Filesystem object (as defined in fsset.py)
+ """
+ if part.fs_type == None:
+ return None
+ if part.fs_type.name == "linux-swap":
+ ptype = fsset.fileSystemTypeGet("swap")
+ elif part.fs_type.name == "FAT":
+ ptype = fsset.fileSystemTypeGet("vfat")
+ else:
+ try:
+ ptype = fsset.fileSystemTypeGet(part.fs_type.name)
+ except:
+ ptype = fsset.fileSystemTypeGet("foreign")
+
+ return ptype
+
+
+def set_partition_file_system_type(part, fstype):
+ """Set partition type of part to PedFileSystemType implied by fstype."""
+ if fstype == None:
+ return
+ try:
+ for flag in fstype.getPartedPartitionFlags():
+ if not part.is_flag_available(flag):
+ raise PartitioningError, ("requested FileSystemType needs "
+ "a flag that is not available.")
+ part.set_flag(flag, 1)
+ part.set_system(fstype.getPartedFileSystemType())
+ except:
+ print "Failed to set partition type to ",fstype.getName()
+ pass
+
+def get_partition_drive(partition):
+ """Return the device name for disk that PedPartition partition is on."""
+ return "%s" %(partition.geom.disk.dev.path[5:])
+
+def map_foreign_to_fsname(type):
+ """Return the partition type associated with the numeric type."""
+ if type in allPartitionTypesDict.keys():
+ return allPartitionTypesDict[type]
+ else:
+ return _("Foreign")
+
+def filter_partitions(disk, func):
+ rc = []
+ part = disk.next_partition ()
+ while part:
+ if func(part):
+ rc.append(part)
+ part = disk.next_partition (part)
+
+ return rc
+
+def get_logical_partitions(disk):
+ """Return a list of logical PedPartition objects on disk."""
+ func = lambda part: (part.is_active()
+ and part.type & parted.PARTITION_LOGICAL)
+ return filter_partitions(disk, func)
+
+def get_primary_partitions(disk):
+ """Return a list of primary PedPartition objects on disk."""
+ func = lambda part: part.type == parted.PARTITION_PRIMARY
+ return filter_partitions(disk, func)
+
+def get_raid_partitions(disk):
+ """Return a list of RAID-type PedPartition objects on disk."""
+ func = lambda part: (part.is_active()
+ and part.get_flag(parted.PARTITION_RAID) == 1)
+ return filter_partitions(disk, func)
+
+def get_lvm_partitions(disk):
+ """Return a list of physical volume-type PedPartition objects on disk."""
+ func = lambda part: (part.is_active()
+ and part.get_flag(parted.PARTITION_LVM) == 1)
+ return filter_partitions(disk, func)
+
+
+
+# XXX is this all of the possibilities?
+dosPartitionTypes = [ 1, 6, 11, 12, 14, 15 ]
+
+# master list of partition types
+allPartitionTypesDict = {
+ 0 : "Empty",
+ 1: "DOS 12-bit FAT",
+ 2: "XENIX root",
+ 3: "XENIX usr",
+ 4: "DOS 16-bit <32M",
+ 5: "Extended",
+ 6: "DOS 16-bit >=32M",
+ 7: "NTFS/HPFS",
+ 8: "AIX",
+ 9: "AIX bootable",
+ 10: "OS/2 Boot Manager",
+ 0xb: "Win95 FAT32",
+ 0xc: "Win95 FAT32",
+ 0xe: "Win95 FAT16",
+ 0xf: "Win95 Ext'd",
+ 0x10: "OPUS",
+ 0x11: "Hidden FAT12",
+ 0x12: "Compaq Setup",
+ 0x14: "Hidden FAT16 <32M",
+ 0x16: "Hidden FAT16",
+ 0x17: "Hidden HPFS/NTFS",
+ 0x18: "AST SmartSleep",
+ 0x1b: "Hidden Win95 FAT32",
+ 0x1c: "Hidden Win95 FAT32 (LBA)",
+ 0x1e: "Hidden Win95 FAT16 (LBA)",
+ 0x24: "NEC_DOS",
+ 0x39: "Plan 9",
+ 0x40: "Venix 80286",
+ 0x41: "PPC_PReP Boot",
+ 0x42: "SFS",
+ 0x4d: "QNX4.x",
+ 0x4e: "QNX4.x 2nd part",
+ 0x4f: "QNX4.x 2nd part",
+ 0x51: "Novell?",
+ 0x52: "Microport",
+ 0x63: "GNU HURD",
+ 0x64: "Novell Netware 286",
+ 0x65: "Novell Netware 386",
+ 0x75: "PC/IX",
+ 0x80: "Old MINIX",
+ 0x81: "Linux/MINIX",
+ 0x82: "Linux swap",
+ 0x83: "Linux native",
+ 0x84: "OS/2 hidden C:",
+ 0x85: "Linux Extended",
+ 0x86: "NTFS volume set",
+ 0x87: "NTFS volume set",
+ 0x8e: "Linux LVM",
+ 0x93: "Amoeba",
+ 0x94: "Amoeba BBT",
+ 0x9f: "BSD/OS",
+ 0xa0: "IBM Thinkpad hibernation",
+ 0xa5: "BSD/386",
+ 0xa6: "OpenBSD",
+ 0xb7: "BSDI fs",
+ 0xb8: "BSDI swap",
+ 0xc7: "Syrinx",
+ 0xdb: "CP/M",
+ 0xde: "Dell Utility",
+ 0xe1: "DOS access",
+ 0xe3: "DOS R/O",
+ 0xeb: "BEOS",
+ 0xee: "EFI GPT",
+ 0xef: "EFI (FAT-12/16/32)",
+ 0xf2: "DOS secondary",
+ 0xfd: "Linux RAID",
+ 0xff: "BBT"
+ }
diff --git a/partitioning.py b/partitioning.py
index 80c2fa075..d502e361a 100644
--- a/partitioning.py
+++ b/partitioning.py
@@ -29,10 +29,12 @@ import os
import sys
import string
import iutil
+import partedUtils
from translate import _
from log import log
from constants import *
from flags import flags
+from partErrors import *
# different types of partition requests
# REQUEST_PREEXIST is a placeholder for a pre-existing partition on the system
@@ -54,125 +56,6 @@ CLEARPART_TYPE_LINUX = 1
CLEARPART_TYPE_ALL = 2
CLEARPART_TYPE_NONE = 3
-fsTypes = {}
-
-fs_type = parted.file_system_type_get_next ()
-while fs_type:
- fsTypes[fs_type.name] = fs_type
- fs_type = parted.file_system_type_get_next (fs_type)
-
-class PartitioningError:
- def __init__ (self, value):
- self.value = value
-
- def __str__ (self):
- return self.value
-
-class PartitioningWarning:
- def __init__ (self, value):
- self.value = value
-
- def __str__ (self):
- return self.value
-
-def get_flags (part):
- string=""
- if not part.is_active ():
- return string
- first=1
- flag = parted.partition_flag_next (0)
- while flag:
- if part.get_flag (flag):
- string = string + parted.partition_flag_get_name (flag)
- if first:
- first = 0
- else:
- string = string + ", "
- flag = parted.partition_flag_next (flag)
- return string
-
-def start_sector_to_cyl(device, sector):
- return int(math.floor((float(sector)
- / (device.heads * device.sectors)) + 1))
-
-def end_sector_to_cyl(device, sector):
- return int(math.ceil(float((sector + 1))
- / (device.heads * device.sectors)))
-
-def start_cyl_to_sector(device, cyl):
- return long((cyl - 1) * (device.heads * device.sectors))
-
-def end_cyl_to_sector(device, cyl):
- return long(((cyl) * (device.heads * device.sectors)) - 1)
-
-def getPartSize(partition):
- return partition.geom.length
-
-def getPartSizeMB(partition):
- return (partition.geom.length * partition.geom.disk.dev.sector_size
- / 1024.0 / 1024.0)
-
-def getDeviceSizeMB(dev):
- return (float(dev.heads * dev.cylinders * dev.sectors) / (1024 * 1024)
- * dev.sector_size)
-
-def get_partition_by_name(disks, partname):
- for diskname in disks.keys():
- disk = disks[diskname]
- part = disk.next_partition()
- while part:
- if get_partition_name(part) == partname:
- return part
-
- part = disk.next_partition(part)
-
- return None
-
-def get_partition_name(partition):
- if (partition.geom.disk.dev.type == parted.DEVICE_DAC960
- or partition.geom.disk.dev.type == parted.DEVICE_CPQARRAY):
- return "%sp%d" % (partition.geom.disk.dev.path[5:],
- partition.num)
- return "%s%d" % (partition.geom.disk.dev.path[5:],
- partition.num)
-
-def get_partition_file_system_type(part):
- if part.fs_type == None:
- return None
- if part.fs_type.name == "linux-swap":
- ptype = fsset.fileSystemTypeGet("swap")
- elif part.fs_type.name == "FAT":
- ptype = fsset.fileSystemTypeGet("vfat")
- else:
- try:
- ptype = fsset.fileSystemTypeGet(part.fs_type.name)
- except:
- ptype = fsset.fileSystemTypeGet("foreign")
-
- return ptype
-
-def set_partition_file_system_type(part, fstype):
- if fstype == None:
- return
- try:
- for flag in fstype.getPartedPartitionFlags():
- if not part.is_flag_available(flag):
- raise PartitioningError, ("requested FileSystemType needs "
- "a flag that is not available.")
- part.set_flag(flag, 1)
- part.set_system(fstype.getPartedFileSystemType())
- except:
- print "Failed to set partition type to ",fstype.getName()
- pass
-
-def get_partition_drive(partition):
- return "%s" %(partition.geom.disk.dev.path[5:])
-
-def map_foreign_to_fsname(type):
- if type in allPartitionTypesDict.keys():
- return allPartitionTypesDict[type]
- else:
- return _("Foreign")
def query_is_linux_native_by_numtype(numtype):
linuxtypes = [0x82, 0x83, 0x8e, 0xfd]
@@ -183,37 +66,6 @@ def query_is_linux_native_by_numtype(numtype):
return 0
-def filter_partitions(disk, func):
- rc = []
- part = disk.next_partition ()
- while part:
- if func(part):
- rc.append(part)
- part = disk.next_partition (part)
-
- return rc
-
-def get_logical_partitions(disk):
- func = lambda part: (part.is_active()
- and part.type & parted.PARTITION_LOGICAL)
- return filter_partitions(disk, func)
-
-def get_primary_partitions(disk):
- func = lambda part: part.type == parted.PARTITION_PRIMARY
- return filter_partitions(disk, func)
-
-# returns a list of partitions which can make up RAID devices
-def get_raid_partitions(disk):
- func = lambda part: (part.is_active()
- and part.get_flag(parted.PARTITION_RAID) == 1)
- return filter_partitions(disk, func)
-
-# returns a list of partitions which can make up volume groups
-def get_lvm_partitions(disk):
- func = lambda part: (part.is_active()
- and part.get_flag(parted.PARTITION_LVM) == 1)
- return filter_partitions(disk, func)
-
# returns a list of the actual raid device requests
def get_lvm_volume_groups(requests):
raidRequests = []
@@ -257,8 +109,8 @@ def get_available_raid_partitions(diskset, requests, request):
drives.sort()
for drive in drives:
disk = diskset.disks[drive]
- for part in get_raid_partitions(disk):
- partname = get_partition_name(part)
+ for part in partedUtils.get_raid_partitions(disk):
+ partname = partedUtils.get_partition_name(part)
used = 0
for raid in raiddevs:
if raid.raidmembers:
@@ -287,8 +139,8 @@ def get_available_lvm_partitions(diskset, requests, request):
volgroups = get_lvm_volume_groups(requests.requests)
for drive in drives:
disk = diskset.disks[drive]
- for part in get_lvm_partitions(disk):
- partname = get_partition_name(part)
+ for part in partedUtils.get_lvm_partitions(disk):
+ partname = partedUtils.get_partition_name(part)
partrequest = requests.getRequestByDeviceName(partname)
used = 0
for volgroup in volgroups:
@@ -315,7 +167,8 @@ def get_lvm_volume_group_size(request, requests, diskset):
totalspace = 0
for physvolid in request.physicalVolumes:
pvreq = requests.getRequestByID(physvolid)
- part = get_partition_by_name(diskset.disks, pvreq.device)
+ part = partedUtils.get_partition_by_name(diskset.disks,
+ pvreq.device)
totalspace = totalspace + part.geom.length * part.geom.disk.dev.sector_size
return totalspace
@@ -380,7 +233,7 @@ def get_raid_device_size(raidrequest, partitions, diskset):
for member in raidrequest.raidmembers:
req = partitions.getRequestByID(member)
device = req.device
- part = get_partition_by_name(diskset.disks, device)
+ part = partedUtils.get_partition_by_name(diskset.disks, device)
partsize = part.geom.length * part.geom.disk.dev.sector_size
if isRaid0(raidlevel):
@@ -681,7 +534,7 @@ def requestSize(req, diskset):
else:
thissize = 0
else:
- part = get_partition_by_name(diskset.disks, req.device)
+ part = partedUtils.get_partition_by_name(diskset.disks, req.device)
if not part:
# XXX hack for kickstart which ends up calling this
# before allocating the partitions
@@ -690,7 +543,7 @@ def requestSize(req, diskset):
else:
thissize = 0
else:
- thissize = getPartSizeMB(part)
+ thissize = partedUtils.getPartSizeMB(part)
return thissize
# this function is called at the end of partitioning so that we
@@ -807,8 +660,8 @@ def getPreExistFormatWarnings(partitions, diskset):
# add delete specs to requests for all logical partitions in part
def deleteAllLogicalPartitions(part, requests):
- for partition in get_logical_partitions(part.geom.disk):
- request = requests.getRequestByDeviceName(get_partition_name(partition))
+ for partition in partedUtils.get_logical_partitions(part.geom.disk):
+ request = requests.getRequestByDeviceName(partedUtils.get_partition_name(partition))
requests.removeRequest(request)
if request.type == REQUEST_PREEXIST:
drive = get_partition_drive(partition)
@@ -1085,7 +938,7 @@ class Partitions:
elif part.get_flag(parted.PARTITION_LVM) == 1:
ptype = fsset.fileSystemTypeGet("physical volume (LVM)")
elif part.fs_type:
- ptype = get_partition_file_system_type(part)
+ ptype = partedUtils.get_partition_file_system_type(part)
if part.fs_type.name == "linux-swap":
# XXX this is a hack
format = 1
@@ -1094,8 +947,8 @@ class Partitions:
start = part.geom.start
end = part.geom.end
- size = getPartSizeMB(part)
- drive = get_partition_drive(part)
+ size = partedUtils.getPartSizeMB(part)
+ drive = partedUtils.get_partition_drive(part)
spec = PartitionSpec(ptype, origfstype = ptype,
requesttype = REQUEST_PREEXIST,
@@ -1511,9 +1364,9 @@ class DiskSet:
and part.fs_type
and (part.fs_type.name == "ext2"
or part.fs_type.name == "ext3"))
- parts = filter_partitions(disk, func)
+ parts = partedUtils.filter_partitions(disk, func)
for part in parts:
- node = get_partition_name(part)
+ node = partedUtils.get_partition_name(part)
label = isys.readExt2Label(node)
if label:
labels[node] = label
@@ -1568,7 +1421,7 @@ class DiskSet:
# (#32562)
pass
elif part.fs_type and part.fs_type.name in fsset.getUsableLinuxFs():
- node = get_partition_name(part)
+ node = partedUtils.get_partition_name(part)
try:
isys.mount(node, mountpoint, part.fs_type.name)
except SystemError, (errno, msg):
@@ -1581,7 +1434,7 @@ class DiskSet:
rootparts.append ((node, part.fs_type.name))
isys.umount(mountpoint)
elif part.fs_type and (part.fs_type.name == "FAT"):
- node = get_partition_name(part)
+ node = partedUtils.get_partition_name(part)
try:
isys.mount(node, mountpoint, fstype = "vfat",
readOnly = 1)
@@ -1823,7 +1676,7 @@ class DiskSet:
def partitionTypes (self):
rc = []
drives = self.disks.keys()
- drives.sort
+ drives.sort()
for drive in drives:
disk = self.disks[drive]
@@ -1831,7 +1684,7 @@ class DiskSet:
while part:
if part.type in (parted.PARTITION_PRIMARY,
parted.PARTITION_LOGICAL):
- device = get_partition_name(part)
+ device = partedUtils.get_partition_name(part)
if part.fs_type:
ptype = part.fs_type.name
else:
@@ -1862,10 +1715,10 @@ class DiskSet:
device = ""
fs_type_name = ""
if part.num > 0:
- device = get_partition_name(part)
+ device = partedUtils.get_partition_name(part)
if part.fs_type:
fs_type_name = part.fs_type.name
- flags = get_flags (part)
+ flags = partedUtils.get_flags (part)
rc = rc + ("%-9s %-12s %-12s %-10ld %-10ld %-10ld %7s\n"
% (device, part.type_name, fs_type_name,
part.geom.start, part.geom.end, part.geom.length,
@@ -2004,7 +1857,7 @@ def containsImmutablePart(part, requestlist):
part = disk.next_partition(part)
continue
- device = get_partition_name(part)
+ device = partedUtils.get_partition_name(part)
request = requestlist.getRequestByDeviceName(device)
if request:
@@ -2038,7 +1891,7 @@ def doDeletePartitionByRequest(intf, requestlist, partition):
_("You cannot remove free space."))
return 0
else:
- device = get_partition_name(partition)
+ device = partedUtils.get_partition_name(partition)
ret = containsImmutablePart(partition, requestlist)
if ret:
@@ -2085,7 +1938,7 @@ def doDeletePartitionByRequest(intf, requestlist, partition):
if request.type == REQUEST_PREEXIST:
# get the drive
- drive = get_partition_drive(partition)
+ drive = partedUtils.get_partition_drive(partition)
if partition.type & parted.PARTITION_EXTENDED:
deleteAllLogicalPartitions(partition, requestlist)
@@ -2122,17 +1975,17 @@ def doEditPartitionByRequest(intf, requestlist, part):
else:
return (None, None)
elif iutil.getArch() == "s390":
- self.intf.messageWindow(_("Error"),
+ intf.messageWindow(_("Error"),
_("You must go back and use fdasd to "
"inititalize this partition"))
return (None, None)
elif part.type & parted.PARTITION_FREESPACE:
request = PartitionSpec(fsset.fileSystemTypeGetDefault(), REQUEST_NEW,
- start = start_sector_to_cyl(part.geom.disk.dev,
+ start = partedUtils.start_sector_to_cyl(part.geom.disk.dev,
part.geom.start),
- end = end_sector_to_cyl(part.geom.disk.dev,
+ end = partedUtils.end_sector_to_cyl(part.geom.disk.dev,
part.geom.end),
- drive = [ get_partition_drive(part) ])
+ drive = [ partedUtils.get_partition_drive(part) ])
return ("NEW", request)
elif part.type & parted.PARTITION_EXTENDED:
@@ -2146,7 +1999,7 @@ def doEditPartitionByRequest(intf, requestlist, part):
"which contains %s") %(ret))
return 0
- request = requestlist.getRequestByDeviceName(get_partition_name(part))
+ request = requestlist.getRequestByDeviceName(partedUtils.get_partition_name(part))
if request:
if requestlist.isRaidMember(request):
intf.messageWindow( _("Unable to Edit"),
@@ -2157,7 +2010,7 @@ def doEditPartitionByRequest(intf, requestlist, part):
return ("PARTITION", request)
else: # shouldn't ever happen
raise ValueError, ("Trying to edit non-existent partition %s"
- % (get_partition_name(part)))
+ % (partedUtils.get_partition_name(part)))
def partitioningComplete(bl, fsset, diskSet, partitions, intf, instPath, dir):
@@ -2210,7 +2063,8 @@ def checkForSwapNoMatch(intf, diskset, partitions):
if not request.device or not request.fstype:
continue
- part = get_partition_by_name(diskset.disks, request.device)
+ part = partedUtils.get_partition_by_name(diskset.disks,
+ request.device)
if (part and (not part.type & parted.PARTITION_FREESPACE) and (part.native_type == 0x82) and (request.fstype and request.fstype.getName() != "swap") and (not request.format)):
rc = intf.messageWindow(_("Format as Swap?"),
_("/dev/%s has a partition type of 0x82 "
@@ -2228,7 +2082,7 @@ def checkForSwapNoMatch(intf, diskset, partitions):
else:
part.set_flag(parted.PARTITION_RAID, 0)
- set_partition_file_system_type(part, request.fstype)
+ partedUtils.set_partition_file_system_type(part, request.fstype)
def queryFormatPreExisting(intf):
@@ -2299,76 +2153,4 @@ def partitionPreExistFormatWarnings(intf, warnings):
type="yesno")
return rc
-# XXX is this all of the possibilities?
-dosPartitionTypes = [ 1, 6, 11, 12, 14, 15 ]
-
-# master list of partition types
-allPartitionTypesDict = {
- 0 : "Empty",
- 1: "DOS 12-bit FAT",
- 2: "XENIX root",
- 3: "XENIX usr",
- 4: "DOS 16-bit <32M",
- 5: "Extended",
- 6: "DOS 16-bit >=32M",
- 7: "NTFS/HPFS",
- 8: "AIX",
- 9: "AIX bootable",
- 10: "OS/2 Boot Manager",
- 0xb: "Win95 FAT32",
- 0xc: "Win95 FAT32",
- 0xe: "Win95 FAT16",
- 0xf: "Win95 Ext'd",
- 0x10: "OPUS",
- 0x11: "Hidden FAT12",
- 0x12: "Compaq Setup",
- 0x14: "Hidden FAT16 <32M",
- 0x16: "Hidden FAT16",
- 0x17: "Hidden HPFS/NTFS",
- 0x18: "AST SmartSleep",
- 0x1b: "Hidden Win95 FAT32",
- 0x1c: "Hidden Win95 FAT32 (LBA)",
- 0x1e: "Hidden Win95 FAT16 (LBA)",
- 0x24: "NEC_DOS",
- 0x39: "Plan 9",
- 0x40: "Venix 80286",
- 0x41: "PPC_PReP Boot",
- 0x42: "SFS",
- 0x4d: "QNX4.x",
- 0x4e: "QNX4.x 2nd part",
- 0x4f: "QNX4.x 2nd part",
- 0x51: "Novell?",
- 0x52: "Microport",
- 0x63: "GNU HURD",
- 0x64: "Novell Netware 286",
- 0x65: "Novell Netware 386",
- 0x75: "PC/IX",
- 0x80: "Old MINIX",
- 0x81: "Linux/MINIX",
- 0x82: "Linux swap",
- 0x83: "Linux native",
- 0x84: "OS/2 hidden C:",
- 0x85: "Linux Extended",
- 0x86: "NTFS volume set",
- 0x87: "NTFS volume set",
- 0x8e: "Linux LVM",
- 0x93: "Amoeba",
- 0x94: "Amoeba BBT",
- 0x9f: "BSD/OS",
- 0xa0: "IBM Thinkpad hibernation",
- 0xa5: "BSD/386",
- 0xa6: "OpenBSD",
- 0xb7: "BSDI fs",
- 0xb8: "BSDI swap",
- 0xc7: "Syrinx",
- 0xdb: "CP/M",
- 0xde: "Dell Utility",
- 0xe1: "DOS access",
- 0xe3: "DOS R/O",
- 0xeb: "BEOS",
- 0xee: "EFI GPT",
- 0xef: "EFI (FAT-12/16/32)",
- 0xf2: "DOS secondary",
- 0xfd: "Linux RAID",
- 0xff: "BBT"
- }
+
diff --git a/raid.py b/raid.py
index 061209d44..949cff3cc 100644
--- a/raid.py
+++ b/raid.py
@@ -18,6 +18,7 @@ import parted
import isys
import os
import partitioning
+import partedUtils
from log import log
def scanForRaid(drives):
@@ -31,9 +32,9 @@ def scanForRaid(drives):
dev = parted.PedDevice.get("/tmp/" + d)
disk = parted.PedDisk.open(dev)
- raidParts = partitioning.get_raid_partitions(disk)
+ raidParts = partedUtils.get_raid_partitions(disk)
for part in raidParts:
- parts.append(partitioning.get_partition_name(part))
+ parts.append(partedUtils.get_partition_name(part))
except:
pass
diff --git a/textw/partition_text.py b/textw/partition_text.py
index b69a4cef2..cef11bd70 100644
--- a/textw/partition_text.py
+++ b/textw/partition_text.py
@@ -20,6 +20,7 @@ import string
import copy
import parted
from partitioning import *
+from partedUtils import *
from fsset import *
from autopart import *
from snack import *