MySQL 9.2.0
Source Code Documentation
my_io.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24
25#ifndef MY_IO_INCLUDED
26#define MY_IO_INCLUDED 1
27
28/**
29 @file include/my_io.h
30 Common \#defines and includes for file and socket I/O.
31*/
32
34
35#ifdef MYSQL_COMPONENT
36#error This header shall not be included in components
37#endif
38
39#ifdef _WIN32
40
41/* Define missing access() modes. */
42#define F_OK 0
43#define W_OK 2
44#define R_OK 4 /* Test for read permission. */
45
46/* Define missing file locking constants. */
47#define F_RDLCK 1
48#define F_WRLCK 2
49#define F_UNLCK 3
50
51#define O_NONBLOCK 1 /* For emulation of fcntl() */
52
53/*
54 SHUT_RDWR is called SD_BOTH in windows and
55 is defined to 2 in winsock2.h
56 #define SD_BOTH 0x02
57*/
58#define SHUT_RDWR 0x02
59
60#endif // _WIN32
61
62/* file create flags */
63
64#ifdef _WIN32
65/* Only for my_fopen() - _O_BINARY is set by default for my_open() */
66#define MY_FOPEN_BINARY _O_BINARY
67#else
68#define MY_FOPEN_BINARY 0 /* Ignore on non-Windows */
69#endif
70
71#ifdef _WIN32
72#define O_NOFOLLOW 0 /* Ignore on Windows */
73#endif
74
75/* additional file share flags for win32 */
76#ifdef _WIN32
77#define _SH_DENYRWD 0x110 /* deny read/write mode & delete */
78#define _SH_DENYWRD 0x120 /* deny write mode & delete */
79#define _SH_DENYRDD 0x130 /* deny read mode & delete */
80#define _SH_DENYDEL 0x140 /* deny delete only */
81#endif /* _WIN32 */
82
83/* General constants */
84#define FN_LEN 256 /* Max file name len */
85#define FN_HEADLEN 253 /* Max length of filepart of file name */
86#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
87#define FN_REFLEN 512 /* Max length of full path-name */
88#define FN_REFLEN_SE 4000 /* Max length of full path-name in SE */
89#define FN_EXTCHAR '.'
90#define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
91#define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
92#define FN_PARENTDIR ".." /* Parent directory; Must be a string */
93
94#ifdef _WIN32
95#define FN_LIBCHAR '\\'
96#define FN_LIBCHAR2 '/'
97#define FN_DIRSEP "/\\" /* Valid directory separators */
98#define FN_EXEEXT ".exe"
99#define FN_SOEXT ".dll"
100#define FN_ROOTDIR "\\"
101#define FN_DEVCHAR ':'
102#define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
103#else
104#define FN_LIBCHAR '/'
105/*
106 FN_LIBCHAR2 is not defined on !Windows. Use is_directory_separator().
107*/
108#define FN_DIRSEP "/" /* Valid directory separators */
109#define FN_EXEEXT ""
110#define FN_SOEXT ".so"
111#define FN_ROOTDIR "/"
112#endif
113
114static inline int is_directory_separator(char c) {
115#ifdef _WIN32
116 return c == FN_LIBCHAR || c == FN_LIBCHAR2;
117#else
118 return c == FN_LIBCHAR;
119#endif
120}
121
122/*
123 MY_FILE_MIN is Windows speciality and is used to quickly detect
124 the mismatch of CRT and mysys file IO usage on Windows at runtime.
125 CRT file descriptors can be in the range 0-2047, whereas descriptors
126 returned by my_open() will start with 2048. If a file descriptor with value
127 less then MY_FILE_MIN is passed to mysys IO function, chances are it stemms
128 from open()/fileno() and not my_open()/my_fileno.
129
130 For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN
131 is logically 0.
132*/
133
134#ifdef _WIN32
135#define MY_FILE_MIN 2048
136#else
137#define MY_FILE_MIN 0
138#endif
139
140/*
141 MY_NFILE is the default size of my_file_info array.
142
143 It is larger on Windows, because it all file handles are stored in
144 my_file_info Default size is 16384 and this should be enough for most cases.If
145 it is not enough, --max-open-files with larger value can be used.
146
147 For Posix , my_file_info array is only used to store filenames for
148 error reporting and its size is not a limitation for number of open files.
149*/
150#ifdef _WIN32
151#define MY_NFILE (16384 + MY_FILE_MIN)
152#else
153#define MY_NFILE 64
154#endif
155
156#define OS_FILE_LIMIT UINT_MAX
157
158/*
159 Io buffer size; Must be a power of 2 and a multiple of 512. May be
160 smaller what the disk page size. This influences the speed of the
161 isam btree library. eg to big to slow.
162*/
163constexpr const size_t IO_SIZE{4096};
164
165/* Pointer_buffer_size */
166constexpr const unsigned int READ_RECORD_BUFFER{IO_SIZE * 8};
167/* Size of diskbuffer */
168constexpr const unsigned int DISK_BUFFER_SIZE{IO_SIZE * 16};
169
170#if defined(_WIN32)
171#define socket_errno WSAGetLastError()
172#define SOCKET_EINTR WSAEINTR
173#define SOCKET_EAGAIN WSAEINPROGRESS
174#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
175#define SOCKET_EADDRINUSE WSAEADDRINUSE
176#define SOCKET_ETIMEDOUT WSAETIMEDOUT
177#define SOCKET_ECONNRESET WSAECONNRESET
178#define SOCKET_ENFILE ENFILE
179#define SOCKET_EMFILE EMFILE
180#else /* Unix */
181#define socket_errno errno
182#define closesocket(A) close(A)
183#define SOCKET_EINTR EINTR
184#define SOCKET_EAGAIN EAGAIN
185#define SOCKET_EWOULDBLOCK EWOULDBLOCK
186#define SOCKET_EADDRINUSE EADDRINUSE
187#define SOCKET_ETIMEDOUT ETIMEDOUT
188#define SOCKET_ECONNRESET ECONNRESET
189#define SOCKET_ENFILE ENFILE
190#define SOCKET_EMFILE EMFILE
191#endif
192
193#ifndef _WIN32
194#define INVALID_SOCKET -1
195#endif /* _WIN32 */
196
197/* File permissions */
198#define USER_READ (1L << 0)
199#define USER_WRITE (1L << 1)
200#define USER_EXECUTE (1L << 2)
201#define GROUP_READ (1L << 3)
202#define GROUP_WRITE (1L << 4)
203#define GROUP_EXECUTE (1L << 5)
204#define OTHERS_READ (1L << 6)
205#define OTHERS_WRITE (1L << 7)
206#define OTHERS_EXECUTE (1L << 8)
207#define USER_RWX USER_READ | USER_WRITE | USER_EXECUTE
208#define GROUP_RWX GROUP_READ | GROUP_WRITE | GROUP_EXECUTE
209#define OTHERS_RWX OTHERS_READ | OTHERS_WRITE | OTHERS_EXECUTE
210
211#endif // MY_IO_INCLUDED
constexpr const unsigned int DISK_BUFFER_SIZE
Definition: my_io.h:168
constexpr const unsigned int READ_RECORD_BUFFER
Definition: my_io.h:166
static int is_directory_separator(char c)
Definition: my_io.h:114
#define FN_LIBCHAR
Definition: my_io.h:104
constexpr const size_t IO_SIZE
Definition: my_io.h:163
Types to make file and socket I/O compatible.