【发布时间】:2011-09-12 14:28:47
【问题描述】:
我正在编写一些代码来读取和解释 MBR,然后是用 fat32 格式化的笔式驱动器的 FAT,一切正常,我现在想在特定位置写入设备,所以在关闭设备后我已经打开阅读,我再试一次:
dr = file("/dev/disk5","r+")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 16] Resource busy: '/dev/disk5'
所以我关闭了所有内容,并使用 sudo (sudo python) 重新启动解释器,然后重试所有内容,结果相同。
如何才能打开设备进行写访问? 谢谢 编辑更多代码。
import sys,os
disk = file("/dev/disk5",'rb')
disk.seek(0)
sector_size=512
first_sector = disk.read(1*sector_size)
fat_part_list = (first_sector[-66:])[:64]
part1=fat_part_list[:16]
#more code here in order to analyse the first partition information in the MBR and get the required offset to actually read the partition itself.
#now for instance lets say I want to write here in sector 1 byte 0 ( so basically at seek(0).
disk.close()#close the device
disk = file("/dev/disk5","r+")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 16] Resource busy: '/dev/disk5'
其实你可以简单地把问题看成这样:
从来没有让格式化工作正常......
这一切似乎都是权限错误,但使用 sudo 运行解释器不会产生任何变化。
【问题讨论】:
-
您能否将您的代码修剪到演示问题的绝对(自包含)最小值,并将结果添加到您的问题中?