MySQL 9.7.2
Source Code Documentation
polyglot_file_system.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2026, 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, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the 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 Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_POLYGLOT_FILE_SYSTEM_H_
27#define ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_POLYGLOT_FILE_SYSTEM_H_
28
29#include <cstdint>
30#include <memory>
31#include <string>
32
34
35namespace shcore {
36namespace polyglot {
37
39 public:
40 virtual ~ISeekable_channel() = default;
41 /**
42 * Tells whether or not this channel is open.
43 */
44 virtual bool is_open() = 0;
45
46 /**
47 * Closes this channel.
48 *
49 * <p> After a channel is closed, any further attempt to invoke I/O
50 * operations upon it will cause a ClosedChannelException to be thrown.
51 *
52 * <p> If this channel is already closed then invoking this method has no
53 * effect.
54 *
55 * <p> This method may be invoked at any time. If some other thread has
56 * already invoked it, however, then another invocation will block until
57 * the first invocation is complete, after which it will return without
58 * effect. </p>
59 *
60 * @throws IOException If an I/O error occurs
61 */
62 virtual void close() = 0;
63
64 /**
65 * Reads a sequence of bytes from this channel into the given buffer.
66 *
67 * <p> Bytes are read starting at this channel's current position, and
68 * then the position is updated with the number of bytes actually read.
69 * Otherwise this method behaves exactly as specified in the
70 * ReadableByteChannel interface.
71 *
72 * @throws ClosedChannelException {@inheritDoc}
73 * @throws AsynchronousCloseException {@inheritDoc}
74 * @throws ClosedByInterruptException {@inheritDoc}
75 * @throws NonReadableChannelException {@inheritDoc}
76 */
77 virtual int64_t read(void *buffer, size_t size) = 0;
78
79 /**
80 * Writes a sequence of bytes to this channel from the given buffer.
81 *
82 * <p> Bytes are written starting at this channel's current position, unless
83 * the channel is connected to an entity such as a file that is opened with
84 * the APPEND option, in which case the position is first advanced to the end.
85 * The entity to which the channel is connected is grown, if necessary, to
86 * accommodate the written bytes, and then the position is updated with the
87 * number of bytes actually written. Otherwise this method behaves exactly as
88 * specified by the WritableByteChannel interface.
89 *
90 * @throws ClosedChannelException {@inheritDoc}
91 * @throws AsynchronousCloseException {@inheritDoc}
92 * @throws ClosedByInterruptException {@inheritDoc}
93 * @throws NonWritableChannelException {@inheritDoc}
94 */
95 virtual int64_t write(const char *buffer, size_t size) = 0;
96
97 /**
98 * Returns this channel's position.
99 *
100 * @return This channel's position,
101 * a non-negative integer counting the number of bytes
102 * from the beginning of the entity to the current position
103 *
104 * @throws ClosedChannelException
105 * If this channel is closed
106 * @throws IOException
107 * If some other I/O error occurs
108 */
109 virtual int64_t position() = 0;
110
111 /**
112 * Sets this channel's position.
113 *
114 * <p> Setting the position to a value that is greater than the current size
115 * is legal but does not change the size of the entity. A later attempt to
116 * read bytes at such a position will immediately return an end-of-file
117 * indication. A later attempt to write bytes at such a position will cause
118 * the entity to grow to accommodate the new bytes; the values of any bytes
119 * between the previous end-of-file and the newly-written bytes are
120 * unspecified.
121 *
122 * <p> Setting the channel's position is not recommended when connected to
123 * an entity, typically a file, that is opened with the APPEND option.
124 * When opened for append, the position is first advanced to the end before
125 * writing.
126 *
127 * @param new_position
128 * The new position, a non-negative integer counting
129 * the number of bytes from the beginning of the entity
130 *
131 * @return This channel
132 *
133 * @throws ClosedChannelException
134 * If this channel is closed
135 * @throws IllegalArgumentException
136 * If the new position is negative
137 * @throws IOException
138 * If some other I/O error occurs
139 */
140 virtual ISeekable_channel &set_position(int64_t new_position) = 0;
141
142 /**
143 * Returns the current size of entity to which this channel is connected.
144 *
145 * @return The current size, measured in bytes
146 *
147 * @throws ClosedChannelException
148 * If this channel is closed
149 * @throws IOException
150 * If some other I/O error occurs
151 */
152 virtual int64_t size() = 0;
153
154 /**
155 * Truncates the entity, to which this channel is connected, to the given
156 * size.
157 *
158 * <p> If the given size is less than the current size then the entity is
159 * truncated, discarding any bytes beyond the new end. If the given size is
160 * greater than or equal to the current size then the entity is not modified.
161 * In either case, if the current position is greater than the given size
162 * then it is set to that size.
163 *
164 * <p> An implementation of this interface may prohibit truncation when
165 * connected to an entity, typically a file, opened with the APPEND option.
166 *
167 * @param size
168 * The new size, a non-negative byte count
169 *
170 * @return This channel
171 *
172 * @throws NonWritableChannelException
173 * If this channel was not opened for writing
174 * @throws ClosedChannelException
175 * If this channel is closed
176 * @throws IllegalArgumentException
177 * If the new size is negative
178 * @throws IOException
179 * If some other I/O error occurs
180 */
181 virtual ISeekable_channel &truncate(int64_t size) = 0;
182};
183
185
187 public:
188 virtual ~IFile_system() = default;
189
190 /**
191 * Parses a path from an URI.
192 *
193 * @param uri the URI to be converted to Path
194 * @return the Path representing given URI
195 * @throws UnsupportedOperationException when URI scheme is not
196 * supported
197 * @throws IllegalArgumentException if preconditions on the {@code uri} do not
198 * hold. The format of the URI is FileSystem specific.
199 */
200 virtual std::string parse_uri_path(const std::string &uri) = 0;
201
202 /**
203 * Parses a path from a String. This method is called only on the
204 * FileSystem with {@code file} scheme.
205 *
206 * @param path the string path to be converted to Path
207 * @return the Path
208 * @throws UnsupportedOperationException when the FileSystem supports
209 * only URI
210 * @throws IllegalArgumentException if the {@code path} string cannot be
211 * converted to a
212 * Path
213 */
214 virtual std::string parse_string_path(const std::string &path) = 0;
215
216 /**
217 * Checks existence and accessibility of a file.
218 *
219 * @param path the path to the file to check
220 * @param flags the access modes to check, as a binary mask RWX
221 * only.
222 * @throws NoSuchFileException if the file denoted by the path does not exist
223 * @throws IOException in case of IO error
224 * @throws SecurityException if this FileSystem denied the operation
225 */
226 virtual void check_access(const std::string &path, int64_t flags) = 0;
227
228 /**
229 * Creates a directory.
230 *
231 * param dir the directory to create
232 * param attrs the optional attributes to set atomically when creating the
233 * directory
234 * @throws FileAlreadyExistsException if a file on given path already exists
235 * @throws IOException in case of IO error
236 * @throws UnsupportedOperationException if the attributes contain an
237 * attribute which cannot be set atomically
238 * @throws SecurityException if this FileSystem denied the operation
239 */
240 virtual void create_directory(const std::string &path) = 0;
241
242 /**
243 * Deletes a file.
244 *
245 * @param path the path to the file to delete
246 * @throws NoSuchFileException if a file on given path does not exist
247 * @throws DirectoryNotEmptyException if the path denotes a non empty
248 * directory
249 * @throws IOException in case of IO error
250 * @throws SecurityException if this FileSystem denied the operation
251 */
252 virtual void remove(const std::string &path) = 0;
253
254 /**
255 * Opens or creates a file returning a SeekableByteChannel to access
256 * the file content.
257 *
258 * @param path the path to the file to open
259 * @return the created SeekableByteChannel
260 * @throws FileAlreadyExistsException if CREATE_NEW option is set and a file
261 * already exists on given path
262 * @throws IOException in case of IO error
263 * @throws UnsupportedOperationException if the attributes contain an
264 * attribute which cannot be set atomically
265 * @throws IllegalArgumentException in case of invalid options combination
266 * @throws SecurityException if this FileSystem denied the operation
267 */
268 virtual std::shared_ptr<ISeekable_channel> new_byte_channel(
269 const std::string &path) = 0;
270
271 /**
272 * Returns directory entries.
273 *
274 * param dir the path to the directory to iterate entries for
275 * param filter the filter
276 * @return the new DirectoryStream
277 * @throws NotDirectoryException when given path does not denote a directory
278 * @throws IOException in case of IO error
279 * @throws SecurityException if this FileSystem denied the operation
280 */
281 virtual std::shared_ptr<IDirectory_stream> new_directory_stream(
282 const std::string &path) = 0;
283
284 /**
285 * Resolves given path to an absolute path.
286 *
287 * @param path the path to resolve, may be a non normalized path
288 * @return an absolute Path
289 * @throws SecurityException if this FileSystem denied the operation
290 */
291 virtual std::string to_absolute_path(const std::string &path) = 0;
292
293 /**
294 * Returns the real (canonical) path of an existing file.
295 *
296 * @param path the path to resolve, may be a non normalized path
297 * param linkOptions options determining how the symbolic links should be
298 * handled
299 * @return an absolute canonical path
300 * @throws IOException in case of IO error
301 * @throws SecurityException if this FileSystem denied the operation
302 */
303 virtual std::string to_real_path(const std::string &path) = 0;
304};
305
306} // namespace polyglot
307} // namespace shcore
308
309#endif // ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_POLYGLOT_FILE_SYSTEM_H_
Definition: polyglot_file_system.h:184
Definition: polyglot_file_system.h:186
virtual void check_access(const std::string &path, int64_t flags)=0
Checks existence and accessibility of a file.
virtual std::shared_ptr< ISeekable_channel > new_byte_channel(const std::string &path)=0
Opens or creates a file returning a SeekableByteChannel to access the file content.
virtual std::string to_absolute_path(const std::string &path)=0
Resolves given path to an absolute path.
virtual std::string parse_uri_path(const std::string &uri)=0
Parses a path from an URI.
virtual std::string parse_string_path(const std::string &path)=0
Parses a path from a String.
virtual std::shared_ptr< IDirectory_stream > new_directory_stream(const std::string &path)=0
Returns directory entries.
virtual ~IFile_system()=default
virtual void remove(const std::string &path)=0
Deletes a file.
virtual void create_directory(const std::string &path)=0
Creates a directory.
virtual std::string to_real_path(const std::string &path)=0
Returns the real (canonical) path of an existing file.
Definition: polyglot_file_system.h:38
virtual ISeekable_channel & set_position(int64_t new_position)=0
Sets this channel's position.
virtual int64_t position()=0
Returns this channel's position.
virtual int64_t read(void *buffer, size_t size)=0
Reads a sequence of bytes from this channel into the given buffer.
virtual int64_t size()=0
Returns the current size of entity to which this channel is connected.
virtual void close()=0
Closes this channel.
virtual bool is_open()=0
Tells whether or not this channel is open.
virtual int64_t write(const char *buffer, size_t size)=0
Writes a sequence of bytes to this channel from the given buffer.
virtual ISeekable_channel & truncate(int64_t size)=0
Truncates the entity, to which this channel is connected, to the given size.
static int flags[50]
Definition: hp_test1.cc:40
static char * path
Definition: mysqldump.cc:150
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Definition: file_system_exceptions.h:34