从 Linux 打开物理驱动器
我想在 Linux 上打开 SD 卡作为物理驱动器。 有些人认为: 创建文件(“PHYSICALDRIVE0”,...) 在 MS Windows 上。 我该怎么做呢?
I'd like to open SD card as physical drive on Linux.
Somethink like:
CreateFile("PHYSICALDRIVE0",...)
On MS Windows.
How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所有设备都表示为
/dev
目录下的文件。这些文件可以像常规文件一样打开,例如open(/dev/sdb, ...)
。类似磁盘的设备也在目录
/dev/disk/by-id/
、/dev/disk/by-path
和/dev/ 中进行符号链接disk/by-uuid
,这使得更容易找到匹配的设备文件。All devices are represented as files under the
/dev
directory. These files can be opened exactly like regular files, e.g.open(/dev/sdb, ...)
.Disk-like devices are also symlinked in the directories
/dev/disk/by-id/
,/dev/disk/by-path
, and/dev/disk/by-uuid
, which makes it much easier to find to matching device file.输入 df,列出所有已安装或已卸载的文件系统。一旦你知道了它的地址(Linux 中的所有内容都是一个文件,因此它看起来像 /dev/sda# 或类似的东西),你可以使用挂载命令挂载它:
mount /path/to/drive /folder/to/mount /到
Type df, to list all your filesystems mounted or unmounted. Once you know its address(everything in Linux is a file, so it will look like /dev/sda# or something like that) you can mount it with the mount command:
mount /path/to/drive /folder/to/mount/to
您打开块设备特殊文件(通常类似于 /dev/sdb),然后您可以从中读取/写入块。
接口没有明确记录,没有 block(4) 手册页是一个错误。
sd(4) 手册页确实有一点帮助。那里描述的 ioctl 可能也适用于(某些)其他块设备。
如今,几乎所有块设备都显示为“scsi 驱动器”,无论它们实际上是否由 scsi 连接。这包括 USB 和(大多数)ATA 驱动器。
不过,找到合适的设备来打开可能是问题的一个重要部分,特别是如果您有热插拔设备。您也许可以询问 /sys 中的某些内容以找出其中有哪些设备。
You open the block device special file (typically something like /dev/sdb) and then you can read/write blocks from it.
The interface is not clearly documented, it is a bug that there is no block(4) man page.
The sd(4) man page does help a bit though. The ioctls described there are probably valid for (some) other block devices as well.
Nowadays nearly all block devices appear as a "scsi drive" regardless of whether they are actually attached by scsi or not. This includes USB and (most) ATA drives.
Finding the right device to open may be a big part of the problem though, particularly if you have hotplug devices. You might be able to interrogate some things in /sys to find out what devices there are.