| 1 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation; version 2 of the License. |
| 6 | |
| 7 | This program is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | GNU General Public License for more details. |
| 11 | |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software |
| 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 15 | |
| 16 | #ifndef MYSYS_PRIV_INCLUDED |
| 17 | #define MYSYS_PRIV_INCLUDED |
| 18 | |
| 19 | #include <my_global.h> |
| 20 | #include <my_sys.h> |
| 21 | #include <my_crypt.h> |
| 22 | |
| 23 | C_MODE_START |
| 24 | |
| 25 | #ifdef USE_SYSTEM_WRAPPERS |
| 26 | #include "system_wrappers.h" |
| 27 | #endif |
| 28 | |
| 29 | #ifdef HAVE_GETRUSAGE |
| 30 | #include <sys/resource.h> |
| 31 | #endif |
| 32 | |
| 33 | #include <my_pthread.h> |
| 34 | |
| 35 | #ifdef HAVE_PSI_INTERFACE |
| 36 | |
| 37 | #if !defined(HAVE_PREAD) && !defined(_WIN32) |
| 38 | extern PSI_mutex_key key_my_file_info_mutex; |
| 39 | #endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */ |
| 40 | |
| 41 | #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) |
| 42 | extern PSI_mutex_key key_LOCK_localtime_r; |
| 43 | #endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */ |
| 44 | |
| 45 | extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, |
| 46 | key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, key_LOCK_alarm, |
| 47 | key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap, |
| 48 | key_THR_LOCK_lock, key_THR_LOCK_malloc, |
| 49 | key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, |
| 50 | key_THR_LOCK_open, key_THR_LOCK_threads, key_LOCK_uuid_generator, |
| 51 | key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_timer; |
| 52 | |
| 53 | extern PSI_cond_key key_COND_alarm, key_COND_timer, key_IO_CACHE_SHARE_cond, |
| 54 | key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend, |
| 55 | key_THR_COND_threads; |
| 56 | |
| 57 | #ifdef USE_ALARM_THREAD |
| 58 | extern PSI_thread_key key_thread_alarm; |
| 59 | #endif /* USE_ALARM_THREAD */ |
| 60 | extern PSI_thread_key key_thread_timer; |
| 61 | extern PSI_rwlock_key key_SAFEHASH_mutex; |
| 62 | |
| 63 | #endif /* HAVE_PSI_INTERFACE */ |
| 64 | |
| 65 | extern PSI_stage_info stage_waiting_for_table_level_lock; |
| 66 | |
| 67 | extern mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache; |
| 68 | extern mysql_mutex_t THR_LOCK_lock, THR_LOCK_net; |
| 69 | extern mysql_mutex_t THR_LOCK_charset; |
| 70 | |
| 71 | #include <mysql/psi/mysql_file.h> |
| 72 | |
| 73 | #ifdef HAVE_PSI_INTERFACE |
| 74 | #ifdef HUGETLB_USE_PROC_MEMINFO |
| 75 | extern PSI_file_key key_file_proc_meminfo; |
| 76 | #endif /* HUGETLB_USE_PROC_MEMINFO */ |
| 77 | extern PSI_file_key key_file_charset, key_file_cnf; |
| 78 | #endif /* HAVE_PSI_INTERFACE */ |
| 79 | |
| 80 | typedef struct { |
| 81 | ulonglong counter; |
| 82 | uint block_length, last_block_length; |
| 83 | uchar key[MY_AES_BLOCK_SIZE]; |
| 84 | ulonglong inbuf_counter; |
| 85 | } IO_CACHE_CRYPT; |
| 86 | |
| 87 | extern int (*_my_b_encr_read)(IO_CACHE *info,uchar *Buffer,size_t Count); |
| 88 | extern int (*_my_b_encr_write)(IO_CACHE *info,const uchar *Buffer,size_t Count); |
| 89 | |
| 90 | #ifdef SAFEMALLOC |
| 91 | void *sf_malloc(size_t size, myf my_flags); |
| 92 | void *sf_realloc(void *ptr, size_t size, myf my_flags); |
| 93 | void sf_free(void *ptr); |
| 94 | size_t sf_malloc_usable_size(void *ptr, my_bool *is_thread_specific); |
| 95 | #else |
| 96 | #define sf_malloc(X,Y) malloc(X) |
| 97 | #define sf_realloc(X,Y,Z) realloc(X,Y) |
| 98 | #define sf_free(X) free(X) |
| 99 | #endif |
| 100 | |
| 101 | /* |
| 102 | EDQUOT is used only in 3 C files only in mysys/. If it does not exist on |
| 103 | system, we set it to some value which can never happen. |
| 104 | */ |
| 105 | #ifndef EDQUOT |
| 106 | #define EDQUOT (-1) |
| 107 | #endif |
| 108 | |
| 109 | void my_error_unregister_all(void); |
| 110 | |
| 111 | #ifndef O_PATH /* not Linux */ |
| 112 | #if defined(O_SEARCH) /* Illumos */ |
| 113 | #define O_PATH O_SEARCH |
| 114 | #elif defined(O_EXEC) /* FreeBSD */ |
| 115 | #define O_PATH O_EXEC |
| 116 | #endif |
| 117 | #endif |
| 118 | |
| 119 | #ifdef O_PATH |
| 120 | #define HAVE_OPEN_PARENT_DIR_NOSYMLINKS |
| 121 | const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd); |
| 122 | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
| 123 | int dfd, res; \ |
| 124 | const char *filename= my_open_parent_dir_nosymlinks(pathname, &dfd); \ |
| 125 | if (filename == NULL) return -1; \ |
| 126 | res= AT; \ |
| 127 | if (dfd >= 0) close(dfd); \ |
| 128 | return res; |
| 129 | #elif defined(HAVE_REALPATH) && defined(PATH_MAX) |
| 130 | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
| 131 | char buf[PATH_MAX+1]; \ |
| 132 | if (realpath(pathname, buf) == NULL) return -1; \ |
| 133 | if (strcmp(pathname, buf)) { errno= ENOTDIR; return -1; } \ |
| 134 | return NOAT; |
| 135 | #elif defined(HAVE_REALPATH) |
| 136 | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
| 137 | char *buf= realpath(pathname, NULL); \ |
| 138 | int res; \ |
| 139 | if (buf == NULL) return -1; \ |
| 140 | if (strcmp(pathname, buf)) { errno= ENOTDIR; res= -1; } \ |
| 141 | else res= NOAT; \ |
| 142 | free(buf); \ |
| 143 | return res; |
| 144 | #else |
| 145 | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
| 146 | return NOAT; |
| 147 | #endif |
| 148 | |
| 149 | #ifndef _WIN32 |
| 150 | #define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) \ |
| 151 | static int PROTO { NOSYMLINK_FUNCTION_BODY(AT,NOAT) } |
| 152 | #else |
| 153 | #define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) |
| 154 | #endif |
| 155 | |
| 156 | #ifdef _WIN32 |
| 157 | #include <sys/stat.h> |
| 158 | /* my_winfile.c exports, should not be used outside mysys */ |
| 159 | extern File my_win_open(const char *path, int oflag); |
| 160 | extern int my_win_close(File fd); |
| 161 | extern size_t my_win_read(File fd, uchar *buffer, size_t count); |
| 162 | extern size_t my_win_write(File fd, const uchar *buffer, size_t count); |
| 163 | extern size_t my_win_pread(File fd, uchar *buffer, size_t count, |
| 164 | my_off_t offset); |
| 165 | extern size_t my_win_pwrite(File fd, const uchar *buffer, size_t count, |
| 166 | my_off_t offset); |
| 167 | extern my_off_t my_win_lseek(File fd, my_off_t pos, int whence); |
| 168 | extern int my_win_chsize(File fd, my_off_t newlength); |
| 169 | extern FILE* my_win_fopen(const char *filename, const char *type); |
| 170 | extern File my_win_fclose(FILE *file); |
| 171 | extern File my_win_fileno(FILE *file); |
| 172 | extern FILE* my_win_fdopen(File Filedes, const char *type); |
| 173 | extern int my_win_stat(const char *path, struct _stati64 *buf); |
| 174 | extern int my_win_fstat(File fd, struct _stati64 *buf); |
| 175 | extern int my_win_fsync(File fd); |
| 176 | extern File my_win_dup(File fd); |
| 177 | extern File my_win_sopen(const char *path, int oflag, int shflag, int perm); |
| 178 | extern File my_open_osfhandle(HANDLE handle, int oflag); |
| 179 | #endif |
| 180 | |
| 181 | C_MODE_END |
| 182 | |
| 183 | #endif |
| 184 | |