1 /* Copyright (c) 2000, 2001, 2003-2007 MySQL AB, 2009 Sun Microsystems, Inc.
2 Use is subject to license terms.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 /* Return useful base information for an open table */
25
26 #include "myisamdef.h"
27 #ifdef __WIN__
28 #include <sys/stat.h>
29 #endif
30
31 /* Get position to last record */
32
mi_position(MI_INFO * info)33 my_off_t mi_position(MI_INFO *info)
34 {
35 return info->lastpos;
36 }
37
38
39 /* Get information about the table */
40 /* if flag == 2 one get current info (no sync from database */
41
mi_status(MI_INFO * info,MI_ISAMINFO * x,uint flag)42 int mi_status(MI_INFO *info, MI_ISAMINFO *x, uint flag)
43 {
44 MY_STAT state;
45 MYISAM_SHARE *share=info->s;
46 DBUG_ENTER("mi_status");
47
48 x->recpos = info->lastpos;
49 if (flag == HA_STATUS_POS)
50 DBUG_RETURN(0); /* Compatible with ISAM */
51 if (!(flag & HA_STATUS_NO_LOCK))
52 {
53 mysql_mutex_lock(&share->intern_lock);
54 (void) _mi_readinfo(info,F_RDLCK,0);
55 fast_mi_writeinfo(info);
56 mysql_mutex_unlock(&share->intern_lock);
57 }
58 if (flag & HA_STATUS_VARIABLE)
59 {
60 x->records = info->state->records;
61 x->deleted = info->state->del;
62 x->delete_length = info->state->empty;
63 x->data_file_length =info->state->data_file_length;
64 x->index_file_length=info->state->key_file_length;
65
66 x->keys = share->state.header.keys;
67 x->check_time = share->state.check_time;
68 x->mean_reclength= x->records ?
69 (ulong) ((x->data_file_length - x->delete_length) / x->records) :
70 (ulong) share->min_pack_length;
71 }
72 if (flag & HA_STATUS_ERRKEY)
73 {
74 x->errkey = info->errkey;
75 x->dupp_key_pos= info->dupp_key_pos;
76 }
77 if (flag & HA_STATUS_CONST)
78 {
79 x->reclength = share->base.reclength;
80 x->max_data_file_length=share->base.max_data_file_length;
81 x->max_index_file_length=info->s->base.max_key_file_length;
82 x->filenr = info->dfile;
83 x->options = share->options;
84 x->create_time=share->state.create_time;
85 x->reflength= mi_get_pointer_length(share->base.max_data_file_length,
86 myisam_data_pointer_size);
87 x->record_offset= ((share->options &
88 (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
89 0L : share->base.pack_reclength);
90 x->sortkey= -1; /* No clustering */
91 x->rec_per_key = share->state.rec_per_key_part;
92 x->key_map = share->state.key_map;
93 x->data_file_name = share->data_file_name;
94 x->index_file_name = share->index_file_name;
95 }
96 if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(info->dfile, &state, MYF(0)))
97 x->update_time=state.st_mtime;
98 else
99 x->update_time=0;
100 if (flag & HA_STATUS_AUTO)
101 {
102 x->auto_increment= share->state.auto_increment+1;
103 if (!x->auto_increment) /* This shouldn't happen */
104 x->auto_increment= ~(ulonglong) 0;
105 }
106 DBUG_RETURN(0);
107 }
108
109
110 /*
111 Write a message to the error log.
112
113 SYNOPSIS
114 mi_report_error()
115 file_name Name of table file (e.g. index_file_name).
116 errcode Error number.
117
118 DESCRIPTION
119 This function supplies my_error() with a table name. Most error
120 messages need one. Since string arguments in error messages are limited
121 to 64 characters by convention, we ensure that in case of truncation,
122 that the end of the index file path is in the message. This contains
123 the most valuable information (the table name and the database name).
124
125 RETURN
126 void
127 */
128
mi_report_error(int errcode,const char * file_name)129 void mi_report_error(int errcode, const char *file_name)
130 {
131 size_t lgt;
132 DBUG_ENTER("mi_report_error");
133 DBUG_PRINT("enter",("errcode %d, table '%s'", errcode, file_name));
134
135 if ((lgt= strlen(file_name)) > 64)
136 file_name+= lgt - 64;
137 my_error(errcode, MYF(ME_NOREFRESH), file_name);
138 DBUG_VOID_RETURN;
139 }
140
141