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