From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 23 14:58:18 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B8A9416A494 for ; Fri, 23 Jun 2006 14:58:18 +0000 (UTC) (envelope-from stas@310.ru) Received: from com1.ht-systems.ru (com1.ht-systems.ru [83.97.104.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id E367C43D45 for ; Fri, 23 Jun 2006 14:58:17 +0000 (GMT) (envelope-from stas@310.ru) Received: from [80.250.160.136] (helo=fonon.realnet) by com1.ht-systems.ru with esmtpa (Exim 4.62) (envelope-from ) id 1Ftn5W-0001We-0L for freebsd-hackers@freebsd.org; Fri, 23 Jun 2006 18:56:50 +0400 Received: from fonon.realnet (localhost [127.0.0.1]) by fonon.realnet (8.13.6/8.13.6) with ESMTP id k5NEvg05018585 for ; Fri, 23 Jun 2006 18:57:42 +0400 (MSD) (envelope-from stas@fonon.realnet) Received: (from stas@localhost) by fonon.realnet (8.13.6/8.13.6/Submit) id k5NEvfNI018584; Fri, 23 Jun 2006 18:57:41 +0400 (MSD) (envelope-from stas) Date: Fri, 23 Jun 2006 18:57:41 +0400 From: Stanislav Sedov To: freebsd-hackers@freebsd.org Message-Id: <20060623185741.71a441ec.stas@310.ru> In-Reply-To: <20060623173723.H39481@atlantis.atlantis.dp.ua> References: <20060623173723.H39481@atlantis.atlantis.dp.ua> Organization: MBSD labs, Inc. X-Mailer: carrier-pigeon X-Operating-System: FreeBSD Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="PGP-SHA1"; boundary="Signature=_Fri__23_Jun_2006_18_57_41_+0400_x5_m2pwdgUT0FRbx" X-Spam-Flag: SKIP X-Spam-Yversion: Spamooborona 1.5.2 Subject: Re: Simple question about mmap() system call X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jun 2006 14:58:18 -0000 --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 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. =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--