Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jun 2006 18:57:41 +0400
From:      Stanislav Sedov <stas@310.ru>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Simple question about mmap() system call
Message-ID:  <20060623185741.71a441ec.stas@310.ru>
In-Reply-To: <20060623173723.H39481@atlantis.atlantis.dp.ua>
References:  <20060623173723.H39481@atlantis.atlantis.dp.ua>

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

On Fri, 23 Jun 2006 17:47:57 +0300 (EEST)
Dmitry Pryanishnikov <dmitry@atlantis.dp.ua> wrote:

> Hello!
>=20
>   I'm writing an utility that should examine some bytes of a large file
> and modify them - that't all. I've decided to mmap() the file:
>=20
>      void *diskp;
>=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, 512,
>          PROT_READ | PROT_WRITE, 0, fd, 0)) =3D=3D MAP_FAILED)
>              err(EX_IOERR, "Can't mmap() file");
>=20
>      printf("<%c>\n",* (char *)diskp);
>      * (char *)diskp =3D '!';
>=20
>      if (msync(diskp, 0, MS_SYNC) || close(fd))
>          err(EX_IOERR, "Error closing file");
>=20
> All proceeds w/o errors with the sample (2 bytes long) file, printf()
> shows actual first byte of my file. But modification doesn't get written =
back=20
> to the disk, file contents are unchanged after execution of my code. I'm =
sure=20
> I'm overlooking something very basic and stupid, but can't find what exac=
tly.
>=20

munmap(2)?

--=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=_Fri__23_Jun_2006_18_57_41_+0400_x5_m2pwdgUT0FRbx
Content-Type: application/pgp-signature

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

iD8DBQFEnAFlK/VZk+smlYERAvvvAJ4pCwXLpEZTqyEzKzWh30Nuw0OQNACdEVPI
yO+PHwYDOS/u+pdllpPvaJk=
=gULp
-----END PGP SIGNATURE-----

--Signature=_Fri__23_Jun_2006_18_57_41_+0400_x5_m2pwdgUT0FRbx--



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