MySQL  8.0.19
Source Code Documentation
os0file.h
Go to the documentation of this file.
1 /***********************************************************************
2 
3 Copyright (c) 1995, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2009, Percona Inc.
5 
6 Portions of this file contain modifications contributed and copyrighted
7 by Percona Inc.. Those modifications are
8 gratefully acknowledged and are described briefly in the InnoDB
9 documentation. The contributions by Percona Inc. are incorporated with
10 their permission, and subject to the conditions contained in the file
11 COPYING.Percona.
12 
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License, version 2.0,
15 as published by the Free Software Foundation.
16 
17 This program is also distributed with certain software (including
18 but not limited to OpenSSL) that is licensed under separate terms,
19 as designated in a particular file or component or in included license
20 documentation. The authors of MySQL hereby grant you an additional
21 permission to link the program and your derivative works with the
22 separately licensed software that they have included with MySQL.
23 
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License, version 2.0, for more details.
28 
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 
33 ***********************************************************************/
34 
35 /** @file include/os0file.h
36  The interface to the operating system file io
37 
38  Created 10/21/1995 Heikki Tuuri
39  *******************************************************/
40 
41 #ifndef os0file_h
42 #define os0file_h
43 
44 #include "my_dbug.h"
45 #include "my_io.h"
46 #include "os/file.h"
47 #include "univ.i"
48 
49 #ifndef _WIN32
50 #include <dirent.h>
51 #include <sys/stat.h>
52 #include <sys/statvfs.h>
53 #include <time.h>
54 #else
55 #include <Strsafe.h>
56 #include <locale>
57 #include <string>
58 #endif /* !_WIN32 */
59 
60 #include <functional>
61 #include <stack>
62 
63 /** Prefix all files and directory created under data directory with special
64 string so that it never conflicts with MySQL schema directory. */
65 #define OS_FILE_PREFIX "#"
66 
67 /** File node of a tablespace or the log data space */
68 struct fil_node_t;
69 
70 extern bool os_has_said_disk_full;
71 
72 /** Number of pending read operations */
73 extern ulint os_n_pending_reads;
74 /** Number of pending write operations */
75 extern ulint os_n_pending_writes;
76 
77 /* Flush after each os_fsync_threshold bytes */
78 extern unsigned long long os_fsync_threshold;
79 
80 /** File offset in bytes */
81 typedef ib_uint64_t os_offset_t;
82 
83 #ifdef _WIN32
84 
85 typedef HANDLE os_file_dir_t; /*!< directory stream */
86 
87 /** We define always WIN_ASYNC_IO, and check at run-time whether
88 the OS actually supports it: Win 95 does not, NT does. */
89 #define WIN_ASYNC_IO
90 
91 /** Use unbuffered I/O */
92 #define UNIV_NON_BUFFERED_IO
93 
94 /** File handle */
95 #define os_file_t HANDLE
96 
97 /** Convert a C file descriptor to a native file handle
98 @param fd file descriptor
99 @return native file handle */
100 #define OS_FILE_FROM_FD(fd) (HANDLE) _get_osfhandle(fd)
101 
102 /** Associates a C file descriptor with an existing native file handle
103 @param[in] file native file handle
104 @return C file descriptor */
105 #define OS_FD_FROM_FILE(file) _open_osfhandle((intptr_t)file, _O_RDONLY)
106 
107 /** Closes the file associated with C file descriptor fd
108 @param[in] fd C file descriptor
109 @return 0 if success */
110 #define OS_FILE_CLOSE_FD(fd) _close(fd)
111 
112 #else /* _WIN32 */
113 
114 /** File handle */
115 typedef int os_file_t;
116 
117 /** Convert a C file descriptor to a native file handle
118 @param fd file descriptor
119 @return native file handle */
120 #define OS_FILE_FROM_FD(fd) fd
121 
122 /** C file descriptor from an existing native file handle
123 @param[in] file native file handle
124 @return C file descriptor */
125 #define OS_FD_FROM_FILE(file) file
126 
127 /** Closes the file associated with C file descriptor fd
128 @param[in] fd C file descriptor
129 @return 0 if success */
130 #define OS_FILE_CLOSE_FD(fd) (os_file_close(fd) ? 0 : -1)
131 
132 #endif /* _WIN32 */
133 
134 /** Common file descriptor for file IO instrumentation with PFS
135 on windows and other platforms */
137 #ifdef UNIV_PFS_IO
138  struct PSI_file *m_psi;
139 #else /* UNIV_PFS_IO */
140  pfs_os_file_t &operator=(os_file_t file) {
141  m_file = file;
142  return (*this);
143  }
144 #endif /* UNIV_PFS_IO */
145 
147 };
148 
149 static const os_file_t OS_FILE_CLOSED = os_file_t(~0);
150 
151 /** The next value should be smaller or equal to the smallest sector size used
152 on any disk. A log block is required to be a portion of disk which is written
153 so that if the start and the end of a block get written to disk, then the
154 whole block gets written. This should be true even in most cases of a crash:
155 if this fails for a log block, then it is equivalent to a media failure in the
156 log. */
157 
158 #define OS_FILE_LOG_BLOCK_SIZE 512
159 
160 /** Options for os_file_create_func @{ */
162  OS_FILE_OPEN = 51, /*!< to open an existing file (if
163  doesn't exist, error) */
164  OS_FILE_CREATE, /*!< to create new file (if
165  exists, error) */
166  OS_FILE_OPEN_RAW, /*!< to open a raw device or disk
167  partition */
168  OS_FILE_CREATE_PATH, /*!< to create the directories */
169  OS_FILE_OPEN_RETRY, /*!< open with retry */
170 
171  /** Flags that can be combined with the above values. Please ensure
172  that the above values stay below 128. */
173 
174  OS_FILE_ON_ERROR_NO_EXIT = 128, /*!< do not exit on unknown errors */
175  OS_FILE_ON_ERROR_SILENT = 256 /*!< don't print diagnostic messages to
176  the log unless it is a fatal error,
177  this flag is only used if
178  ON_ERROR_NO_EXIT is set */
179 };
180 
181 static const ulint OS_FILE_READ_ONLY = 333;
182 static const ulint OS_FILE_READ_WRITE = 444;
183 
184 /** Used by MySQLBackup */
185 static const ulint OS_FILE_READ_ALLOW_DELETE = 555;
186 
187 /* Options for file_create */
188 static const ulint OS_FILE_AIO = 61;
189 static const ulint OS_FILE_NORMAL = 62;
190 /* @} */
191 
192 /** Types for file create @{ */
193 static const ulint OS_DATA_FILE = 100;
194 static const ulint OS_LOG_FILE = 101;
195 /* Don't use this for Data files, Log files. Use it for smaller files
196 or if number of bytes to write are not multiple of sector size.
197 With this flag, writes to file will be always buffered and ignores the value
198 of innodb_flush_method. */
199 static const ulint OS_BUFFERED_FILE = 102;
200 
201 static const ulint OS_CLONE_DATA_FILE = 103;
202 static const ulint OS_CLONE_LOG_FILE = 104;
203 
204 static const ulint OS_REDO_LOG_ARCHIVE_FILE = 105;
205 /* @} */
206 
207 /** Error codes from os_file_get_last_error @{ */
208 static const ulint OS_FILE_NOT_FOUND = 71;
209 static const ulint OS_FILE_DISK_FULL = 72;
210 static const ulint OS_FILE_ALREADY_EXISTS = 73;
211 static const ulint OS_FILE_PATH_ERROR = 74;
212 
213 /** wait for OS aio resources to become available again */
214 static const ulint OS_FILE_AIO_RESOURCES_RESERVED = 75;
215 
216 static const ulint OS_FILE_SHARING_VIOLATION = 76;
217 static const ulint OS_FILE_ERROR_NOT_SPECIFIED = 77;
218 static const ulint OS_FILE_INSUFFICIENT_RESOURCE = 78;
219 static const ulint OS_FILE_AIO_INTERRUPTED = 79;
220 static const ulint OS_FILE_OPERATION_ABORTED = 80;
221 static const ulint OS_FILE_ACCESS_VIOLATION = 81;
222 static const ulint OS_FILE_NAME_TOO_LONG = 82;
223 static const ulint OS_FILE_ERROR_MAX = 100;
224 /* @} */
225 
226 /** Encryption key length */
227 static const ulint ENCRYPTION_KEY_LEN = 32;
228 
229 /** Encryption magic bytes size */
230 static const ulint ENCRYPTION_MAGIC_SIZE = 3;
231 
232 /** Encryption magic bytes for 5.7.11, it's for checking the encryption
233 information version. */
234 static const char ENCRYPTION_KEY_MAGIC_V1[] = "lCA";
235 
236 /** Encryption magic bytes for 5.7.12+, it's for checking the encryption
237 information version. */
238 static const char ENCRYPTION_KEY_MAGIC_V2[] = "lCB";
239 
240 /** Encryption magic bytes for 8.0.5+, it's for checking the encryption
241 information version. */
242 static const char ENCRYPTION_KEY_MAGIC_V3[] = "lCC";
243 
244 /** Encryption master key prifix */
245 static const char ENCRYPTION_MASTER_KEY_PRIFIX[] = "INNODBKey";
246 
247 /** Encryption master key prifix size */
248 static const ulint ENCRYPTION_MASTER_KEY_PRIFIX_LEN = 9;
249 
250 /** Encryption master key prifix size */
251 static const ulint ENCRYPTION_MASTER_KEY_NAME_MAX_LEN = 100;
252 
253 /** UUID of server instance, it's needed for composing master key name */
254 static const ulint ENCRYPTION_SERVER_UUID_LEN = 36;
255 
256 /** Encryption information total size: magic number + master_key_id +
257 key + iv + server_uuid + checksum */
258 static const ulint ENCRYPTION_INFO_SIZE =
259  (ENCRYPTION_MAGIC_SIZE + sizeof(uint32) + (ENCRYPTION_KEY_LEN * 2) +
261 
262 /** Maximum size of Encryption information considering all formats v1, v2 & v3.
263  */
264 static const ulint ENCRYPTION_INFO_MAX_SIZE =
265  (ENCRYPTION_INFO_SIZE + sizeof(uint32));
266 
267 /** Default master key for bootstrap */
268 static const char ENCRYPTION_DEFAULT_MASTER_KEY[] = "DefaultMasterKey";
269 
270 /** Default master key id for bootstrap */
271 static const ulint ENCRYPTION_DEFAULT_MASTER_KEY_ID = 0;
272 
273 /** (Un)Encryption Operation information size */
275 
276 /** Encryption Progress information size */
277 static const uint ENCRYPTION_PROGRESS_INFO_SIZE = sizeof(uint);
278 
279 /** Flag bit to indicate if Encryption/Decryption is in progress */
280 #define ENCRYPTION_IN_PROGRESS (1 << 0)
281 #define UNENCRYPTION_IN_PROGRESS (1 << 1)
282 
283 class IORequest;
284 
285 /** Encryption algorithm. */
286 struct Encryption {
287  /** Algorithm types supported */
288  enum Type {
289 
290  /** No encryption */
291  NONE = 0,
292 
293  /** Use AES */
294  AES = 1,
295  };
296 
297  /** Encryption information format version */
298  enum Version {
299 
300  /** Version in 5.7.11 */
302 
303  /** Version in > 5.7.11 */
305 
306  /** Version in > 8.0.4 */
308  };
309 
310  /** Default constructor */
312 
313  /** Specific constructor
314  @param[in] type Algorithm type */
315  explicit Encryption(Type type) : m_type(type) {
316 #ifdef UNIV_DEBUG
317  switch (m_type) {
318  case NONE:
319  case AES:
320 
321  default:
322  ut_error;
323  }
324 #endif /* UNIV_DEBUG */
325  }
326 
327  /** Copy constructor */
328  Encryption(const Encryption &other)
329  : m_type(other.m_type),
330  m_key(other.m_key),
331  m_klen(other.m_klen),
332  m_iv(other.m_iv) {}
333 
334  Encryption &operator=(const Encryption &) = default;
335 
336  /** Check if page is encrypted page or not
337  @param[in] page page which need to check
338  @return true if it is an encrypted page */
339  static bool is_encrypted_page(const byte *page)
340  MY_ATTRIBUTE((warn_unused_result));
341 
342  /** Check if a log block is encrypted or not
343  @param[in] block block which need to check
344  @return true if it is an encrypted block */
345  static bool is_encrypted_log(const byte *block)
346  MY_ATTRIBUTE((warn_unused_result));
347 
348  /** Check the encryption option and set it
349  @param[in] option encryption option
350  @param[in,out] encryption The encryption type
351  @return DB_SUCCESS or DB_UNSUPPORTED */
353  MY_ATTRIBUTE((warn_unused_result));
354 
355  /** Validate the algorithm string.
356  @param[in] option Encryption option
357  @return DB_SUCCESS or error code */
358  static dberr_t validate(const char *option)
359  MY_ATTRIBUTE((warn_unused_result));
360 
361  /** Convert to a "string".
362  @param[in] type The encryption type
363  @return the string representation */
364  static const char *to_string(Type type) MY_ATTRIBUTE((warn_unused_result));
365 
366  /** Check if the string is "empty" or "none".
367  @param[in] algorithm Encryption algorithm to check
368  @return true if no algorithm requested */
369  static bool is_none(const char *algorithm) MY_ATTRIBUTE((warn_unused_result));
370 
371  /** Generate random encryption value for key and iv.
372  @param[in,out] value Encryption value */
373  static void random_value(byte *value);
374 
375  /** Create new master key for key rotation.
376  @param[in,out] master_key master key */
377  static void create_master_key(byte **master_key);
378 
379  /** Get master key by key id.
380  @param[in] master_key_id master key id
381  @param[in] srv_uuid uuid of server instance
382  @param[in,out] master_key master key */
383  static void get_master_key(ulint master_key_id, char *srv_uuid,
384  byte **master_key);
385 
386  /** Get current master key and key id.
387  @param[in,out] master_key_id master key id
388  @param[in,out] master_key master key */
389  static void get_master_key(ulint *master_key_id, byte **master_key);
390 
391  /** Fill the encryption information.
392  @param[in] key encryption key
393  @param[in] iv encryption iv
394  @param[in,out] encrypt_info encryption information
395  @param[in] is_boot if it's for bootstrap
396  @param[in] encrypt_key encrypt with master key
397  @return true if success. */
398  static bool fill_encryption_info(byte *key, byte *iv, byte *encrypt_info,
399  bool is_boot, bool encrypt_key);
400 
401  /** Get master key from encryption information
402  @param[in] encrypt_info encryption information
403  @param[in] version version of encryption information
404  @param[in,out] m_key_id master key id
405  @param[in,out] srv_uuid server uuid
406  @param[in,out] master_key master key
407  @return position after master key id or uuid, or the old position
408  if can't get the master key. */
409  static byte *get_master_key_from_info(byte *encrypt_info, Version version,
410  uint32_t *m_key_id, char *srv_uuid,
411  byte **master_key);
412 
413  /** Decoding the encryption info from the first page of a tablespace.
414  @param[in,out] key key
415  @param[in,out] iv iv
416  @param[in] encryption_info encryption info
417  @param[in] decrypt_key decrypt key using master key
418  @return true if success */
419  static bool decode_encryption_info(byte *key, byte *iv, byte *encryption_info,
420  bool decrypt_key);
421 
422  /** Encrypt the redo log block.
423  @param[in] type IORequest
424  @param[in,out] src_ptr log block which need to encrypt
425  @param[in,out] dst_ptr destination area
426  @return true if success. */
427  bool encrypt_log_block(const IORequest &type, byte *src_ptr, byte *dst_ptr);
428 
429  /** Encrypt the redo log data contents.
430  @param[in] type IORequest
431  @param[in,out] src page data which need to encrypt
432  @param[in] src_len size of the source in bytes
433  @param[in,out] dst destination area
434  @param[in,out] dst_len size of the destination in bytes
435  @return buffer data, dst_len will have the length of the data */
436  byte *encrypt_log(const IORequest &type, byte *src, ulint src_len, byte *dst,
437  ulint *dst_len);
438 
439  /** Encrypt the page data contents. Page type can't be
440  FIL_PAGE_ENCRYPTED, FIL_PAGE_COMPRESSED_AND_ENCRYPTED,
441  FIL_PAGE_ENCRYPTED_RTREE.
442  @param[in] type IORequest
443  @param[in,out] src page data which need to encrypt
444  @param[in] src_len size of the source in bytes
445  @param[in,out] dst destination area
446  @param[in,out] dst_len size of the destination in bytes
447  @return buffer data, dst_len will have the length of the data */
448  byte *encrypt(const IORequest &type, byte *src, ulint src_len, byte *dst,
449  ulint *dst_len) MY_ATTRIBUTE((warn_unused_result));
450 
451  /** Decrypt the log block.
452  @param[in] type IORequest
453  @param[in,out] src data read from disk, decrypted data
454  will be copied to this page
455  @param[in,out] dst scratch area to use for decryption
456  @return DB_SUCCESS or error code */
457  dberr_t decrypt_log_block(const IORequest &type, byte *src, byte *dst);
458 
459  /** Decrypt the log data contents.
460  @param[in] type IORequest
461  @param[in,out] src data read from disk, decrypted data
462  will be copied to this page
463  @param[in] src_len source data length
464  @param[in,out] dst scratch area to use for decryption
465  @param[in] dst_len size of the scratch area in bytes
466  @return DB_SUCCESS or error code */
467  dberr_t decrypt_log(const IORequest &type, byte *src, ulint src_len,
468  byte *dst, ulint dst_len);
469 
470  /** Decrypt the page data contents. Page type must be
471  FIL_PAGE_ENCRYPTED, FIL_PAGE_COMPRESSED_AND_ENCRYPTED,
472  FIL_PAGE_ENCRYPTED_RTREE, if not then the source contents are
473  left unchanged and DB_SUCCESS is returned.
474  @param[in] type IORequest
475  @param[in,out] src data read from disk, decrypt
476  data will be copied to this page
477  @param[in] src_len source data length
478  @param[in,out] dst scratch area to use for decrypt
479  @param[in] dst_len size of the scratch area in bytes
480  @return DB_SUCCESS or error code */
481  dberr_t decrypt(const IORequest &type, byte *src, ulint src_len, byte *dst,
482  ulint dst_len) MY_ATTRIBUTE((warn_unused_result));
483 
484  /** Check if keyring plugin loaded. */
485  static bool check_keyring();
486 
487  /** Encrypt type */
489 
490  /** Encrypt key */
491  byte *m_key;
492 
493  /** Encrypt key length*/
494  ulint m_klen;
495 
496  /** Encrypt initial vector */
497  byte *m_iv;
498 
499  /** Current master key id */
500  static ulint s_master_key_id;
501 
502  /** Current uuid of server instance */
504 };
505 
506 /** Types for AIO operations @{ */
507 
508 /** No transformations during read/write, write as is. */
509 #define IORequestRead IORequest(IORequest::READ)
510 #define IORequestWrite IORequest(IORequest::WRITE)
511 #define IORequestLogRead IORequest(IORequest::LOG | IORequest::READ)
512 #define IORequestLogWrite IORequest(IORequest::LOG | IORequest::WRITE)
513 
514 /**
515 The IO Context that is passed down to the low level IO code */
516 class IORequest {
517  public:
518  /** Flags passed in the request, they can be ORred together. */
519  enum {
520  UNSET = 0,
521  READ = 1,
522  WRITE = 2,
523 
524  /** Double write buffer recovery. */
526 
527  /** Enumerations below can be ORed to READ/WRITE above*/
528 
529  /** Data file */
531 
532  /** Log file request*/
533  LOG = 16,
534 
535  /** Disable partial read warnings */
537 
538  /** Do not to wake i/o-handler threads, but the caller will do
539  the waking explicitly later, in this way the caller can post
540  several requests in a batch; NOTE that the batch must not be
541  so big that it exhausts the slots in AIO arrays! NOTE that
542  a simulated batch may introduce hidden chances of deadlocks,
543  because I/Os are not actually handled until all
544  have been posted: use with great caution! */
546 
547  /** Ignore failed reads of non-existent pages */
549 
550  /** Use punch hole if available, only makes sense if
551  compression algorithm != NONE. Ignored if not set */
552  PUNCH_HOLE = 256,
553 
554  /** Force raw read, do not try to compress/decompress.
555  This can be used to force a read and write without any
556  compression e.g., for redo log, merge sort temporary files
557  and the truncate redo log. */
559  };
560 
561  /** Default constructor */
563  : m_block_size(UNIV_SECTOR_SIZE),
564  m_type(READ),
565  m_compression(),
566  m_encryption() {
567  /* No op */
568  }
569 
570  /**
571  @param[in] type Request type, can be a value that is
572  ORed from the above enum */
573  explicit IORequest(ulint type)
574  : m_block_size(UNIV_SECTOR_SIZE),
575  m_type(static_cast<uint16_t>(type)),
576  m_compression(),
577  m_encryption() {
578  if (is_log()) {
580  }
581 
582  if (!is_punch_hole_supported()) {
584  }
585  }
586 
587  /** @return true if ignore missing flag is set */
588  static bool ignore_missing(ulint type) MY_ATTRIBUTE((warn_unused_result)) {
589  return ((type & IGNORE_MISSING) == IGNORE_MISSING);
590  }
591 
592  /** @return true if it is a read request */
593  bool is_read() const MY_ATTRIBUTE((warn_unused_result)) {
594  return ((m_type & READ) == READ);
595  }
596 
597  /** @return true if it is a write request */
598  bool is_write() const MY_ATTRIBUTE((warn_unused_result)) {
599  return ((m_type & WRITE) == WRITE);
600  }
601 
602  /** @return true if it is a redo log write */
603  bool is_log() const MY_ATTRIBUTE((warn_unused_result)) {
604  return ((m_type & LOG) == LOG);
605  }
606 
607  /** @return true if the simulated AIO thread should be woken up */
608  bool is_wake() const MY_ATTRIBUTE((warn_unused_result)) {
609  return ((m_type & DO_NOT_WAKE) == 0);
610  }
611 
612  /** @return true if partial read warning disabled */
614  MY_ATTRIBUTE((warn_unused_result)) {
615  return ((m_type & DISABLE_PARTIAL_IO_WARNINGS) ==
617  }
618 
619  /** Disable partial read warnings */
621 
622  /** @return true if missing files should be ignored */
623  bool ignore_missing() const MY_ATTRIBUTE((warn_unused_result)) {
624  return (ignore_missing(m_type));
625  }
626 
627  /** @return true if punch hole should be used */
628  bool punch_hole() const MY_ATTRIBUTE((warn_unused_result)) {
629  return ((m_type & PUNCH_HOLE) == PUNCH_HOLE);
630  }
631 
632  /** @return true if the read should be validated */
633  bool validate() const MY_ATTRIBUTE((warn_unused_result)) {
634  ut_a(is_read() ^ is_write());
635 
636  return (!is_read() || !punch_hole());
637  }
638 
639  /** Set the punch hole flag */
640  void set_punch_hole() {
641  if (is_punch_hole_supported()) {
642  m_type |= PUNCH_HOLE;
643  }
644  }
645 
646  /** Clear the do not wake flag */
648 
649  /** Clear the punch hole flag */
651 
652  /** @return the block size to use for IO */
653  ulint block_size() const MY_ATTRIBUTE((warn_unused_result)) {
654  return (m_block_size);
655  }
656 
657  /** Set the block size for IO
658  @param[in] block_size Block size to set */
659  void block_size(ulint block_size) {
660  m_block_size = static_cast<uint32_t>(block_size);
661  }
662 
663  /** Clear all compression related flags */
666 
668  }
669 
670  /** Compare two requests
671  @return true if the are equal */
672  bool operator==(const IORequest &rhs) const { return (m_type == rhs.m_type); }
673 
674  /** Set compression algorithm
675  @param[in] type The compression algorithm to use */
677  if (type == Compression::NONE) {
678  return;
679  }
680 
681  set_punch_hole();
682 
684  }
685 
686  /** Get the compression algorithm.
687  @return the compression algorithm */
688  Compression compression_algorithm() const MY_ATTRIBUTE((warn_unused_result)) {
689  return (m_compression);
690  }
691 
692  /** @return true if the page should be compressed */
693  bool is_compressed() const MY_ATTRIBUTE((warn_unused_result)) {
695  }
696 
697  /** @return true if the page read should not be transformed. */
698  bool is_compression_enabled() const MY_ATTRIBUTE((warn_unused_result)) {
699  return ((m_type & NO_COMPRESSION) == 0);
700  }
701 
702  /** Disable transformations. */
704 
705  /** Set encryption algorithm
706  @param[in] type The encryption algorithm to use */
708  if (type == Encryption::NONE) {
709  return;
710  }
711 
713  }
714 
715  /** Set encryption key and iv
716  @param[in] key The encryption key to use
717  @param[in] key_len length of the encryption key
718  @param[in] iv The encryption iv to use */
719  void encryption_key(byte *key, ulint key_len, byte *iv) {
721  m_encryption.m_klen = key_len;
722  m_encryption.m_iv = iv;
723  }
724 
725  /** Get the encryption algorithm.
726  @return the encryption algorithm */
727  Encryption encryption_algorithm() const MY_ATTRIBUTE((warn_unused_result)) {
728  return (m_encryption);
729  }
730 
731  /** @return true if the page should be encrypted. */
732  bool is_encrypted() const MY_ATTRIBUTE((warn_unused_result)) {
734  }
735 
736  /** Clear all encryption related flags */
739  m_encryption.m_klen = 0;
742  }
743 
744  /** Note that the IO is for double write recovery. */
746 
747  /** @return true if the request is from the dblwr recovery */
748  bool is_dblwr_recover() const MY_ATTRIBUTE((warn_unused_result)) {
749  return ((m_type & DBLWR_RECOVER) == DBLWR_RECOVER);
750  }
751 
752  /** @return true if punch hole is supported */
753  static bool is_punch_hole_supported() {
754  /* In this debugging mode, we act as if punch hole is supported,
755  and then skip any calls to actually punch a hole here.
756  In this way, Transparent Page Compression is still being tested. */
757  DBUG_EXECUTE_IF("ignore_punch_hole", return (true););
758 
759 #if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) || defined(_WIN32)
760  return (true);
761 #else
762  return (false);
763 #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE || _WIN32 */
764  }
765 
766  private:
767  /* File system best block size */
768  uint32_t m_block_size;
769 
770  /** Request type bit flags */
771  uint16_t m_type;
772 
773  /** Compression algorithm */
775 
776  /** Encryption algorithm */
778 };
779 
780 /* @} */
781 
782 /** Sparse file size information. */
784  /** Total size of file in bytes */
786 
787  /** If it is a sparse file then this is the number of bytes
788  actually allocated for the file. */
790 };
791 
792 /** Win NT does not allow more than 64 */
793 static const ulint OS_AIO_N_PENDING_IOS_PER_THREAD = 32;
794 
795 /** Modes for aio operations @{ */
796 enum class AIO_mode : size_t {
797  /** Normal asynchronous i/o not for ibuf pages or ibuf bitmap pages */
798  NORMAL = 21,
799 
800  /** Asynchronous i/o for ibuf pages or ibuf bitmap pages */
801  IBUF = 22,
802 
803  /** Asynchronous i/o for the log */
804  LOG = 23,
805 
806  /** Asynchronous i/o where the calling thread will itself wait for
807  the i/o to complete, doing also the job of the i/o-handler thread;
808  can be used for any pages, ibuf or non-ibuf. This is used to save
809  CPU time, as we can do with fewer thread switches. Plain synchronous
810  I/O is not as good, because it must serialize the file seek and read
811  or write, causing a bottleneck for parallelism. */
812  SYNC = 24
813 };
814 /* @} */
815 
816 extern ulint os_n_file_reads;
817 extern ulint os_n_file_writes;
818 extern ulint os_n_fsyncs;
819 
820 /* File types for directory entry data type */
821 
823  /** Get status failed. */
825 
826  /** stat() failed, with ENAMETOOLONG */
828 
829  /** stat() failed with EACCESS */
831 
832  /** File doesn't exist. */
834 
835  /** File exists but type is unknown. */
837 
838  /** Ordinary file. */
840 
841  /** Directory. */
843 
844  /** Symbolic link. */
846 
847  /** Block device. */
849 };
850 
851 /* Maximum path string length in bytes when referring to tables with in the
852 './databasename/tablename.ibd' path format; we can allocate at least 2 buffers
853 of this size from the thread stack; that is why this should not be made much
854 bigger than 4000 bytes. The maximum path length used by any storage engine
855 in the server must be at least this big. */
856 #define OS_FILE_MAX_PATH 4000
857 #if (FN_REFLEN_SE < OS_FILE_MAX_PATH)
858 #error "(FN_REFLEN_SE < OS_FILE_MAX_PATH)"
859 #endif
860 
861 /** Struct used in fetching information of a file in a directory */
863  char name[OS_FILE_MAX_PATH]; /*!< path to a file */
864  os_file_type_t type; /*!< file type */
865  os_offset_t size; /*!< file size in bytes */
866  os_offset_t alloc_size; /*!< Allocated size for
867  sparse files in bytes */
868  uint32_t block_size; /*!< Block size to use for IO
869  in bytes*/
870  time_t ctime; /*!< creation time */
871  time_t mtime; /*!< modification time */
872  time_t atime; /*!< access time */
873  bool rw_perm; /*!< true if can be opened
874  in read-write mode. Only valid
875  if type == OS_FILE_TYPE_FILE */
876 };
877 
878 #ifndef UNIV_HOTBACKUP
879 /** Create a temporary file. This function is like tmpfile(3), but
880 the temporary file is created in the given parameter path. If the path
881 is null then it will create the file in the mysql server configuration
882 parameter (--tmpdir).
883 @param[in] path location for creating temporary file
884 @return temporary file handle, or NULL on error */
885 FILE *os_file_create_tmpfile(const char *path);
886 #endif /* !UNIV_HOTBACKUP */
887 
888 /**
889 This function attempts to create a directory named pathname. The new directory
890 gets default permissions. On Unix, the permissions are (0770 & ~umask). If the
891 directory exists already, nothing is done and the call succeeds, unless the
892 fail_if_exists arguments is true.
893 
894 @param[in] pathname directory name as null-terminated string
895 @param[in] fail_if_exists if true, pre-existing directory is treated
896  as an error.
897 @return true if call succeeds, false on error */
898 bool os_file_create_directory(const char *pathname, bool fail_if_exists);
899 
900 /** Callback function type to be implemented by caller. It is called for each
901 entry in directory.
902 @param[in] path path to the file
903 @param[in] name name of the file */
904 typedef void (*os_dir_cbk_t)(const char *path, const char *name);
905 
906 /** This function scans the contents of a directory and invokes the callback
907 for each entry.
908 @param[in] path directory name as null-terminated string
909 @param[in] scan_cbk use callback to be called for each entry
910 @param[in] is_drop attempt to drop the directory after scan
911 @return true if call succeeds, false on error */
912 bool os_file_scan_directory(const char *path, os_dir_cbk_t scan_cbk,
913  bool is_delete);
914 
915 /** NOTE! Use the corresponding macro os_file_create_simple(), not directly
916 this function!
917 A simple function to open or create a file.
918 @param[in] name name of the file or path as a null-terminated
919  string
920 @param[in] create_mode create mode
921 @param[in] access_type OS_FILE_READ_ONLY or OS_FILE_READ_WRITE
922 @param[in] read_only if true read only mode checks are enforced
923 @param[out] success true if succeed, false if error
924 @return own: handle to the file, not defined if error, error number
925  can be retrieved with os_file_get_last_error */
926 os_file_t os_file_create_simple_func(const char *name, ulint create_mode,
927  ulint access_type, bool read_only,
928  bool *success);
929 
930 /** NOTE! Use the corresponding macro
931 os_file_create_simple_no_error_handling(), not directly this function!
932 A simple function to open or create a file.
933 @param[in] name name of the file or path as a
934 null-terminated string
935 @param[in] create_mode create mode
936 @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
937  OS_FILE_READ_ALLOW_DELETE; the last option
938  is used by a backup program reading the file
939 @param[in] read_only if true read only mode checks are enforced
940 @param[out] success true if succeeded
941 @return own: handle to the file, not defined if error, error number
942  can be retrieved with os_file_get_last_error */
944  const char *name, ulint create_mode, ulint access_type, bool read_only,
945  bool *success) MY_ATTRIBUTE((warn_unused_result));
946 
947 /** Tries to disable OS caching on an opened file descriptor.
948 @param[in] fd file descriptor to alter
949 @param[in] file_name file name, used in the diagnostic message
950 @param[in] operation_name "open" or "create"; used in the diagnostic
951  message */
952 void os_file_set_nocache(int fd, const char *file_name,
953  const char *operation_name);
954 
955 /** NOTE! Use the corresponding macro os_file_create(), not directly
956 this function!
957 Opens an existing file or creates a new.
958 @param[in] name name of the file or path as a null-terminated
959  string
960 @param[in] create_mode create mode
961 @param[in] purpose OS_FILE_AIO, if asynchronous, non-buffered I/O
962  is desired, OS_FILE_NORMAL, if any normal file;
963  NOTE that it also depends on type, os_aio_..
964  and srv_.. variables whether we really use
965  async I/O or unbuffered I/O: look in the
966  function source code for the exact rules
967 @param[in] type OS_DATA_FILE or OS_LOG_FILE
968 @param[in] read_only if true read only mode checks are enforced
969 @param[in] success true if succeeded
970 @return own: handle to the file, not defined if error, error number
971  can be retrieved with os_file_get_last_error */
972 pfs_os_file_t os_file_create_func(const char *name, ulint create_mode,
973  ulint purpose, ulint type, bool read_only,
974  bool *success)
975  MY_ATTRIBUTE((warn_unused_result));
976 
977 /** Deletes a file. The file has to be closed before calling this.
978 @param[in] name file path as a null-terminated string
979 @return true if success */
980 bool os_file_delete_func(const char *name);
981 
982 /** Deletes a file if it exists. The file has to be closed before calling this.
983 @param[in] name file path as a null-terminated string
984 @param[out] exist indicate if file pre-exist
985 @return true if success */
986 bool os_file_delete_if_exists_func(const char *name, bool *exist);
987 
988 /** NOTE! Use the corresponding macro os_file_rename(), not directly
989 this function!
990 Renames a file (can also move it to another directory). It is safest that the
991 file is closed before calling this function.
992 @param[in] oldpath old file path as a null-terminated string
993 @param[in] newpath new file path
994 @return true if success */
995 bool os_file_rename_func(const char *oldpath, const char *newpath);
996 
997 /** NOTE! Use the corresponding macro os_file_close(), not directly this
998 function!
999 Closes a file handle. In case of error, error number can be retrieved with
1000 os_file_get_last_error.
1001 @param[in] file own: handle to a file
1002 @return true if success */
1003 bool os_file_close_func(os_file_t file);
1004 
1005 #ifdef UNIV_PFS_IO
1006 
1007 /* Keys to register InnoDB I/O with performance schema */
1014 
1015 /* Following four macros are instumentations to register
1016 various file I/O operations with performance schema.
1017 1) register_pfs_file_open_begin() and register_pfs_file_open_end() are
1018 used to register file creation, opening and closing.
1019 2) register_pfs_file_rename_begin() and register_pfs_file_rename_end()
1020 are used to register file renaming.
1021 3) register_pfs_file_io_begin() and register_pfs_file_io_end() are
1022 used to register actual file read, write and flush
1023 4) register_pfs_file_close_begin() and register_pfs_file_close_end()
1024 are used to register file deletion operations*/
1025 #define register_pfs_file_open_begin(state, locker, key, op, name, src_file, \
1026  src_line) \
1027  do { \
1028  locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
1029  op, name, &locker); \
1030  if (locker != NULL) { \
1031  PSI_FILE_CALL(start_file_open_wait) \
1032  (locker, src_file, static_cast<uint>(src_line)); \
1033  } \
1034  } while (0)
1035 
1036 #define register_pfs_file_open_end(locker, file, result) \
1037  do { \
1038  if (locker != NULL) { \
1039  file.m_psi = PSI_FILE_CALL(end_file_open_wait)(locker, result); \
1040  } \
1041  } while (0)
1042 
1043 #define register_pfs_file_rename_begin(state, locker, key, op, from, to, \
1044  src_file, src_line) \
1045  do { \
1046  locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
1047  op, from, &locker); \
1048  if (locker != nullptr) { \
1049  PSI_FILE_CALL(start_file_rename_wait) \
1050  (locker, (size_t)0, from, to, src_file, static_cast<uint>(src_line)); \
1051  } \
1052  } while (0)
1053 
1054 #define register_pfs_file_rename_end(locker, from, to, result) \
1055  do { \
1056  if (locker != NULL) { \
1057  PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result); \
1058  } \
1059  } while (0)
1060 
1061 #define register_pfs_file_close_begin(state, locker, key, op, name, src_file, \
1062  src_line) \
1063  do { \
1064  locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
1065  op, name, &locker); \
1066  if (locker != NULL) { \
1067  PSI_FILE_CALL(start_file_close_wait) \
1068  (locker, src_file, static_cast<uint>(src_line)); \
1069  } \
1070  } while (0)
1071 
1072 #define register_pfs_file_close_end(locker, result) \
1073  do { \
1074  if (locker != NULL) { \
1075  PSI_FILE_CALL(end_file_close_wait)(locker, result); \
1076  } \
1077  } while (0)
1078 
1079 #define register_pfs_file_io_begin(state, locker, file, count, op, src_file, \
1080  src_line) \
1081  do { \
1082  locker = \
1083  PSI_FILE_CALL(get_thread_file_stream_locker)(state, file.m_psi, op); \
1084  if (locker != NULL) { \
1085  PSI_FILE_CALL(start_file_wait) \
1086  (locker, count, src_file, static_cast<uint>(src_line)); \
1087  } \
1088  } while (0)
1089 
1090 #define register_pfs_file_io_end(locker, count) \
1091  do { \
1092  if (locker != NULL) { \
1093  PSI_FILE_CALL(end_file_wait)(locker, count); \
1094  } \
1095  } while (0)
1096 
1097 /* Following macros/functions are file I/O APIs that would be performance
1098 schema instrumented if "UNIV_PFS_IO" is defined. They would point to
1099 wrapper functions with performance schema instrumentation in such case.
1100 
1101 os_file_create
1102 os_file_create_simple
1103 os_file_create_simple_no_error_handling
1104 os_file_close
1105 os_file_rename
1106 os_aio
1107 os_file_read
1108 os_file_read_no_error_handling
1109 os_file_read_no_error_handling_int_fd
1110 os_file_write
1111 
1112 The wrapper functions have the prefix of "innodb_". */
1113 
1114 #define os_file_create(key, name, create, purpose, type, read_only, success) \
1115  pfs_os_file_create_func(key, name, create, purpose, type, read_only, \
1116  success, __FILE__, __LINE__)
1117 
1118 #define os_file_create_simple(key, name, create, access, read_only, success) \
1119  pfs_os_file_create_simple_func(key, name, create, access, read_only, \
1120  success, __FILE__, __LINE__)
1121 
1122 #define os_file_create_simple_no_error_handling(key, name, create_mode, \
1123  access, read_only, success) \
1124  pfs_os_file_create_simple_no_error_handling_func( \
1125  key, name, create_mode, access, read_only, success, __FILE__, __LINE__)
1126 
1127 #define os_file_close_pfs(file) pfs_os_file_close_func(file, __FILE__, __LINE__)
1128 
1129 #define os_aio(type, mode, name, file, buf, offset, n, read_only, message1, \
1130  message2) \
1131  pfs_os_aio_func(type, mode, name, file, buf, offset, n, read_only, message1, \
1132  message2, __FILE__, __LINE__)
1133 
1134 #define os_file_read_pfs(type, file_name, file, buf, offset, n) \
1135  pfs_os_file_read_func(type, file_name, file, buf, offset, n, __FILE__, \
1136  __LINE__)
1137 
1138 #define os_file_read_first_page_pfs(type, file_name, file, buf, n) \
1139  pfs_os_file_read_first_page_func(type, file_name, file, buf, n, __FILE__, \
1140  __LINE__)
1141 
1142 #define os_file_copy_pfs(src, src_offset, dest, dest_offset, size) \
1143  pfs_os_file_copy_func(src, src_offset, dest, dest_offset, size, __FILE__, \
1144  __LINE__)
1145 
1146 #define os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, \
1147  n, o) \
1148  pfs_os_file_read_no_error_handling_func(type, file_name, file, buf, offset, \
1149  n, o, __FILE__, __LINE__)
1150 
1151 #define os_file_read_no_error_handling_int_fd(type, file_name, file, buf, \
1152  offset, n, o) \
1153  pfs_os_file_read_no_error_handling_int_fd_func( \
1154  type, file_name, file, buf, offset, n, o, __FILE__, __LINE__)
1155 
1156 #define os_file_write_pfs(type, name, file, buf, offset, n) \
1157  pfs_os_file_write_func(type, name, file, buf, offset, n, __FILE__, __LINE__)
1158 
1159 #define os_file_write_int_fd(type, name, file, buf, offset, n) \
1160  pfs_os_file_write_int_fd_func(type, name, file, buf, offset, n, __FILE__, \
1161  __LINE__)
1162 
1163 #define os_file_flush_pfs(file) pfs_os_file_flush_func(file, __FILE__, __LINE__)
1164 
1165 #define os_file_rename(key, oldpath, newpath) \
1166  pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__)
1167 
1168 #define os_file_delete(key, name) \
1169  pfs_os_file_delete_func(key, name, __FILE__, __LINE__)
1170 
1171 #define os_file_delete_if_exists(key, name, exist) \
1172  pfs_os_file_delete_if_exists_func(key, name, exist, __FILE__, __LINE__)
1173 
1174 /** NOTE! Please use the corresponding macro os_file_create_simple(),
1175 not directly this function!
1176 A performance schema instrumented wrapper function for
1177 os_file_create_simple() which opens or creates a file.
1178 @param[in] key Performance Schema Key
1179 @param[in] name name of the file or path as a null-terminated
1180  string
1181 @param[in] create_mode create mode
1182 @param[in] access_type OS_FILE_READ_ONLY or OS_FILE_READ_WRITE
1183 @param[in] read_only if true read only mode checks are enforced
1184 @param[out] success true if succeeded
1185 @param[in] src_file file name where func invoked
1186 @param[in] src_line line where the func invoked
1187 @return own: handle to the file, not defined if error, error number
1188  can be retrieved with os_file_get_last_error */
1189 UNIV_INLINE
1191  mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type,
1192  bool read_only, bool *success, const char *src_file, uint src_line)
1193  MY_ATTRIBUTE((warn_unused_result));
1194 
1195 /** NOTE! Please use the corresponding macro
1196 os_file_create_simple_no_error_handling(), not directly this function!
1197 A performance schema instrumented wrapper function for
1198 os_file_create_simple_no_error_handling(). Add instrumentation to
1199 monitor file creation/open.
1200 @param[in] key Performance Schema Key
1201 @param[in] name name of the file or path as a null-terminated
1202  string
1203 @param[in] create_mode create mode
1204 @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
1205  OS_FILE_READ_ALLOW_DELETE; the last option is
1206  used by a backup program reading the file
1207 @param[in] read_only if true read only mode checks are enforced
1208 @param[out] success true if succeeded
1209 @param[in] src_file file name where func invoked
1210 @param[in] src_line line where the func invoked
1211 @return own: handle to the file, not defined if error, error number
1212  can be retrieved with os_file_get_last_error */
1213 UNIV_INLINE
1215  mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type,
1216  bool read_only, bool *success, const char *src_file, uint src_line)
1217  MY_ATTRIBUTE((warn_unused_result));
1218 
1219 /** NOTE! Please use the corresponding macro os_file_create(), not directly
1220 this function!
1221 A performance schema wrapper function for os_file_create().
1222 Add instrumentation to monitor file creation/open.
1223 @param[in] key Performance Schema Key
1224 @param[in] name name of the file or path as a null-terminated
1225  string
1226 @param[in] create_mode create mode
1227 @param[in] purpose OS_FILE_AIO, if asynchronous, non-buffered I/O
1228  is desired, OS_FILE_NORMAL, if any normal file;
1229  NOTE that it also depends on type, os_aio_..
1230  and srv_.. variables whether we really use
1231  async I/O or unbuffered I/O: look in the
1232  function source code for the exact rules
1233 @param[in] type OS_DATA_FILE or OS_LOG_FILE
1234 @param[in] read_only if true read only mode checks are enforced
1235 @param[out] success true if succeeded
1236 @param[in] src_file file name where func invoked
1237 @param[in] src_line line where the func invoked
1238 @return own: handle to the file, not defined if error, error number
1239  can be retrieved with os_file_get_last_error */
1240 UNIV_INLINE
1242  ulint create_mode, ulint purpose,
1243  ulint type, bool read_only, bool *success,
1244  const char *src_file, uint src_line)
1245  MY_ATTRIBUTE((warn_unused_result));
1246 
1247 /** NOTE! Please use the corresponding macro os_file_close(), not directly
1248 this function!
1249 A performance schema instrumented wrapper function for os_file_close().
1250 @param[in] file handle to a file
1251 @param[in] src_file file name where func invoked
1252 @param[in] src_line line where the func invoked
1253 @return true if success */
1254 UNIV_INLINE
1255 bool pfs_os_file_close_func(pfs_os_file_t file, const char *src_file,
1256  uint src_line);
1257 
1258 /** NOTE! Please use the corresponding macro os_file_read(), not directly
1259 this function!
1260 This is the performance schema instrumented wrapper function for
1261 os_file_read() which requests a synchronous read operation.
1262 @param[in, out] type IO request context
1263 @param[in] file_name file name
1264 @param[in] file Open file handle
1265 @param[out] buf buffer where to read
1266 @param[in] offset file offset where to read
1267 @param[in] n number of bytes to read
1268 @param[in] src_file file name where func invoked
1269 @param[in] src_line line where the func invoked
1270 @return DB_SUCCESS if request was successful */
1271 UNIV_INLINE
1272 dberr_t pfs_os_file_read_func(IORequest &type, const char *file_name,
1273  pfs_os_file_t file, void *buf, os_offset_t offset,
1274  ulint n, const char *src_file, uint src_line);
1275 
1276 /** NOTE! Please use the corresponding macro os_file_read_first_page(),
1277 not directly this function!
1278 This is the performance schema instrumented wrapper function for
1279 os_file_read_first_page() which requests a synchronous read operation
1280 of page 0 of IBD file
1281 @param[in, out] type IO request context
1282 @param[in] file_name file name
1283 @param[in] file Open file handle
1284 @param[out] buf buffer where to read
1285 @param[in] n number of bytes to read
1286 @param[in] src_file file name where func invoked
1287 @param[in] src_line line where the func invoked
1288 @return DB_SUCCESS if request was successful */
1289 UNIV_INLINE
1290 dberr_t pfs_os_file_read_first_page_func(IORequest &type, const char *file_name,
1291  pfs_os_file_t file, void *buf, ulint n,
1292  const char *src_file, uint src_line);
1293 
1294 /** copy data from one file to another file. Data is read/written
1295 at current file offset.
1296 @param[in] src file handle to copy from
1297 @param[in] src_offset offset to copy from
1298 @param[in] dest file handle to copy to
1299 @param[in] dest_offset offset to copy to
1300 @param[in] size number of bytes to copy
1301 @param[in] src_file file name where func invoked
1302 @param[in] src_line line where the func invoked
1303 @return DB_SUCCESS if successful */
1304 UNIV_INLINE
1306  pfs_os_file_t dest, os_offset_t dest_offset,
1307  uint size, const char *src_file, uint src_line);
1308 
1309 /** NOTE! Please use the corresponding macro os_file_read_no_error_handling(),
1310 not directly this function!
1311 This is the performance schema instrumented wrapper function for
1312 os_file_read_no_error_handling_func() which requests a synchronous
1313 read operation.
1314 @param[in, out] type IO request context
1315 @param[in] file_name file name
1316 @param[in] file Open file handle
1317 @param[out] buf buffer where to read
1318 @param[in] offset file offset where to read
1319 @param[in] n number of bytes to read
1320 @param[out] o number of bytes actually read
1321 @param[in] src_file file name where func invoked
1322 @param[in] src_line line where the func invoked
1323 @return DB_SUCCESS if request was successful */
1324 UNIV_INLINE
1326  IORequest &type, const char *file_name, pfs_os_file_t file, void *buf,
1327  os_offset_t offset, ulint n, ulint *o, const char *src_file, uint src_line);
1328 
1329 /** NOTE! Please use the corresponding macro
1330 os_file_read_no_error_handling_int_fd(), not directly this function!
1331 This is the performance schema instrumented wrapper function for
1332 os_file_read_no_error_handling_int_fd_func() which requests a
1333 synchronous read operation on files with int type descriptors.
1334 @param[in, out] type IO request context
1335 @param[in] file_name file name
1336 @param[in] file Open file handle
1337 @param[out] buf buffer where to read
1338 @param[in] offset file offset where to read
1339 @param[in] n number of bytes to read
1340 @param[out] o number of bytes actually read
1341 @param[in] src_file file name where func invoked
1342 @param[in] src_line line where the func invoked
1343 @return DB_SUCCESS if request was successful */
1344 
1345 UNIV_INLINE
1347  IORequest &type, const char *file_name, int file, void *buf,
1348  os_offset_t offset, ulint n, ulint *o, const char *src_file,
1349  ulint src_line);
1350 
1351 /** NOTE! Please use the corresponding macro os_aio(), not directly this
1352 function!
1353 Performance schema wrapper function of os_aio() which requests
1354 an asynchronous I/O operation.
1355 @param[in] type IO request context
1356 @param[in] mode IO mode
1357 @param[in] name Name of the file or path as NUL terminated
1358  string
1359 @param[in] file Open file handle
1360 @param[out] buf buffer where to read
1361 @param[in] offset file offset where to read
1362 @param[in] n number of bytes to read
1363 @param[in] read_only if true read only mode checks are enforced
1364 @param[in,out] m1 Message for the AIO handler, (can be used to
1365  identify a completed AIO operation); ignored
1366  if mode is OS_AIO_SYNC
1367 @param[in,out] m2 message for the AIO handler (can be used to
1368  identify a completed AIO operation); ignored
1369  if mode is OS_AIO_SYNC
1370 @param[in] src_file file name where func invoked
1371 @param[in] src_line line where the func invoked
1372 @return DB_SUCCESS if request was queued successfully, false if fail */
1373 UNIV_INLINE
1374 dberr_t pfs_os_aio_func(IORequest &type, AIO_mode mode, const char *name,
1375  pfs_os_file_t file, void *buf, os_offset_t offset,
1376  ulint n, bool read_only, fil_node_t *m1, void *m2,
1377  const char *src_file, uint src_line);
1378 
1379 /** NOTE! Please use the corresponding macro os_file_write(), not directly
1380 this function!
1381 This is the performance schema instrumented wrapper function for
1382 os_file_write() which requests a synchronous write operation.
1383 @param[in, out] type IO request context
1384 @param[in] name Name of the file or path as NUL terminated
1385  string
1386 @param[in] file Open file handle
1387 @param[out] buf buffer where to read
1388 @param[in] offset file offset where to read
1389 @param[in] n number of bytes to read
1390 @param[in] src_file file name where func invoked
1391 @param[in] src_line line where the func invoked
1392 @return DB_SUCCESS if request was successful */
1393 UNIV_INLINE
1395  pfs_os_file_t file, const void *buf,
1396  os_offset_t offset, ulint n,
1397  const char *src_file, uint src_line);
1398 
1399 /** NOTE! Please use the corresponding macro os_file_write(), not
1400 directly this function!
1401 This is the performance schema instrumented wrapper function for
1402 os_file_write() which requests a synchronous write operation
1403 on files with int type descriptors.
1404 @param[in, out] type IO request context
1405 @param[in] name Name of the file or path as NUL terminated
1406  string
1407 @param[in] file Open file handle
1408 @param[out] buf buffer where to read
1409 @param[in] offset file offset where to read
1410 @param[in] n number of bytes to read
1411 @param[in] src_file file name where func invoked
1412 @param[in] src_line line where the func invoked
1413 @return DB_SUCCESS if request was successful */
1414 UNIV_INLINE
1416  int file, const void *buf,
1417  os_offset_t offset, ulint n,
1418  const char *src_file, ulint src_line);
1419 
1420 /** NOTE! Please use the corresponding macro os_file_flush(), not directly
1421 this function!
1422 This is the performance schema instrumented wrapper function for
1423 os_file_flush() which flushes the write buffers of a given file to the disk.
1424 Flushes the write buffers of a given file to the disk.
1425 @param[in] file Open file handle
1426 @param[in] src_file file name where func invoked
1427 @param[in] src_line line where the func invoked
1428 @return true if success */
1429 UNIV_INLINE
1430 bool pfs_os_file_flush_func(pfs_os_file_t file, const char *src_file,
1431  uint src_line);
1432 
1433 /** NOTE! Please use the corresponding macro os_file_rename(), not directly
1434 this function!
1435 This is the performance schema instrumented wrapper function for
1436 os_file_rename()
1437 @param[in] key Performance Schema Key
1438 @param[in] oldpath old file path as a null-terminated string
1439 @param[in] newpath new file path
1440 @param[in] src_file file name where func invoked
1441 @param[in] src_line line where the func invoked
1442 @return true if success */
1443 UNIV_INLINE
1444 bool pfs_os_file_rename_func(mysql_pfs_key_t key, const char *oldpath,
1445  const char *newpath, const char *src_file,
1446  uint src_line);
1447 
1448 /**
1449 NOTE! Please use the corresponding macro os_file_delete(), not directly
1450 this function!
1451 This is the performance schema instrumented wrapper function for
1452 os_file_delete()
1453 @param[in] key Performance Schema Key
1454 @param[in] name old file path as a null-terminated string
1455 @param[in] src_file file name where func invoked
1456 @param[in] src_line line where the func invoked
1457 @return true if success */
1458 UNIV_INLINE
1460  const char *src_file, uint src_line);
1461 
1462 /**
1463 NOTE! Please use the corresponding macro os_file_delete_if_exists(), not
1464 directly this function!
1465 This is the performance schema instrumented wrapper function for
1466 os_file_delete_if_exists()
1467 @param[in] key Performance Schema Key
1468 @param[in] name old file path as a null-terminated string
1469 @param[in] exist indicate if file pre-exist
1470 @param[in] src_file file name where func invoked
1471 @param[in] src_line line where the func invoked
1472 @return true if success */
1473 UNIV_INLINE
1475  bool *exist, const char *src_file,
1476  uint src_line);
1477 
1478 #else /* UNIV_PFS_IO */
1479 
1480 /* If UNIV_PFS_IO is not defined, these I/O APIs point
1481 to original un-instrumented file I/O APIs */
1482 #define os_file_create(key, name, create, purpose, type, read_only, success) \
1483  os_file_create_func(name, create, purpose, type, read_only, success)
1484 
1485 #define os_file_create_simple(key, name, create_mode, access, read_only, \
1486  success) \
1487  os_file_create_simple_func(name, create_mode, access, read_only, success)
1488 
1489 #define os_file_create_simple_no_error_handling(key, name, create_mode, \
1490  access, read_only, success) \
1491  os_file_create_simple_no_error_handling_func(name, create_mode, access, \
1492  read_only, success)
1493 
1494 #define os_file_close_pfs(file) os_file_close_func(file)
1495 
1496 #define os_aio(type, mode, name, file, buf, offset, n, read_only, message1, \
1497  message2) \
1498  os_aio_func(type, mode, name, file, buf, offset, n, read_only, message1, \
1499  message2)
1500 
1501 #define os_file_read_pfs(type, file_name, file, buf, offset, n) \
1502  os_file_read_func(type, file_name, file, buf, offset, n)
1503 
1504 #define os_file_read_first_page_pfs(type, file_name, file, buf, n) \
1505  os_file_read_first_page_func(type, file_name, file, buf, n)
1506 
1507 #define os_file_copy_pfs(src, src_offset, dest, dest_offset, size) \
1508  os_file_copy_func(src, src_offset, dest, dest_offset, size)
1509 
1510 #define os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, \
1511  n, o) \
1512  os_file_read_no_error_handling_func(type, file_name, file, buf, offset, n, o)
1513 
1514 #define os_file_read_no_error_handling_int_fd(type, file_name, file, buf, \
1515  offset, n, o) \
1516  os_file_read_no_error_handling_func(type, file_name, file, buf, offset, n, o)
1517 
1518 #define os_file_write_pfs(type, name, file, buf, offset, n) \
1519  os_file_write_func(type, name, file, buf, offset, n)
1520 
1521 #define os_file_write_int_fd(type, name, file, buf, offset, n) \
1522  os_file_write_func(type, name, file, buf, offset, n)
1523 
1524 #define os_file_flush_pfs(file) os_file_flush_func(file)
1525 
1526 #define os_file_rename(key, oldpath, newpath) \
1527  os_file_rename_func(oldpath, newpath)
1528 
1529 #define os_file_delete(key, name) os_file_delete_func(name)
1530 
1531 #define os_file_delete_if_exists(key, name, exist) \
1532  os_file_delete_if_exists_func(name, exist)
1533 
1534 #endif /* UNIV_PFS_IO */
1535 
1536 #ifdef UNIV_PFS_IO
1537 #define os_file_close(file) os_file_close_pfs(file)
1538 #else
1539 #define os_file_close(file) os_file_close_pfs((file).m_file)
1540 #endif
1541 
1542 #ifdef UNIV_PFS_IO
1543 #define os_file_read(type, file_name, file, buf, offset, n) \
1544  os_file_read_pfs(type, file_name, file, buf, offset, n)
1545 #else
1546 #define os_file_read(type, file_name, file, buf, offset, n) \
1547  os_file_read_pfs(type, file_name, file.m_file, buf, offset, n)
1548 #endif
1549 
1550 #ifdef UNIV_PFS_IO
1551 #define os_file_read_first_page(type, file_name, file, buf, n) \
1552  os_file_read_first_page_pfs(type, file_name, file, buf, n)
1553 #else
1554 #define os_file_read_first_page(type, file_name, file, buf, n) \
1555  os_file_read_first_page_pfs(type, file_name, file.m_file, buf, n)
1556 #endif
1557 
1558 #ifdef UNIV_PFS_IO
1559 #define os_file_flush(file) os_file_flush_pfs(file)
1560 #else
1561 #define os_file_flush(file) os_file_flush_pfs(file.m_file)
1562 #endif
1563 
1564 #ifdef UNIV_PFS_IO
1565 #define os_file_write(type, name, file, buf, offset, n) \
1566  os_file_write_pfs(type, name, file, buf, offset, n)
1567 #else
1568 #define os_file_write(type, name, file, buf, offset, n) \
1569  os_file_write_pfs(type, name, file.m_file, buf, offset, n)
1570 #endif
1571 
1572 #ifdef UNIV_PFS_IO
1573 #define os_file_copy(src, src_offset, dest, dest_offset, size) \
1574  os_file_copy_pfs(src, src_offset, dest, dest_offset, size)
1575 #else
1576 #define os_file_copy(src, src_offset, dest, dest_offset, size) \
1577  os_file_copy_pfs(src.m_file, src_offset, dest.m_file, dest_offset, size)
1578 #endif
1579 
1580 #ifdef UNIV_PFS_IO
1581 #define os_file_read_no_error_handling(type, file_name, file, buf, offset, n, \
1582  o) \
1583  os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, n, o)
1584 #else
1585 #define os_file_read_no_error_handling(type, file_name, file, buf, offset, n, \
1586  o) \
1587  os_file_read_no_error_handling_pfs(type, file_name, file.m_file, buf, \
1588  offset, n, o)
1589 #endif
1590 
1591 #ifdef UNIV_HOTBACKUP
1592 /** Closes a file handle.
1593 @param[in] file handle to a file
1594 @return true if success */
1595 bool os_file_close_no_error_handling(os_file_t file);
1596 #endif /* UNIV_HOTBACKUP */
1597 
1598 /** Gets a file size.
1599 @param[in] filename handle to a file
1600 @return file size if OK, else set m_total_size to ~0 and m_alloc_size
1601  to errno */
1603  MY_ATTRIBUTE((warn_unused_result));
1604 
1605 /** Gets a file size.
1606 @param[in] file handle to a file
1607 @return file size, or (os_offset_t) -1 on failure */
1609  MY_ATTRIBUTE((warn_unused_result));
1610 
1611 /** Write the specified number of zeros to a file from specific offset.
1612 @param[in] name name of the file or path as a null-terminated
1613  string
1614 @param[in] file handle to a file
1615 @param[in] offset file offset
1616 @param[in] size file size
1617 @param[in] read_only Enable read-only checks if true
1618 @param[in] flush Flush file content to disk
1619 @return true if success */
1620 bool os_file_set_size(const char *name, pfs_os_file_t file, os_offset_t offset,
1621  os_offset_t size, bool read_only, bool flush)
1622  MY_ATTRIBUTE((warn_unused_result));
1623 
1624 /** Truncates a file at its current position.
1625 @param[in,out] file file to be truncated
1626 @return true if success */
1627 bool os_file_set_eof(FILE *file); /*!< in: file to be truncated */
1628 
1629 /** Truncates a file to a specified size in bytes. Do nothing if the size
1630 preserved is smaller or equal than current size of file.
1631 @param[in] pathname file path
1632 @param[in] file file to be truncated
1633 @param[in] size size preserved in bytes
1634 @return true if success */
1635 bool os_file_truncate(const char *pathname, pfs_os_file_t file,
1636  os_offset_t size);
1637 
1638 /** Set read/write position of a file handle to specific offset.
1639 @param[in] pathname file path
1640 @param[in] file file handle
1641 @param[in] offset read/write offset
1642 @return true if success */
1643 bool os_file_seek(const char *pathname, os_file_t file, os_offset_t offset);
1644 
1645 /** NOTE! Use the corresponding macro os_file_flush(), not directly this
1646 function!
1647 Flushes the write buffers of a given file to the disk.
1648 @param[in] file handle to a file
1649 @return true if success */
1650 bool os_file_flush_func(os_file_t file);
1651 
1652 /** Retrieves the last error number if an error occurs in a file io function.
1653 The number should be retrieved before any other OS calls (because they may
1654 overwrite the error number). If the number is not known to this program,
1655 the OS error number + 100 is returned.
1656 @param[in] report_all_errors true if we want an error message printed
1657  for all errors
1658 @return error number, or OS error number + 100 */
1659 ulint os_file_get_last_error(bool report_all_errors);
1660 
1661 /** NOTE! Use the corresponding macro os_file_read(), not directly this
1662 function!
1663 Requests a synchronous read operation.
1664 @param[in] type IO request context
1665 @param[in] file_name file name
1666 @param[in] file Open file handle
1667 @param[out] buf buffer where to read
1668 @param[in] offset file offset where to read
1669 @param[in] n number of bytes to read
1670 @return DB_SUCCESS if request was successful */
1671 dberr_t os_file_read_func(IORequest &type, const char *file_name,
1672  os_file_t file, void *buf, os_offset_t offset,
1673  ulint n) MY_ATTRIBUTE((warn_unused_result));
1674 
1675 /** NOTE! Use the corresponding macro os_file_read_first_page(),
1676 not directly this function!
1677 Requests a synchronous read operation of page 0 of IBD file
1678 @param[in] type IO request context
1679 @param[in] file_name file name
1680 @param[in] file Open file handle
1681 @param[out] buf buffer where to read
1682 @param[in] n number of bytes to read
1683 @return DB_SUCCESS if request was successful */
1684 dberr_t os_file_read_first_page_func(IORequest &type, const char *file_name,
1685  os_file_t file, void *buf, ulint n)
1686  MY_ATTRIBUTE((warn_unused_result));
1687 
1688 /** copy data from one file to another file. Data is read/written
1689 at current file offset.
1690 @param[in] src_file file handle to copy from
1691 @param[in] src_offset offset to copy from
1692 @param[in] dest_file file handle to copy to
1693 @param[in] dest_offset offset to copy to
1694 @param[in] size number of bytes to copy
1695 @return DB_SUCCESS if successful */
1696 dberr_t os_file_copy_func(os_file_t src_file, os_offset_t src_offset,
1697  os_file_t dest_file, os_offset_t dest_offset,
1698  uint size) MY_ATTRIBUTE((warn_unused_result));
1699 
1700 /** Rewind file to its start, read at most size - 1 bytes from it to str, and
1701 NUL-terminate str. All errors are silently ignored. This function is
1702 mostly meant to be used with temporary files.
1703 @param[in,out] file file to read from
1704 @param[in,out] str buffer where to read
1705 @param[in] size size of buffer */
1706 void os_file_read_string(FILE *file, char *str, ulint size);
1707 
1708 /** NOTE! Use the corresponding macro os_file_read_no_error_handling(),
1709 not directly this function!
1710 Requests a synchronous positioned read operation. This function does not do
1711 any error handling. In case of error it returns FALSE.
1712 @param[in] type IO request context
1713 @param[in] file_name file name
1714 @param[in] file Open file handle
1715 @param[out] buf buffer where to read
1716 @param[in] offset file offset where to read
1717 @param[in] n number of bytes to read
1718 @param[out] o number of bytes actually read
1719 @return DB_SUCCESS or error code */
1721  IORequest &type, const char *file_name, os_file_t file, void *buf,
1722  os_offset_t offset, ulint n, ulint *o) MY_ATTRIBUTE((warn_unused_result));
1723 
1724 /** NOTE! Use the corresponding macro os_file_write(), not directly this
1725 function!
1726 Requests a synchronous write operation.
1727 @param[in,out] type IO request context
1728 @param[in] name name of the file or path as a null-terminated
1729  string
1730 @param[in] file Open file handle
1731 @param[out] buf buffer where to read
1732 @param[in] offset file offset where to read
1733 @param[in] n number of bytes to read
1734 @return DB_SUCCESS if request was successful */
1736  const void *buf, os_offset_t offset, ulint n)
1737  MY_ATTRIBUTE((warn_unused_result));
1738 
1739 /** Check the existence and type of the given file.
1740 @param[in] path pathname of the file
1741 @param[out] exists true if file exists
1742 @param[out] type type of the file (if it exists)
1743 @return true if call succeeded */
1744 bool os_file_status(const char *path, bool *exists, os_file_type_t *type);
1745 
1746 /** Create all missing subdirectories along the given path.
1747 @return DB_SUCCESS if OK, otherwise error code. */
1749 
1750 #ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR
1751 /* Test the function os_file_get_parent_dir. */
1752 void unit_test_os_file_get_parent_dir();
1753 #endif /* UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR */
1754 
1755 #ifdef UNIV_HOTBACKUP
1756 /** Deallocates the "Blocks" in block_cache */
1757 void meb_free_block_cache();
1758 #endif /* UNIV_HOTBACKUP */
1759 
1760 /** Creates and initializes block_cache. Creates array of MAX_BLOCKS
1761 and allocates the memory in each block to hold BUFFER_BLOCK_SIZE
1762 of data.
1763 
1764 This function is called by InnoDB during srv_start().
1765 It is also called by MEB while applying the redo logs on TDE tablespaces,
1766 the "Blocks" allocated in this block_cache are used to hold the decrypted
1767 page data. */
1768 void os_create_block_cache();
1769 
1770 /** Initializes the asynchronous io system. Creates one array each for ibuf
1771 and log i/o. Also creates one array each for read and write where each
1772 array is divided logically into n_read_segs and n_write_segs
1773 respectively. The caller must create an i/o handler thread for each
1774 segment in these arrays. This function also creates the sync array.
1775 No i/o handler thread needs to be created for that
1776 @param[in] n_readers number of reader threads
1777 @param[in] n_writers number of writer threads
1778 @param[in] n_slots_sync number of slots in the sync aio array */
1779 
1780 bool os_aio_init(ulint n_readers, ulint n_writers, ulint n_slots_sync);
1781 
1782 /**
1783 Frees the asynchronous io system. */
1784 void os_aio_free();
1785 
1786 /**
1787 NOTE! Use the corresponding macro os_aio(), not directly this function!
1788 Requests an asynchronous i/o operation.
1789 @param[in] type IO request context
1790 @param[in] aio_mode IO mode
1791 @param[in] name Name of the file or path as NUL terminated
1792  string
1793 @param[in] file Open file handle
1794 @param[out] buf buffer where to read
1795 @param[in] offset file offset where to read
1796 @param[in] n number of bytes to read
1797 @param[in] read_only if true read only mode checks are enforced
1798 @param[in,out] m1 Message for the AIO handler, (can be used to
1799  identify a completed AIO operation); ignored
1800  if mode is OS_AIO_SYNC
1801 @param[in,out] m2 message for the AIO handler (can be used to
1802  identify a completed AIO operation); ignored
1803  if mode is OS_AIO_SYNC
1804 @return DB_SUCCESS or error code */
1805 dberr_t os_aio_func(IORequest &type, AIO_mode aio_mode, const char *name,
1806  pfs_os_file_t file, void *buf, os_offset_t offset, ulint n,
1807  bool read_only, fil_node_t *m1, void *m2);
1808 
1809 /** Wakes up all async i/o threads so that they know to exit themselves in
1810 shutdown. */
1812 
1813 /** Waits until there are no pending writes in os_aio_write_array. There can
1814 be other, synchronous, pending writes. */
1816 
1817 /** Wakes up simulated aio i/o-handler threads if they have something to do. */
1819 
1820 /** This function can be called if one wants to post a batch of reads and
1821 prefers an i/o-handler thread to handle them all at once later. You must
1822 call os_aio_simulated_wake_handler_threads later to ensure the threads
1823 are not left sleeping! */
1825 
1826 /** This is the generic AIO handler interface function.
1827 Waits for an aio operation to complete. This function is used to wait the
1828 for completed requests. The AIO array of pending requests is divided
1829 into segments. The thread specifies which segment or slot it wants to wait
1830 for. NOTE: this function will also take care of freeing the aio slot,
1831 therefore no other thread is allowed to do the freeing!
1832 @param[in] segment the number of the segment in the aio arrays to
1833  wait for; segment 0 is the ibuf I/O thread,
1834  segment 1 the log I/O thread, then follow the
1835  non-ibuf read threads, and as the last are the
1836  non-ibuf write threads; if this is
1837  ULINT_UNDEFINED, then it means that sync AIO
1838  is used, and this parameter is ignored
1839 @param[out] m1 the messages passed with the AIO request;
1840  note that also in the case where the AIO
1841  operation failed, these output parameters
1842  are valid and can be used to restart the
1843  operation, for example
1844 @param[out] m2 callback message
1845 @param[out] request OS_FILE_WRITE or ..._READ
1846 @return DB_SUCCESS or error code */
1847 dberr_t os_aio_handler(ulint segment, fil_node_t **m1, void **m2,
1848  IORequest *request);
1849 
1850 /** Prints info of the aio arrays.
1851 @param[in,out] file file where to print */
1852 void os_aio_print(FILE *file);
1853 
1854 /** Refreshes the statistics used to print per-second averages. */
1855 void os_aio_refresh_stats();
1856 
1857 /** Checks that all slots in the system have been freed, that is, there are
1858 no pending io operations. */
1859 bool os_aio_all_slots_free();
1860 
1861 #ifdef UNIV_DEBUG
1862 
1863 /** Prints all pending IO
1864 @param[in] file file where to print */
1865 void os_aio_print_pending_io(FILE *file);
1866 
1867 #endif /* UNIV_DEBUG */
1868 
1869 /** Get available free space on disk
1870 @param[in] path pathname of a directory or file in disk
1871 @param[out] free_space free space available in bytes
1872 @return DB_SUCCESS if all OK */
1873 dberr_t os_get_free_space(const char *path, uint64_t &free_space);
1874 
1875 /** This function returns information about the specified file
1876 @param[in] path pathname of the file
1877 @param[in] stat_info information of a file in a directory
1878 @param[in] check_rw_perm for testing whether the file can be opened
1879  in RW mode
1880 @param[in] read_only if true read only mode checks are enforced
1881 @return DB_SUCCESS if all OK */
1882 dberr_t os_file_get_status(const char *path, os_file_stat_t *stat_info,
1883  bool check_rw_perm, bool read_only);
1884 
1885 #ifndef UNIV_HOTBACKUP
1886 
1887 /** return any of the tmpdir path */
1888 char *innobase_mysql_tmpdir();
1889 /** Creates a temporary file in the location specified by the parameter
1890 path. If the path is NULL then it will be created on --tmpdir location.
1891 This function is defined in ha_innodb.cc.
1892 @param[in] path location for creating temporary file
1893 @return temporary file descriptor, or < 0 on error */
1894 int innobase_mysql_tmpfile(const char *path);
1895 #endif /* !UNIV_HOTBACKUP */
1896 
1897 /** If it is a compressed page return the compressed page data + footer size
1898 @param[in] buf Buffer to check, must include header + 10 bytes
1899 @return ULINT_UNDEFINED if the page is not a compressed page or length
1900  of the compressed data (including footer) if it is a compressed page */
1901 ulint os_file_compressed_page_size(const byte *buf);
1902 
1903 /** If it is a compressed page return the original page data + footer size
1904 @param[in] buf Buffer to check, must include header + 10 bytes
1905 @return ULINT_UNDEFINED if the page is not a compressed page or length
1906  of the original data + footer if it is a compressed page */
1907 ulint os_file_original_page_size(const byte *buf);
1908 
1909 /** Set the file create umask
1910 @param[in] umask The umask to use for file creation. */
1911 void os_file_set_umask(ulint umask);
1912 
1913 /** Get the file create umask
1914 @return the umask to use for file creation. */
1915 ulint os_file_get_umask();
1916 
1917 /** Free storage space associated with a section of the file.
1918 @param[in] fh Open file handle
1919 @param[in] off Starting offset (SEEK_SET)
1920 @param[in] len Size of the hole
1921 @return DB_SUCCESS or error code */
1923  MY_ATTRIBUTE((warn_unused_result));
1924 
1925 /** Check if the file system supports sparse files.
1926 
1927 Warning: On POSIX systems we try and punch a hole from offset 0 to
1928 the system configured page size. This should only be called on an empty
1929 file.
1930 
1931 Note: On Windows we use the name and on Unices we use the file handle.
1932 
1933 @param[in] path File name
1934 @param[in] fh File handle for the file - if opened
1935 @return true if the file system supports sparse files */
1936 bool os_is_sparse_file_supported(const char *path, pfs_os_file_t fh)
1937  MY_ATTRIBUTE((warn_unused_result));
1938 
1939 /** Decompress the page data contents. Page type must be FIL_PAGE_COMPRESSED, if
1940 not then the source contents are left unchanged and DB_SUCCESS is returned.
1941 @param[in] dblwr_recover true of double write recovery in progress
1942 @param[in,out] src Data read from disk, decompressed data will be
1943  copied to this page
1944 @param[in,out] dst Scratch area to use for decompression
1945 @param[in] dst_len Size of the scratch area in bytes
1946 @return DB_SUCCESS or error code */
1947 dberr_t os_file_decompress_page(bool dblwr_recover, byte *src, byte *dst,
1948  ulint dst_len)
1949  MY_ATTRIBUTE((warn_unused_result));
1950 
1951 /** Compress a data page
1952 @param[in] compression Compression algorithm
1953 @param[in] block_size File system block size
1954 @param[in] src Source contents to compress
1955 @param[in] src_len Length in bytes of the source
1956 @param[out] dst Compressed page contents
1957 @param[out] dst_len Length in bytes of dst contents
1958 @return buffer data, dst_len will have the length of the data */
1959 byte *os_file_compress_page(Compression compression, ulint block_size,
1960  byte *src, ulint src_len, byte *dst,
1961  ulint *dst_len);
1962 
1963 /** Determine if O_DIRECT is supported.
1964 @retval true if O_DIRECT is supported.
1965 @retval false if O_DIRECT is not supported. */
1966 bool os_is_o_direct_supported() MY_ATTRIBUTE((warn_unused_result));
1967 
1968 /** Class to scan the directory heirarchy using a depth first scan. */
1969 class Dir_Walker {
1970  public:
1971  using Path = std::string;
1972 
1973  /** Check if the path is a directory. The file/directory must exist.
1974  @param[in] path The path to check
1975  @return true if it is a directory */
1976  static bool is_directory(const Path &path);
1977 
1978  /** Depth first traversal of the directory starting from basedir
1979  @param[in] basedir Start scanning from this directory
1980  @param[in] recursive `true` if scan should be recursive
1981  @param[in] f Function to call for each entry */
1982  template <typename F>
1983  static void walk(const Path &basedir, bool recursive, F &&f) {
1984 #ifdef _WIN32
1985  walk_win32(basedir, recursive,
1986  [&](const Path &path, size_t depth) { f(path); });
1987 #else
1988  walk_posix(basedir, recursive,
1989  [&](const Path &path, size_t depth) { f(path); });
1990 #endif /* _WIN32 */
1991  }
1992 
1993  private:
1994  /** Directory names for the depth first directory scan. */
1995  struct Entry {
1996  /** Constructor
1997  @param[in] path Directory to traverse
1998  @param[in] depth Relative depth to the base
1999  directory in walk() */
2000  Entry(const Path &path, size_t depth) : m_path(path), m_depth(depth) {}
2001 
2002  /** Path to the directory */
2004 
2005  /** Relative depth of m_path */
2006  size_t m_depth;
2007  };
2008 
2009  using Function = std::function<void(const Path &, size_t)>;
2010 
2011  /** Depth first traversal of the directory starting from basedir
2012  @param[in] basedir Start scanning from this directory
2013  @param[in] recursive `true` if scan should be recursive
2014  @param[in] f Callback for each entry found */
2015 #ifdef _WIN32
2016  static void walk_win32(const Path &basedir, bool recursive, Function &&f);
2017 #else
2018  static void walk_posix(const Path &basedir, bool recursive, Function &&f);
2019 #endif /* _WIN32 */
2020 };
2021 
2022 #include "os0file.ic"
2023 
2024 #endif /* os0file_h */
IORequest::m_compression
Compression m_compression
Compression algorithm.
Definition: os0file.h:774
IORequest::IORequest
IORequest(ulint type)
Definition: os0file.h:573
os_file_close_func
bool os_file_close_func(os_file_t file)
NOTE! Use the corresponding macro os_file_close(), not directly this function! Closes a file handle.
Definition: os0file.cc:3443
ENCRYPTION_INFO_MAX_SIZE
static const ulint ENCRYPTION_INFO_MAX_SIZE
Maximum size of Encryption information considering all formats v1, v2 & v3.
Definition: os0file.h:264
os_file_write_func
dberr_t os_file_write_func(IORequest &type, const char *name, os_file_t file, const void *buf, os_offset_t offset, ulint n)
NOTE! Use the corresponding macro os_file_write(), not directly this function! Requests a synchronous...
Definition: os0file.cc:5810
Dir_Walker::Entry::m_depth
size_t m_depth
Relative depth of m_path.
Definition: os0file.h:2006
Encryption::operator=
Encryption & operator=(const Encryption &)=default
OS_FILE_SHARING_VIOLATION
static const ulint OS_FILE_SHARING_VIOLATION
Definition: os0file.h:216
OS_FILE_READ_WRITE
static const ulint OS_FILE_READ_WRITE
Definition: os0file.h:182
Page_fetch::NORMAL
@ NORMAL
Get always.
os_aio_wait_until_no_pending_writes
void os_aio_wait_until_no_pending_writes()
Waits until there are no pending writes in os_aio_write_array.
Definition: os0file.cc:6513
os_file_create_simple_func
os_file_t os_file_create_simple_func(const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success)
NOTE! Use the corresponding macro os_file_create_simple(), not directly this function!...
Definition: os0file.cc:2987
Path
A helper class for handling file paths.
Definition: path.h:37
IORequest::disable_compression
void disable_compression()
Disable transformations.
Definition: os0file.h:703
ENCRYPTION_DEFAULT_MASTER_KEY_ID
static const ulint ENCRYPTION_DEFAULT_MASTER_KEY_ID
Default master key id for bootstrap.
Definition: os0file.h:271
OS_AIO_N_PENDING_IOS_PER_THREAD
static const ulint OS_AIO_N_PENDING_IOS_PER_THREAD
Win NT does not allow more than 64.
Definition: os0file.h:793
IORequest::ignore_missing
static bool ignore_missing(ulint type)
Definition: os0file.h:588
IORequest::DBLWR_RECOVER
@ DBLWR_RECOVER
Double write buffer recovery.
Definition: os0file.h:525
IORequest::punch_hole
bool punch_hole() const
Definition: os0file.h:628
os_fsync_threshold
unsigned long long os_fsync_threshold
Definition: os0file.cc:101
innodb_temp_file_key
mysql_pfs_key_t innodb_temp_file_key
Encryption::m_key
byte * m_key
Encrypt key.
Definition: os0file.h:491
os_file_stat_t::mtime
time_t mtime
modification time
Definition: os0file.h:871
pfs_os_file_read_no_error_handling_int_fd_func
UNIV_INLINE dberr_t pfs_os_file_read_no_error_handling_int_fd_func(IORequest &type, const char *file_name, int file, void *buf, os_offset_t offset, ulint n, ulint *o, const char *src_file, ulint src_line)
NOTE! Please use the corresponding macro os_file_read_no_error_handling_int_fd(), not directly this f...
Compression::Type
Type
Algorithm types supported.
Definition: file.h:52
ENCRYPTION_KEY_LEN
static const ulint ENCRYPTION_KEY_LEN
Encryption key length.
Definition: os0file.h:227
Encryption::AES
@ AES
Use AES.
Definition: os0file.h:294
OS_FILE_ERROR_MAX
static const ulint OS_FILE_ERROR_MAX
Definition: os0file.h:223
Dir_Walker::walk
static void walk(const Path &basedir, bool recursive, F &&f)
Depth first traversal of the directory starting from basedir.
Definition: os0file.h:1983
OS_FILE_TYPE_LINK
@ OS_FILE_TYPE_LINK
Symbolic link.
Definition: os0file.h:845
NULL
#define NULL
Definition: types.h:55
os_file_get_status
dberr_t os_file_get_status(const char *path, os_file_stat_t *stat_info, bool check_rw_perm, bool read_only)
This function returns information about the specified file.
Definition: os0file.cc:5906
Encryption::m_klen
ulint m_klen
Encrypt key length.
Definition: os0file.h:494
innodb_log_file_key
mysql_pfs_key_t innodb_log_file_key
ut_a
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:53
OS_FILE_READ_ALLOW_DELETE
static const ulint OS_FILE_READ_ALLOW_DELETE
Used by MySQLBackup.
Definition: os0file.h:185
os_file_decompress_page
dberr_t os_file_decompress_page(bool dblwr_recover, byte *src, byte *dst, ulint dst_len)
Decompress the page data contents.
Definition: file.cc:260
version
const string version("\"Version\"")
os_file_read_first_page_func
dberr_t os_file_read_first_page_func(IORequest &type, const char *file_name, os_file_t file, void *buf, ulint n)
NOTE! Use the corresponding macro os_file_read_first_page(), not directly this function!...
Definition: os0file.cc:5635
OS_FILE_AIO
static const ulint OS_FILE_AIO
Definition: os0file.h:188
IORequest::block_size
ulint block_size() const
Definition: os0file.h:653
DBUG_EXECUTE_IF
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:169
OS_FILE_OPEN_RETRY
@ OS_FILE_OPEN_RETRY
open with retry
Definition: os0file.h:169
Encryption::to_string
static const char * to_string(Type type)
Convert to a "string".
Definition: os0file.cc:7967
OS_FILE_ALREADY_EXISTS
static const ulint OS_FILE_ALREADY_EXISTS
Definition: os0file.h:210
os_file_get_last_error
ulint os_file_get_last_error(bool report_all_errors)
Retrieves the last error number if an error occurs in a file io function.
Definition: os0file.cc:5270
IORequest::m_type
uint16_t m_type
Request type bit flags.
Definition: os0file.h:771
IORequest::IORequest
IORequest()
Default constructor.
Definition: os0file.h:562
my_dbug.h
os_file_delete_if_exists_func
bool os_file_delete_if_exists_func(const char *name, bool *exist)
Deletes a file if it exists.
Definition: os0file.cc:3365
pfs_os_file_flush_func
UNIV_INLINE bool pfs_os_file_flush_func(pfs_os_file_t file, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_flush(), not directly this function!...
os_file_get_umask
ulint os_file_get_umask()
Get the file create umask.
Definition: os0file.cc:7962
pfs_os_file_create_simple_no_error_handling_func
UNIV_INLINE pfs_os_file_t pfs_os_file_create_simple_no_error_handling_func(mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_create_simple_no_error_handling(),...
OS_FILE_ON_ERROR_NO_EXIT
@ OS_FILE_ON_ERROR_NO_EXIT
Flags that can be combined with the above values.
Definition: os0file.h:174
os_create_block_cache
void os_create_block_cache()
Creates and initializes block_cache.
Definition: os0file.cc:6392
os_file_rename_func
bool os_file_rename_func(const char *oldpath, const char *newpath)
NOTE! Use the corresponding macro os_file_rename(), not directly this function! Renames a file (can a...
Definition: os0file.cc:3412
os_file_set_eof
bool os_file_set_eof(FILE *file)
Truncates a file at its current position.
Definition: os0file.cc:3602
OS_FILE_ERROR_NOT_SPECIFIED
static const ulint OS_FILE_ERROR_NOT_SPECIFIED
Definition: os0file.h:217
AIO_mode::IBUF
@ IBUF
Asynchronous i/o for ibuf pages or ibuf bitmap pages.
OS_FILE_READ_ONLY
static const ulint OS_FILE_READ_ONLY
Definition: os0file.h:181
Encryption::get_master_key_from_info
static byte * get_master_key_from_info(byte *encrypt_info, Version version, uint32_t *m_key_id, char *srv_uuid, byte **master_key)
Get master key from encryption information.
Definition: os0file.cc:8303
IORequest::set_punch_hole
void set_punch_hole()
Set the punch hole flag.
Definition: os0file.h:640
IORequest::is_wake
bool is_wake() const
Definition: os0file.h:608
IORequest
The IO Context that is passed down to the low level IO code.
Definition: os0file.h:516
Version
Class representing a version.
Definition: designator.h:44
IORequest::is_read
bool is_read() const
Definition: os0file.h:593
OS_FILE_TYPE_NAME_TOO_LONG
@ OS_FILE_TYPE_NAME_TOO_LONG
stat() failed, with ENAMETOOLONG
Definition: os0file.h:827
dberr_t
dberr_t
Definition: db0err.h:38
Encryption::is_none
static bool is_none(const char *algorithm)
Check if the string is "empty" or "none".
Definition: ha_innodb.cc:2360
os_file_punch_hole
dberr_t os_file_punch_hole(os_file_t fh, os_offset_t off, os_offset_t len)
Free storage space associated with a section of the file.
Definition: os0file.cc:5844
value
const string value("\"Value\"")
Encryption::fill_encryption_info
static bool fill_encryption_info(byte *key, byte *iv, byte *encrypt_info, bool is_boot, bool encrypt_key)
Fill the encryption information.
Definition: os0file.cc:8203
IORequest::encryption_algorithm
Encryption encryption_algorithm() const
Get the encryption algorithm.
Definition: os0file.h:727
os_aio_simulated_wake_handler_threads
void os_aio_simulated_wake_handler_threads()
Wakes up simulated aio i/o-handler threads if they have something to do.
Definition: os0file.cc:6827
Encryption::set_algorithm
dberr_t set_algorithm(const char *option, Encryption *type)
Check the encryption option and set it.
Definition: ha_innodb.cc:2373
pfs_os_file_t::m_file
os_file_t m_file
Definition: os0file.h:146
ut_error
#define ut_error
Abort execution.
Definition: ut0dbg.h:61
IORequest::dblwr_recover
void dblwr_recover()
Note that the IO is for double write recovery.
Definition: os0file.h:745
Compression::NONE
@ NONE
No compression.
Definition: file.h:58
Encryption::ENCRYPTION_VERSION_2
@ ENCRYPTION_VERSION_2
Version in > 5.7.11.
Definition: os0file.h:304
Encryption::check_keyring
static bool check_keyring()
Check if keyring plugin loaded.
Definition: os0file.cc:9190
key
static const char * key
Definition: suite_stubs.c:14
os_file_type_t
os_file_type_t
Definition: os0file.h:822
Encryption::is_encrypted_log
static bool is_encrypted_log(const byte *block)
Check if a log block is encrypted or not.
Definition: os0file.cc:8537
os_file_stat_t::alloc_size
os_offset_t alloc_size
Allocated size for sparse files in bytes.
Definition: os0file.h:866
os_n_pending_writes
ulint os_n_pending_writes
Number of pending write operations.
Definition: os0file.cc:797
pfs_os_file_delete_if_exists_func
UNIV_INLINE bool pfs_os_file_delete_if_exists_func(mysql_pfs_key_t key, const char *name, bool *exist, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_delete_if_exists(), not directly this function!...
Encryption::Type
Type
Algorithm types supported.
Definition: os0file.h:288
PSI_file
struct PSI_file PSI_file
Definition: psi_file_bits.h:53
ENCRYPTION_KEY_MAGIC_V1
static const char ENCRYPTION_KEY_MAGIC_V1[]
Encryption magic bytes for 5.7.11, it's for checking the encryption information version.
Definition: os0file.h:234
OS_BUFFERED_FILE
static const ulint OS_BUFFERED_FILE
Definition: os0file.h:199
os_dir_cbk_t
void(* os_dir_cbk_t)(const char *path, const char *name)
Callback function type to be implemented by caller.
Definition: os0file.h:904
IORequest::is_compression_enabled
bool is_compression_enabled() const
Definition: os0file.h:698
os_offset_t
ib_uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:81
os_file_status
bool os_file_status(const char *path, bool *exists, os_file_type_t *type)
Check the existence and type of the given file.
Definition: os0file.cc:5831
IORequest::encryption_algorithm
void encryption_algorithm(Encryption::Type type)
Set encryption algorithm.
Definition: os0file.h:707
OS_FILE_TYPE_BLOCK
@ OS_FILE_TYPE_BLOCK
Block device.
Definition: os0file.h:848
OS_FILE_ACCESS_VIOLATION
static const ulint OS_FILE_ACCESS_VIOLATION
Definition: os0file.h:221
ENCRYPTION_KEY_MAGIC_V3
static const char ENCRYPTION_KEY_MAGIC_V3[]
Encryption magic bytes for 8.0.5+, it's for checking the encryption information version.
Definition: os0file.h:242
IORequest::is_partial_io_warning_disabled
bool is_partial_io_warning_disabled() const
Definition: os0file.h:613
read_only
bool read_only
Definition: mysqld.cc:1054
IORequest::READ
@ READ
Definition: os0file.h:521
ENCRYPTION_OPERATION_INFO_SIZE
static const uint ENCRYPTION_OPERATION_INFO_SIZE
(Un)Encryption Operation information size
Definition: os0file.h:274
flush
void flush(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:97
os_file_compress_page
byte * os_file_compress_page(Compression compression, ulint block_size, byte *src, ulint src_len, byte *dst, ulint *dst_len)
Compress a data page.
Definition: os0file.cc:1333
ENCRYPTION_INFO_SIZE
static const ulint ENCRYPTION_INFO_SIZE
Encryption information total size: magic number + master_key_id + key + iv + server_uuid + checksum.
Definition: os0file.h:258
Dir_Walker::Entry
Directory names for the depth first directory scan.
Definition: os0file.h:1995
OS_DATA_FILE
static const ulint OS_DATA_FILE
Types for file create.
Definition: os0file.h:193
pfs_os_file_write_int_fd_func
UNIV_INLINE dberr_t pfs_os_file_write_int_fd_func(IORequest &type, const char *name, int file, const void *buf, os_offset_t offset, ulint n, const char *src_file, ulint src_line)
NOTE! Please use the corresponding macro os_file_write(), not directly this function!...
OS_FILE_OPEN
@ OS_FILE_OPEN
to open an existing file (if doesn't exist, error)
Definition: os0file.h:162
Compression
Compression algorithm.
Definition: file.h:50
pfs_os_file_close_func
UNIV_INLINE bool pfs_os_file_close_func(pfs_os_file_t file, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_close(), not directly this function!...
OS_FILE_CREATE_PATH
@ OS_FILE_CREATE_PATH
to create the directories
Definition: os0file.h:168
os_file_read_func
dberr_t os_file_read_func(IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n)
NOTE! Use the corresponding macro os_file_read(), not directly this function! Requests a synchronous ...
Definition: os0file.cc:5617
OS_FILE_NORMAL
static const ulint OS_FILE_NORMAL
Definition: os0file.h:189
HANDLE
#define HANDLE
Definition: violite.h:158
os_aio_refresh_stats
void os_aio_refresh_stats()
Refreshes the statistics used to print per-second averages.
Definition: os0file.cc:7880
Encryption::create_master_key
static void create_master_key(byte **master_key)
Create new master key for key rotation.
Definition: os0file.cc:7990
os_aio_free
void os_aio_free()
Frees the asynchronous io system.
Definition: os0file.cc:6459
IORequest::DATA_FILE
@ DATA_FILE
Enumerations below can be ORed to READ/WRITE above.
Definition: os0file.h:530
OS_FILE_INSUFFICIENT_RESOURCE
static const ulint OS_FILE_INSUFFICIENT_RESOURCE
Definition: os0file.h:218
IORequest::is_encrypted
bool is_encrypted() const
Definition: os0file.h:732
pfs_os_file_read_func
UNIV_INLINE dberr_t pfs_os_file_read_func(IORequest &type, const char *file_name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_read(), not directly this function!...
os_aio_handler
dberr_t os_aio_handler(ulint segment, fil_node_t **m1, void **m2, IORequest *request)
This is the generic AIO handler interface function.
Definition: os0file.cc:5954
Dir_Walker
Class to scan the directory heirarchy using a depth first scan.
Definition: os0file.h:1969
IORequest::NO_COMPRESSION
@ NO_COMPRESSION
Force raw read, do not try to compress/decompress.
Definition: os0file.h:558
os_file_set_umask
void os_file_set_umask(ulint umask)
Set the file create umask.
Definition: os0file.cc:7958
IORequest::operator==
bool operator==(const IORequest &rhs) const
Compare two requests.
Definition: os0file.h:672
time.h
os_get_free_space
dberr_t os_get_free_space(const char *path, uint64_t &free_space)
Get available free space on disk.
Definition: os0file.cc:5887
OS_FILE_TYPE_UNKNOWN
@ OS_FILE_TYPE_UNKNOWN
File exists but type is unknown.
Definition: os0file.h:836
page
int page
Definition: ctype-mb.cc:1232
os_file_t
int os_file_t
File handle.
Definition: os0file.h:115
OS_FILE_TYPE_FAILED
@ OS_FILE_TYPE_FAILED
Get status failed.
Definition: os0file.h:824
OS_CLONE_LOG_FILE
static const ulint OS_CLONE_LOG_FILE
Definition: os0file.h:202
os_file_set_size
bool os_file_set_size(const char *name, pfs_os_file_t file, os_offset_t offset, os_offset_t size, bool read_only, bool flush)
Write the specified number of zeros to a file from specific offset.
Definition: os0file.cc:5449
pfs_os_file_read_no_error_handling_func
UNIV_INLINE dberr_t pfs_os_file_read_no_error_handling_func(IORequest &type, const char *file_name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, ulint *o, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_read_no_error_handling(), not directly this function...
pfs_os_file_t::m_psi
struct PSI_file * m_psi
Definition: os0file.h:138
uint
unsigned int uint
Definition: uca-dump.cc:29
OS_REDO_LOG_ARCHIVE_FILE
static const ulint OS_REDO_LOG_ARCHIVE_FILE
Definition: os0file.h:204
innobase_mysql_tmpfile
int innobase_mysql_tmpfile(const char *path)
Creates a temporary file in the location specified by the parameter path.
Definition: ha_innodb.cc:2205
os_file_truncate
bool os_file_truncate(const char *pathname, pfs_os_file_t file, os_offset_t size)
Truncates a file to a specified size in bytes.
Definition: os0file.cc:5557
IORequest::m_encryption
Encryption m_encryption
Encryption algorithm.
Definition: os0file.h:777
pfs_os_file_t
Common file descriptor for file IO instrumentation with PFS on windows and other platforms.
Definition: os0file.h:136
Dir_Walker::Entry::m_path
Path m_path
Path to the directory.
Definition: os0file.h:2003
Encryption::validate
static dberr_t validate(const char *option)
Validate the algorithm string.
Definition: ha_innodb.cc:2390
os_n_file_reads
ulint os_n_file_reads
Definition: os0file.cc:789
IORequest::clear_punch_hole
void clear_punch_hole()
Clear the punch hole flag.
Definition: os0file.h:650
os_file_read_no_error_handling_func
dberr_t os_file_read_no_error_handling_func(IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n, ulint *o)
NOTE! Use the corresponding macro os_file_read_no_error_handling(), not directly this function!...
Definition: os0file.cc:5790
IORequest::disable_partial_io_warnings
void disable_partial_io_warnings()
Disable partial read warnings.
Definition: os0file.h:620
os_is_sparse_file_supported
bool os_is_sparse_file_supported(const char *path, pfs_os_file_t fh)
Check if the file system supports sparse files.
Definition: os0file.cc:5868
os_n_fsyncs
ulint os_n_fsyncs
Definition: os0file.cc:792
Encryption::decrypt
dberr_t decrypt(const IORequest &type, byte *src, ulint src_len, byte *dst, ulint dst_len)
Decrypt the page data contents.
Definition: os0file.cc:9029
os_file_create_func
pfs_os_file_t os_file_create_func(const char *name, ulint create_mode, ulint purpose, ulint type, bool read_only, bool *success)
NOTE! Use the corresponding macro os_file_create(), not directly this function! Opens an existing fil...
Definition: os0file.cc:3148
ENCRYPTION_KEY_MAGIC_V2
static const char ENCRYPTION_KEY_MAGIC_V2[]
Encryption magic bytes for 5.7.12+, it's for checking the encryption information version.
Definition: os0file.h:238
OS_FILE_AIO_RESOURCES_RESERVED
static const ulint OS_FILE_AIO_RESOURCES_RESERVED
wait for OS aio resources to become available again
Definition: os0file.h:214
pfs_os_file_create_simple_func
UNIV_INLINE pfs_os_file_t pfs_os_file_create_simple_func(mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_create_simple(), not directly this function!...
os_aio_wake_all_threads_at_shutdown
void os_aio_wake_all_threads_at_shutdown()
Wakes up all async i/o threads so that they know to exit themselves in shutdown.
Definition: os0file.cc:6483
os_file_copy_func
dberr_t os_file_copy_func(os_file_t src_file, os_offset_t src_offset, os_file_t dest_file, os_offset_t dest_offset, uint size)
copy data from one file to another file.
Definition: os0file.cc:5767
OS_FILE_OPEN_RAW
@ OS_FILE_OPEN_RAW
to open a raw device or disk partition
Definition: os0file.h:166
Dir_Walker::Entry::Entry
Entry(const Path &path, size_t depth)
Constructor.
Definition: os0file.h:2000
IORequest::is_dblwr_recover
bool is_dblwr_recover() const
Definition: os0file.h:748
mysql_pfs_key_t
Define for performance schema registration key.
Definition: sync0sync.h:50
os_file_stat_t::type
os_file_type_t type
file type
Definition: os0file.h:864
IORequest::encryption_key
void encryption_key(byte *key, ulint key_len, byte *iv)
Set encryption key and iv.
Definition: os0file.h:719
os_file_stat_t::rw_perm
bool rw_perm
true if can be opened in read-write mode.
Definition: os0file.h:873
os_file_set_nocache
void os_file_set_nocache(int fd, const char *file_name, const char *operation_name)
Tries to disable OS caching on an opened file descriptor.
Definition: os0file.cc:5394
OS_LOG_FILE
static const ulint OS_LOG_FILE
Definition: os0file.h:194
OS_FILE_TYPE_MISSING
@ OS_FILE_TYPE_MISSING
File doesn't exist.
Definition: os0file.h:833
IORequest::WRITE
@ WRITE
Definition: os0file.h:522
innobase_mysql_tmpdir
char * innobase_mysql_tmpdir()
return any of the tmpdir path
Definition: ha_innodb.cc:2199
os_file_stat_t::atime
time_t atime
access time
Definition: os0file.h:872
os_file_create_subdirs_if_needed
dberr_t os_file_create_subdirs_if_needed(const char *path)
Create all missing subdirectories along the given path.
Definition: os0file.cc:1862
ENCRYPTION_PROGRESS_INFO_SIZE
static const uint ENCRYPTION_PROGRESS_INFO_SIZE
Encryption Progress information size.
Definition: os0file.h:277
OS_FILE_TYPE_DIR
@ OS_FILE_TYPE_DIR
Directory.
Definition: os0file.h:842
os_file_create_directory
bool os_file_create_directory(const char *pathname, bool fail_if_exists)
This function attempts to create a directory named pathname.
Definition: os0file.cc:3078
os_aio_print
void os_aio_print(FILE *file)
Prints info of the aio arrays.
Definition: os0file.cc:7817
IORequest::clear_compressed
void clear_compressed()
Clear all compression related flags.
Definition: os0file.h:664
uint32
uint32_t uint32
Definition: my_inttypes.h:66
Encryption::s_uuid
static char s_uuid[ENCRYPTION_SERVER_UUID_LEN+1]
Current uuid of server instance.
Definition: os0file.h:503
OS_FILE_AIO_INTERRUPTED
static const ulint OS_FILE_AIO_INTERRUPTED
Definition: os0file.h:219
Encryption::encrypt
byte * encrypt(const IORequest &type, byte *src, ulint src_len, byte *dst, ulint *dst_len)
Encrypt the page data contents.
Definition: os0file.cc:8717
exists
static int exists(node_address *name, node_list const *nodes, u_int with_uid)
Definition: node_list.c:108
pfs_os_aio_func
UNIV_INLINE dberr_t pfs_os_aio_func(IORequest &type, AIO_mode mode, const char *name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, bool read_only, fil_node_t *m1, void *m2, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_aio(), not directly this function! Performance schema wra...
os_file_size_t
Sparse file size information.
Definition: os0file.h:783
os_file_stat_t::ctime
time_t ctime
creation time
Definition: os0file.h:870
os_aio_all_slots_free
bool os_aio_all_slots_free()
Checks that all slots in the system have been freed, that is, there are no pending io operations.
Definition: os0file.cc:7899
Encryption::m_type
Type m_type
Encrypt type.
Definition: os0file.h:488
consts::FILE
const std::string FILE("FILE")
IORequest::clear_do_not_wake
void clear_do_not_wake()
Clear the do not wake flag.
Definition: os0file.h:647
OS_FILE_NOT_FOUND
static const ulint OS_FILE_NOT_FOUND
Error codes from os_file_get_last_error.
Definition: os0file.h:208
Encryption::get_master_key
static void get_master_key(ulint master_key_id, char *srv_uuid, byte **master_key)
Get master key by key id.
Definition: os0file.cc:8033
os_n_file_writes
ulint os_n_file_writes
Definition: os0file.cc:791
IORequest::is_punch_hole_supported
static bool is_punch_hole_supported()
Definition: os0file.h:753
IORequest::is_write
bool is_write() const
Definition: os0file.h:598
Compression::m_type
Type m_type
Compression type.
Definition: file.h:157
OS_CLONE_DATA_FILE
static const ulint OS_CLONE_DATA_FILE
Definition: os0file.h:201
IORequest::PUNCH_HOLE
@ PUNCH_HOLE
Use punch hole if available, only makes sense if compression algorithm != NONE.
Definition: os0file.h:552
Encryption::NONE
@ NONE
No encryption.
Definition: os0file.h:291
IORequest::compression_algorithm
Compression compression_algorithm() const
Get the compression algorithm.
Definition: os0file.h:688
ENCRYPTION_DEFAULT_MASTER_KEY
static const char ENCRYPTION_DEFAULT_MASTER_KEY[]
Default master key for bootstrap.
Definition: os0file.h:268
path
static char * path
Definition: mysqldump.cc:130
name
const string name("\"Name\"")
pfs_os_file_copy_func
UNIV_INLINE dberr_t pfs_os_file_copy_func(pfs_os_file_t src, os_offset_t src_offset, pfs_os_file_t dest, os_offset_t dest_offset, uint size, const char *src_file, uint src_line)
copy data from one file to another file.
os_file_stat_t
Struct used in fetching information of a file in a directory.
Definition: os0file.h:862
IORequest::block_size
void block_size(ulint block_size)
Set the block size for IO.
Definition: os0file.h:659
AIO_mode::SYNC
@ SYNC
Asynchronous i/o where the calling thread will itself wait for the i/o to complete,...
ENCRYPTION_MASTER_KEY_NAME_MAX_LEN
static const ulint ENCRYPTION_MASTER_KEY_NAME_MAX_LEN
Encryption master key prifix size.
Definition: os0file.h:251
innodb_arch_file_key
mysql_pfs_key_t innodb_arch_file_key
OS_FILE_NAME_TOO_LONG
static const ulint OS_FILE_NAME_TOO_LONG
Definition: os0file.h:222
IORequest::UNSET
@ UNSET
Definition: os0file.h:520
innodb_tablespace_open_file_key
mysql_pfs_key_t innodb_tablespace_open_file_key
IORequest::validate
bool validate() const
Definition: os0file.h:633
AIO_mode
AIO_mode
Modes for aio operations.
Definition: os0file.h:796
option
structure to define some default "config_option" option settings
Definition: innodb_config.h:180
os_n_pending_reads
ulint os_n_pending_reads
Number of pending read operations.
Definition: os0file.cc:799
innodb_data_file_key
mysql_pfs_key_t innodb_data_file_key
Dir_Walker::Function
std::function< void(const Path &, size_t)> Function
Definition: os0file.h:2009
Encryption::ENCRYPTION_VERSION_3
@ ENCRYPTION_VERSION_3
Version in > 8.0.4.
Definition: os0file.h:307
os_file_original_page_size
ulint os_file_original_page_size(const byte *buf)
If it is a compressed page return the original page data + footer size.
Definition: os0file.cc:1160
os_file_get_size
os_file_size_t os_file_get_size(const char *filename)
Gets a file size.
Definition: os0file.cc:3471
Encryption::decrypt_log_block
dberr_t decrypt_log_block(const IORequest &type, byte *src, byte *dst)
Decrypt the log block.
Definition: os0file.cc:8870
os_file_create_t
os_file_create_t
Options for os_file_create_func.
Definition: os0file.h:161
os_is_o_direct_supported
bool os_is_o_direct_supported()
Determine if O_DIRECT is supported.
Definition: os0file.cc:142
os_file_stat_t::block_size
uint32_t block_size
Block size to use for IO in bytes.
Definition: os0file.h:868
os_file_seek
bool os_file_seek(const char *pathname, os_file_t file, os_offset_t offset)
Set read/write position of a file handle to specific offset.
Definition: os0file.cc:5579
os_file_read_string
void os_file_read_string(FILE *file, char *str, ulint size)
Rewind file to its start, read at most size - 1 bytes from it to str, and NUL-terminate str.
Definition: os0file.cc:1639
IORequest::is_compressed
bool is_compressed() const
Definition: os0file.h:693
Encryption::Encryption
Encryption()
Default constructor.
Definition: os0file.h:311
HttpMethod::type
int type
Definition: http_common.h:411
pfs_os_file_delete_func
UNIV_INLINE bool pfs_os_file_delete_func(mysql_pfs_key_t key, const char *name, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_delete(), not directly this function!...
OS_FILE_TYPE_FILE
@ OS_FILE_TYPE_FILE
Ordinary file.
Definition: os0file.h:839
IORequest::ignore_missing
bool ignore_missing() const
Definition: os0file.h:623
Encryption::s_master_key_id
static ulint s_master_key_id
Current master key id.
Definition: os0file.h:500
OS_FILE_CLOSED
static const os_file_t OS_FILE_CLOSED
Definition: os0file.h:149
os_file_create_tmpfile
FILE * os_file_create_tmpfile(const char *path)
Create a temporary file.
Definition: os0file.cc:1612
IORequest::compression_algorithm
void compression_algorithm(Compression::Type type)
Set compression algorithm.
Definition: os0file.h:676
os_aio_simulated_put_read_threads_to_sleep
void os_aio_simulated_put_read_threads_to_sleep()
This function can be called if one wants to post a batch of reads and prefers an i/o-handler thread t...
Definition: os0file.cc:3620
pfs_os_file_read_first_page_func
UNIV_INLINE dberr_t pfs_os_file_read_first_page_func(IORequest &type, const char *file_name, pfs_os_file_t file, void *buf, ulint n, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_read_first_page(), not directly this function!...
os_aio_init
bool os_aio_init(ulint n_readers, ulint n_writers, ulint n_slots_sync)
Initializes the asynchronous io system.
Definition: os0file.cc:6439
os_has_said_disk_full
bool os_has_said_disk_full
Definition: os0file.cc:802
pfs_os_file_write_func
UNIV_INLINE dberr_t pfs_os_file_write_func(IORequest &type, const char *name, pfs_os_file_t file, const void *buf, os_offset_t offset, ulint n, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_write(), not directly this function!...
innodb_clone_file_key
mysql_pfs_key_t innodb_clone_file_key
OS_FILE_PERMISSION_ERROR
@ OS_FILE_PERMISSION_ERROR
stat() failed with EACCESS
Definition: os0file.h:830
AIO_mode::LOG
@ LOG
Asynchronous i/o for the log.
os_file_delete_func
bool os_file_delete_func(const char *name)
Deletes a file.
Definition: os0file.cc:3393
ENCRYPTION_SERVER_UUID_LEN
static const ulint ENCRYPTION_SERVER_UUID_LEN
UUID of server instance, it's needed for composing master key name.
Definition: os0file.h:254
Encryption::random_value
static void random_value(byte *value)
Generate random encryption value for key and iv.
Definition: os0file.cc:7982
pfs_os_file_rename_func
UNIV_INLINE bool pfs_os_file_rename_func(mysql_pfs_key_t key, const char *oldpath, const char *newpath, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_rename(), not directly this function!...
Encryption::m_iv
byte * m_iv
Encrypt initial vector.
Definition: os0file.h:497
Encryption::Encryption
Encryption(const Encryption &other)
Copy constructor.
Definition: os0file.h:328
IORequest::DISABLE_PARTIAL_IO_WARNINGS
@ DISABLE_PARTIAL_IO_WARNINGS
Disable partial read warnings.
Definition: os0file.h:536
IORequest::IGNORE_MISSING
@ IGNORE_MISSING
Ignore failed reads of non-existent pages.
Definition: os0file.h:548
file.h
NOTE: The functions in this file should only use functions from other files in library.
OS_FILE_MAX_PATH
#define OS_FILE_MAX_PATH
Definition: os0file.h:856
ENCRYPTION_MASTER_KEY_PRIFIX
static const char ENCRYPTION_MASTER_KEY_PRIFIX[]
Encryption master key prifix.
Definition: os0file.h:245
pfs_os_file_create_func
UNIV_INLINE pfs_os_file_t pfs_os_file_create_func(mysql_pfs_key_t key, const char *name, ulint create_mode, ulint purpose, ulint type, bool read_only, bool *success, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_create(), not directly this function!...
IORequest::LOG
@ LOG
Log file request.
Definition: os0file.h:533
Encryption::decrypt_log
dberr_t decrypt_log(const IORequest &type, byte *src, ulint src_len, byte *dst, ulint dst_len)
Decrypt the log data contents.
Definition: os0file.cc:8961
my_io.h
OS_FILE_OPERATION_ABORTED
static const ulint OS_FILE_OPERATION_ABORTED
Definition: os0file.h:220
os_aio_func
dberr_t os_aio_func(IORequest &type, AIO_mode aio_mode, const char *name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, bool read_only, fil_node_t *m1, void *m2)
NOTE! Use the corresponding macro os_aio(), not directly this function! Requests an asynchronous i/o ...
Definition: os0file.cc:7070
n
int n
Definition: xcom_base.c:425
os_file_stat_t::name
char name[OS_FILE_MAX_PATH]
path to a file
Definition: os0file.h:863
IORequest::is_log
bool is_log() const
Definition: os0file.h:603
os_file_compressed_page_size
ulint os_file_compressed_page_size(const byte *buf)
If it is a compressed page return the compressed page data + footer size.
Definition: os0file.cc:1144
OS_FILE_PATH_ERROR
static const ulint OS_FILE_PATH_ERROR
Definition: os0file.h:211
Encryption::encrypt_log
byte * encrypt_log(const IORequest &type, byte *src, ulint src_len, byte *dst, ulint *dst_len)
Encrypt the redo log data contents.
Definition: os0file.cc:8667
Encryption
Encryption algorithm.
Definition: os0file.h:286
IORequest::clear_encrypted
void clear_encrypted()
Clear all encryption related flags.
Definition: os0file.h:737
os_file_size_t::m_total_size
os_offset_t m_total_size
Total size of file in bytes.
Definition: os0file.h:785
ENCRYPTION_MASTER_KEY_PRIFIX_LEN
static const ulint ENCRYPTION_MASTER_KEY_PRIFIX_LEN
Encryption master key prifix size.
Definition: os0file.h:248
Encryption::is_encrypted_page
static bool is_encrypted_page(const byte *page)
Check if page is encrypted page or not.
Definition: os0file.cc:8526
os_aio_print_pending_io
void os_aio_print_pending_io(FILE *file)
Prints all pending IO.
Definition: os0file.cc:7951
OS_FILE_ON_ERROR_SILENT
@ OS_FILE_ON_ERROR_SILENT
don't print diagnostic messages to the log unless it is a fatal error, this flag is only used if ON_E...
Definition: os0file.h:175
OS_FILE_DISK_FULL
static const ulint OS_FILE_DISK_FULL
Definition: os0file.h:209
OS_FILE_CREATE
@ OS_FILE_CREATE
to create new file (if exists, error)
Definition: os0file.h:164
fil_node_t
File node of a tablespace or the log data space.
Definition: fil0fil.h:144
Encryption::decode_encryption_info
static bool decode_encryption_info(byte *key, byte *iv, byte *encryption_info, bool decrypt_key)
Decoding the encryption info from the first page of a tablespace.
Definition: os0file.cc:8389
os_file_stat_t::size
os_offset_t size
file size in bytes
Definition: os0file.h:865
IORequest::m_block_size
uint32_t m_block_size
Definition: os0file.h:768
Encryption::ENCRYPTION_VERSION_1
@ ENCRYPTION_VERSION_1
Version in 5.7.11.
Definition: os0file.h:301
os_file_scan_directory
bool os_file_scan_directory(const char *path, os_dir_cbk_t scan_cbk, bool is_delete)
This function scans the contents of a directory and invokes the callback for each entry.
Definition: os0file.cc:3097
ENCRYPTION_MAGIC_SIZE
static const ulint ENCRYPTION_MAGIC_SIZE
Encryption magic bytes size.
Definition: os0file.h:230
Encryption::Encryption
Encryption(Type type)
Specific constructor.
Definition: os0file.h:315
os_file_flush_func
bool os_file_flush_func(os_file_t file)
NOTE! Use the corresponding macro os_file_flush(), not directly this function! Flushes the write buff...
Definition: os0file.cc:2949
os_file_create_simple_no_error_handling_func
pfs_os_file_t os_file_create_simple_no_error_handling_func(const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success)
NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(), not directly this functi...
Definition: os0file.cc:3305
filename
const char * filename
Definition: pfs_example_component_population.cc:64
IORequest::DO_NOT_WAKE
@ DO_NOT_WAKE
Do not to wake i/o-handler threads, but the caller will do the waking explicitly later,...
Definition: os0file.h:545
Encryption::encrypt_log_block
bool encrypt_log_block(const IORequest &type, byte *src_ptr, byte *dst_ptr)
Encrypt the redo log block.
Definition: os0file.cc:8546
os_file_size_t::m_alloc_size
os_offset_t m_alloc_size
If it is a sparse file then this is the number of bytes actually allocated for the file.
Definition: os0file.h:789