File opening, unlinking, and closing. More...
#include "private.h"
#include <fcntl.h>
#include "tuklib_open_stdxxx.h"
Defines | |
#define | O_BINARY 0 |
#define | O_NOCTTY 0 |
Functions | |
static bool | io_write_buf (file_pair *pair, const uint8_t *buf, size_t size) |
void | io_init (void) |
Initialize the I/O module. | |
void | io_no_sparse (void) |
Disable creation of sparse files when decompressing. | |
static void | io_unlink (const char *name, const struct stat *known_st) |
Unlink a file. | |
static void | io_copy_attrs (const file_pair *pair) |
Copies owner/group and permissions. | |
static bool | io_open_src_real (file_pair *pair) |
Opens the source file. Returns false on success, true on error. | |
file_pair * | io_open_src (const char *src_name) |
Open the source file. | |
static void | io_close_src (file_pair *pair, bool success) |
Closes source file of the file_pair structure. | |
static bool | io_open_dest_real (file_pair *pair) |
bool | io_open_dest (file_pair *pair) |
Open the destination file. | |
static bool | io_close_dest (file_pair *pair, bool success) |
Closes destination file of the file_pair structure. | |
void | io_close (file_pair *pair, bool success) |
Closes the file descriptors and frees possible allocated memory. | |
size_t | io_read (file_pair *pair, io_buf *buf_union, size_t size) |
Reads from the source file to a buffer. | |
bool | io_pread (file_pair *pair, io_buf *buf, size_t size, off_t pos) |
Read from source file from given offset to a buffer. | |
static bool | is_sparse (const io_buf *buf) |
bool | io_write (file_pair *pair, const io_buf *buf, size_t size) |
Writes a buffer to the destination file. | |
Variables | |
static bool | warn_fchown |
static bool | try_sparse = true |
If true, try to create sparse files when decompressing. | |
static int | stdout_flags = 0 |
File opening, unlinking, and closing.
void io_init | ( | void | ) |
Initialize the I/O module.
void io_no_sparse | ( | void | ) |
Disable creation of sparse files when decompressing.
References try_sparse.
static void io_unlink | ( | const char * | name, | |
const struct stat * | known_st | |||
) | [static] |
Unlink a file.
This tries to verify that the file being unlinked really is the file that we want to unlink by verifying device and inode numbers. There's still a small unavoidable race, but this is much better than nothing (the file could have been moved/replaced even hours earlier).
References message_error().
Referenced by io_close_dest(), and io_close_src().
static void io_copy_attrs | ( | const file_pair * | pair | ) | [static] |
Copies owner/group and permissions.
References file_pair::dest_fd, file_pair::dest_name, message_warning(), and file_pair::src_st.
Referenced by io_close().
static bool io_open_src_real | ( | file_pair * | pair | ) | [static] |
Opens the source file. Returns false on success, true on error.
References message_error(), message_warning(), signals_block(), signals_unblock(), file_pair::src_fd, file_pair::src_name, file_pair::src_st, and user_abort.
Referenced by io_open_src().
file_pair* io_open_src | ( | const char * | src_name | ) |
Open the source file.
References io_open_src_real(), is_empty_filename(), signals_block(), signals_unblock(), and file_pair::src_name.
Referenced by coder_run(), and list_file().
static void io_close_src | ( | file_pair * | pair, | |
bool | success | |||
) | [static] |
Closes source file of the file_pair structure.
pair | File whose src_fd should be closed | |
success | If true, the file will be removed from the disk if closing succeeds and --keep hasn't been used. |
References io_unlink(), file_pair::src_fd, file_pair::src_name, and file_pair::src_st.
Referenced by io_close().
bool io_open_dest | ( | file_pair * | pair | ) |
Open the destination file.
References signals_block(), and signals_unblock().
Referenced by coder_run().
static bool io_close_dest | ( | file_pair * | pair, | |
bool | success | |||
) | [static] |
Closes destination file of the file_pair structure.
pair | File whose dest_fd should be closed | |
success | If false, the file will be removed from the disk. |
References file_pair::dest_fd, file_pair::dest_name, file_pair::dest_st, io_unlink(), message_error(), and stdout_flags.
Referenced by io_close().
void io_close | ( | file_pair * | pair, | |
bool | success | |||
) |
Closes the file descriptors and frees possible allocated memory.
The success argument determines if source or destination file gets unlinked:
References file_pair::dest_fd, file_pair::dest_name, file_pair::dest_pending_sparse, file_pair::dest_try_sparse, io_close_dest(), io_close_src(), io_copy_attrs(), message_error(), signals_block(), and signals_unblock().
Referenced by coder_run(), and list_file().
Reads from the source file to a buffer.
pair | File pair having the source file open for reading | |
buf | Destination buffer to hold the read data | |
size | Size of the buffer; assumed be smaller than SSIZE_MAX |
References message_error(), file_pair::src_eof, file_pair::src_fd, file_pair::src_name, and user_abort.
Referenced by coder_normal(), coder_passthru(), coder_run(), and io_pread().
Read from source file from given offset to a buffer.
This is remotely similar to standard pread(). This uses lseek() though, so the read offset is changed on each call.
pair | Seekable source file | |
buf | Destination buffer | |
size | Amount of data to read | |
pos | Offset relative to the beginning of the file, from which the data should be read. |
References io_read(), message_error(), file_pair::src_fd, and file_pair::src_name.
Referenced by parse_block_header(), parse_check_value(), and parse_indexes().
Writes a buffer to the destination file.
pair | File pair having the destination file open for writing | |
buf | Buffer containing the data to be written | |
size | Size of the buffer; assumed be smaller than SSIZE_MAX |
References file_pair::dest_fd, file_pair::dest_name, file_pair::dest_pending_sparse, file_pair::dest_try_sparse, and message_error().
Referenced by coder_normal(), and coder_passthru().
bool try_sparse = true [static] |
If true, try to create sparse files when decompressing.
Referenced by io_no_sparse().
int stdout_flags = 0 [static] |
File status flags of standard output. This is used by io_open_dest() and io_close_dest().
Referenced by io_close_dest().