00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #pragma once
00036 #ifndef os0file_h
00037 #define os0file_h
00038
00039 #include "univ.i"
00040
00041 #ifndef __WIN__
00042 #include <dirent.h>
00043 #include <sys/stat.h>
00044 #include <time.h>
00045 #endif
00046
00048 typedef struct fil_node_struct fil_node_t;
00049
00050 #ifdef UNIV_DO_FLUSH
00051 extern ibool os_do_not_call_flush_at_each_write;
00052 #endif
00053 extern ibool os_has_said_disk_full;
00055 extern ibool os_aio_print_debug;
00056
00058 extern ulint os_file_n_pending_preads;
00060 extern ulint os_file_n_pending_pwrites;
00061
00063 extern ulint os_n_pending_reads;
00065 extern ulint os_n_pending_writes;
00066
00067 #ifdef __WIN__
00068
00071 #define WIN_ASYNC_IO
00072
00074 #define UNIV_NON_BUFFERED_IO
00075
00076 #endif
00077
00078 #ifdef __WIN__
00079
00080 # define os_file_t HANDLE
00081
00084 # define OS_FILE_FROM_FD(fd) (HANDLE) _get_osfhandle(fd)
00085 #else
00086
00087 typedef int os_file_t;
00091 # define OS_FILE_FROM_FD(fd) fd
00092 #endif
00093
00095 extern ulint os_innodb_umask;
00096
00104 #define OS_FILE_LOG_BLOCK_SIZE 512
00105
00107 #define OS_FILE_OPEN 51
00108 #define OS_FILE_CREATE 52
00109 #define OS_FILE_OVERWRITE 53
00110 #define OS_FILE_OPEN_RAW 54
00111 #define OS_FILE_CREATE_PATH 55
00112 #define OS_FILE_OPEN_RETRY 56
00113
00114
00115 #define OS_FILE_READ_ONLY 333
00116 #define OS_FILE_READ_WRITE 444
00117 #define OS_FILE_READ_ALLOW_DELETE 555
00118
00119
00120 #define OS_FILE_AIO 61
00121 #define OS_FILE_NORMAL 62
00122
00123
00125 #define OS_DATA_FILE 100
00126 #define OS_LOG_FILE 101
00127
00128
00130 #define OS_FILE_NOT_FOUND 71
00131 #define OS_FILE_DISK_FULL 72
00132 #define OS_FILE_ALREADY_EXISTS 73
00133 #define OS_FILE_PATH_ERROR 74
00134 #define OS_FILE_AIO_RESOURCES_RESERVED 75
00135
00136 #define OS_FILE_SHARING_VIOLATION 76
00137 #define OS_FILE_ERROR_NOT_SPECIFIED 77
00138 #define OS_FILE_INSUFFICIENT_RESOURCE 78
00139 #define OS_FILE_AIO_INTERRUPTED 79
00140 #define OS_FILE_OPERATION_ABORTED 80
00141
00142
00144 #define OS_FILE_READ 10
00145 #define OS_FILE_WRITE 11
00146
00147 #define OS_FILE_LOG 256
00148
00149
00150 #define OS_AIO_N_PENDING_IOS_PER_THREAD 32
00154 #define OS_AIO_NORMAL 21
00156 #define OS_AIO_IBUF 22
00158 #define OS_AIO_LOG 23
00159 #define OS_AIO_SYNC 24
00169 #define OS_AIO_SIMULATED_WAKE_LATER 512
00175
00176
00177 #define OS_WIN31 1
00178 #define OS_WIN95 2
00179 #define OS_WINNT 3
00180 #define OS_WIN2000 4
00181 #define OS_WINXP 5
00183 #define OS_WINVISTA 6
00185 #define OS_WIN7 7
00189 extern ulint os_n_file_reads;
00190 extern ulint os_n_file_writes;
00191 extern ulint os_n_fsyncs;
00192
00193 #ifdef UNIV_PFS_IO
00194
00195 extern mysql_pfs_key_t innodb_file_data_key;
00196 extern mysql_pfs_key_t innodb_file_log_key;
00197 extern mysql_pfs_key_t innodb_file_temp_key;
00198
00199
00200
00201
00202
00203
00204
00205 # define register_pfs_file_open_begin(state, locker, key, op, name, \
00206 src_file, src_line) \
00207 do { \
00208 if (PSI_server) { \
00209 locker = PSI_server->get_thread_file_name_locker( \
00210 state, key, op, name, &locker); \
00211 if (locker) { \
00212 PSI_server->start_file_open_wait( \
00213 locker, src_file, src_line); \
00214 } \
00215 } \
00216 } while (0)
00217
00218 # define register_pfs_file_open_end(locker, file) \
00219 do { \
00220 if (locker) { \
00221 PSI_server->end_file_open_wait_and_bind_to_descriptor( \
00222 locker, file); \
00223 } \
00224 } while (0)
00225
00226 # define register_pfs_file_io_begin(state, locker, file, count, op, \
00227 src_file, src_line) \
00228 do { \
00229 if (PSI_server) { \
00230 locker = PSI_server->get_thread_file_descriptor_locker( \
00231 state, file, op); \
00232 if (locker) { \
00233 PSI_server->start_file_wait( \
00234 locker, count, src_file, src_line); \
00235 } \
00236 } \
00237 } while (0)
00238
00239 # define register_pfs_file_io_end(locker, count) \
00240 do { \
00241 if (locker) { \
00242 PSI_server->end_file_wait(locker, count); \
00243 } \
00244 } while (0)
00245 #endif
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 #ifdef UNIV_PFS_IO
00264 # define os_file_create(key, name, create, purpose, type, success) \
00265 pfs_os_file_create_func(key, name, create, purpose, type, \
00266 success, __FILE__, __LINE__)
00267
00268 # define os_file_create_simple(key, name, create, access, success) \
00269 pfs_os_file_create_simple_func(key, name, create, access, \
00270 success, __FILE__, __LINE__)
00271
00272 # define os_file_create_simple_no_error_handling( \
00273 key, name, create_mode, access, success) \
00274 pfs_os_file_create_simple_no_error_handling_func( \
00275 key, name, create_mode, access, success, __FILE__, __LINE__)
00276
00277 # define os_file_close(file) \
00278 pfs_os_file_close_func(file, __FILE__, __LINE__)
00279
00280 # define os_aio(type, mode, name, file, buf, offset, offset_high, \
00281 n, message1, message2) \
00282 pfs_os_aio_func(type, mode, name, file, buf, offset, \
00283 offset_high, n, message1, message2, \
00284 __FILE__, __LINE__)
00285
00286 # define os_file_read(file, buf, offset, offset_high, n) \
00287 pfs_os_file_read_func(file, buf, offset, offset_high, n, \
00288 __FILE__, __LINE__)
00289
00290 # define os_file_read_no_error_handling(file, buf, offset, \
00291 offset_high, n) \
00292 pfs_os_file_read_no_error_handling_func(file, buf, offset, \
00293 offset_high, n, \
00294 __FILE__, __LINE__)
00295
00296 # define os_file_write(name, file, buf, offset, offset_high, n) \
00297 pfs_os_file_write_func(name, file, buf, offset, offset_high, \
00298 n, __FILE__, __LINE__)
00299
00300 # define os_file_flush(file) \
00301 pfs_os_file_flush_func(file, __FILE__, __LINE__)
00302
00303 # define os_file_rename(key, oldpath, newpath) \
00304 pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__)
00305 #else
00306
00307
00308
00309 # define os_file_create(key, name, create, purpose, type, success) \
00310 os_file_create_func(name, create, purpose, type, success)
00311
00312 # define os_file_create_simple(key, name, create, access, success) \
00313 os_file_create_simple_func(name, create_mode, access, success)
00314
00315 # define os_file_create_simple_no_error_handling( \
00316 key, name, create_mode, access, success) \
00317 os_file_create_simple_no_error_handling_func( \
00318 name, create_mode, access, success)
00319
00320 # define os_file_close(file) os_file_close_func(file)
00321
00322 # define os_aio(type, mode, name, file, buf, offset, offset_high, \
00323 n, message1, message2) \
00324 os_aio_func(type, mode, name, file, buf, offset, offset_high, n,\
00325 message1, message2)
00326
00327 # define os_file_read(file, buf, offset, offset_high, n) \
00328 os_file_read_func(file, buf, offset, offset_high, n)
00329
00330 # define os_file_read_no_error_handling(file, buf, offset, \
00331 offset_high, n) \
00332 os_file_read_no_error_handling_func(file, buf, offset, offset_high, n)
00333
00334 # define os_file_write(name, file, buf, offset, offset_high, n) \
00335 os_file_write_func(name, file, buf, offset, offset_high, n)
00336
00337 # define os_file_flush(file) os_file_flush_func(file)
00338
00339 # define os_file_rename(key, oldpath, newpath) \
00340 os_file_rename_func(oldpath, newpath)
00341
00342 #endif
00343
00344
00345
00346 enum os_file_type_enum{
00347 OS_FILE_TYPE_UNKNOWN = 0,
00348 OS_FILE_TYPE_FILE,
00349 OS_FILE_TYPE_DIR,
00350 OS_FILE_TYPE_LINK
00351 };
00352 typedef enum os_file_type_enum os_file_type_t;
00353
00354
00355
00356
00357
00358 #define OS_FILE_MAX_PATH 4000
00359
00360
00361 struct os_file_stat_struct{
00362 char name[OS_FILE_MAX_PATH];
00363 os_file_type_t type;
00364 ib_int64_t size;
00365 time_t ctime;
00366 time_t mtime;
00367 time_t atime;
00368 };
00369 typedef struct os_file_stat_struct os_file_stat_t;
00370
00371 #ifdef __WIN__
00372 typedef HANDLE os_file_dir_t;
00373 #else
00374 typedef DIR* os_file_dir_t;
00375 #endif
00376
00377
00381 UNIV_INTERN
00382 ulint
00383 os_get_os_version(void);
00384
00385 #ifndef UNIV_HOTBACKUP
00386
00388 UNIV_INTERN
00389 void
00390 os_io_init_simple(void);
00391
00392
00397 FILE*
00398 os_file_create_tmpfile(void);
00399
00400 #endif
00401
00407 UNIV_INTERN
00408 os_file_dir_t
00409 os_file_opendir(
00410
00411 const char* dirname,
00413 ibool error_is_fatal);
00418
00421 UNIV_INTERN
00422 int
00423 os_file_closedir(
00424
00425 os_file_dir_t dir);
00426
00430 UNIV_INTERN
00431 int
00432 os_file_readdir_next_file(
00433
00434 const char* dirname,
00435 os_file_dir_t dir,
00436 os_file_stat_t* info);
00437
00443 UNIV_INTERN
00444 ibool
00445 os_file_create_directory(
00446
00447 const char* pathname,
00449 ibool fail_if_exists);
00451
00457 UNIV_INTERN
00458 os_file_t
00459 os_file_create_simple_func(
00460
00461 const char* name,
00463 ulint create_mode,
00470 ulint access_type,
00472 ibool* success);
00473
00479 UNIV_INTERN
00480 os_file_t
00481 os_file_create_simple_no_error_handling_func(
00482
00483 const char* name,
00485 ulint create_mode,
00489 ulint access_type,
00493 ibool* success);
00494
00496 UNIV_INTERN
00497 void
00498 os_file_set_nocache(
00499
00500 int fd,
00501 const char* file_name,
00503 const char* operation_name);
00505
00511 UNIV_INTERN
00512 os_file_t
00513 os_file_create_func(
00514
00515 const char* name,
00517 ulint create_mode,
00525 ulint purpose,
00532 ulint type,
00533 ibool* success);
00534
00537 UNIV_INTERN
00538 ibool
00539 os_file_delete(
00540
00541 const char* name);
00543
00546 UNIV_INTERN
00547 ibool
00548 os_file_delete_if_exists(
00549
00550 const char* name);
00551
00557 UNIV_INTERN
00558 ibool
00559 os_file_rename_func(
00560
00561 const char* oldpath,
00563 const char* newpath);
00564
00570 UNIV_INTERN
00571 ibool
00572 os_file_close_func(
00573
00574 os_file_t file);
00576 #ifdef UNIV_PFS_IO
00577
00584 UNIV_INLINE
00585 os_file_t
00586 pfs_os_file_create_simple_func(
00587
00588 mysql_pfs_key_t key,
00589 const char* name,
00591 ulint create_mode,
00598 ulint access_type,
00600 ibool* success,
00601 const char* src_file,
00602 ulint src_line);
00604
00612 UNIV_INLINE
00613 os_file_t
00614 pfs_os_file_create_simple_no_error_handling_func(
00615
00616 mysql_pfs_key_t key,
00617 const char* name,
00619 ulint create_mode,
00623 ulint access_type,
00627 ibool* success,
00628 const char* src_file,
00629 ulint src_line);
00631
00638 UNIV_INLINE
00639 os_file_t
00640 pfs_os_file_create_func(
00641
00642 mysql_pfs_key_t key,
00643 const char* name,
00645 ulint create_mode,
00653 ulint purpose,
00660 ulint type,
00661 ibool* success,
00662 const char* src_file,
00663 ulint src_line);
00665
00670 UNIV_INLINE
00671 ibool
00672 pfs_os_file_close_func(
00673
00674 os_file_t file,
00675 const char* src_file,
00676 ulint src_line);
00677
00683 UNIV_INLINE
00684 ibool
00685 pfs_os_file_read_func(
00686
00687 os_file_t file,
00688 void* buf,
00689 ulint offset,
00691 ulint offset_high,
00693 ulint n,
00694 const char* src_file,
00695 ulint src_line);
00697
00704 UNIV_INLINE
00705 ibool
00706 pfs_os_file_read_no_error_handling_func(
00707
00708 os_file_t file,
00709 void* buf,
00710 ulint offset,
00712 ulint offset_high,
00714 ulint n,
00715 const char* src_file,
00716 ulint src_line);
00718
00724 UNIV_INLINE
00725 ibool
00726 pfs_os_aio_func(
00727
00728 ulint type,
00729 ulint mode,
00730 const char* name,
00732 os_file_t file,
00733 void* buf,
00735 ulint offset,
00737 ulint offset_high,
00739 ulint n,
00740 fil_node_t* message1,
00744 void* message2,
00748 const char* src_file,
00749 ulint src_line);
00750
00756 UNIV_INLINE
00757 ibool
00758 pfs_os_file_write_func(
00759
00760 const char* name,
00762 os_file_t file,
00763 const void* buf,
00764 ulint offset,
00766 ulint offset_high,
00768 ulint n,
00769 const char* src_file,
00770 ulint src_line);
00771
00778 UNIV_INLINE
00779 ibool
00780 pfs_os_file_flush_func(
00781
00782 os_file_t file,
00783 const char* src_file,
00784 ulint src_line);
00786
00792 UNIV_INLINE
00793 ibool
00794 pfs_os_file_rename_func(
00795
00796 mysql_pfs_key_t key,
00797 const char* oldpath,
00799 const char* newpath,
00800 const char* src_file,
00801 ulint src_line);
00802 #endif
00803
00804 #ifdef UNIV_HOTBACKUP
00805
00808 UNIV_INTERN
00809 ibool
00810 os_file_close_no_error_handling(
00811
00812 os_file_t file);
00813 #endif
00814
00817 UNIV_INTERN
00818 ibool
00819 os_file_get_size(
00820
00821 os_file_t file,
00822 ulint* size,
00824 ulint* size_high);
00825
00828 UNIV_INTERN
00829 ib_int64_t
00830 os_file_get_size_as_iblonglong(
00831
00832 os_file_t file);
00833
00836 UNIV_INTERN
00837 ibool
00838 os_file_set_size(
00839
00840 const char* name,
00842 os_file_t file,
00843 ulint size,
00845 ulint size_high);
00846
00849 UNIV_INTERN
00850 ibool
00851 os_file_set_eof(
00852
00853 FILE* file);
00854
00858 UNIV_INTERN
00859 ibool
00860 os_file_flush_func(
00861
00862 os_file_t file);
00863
00869 UNIV_INTERN
00870 ulint
00871 os_file_get_last_error(
00872
00873 ibool report_all_errors);
00875
00879 UNIV_INTERN
00880 ibool
00881 os_file_read_func(
00882
00883 os_file_t file,
00884 void* buf,
00885 ulint offset,
00887 ulint offset_high,
00889 ulint n);
00890
00894 UNIV_INTERN
00895 void
00896 os_file_read_string(
00897
00898 FILE* file,
00899 char* str,
00900 ulint size);
00901
00907 UNIV_INTERN
00908 ibool
00909 os_file_read_no_error_handling_func(
00910
00911 os_file_t file,
00912 void* buf,
00913 ulint offset,
00915 ulint offset_high,
00917 ulint n);
00919
00924 UNIV_INTERN
00925 ibool
00926 os_file_write_func(
00927
00928 const char* name,
00930 os_file_t file,
00931 const void* buf,
00932 ulint offset,
00934 ulint offset_high,
00936 ulint n);
00937
00940 UNIV_INTERN
00941 ibool
00942 os_file_status(
00943
00944 const char* path,
00945 ibool* exists,
00946 os_file_type_t* type);
00947
00975 UNIV_INTERN
00976 char*
00977 os_file_dirname(
00978
00979 const char* path);
00980
00983 UNIV_INTERN
00984 ibool
00985 os_file_create_subdirs_if_needed(
00986
00987 const char* path);
00988
00989
00990
00991
00992
00993
00994
00995 UNIV_INTERN
00996 ibool
00997 os_aio_init(
00998
00999 ulint n_per_seg,
01000
01001 ulint n_read_segs,
01002 ulint n_write_segs,
01003 ulint n_slots_sync);
01004
01005
01006
01007 UNIV_INTERN
01008 void
01009 os_aio_free(void);
01010
01011
01012
01016 UNIV_INTERN
01017 ibool
01018 os_aio_func(
01019
01020 ulint type,
01021 ulint mode,
01034 const char* name,
01036 os_file_t file,
01037 void* buf,
01039 ulint offset,
01041 ulint offset_high,
01043 ulint n,
01044 fil_node_t* message1,
01048 void* message2);
01052
01055 UNIV_INTERN
01056 void
01057 os_aio_wake_all_threads_at_shutdown(void);
01058
01059
01062 UNIV_INTERN
01063 void
01064 os_aio_wait_until_no_pending_writes(void);
01065
01066
01068 UNIV_INTERN
01069 void
01070 os_aio_simulated_wake_handler_threads(void);
01071
01072
01077 UNIV_INTERN
01078 void
01079 os_aio_simulated_put_read_threads_to_sleep(void);
01080
01081
01082 #ifdef WIN_ASYNC_IO
01083
01091 UNIV_INTERN
01092 ibool
01093 os_aio_windows_handle(
01094
01095 ulint segment,
01103 ulint pos,
01105 fil_node_t**message1,
01110 void** message2,
01111 ulint* type);
01112 #endif
01113
01114
01118 UNIV_INTERN
01119 ibool
01120 os_aio_simulated_handle(
01121
01122 ulint segment,
01127 fil_node_t**message1,
01132 void** message2,
01133 ulint* type);
01134
01137 UNIV_INTERN
01138 ibool
01139 os_aio_validate(void);
01140
01141
01143 UNIV_INTERN
01144 void
01145 os_aio_print(
01146
01147 FILE* file);
01148
01150 UNIV_INTERN
01151 void
01152 os_aio_refresh_stats(void);
01153
01154
01155 #ifdef UNIV_DEBUG
01156
01159 UNIV_INTERN
01160 ibool
01161 os_aio_all_slots_free(void);
01162
01163 #endif
01164
01165
01168 UNIV_INTERN
01169 ibool
01170 os_file_get_status(
01171
01172 const char* path,
01173 os_file_stat_t* stat_info);
01176 #if !defined(UNIV_HOTBACKUP)
01177
01181 UNIV_INTERN
01182 int
01183 innobase_mysql_tmpfile(void);
01184
01185 #endif
01186
01187
01188 #if defined(LINUX_NATIVE_AIO)
01189
01190
01191
01192
01193
01194
01195
01196
01197 UNIV_INTERN
01198 ibool
01199 os_aio_linux_handle(
01200
01201 ulint global_seg,
01207 fil_node_t**message1,
01208 void** message2,
01212 ulint* type);
01213 #endif
01214
01215 #ifndef UNIV_NONINL
01216 #include "os0file.ic"
01217 #endif
01218
01219 #endif