MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
os0file.cc File Reference
#include "os0file.h"
#include "ut0mem.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "fil0fil.h"
#include "buf0buf.h"
#include "srv0mon.h"
#include "os0sync.h"
#include "os0thread.h"
Include dependency graph for os0file.cc:

Go to the source code of this file.

Classes

struct  os_aio_slot_t
struct  os_aio_array_t

Macros

#define OS_FILE_N_SEEK_MUTEXES   16
#define OS_AIO_MERGE_N_CONSECUTIVE   64
#define USE_FILE_LOCK
#define OS_FILE_PATH_SEPARATOR   '/'

Functions

UNIV_INTERN ulint os_file_get_last_error (bool report_all_errors)
UNIV_INTERN void os_io_init_simple (void)
UNIV_INTERN FILE * os_file_create_tmpfile (void)
UNIV_INTERN os_file_dir_t os_file_opendir (const char *dirname, ibool error_is_fatal)
UNIV_INTERN int os_file_closedir (os_file_dir_t dir)
UNIV_INTERN int os_file_readdir_next_file (const char *dirname, os_file_dir_t dir, os_file_stat_t *info)
UNIV_INTERN ibool os_file_create_directory (const char *pathname, ibool fail_if_exists)
UNIV_INTERN os_file_t os_file_create_simple_func (const char *name, ulint create_mode, ulint access_type, ibool *success)
UNIV_INTERN os_file_t os_file_create_simple_no_error_handling_func (const char *name, ulint create_mode, ulint access_type, ibool *success)
UNIV_INTERN void os_file_set_nocache (int fd__attribute__((unused)), const char *file_name__attribute__((unused)), const char *operation_name __attribute__((unused)))
UNIV_INTERN os_file_t os_file_create_func (const char *name, ulint create_mode, ulint purpose, ulint type, ibool *success)
UNIV_INTERN bool os_file_delete_if_exists_func (const char *name)
UNIV_INTERN bool os_file_delete_func (const char *name)
UNIV_INTERN ibool os_file_rename_func (const char *oldpath, const char *newpath)
UNIV_INTERN ibool os_file_close_func (os_file_t file)
UNIV_INTERN os_offset_t os_file_get_size (os_file_t file)
UNIV_INTERN ibool os_file_set_size (const char *name, os_file_t file, os_offset_t size)
UNIV_INTERN ibool os_file_set_eof (FILE *file)
UNIV_INTERN ibool os_file_flush_func (os_file_t file)

Variables

UNIV_INTERN ulint os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
UNIV_INTERN os_ib_mutex_t os_file_seek_mutexes [OS_FILE_N_SEEK_MUTEXES]
UNIV_INTERN ibool os_aio_print_debug = FALSE
UNIV_INTERN ulint os_n_file_reads = 0
UNIV_INTERN ulint os_bytes_read_since_printout = 0
UNIV_INTERN ulint os_n_file_writes = 0
UNIV_INTERN ulint os_n_fsyncs = 0
UNIV_INTERN ulint os_n_file_reads_old = 0
UNIV_INTERN ulint os_n_file_writes_old = 0
UNIV_INTERN ulint os_n_fsyncs_old = 0
UNIV_INTERN time_t os_last_printout
UNIV_INTERN ibool os_has_said_disk_full = FALSE
UNIV_INTERN ulint os_file_n_pending_preads = 0
UNIV_INTERN ulint os_file_n_pending_pwrites = 0
UNIV_INTERN ulint os_n_pending_writes = 0
UNIV_INTERN ulint os_n_pending_reads = 0
static void * buf
static void ulint n

Detailed Description

The interface to the operating system file i/o primitives

Created 10/21/1995 Heikki Tuuri

Definition in file os0file.cc.

Function Documentation

UNIV_INTERN ibool os_file_close_func ( os_file_t  file)

NOTE! Use the corresponding macro os_file_close(), not directly this function! Closes a file handle. In case of error, error number can be retrieved with os_file_get_last_error.

Returns
TRUE if success
Parameters
filein, own: handle to a file

Definition at line 1973 of file os0file.cc.

