1
/* Copyright (C) 2000-2001, 2004-2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
#ifdef USE_PRAGMA_IMPLEMENTATION
18
#pragma implementation // gcc: Class implementation
21
#include "mysql_priv.h"
23
#ifdef HAVE_SYS_MMAN_H
27
mapped_files::mapped_files(const char * filename,uchar *magic,uint magic_length)
30
name=my_strdup(filename,MYF(0));
35
if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) >= 0)
38
if (!fstat(file,&stat_buf))
40
if (!(map=(uchar*) my_mmap(0,(size_t)(size= stat_buf.st_size),PROT_READ,
41
MAP_SHARED | MAP_NORESERVE,file,
45
my_error(ER_NO_FILE_MAPPING, MYF(0), (char *) name, error);
48
if (map && memcmp(map,magic,magic_length))
50
my_error(ER_WRONG_MAGIC, MYF(0), name);
51
VOID(my_munmap((char*) map,(size_t)size));
56
VOID(my_close(file,MYF(0)));
64
mapped_files::~mapped_files()
69
VOID(my_munmap((char*) map,(size_t)size));
70
VOID(my_close(file,MYF(0)));
78
static I_List<mapped_files> maps_in_use;
81
** Check if a file is mapped. If it is, then return pointer to old map,
82
** else alloc new object
85
mapped_files *map_file(const char * name,uchar *magic,uint magic_length)
88
VOID(pthread_mutex_lock(&LOCK_mapped_file));
89
I_List_iterator<mapped_files> list(maps_in_use);
92
sprintf(path,"%s/%s/%s.uniq",mysql_data_home,current_thd->db,name);
93
(void) unpack_filename(path,path);
97
if (!strcmp(path,map->name))
102
map=new mapped_files(path,magic,magic_length);
103
maps_in_use.append(map);
109
my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error);
111
VOID(pthread_mutex_unlock(&LOCK_mapped_file));
119
** free the map if there are no more users for it
122
void unmap_file(mapped_files *map)
125
VOID(pthread_mutex_lock(&LOCK_mapped_file));
126
if (!map->use_count--)
128
VOID(pthread_mutex_unlock(&LOCK_mapped_file));
132
/*****************************************************************************
133
** Instansiate templates
134
*****************************************************************************/
136
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
138
template class I_List<mapped_files>;
139
template class I_List_iterator<mapped_files>;