198
edits
Changes
→Overview
[[Category:OPS435-Python]][[Category:rchan]]
= Overview =
In order to use a physical storage device (e.g. Hard Disk, USB Flash memeorymemory, SSD, etc.), the first step is to create partition(s) on it. There many different ways to partition a physical storage device. The two most common partition schemes used on Intel based micro-computer systems are MBR and GPT. Detail about the MBR partition scheme can be found [https://en.wikipedia.org/wiki/Master_boot_record here], and GPT partition scheme can be found at [https://en.wikipedia.org/wiki/GUID_Partition_Table].
On most Linux systems, fdisk or parted can be used to create, view, and manage MBR and GPT partitionpartitions.
The task for you in this assignment is to write a python module named "partinfo.py", which contains at least three functions: part_scheme(), mbr_part(), gpt_part(), which can be used to retrieve partition information from a specified physical storage device.
= Instruction =
== Module name, function names, function parameter(s) and return values ==
Name your python module as "partinfo.py". The module should contains at least the following 3 functions:
* <code>part_scheme() </code> - which when called with a valid physical storage device name, will return the partition scheme used on the device. The return returned value should only be
** None - no valid partition scheme found on the device
** MBR - MBR partitions is/are found on the device
** GPT - GUID partitions is/are found on the device
* <code>mbr_part() </code> - which when called with a valid physical storage device name, will return all the partitions (primary, extended, and logical) found on the device. Each partition information return returned must contain the following fields:
** partition number
** partition flag (bootable or not)
** start sector number (in LBA mode)
** size of partition in sectors
* <code>gpt_part() </code> - which when called with a valid physical storage device name, will return all the partitions found on the device. Each partition information return returned must contain the following fields:
** Partition type GUID
** Unique partition GUID
== Sample Python codes ==
The following sample python code reads and display displays primary partition partitions on a given physical storage device with MBR partition scheme:. Please note that this python script does not check for extended partition and does not try to extract the information for logical partitions even they exist.<codepre>
#! /usr/bin/python
# read and display primary partition info
# on a physical disk or disk image
#
except IOError:
print "File missing."
</codepre>
= Resources =