2002-08-29  Ulrich Drepper  <drepper@redhat.com>

	* libio/fileops.c (_IO_new_file_fopen): Recognize new mode specifier
	'm' to enable mmap I/O.
	* libio/libio.h (_IO_FILE): Rename _blksize field to _flags2.  The
	former wasn't used (anymore?).
	(_IO_FLAGS2_MMAP): New define.
	* libio/genops.c (_IO_no_init): Initialize _flags2 field.
	* libio/iofopen.c (__fopen_maybe_mmap): Use mmap callbacks only if
	_IO_FLAGS2_MMAP bit is set.
	* libio/iofdopen.c (_IO_new_fdopen): Recognize 'm' mode specifier.
	Enable mmap-using mode only if 'm' was set.
This commit is contained in:
Ulrich Drepper 2002-08-30 07:07:16 +00:00
parent b7fc6d07af
commit dd0ee2e102
5 changed files with 47 additions and 6 deletions

View File

@ -1,3 +1,16 @@
2002-08-29 Ulrich Drepper <drepper@redhat.com>
* libio/fileops.c (_IO_new_file_fopen): Recognize new mode specifier
'm' to enable mmap I/O.
* libio/libio.h (_IO_FILE): Rename _blksize field to _flags2. The
former wasn't used (anymore?).
(_IO_FLAGS2_MMAP): New define.
* libio/genops.c (_IO_no_init): Initialize _flags2 field.
* libio/iofopen.c (__fopen_maybe_mmap): Use mmap callbacks only if
_IO_FLAGS2_MMAP bit is set.
* libio/iofdopen.c (_IO_new_fdopen): Recognize 'm' mode specifier.
Enable mmap-using mode only if 'm' was set.
2002-08-29 Roland McGrath <roland@redhat.com>
* sysdeps/mach/hurd/i386/init-first.c (_hurd_stack_setup: doinit):

View File

@ -610,6 +610,7 @@ _IO_no_init (fp, flags, orientation, wd, jmp)
struct _IO_jump_t *jmp;
{
fp->_flags = _IO_MAGIC|flags;
fp->_flags2 = 0;
fp->_IO_buf_base = NULL;
fp->_IO_buf_end = NULL;
fp->_IO_read_base = NULL;

View File

@ -59,8 +59,10 @@ _IO_new_fdopen (fd, mode)
struct _IO_wide_data wd;
} *new_f;
int fd_flags;
int i;
int use_mmap = 0;
switch (*mode++)
switch (*mode)
{
case 'r':
read_write = _IO_NO_WRITES;
@ -76,8 +78,26 @@ _IO_new_fdopen (fd, mode)
MAYBE_SET_EINVAL;
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
read_write &= _IO_IS_APPENDING;
for (i = 1; i < 5; ++i)
{
switch (*++mode)
{
case '\0':
break;
case '+':
read_write &= _IO_IS_APPENDING;
break;
case 'm':
use_mmap = 1;
continue;
case 'x':
case 'b':
default:
/* Ignore */
continue;
}
break;
}
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
#ifndef O_ACCMODE
@ -129,12 +149,13 @@ _IO_new_fdopen (fd, mode)
call _IO_file_attach or else it will allocate a buffer immediately. */
_IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd,
#ifdef _G_HAVE_MMAP
(read_write & _IO_NO_WRITES) ? &_IO_wfile_jumps_maybe_mmap :
(use_mmap && (read_write & _IO_NO_WRITES))
? &_IO_wfile_jumps_maybe_mmap :
#endif
&INTUSE(_IO_wfile_jumps));
_IO_JUMPS (&new_f->fp) =
#ifdef _G_HAVE_MMAP
(read_write & _IO_NO_WRITES) ? &_IO_file_jumps_maybe_mmap :
(use_mmap && (read_write & _IO_NO_WRITES)) ? &_IO_file_jumps_maybe_mmap :
#endif
&INTUSE(_IO_file_jumps);
INTUSE(_IO_file_init) (&new_f->fp);

View File

@ -41,7 +41,7 @@ __fopen_maybe_mmap (fp)
_IO_FILE *fp;
{
#ifdef _G_HAVE_MMAP
if (fp->_flags & _IO_NO_WRITES)
if ((fp->_flags2 & _IO_FLAGS2_MMAP) && (fp->_flags & _IO_NO_WRITES))
{
/* Since this is read-only, we might be able to mmap the contents
directly. We delay the decision until the first read attempt by

View File

@ -137,6 +137,8 @@
#define _IO_BAD_SEEN 0x4000
#define _IO_USER_LOCK 0x8000
#define _IO_FLAGS2_MMAP 1
/* These are "formatting flags" matching the iostream fmtflags enum values. */
#define _IO_SKIPWS 01
#define _IO_LEFT 02
@ -282,7 +284,11 @@ struct _IO_FILE {
struct _IO_FILE *_chain;
int _fileno;
#if 0
int _blksize;
#else
int _flags2;
#endif
_IO_off_t _old_offset; /* This used to be _offset but it's too small. */
#define __HAVE_COLUMN /* temporary */