将Windows CDROM驱动器视为阻止文件? [英] Treat Windows CDROM Drive as Block File?

查看:46
本文介绍了将Windows CDROM驱动器视为阻止文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python模块( python-dvdvideo 准确地说)来克隆ISO映像.如果提供的类将文件路径传递给计算机上已经存在的ISO文件,则提供的类可以正常工作,但是如果我尝试将其传递给CDROM驱动器的驱动器号,则它将引发异常.

I'm attempting to use a Python module (python-dvdvideo to be exact) to clone an ISO image. The provided class works fine if I pass it a filepath to an ISO file that is already on my computer, but it throws an exception if I attempt to pass it the drive letter of my CDROM drive instead.

在快速检查了库的代码之后,我确定该类期望使用常规文件还是块特殊设备文件,如下所示:

After quickly inspecting the library's code, I determined that the class is expecting either a regular file or a block special device file, as shown here:

def __init__(self, filename):
    s = os.stat(filename)
        if stat.S_ISREG(s.st_mode):
            f = self.File(filename)
        elif stat.S_ISBLK(s.st_mode):
            f = DvdCssFile(filename)
        else:
            raise RuntimeError

这引出我一个问题:是否可以将Windows CDROM驱动器视为其中一种?我模糊地熟悉Linux在这方面的工作方式(它将CDROM驱动器视为/dev/*下的块设备文件),而不是Windows看到驱动器的方式.

This leads me to my question: Is there a way to treat a Windows CDROM drive as either of these? I'm vaguely familiar with how Linux works in this regard (it treats a CDROM drive as a block device file under /dev/*), but not with how Windows sees drives.

推荐答案

在尝试做类似的事情时,我发现此线程有用.根据那里的信息(以及这里),我创建了这个,向您展示了基础知识:

While trying to do something similar I found this thread useful. Based on the information there (and also here) I created this, which shows you the basics:

import os

driveName = "D"

# Get Window raw block device name from logical drive
# Adapted from https://stackoverflow.com/a/6523306/1209004
deviceName = "\\\\.\\" + driveName + ":" 

# Open as file object
# Adapted from https://stackoverflow.com/q/7135398/1209004
d = os.fdopen(os.open(deviceName, os.O_RDONLY|os.O_BINARY), 'rb+')

# Read data
data = d.read()

# Close file object
d.close()

# Write data to an output file
fOut = open('data.bin','wb')
fOut.write(data)
fOut.close()

我注意到的一件事是,与像IsoBuster这样的专用成像工具相比,以这种方式读取的数据可能是不完整的.此外,访问增强型"音频CD上的数据会话似乎也不起作用.因此,请谨慎使用.

One thing I noted is that compared against dedicated imaging tools like IsoBuster the data read in this way may be incomplete. Also, it doesn't appear to work to access data sessions on an 'enhanced' audio CD. So use with caution.

这篇关于将Windows CDROM驱动器视为阻止文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