UNIV_INTERN int os_file_closedir ( os_file_dir_t  dir)

Closes a directory stream.

Returns
0 if success, -1 if failure
Parameters
dirin: directory stream

Definition at line 848 of file os0file.cc.

Here is the caller graph for this function:

UNIV_INTERN ibool os_file_create_directory ( const char *  pathname,
ibool  fail_if_exists 
)

This function attempts to create a directory named pathname. The new directory gets default permissions. On Unix the permissions are (0770 & ~umask). If the directory exists already, nothing is done and the call succeeds, unless the fail_if_exists arguments is true. If another error occurs, such as a permission error, this does not crash, but reports the error and returns FALSE.

Returns
TRUE if call succeeds, FALSE on error
Parameters
pathnamein: directory name as null-terminated string
fail_if_existsin: if TRUE, pre-existing directory is treated as an error.

Definition at line 1063 of file os0file.cc.

UNIV_INTERN os_file_t os_file_create_func ( const char *  name,
ulint  create_mode,
ulint  purpose,
ulint  type,
ibool *  success 
)

NOTE! Use the corresponding macro os_file_create(), not directly this function! Opens an existing file or creates a new.

Returns
own: handle to the file, not defined if error, error number can be retrieved with os_file_get_last_error
Parameters
namein: name of the file or path as a null-terminated string
create_modein: create mode
purposein: OS_FILE_AIO, if asynchronous, non-buffered i/o is desired, OS_FILE_NORMAL, if any normal file; NOTE that it also depends on type, os_aio_.. and srv_.. variables whether we really use async i/o or unbuffered i/o: look in the function source code for the exact rules
typein: OS_DATA_FILE or OS_LOG_FILE
successout: TRUE if succeed, FALSE if error

Definition at line 1492 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN os_file_t os_file_create_simple_func ( const char *  name,
ulint  create_mode,
ulint  access_type,
ibool *  success 
)

NOTE! Use the corresponding macro os_file_create_simple(), not directly this function! A simple function to open or create a file.

Returns
own: handle to the file, not defined if error, error number can be retrieved with os_file_get_last_error
Parameters
namein: name of the file or path as a null-terminated string
create_modein: create mode
access_typein: OS_FILE_READ_ONLY or OS_FILE_READ_WRITE
successout: TRUE if succeed, FALSE if error

Definition at line 1109 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN os_file_t os_file_create_simple_no_error_handling_func ( const char *  name,
ulint  create_mode,
ulint  access_type,
ibool *  success 
)

NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(), not directly this function! A simple function to open or create a file.

Returns
own: handle to the file, not defined if error, error number can be retrieved with os_file_get_last_error
Parameters
namein: name of the file or path as a null-terminated string
create_modein: create mode
access_typein: OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or OS_FILE_READ_ALLOW_DELETE; the last option is used by a backup program reading the file
successout: TRUE if succeed, FALSE if error

Definition at line 1303 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN FILE* os_file_create_tmpfile ( void  )

Creates a temporary file. This function is like tmpfile(3), but the temporary file is created in the MySQL temporary directory.

Returns
temporary file handle, or NULL on error

Definition at line 757 of file os0file.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN bool os_file_delete_func ( const char *  name)

Deletes a file. The file has to be closed before calling this.

Returns
TRUE if success
Parameters
namein: file path as a null-terminated string

Definition at line 1854 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN bool os_file_delete_if_exists_func ( const char *  name)

Deletes a file if it exists. The file has to be closed before calling this.

Returns
TRUE if success
Parameters
namein: file path as a null-terminated string

Definition at line 1792 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN ibool os_file_flush_func ( os_file_t  file)

NOTE! Use the corresponding macro os_file_flush(), not directly this function! Flushes the write buffers of a given file to the disk.

Returns
TRUE if success
Parameters
filein, own: handle to a file

Definition at line 2223 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN ulint os_file_get_last_error ( bool  report_all_errors)

Retrieves the last error number if an error occurs in a file io function. The number should be retrieved before any other OS calls (because they may overwrite the error number). If the number is not known to this program, the OS error number + 100 is returned.

