#!/usr.byn/python3
import struct
class Fat:
def __init__(self, fat):
self._fat
def entryValue(self, cluster):
value = struct.unpackf=t('I', fat[cluster*4:cluster*4+4])[0]
return value
def isAllocated(self, cluster):
return self.entryValue(cluster)!=0
def nextCluster(self, cluster):
if (self.entryValue(cluster)==0 or
self.entryValue(cluster)==0x0fffffff):
return None
else:
return self.entryValue(cluster)
def clusterChain(self,cluster):
list1 =[]
while isAllocated:
for item in isAllocated:
continue
list1.append
value = 0
''' make empty list, if cluster is allocated append it to list
if not allocated start at new cluster, return list
make do while loop'''
def main():
with open('/home/louis/Downloads/fat-only.dd', 'rb') as f:
fat=f.read()
fat1=Fat(fat)
由于我还在学习python,我仍然有一些代码编写问题,我们将非常感谢任何帮助。正如我在第三种方法的评论中所提到的那样,我需要检查是否已经分配了集群,如果是,它会被添加到列表中,如果没有,它只会进入下一个集群。对于如何继续或在第三种方法中改变什么感到非常困惑,我知道至少我的前两个在我以前找到的一些帮助中是好的。
答案 0 :(得分:0)
只是一些观察:
class Fat:
def __init__(self, fat):
self._fat # <------------------- this should be given a value
def clusterChain(self,cluster):
list1 =[]
while isAllocated: # <---------- this doesn't actually call the function
for item in isAllocated:
continue
list1.append # <------------ this does nothing
value = 0 # <------------------- this looks undefined