1
/* Copyright (C) 2004 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 */
21
Functions for discover of frm file from handler
24
#include "mysql_priv.h"
28
Read the contents of a .frm file.
30
frmdata and len are set to 0 on error.
32
@param name path to table-file "db/name"
33
@param frmdata frm data
34
@param len length of the read frmdata
43
3 Could not allocate data for read. Could not read file
46
int readfrm(const char *name, uchar **frmdata, size_t *len)
49
char index_file[FN_REFLEN];
54
DBUG_ENTER("readfrm");
55
DBUG_PRINT("enter",("name: '%s'",name));
57
*frmdata= NULL; // In case of errors
60
if ((file=my_open(fn_format(index_file,name,"",reg_ext,
61
MY_UNPACK_FILENAME|MY_APPEND_EXT),
68
if (my_fstat(file, &state, MYF(0)))
70
read_len= state.st_size;
72
// Read whole frm file
74
read_data= 0; // Nothing to free
75
if (read_string(file, &read_data, read_len))
79
*frmdata= (uchar*) read_data;
85
VOID(my_close(file,MYF(MY_WME)));
87
err_end: /* Here when no file */
93
Write the content of a frm data pointer
96
@param name path to table-file "db/name"
97
@param frmdata frm data
98
@param len length of the frmdata
103
2 Could not write file
106
int writefrm(const char *name, const uchar *frmdata, size_t len)
109
char index_file[FN_REFLEN];
111
DBUG_ENTER("writefrm");
112
DBUG_PRINT("enter",("name: '%s' len: %lu ",name, (ulong) len));
115
if ((file=my_create(fn_format(index_file,name,"",reg_ext,
116
MY_UNPACK_FILENAME|MY_APPEND_EXT),
117
CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
119
if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP)))
121
VOID(my_close(file,MYF(0)));