1/******************************************************
2XtraBackup: hot backup tool for InnoDB
3(c) 2009-2013 Percona LLC and/or its affiliates.
4Originally Created 3/3/2009 Yasufumi Kinoshita
5Written by Alexey Kopytov, Aleksandr Kuzminsky, Stewart Smith, Vadim Tkachenko,
6Yasufumi Kinoshita, Ignacio Nin and Baron Schwartz.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; version 2 of the License.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20
21*******************************************************/
22
23/* Source file cursor interface */
24
25#ifndef FIL_CUR_H
26#define FIL_CUR_H
27
28#include <my_dir.h>
29#include "read_filt.h"
30#include "srv0start.h"
31#include "srv0srv.h"
32
33struct xb_fil_cur_t {
34 pfs_os_file_t file; /*!< source file handle */
35 fil_node_t* node; /*!< source tablespace node */
36 char rel_path[FN_REFLEN];
37 /*!< normalized file path */
38 char abs_path[FN_REFLEN];
39 /*!< absolute file path */
40 MY_STAT statinfo; /*!< information about the file */
41 page_size_t page_size; /*!< page size */
42 xb_read_filt_t* read_filter; /*!< read filter */
43 xb_read_filt_ctxt_t read_filter_ctxt;
44 /*!< read filter context */
45 byte* orig_buf; /*!< read buffer */
46 byte* buf; /*!< aligned pointer for orig_buf */
47 size_t buf_size; /*!< buffer size in bytes */
48 size_t buf_read; /*!< number of read bytes in buffer
49 after the last cursor read */
50 size_t buf_npages; /*!< number of pages in buffer after the
51 last cursor read */
52 ib_int64_t buf_offset; /*!< file offset of the first page in
53 buffer */
54 ulint buf_page_no; /*!< number of the first page in
55 buffer */
56 uint thread_n; /*!< thread number for diagnostics */
57 ulint space_id; /*!< ID of tablespace */
58 ulint space_size; /*!< space size in pages */
59
60 /** TODO: remove this default constructor */
61 xb_fil_cur_t() : page_size(0), read_filter_ctxt() {}
62
63 /** @return whether this is not a file-per-table tablespace */
64 bool is_system() const
65 {
66 ut_ad(space_id != SRV_TMP_SPACE_ID);
67 return(space_id == TRX_SYS_SPACE
68 || srv_is_undo_tablespace(space_id));
69 }
70};
71
72typedef enum {
73 XB_FIL_CUR_SUCCESS,
74 XB_FIL_CUR_SKIP,
75 XB_FIL_CUR_ERROR,
76 XB_FIL_CUR_EOF
77} xb_fil_cur_result_t;
78
79/************************************************************************
80Open a source file cursor and initialize the associated read filter.
81
82@return XB_FIL_CUR_SUCCESS on success, XB_FIL_CUR_SKIP if the source file must
83be skipped and XB_FIL_CUR_ERROR on error. */
84xb_fil_cur_result_t
85xb_fil_cur_open(
86/*============*/
87 xb_fil_cur_t* cursor, /*!< out: source file cursor */
88 xb_read_filt_t* read_filter, /*!< in/out: the read filter */
89 fil_node_t* node, /*!< in: source tablespace node */
90 uint thread_n); /*!< thread number for diagnostics */
91
92/************************************************************************
93Reads and verifies the next block of pages from the source
94file. Positions the cursor after the last read non-corrupted page.
95
96@return XB_FIL_CUR_SUCCESS if some have been read successfully, XB_FIL_CUR_EOF
97if there are no more pages to read and XB_FIL_CUR_ERROR on error. */
98xb_fil_cur_result_t
99xb_fil_cur_read(
100/*============*/
101 xb_fil_cur_t* cursor); /*!< in/out: source file cursor */
102
103/************************************************************************
104Close the source file cursor opened with xb_fil_cur_open() and its
105associated read filter. */
106void
107xb_fil_cur_close(
108/*=============*/
109 xb_fil_cur_t *cursor); /*!< in/out: source file cursor */
110
111/***********************************************************************
112Extracts the relative path ("database/table.ibd") of a tablespace from a
113specified possibly absolute path.
114
115For user tablespaces both "./database/table.ibd" and
116"/remote/dir/database/table.ibd" result in "database/table.ibd".
117
118For system tablepsaces (i.e. When is_system is TRUE) both "/remote/dir/ibdata1"
119and "./ibdata1" yield "ibdata1" in the output. */
120const char *
121xb_get_relative_path(
122/*=================*/
123 const char* path, /*!< in: tablespace path (either
124 relative or absolute) */
125 ibool is_system); /*!< in: TRUE for system tablespaces,
126 i.e. when only the filename must be
127 returned. */
128
129#endif
130