- Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathmy_io.h
211 lines (177 loc) · 6.42 KB
/
my_io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
Copyright (c) 2016, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef MY_IO_INCLUDED
#defineMY_IO_INCLUDED1
/**
@file include/my_io.h
Common \#defines and includes for file and socket I/O.
*/
#include<mysql/components/services/bits/my_io_bits.h>
#ifdef MYSQL_COMPONENT
#error This header shall not be included in components
#endif
#ifdef _WIN32
/* Define missing access() modes. */
#defineF_OK0
#defineW_OK2
#defineR_OK4/* Test for read permission. */
/* Define missing file locking constants. */
#defineF_RDLCK1
#defineF_WRLCK2
#defineF_UNLCK3
#defineO_NONBLOCK1/* For emulation of fcntl() */
/*
SHUT_RDWR is called SD_BOTH in windows and
is defined to 2 in winsock2.h
#define SD_BOTH 0x02
*/
#defineSHUT_RDWR0x02
#endif// _WIN32
/* file create flags */
#ifdef _WIN32
/* Only for my_fopen() - _O_BINARY is set by default for my_open() */
#defineMY_FOPEN_BINARY _O_BINARY
#else
#defineMY_FOPEN_BINARY0/* Ignore on non-Windows */
#endif
#ifdef _WIN32
#defineO_NOFOLLOW0/* Ignore on Windows */
#endif
/* additional file share flags for win32 */
#ifdef _WIN32
#define_SH_DENYRWD0x110/* deny read/write mode & delete */
#define_SH_DENYWRD0x120/* deny write mode & delete */
#define_SH_DENYRDD0x130/* deny read mode & delete */
#define_SH_DENYDEL0x140/* deny delete only */
#endif/* _WIN32 */
/* General constants */
#defineFN_LEN256/* Max file name len */
#defineFN_HEADLEN253/* Max length of filepart of file name */
#defineFN_EXTLEN20/* Max length of extension (part of FN_LEN) */
#defineFN_REFLEN512/* Max length of full path-name */
#defineFN_REFLEN_SE4000/* Max length of full path-name in SE */
#defineFN_EXTCHAR'.'
#defineFN_HOMELIB'~'/* ~/ is used as abbrev for home dir */
#defineFN_CURLIB'.'/* ./ is used as abbrev for current dir */
#defineFN_PARENTDIR".."/* Parent directory; Must be a string */
#ifdef _WIN32
#defineFN_LIBCHAR'\\'
#defineFN_LIBCHAR2'/'
#defineFN_DIRSEP"/\\"/* Valid directory separators */
#defineFN_EXEEXT".exe"
#defineFN_SOEXT".dll"
#defineFN_ROOTDIR"\\"
#defineFN_DEVCHAR':'
#defineFN_NETWORK_DRIVES/* Uses \\ to indicate network drives */
#else
#defineFN_LIBCHAR'/'
/*
FN_LIBCHAR2 is not defined on !Windows. Use is_directory_separator().
*/
#defineFN_DIRSEP"/"/* Valid directory separators */
#defineFN_EXEEXT""
#defineFN_SOEXT".so"
#defineFN_ROOTDIR"/"
#endif
staticinlineintis_directory_separator(char c) {
#ifdef _WIN32
return c == FN_LIBCHAR || c == FN_LIBCHAR2;
#else
return c == FN_LIBCHAR;
#endif
}
/*
MY_FILE_MIN is Windows speciality and is used to quickly detect
the mismatch of CRT and mysys file IO usage on Windows at runtime.
CRT file descriptors can be in the range 0-2047, whereas descriptors
returned by my_open() will start with 2048. If a file descriptor with value
less then MY_FILE_MIN is passed to mysys IO function, chances are it stemms
from open()/fileno() and not my_open()/my_fileno.
For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN
is logically 0.
*/
#ifdef _WIN32
#defineMY_FILE_MIN2048
#else
#defineMY_FILE_MIN0
#endif
/*
MY_NFILE is the default size of my_file_info array.
It is larger on Windows, because it all file handles are stored in
my_file_info Default size is 16384 and this should be enough for most cases.If
it is not enough, --max-open-files with larger value can be used.
For Posix , my_file_info array is only used to store filenames for
error reporting and its size is not a limitation for number of open files.
*/
#ifdef _WIN32
#defineMY_NFILE (16384 + MY_FILE_MIN)
#else
#defineMY_NFILE64
#endif
#defineOS_FILE_LIMIT UINT_MAX
/*
Io buffer size; Must be a power of 2 and a multiple of 512. May be
smaller what the disk page size. This influences the speed of the
isam btree library. eg to big to slow.
*/
constexprconstsize_t IO_SIZE{4096};
/* Pointer_buffer_size */
constexprconstunsignedint READ_RECORD_BUFFER{IO_SIZE * 8};
/* Size of diskbuffer */
constexprconstunsignedint DISK_BUFFER_SIZE{IO_SIZE * 16};
#if defined(_WIN32)
#definesocket_errnoWSAGetLastError()
#defineSOCKET_EINTR WSAEINTR
#defineSOCKET_EAGAIN WSAEINPROGRESS
#defineSOCKET_EWOULDBLOCK WSAEWOULDBLOCK
#defineSOCKET_EADDRINUSE WSAEADDRINUSE
#defineSOCKET_ETIMEDOUT WSAETIMEDOUT
#defineSOCKET_ECONNRESET WSAECONNRESET
#defineSOCKET_ENFILE ENFILE
#defineSOCKET_EMFILE EMFILE
#else/* Unix */
#definesocket_errno errno
#defineclosesocket(A) close(A)
#defineSOCKET_EINTR EINTR
#defineSOCKET_EAGAIN EAGAIN
#defineSOCKET_EWOULDBLOCK EWOULDBLOCK
#defineSOCKET_EADDRINUSE EADDRINUSE
#defineSOCKET_ETIMEDOUT ETIMEDOUT
#defineSOCKET_ECONNRESET ECONNRESET
#defineSOCKET_ENFILE ENFILE
#defineSOCKET_EMFILE EMFILE
#endif
#ifndef _WIN32
#defineINVALID_SOCKET -1
#endif/* _WIN32 */
/* File permissions */
#defineUSER_READ (1L << 0)
#defineUSER_WRITE (1L << 1)
#defineUSER_EXECUTE (1L << 2)
#defineGROUP_READ (1L << 3)
#defineGROUP_WRITE (1L << 4)
#defineGROUP_EXECUTE (1L << 5)
#defineOTHERS_READ (1L << 6)
#defineOTHERS_WRITE (1L << 7)
#defineOTHERS_EXECUTE (1L << 8)
#defineUSER_RWX USER_READ | USER_WRITE | USER_EXECUTE
#defineGROUP_RWX GROUP_READ | GROUP_WRITE | GROUP_EXECUTE
#defineOTHERS_RWX OTHERS_READ | OTHERS_WRITE | OTHERS_EXECUTE
#endif// MY_IO_INCLUDED