mmap() vs. character special file

Dmitry Pryanishnikov dmitry at atlantis.dp.ua
Fri Jun 23 22:27:12 UTC 2006


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.

Sincerely, Dmitry
-- 
Atlantis ISP, System Administrator
e-mail:  dmitry at atlantis.dp.ua
nic-hdl: LYNX-RIPE


More information about the freebsd-hackers mailing list