Re: REQUEST for /proc/cpuinfo copies & a baby bugbear :o(

Matthew Wilcox (Matthew.Wilcox@genedata.com)
Sun, 27 Sep 1998 23:56:46 +0200


> From: Tim Smith <tzs@tzs.net>
> Date: Sun, 27 Sep 1998 09:57:14 -0700 (PDT)
> Subject: Re: What's wrong with MAP_SHARED|MAP_ANONYMOUS?
>
> On 27 Sep 1998, Andi Kleen wrote:
> > > Would it work if you create a scratch file, open it, unlink it, fill it
> > > to the right size with zeros and then map it with a shared mapping?
> >
> > Yes, but you don't even need to fill it with zeros. Just use
> > ftruncate(fd, length). This has the advantage that unused blocks won't
> > be allocated.
>
> It's probably better to lseek to the length you want and write a zero.
> ftruncate is not required by POSIX to allow length to be greater than
> the current length of the file, so using it that way is not portable.

That's not what O'Reilly's POSIX.4 book tells me. in the January 1995
edition, page 117:

`ftruncate actually works on all files ... ftruncate works both ways ...
Whatever size you pass in to ftruncate becomes the size of the shared
memory object.'

And I think Bill Gallmeister ought to know what he's talking about ;-)

-- 
Matthew Wilcox <willy@bofh.ai>
"I decry the current tendency to seek patents on algorithms.  There are
better ways to earn a living than to prevent other people from making use of
one's contributions to computer science."  -- Donald E. Knuth, TAoCP vol 3

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/