Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jun 2006 10:18:09 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Dmitry Pryanishnikov <dmitry@atlantis.dp.ua>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Simple question about mmap() system call
Message-ID:  <20060623151809.GF95588@dan.emsphone.com>
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
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



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