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