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 srv_log_block_size
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 extern uint32_t srv_log_block_size;
00194
00195 #ifdef UNIV_PFS_IO
00196
00197 extern mysql_pfs_key_t innodb_file_data_key;
00198 extern mysql_pfs_key_t innodb_file_log_key;
00199 extern mysql_pfs_key_t innodb_file_temp_key;
00200
00201
00202
00203
00204
00205
00206
00207 # define register_pfs_file_open_begin(state, locker, key, op, name, \
00208 src_file, src_line) \
00209 do { \
00210 if (PSI_server) { \
00211 locker = PSI_server->get_thread_file_name_locker( \
00212 state, key, op, name, &locker); \
00213 if (locker) { \
00214 PSI_server->start_file_open_wait( \
00215 locker, src_file, src_line); \
00216 } \
00217 } \
00218 } while (0)
00219
00220 # define register_pfs_file_open_end(locker, file) \
00221 do { \
00222 if (locker) { \
00223 PSI_server->end_file_open_wait_and_bind_to_descriptor( \
00224 locker, file); \
00225 } \
00226 } while (0)
00227
00228 # define register_pfs_file_io_begin(state, locker, file, count, op, \
00229 src_file, src_line) \
00230 do { \
00231 if (PSI_server) { \
00232 locker = PSI_server->get_thread_file_descriptor_locker( \
00233 state, file, op); \
00234 if (locker) { \
00235 PSI_server->start_file_wait( \
00236 locker, count, src_file, src_line); \
00237 } \
00238 } \
00239 } while (0)
00240
00241 # define register_pfs_file_io_end(locker, count) \
00242 do { \
00243 if (locker) { \
00244 PSI_server->end_file_wait(locker, count); \
00245 } \
00246 } while (0)
00247 #endif
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 #ifdef UNIV_PFS_IO
00266 # define os_file_create(key, name, create, purpose, type, success) \
00267 pfs_os_file_create_func(key, name, create, purpose, type, \
00268 success, __FILE__, __LINE__)
00269
00270 # define os_file_create_simple(key, name, create, access, success) \
00271 pfs_os_file_create_simple_func(key, name, create, access, \
00272 success, __FILE__, __LINE__)
00273
00274 # define os_file_create_simple_no_error_handling( \
00275 key, name, create_mode, access, success) \
00276 pfs_os_file_create_simple_no_error_handling_func( \
00277 key, name, create_mode, access, success, __FILE__, __LINE__)
00278
00279 # define os_file_close(file) \
00280 pfs_os_file_close_func(file, __FILE__, __LINE__)
00281
00282 # define os_aio(type, mode, name, file, buf, offset, offset_high, \
00283 n, message1, message2) \
00284 pfs_os_aio_func(type, mode, name, file, buf, offset, \
00285 offset_high, n, message1, message2, \
00286 __FILE__, __LINE__)
00287
00288 # define os_file_read(file, buf, offset, offset_high, n) \
00289 pfs_os_file_read_func(file, buf, offset, offset_high, n, \
00290 __FILE__, __LINE__)
00291
00292 # define os_file_read_no_error_handling(file, buf, offset, \
00293 offset_high, n) \
00294 pfs_os_file_read_no_error_handling_func(file, buf, offset, \
00295 offset_high, n, \
00296 __FILE__, __LINE__)
00297
00298 # define os_file_write(name, file, buf, offset, offset_high, n) \
00299 pfs_os_file_write_func(name, file, buf, offset, offset_high, \
00300 n, __FILE__, __LINE__)
00301
00302 # define os_file_flush(file) \
00303 pfs_os_file_flush_func(file, __FILE__, __LINE__)
00304
00305 # define os_file_rename(key, oldpath, newpath) \
00306 pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__)
00307 #else
00308
00309
00310
00311 # define os_file_create(key, name, create, purpose, type, success) \
00312 os_file_create_func(name, create, purpose, type, success)
00313
00314 # define os_file_create_simple(key, name, create, access, success) \
00315 os_file_create_simple_func(name, create_mode, access, success)
00316
00317 # define os_file_create_simple_no_error_handling( \
00318 key, name, create_mode, access, success) \
00319 os_file_create_simple_no_error_handling_func( \
00320 name, create_mode, access, success)
00321
00322 # define os_file_close(file) os_file_close_func(file)
00323
00324 # define os_aio(type, mode, name, file, buf, offset, offset_high, \
00325 n, message1, message2) \
00326 os_aio_func(type, mode, name, file, buf, offset, offset_high, n,\
00327 message1, message2)
00328
00329 # define os_file_read(file, buf, offset, offset_high, n) \
00330 os_file_read_func(file, buf, offset, offset_high, n)
00331
00332 # define os_file_read_no_error_handling(file, buf, offset, \
00333 offset_high, n) \
00334 os_file_read_no_error_handling_func(file, buf, offset, offset_high, n)
00335
00336 # define os_file_write(name, file, buf, offset, offset_high, n) \
00337 os_file_write_func(name, file, buf, offset, offset_high, n)
00338
00339 # define os_file_flush(file) os_file_flush_func(file)
00340
00341 # define os_file_rename(key, oldpath, newpath) \
00342 os_file_rename_func(oldpath, newpath)
00343
00344 #endif
00345
00346
00347
00348 enum os_file_type_enum{
00349 OS_FILE_TYPE_UNKNOWN = 0,
00350 OS_FILE_TYPE_FILE,
00351 OS_FILE_TYPE_DIR,
00352 OS_FILE_TYPE_LINK
00353 };
00354 typedef enum os_file_type_enum os_file_type_t;
00355
00356
00357
00358
00359
00360 #define OS_FILE_MAX_PATH 4000
00361
00362
00363 struct os_file_stat_struct{
00364 char name[OS_FILE_MAX_PATH];
00365 os_file_type_t type;
00366 ib_int64_t size;
00367 time_t ctime;
00368 time_t mtime;
00369 time_t atime;
00370 };
00371 typedef struct os_file_stat_struct os_file_stat_t;
00372
00373 #ifdef __WIN__
00374 typedef HANDLE os_file_dir_t;
00375 #else
00376 typedef DIR* os_file_dir_t;
00377 #endif
00378
00379
00383 UNIV_INTERN
00384 ulint
00385 os_get_os_version(void);
00386
00387 #ifndef UNIV_HOTBACKUP
00388
00390 UNIV_INTERN
00391 void
00392 os_io_init_simple(void);
00393
00394
00399 FILE*
00400 os_file_create_tmpfile(void);
00401
00402 #endif
00403
00409 UNIV_INTERN
00410 os_file_dir_t
00411 os_file_opendir(
00412
00413 const char* dirname,
00415 ibool error_is_fatal);
00420
00423 UNIV_INTERN
00424 int
00425 os_file_closedir(
00426
00427 os_file_dir_t dir);
00428
00432 UNIV_INTERN
00433 int
00434 os_file_readdir_next_file(
00435
00436 const char* dirname,
00437 os_file_dir_t dir,
00438 os_file_stat_t* info);
00439
00445 UNIV_INTERN
00446 ibool
00447 os_file_create_directory(
00448
00449 const char* pathname,
00451 ibool fail_if_exists);
00453
00459 UNIV_INTERN
00460 os_file_t
00461 os_file_create_simple_func(
00462
00463 const char* name,
00465 ulint create_mode,
00472 ulint access_type,
00474 ibool* success);
00475
00481 UNIV_INTERN
00482 os_file_t
00483 os_file_create_simple_no_error_handling_func(
00484
00485 const char* name,
00487 ulint create_mode,
00491 ulint access_type,
00495 ibool* success);
00496
00498 UNIV_INTERN
00499 void
00500 os_file_set_nocache(
00501
00502 int fd,
00503 const char* file_name,
00505 const char* operation_name);
00507
00513 UNIV_INTERN
00514 os_file_t
00515 os_file_create_func(
00516
00517 const char* name,
00519 ulint create_mode,
00527 ulint purpose,
00534 ulint type,
00535 ibool* success);
00536
00539 UNIV_INTERN
00540 ibool
00541 os_file_delete(
00542
00543 const char* name);
00545
00548 UNIV_INTERN
00549 ibool
00550 os_file_delete_if_exists(
00551
00552 const char* name);
00553
00559 UNIV_INTERN
00560 ibool
00561 os_file_rename_func(
00562
00563 const char* oldpath,
00565 const char* newpath);
00566
00572 UNIV_INTERN
00573 ibool
00574 os_file_close_func(
00575
00576 os_file_t file);
00578 #ifdef UNIV_PFS_IO
00579
00586 UNIV_INLINE
00587 os_file_t
00588 pfs_os_file_create_simple_func(
00589
00590 mysql_pfs_key_t key,
00591 const char* name,
00593 ulint create_mode,
00600 ulint access_type,
00602 ibool* success,
00603 const char* src_file,
00604 ulint src_line);
00606
00614 UNIV_INLINE
00615 os_file_t
00616 pfs_os_file_create_simple_no_error_handling_func(
00617
00618 mysql_pfs_key_t key,
00619 const char* name,
00621 ulint create_mode,
00625 ulint access_type,
00629 ibool* success,
00630 const char* src_file,
00631 ulint src_line);
00633
00640 UNIV_INLINE
00641 os_file_t
00642 pfs_os_file_create_func(
00643
00644 mysql_pfs_key_t key,
00645 const char* name,
00647 ulint create_mode,
00655 ulint purpose,
00662 ulint type,
00663 ibool* success,
00664 const char* src_file,
00665 ulint src_line);
00667
00672 UNIV_INLINE
00673 ibool
00674 pfs_os_file_close_func(
00675
00676 os_file_t file,
00677 const char* src_file,
00678 ulint src_line);
00679
00685 UNIV_INLINE
00686 ibool
00687 pfs_os_file_read_func(
00688
00689 os_file_t file,
00690 void* buf,
00691 ulint offset,
00693 ulint offset_high,
00695 ulint n,
00696 const char* src_file,
00697 ulint src_line);
00699
00706 UNIV_INLINE
00707 ibool
00708 pfs_os_file_read_no_error_handling_func(
00709
00710 os_file_t file,
00711 void* buf,
00712 ulint offset,
00714 ulint offset_high,
00716 ulint n,
00717 const char* src_file,
00718 ulint src_line);
00720
00726 UNIV_INLINE
00727 ibool
00728 pfs_os_aio_func(
00729
00730 ulint type,
00731 ulint mode,
00732 const char* name,
00734 os_file_t file,
00735 void* buf,
00737 ulint offset,
00739 ulint offset_high,
00741 ulint n,
00742 fil_node_t* message1,
00746 void* message2,
00750 const char* src_file,
00751 ulint src_line);
00752
00758 UNIV_INLINE
00759 ibool
00760 pfs_os_file_write_func(
00761
00762 const char* name,
00764 os_file_t file,
00765 const void* buf,
00766 ulint offset,
00768 ulint offset_high,
00770 ulint n,
00771 const char* src_file,
00772 ulint src_line);
00773
00780 UNIV_INLINE
00781 ibool
00782 pfs_os_file_flush_func(
00783
00784 os_file_t file,
00785 const char* src_file,
00786 ulint src_line);
00788
00794 UNIV_INLINE
00795 ibool
00796 pfs_os_file_rename_func(
00797
00798 mysql_pfs_key_t key,
00799 const char* oldpath,
00801 const char* newpath,
00802 const char* src_file,
00803 ulint src_line);
00804 #endif
00805
00806 #ifdef UNIV_HOTBACKUP
00807
00810 UNIV_INTERN
00811 ibool
00812 os_file_close_no_error_handling(
00813
00814 os_file_t file);
00815 #endif
00816
00819 UNIV_INTERN
00820 ibool
00821 os_file_get_size(
00822
00823 os_file_t file,
00824 ulint* size,
00826 ulint* size_high);
00827
00830 UNIV_INTERN
00831 ib_int64_t
00832 os_file_get_size_as_iblonglong(
00833
00834 os_file_t file);
00835
00838 UNIV_INTERN
00839 ibool
00840 os_file_set_size(
00841
00842 const char* name,
00844 os_file_t file,
00845 ulint size,
00847 ulint size_high);
00848
00851 UNIV_INTERN
00852 ibool
00853 os_file_set_eof(
00854
00855 FILE* file);
00856
00860 UNIV_INTERN
00861 ibool
00862 os_file_flush_func(
00863
00864 os_file_t file);
00865
00871 UNIV_INTERN
00872 ulint
00873 os_file_get_last_error(
00874
00875 ibool report_all_errors);
00877
00881 UNIV_INTERN
00882 ibool
00883 os_file_read_func(
00884
00885 os_file_t file,
00886 void* buf,
00887 ulint offset,
00889 ulint offset_high,
00891 ulint n);
00892
00896 UNIV_INTERN
00897 void
00898 os_file_read_string(
00899
00900 FILE* file,
00901 char* str,
00902 ulint size);
00903
00909 UNIV_INTERN
00910 ibool
00911 os_file_read_no_error_handling_func(
00912
00913 os_file_t file,
00914 void* buf,
00915 ulint offset,
00917 ulint offset_high,
00919 ulint n);
00921
00926 UNIV_INTERN
00927 ibool
00928 os_file_write_func(
00929
00930 const char* name,
00932 os_file_t file,
00933 const void* buf,
00934 ulint offset,
00936 ulint offset_high,
00938 ulint n);
00939
00942 UNIV_INTERN
00943 ibool
00944 os_file_status(
00945
00946 const char* path,
00947 ibool* exists,
00948 os_file_type_t* type);
00949
00977 UNIV_INTERN
00978 char*
00979 os_file_dirname(
00980
00981 const char* path);
00982
00985 UNIV_INTERN
00986 ibool
00987 os_file_create_subdirs_if_needed(
00988
00989 const char* path);
00990
00991
00992
00993
00994
00995
00996
00997 UNIV_INTERN
00998 ibool
00999 os_aio_init(
01000
01001 ulint n_per_seg,
01002
01003 ulint n_read_segs,
01004 ulint n_write_segs,
01005 ulint n_slots_sync);
01006
01007
01008
01009 UNIV_INTERN
01010 void
01011 os_aio_free(void);
01012
01013
01014
01018 UNIV_INTERN
01019 ibool
01020 os_aio_func(
01021
01022 ulint type,
01023 ulint mode,
01036 const char* name,
01038 os_file_t file,
01039 void* buf,
01041 ulint offset,
01043 ulint offset_high,
01045 ulint n,
01046 fil_node_t* message1,
01050 void* message2);
01054
01057 UNIV_INTERN
01058 void
01059 os_aio_wake_all_threads_at_shutdown(void);
01060
01061
01064 UNIV_INTERN
01065 void
01066 os_aio_wait_until_no_pending_writes(void);
01067
01068
01070 UNIV_INTERN
01071 void
01072 os_aio_simulated_wake_handler_threads(void);
01073
01074
01079 UNIV_INTERN
01080 void
01081 os_aio_simulated_put_read_threads_to_sleep(void);
01082
01083
01084 #ifdef WIN_ASYNC_IO
01085
01093 UNIV_INTERN
01094 ibool
01095 os_aio_windows_handle(
01096
01097 ulint segment,
01105 ulint pos,
01107 fil_node_t**message1,
01112 void** message2,
01113 ulint* type);
01114 #endif
01115
01116
01120 UNIV_INTERN
01121 ibool
01122 os_aio_simulated_handle(
01123
01124 ulint segment,
01129 fil_node_t**message1,
01134 void** message2,
01135 ulint* type);
01136
01139 UNIV_INTERN
01140 ibool
01141 os_aio_validate(void);
01142
01143
01145 UNIV_INTERN
01146 void
01147 os_aio_print(
01148
01149 FILE* file);
01150
01152 UNIV_INTERN
01153 void
01154 os_aio_refresh_stats(void);
01155
01156
01157 #ifdef UNIV_DEBUG
01158
01161 UNIV_INTERN
01162 ibool
01163 os_aio_all_slots_free(void);
01164
01165 #endif
01166
01167
01170 UNIV_INTERN
01171 ibool
01172 os_file_get_status(
01173
01174 const char* path,
01175 os_file_stat_t* stat_info);
01178 #if !defined(UNIV_HOTBACKUP)
01179
01183 UNIV_INTERN
01184 int
01185 innobase_mysql_tmpfile(void);
01186
01187 #endif
01188
01189
01190 #if defined(LINUX_NATIVE_AIO)
01191
01192
01193
01194
01195
01196
01197
01198
01199 UNIV_INTERN
01200 ibool
01201 os_aio_linux_handle(
01202
01203 ulint global_seg,
01209 fil_node_t**message1,
01210 void** message2,
01214 ulint* type);
01215 #endif
01216
01217 #ifndef UNIV_NONINL
01218 #include "os0file.ic"
01219 #endif
01220
01221 #endif