【问题标题】:How do I find the last sector of harddisk?如何找到硬盘的最后一个扇区?
【发布时间】:2020-02-11 07:24:48
【问题描述】:

我没有尝试通过将扇区数乘以 10 来找到最后一个扇区。我试图通过增加 1 来找到它,但是系统非常疲倦并且花费了很多时间。我不想过滤掉就绪命令的输出。

如何找到柱面、磁头和扇区的数量。我想我会通过从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()

【问题讨论】:

    标签: python python-3.x file


    【解决方案1】:
    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)
    

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 2013-07-06
      • 2013-03-18
      • 2013-07-15
      • 1970-01-01
      • 2021-09-10
      • 2020-06-12
      • 2011-03-20
      • 2011-03-27
      相关资源
      最近更新 更多