Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: uses of mmap Message-ID: <4024@auspex.auspex.com> Date: 5 Sep 90 18:24:27 GMT References: <1990Sep4.123135.10479@mips2.cr.bull.com> Organization: Auspex Systems, Santa Clara Lines: 37 > 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").