MySQL 9.6.0
Source Code Documentation
mysql_file.h
Go to the documentation of this file.
1/* Copyright (c) 2025, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_FILE_IO_H
25#define MYSQL_FILE_IO_H
26
28#include <cstddef>
29
30/**
31 File access flags.
32*/
33/* Open for reading only. */
34#define MY_FILE_O_RDONLY 0
35/* Open for writing only. */
36#define MY_FILE_O_WRONLY 0x1
37/* Open for reading and writing. */
38#define MY_FILE_O_RDWR 0x2
39/* Mask for access mode (combines O_RDONLY, O_WRONLY, O_RDWR). */
40#define MY_FILE_O_ACCMODE (MY_FILE_O_WRONLY | MY_FILE_O_RDWR)
41/* Create file if it does not exist. */
42#define MY_FILE_O_CREAT 0x4
43/* Error if file already exists. */
44#define MY_FILE_O_EXCL 0x8
45/* Do not assign controlling terminal. */
46#define MY_FILE_O_NOCTTY 0x10
47/* Truncate size to 0 if file exists. */
48#define MY_FILE_O_TRUNC 0x20
49/* Append on each write. */
50#define MY_FILE_O_APPEND 0x40
51/* Non-blocking mode. */
52#define MY_FILE_O_NONBLOCK 0x80
53/* Synchronous writes; ensure data is physically written. */
54#define MY_FILE_O_SYNC 0x100
55/* Enable signal-driven I/O. */
56#define MY_FILE_FASYNC 0x200
57/* Minimize cache effects, use direct I/O if possible. */
58#define MY_FILE_O_DIRECT 0x400
59/* Allow files larger than 2GB. */
60#define MY_FILE_O_LARGEFILE 0x800
61/* Fail if not a directory. */
62#define MY_FILE_O_DIRECTORY 0x1000
63/* Do not follow symbolic links. */
64#define MY_FILE_O_NOFOLLOW 0x2000
65/* Do not update access time. */
66#define MY_FILE_O_NOATIME 0x4000
67/* Set close-on-exec. */
68#define MY_FILE_O_CLOEXEC 0x8000
69/* Open as text file. */
70#define MY_FILE_O_TEXT 0x10000
71/* Open as binary file. */
72#define MY_FILE_O_BINARY 0x20000
73/* Open as raw device/file. */
74#define MY_FILE_O_RAW 0x40000
75/* Open as a temporary file. */
76#define MY_FILE_O_TEMPORARY 0x80000
77/* Prevent file from being inherited by child processes. */
78#define MY_FILE_O_NOINHERIT 0x100000
79/* Access file sequentially. */
80#define MY_FILE_O_SEQUENTIAL 0x200000
81/* Access file randomly. */
82#define MY_FILE_O_RANDOM 0x400000
83
84/**
85 File permission flags.
86*/
87/* Read permission for the file owner (POSIX S_IRUSR). */
88#define MY_FILE_PERMISSION_USER_READ 0x1
89/* Write permission for the file owner (POSIX S_IWUSR). */
90#define MY_FILE_PERMISSION_USER_WRITE 0x2
91/* Execute/search permission for the file owner (POSIX S_IXUSR). */
92#define MY_FILE_PERMISSION_USER_EXECUTE 0x4
93/* Read permission for the group (POSIX S_IRGRP). */
94#define MY_FILE_PERMISSION_GROUP_READ 0x8
95/* Write permission for the group (POSIX S_IWGRP). */
96#define MY_FILE_PERMISSION_GROUP_WRITE 0x10
97/* Execute/search permission for the group (POSIX S_IXGRP). */
98#define MY_FILE_PERMISSION_GROUP_EXECUTE 0x20
99/* Read permission for others (POSIX S_IROTH). */
100#define MY_FILE_PERMISSION_OTHERS_READ 0x40
101/* Write permission for others (POSIX S_IWOTH). */
102#define MY_FILE_PERMISSION_OTHERS_WRITE 0x80
103/* Execute/search permission for others (POSIX S_IXOTH). */
104#define MY_FILE_PERMISSION_OTHERS_EXECUTE 0x100
105/* Read, write, and execute permissions for owner. */
106#define MY_FILE_PERMISSION_USER_RWX \
107 (MY_FILE_PERMISSION_USER_READ | MY_FILE_PERMISSION_USER_WRITE | \
108 MY_FILE_PERMISSION_USER_EXECUTE)
109/* Read, write, and execute permissions for group. */
110#define MY_FILE_PERMISSION_GROUP_RWX \
111 (MY_FILE_PERMISSION_GROUP_READ | MY_FILE_PERMISSION_GROUP_WRITE | \
112 MY_FILE_PERMISSION_GROUP_EXECUTE)
113/* Read, write, and execute permissions for others. */
114#define MY_FILE_PERMISSION_OTHERS_RWX \
115 (MY_FILE_PERMISSION_OTHERS_READ | MY_FILE_PERMISSION_OTHERS_WRITE | \
116 MY_FILE_PERMISSION_OTHERS_EXECUTE)
117
118/*
119 File positioning flags.
120*/
121/* Seek from the beginning of the file. */
122#define MY_FILE_SEEK_SET 0
123/* Seek from the current position in the file. */
124#define MY_FILE_SEEK_CUR 0x1
125/* Seek from the end of the file. */
126#define MY_FILE_SEEK_END 0x2
127
128/*
129 Error codes.
130*/
131/* Read/write error. */
132#define MY_FILE_ERROR_IO (~(size_t)0)
133/* File position error code. */
134#define MY_FILE_ERROR_POS (~(unsigned long long)0)
135
137
138/**
139 @ingroup group_components_services_inventory
140
141 File service allows file manipulation depending on the "mysql_file" component
142 service implementation. Every function has additional my_flags argument that
143 can be customized depending on the custom implementation.
144*/
146
147/**
148 Open a file.
149
150 @param file_name File path.
151 @param open_flags File open flags starting with MY_FILE_O prefix, e.g.
152 MY_FILE_O_RDONLY.
153
154 @return Non zero file handle on success, otherwise failed.
155*/
156DECLARE_METHOD(FILE_h, open, (const char *file_name, int open_flags));
157
158/**
159 Create a new file.
160
161 @param file_name File path.
162 @param open_flags File open flags starting with MY_FILE_O prefix, e.g.
163 MY_FILE_O_RDONLY.
164 @param permission_flags File permission specifier flags starting with
165 MY_FILE_PERMISSION prefix.
166
167 @return Non zero file handle on success, otherwise failed.
168*/
170 (const char *file_name, int open_flags, int permission_flags));
171
172/**
173 Close a file previously opened or created using the open/create functions.
174
175 @param file File handle.
176
177 @return Zero value on success, otherwise failed.
178*/
180
181/**
182 Write data into a file
183
184 @param file File handle.
185 @param data Data to be written.
186 @param size Data size.
187
188 @return Number of bytes written.
189*/
190DECLARE_METHOD(size_t, write,
191 (FILE_h file, const unsigned char *data, size_t size));
192
193/**
194 Read data from a file.
195
196 @param file File handle.
197 @param data Data buffer, where data will be written.
198 @param size Data buffer size.
199
200 @return Number of bytes read.
201*/
202DECLARE_METHOD(size_t, read, (FILE_h file, unsigned char *data, size_t size));
203
204/**
205 Flush written data into the file.
206
207 @param file File handle.
208
209 @return Zero value on success, otherwise failed.
210*/
212
213/**
214 Go to the specified position within a file.
215
216 @param file File handle.
217 @param pos A new read/write position within a file.
218 @param whence File position flag starting with MY_FILE_SEEK prefix.
219
220 @return Non MY_FILE_ERROR_POS value on success, otherwise failed.
221*/
222DECLARE_METHOD(unsigned long long, seek,
223 (FILE_h file, unsigned long long pos, int whence));
224
225/**
226 Get current absolute position within a file.
227
228 @param file File handle.
229
230 @return Position within a file on success or MY_FILE_ERROR_POS on failure.
231*/
232DECLARE_METHOD(unsigned long long, tell, (FILE_h file));
233
235
236#endif /* MYSQL_FILE_IO_H */
struct FILE_h_imp * FILE_h
Definition: mysql_file.h:136
void write(W *w, const T &t, const char *key, size_t key_sz)
Definition: sdi_impl.h:335
static const char * whence(const Item_field *cached_field)
Get the name of the cached field of an Item_cache_json instance.
Definition: item.cc:10083
Definition: os0file.h:89
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:94
static mysql_service_status_t create(my_h_string *) noexcept
Definition: mysql_string_all_empty.cc:43
size_t size(const char *const c)
Definition: base64.h:46
stdx::expected< void, std::error_code > close(file_handle_type native_handle)
close file handle.
Definition: file.h:239
stdx::expected< size_t, std::error_code > read(SyncReadStream &stream, const MutableBufferSequence &buffers)
Definition: buffer.h:835
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:114
stdx::expected< int, std::error_code > open(const char *fname, int flags, mode_t mode) noexcept
Definition: file_handle.cc:79
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:103
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:129