Python 如何找到硬盘的最后一个扇区?

Python 如何找到硬盘的最后一个扇区?,python,python-3.x,file,Python,Python 3.x,File,我没有试图用扇区数乘以10来找到最后一个扇区。我试图通过增加1来找到它,但是系统很累,花费了很多时间。我不想过滤掉ready命令的输出 如何找到气缸、缸盖和扇区的数量。我想我将通过从chs系统转换到lba系统来获得扇区数 import os def main(): s=1 if os.name == "nt": while True: if read_sector(r"\\.\physicaldrive0",s)=='':

我没有试图用扇区数乘以10来找到最后一个扇区。我试图通过增加1来找到它,但是系统很累,花费了很多时间。我不想过滤掉ready命令的输出

如何找到气缸、缸盖和扇区的数量。我想我将通过从chs系统转换到lba系统来获得扇区数

import os
def main():
    s=1
    if os.name == "nt":
        while True:
            if read_sector(r"\\.\physicaldrive0",s)=='':
                break
            else:
                s=s*10
            print(s)
    else:
        while True:
            if read_sector("/dev/sda",s)=='':
                break
            else:
                s=s*10
            print(s)
def read_sector(disk, sector_no=0):
    f = open(disk, 'rb')
    f.seek(sector_no * 1)
    read = f.read(1)
    return read

if __name__ == "__main__":
    main()

import os
def main():
    s=0
    if os.name == "nt":
        while True:
            if read_sector(r"\\.\physicaldrive0",s)=='':
                break
            else:
                s=s+1
            print(s)
    else:
        while True:
            if read_sector("/dev/sda",s)=='':
                break
            else:
                s=s+1
            print(s)
def read_sector(disk, sector_no=0):
    f = open(disk, 'rb')
    f.seek(sector_no * 1)
    read = f.read(1)
    return read

if __name__ == "__main__":
    main()
import os
def end_sector(disk):
    os.system("fdisk -l %s >fdisk.lst"%disk)
    with open("fdisk.lst") as file:
        dosya=file.read()
        dosya=dosya.split()
        j=0
        for i in dosya:
            j=j+1
        for i in range(j):
            if dosya[i]=="sektör":
                max_sector=int(dosya[i-1])
        for i in range(j):
            if dosya[i]=="=" and dosya[i-1]==dosya[i+1]:
                sector_size=int(dosya[i+1])
    return max_sector,sector_size
dizi=end_sector("/dev/sdb")
print(dizi)