MySQL 9.1.0
Source Code Documentation
|
The purpose of this file is to provide implementation of file IO routines on Windows that can be thought as drop-in replacement for corresponding C runtime functionality. More...
#include <algorithm>
#include <iostream>
#include <vector>
#include <errno.h>
#include <fcntl.h>
#include <io.h>
#include <share.h>
#include <sys/stat.h>
#include "mutex_lock.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_sys.h"
#include "my_thread_local.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysys_priv.h"
#include "scope_guard.h"
#include "sql/malloc_allocator.h"
Classes | |
class | anonymous_namespace{my_winfile.cc}::WindowsErrorGuard |
RAII guard which ensures that: More... | |
struct | anonymous_namespace{my_winfile.cc}::HandleInfo |
Namespaces | |
namespace | anonymous_namespace{my_winfile.cc} |
Typedefs | |
using | anonymous_namespace{my_winfile.cc}::HandleInfoAllocator = Malloc_allocator< HandleInfo > |
using | anonymous_namespace{my_winfile.cc}::HandleInfoVector = std::vector< HandleInfo, HandleInfoAllocator > |
Functions | |
size_t | anonymous_namespace{my_winfile.cc}::ToIndex (File fd) |
int | anonymous_namespace{my_winfile.cc}::ToDescr (size_t hi) |
bool | anonymous_namespace{my_winfile.cc}::IsValidIndex (size_t hi) |
HandleInfo | anonymous_namespace{my_winfile.cc}::GetHandleInfo (File fd) |
File | anonymous_namespace{my_winfile.cc}::RegisterHandle (HANDLE handle, int oflag) |
HandleInfo | anonymous_namespace{my_winfile.cc}::UnregisterHandle (File fd) |
File | anonymous_namespace{my_winfile.cc}::FileIndex (HANDLE handle) |
LARGE_INTEGER | anonymous_namespace{my_winfile.cc}::MakeLargeInteger (int64_t src) |
OVERLAPPED | anonymous_namespace{my_winfile.cc}::MakeOverlapped (DWORD l, DWORD h) |
OVERLAPPED | anonymous_namespace{my_winfile.cc}::MakeOverlapped (int64_t src) |
File | anonymous_namespace{my_winfile.cc}::my_win_sopen (const char *path, int oflag, int shflag, int pmode) |
Open a file with sharing. More... | |
File | anonymous_namespace{my_winfile.cc}::my_get_stdfile_descriptor (FILE *stream) |
HANDLE | my_get_osfhandle (File fd) |
Return the Windows HANDLE for a file descriptor obtained from RegisterHandle(). More... | |
File | my_win_open (const char *path, int mode) |
Homegrown posix emulation for Windows. More... | |
int | my_win_close (File fd) |
Homegrown posix emulation for Windows. More... | |
int64_t | my_win_pread (File fd, uchar *buffer, size_t count, int64_t offset) |
Homegrown posix emulation for Windows. More... | |
int64_t | my_win_pwrite (File fd, const uchar *buffer, size_t count, int64_t offset) |
Homegrown posix emulation for Windows. More... | |
int64_t | my_win_lseek (File fd, int64_t pos, int whence) |
Homegrown posix emulation for Windows. More... | |
int64_t | my_win_write (File fd, const uchar *Buffer, size_t Count) |
Homegrown posix emulation for Windows. More... | |
int | my_win_chsize (File fd, int64_t newlength) |
Homegrown posix emulation for Windows. More... | |
File | my_win_fileno (FILE *stream) |
Homegrown posix emulation for Windows. More... | |
FILE * | my_win_fopen (const char *filename, const char *mode) |
Homegrown posix emulation for Windows. More... | |
FILE * | my_win_fdopen (File fd, const char *mode) |
Homegrown posix emulation for Windows. More... | |
int | my_win_fclose (FILE *stream) |
Homegrown posix emulation for Windows. More... | |
FILE * | my_win_freopen (const char *path, const char *mode, FILE *stream) |
Homegrown posix emulation for Windows. More... | |
int | my_win_fstat (File fd, struct _stati64 *buf) |
Homegrown posix emulation for Windows. More... | |
int | my_win_stat (const char *path, struct _stati64 *buf) |
Homegrown posix emulation for Windows. More... | |
int | my_win_fsync (File fd) |
Homegrown posix emulation for Windows. More... | |
void | MyWinfileInit () |
Constructs static objects. More... | |
void | MyWinfileEnd () |
Destroys static objects. More... | |
Variables | |
HandleInfoVector * | anonymous_namespace{my_winfile.cc}::hivp = nullptr |
The purpose of this file is to provide implementation of file IO routines on Windows that can be thought as drop-in replacement for corresponding C runtime functionality.
Compared to Windows CRT, this one
Naming convention: All routines are prefixed with my_win_, e.g Posix open() is implemented with my_win_open()
Implemented are
Worth to note:
Return the Windows HANDLE for a file descriptor obtained from RegisterHandle().
fd | "file descriptor" index into HandleInfoVector. |
handle | corresponding to fd, if found |
INVALID_HANDLE_VALUE,if | fd is not valid (illegal index into HandleInfoVector). In this case SetLastError(ERROR_INVALID_HANDLE) will have been called. |
int my_win_chsize | ( | File | fd, |
int64_t | newlength | ||
) |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
newlength | new desired length. |
0 | if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
int my_win_close | ( | File | fd | ) |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
0 | if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
int my_win_fclose | ( | FILE * | stream | ) |
Homegrown posix emulation for Windows.
stream | FILE stream to close. |
0 | if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
FILE * my_win_fdopen | ( | File | fd, |
const char * | mode | ||
) |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
mode | File access mode string. |
FILE | stream associated with given file descriptor, if successful. |
nullptr | in case of errors. errno and/or LastError set to indicate the error. |
File my_win_fileno | ( | FILE * | stream | ) |
Homegrown posix emulation for Windows.
stream | FILE stream to get fd for. |
Valid | "file descriptor" if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
FILE * my_win_fopen | ( | const char * | filename, |
const char * | mode | ||
) |
Homegrown posix emulation for Windows.
filename | File name. |
mode | File access mode string. |
FILE | stream associated with given file name, if successful. |
nullptr | in case of errors. errno and/or LastError set to indicate the error. |
FILE * my_win_freopen | ( | const char * | path, |
const char * | mode, | ||
FILE * | stream | ||
) |
Homegrown posix emulation for Windows.
path | File name. |
mode | File access mode string |
stream | Existing stream to reopen |
valid | FILE stream if successful. |
nullptr | in case of errors. errno and/or LastError set to indicate the error. |
int my_win_fstat | ( | File | fd, |
struct _stati64 * | buf | ||
) |
Homegrown posix emulation for Windows.
Quick and dirty implementation for Windows. Use CRT fstat on temporarily allocated file descriptor. Patch file size, because size that fstat returns is not reliable (may be outdated).
fd | "File descriptor" (index into mapping vector). | |
[out] | buf | Area to store stat information in. |
0 | if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
int my_win_fsync | ( | File | fd | ) |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
0 | if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
int64_t my_win_lseek | ( | File | fd, |
int64_t | pos, | ||
int | whence | ||
) |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
pos | Offset to seek. |
whence | Where to seek from. |
New | offset into file, if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
File my_win_open | ( | const char * | path, |
int | mode | ||
) |
Homegrown posix emulation for Windows.
path | File name. |
mode | File access mode string. |
valid | "file descriptor" (actually index into mapping vector) if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
Homegrown posix emulation for Windows.
Implements BOTH posix read() and posix pread(). To read from the current file position (like posix read() supply an offset argument that is -1.
fd | "File descriptor" (index into mapping vector). |
buffer | Destination buffer. |
count | Number of bytes to read. |
offset | Offset where read starts. -1 to read from the current file position. |
Number | of bytes read, if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
buffer | Source buffer. |
count | Number of bytes to write. |
offset | Where to start the write. |
Number | of bytes written, if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
int my_win_stat | ( | const char * | path, |
struct _stati64 * | buf | ||
) |
Homegrown posix emulation for Windows.
path | File name to obtain information about. | |
[out] | buf | Area to store stat information in. |
Valid | "file descriptor" (actually index into mapping vector) if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
Homegrown posix emulation for Windows.
fd | "File descriptor" (index into mapping vector). |
Buffer | Source Bytes. |
Count | Number of bytes to write. |
Number | of bytes written, if successful. |
-1 | in case of errors. errno and/or LastError set to indicate the error. |
void MyWinfileEnd | ( | ) |
Destroys static objects.
void MyWinfileInit | ( | ) |
Constructs static objects.