python - 如何找到硬盘的最后一个扇区?
问题描述
我没有尝试通过将扇区数乘以 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()
解决方案
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)
推荐阅读
- angular - 如何在 angular6 项目中实现 bcrypt
- java - Java readObject/writeObject 可以保存/加载超类,那为什么需要read/writeExternal?
- c - 在 32 位保护模式下从 c 从文本模式切换到图形模式
- c# - 根据文件内容为文件生成id
- python - 根据最小阈值或置信区间,计算与另一组相比,给定集合中改进了多少样本?
- python - 使用python ffmpeg转换视频文件时无法保存元数据
- php - 如何使 \n 进入新行但恰好在当前行的开头下方开始?
- python-3.x - cmd窗口和关机未运行
- go - 如何使用变量访问结构?
- python - 高级列表理解:创建平均值