uses of mmap

Guy Harris guy at auspex.auspex.com
Thu Sep 6 04:24:27 AEST 1990


 >  I have been looking at mmap (for work I did last year it
 >would have been GREAT - i think). I am not sure I understand
 >how it is used - I am looking at the man page (MIPS RiscOs).
 >
 >"mmap maps pages of memory from the memory device associated
 >with file fd into the address space of the calling process.."
 >
 > Now , If I want to mmap a file it looks as though I have to
 >open the device on which the file resides to get the fd 
 >mentioned in the man pages and somehow get the offset of
 >the file I want to map - is this a correct interpretation
 >it all seems murky.

Hmm.

Different systems implement "mmap()" to different degrees.

Some systems (e.g., SunOS prior to 4.0) only let you "mmap()" some
special files; they did *not* allow you to map an ordinary file into
memory.

Other systems (e.g., SunOS 4.0 and later, System V Release 4, and, I
think, Convex's OS and Dynix, at least in some releases - possibly
others) let you "mmap()" ordinary files into memory.

The fact that the man page says "memory device" makes it sound as if
RISC/OS falls into the first category, and only lets you map memory
devices into memory, not regular files.  If so, you can't "mmap()" a
file, period.

If it's one of the systems that *does* let you "mmap()" a file, you open
the file and use the file descriptor you get from the open to map the
file; you don't have to open the device on which the file resides.  (You
can't find "the offset of the file" in any case, because there is no
such thing in general, unless you consider the block number of the first
block of the file to be its "offset").



More information about the Comp.unix.questions mailing list