From owner-freebsd-hackers  Sun Jun  2 00:33:15 1996
Return-Path: owner-hackers
Received: (from root@localhost)
          by freefall.freebsd.org (8.7.5/8.7.3) id AAA07700
          for hackers-outgoing; Sun, 2 Jun 1996 00:33:15 -0700 (PDT)
Received: from harbor.silcom.com (harbor.silcom.com [199.201.128.1])
          by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id AAA07695;
          Sun, 2 Jun 1996 00:33:13 -0700 (PDT)
Received: from beach.silcom.com (root@beach.silcom.com [199.201.128.19]) by harbor.silcom.com (8.6.12/8.6.9) with ESMTP id AAA08986; Sun, 2 Jun 1996 00:34:35 -0700
Received: from zoof.cts.com by beach.silcom.com (8.6.12/SMI-4.1)
	id AAA30459; Sun, 2 Jun 1996 00:33:19 -0700
Received: from zoof.cts.com ([127.0.0.1]) by zoof.cts.com
          (post.office MTA v2.0 pre-alpha ID# 0-1001) with SMTP id AAA158;
          Sun, 2 Jun 1996 00:28:28 -0700
From: pjf@cts.com (Paul Falstad)
Message-Id: <9606020028.ZM156@zoof>
Date: Sun, 2 Jun 1996 00:28:28 -0700
In-Reply-To: Bruce Evans <bde@zeta.org.au>
        "Re: bugs" (Jun  2,  3:43pm)
In-Reply-To: "John S. Dyson" <toor@dyson.iquest.net>
        "Re: bugs" (Jun  2,  1:00am)
References: <199606020543.PAA12662@godzilla.zeta.org.au> 
	<199606020600.BAA00232@dyson.iquest.net>
X-Face: 71i.]_O;=~3NUn@{y'aiw`u/:pGg(SVt6Nmf")$[Uly'p"3qt6-59>6z=!zV|h>&0h0q!K/
 [0A|s7Wa:He\e-SK&B~</P4v@}gLG):P/|W/58k`Fh;o.LCca-19$t
X-Anagram: Salad, Flat Up
X-Shakespearean-Insult: Thou dissembling motley-minded skainsmate!
X-Face-Info: Alien from the Far Side
Reply-To: Paul Falstad <pjf@cts.com>
To: bde@freebsd.org
Subject: Re: bugs
Cc: hackers@freebsd.org
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Sender: owner-hackers@freebsd.org
X-Loop: FreeBSD.org
Precedence: bulk

Bruce Evans says:
| Subject: Re: bugs
| >Hi, here are some problems I encountered while trying to port na
| >application to FreeBSD.  I have workarounds for all of them, but
| >I thought you might like to know.
| 
| Which version of FreeBSD? :-)

sorry..  2.1 off the jan '96 cd from cdrom.com.

| This is more or less fixed.  setgroups(0, any) now returns EINVAL.  It

well, that's better I guess.  :-)  It's not compatible with many other
systems though.  But setting the group set to nothing is pretty weird I
admit.

| previously gave no groups or something silly like that.  The program
| worked right with setgroups(1, gr) (gr[0] = getegid()).

That was my workaround.  :-)  We should probably just use that
"workaround" everywhere, since it seems like the correct way to
express what we want to happen.

John S. Dyson says:
| 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 <stdio.h>
#include <sys/mman.h>
#include <sys/file.h>

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.


-- 
Paul Falstad, pjf@cts.com, 805-966-4935, http://www.ttinet.com/pjf/
    work: pf@software.com, 805-882-2470, http://www.software.com

I bought my brother some gift-wrap for Christmas.  I took it to
the Gift Wrap department and told them to wrap it, but in a
different print so he would know when to stop unwrapping.