是否可以映射/dev/port?当我尝试时,我得到“没有这样的设备”。
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import mmap
>>> os.open('/dev/port', os.O_RDWR|os.O_NDELAY)
3
>>> mapfd = mmap.mmap(3, 0xfff)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
mmap.error: [Errno 19] No such device
>>>
我已经能够使用相同的选项映射常规文件。
最佳答案
Errno 19 被列为“没有此类设备”(Linux) 或“设备不支持操作”(FreeBSD)。
查看drivers/char/mem.c
中/dev/port
的源代码,特别是struct file_operations
,你会发现see :
770 #ifdef CONFIG_DEVPORT
771 static const struct file_operations port_fops = {
772 .llseek = memory_lseek,
773 .read = read_port,
774 .write = write_port,
775 .open = open_port,
776 };
777 #endif
该设备不支持 mmap。只有打开、寻找、阅读和写作。
关于Python mmap/dev/端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379329/