From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 23 15:18: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 1EB7C16A4C2 for ; Fri, 23 Jun 2006 15:18:18 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3D78E43D72 for ; Fri, 23 Jun 2006 15:18:15 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.4) id k5NFI9SH069116; Fri, 23 Jun 2006 10:18:09 -0500 (CDT) (envelope-from dan) Date: Fri, 23 Jun 2006 10:18:09 -0500 From: Dan Nelson To: Dmitry Pryanishnikov Message-ID: <20060623151809.GF95588@dan.emsphone.com> References: <20060623173723.H39481@atlantis.atlantis.dp.ua> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060623173723.H39481@atlantis.atlantis.dp.ua> X-OS: FreeBSD 5.5-PRERELEASE X-message-flag: Outlook Error User-Agent: Mutt/1.5.11 Cc: freebsd-hackers@freebsd.org 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 15:18:18 -0000 In the last episode (Jun 23), Dmitry Pryanishnikov said: > 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: > > void *diskp; > > 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, 512, > PROT_READ | PROT_WRITE, 0, fd, 0)) == MAP_FAILED) > err(EX_IOERR, "Can't mmap() file"); Try adding MAP_SHARED. mmap defaults to private mappings, which means you changes don't get synched back to disk. I wonder how many programs would break if the mmap syscall returned an error if neither MAP_PRIVATE or MAP_SHARED were set... -- Dan Nelson dnelson@allantgroup.com