Python mmap /dev/端口
是否可以 mmap /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
>>>
我已经能够使用相同的选项映射常规文件。
Is it possible to mmap /dev/port? I'm getting 'No such device' when I try.
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
>>>
I've been able to mmap a regular file with the same options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Errno 19 被列为“无此类设备”(Linux) 或“设备不支持操作”(FreeBSD)。
查看
drivers/char/mem.c
中/dev/port
的源代码,特别是struct file_operations
,您会参见:此设备不支持映射。只有打开、寻找、阅读和写作。
Errno 19 is listed as "No such device" (Linux), or "Operation not supported by device" (FreeBSD).
Looking at the source code for
/dev/port
indrivers/char/mem.c
, especially thestruct file_operations
, you'll see:This device doesn't support mmap. Only opening, seeking, reading and writing.
正如已经指出的,
/dev/port
不支持mmap
。但是看看您如何使用 python —— 让我们利用动态类型的真正力量!为什么不创建一个类似mmap
的对象,它支持相同的接口,但在底层使用lseek
呢?As has been pointed out,
/dev/port
isn'tmmap
-able. But seeing as how you're using python -- let's harness the true power of dynamic types! Why not create anmmap
-like object which supports the same interface, but useslseek
underneath?