From owner-freebsd-hackers Sun Jun 2 13:56:27 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id NAA10524 for hackers-outgoing; Sun, 2 Jun 1996 13:56:27 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id NAA10509; Sun, 2 Jun 1996 13:56:19 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.12/8.6.9) id GAA06199; Mon, 3 Jun 1996 06:52:32 +1000 Date: Mon, 3 Jun 1996 06:52:32 +1000 From: Bruce Evans Message-Id: <199606022052.GAA06199@godzilla.zeta.org.au> To: bde@freebsd.org, pjf@cts.com Subject: Re: bugs Cc: dyson@freebsd.org, hackers@freebsd.org Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >| Subject: Re: bugs >| 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. >Sorry, I screwed up my example. Here's the real one: >------------------------- >#include >#include >#include >main() >{ > int fd = open("newfile", O_RDWR|O_CREAT|O_EXCL, 0660); > char *buf; > ftruncate(fd, 100); > buf = mmap(NULL, 100, PROT_WRITE, MAP_SHARED, fd, 0); > printf("%lx\n", buf); > strcpy(buf, "hi!"); >} >------------------------- >This doesn't work either. The ftruncate() appears not to work; the file >is still zero length after the program crashes. So perhaps the problem >is with ftruncate() and not mmap(). >This works on all of our 10 existing UNIX platforms except BSDI and >Linux. BSDI has the same problem with ftruncate, I think; Linux's >ftruncate works, but its mmap() appears to be totally broken, at least >in 1.2.13. The ftruncate() works if a prototype for ftruncate() is in scope or if the `length' arg to ftruncate has the correct type (off_t = long long). Otherwise the top 32 bits of the length are random. ftruncate() is prototyped in . You should also include before including . The above happens to work because bogusly includes . You should also include instead of except on old systems. The strcpy() doesn't work unless PROT_WRITE is changed to `PROT_READ | PROT_WRITE', and this isn't because strcpy() reads its target - `buf[0] = 1' fails in the same way. Bruce