unix.c: Remove mmap code.

2005-09-10  Janne Blomqvist  <jblomqvi@cc.hut.fi>

	* io/unix.c: Remove mmap code.

From-SVN: r104127
This commit is contained in:
Janne Blomqvist 2005-09-10 19:31:28 +03:00 committed by Tobias Schlüter
parent 225d3396bf
commit ca0d06ac97
2 changed files with 10 additions and 209 deletions

View File

@ -1,3 +1,7 @@
2005-09-10 Janne Blomqvist <jblomqvi@cc.hut.fi>
* io/unix.c: Remove mmap code.
2005-09-09 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR libfortran/23784

View File

@ -140,7 +140,7 @@ typedef struct
int special_file; /* =1 if the fd refers to a special file */
unsigned unbuffered:1, mmaped:1;
unsigned unbuffered:1;
char small_buffer[BUFFER_SIZE];
@ -371,7 +371,6 @@ fd_alloc (unix_stream * s, gfc_offset where,
s->buffer = new_buffer;
s->len = read_len;
s->mmaped = 0;
}
@ -570,201 +569,6 @@ fd_open (unix_stream * s)
}
/*********************************************************************
mmap stream functions
Because mmap() is not capable of extending a file, we have to keep
track of how long the file is. We also have to be able to detect end
of file conditions. If there are multiple writers to the file (which
can only happen outside the current program), things will get
confused. Then again, things will get confused anyway.
*********************************************************************/
#if HAVE_MMAP
static int page_size, page_mask;
/* mmap_flush()-- Deletes a memory mapping if something is mapped. */
static try
mmap_flush (unix_stream * s)
{
if (!s->mmaped)
return fd_flush (s);
if (s->buffer == NULL)
return SUCCESS;
if (munmap (s->buffer, s->active))
return FAILURE;
s->buffer = NULL;
s->active = 0;
return SUCCESS;
}
/* mmap_alloc()-- mmap() a section of the file. The whole section is
* guaranteed to be mappable. */
static try
mmap_alloc (unix_stream * s, gfc_offset where,
int *len __attribute__ ((unused)))
{
gfc_offset offset;
int length;
char *p;
if (mmap_flush (s) == FAILURE)
return FAILURE;
offset = where & page_mask; /* Round down to the next page */
length = ((where - offset) & page_mask) + 2 * page_size;
p = mmap (NULL, length, s->prot, MAP_SHARED, s->fd, offset);
if (p == (char *) MAP_FAILED)
return FAILURE;
s->mmaped = 1;
s->buffer = p;
s->buffer_offset = offset;
s->active = length;
return SUCCESS;
}
static char *
mmap_alloc_r_at (unix_stream * s, int *len, gfc_offset where)
{
gfc_offset m;
if (where == -1)
where = s->logical_offset;
m = where + *len;
if ((s->buffer == NULL || s->buffer_offset > where ||
m > s->buffer_offset + s->active) &&
mmap_alloc (s, where, len) == FAILURE)
return NULL;
if (m > s->file_length)
{
*len = s->file_length - s->logical_offset;
s->logical_offset = s->file_length;
}
else
s->logical_offset = m;
return s->buffer + (where - s->buffer_offset);
}
static char *
mmap_alloc_w_at (unix_stream * s, int *len, gfc_offset where)
{
if (where == -1)
where = s->logical_offset;
/* If we're extending the file, we have to use file descriptor
* methods. */
if (where + *len > s->file_length)
{
if (s->mmaped)
mmap_flush (s);
return fd_alloc_w_at (s, len, where);
}
if ((s->buffer == NULL || s->buffer_offset > where ||
where + *len > s->buffer_offset + s->active ||
where < s->buffer_offset + s->active) &&
mmap_alloc (s, where, len) == FAILURE)
return NULL;
s->logical_offset = where + *len;
return s->buffer + where - s->buffer_offset;
}
static int
mmap_seek (unix_stream * s, gfc_offset offset)
{
s->logical_offset = offset;
return SUCCESS;
}
static try
mmap_close (unix_stream * s)
{
try t;
t = mmap_flush (s);
if (close (s->fd) < 0)
t = FAILURE;
free_mem (s);
return t;
}
static try
mmap_sfree (unix_stream * s __attribute__ ((unused)))
{
return SUCCESS;
}
/* mmap_open()-- mmap_specific open. If the particular file cannot be
* mmap()-ed, we fall back to the file descriptor functions. */
static try
mmap_open (unix_stream * s __attribute__ ((unused)))
{
char *p;
int i;
page_size = getpagesize ();
page_mask = ~0;
p = mmap (0, page_size, s->prot, MAP_SHARED, s->fd, 0);
if (p == (char *) MAP_FAILED)
{
fd_open (s);
return SUCCESS;
}
munmap (p, page_size);
i = page_size >> 1;
while (i != 0)
{
page_mask <<= 1;
i >>= 1;
}
s->st.alloc_r_at = (void *) mmap_alloc_r_at;
s->st.alloc_w_at = (void *) mmap_alloc_w_at;
s->st.sfree = (void *) mmap_sfree;
s->st.close = (void *) mmap_close;
s->st.seek = (void *) mmap_seek;
s->st.truncate = (void *) fd_truncate;
if (lseek (s->fd, s->file_length, SEEK_SET) < 0)
return FAILURE;
return SUCCESS;
}
#endif
/*********************************************************************
memory stream functions - These are used for internal files
@ -900,7 +704,7 @@ open_internal (char *base, int length)
* around it. */
static stream *
fd_to_stream (int fd, int prot, int avoid_mmap)
fd_to_stream (int fd, int prot)
{
struct stat statbuf;
unix_stream *s;
@ -920,14 +724,7 @@ fd_to_stream (int fd, int prot, int avoid_mmap)
s->file_length = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
s->special_file = !S_ISREG (statbuf.st_mode);
#if HAVE_MMAP
if (avoid_mmap)
fd_open (s);
else
mmap_open (s);
#else
fd_open (s);
#endif
return (stream *) s;
}
@ -1180,7 +977,7 @@ open_external (unit_flags *flags)
internal_error ("open_external(): Bad action");
}
return fd_to_stream (fd, prot, 0);
return fd_to_stream (fd, prot);
}
@ -1190,7 +987,7 @@ open_external (unit_flags *flags)
stream *
input_stream (void)
{
return fd_to_stream (STDIN_FILENO, PROT_READ, 1);
return fd_to_stream (STDIN_FILENO, PROT_READ);
}
@ -1200,7 +997,7 @@ input_stream (void)
stream *
output_stream (void)
{
return fd_to_stream (STDOUT_FILENO, PROT_WRITE, 1);
return fd_to_stream (STDOUT_FILENO, PROT_WRITE);
}
@ -1210,7 +1007,7 @@ output_stream (void)
stream *
error_stream (void)
{
return fd_to_stream (STDERR_FILENO, PROT_WRITE, 1);
return fd_to_stream (STDERR_FILENO, PROT_WRITE);
}
/* init_error_stream()-- Return a pointer to the error stream. This