Date: Mon, 8 Jan 1996 12:15:47 +0100 From: Wolfram Schneider <wosch@cs.tu-berlin.de> To: hackers@freebsd.org Subject: large files Message-ID: <199601081115.MAA16136@caramba.cs.tu-berlin.de>
next in thread | raw e-mail | index | archive | help
On FreeBSD 2.0 I can mmap only file less than 2GB (SSIZE_MAX alias
INT_MAX). On FreeBSD 2.1 I can't write(2) to files larger than 2GB
(and don't test if mmap works with 2GB files).
Why?
Wolfram
Example:
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# Makefile
# mmap.c
#
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
XFILE=mmap.c
XALL=mmap1 mmap2
X
Xall: test
X
Xmmap1:
X cc -Wall -DSIZE=SIZE_T_MAX -DFILENAME=\"/tmp/$@\" ${FILE} -o $@
X
Xmmap2:
X cc -Wall -DSIZE=SSIZE_MAX -DFILENAME=\"/tmp/$@\" ${FILE} -o $@
X
Xtest: ${ALL}
X -@for i in $>; do ./$$i; ls -l /tmp/$$i; done
X
Xclean:
X rm -f ${ALL}; cd /tmp; rm -f ${ALL}
X
END-of-Makefile
echo x - mmap.c
sed 's/^X//' >mmap.c << 'END-of-mmap.c'
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <sys/stat.h>
X#include <unistd.h>
X#include <limits.h>
X
X#include <err.h>
X#include <stdio.h>
X
X#ifndef SIZE
X#define SIZE (SIZE_T_MAX)
X#endif
X
Xchar *filename =
X#ifndef FILENAME
X "/tmp/bla";
X#else
X FILENAME;
X#endif
X
Xvoid
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X struct stat sb;
X int fd;
X caddr_t p;
X off_t len;
X char buf[256];
X
X
X
X if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1)
X err(1, "``%s''", filename);
X
X /* make a long seek */
X if (lseek(fd, (off_t)SIZE - 16, SEEK_SET) == -1)
X err(1, "lseek");
X
X strcpy(buf, "foobar\n");
X
X /* write something into file */
X if (write(fd, buf, strlen(buf)) == -1)
X err(1, "write");
X
X if (fstat(fd, &sb) < 0)
X err(1, "``%s''", filename);
X len = sb.st_size;
X
X
X if ((p = mmap((caddr_t)0, (size_t)len,
X PROT_READ, MAP_SHARED,
X fd, (off_t)0)) == (caddr_t)-1)
X err(1, "mmap ``%s''", filename);
X
X /* print "foobar" */
X printf("%s", p+len-7);
X
X close(fd);
X}
END-of-mmap.c
exit
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199601081115.MAA16136>
