Вопрос

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.

Это было полезно?

Решение

Errno 19 is listed as "No such device" (Linux), or "Operation not supported by device" (FreeBSD).

Looking at the source code for /dev/port in drivers/char/mem.c, especially the struct file_operations, you'll 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

This device doesn't support mmap. Only opening, seeking, reading and writing.

Другие советы

As has been pointed out, /dev/port isn't mmap-able. But seeing as how you're using python -- let's harness the true power of dynamic types! Why not create an mmap-like object which supports the same interface, but uses lseek underneath?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top