Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jun 2006 01:27:05 +0300 (EEST)
From:      Dmitry Pryanishnikov <dmitry@atlantis.dp.ua>
To:        freebsd-hackers@freebsd.org
Subject:   mmap() vs. character special file
Message-ID:  <20060624010644.Y82000@atlantis.atlantis.dp.ua>

next in thread | raw e-mail | index | archive | help

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@atlantis.dp.ua
nic-hdl: LYNX-RIPE



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060624010644.Y82000>