Returns
error number, or OS error number + 100
Parameters
report_all_errorsin: TRUE if we want an error message printed of all errors

Definition at line 556 of file os0file.cc.

Here is the caller graph for this function:

UNIV_INTERN os_offset_t os_file_get_size ( os_file_t  file)

Gets a file size.

Returns
file size, or (os_offset_t) -1 on failure
Parameters
filein: handle to a file

Definition at line 2048 of file os0file.cc.

Here is the caller graph for this function:

UNIV_INTERN os_file_dir_t os_file_opendir ( const char *  dirname,
ibool  error_is_fatal 
)

The os_file_opendir() function opens a directory stream corresponding to the directory named by the dirname argument. The directory stream is positioned at the first entry. In both Unix and Windows we automatically skip the '.' and '..' items at the start of the directory listing.

Returns
directory stream, NULL if error
Parameters
dirnamein: directory name; it must not contain a trailing '\' or '/'
error_is_fatalin: TRUE if we should treat an error as a fatal error; if we try to open symlinks then we do not wish a fatal error if it happens not to be a directory

Definition at line 791 of file os0file.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN int os_file_readdir_next_file ( const char *  dirname,
os_file_dir_t  dir,
os_file_stat_t info 
)

This function returns information of the next file in the directory. We jump over the '.' and '..' entries in the directory.

Returns
0 if ok, -1 if error, 1 if at the end of the directory
Parameters
dirnamein: directory name or path
dirin: directory stream
infoin/out: buffer where the info is returned

Definition at line 883 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN ibool os_file_rename_func ( const char *  oldpath,
const char *  newpath 
)

NOTE! Use the corresponding macro os_file_rename(), not directly this function! Renames a file (can also move it to another directory). It is safest that the file is closed before calling this function.

Returns
TRUE if success
Parameters
oldpathin: old file path as a null-terminated string
newpathin: new file path

Definition at line 1920 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN ibool os_file_set_eof ( FILE *  file)

Truncates a file at its current position.

Returns
TRUE if success
Parameters
filein: file to be truncated

Definition at line 2156 of file os0file.cc.

Here is the caller graph for this function:

UNIV_INTERN void os_file_set_nocache ( int   fd__attribute__(unused),
const char *  file_name__attribute__(unused),
const char *operation_name   __attribute__(unused) 
)

Tries to disable OS caching on an opened file descriptor.

Parameters
fd__attribute__in: file descriptor to alter
file_name__attribute__in: used in the diagnostic message
__attribute__in: "open" or "create"; used in the diagnostic message

Definition at line 1444 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN ibool os_file_set_size ( const char *  name,
os_file_t  file,
os_offset_t  size 
)

Write the specified number of zeros to a newly created file.

Returns
TRUE if success
Parameters
namein: name of the file or path as a null-terminated string
filein: handle to a file
sizein: file size

Definition at line 2076 of file os0file.cc.

Here is the call graph for this function:

UNIV_INTERN void os_io_init_simple ( void  )

Creates the seek mutexes used in positioned reads and writes.

Definition at line 739 of file os0file.cc.

Here is the call graph for this function:

Variable Documentation

void* buf

< in: handle to a file in: buffer where to read

Definition at line 2322 of file os0file.cc.

void ulint n

in: number of bytes to read

Definition at line 2322 of file os0file.cc.

UNIV_INTERN ibool os_aio_print_debug = FALSE

Flag: enable debug printout for asynchronous i/o

Definition at line 145 of file os0file.cc.

UNIV_INTERN ulint os_file_n_pending_preads = 0

Number of pending os_file_pread() operations

Definition at line 289 of file os0file.cc.

UNIV_INTERN ulint os_file_n_pending_pwrites = 0

Number of pending os_file_pwrite() operations

Definition at line 291 of file os0file.cc.

UNIV_INTERN ulint os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP

Umask for creating files

Definition at line 75 of file os0file.cc.

UNIV_INTERN ulint os_n_pending_reads = 0

Number of pending read operations

Definition at line 295 of file os0file.cc.

UNIV_INTERN ulint os_n_pending_writes = 0

Number of pending write operations

Definition at line 293 of file os0file.cc.