Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jun 1996 01:00:09 -0500 (EST)
From:      "John S. Dyson" <toor@dyson.iquest.net>
To:        bde@zeta.org.au (Bruce Evans)
Cc:        bde@freebsd.org, pjf@cts.com, dyson@freebsd.org, hackers@freebsd.org
Subject:   Re: bugs
Message-ID:  <199606020600.BAA00232@dyson.iquest.net>
In-Reply-To: <199606020543.PAA12662@godzilla.zeta.org.au> from "Bruce Evans" at Jun 2, 96 03:43:37 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> Which version of FreeBSD? :-)
> 
> >(1) mmap doesn't seem to work for extending a file.  Here's a sample:
> 
> >------------------------------------------
> >#include <stdio.h>
> >#include <sys/mman.h>
> >#include <sys/file.h>
> 
> >main()
> >{
> >  int fd = open("newfile", O_RDWR|O_CREAT|O_EXCL, 0660);
> >  char *buf = mmap(NULL, 100, PROT_WRITE, MAP_SHARED, fd, 0);
> >  printf("%lx\n", buf);
> >  strcpy(buf, "hi!");
> >}
> >------------------------------------------
> 
> >This test program dies when trying to do the strcpy.  What we're
> >trying to do is create a file using mmap() instead of write().
> >(This is in BSDI too.)
> 
> I don't know much about mmap.  This still seems to be broken.  It works if
> the file already exists and is nonempty and is opened in non-exclusive
> mode.  I tried a file of length 512.  Setting buf[4095] to 1 didn't trap
> but the file wasn't extended.  Setting buf[4096] to 1 trapped.
> 
MMAP doesn't extend files, AFAIK it doesn't on many (if not most
other OSes.)  To set the length of the file you need to do an ftruncate.
After that, then blocks will be allocated as needed.

John




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