mmap question...
Badri Pillai
badri at ecrc.de
Thu Jun 6 00:17:00 AEST 1991
Can somebody explain me, why mmap fails if the object is created
on TMPFS.
The following is an example source, test it by creating the object in
/tmp(tmpfs) and then try on any other filesystem.
Thanks in advance.
--------------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: xx.c
# Wrapped by badri at acrab7 on Wed May 29 10:19:37 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xx.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xx.c'\"
else
echo shar: Extracting \"'xx.c'\" \(1041 characters\)
sed "s/^X//" >'xx.c' <<'END_OF_FILE'
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <fcntl.h>
X#include <stdio.h>
X#include <errno.h>
X
Xextern int errno;
X
Xmain()
X{
X char memory_object[128];
X int MEMORY_OBJECT;
X
X int page_size;
X
X caddr_t address;
X caddr_t addr;
X size_t size;
X off_t offset;
X char* ptr;
X
X page_size = getpagesize();
X
X sprintf(memory_object, "/tmp/%s.%d", "memory_object", getpid());
X MEMORY_OBJECT = open(memory_object, (O_RDWR | O_CREAT),
X (S_IRUSR | S_IWUSR));
X if (MEMORY_OBJECT == -1)
X perror("open()");
X else
X unlink(memory_object);
X
X size = (size_t) page_size;
X offset = (off_t) 0;
X addr = (caddr_t) 0;
X address = mmap(addr,
X size,
X (PROT_READ | PROT_WRITE),
X MAP_SHARED,
X MEMORY_OBJECT,
X offset);
X if (address == (caddr_t) -1)
X perror("mmap()");
X}
END_OF_FILE
if test 1041 -ne `wc -c <'xx.c'`; then
echo shar: \"'xx.c'\" unpacked with wrong size!
fi
chmod +x 'xx.c'
# end of 'xx.c'
fi
echo shar: End of shell archive.
exit 0
badri
Badri Pillai
European Computer-Industry Research Centre Tel. + (49) 89-92699-119
Arabellastr 17, 8000 Muenchen 81. West Germany.
Internet: badri at ecrc.de
UUCP: ..unido!ecrc!badri
..pyramid!ecrc!badri
More information about the Comp.sys.sun
mailing list