Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jun 2006 04:06:03 +0400
From:      Stanislav Sedov <stas@310.ru>
To:        freebsd-hackers@freebsd.org
Subject:   Re: mmap() vs. character special file
Message-ID:  <20060624040603.594c44bc.stas@310.ru>
In-Reply-To: <20060624010644.Y82000@atlantis.atlantis.dp.ua>
References:  <20060624010644.Y82000@atlantis.atlantis.dp.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
--Signature=_Sat__24_Jun_2006_04_06_03_+0400_1DiBAEdzRAxbo6rp
Content-Type: text/plain; charset=KOI8-R
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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

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

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 -=20
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.

--=20
Stanislav Sedov         MBSD labs, Inc.         <ssedov@mbsd.msk.ru>
=F2=CF=D3=D3=C9=D1, =ED=CF=D3=CB=D7=C1		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

--Signature=_Sat__24_Jun_2006_04_06_03_+0400_1DiBAEdzRAxbo6rp
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (FreeBSD)

iD8DBQFEnIHrK/VZk+smlYERAv+0AJ9qLE15svuMk21Xz5WXMJBbtlekyQCfSvFD
6MsdGa0ghFgxEJll0dJQCaA=
=UduD
-----END PGP SIGNATURE-----

--Signature=_Sat__24_Jun_2006_04_06_03_+0400_1DiBAEdzRAxbo6rp--



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