🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #13001

creating file space via mmap

#13001
From: Don Faulkner
Date: Wed, 17 May 1989 13:55
47 lines
2270 bytes
I've been working with mmap to create file space.  There are some problems
in letting mmap set the size of the file.

>From "man mmap":
     It should be noted that the system will always zero-fill any
     partial  pages at the end of an object.  Further, the system
     will never write out any modified portions of the last  page
     of  an object which are beyond its end.  References to whole
     pages following the end of an  object  will  result  in  the
     delivery  of  a  SIGBUS  signal.  SIGBUS signals may also be
     delivered on various filesystem conditions, including  quota
     exceeded errors.


(the System Services Overview chapter "Memory Management" doesn't
add any info for my question ...)

So --- you can't just "mmap" with a "len" greater than the length
of the file, and let it grow ...

Experimentally, the following DOES work:

fd = open ("file", O_RDWR | O_CREAT, 0666)
lseek (fd, 10000000, L_SET)  /*  max file size reasonable  */
write (fd, "", 1)
This will create a file with an enormous hole.
Then, you can mmap with len=10000000
if you address and write into the middle of a file, those blocks
touched get allocated and filled in automagically ...
(I'm trying to avoid actually POPULATING a huge block if it's not needed...)

Afterwards, you could open a new file, and copy only the elements that
were actually created...

This DOES work; the question is:  can one DEPEND on it working?
Is there a better way?
--

 Don Faulkner                                       
 Building 1, Room 803
 Harvard University, School of Public Health
 665 Huntington Avenue
 Boston, MA  02115

 ARPA:      faulkner%jmullins@harvard.harvard.edu                
 BITNET:    faulkner@harvard
 Telephone: (617) 732-2297
Technical Details
Message-ID: <FAULKNER.89May17095518@jmullins.harvard.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!husc6!rice!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!husc6!rice!sun-spots-request
From: faulkner%jmullins@husc6.harvard.edu (Don Faulkner)
Newsgroups: comp.sys.sun
Subject: creating file space via mmap
Keywords: SunOS
Message-ID: <FAULKNER.89May17095518@jmullins.harvard.edu>
Date: 17 May 89 13:55:18 GMT
Sender: usenet@rice.edu
Organization: Harvard University
Lines: 47
Approved: Sun-Spots@rice.edu
X-Sun-Spots-Digest: Volume 7, Issue 299, message 7 of 13