Re: mmap on a device returns ENODEV

Linus Torvalds (torvalds@transmeta.com)
Wed, 8 Dec 1999 09:07:51 -0800 (PST)


On Wed, 8 Dec 1999, Reid Spencer wrote:
>
> I have discovered in the usual way (looking at the code) that it seems
> the 2.2 kernel doesn't support mmap on devices. In the do_mmap function
> (mm/mmap.c:247), ENODEV is returned if the file doesn't support the mmap
> operation.

Yes. This should finally be a thing of the past soon: one of the issues is
that the mmap() code requires the page cache, and the page cache didn't
use to handle the case of large devices correctly, and as such couldn't be
used - and raw devices for that reason had their very own special code.

> A) Has this been implemented anytime after my kernel release 2.2.5-15?

It's not worth even trying in the 2.2.x series.

> B) Has anyone even thought about implementing this?

Yes. It's still not done in 2.3.x, but in 2.3.x it should be trivial to
do:
- make raw devices (well, the "pseudo-raw" ones that Linux uses) use
"generic_file_read()" and "generic_file_write()"
- implement readpage and writepage for them (simple: you should be able
to use the generic_block_readpage() and generic_block_writepage()
functionality trivially, by just supplying a 1:1 block_map() function.
- test HEAVILY with fsck/mkfs etc, to make sure nothing broke ;)

> C) Is there a technical reason why block devices can't be mmap'd?

Not any more. But see above.

> D) Would someone far more knowledgeable than me like to step up to
> implementing it?
> E) Would someone far more knowledgeable than me provide some tips on how
> it might be implemented?

This is one of those "small details" that I've wanted for a long time.
I've never had the time to actually do it, even though it should be
trivial. The sucker^H^H^H^H^H^Hperson to ask is probably Alex Viro or Ingo
Molnar, and see if you can entice them into doing it - they both know this
area forwards and backwards. Or it could be a great project for somebody
willing to learn and not too afraid of messing his disks over in case of
bugs..

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/