Changes

Jump to: navigation, search

OPS435 Python Assignment 2 C

1,184 bytes added, 01:09, 3 April 2018
Module and function documentation
== Module and function documentation ==
Use the python docstring to provide embedded documentation for the module "partinfo.py" and the functions in it.
 
== Sample Python codes ==
The following sample python code reads and display primary partition on a given physical storage device with MBR partition scheme:
<code>
#! /usr/bin/python
# read and display partition info
# on a physical disk or disk image
#
import struct
import sys
 
# ask the user for disk file name
# if not provided on the command line
no_arg = len(sys.argv) # one is for command only
 
if no_arg <= 1:
diskfile=raw_input("Disk file name please: ")
else:
diskfile=sys.argv[1]
 
# verify that the file exist
# notify when file is missing
 
try:
f=open(diskfile, 'rb')
f.seek(446)
 
ptt = f.read(64)
pte1 = ptt[0:16]
pte2 = ptt[16:32]
pte3 = ptt[32:48]
pte4 = ptt[48:64]
tfmt='<b3sb3sLL'
 
t1 = struct.unpack(tfmt,pte1)
t2 = struct.unpack(tfmt,pte2)
t3 = struct.unpack(tfmt,pte3)
t4 = struct.unpack(tfmt,pte4)
print "partition #","boot","start","length","type"
print "partition 1:",t1[0],t1[4], t1[5], t1[2]
print "partition 2:",t2[0],t2[4], t2[5], t2[2]
print "partition 3:",t3[0], t3[4], t3[5], t3[2]
print "partition 4:",t4[0], t4[4], t4[5], t4[2]
 
except IOError:
print "File missing."
</code>
= Resources =
1,760
edits

Navigation menu