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 */
16
#include <drizzled/server_includes.h>
18
#ifdef HAVE_SYS_MMAN_H
22
mapped_files::mapped_files(const char * filename,uchar *magic,uint magic_length)
25
name=my_strdup(filename,MYF(0));
30
if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) >= 0)
33
if (!fstat(file,&stat_buf))
35
if (!(map=(uchar*) my_mmap(0,(size_t)(size= stat_buf.st_size),PROT_READ,
36
MAP_SHARED | MAP_NORESERVE,file,
40
my_error(ER_NO_FILE_MAPPING, MYF(0), (char *) name, error);
43
if (map && memcmp(map,magic,magic_length))
45
my_error(ER_WRONG_MAGIC, MYF(0), name);
46
VOID(my_munmap((char*) map,(size_t)size));
51
VOID(my_close(file,MYF(0)));
59
mapped_files::~mapped_files()
64
VOID(my_munmap((char*) map,(size_t)size));
65
VOID(my_close(file,MYF(0)));
73
static I_List<mapped_files> maps_in_use;
76
** Check if a file is mapped. If it is, then return pointer to old map,
77
** else alloc new object
80
mapped_files *map_file(const char * name,uchar *magic,uint magic_length)
83
VOID(pthread_mutex_lock(&LOCK_mapped_file));
84
I_List_iterator<mapped_files> list(maps_in_use);
87
sprintf(path,"%s/%s/%s.uniq",mysql_data_home,current_thd->db,name);
88
(void) unpack_filename(path,path);
92
if (!strcmp(path,map->name))
97
map=new mapped_files(path,magic,magic_length);
98
maps_in_use.append(map);
104
my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error);
106
VOID(pthread_mutex_unlock(&LOCK_mapped_file));
114
** free the map if there are no more users for it
117
void unmap_file(mapped_files *map)
120
VOID(pthread_mutex_lock(&LOCK_mapped_file));
121
if (!map->use_count--)
123
VOID(pthread_mutex_unlock(&LOCK_mapped_file));
127
/*****************************************************************************
128
** Instansiate templates
129
*****************************************************************************/
131
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
133
template class I_List<mapped_files>;
134
template class I_List_iterator<mapped_files>;