From owner-freebsd-hackers Sun Jun 2 15:24:58 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id PAA14203 for hackers-outgoing; Sun, 2 Jun 1996 15:24:58 -0700 (PDT) Received: from zen.nash.org ([204.95.47.72]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id PAA14197; Sun, 2 Jun 1996 15:24:53 -0700 (PDT) Received: (from alex@localhost) by zen.nash.org (8.7.5/8.6.12) id RAA23224; Sun, 2 Jun 1996 17:25:42 -0500 (CDT) Date: Sun, 2 Jun 1996 17:25:42 -0500 (CDT) Message-Id: <199606022225.RAA23224@zen.nash.org> From: Alex Nash To: pjf@cts.com Cc: bde@freebsd.org, dyson@freebsd.org, hackers@freebsd.org Subject: Re: bugs Reply-to: alex@freebsd.org Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >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. TRUNCATE(2) FreeBSD Programmer's Manual TRUNCATE(2) [...] DESCRIPTION Truncate() causes the file named by path or referenced by fd to be trun- cated to at most length bytes in size. ^^^^^^^ Richard Stevens (APUE) has the following notes on truncate (see page 92): These two functions are provided by SVR4 and 4.3+BSD. They are not part of POSIX.1 or XPG3. SVR4 truncates or extends a file. 4.3+BSD only truncates a file with these functions -- they can't be used to extend a file. As far as mmap is concerned, you cannot write beyond 'len' bytes as specified in the call to mmap. (In reality, under FreeBSD 2.1R you can write up to the next 4K page and get away with it. Linux 1.2.13 is even less stringent.) Alex