mmap() vs. character special file

Stanislav Sedov stas at 310.ru
Sat Jun 24 00:06:55 UTC 2006


On Sat, 24 Jun 2006 01:27:05 +0300 (EEST)
Dmitry Pryanishnikov <dmitry at atlantis.dp.ua> wrote:

> Hello!
> 
>   mmap(2) manpage has the following title:
> 
> NAME
>       mmap -- allocate memory, or map files or devices into memory
> 
> I'm curious about mmap()ing devices (particularly, HDD slices). The manpage
> mentions character special files only once:
> 
>       [EINVAL]           MAP_ANON has not been specified and fd did not refer-
>                          ence a regular or character special file.
> 
> So it looks like one should be able to mmap() a character special file (w/o 
> MAP_ANON, of course). However, if I try to issue:
> 
>      if ((fd=open(argv[1], O_RDWR)) == -1)
>          err(EX_NOINPUT, "Can't open %s for readind and writing", argv[1]);
> 
>      if ((diskp=mmap(NULL, label_offset + sizeof (struct disklabel),
>          PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED)
>              err(EX_IOERR, "Can't mmap() file");
> 
> against /dev/adXsY (adXsY and adXsYZ are _not_ mounted), I'm getting EINVAL
> from mmap(). Is mmap()ping a disk slice/partition impossible by design, or it
> just isn't implemented yet? IMHO manpage doesn't reply to this question.
> 

You cannot mmap ata devices (as well as scsi ones), since mmap functions
was not implemented. Actually, only few devices have such support
(e.g. drm, bktr).

mmap requires device to return pointer to contigues memory range - 
drm, for example, returns pointer to physical memory of the graphical
adapter.

Implementing mmap for disk devices involves complicated VM intercations,
since you cannot simply return pointer to "physical" memory. Actually,
implementing mmap, IMHO, doesn't worth efforts to do this.

-- 
Stanislav Sedov         MBSD labs, Inc.         <ssedov at mbsd.msk.ru>
Россия, Москва		http://mbsd.msk.ru

--------------------------------------------------------------------
If the facts don't fit the theory, change the facts.  -- A. Einstein
--------------------------------------------------------------------
PGP fingerprint:  F21E D6CC 5626 9609 6CE2  A385 2BF5 5993 EB26 9581
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20060624/b853092f/attachment.pgp


More information about the freebsd-hackers mailing list