1
/***********************************************************************
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
Copyright (C) 2009, Percona Inc.
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
13
This program is free software; you can redistribute it and/or modify it
14
under the terms of the GNU General Public License as published by the
15
Free Software Foundation; version 2 of the License.
17
This program is distributed in the hope that it will be useful, but
18
WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
20
Public License for more details.
22
You should have received a copy of the GNU General Public License along
23
with this program; if not, write to the Free Software Foundation, Inc.,
24
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
***********************************************************************/
28
/**************************************************//**
29
@file include/os0file.h
30
The interface to the operating system file io
32
Created 10/21/1995 Heikki Tuuri
33
*******************************************************/
46
/** File node of a tablespace or the log data space */
47
typedef struct fil_node_struct fil_node_t;
50
extern ibool os_do_not_call_flush_at_each_write;
51
#endif /* UNIV_DO_FLUSH */
52
extern ibool os_has_said_disk_full;
53
/** Flag: enable debug printout for asynchronous i/o */
54
extern ibool os_aio_print_debug;
56
/** Number of pending os_file_pread() operations */
57
extern ulint os_file_n_pending_preads;
58
/** Number of pending os_file_pwrite() operations */
59
extern ulint os_file_n_pending_pwrites;
61
/** Number of pending read operations */
62
extern ulint os_n_pending_reads;
63
/** Number of pending write operations */
64
extern ulint os_n_pending_writes;
68
/** We define always WIN_ASYNC_IO, and check at run-time whether
69
the OS actually supports it: Win 95 does not, NT does. */
72
/** Use unbuffered I/O */
73
#define UNIV_NON_BUFFERED_IO
79
# define os_file_t HANDLE
80
/** Convert a C file descriptor to a native file handle
81
@param fd file descriptor
82
@return native file handle */
83
# define OS_FILE_FROM_FD(fd) (HANDLE) _get_osfhandle(fd)
86
typedef int os_file_t;
87
/** Convert a C file descriptor to a native file handle
88
@param fd file descriptor
89
@return native file handle */
90
# define OS_FILE_FROM_FD(fd) fd
93
/** Umask for creating files */
94
extern ulint os_innodb_umask;
96
/** The next value should be smaller or equal to the smallest sector size used
97
on any disk. A log block is required to be a portion of disk which is written
98
so that if the start and the end of a block get written to disk, then the
99
whole block gets written. This should be true even in most cases of a crash:
100
if this fails for a log block, then it is equivalent to a media failure in the
103
#define OS_FILE_LOG_BLOCK_SIZE 512
105
/** Options for file_create @{ */
106
#define OS_FILE_OPEN 51
107
#define OS_FILE_CREATE 52
108
#define OS_FILE_OVERWRITE 53
109
#define OS_FILE_OPEN_RAW 54
110
#define OS_FILE_CREATE_PATH 55
111
#define OS_FILE_OPEN_RETRY 56 /* for os_file_create() on
112
the first ibdata file */
114
#define OS_FILE_READ_ONLY 333
115
#define OS_FILE_READ_WRITE 444
116
#define OS_FILE_READ_ALLOW_DELETE 555 /* for ibbackup */
118
/* Options for file_create */
119
#define OS_FILE_AIO 61
120
#define OS_FILE_NORMAL 62
123
/** Types for file create @{ */
124
#define OS_DATA_FILE 100
125
#define OS_LOG_FILE 101
128
/** Error codes from os_file_get_last_error @{ */
129
#define OS_FILE_NOT_FOUND 71
130
#define OS_FILE_DISK_FULL 72
131
#define OS_FILE_ALREADY_EXISTS 73
132
#define OS_FILE_PATH_ERROR 74
133
#define OS_FILE_AIO_RESOURCES_RESERVED 75 /* wait for OS aio resources
134
to become available again */
135
#define OS_FILE_SHARING_VIOLATION 76
136
#define OS_FILE_ERROR_NOT_SPECIFIED 77
137
#define OS_FILE_INSUFFICIENT_RESOURCE 78
138
#define OS_FILE_AIO_INTERRUPTED 79
139
#define OS_FILE_OPERATION_ABORTED 80
142
/** Types for aio operations @{ */
143
#define OS_FILE_READ 10
144
#define OS_FILE_WRITE 11
146
#define OS_FILE_LOG 256 /* This can be ORed to type */
149
#define OS_AIO_N_PENDING_IOS_PER_THREAD 32 /*!< Win NT does not allow more
152
/** Modes for aio operations @{ */
153
#define OS_AIO_NORMAL 21 /*!< Normal asynchronous i/o not for ibuf
154
pages or ibuf bitmap pages */
155
#define OS_AIO_IBUF 22 /*!< Asynchronous i/o for ibuf pages or ibuf
157
#define OS_AIO_LOG 23 /*!< Asynchronous i/o for the log */
158
#define OS_AIO_SYNC 24 /*!< Asynchronous i/o where the calling thread
159
will itself wait for the i/o to complete,
160
doing also the job of the i/o-handler thread;
161
can be used for any pages, ibuf or non-ibuf.
162
This is used to save CPU time, as we can do
163
with fewer thread switches. Plain synchronous
164
i/o is not as good, because it must serialize
165
the file seek and read or write, causing a
166
bottleneck for parallelism. */
168
#define OS_AIO_SIMULATED_WAKE_LATER 512 /*!< This can be ORed to mode
169
in the call of os_aio(...),
170
if the caller wants to post several i/o
171
requests in a batch, and only after that
172
wake the i/o-handler thread; this has
173
effect only in simulated aio */
176
#define OS_WIN31 1 /*!< Microsoft Windows 3.x */
177
#define OS_WIN95 2 /*!< Microsoft Windows 95 */
178
#define OS_WINNT 3 /*!< Microsoft Windows NT 3.x */
179
#define OS_WIN2000 4 /*!< Microsoft Windows 2000 */
180
#define OS_WINXP 5 /*!< Microsoft Windows XP
181
or Windows Server 2003 */
182
#define OS_WINVISTA 6 /*!< Microsoft Windows Vista
183
or Windows Server 2008 */
184
#define OS_WIN7 7 /*!< Microsoft Windows 7
185
or Windows Server 2008 R2 */
188
extern ulint os_n_file_reads;
189
extern ulint os_n_file_writes;
190
extern ulint os_n_fsyncs;
193
/* Keys to register InnoDB I/O with performance schema */
194
extern mysql_pfs_key_t innodb_file_data_key;
195
extern mysql_pfs_key_t innodb_file_log_key;
196
extern mysql_pfs_key_t innodb_file_temp_key;
198
/* Following four macros are instumentations to register
199
various file I/O operations with performance schema.
200
1) register_pfs_file_open_begin() and register_pfs_file_open_end() are
201
used to register file creation, opening, closing and renaming.
202
2) register_pfs_file_io_begin() and register_pfs_file_io_end() are
203
used to register actual file read, write and flush */
204
# define register_pfs_file_open_begin(state, locker, key, op, name, \
205
src_file, src_line) \
208
locker = PSI_server->get_thread_file_name_locker( \
209
state, key, op, name, &locker); \
211
PSI_server->start_file_open_wait( \
212
locker, src_file, src_line); \
217
# define register_pfs_file_open_end(locker, file) \
220
PSI_server->end_file_open_wait_and_bind_to_descriptor( \
225
# define register_pfs_file_io_begin(state, locker, file, count, op, \
226
src_file, src_line) \
229
locker = PSI_server->get_thread_file_descriptor_locker( \
232
PSI_server->start_file_wait( \
233
locker, count, src_file, src_line); \
238
# define register_pfs_file_io_end(locker, count) \
241
PSI_server->end_file_wait(locker, count); \
244
#endif /* UNIV_PFS_IO */
246
/* Following macros/functions are file I/O APIs that would be performance
247
schema instrumented if "UNIV_PFS_IO" is defined. They would point to
248
wrapper functions with performance schema instrumentation in such case.
251
os_file_create_simple
252
os_file_create_simple_no_error_handling
257
os_file_read_no_error_handling
260
The wrapper functions have the prefix of "innodb_". */
263
# define os_file_create(key, name, create, purpose, type, success) \
264
pfs_os_file_create_func(key, name, create, purpose, type, \
265
success, __FILE__, __LINE__)
267
# define os_file_create_simple(key, name, create, access, success) \
268
pfs_os_file_create_simple_func(key, name, create, access, \
269
success, __FILE__, __LINE__)
271
# define os_file_create_simple_no_error_handling( \
272
key, name, create_mode, access, success) \
273
pfs_os_file_create_simple_no_error_handling_func( \
274
key, name, create_mode, access, success, __FILE__, __LINE__)
276
# define os_file_close(file) \
277
pfs_os_file_close_func(file, __FILE__, __LINE__)
279
# define os_aio(type, mode, name, file, buf, offset, offset_high, \
280
n, message1, message2) \
281
pfs_os_aio_func(type, mode, name, file, buf, offset, \
282
offset_high, n, message1, message2, \
285
# define os_file_read(file, buf, offset, offset_high, n) \
286
pfs_os_file_read_func(file, buf, offset, offset_high, n, \
289
# define os_file_read_no_error_handling(file, buf, offset, \
291
pfs_os_file_read_no_error_handling_func(file, buf, offset, \
295
# define os_file_write(name, file, buf, offset, offset_high, n) \
296
pfs_os_file_write_func(name, file, buf, offset, offset_high, \
297
n, __FILE__, __LINE__)
299
# define os_file_flush(file) \
300
pfs_os_file_flush_func(file, __FILE__, __LINE__)
302
# define os_file_rename(key, oldpath, newpath) \
303
pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__)
304
#else /* UNIV_PFS_IO */
306
/* If UNIV_PFS_IO is not defined, these I/O APIs point
307
to original un-instrumented file I/O APIs */
308
# define os_file_create(key, name, create, purpose, type, success) \
309
os_file_create_func(name, create, purpose, type, success)
311
# define os_file_create_simple(key, name, create, access, success) \
312
os_file_create_simple_func(name, create_mode, access, success)
314
# define os_file_create_simple_no_error_handling( \
315
key, name, create_mode, access, success) \
316
os_file_create_simple_no_error_handling_func( \
317
name, create_mode, access, success)
319
# define os_file_close(file) os_file_close_func(file)
321
# define os_aio(type, mode, name, file, buf, offset, offset_high, \
322
n, message1, message2) \
323
os_aio_func(type, mode, name, file, buf, offset, offset_high, n,\
326
# define os_file_read(file, buf, offset, offset_high, n) \
327
os_file_read_func(file, buf, offset, offset_high, n)
329
# define os_file_read_no_error_handling(file, buf, offset, \
331
os_file_read_no_error_handling_func(file, buf, offset, offset_high, n)
333
# define os_file_write(name, file, buf, offset, offset_high, n) \
334
os_file_write_func(name, file, buf, offset, offset_high, n)
336
# define os_file_flush(file) os_file_flush_func(file)
338
# define os_file_rename(key, oldpath, newpath) \
339
os_file_rename_func(oldpath, newpath)
341
#endif /* UNIV_PFS_IO */
343
/* File types for directory entry data type */
345
enum os_file_type_enum{
346
OS_FILE_TYPE_UNKNOWN = 0,
347
OS_FILE_TYPE_FILE, /* regular file */
348
OS_FILE_TYPE_DIR, /* directory */
349
OS_FILE_TYPE_LINK /* symbolic link */
351
typedef enum os_file_type_enum os_file_type_t;
353
/* Maximum path string length in bytes when referring to tables with in the
354
'./databasename/tablename.ibd' path format; we can allocate at least 2 buffers
355
of this size from the thread stack; that is why this should not be made much
356
bigger than 4000 bytes */
357
#define OS_FILE_MAX_PATH 4000
359
/* Struct used in fetching information of a file in a directory */
360
struct os_file_stat_struct{
361
char name[OS_FILE_MAX_PATH]; /*!< path to a file */
362
os_file_type_t type; /*!< file type */
363
ib_int64_t size; /*!< file size */
364
time_t ctime; /*!< creation time */
365
time_t mtime; /*!< modification time */
366
time_t atime; /*!< access time */
368
typedef struct os_file_stat_struct os_file_stat_t;
371
typedef HANDLE os_file_dir_t; /*!< directory stream */
373
typedef DIR* os_file_dir_t; /*!< directory stream */
376
/***********************************************************************//**
377
Gets the operating system version. Currently works only on Windows.
378
@return OS_WIN95, OS_WIN31, OS_WINNT, OS_WIN2000, OS_WINXP, OS_WINVISTA,
382
os_get_os_version(void);
383
/*===================*/
384
#ifndef UNIV_HOTBACKUP
385
/****************************************************************//**
386
Creates the seek mutexes used in positioned reads and writes. */
389
os_io_init_simple(void);
390
/*===================*/
391
/***********************************************************************//**
392
Creates a temporary file. This function is like tmpfile(3), but
393
the temporary file is created in the MySQL temporary directory.
394
@return temporary file handle, or NULL on error */
397
os_file_create_tmpfile(void);
398
/*========================*/
399
#endif /* !UNIV_HOTBACKUP */
400
/***********************************************************************//**
401
The os_file_opendir() function opens a directory stream corresponding to the
402
directory named by the dirname argument. The directory stream is positioned
403
at the first entry. In both Unix and Windows we automatically skip the '.'
404
and '..' items at the start of the directory listing.
405
@return directory stream, NULL if error */
410
const char* dirname, /*!< in: directory name; it must not
411
contain a trailing '\' or '/' */
412
ibool error_is_fatal);/*!< in: TRUE if we should treat an
413
error as a fatal error; if we try to
414
open symlinks then we do not wish a
415
fatal error if it happens not to be
417
/***********************************************************************//**
418
Closes a directory stream.
419
@return 0 if success, -1 if failure */
424
os_file_dir_t dir); /*!< in: directory stream */
425
/***********************************************************************//**
426
This function returns information of the next file in the directory. We jump
427
over the '.' and '..' entries in the directory.
428
@return 0 if ok, -1 if error, 1 if at the end of the directory */
431
os_file_readdir_next_file(
432
/*======================*/
433
const char* dirname,/*!< in: directory name or path */
434
os_file_dir_t dir, /*!< in: directory stream */
435
os_file_stat_t* info); /*!< in/out: buffer where the info is returned */
436
/*****************************************************************//**
437
This function attempts to create a directory named pathname. The new directory
438
gets default permissions. On Unix, the permissions are (0770 & ~umask). If the
439
directory exists already, nothing is done and the call succeeds, unless the
440
fail_if_exists arguments is true.
441
@return TRUE if call succeeds, FALSE on error */
444
os_file_create_directory(
445
/*=====================*/
446
const char* pathname, /*!< in: directory name as
447
null-terminated string */
448
ibool fail_if_exists);/*!< in: if TRUE, pre-existing directory
449
is treated as an error. */
450
/****************************************************************//**
451
NOTE! Use the corresponding macro os_file_create_simple(), not directly
453
A simple function to open or create a file.
454
@return own: handle to the file, not defined if error, error number
455
can be retrieved with os_file_get_last_error */
458
os_file_create_simple_func(
459
/*=======================*/
460
const char* name, /*!< in: name of the file or path as a
461
null-terminated string */
462
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file is
463
opened (if does not exist, error), or
464
OS_FILE_CREATE if a new file is created
465
(if exists, error), or
466
OS_FILE_CREATE_PATH if new file
467
(if exists, error) and subdirectories along
468
its path are created (if needed)*/
469
ulint access_type,/*!< in: OS_FILE_READ_ONLY or
470
OS_FILE_READ_WRITE */
471
ibool* success);/*!< out: TRUE if succeed, FALSE if error */
472
/****************************************************************//**
473
NOTE! Use the corresponding macro
474
os_file_create_simple_no_error_handling(), not directly this function!
475
A simple function to open or create a file.
476
@return own: handle to the file, not defined if error, error number
477
can be retrieved with os_file_get_last_error */
480
os_file_create_simple_no_error_handling_func(
481
/*=========================================*/
482
const char* name, /*!< in: name of the file or path as a
483
null-terminated string */
484
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
485
is opened (if does not exist, error), or
486
OS_FILE_CREATE if a new file is created
487
(if exists, error) */
488
ulint access_type,/*!< in: OS_FILE_READ_ONLY,
489
OS_FILE_READ_WRITE, or
490
OS_FILE_READ_ALLOW_DELETE; the last option is
491
used by a backup program reading the file */
492
ibool* success);/*!< out: TRUE if succeed, FALSE if error */
493
/****************************************************************//**
494
Tries to disable OS caching on an opened file descriptor. */
499
int fd, /*!< in: file descriptor to alter */
500
const char* file_name, /*!< in: file name, used in the
501
diagnostic message */
502
const char* operation_name);/*!< in: "open" or "create"; used in the
503
diagnostic message */
504
/****************************************************************//**
505
NOTE! Use the corresponding macro os_file_create(), not directly
507
Opens an existing file or creates a new.
508
@return own: handle to the file, not defined if error, error number
509
can be retrieved with os_file_get_last_error */
514
const char* name, /*!< in: name of the file or path as a
515
null-terminated string */
516
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
517
is opened (if does not exist, error), or
518
OS_FILE_CREATE if a new file is created
520
OS_FILE_OVERWRITE if a new file is created
521
or an old overwritten;
522
OS_FILE_OPEN_RAW, if a raw device or disk
523
partition should be opened */
524
ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
525
non-buffered i/o is desired,
526
OS_FILE_NORMAL, if any normal file;
527
NOTE that it also depends on type, os_aio_..
528
and srv_.. variables whether we really use
529
async i/o or unbuffered i/o: look in the
530
function source code for the exact rules */
531
ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
532
ibool* success);/*!< out: TRUE if succeed, FALSE if error */
533
/***********************************************************************//**
534
Deletes a file. The file has to be closed before calling this.
535
@return TRUE if success */
540
const char* name); /*!< in: file path as a null-terminated string */
542
/***********************************************************************//**
543
Deletes a file if it exists. The file has to be closed before calling this.
544
@return TRUE if success */
547
os_file_delete_if_exists(
548
/*=====================*/
549
const char* name); /*!< in: file path as a null-terminated string */
550
/***********************************************************************//**
551
NOTE! Use the corresponding macro os_file_rename(), not directly
553
Renames a file (can also move it to another directory). It is safest that the
554
file is closed before calling this function.
555
@return TRUE if success */
560
const char* oldpath, /*!< in: old file path as a
561
null-terminated string */
562
const char* newpath); /*!< in: new file path */
563
/***********************************************************************//**
564
NOTE! Use the corresponding macro os_file_close(), not directly this
566
Closes a file handle. In case of error, error number can be retrieved with
567
os_file_get_last_error.
568
@return TRUE if success */
573
os_file_t file); /*!< in, own: handle to a file */
576
/****************************************************************//**
577
NOTE! Please use the corresponding macro os_file_create_simple(),
578
not directly this function!
579
A performance schema instrumented wrapper function for
580
os_file_create_simple() which opens or creates a file.
581
@return own: handle to the file, not defined if error, error number
582
can be retrieved with os_file_get_last_error */
585
pfs_os_file_create_simple_func(
586
/*===========================*/
587
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
588
const char* name, /*!< in: name of the file or path as a
589
null-terminated string */
590
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file is
591
opened (if does not exist, error), or
592
OS_FILE_CREATE if a new file is created
593
(if exists, error), or
594
OS_FILE_CREATE_PATH if new file
595
(if exists, error) and subdirectories along
596
its path are created (if needed)*/
597
ulint access_type,/*!< in: OS_FILE_READ_ONLY or
598
OS_FILE_READ_WRITE */
599
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
600
const char* src_file,/*!< in: file name where func invoked */
601
ulint src_line);/*!< in: line where the func invoked */
603
/****************************************************************//**
604
NOTE! Please use the corresponding macro
605
os_file_create_simple_no_error_handling(), not directly this function!
606
A performance schema instrumented wrapper function for
607
os_file_create_simple_no_error_handling(). Add instrumentation to
608
monitor file creation/open.
609
@return own: handle to the file, not defined if error, error number
610
can be retrieved with os_file_get_last_error */
613
pfs_os_file_create_simple_no_error_handling_func(
614
/*=============================================*/
615
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
616
const char* name, /*!< in: name of the file or path as a
617
null-terminated string */
618
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
619
is opened (if does not exist, error), or
620
OS_FILE_CREATE if a new file is created
621
(if exists, error) */
622
ulint access_type,/*!< in: OS_FILE_READ_ONLY,
623
OS_FILE_READ_WRITE, or
624
OS_FILE_READ_ALLOW_DELETE; the last option is
625
used by a backup program reading the file */
626
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
627
const char* src_file,/*!< in: file name where func invoked */
628
ulint src_line);/*!< in: line where the func invoked */
630
/****************************************************************//**
631
NOTE! Please use the corresponding macro os_file_create(), not directly
633
A performance schema wrapper function for os_file_create().
634
Add instrumentation to monitor file creation/open.
635
@return own: handle to the file, not defined if error, error number
636
can be retrieved with os_file_get_last_error */
639
pfs_os_file_create_func(
640
/*====================*/
641
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
642
const char* name, /*!< in: name of the file or path as a
643
null-terminated string */
644
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
645
is opened (if does not exist, error), or
646
OS_FILE_CREATE if a new file is created
648
OS_FILE_OVERWRITE if a new file is created
649
or an old overwritten;
650
OS_FILE_OPEN_RAW, if a raw device or disk
651
partition should be opened */
652
ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
653
non-buffered i/o is desired,
654
OS_FILE_NORMAL, if any normal file;
655
NOTE that it also depends on type, os_aio_..
656
and srv_.. variables whether we really use
657
async i/o or unbuffered i/o: look in the
658
function source code for the exact rules */
659
ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
660
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
661
const char* src_file,/*!< in: file name where func invoked */
662
ulint src_line);/*!< in: line where the func invoked */
664
/***********************************************************************//**
665
NOTE! Please use the corresponding macro os_file_close(), not directly
667
A performance schema instrumented wrapper function for os_file_close().
668
@return TRUE if success */
671
pfs_os_file_close_func(
672
/*===================*/
673
os_file_t file, /*!< in, own: handle to a file */
674
const char* src_file,/*!< in: file name where func invoked */
675
ulint src_line);/*!< in: line where the func invoked */
676
/*******************************************************************//**
677
NOTE! Please use the corresponding macro os_file_read(), not directly
679
This is the performance schema instrumented wrapper function for
680
os_file_read() which requests a synchronous read operation.
681
@return TRUE if request was successful, FALSE if fail */
684
pfs_os_file_read_func(
685
/*==================*/
686
os_file_t file, /*!< in: handle to a file */
687
void* buf, /*!< in: buffer where to read */
688
ulint offset, /*!< in: least significant 32 bits of file
689
offset where to read */
690
ulint offset_high,/*!< in: most significant 32 bits of
692
ulint n, /*!< in: number of bytes to read */
693
const char* src_file,/*!< in: file name where func invoked */
694
ulint src_line);/*!< in: line where the func invoked */
696
/*******************************************************************//**
697
NOTE! Please use the corresponding macro os_file_read_no_error_handling(),
698
not directly this function!
699
This is the performance schema instrumented wrapper function for
700
os_file_read_no_error_handling_func() which requests a synchronous
702
@return TRUE if request was successful, FALSE if fail */
705
pfs_os_file_read_no_error_handling_func(
706
/*====================================*/
707
os_file_t file, /*!< in: handle to a file */
708
void* buf, /*!< in: buffer where to read */
709
ulint offset, /*!< in: least significant 32 bits of file
710
offset where to read */
711
ulint offset_high,/*!< in: most significant 32 bits of
713
ulint n, /*!< in: number of bytes to read */
714
const char* src_file,/*!< in: file name where func invoked */
715
ulint src_line);/*!< in: line where the func invoked */
717
/*******************************************************************//**
718
NOTE! Please use the corresponding macro os_aio(), not directly this
720
Performance schema wrapper function of os_aio() which requests
721
an asynchronous i/o operation.
722
@return TRUE if request was queued successfully, FALSE if fail */
727
ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE */
728
ulint mode, /*!< in: OS_AIO_NORMAL etc. I/O mode */
729
const char* name, /*!< in: name of the file or path as a
730
null-terminated string */
731
os_file_t file, /*!< in: handle to a file */
732
void* buf, /*!< in: buffer where to read or from which
734
ulint offset, /*!< in: least significant 32 bits of file
735
offset where to read or write */
736
ulint offset_high,/*!< in: most significant 32 bits of
738
ulint n, /*!< in: number of bytes to read or write */
739
fil_node_t* message1,/*!< in: message for the aio handler
740
(can be used to identify a completed
741
aio operation); ignored if mode is
743
void* message2,/*!< in: message for the aio handler
744
(can be used to identify a completed
745
aio operation); ignored if mode is
747
const char* src_file,/*!< in: file name where func invoked */
748
ulint src_line);/*!< in: line where the func invoked */
749
/*******************************************************************//**
750
NOTE! Please use the corresponding macro os_file_write(), not directly
752
This is the performance schema instrumented wrapper function for
753
os_file_write() which requests a synchronous write operation.
754
@return TRUE if request was successful, FALSE if fail */
757
pfs_os_file_write_func(
758
/*===================*/
759
const char* name, /*!< in: name of the file or path as a
760
null-terminated string */
761
os_file_t file, /*!< in: handle to a file */
762
const void* buf, /*!< in: buffer from which to write */
763
ulint offset, /*!< in: least significant 32 bits of file
764
offset where to write */
765
ulint offset_high,/*!< in: most significant 32 bits of
767
ulint n, /*!< in: number of bytes to write */
768
const char* src_file,/*!< in: file name where func invoked */
769
ulint src_line);/*!< in: line where the func invoked */
770
/***********************************************************************//**
771
NOTE! Please use the corresponding macro os_file_flush(), not directly
773
This is the performance schema instrumented wrapper function for
774
os_file_flush() which flushes the write buffers of a given file to the disk.
775
Flushes the write buffers of a given file to the disk.
776
@return TRUE if success */
779
pfs_os_file_flush_func(
780
/*===================*/
781
os_file_t file, /*!< in, own: handle to a file */
782
const char* src_file,/*!< in: file name where func invoked */
783
ulint src_line);/*!< in: line where the func invoked */
785
/***********************************************************************//**
786
NOTE! Please use the corresponding macro os_file_rename(), not directly
788
This is the performance schema instrumented wrapper function for
790
@return TRUE if success */
793
pfs_os_file_rename_func(
794
/*====================*/
795
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
796
const char* oldpath,/*!< in: old file path as a null-terminated
798
const char* newpath,/*!< in: new file path */
799
const char* src_file,/*!< in: file name where func invoked */
800
ulint src_line);/*!< in: line where the func invoked */
801
#endif /* UNIV_PFS_IO */
803
#ifdef UNIV_HOTBACKUP
804
/***********************************************************************//**
805
Closes a file handle.
806
@return TRUE if success */
809
os_file_close_no_error_handling(
810
/*============================*/
811
os_file_t file); /*!< in, own: handle to a file */
812
#endif /* UNIV_HOTBACKUP */
813
/***********************************************************************//**
815
@return TRUE if success */
820
os_file_t file, /*!< in: handle to a file */
821
ulint* size, /*!< out: least significant 32 bits of file
823
ulint* size_high);/*!< out: most significant 32 bits of size */
824
/***********************************************************************//**
825
Gets file size as a 64-bit integer ib_int64_t.
826
@return size in bytes, -1 if error */
829
os_file_get_size_as_iblonglong(
830
/*===========================*/
831
os_file_t file); /*!< in: handle to a file */
832
/***********************************************************************//**
833
Write the specified number of zeros to a newly created file.
834
@return TRUE if success */
839
const char* name, /*!< in: name of the file or path as a
840
null-terminated string */
841
os_file_t file, /*!< in: handle to a file */
842
ulint size, /*!< in: least significant 32 bits of file
844
ulint size_high);/*!< in: most significant 32 bits of size */
845
/***********************************************************************//**
846
Truncates a file at its current position.
847
@return TRUE if success */
852
FILE* file); /*!< in: file to be truncated */
853
/***********************************************************************//**
854
NOTE! Use the corresponding macro os_file_flush(), not directly this function!
855
Flushes the write buffers of a given file to the disk.
856
@return TRUE if success */
861
os_file_t file); /*!< in, own: handle to a file */
862
/***********************************************************************//**
863
Retrieves the last error number if an error occurs in a file io function.
864
The number should be retrieved before any other OS calls (because they may
865
overwrite the error number). If the number is not known to this program,
866
the OS error number + 100 is returned.
867
@return error number, or OS error number + 100 */
870
os_file_get_last_error(
871
/*===================*/
872
ibool report_all_errors); /*!< in: TRUE if we want an error message
873
printed of all errors */
874
/*******************************************************************//**
875
NOTE! Use the corresponding macro os_file_read(), not directly this function!
876
Requests a synchronous read operation.
877
@return TRUE if request was successful, FALSE if fail */
882
os_file_t file, /*!< in: handle to a file */
883
void* buf, /*!< in: buffer where to read */
884
ulint offset, /*!< in: least significant 32 bits of file
885
offset where to read */
886
ulint offset_high,/*!< in: most significant 32 bits of
888
ulint n); /*!< in: number of bytes to read */
889
/*******************************************************************//**
890
Rewind file to its start, read at most size - 1 bytes from it to str, and
891
NUL-terminate str. All errors are silently ignored. This function is
892
mostly meant to be used with temporary files. */
897
FILE* file, /*!< in: file to read from */
898
char* str, /*!< in: buffer where to read */
899
ulint size); /*!< in: size of buffer */
900
/*******************************************************************//**
901
NOTE! Use the corresponding macro os_file_read_no_error_handling(),
902
not directly this function!
903
Requests a synchronous positioned read operation. This function does not do
904
any error handling. In case of error it returns FALSE.
905
@return TRUE if request was successful, FALSE if fail */
908
os_file_read_no_error_handling_func(
909
/*================================*/
910
os_file_t file, /*!< in: handle to a file */
911
void* buf, /*!< in: buffer where to read */
912
ulint offset, /*!< in: least significant 32 bits of file
913
offset where to read */
914
ulint offset_high,/*!< in: most significant 32 bits of
916
ulint n); /*!< in: number of bytes to read */
918
/*******************************************************************//**
919
NOTE! Use the corresponding macro os_file_write(), not directly this
921
Requests a synchronous write operation.
922
@return TRUE if request was successful, FALSE if fail */
927
const char* name, /*!< in: name of the file or path as a
928
null-terminated string */
929
os_file_t file, /*!< in: handle to a file */
930
const void* buf, /*!< in: buffer from which to write */
931
ulint offset, /*!< in: least significant 32 bits of file
932
offset where to write */
933
ulint offset_high,/*!< in: most significant 32 bits of
935
ulint n); /*!< in: number of bytes to write */
936
/*******************************************************************//**
937
Check the existence and type of the given file.
938
@return TRUE if call succeeded */
943
const char* path, /*!< in: pathname of the file */
944
ibool* exists, /*!< out: TRUE if file exists */
945
os_file_type_t* type); /*!< out: type of the file (if it exists) */
946
/****************************************************************//**
947
The function os_file_dirname returns a directory component of a
948
null-terminated pathname string. In the usual case, dirname returns
949
the string up to, but not including, the final '/', and basename
950
is the component following the final '/'. Trailing '/' charac�
951
ters are not counted as part of the pathname.
953
If path does not contain a slash, dirname returns the string ".".
955
Concatenating the string returned by dirname, a "/", and the basename
956
yields a complete pathname.
958
The return value is a copy of the directory component of the pathname.
959
The copy is allocated from heap. It is the caller responsibility
960
to free it after it is no longer needed.
962
The following list of examples (taken from SUSv2) shows the strings
963
returned by dirname and basename for different paths:
965
path dirname basename
966
"/usr/lib" "/usr" "lib"
973
@return own: directory component of the pathname */
978
const char* path); /*!< in: pathname */
979
/****************************************************************//**
980
Creates all missing subdirectories along the given path.
981
@return TRUE if call succeeded FALSE otherwise */
984
os_file_create_subdirs_if_needed(
985
/*=============================*/
986
const char* path); /*!< in: path name */
987
/***********************************************************************
988
Initializes the asynchronous io system. Creates one array each for ibuf
989
and log i/o. Also creates one array each for read and write where each
990
array is divided logically into n_read_segs and n_write_segs
991
respectively. The caller must create an i/o handler thread for each
992
segment in these arrays. This function also creates the sync array.
993
No i/o handler thread needs to be created for that */
998
ulint n_per_seg, /*<! in: maximum number of pending aio
999
operations allowed per segment */
1000
ulint n_read_segs, /*<! in: number of reader threads */
1001
ulint n_write_segs, /*<! in: number of writer threads */
1002
ulint n_slots_sync); /*<! in: number of slots in the sync aio
1004
/***********************************************************************
1005
Frees the asynchronous io system. */
1011
/*******************************************************************//**
1012
NOTE! Use the corresponding macro os_aio(), not directly this function!
1013
Requests an asynchronous i/o operation.
1014
@return TRUE if request was queued successfully, FALSE if fail */
1019
ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE */
1020
ulint mode, /*!< in: OS_AIO_NORMAL, ..., possibly ORed
1021
to OS_AIO_SIMULATED_WAKE_LATER: the
1022
last flag advises this function not to wake
1023
i/o-handler threads, but the caller will
1024
do the waking explicitly later, in this
1025
way the caller can post several requests in
1026
a batch; NOTE that the batch must not be
1027
so big that it exhausts the slots in aio
1028
arrays! NOTE that a simulated batch
1029
may introduce hidden chances of deadlocks,
1030
because i/os are not actually handled until
1031
all have been posted: use with great
1033
const char* name, /*!< in: name of the file or path as a
1034
null-terminated string */
1035
os_file_t file, /*!< in: handle to a file */
1036
void* buf, /*!< in: buffer where to read or from which
1038
ulint offset, /*!< in: least significant 32 bits of file
1039
offset where to read or write */
1040
ulint offset_high, /*!< in: most significant 32 bits of
1042
ulint n, /*!< in: number of bytes to read or write */
1043
fil_node_t* message1,/*!< in: message for the aio handler
1044
(can be used to identify a completed
1045
aio operation); ignored if mode is
1047
void* message2);/*!< in: message for the aio handler
1048
(can be used to identify a completed
1049
aio operation); ignored if mode is
1051
/************************************************************************//**
1052
Wakes up all async i/o threads so that they know to exit themselves in
1056
os_aio_wake_all_threads_at_shutdown(void);
1057
/*=====================================*/
1058
/************************************************************************//**
1059
Waits until there are no pending writes in os_aio_write_array. There can
1060
be other, synchronous, pending writes. */
1063
os_aio_wait_until_no_pending_writes(void);
1064
/*=====================================*/
1065
/**********************************************************************//**
1066
Wakes up simulated aio i/o-handler threads if they have something to do. */
1069
os_aio_simulated_wake_handler_threads(void);
1070
/*=======================================*/
1071
/**********************************************************************//**
1072
This function can be called if one wants to post a batch of reads and
1073
prefers an i/o-handler thread to handle them all at once later. You must
1074
call os_aio_simulated_wake_handler_threads later to ensure the threads
1075
are not left sleeping! */
1078
os_aio_simulated_put_read_threads_to_sleep(void);
1079
/*============================================*/
1082
/**********************************************************************//**
1083
This function is only used in Windows asynchronous i/o.
1084
Waits for an aio operation to complete. This function is used to wait the
1085
for completed requests. The aio array of pending requests is divided
1086
into segments. The thread specifies which segment or slot it wants to wait
1087
for. NOTE: this function will also take care of freeing the aio slot,
1088
therefore no other thread is allowed to do the freeing!
1089
@return TRUE if the aio operation succeeded */
1092
os_aio_windows_handle(
1093
/*==================*/
1094
ulint segment, /*!< in: the number of the segment in the aio
1095
arrays to wait for; segment 0 is the ibuf
1096
i/o thread, segment 1 the log i/o thread,
1097
then follow the non-ibuf read threads, and as
1098
the last are the non-ibuf write threads; if
1099
this is ULINT_UNDEFINED, then it means that
1100
sync aio is used, and this parameter is
1102
ulint pos, /*!< this parameter is used only in sync aio:
1103
wait for the aio slot at this position */
1104
fil_node_t**message1, /*!< out: the messages passed with the aio
1105
request; note that also in the case where
1106
the aio operation failed, these output
1107
parameters are valid and can be used to
1108
restart the operation, for example */
1110
ulint* type); /*!< out: OS_FILE_WRITE or ..._READ */
1113
/**********************************************************************//**
1114
Does simulated aio. This function should be called by an i/o-handler
1116
@return TRUE if the aio operation succeeded */
1119
os_aio_simulated_handle(
1120
/*====================*/
1121
ulint segment, /*!< in: the number of the segment in the aio
1122
arrays to wait for; segment 0 is the ibuf
1123
i/o thread, segment 1 the log i/o thread,
1124
then follow the non-ibuf read threads, and as
1125
the last are the non-ibuf write threads */
1126
fil_node_t**message1, /*!< out: the messages passed with the aio
1127
request; note that also in the case where
1128
the aio operation failed, these output
1129
parameters are valid and can be used to
1130
restart the operation, for example */
1132
ulint* type); /*!< out: OS_FILE_WRITE or ..._READ */
1133
/**********************************************************************//**
1134
Validates the consistency of the aio system.
1135
@return TRUE if ok */
1138
os_aio_validate(void);
1139
/*=================*/
1140
/**********************************************************************//**
1141
Prints info of the aio arrays. */
1146
FILE* file); /*!< in: file where to print */
1147
/**********************************************************************//**
1148
Refreshes the statistics used to print per-second averages. */
1151
os_aio_refresh_stats(void);
1152
/*======================*/
1155
/**********************************************************************//**
1156
Checks that all slots in the system have been freed, that is, there are
1157
no pending io operations. */
1160
os_aio_all_slots_free(void);
1161
/*=======================*/
1162
#endif /* UNIV_DEBUG */
1164
/*******************************************************************//**
1165
This function returns information about the specified file
1166
@return TRUE if stat information found */
1171
const char* path, /*!< in: pathname of the file */
1172
os_file_stat_t* stat_info); /*!< information of a file in a
1175
#if !defined(UNIV_HOTBACKUP)
1176
/*********************************************************************//**
1177
Creates a temporary file that will be deleted on close.
1178
This function is defined in ha_innodb.cc.
1179
@return temporary file descriptor, or < 0 on error */
1182
innobase_mysql_tmpfile(void);
1183
/*========================*/
1184
#endif /* !UNIV_HOTBACKUP */
1187
#if defined(LINUX_NATIVE_AIO)
1188
/**************************************************************************
1189
This function is only used in Linux native asynchronous i/o.
1190
Waits for an aio operation to complete. This function is used to wait the
1191
for completed requests. The aio array of pending requests is divided
1192
into segments. The thread specifies which segment or slot it wants to wait
1193
for. NOTE: this function will also take care of freeing the aio slot,
1194
therefore no other thread is allowed to do the freeing!
1195
@return TRUE if the IO was successful */
1198
os_aio_linux_handle(
1199
/*================*/
1200
ulint global_seg, /*!< in: segment number in the aio array
1201
to wait for; segment 0 is the ibuf
1202
i/o thread, segment 1 is log i/o thread,
1203
then follow the non-ibuf read threads,
1204
and the last are the non-ibuf write
1206
fil_node_t**message1, /*!< out: the messages passed with the */
1207
void** message2, /*!< aio request; note that in case the
1208
aio operation failed, these output
1209
parameters are valid and can be used to
1210
restart the operation. */
1211
ulint* type); /*!< out: OS_FILE_WRITE or ..._READ */
1212
#endif /* LINUX_NATIVE_AIO */
1215
#include "os0file.ic"