# /*********************************************************** # * Name of program: # * Authors: # * Description: Starter code for Project 4 # **********************************************************/ import struct import sys import math # Seeking to an aribitrary position and reading in a set number of bytes. # This function unpacks bytes according to little endian disk format and # host order of running computer. # https://docs.python.org/3/library/struct.html def get_bytes(f, pos, numBytes): f.seek(pos) byte = f.read(numBytes) if (numBytes == 2): formatString = "H" elif (numBytes == 1): formatString = "B" elif (numBytes == 4): formatString = "i" else: raise Exception("Not implemented") return struct.unpack(ENDIAN_FORMAT+formatString, byte)[0] # the info command, prints general information about this image def info(): print("BPB_BytesPerSec is ", hex(BPB_BytesPerSec), BPB_BytesPerSec) print("BPB_SecPerClus is ", hex(BPB_SecPerClus), BPB_SecPerClus) print("BPB_RsvdSecCnt is ", hex(BPB_RsvdSecCnt), BPB_RsvdSecCnt) print("BPB_NumFATs is ", hex(BPB_NumFATs), BPB_NumFATs) print("BPB_FATSz32 is ", hex(BPB_FATSz32), BPB_FATSz32) return True def main(): # BPB Constants global BPB_BytesPerSec global BPB_SecPerClus global BPB_RsvdSecCnt global BPB_NumFATs global BPB_FATSz32 global ENDIAN_FORMAT f = open("fat32.img", 'rb') if sys.byteorder == 'little': ENDIAN_FORMAT = "<" else: ENDIAN_FORMAT = ">" BPB_BytesPerSec = get_bytes(f, 11, 2) BPB_SecPerClus = get_bytes(f, 13, 1) BPB_RsvdSecCnt = get_bytes(f, 14, 2) BPB_NumFATs = get_bytes(f, 16, 1) BPB_FATSz32 = get_bytes(f, 36, 4) #TODO: Get and seek to the root directory # Begin taking arguments while True: user_input = input("] ") user_input_list = user_input.split() command = user_input_list[0].strip() args = user_input_list[1:] #Start processing the commands if command == "info": info() #TODO: Finish this function elif command == "stat": print("Not yet implemented\n") elif command == "cd": print("Not yet implemented\n") elif command == "ls": print("Not yet implemented\n") elif command == "read": print("Not yet implemented\n") elif command == "volume": print("Not yet implemented\n") elif command == "deleted": print("Not yet implemented\n") elif command == "quit": print("Quitting.\n") f.close() quit() else: print("Unrecognized command\n") main()