/* Reads the header from a WIM file. */
int
-read_header(filedes_t in_fd, struct wim_header *hdr, int open_flags)
+read_header(int in_fd, struct wim_header *hdr, int open_flags)
{
size_t bytes_read;
u8 buf[WIM_HEADER_DISK_SIZE];
};
static int
-calculate_chunk_sha1(filedes_t in_fd, size_t this_chunk_size,
+calculate_chunk_sha1(int in_fd, size_t this_chunk_size,
off_t offset, u8 sha1_md[])
{
u8 buf[BUFFER_SIZE];
*/
static int
read_integrity_table(const struct resource_entry *res_entry,
- filedes_t in_fd,
+ int in_fd,
u64 num_checked_bytes,
struct integrity_table **table_ret)
{
* Returns 0 on success; nonzero on failure.
*/
static int
-calculate_integrity_table(filedes_t in_fd,
+calculate_integrity_table(int in_fd,
off_t new_check_end,
const struct integrity_table *old_table,
off_t old_check_end,
* to be checked.
*/
int
-write_integrity_table(filedes_t fd,
+write_integrity_table(int fd,
struct resource_entry *integrity_res_entry,
off_t new_lookup_table_end,
off_t old_lookup_table_end,
* -1 (WIM_INTEGRITY_NOT_OK) if the WIM failed the integrity check.
*/
static int
-verify_integrity(filedes_t in_fd, const tchar *filename,
+verify_integrity(int in_fd, const tchar *filename,
const struct integrity_table *table,
u64 bytes_to_check,
wimlib_progress_func_t progress_func)
ret = for_lookup_table_entry_pos_sorted(swms[i]->lookup_table,
copy_resource,
swms[i]);
- swms[i]->out_fd = INVALID_FILEDES;
+ swms[i]->out_fd = -1;
if (i != 0)
close_wim(swms[i]);
int
write_lookup_table_from_stream_list(struct list_head *stream_list,
- filedes_t out_fd,
+ int out_fd,
struct resource_entry *out_res_entry)
{
int ret;
extern int
write_lookup_table_from_stream_list(struct list_head *stream_list,
- filedes_t out_fd,
+ int out_fd,
struct resource_entry *out_res_entry);
extern void
* the buffer to @hash. */
static int
write_wim_resource_from_buffer(const void *buf, size_t buf_size,
- filedes_t out_fd, int out_ctype,
+ int out_fd, int out_ctype,
struct resource_entry *out_res_entry,
u8 hash[SHA1_HASH_SIZE])
{
u64 metadata_original_size;
struct wim_security_data *sd;
- wimlib_assert(w->out_fd != INVALID_FILEDES);
+ wimlib_assert(w->out_fd != -1);
wimlib_assert(w->current_image != WIMLIB_NO_IMAGE);
DEBUG("Writing metadata resource for image %d (offset = %"PRIu64")",
* Returns zero on success, nonzero on failure.
*/
static int
-read_compressed_resource(filedes_t in_fd,
+read_compressed_resource(int in_fd,
u64 resource_compressed_size,
u64 resource_uncompressed_size,
u64 resource_offset,
u64 offset)
{
WIMStruct *wim;
- filedes_t in_fd;
+ int in_fd;
int ret;
wimlib_assert(lte->resource_location == RESOURCE_IN_WIM);
}
part_fd = topen(part_name, O_WRONLY | O_BINARY);
- if (part_fd == INVALID_FILEDES) {
+ if (part_fd == -1) {
ERROR_WITH_ERRNO("Failed to open `%"TS"'", part_name);
ret = WIMLIB_ERR_OPEN;
goto out;
}
off_t
-filedes_offset(filedes_t fd)
+filedes_offset(int fd)
{
return lseek(fd, 0, SEEK_CUR);
}
return n * 0x9e37fffffffc0001ULL;
}
-typedef int filedes_t;
-
extern size_t
-full_read(filedes_t fd, void *buf, size_t n);
+full_read(int fd, void *buf, size_t n);
extern size_t
-full_write(filedes_t fd, const void *buf, size_t n);
+full_write(int fd, const void *buf, size_t n);
extern size_t
-full_pread(filedes_t fd, void *buf, size_t nbyte, off_t offset);
+full_pread(int fd, void *buf, size_t nbyte, off_t offset);
extern size_t
-full_pwrite(filedes_t fd, const void *buf, size_t count, off_t offset);
+full_pwrite(int fd, const void *buf, size_t count, off_t offset);
#ifdef __WIN32__
struct iovec {
struct iovec;
#endif
-
extern size_t
full_writev(int fd, struct iovec *iov, int iovcnt);
extern off_t
-filedes_offset(filedes_t fd);
+filedes_offset(int fd);
#ifndef __WIN32__
# define O_BINARY 0
#endif
-#define INVALID_FILEDES (-1)
-
#endif /* _WIMLIB_UTIL_H */
{
WIMStruct *w = CALLOC(1, sizeof(WIMStruct));
if (w) {
- w->in_fd = INVALID_FILEDES;
- w->out_fd = INVALID_FILEDES;
+ w->in_fd = -1;
+ w->out_fd = -1;
}
return w;
}
}
static int
-do_open_wim(const tchar *filename, filedes_t *fd_ret)
+do_open_wim(const tchar *filename, int *fd_ret)
{
int fd;
fd = topen(filename, O_RDONLY | O_BINARY);
- if (fd == INVALID_FILEDES) {
+ if (fd == -1) {
ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename);
return WIMLIB_ERR_OPEN;
}
int
reopen_wim(WIMStruct *w)
{
- wimlib_assert(w->in_fd == INVALID_FILEDES);
+ wimlib_assert(w->in_fd == -1);
return do_open_wim(w->filename, &w->in_fd);
}
int
close_wim(WIMStruct *w)
{
- if (w->in_fd != INVALID_FILEDES) {
+ if (w->in_fd != -1) {
close(w->in_fd);
- w->in_fd = INVALID_FILEDES;
+ w->in_fd = -1;
}
return 0;
}
if (!w)
return;
- if (w->in_fd != INVALID_FILEDES)
+ if (w->in_fd != -1)
close(w->in_fd);
- if (w->out_fd != INVALID_FILEDES)
+ if (w->out_fd != -1)
close(w->out_fd);
free_lookup_table(w->lookup_table);
/* File descriptor for the WIM file, opened for reading, or -1 if it has
* not been opened or there is no associated file backing it yet. */
- filedes_t in_fd;
+ int in_fd;
/* File descriptor, opened either for writing only or for
* reading+writing, for the WIM file (if any) currently being written.
* */
- filedes_t out_fd;
+ int out_fd;
/* The name of the WIM file (if any) that has been opened. */
tchar *filename;
/* header.c */
extern int
-read_header(filedes_t in_fd, struct wim_header *hdr, int split_ok);
+read_header(int in_fd, struct wim_header *hdr, int split_ok);
extern int
-write_header(const struct wim_header *hdr, filedes_t out_fd);
+write_header(const struct wim_header *hdr, int out_fd);
extern int
init_header(struct wim_header *hdr, int ctype);
#define WIM_INTEGRITY_NONEXISTENT -2
extern int
-write_integrity_table(filedes_t fd,
+write_integrity_table(int fd,
struct resource_entry *integrity_res_entry,
off_t new_lookup_table_end,
off_t old_lookup_table_end,
read_full_resource_into_buf(const struct wim_lookup_table_entry *lte, void *buf);
extern int
-write_wim_resource(struct wim_lookup_table_entry *lte, filedes_t out_fd,
+write_wim_resource(struct wim_lookup_table_entry *lte, int out_fd,
int out_ctype, struct resource_entry *out_res_entry,
int flags);
#if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
extern int
-lock_wim(WIMStruct *w, filedes_t fd);
+lock_wim(WIMStruct *w, int fd);
#else
static inline int
-lock_wim(WIMStruct *w, filedes_t fd)
+lock_wim(WIMStruct *w, int fd)
{
return 0;
}
static int
write_wim_resource_chunk(const void * restrict chunk,
unsigned chunk_size,
- filedes_t out_fd,
+ int out_fd,
compress_func_t compress,
struct chunk_table * restrict chunk_tab)
{
*/
static int
finish_wim_resource_chunk_tab(struct chunk_table *chunk_tab,
- filedes_t out_fd, u64 *compressed_size_p)
+ int out_fd, u64 *compressed_size_p)
{
size_t bytes_written;
}
static int
-seek_and_truncate(filedes_t out_fd, off_t offset)
+seek_and_truncate(int out_fd, off_t offset)
{
if (lseek(out_fd, offset, SEEK_SET) == -1 ||
ftruncate(out_fd, offset))
struct write_resource_ctx {
compress_func_t compress;
struct chunk_table *chunk_tab;
- filedes_t out_fd;
+ int out_fd;
SHA_CTX sha_ctx;
bool doing_sha;
};
*/
int
write_wim_resource(struct wim_lookup_table_entry *lte,
- filedes_t out_fd, int out_ctype,
+ int out_fd, int out_ctype,
struct resource_entry *out_res_entry,
int flags)
{
}
struct serial_write_stream_ctx {
- filedes_t out_fd;
+ int out_fd;
int out_ctype;
int write_resource_flags;
};
static int
do_write_stream_list_serial(struct list_head *stream_list,
struct wim_lookup_table *lookup_table,
- filedes_t out_fd,
+ int out_fd,
int out_ctype,
int write_resource_flags,
wimlib_progress_func_t progress_func,
static int
write_stream_list_serial(struct list_head *stream_list,
struct wim_lookup_table *lookup_table,
- filedes_t out_fd,
+ int out_fd,
int out_ctype,
int write_resource_flags,
wimlib_progress_func_t progress_func,
#ifdef ENABLE_MULTITHREADED_COMPRESSION
static int
-write_wim_chunks(struct message *msg, filedes_t out_fd,
+write_wim_chunks(struct message *msg, int out_fd,
struct chunk_table *chunk_tab)
{
for (unsigned i = 0; i < msg->num_chunks; i++) {
struct main_writer_thread_ctx {
struct list_head *stream_list;
struct wim_lookup_table *lookup_table;
- filedes_t out_fd;
+ int out_fd;
int out_ctype;
int write_resource_flags;
struct shared_queue *res_to_compress_queue;
static int
write_stream_list_parallel(struct list_head *stream_list,
struct wim_lookup_table *lookup_table,
- filedes_t out_fd,
+ int out_fd,
int out_ctype,
int write_resource_flags,
wimlib_progress_func_t progress_func,
static int
write_stream_list(struct list_head *stream_list,
struct wim_lookup_table *lookup_table,
- filedes_t out_fd, int out_ctype, int write_flags,
+ int out_fd, int out_ctype, int write_flags,
unsigned num_threads, wimlib_progress_func_t progress_func)
{
struct wim_lookup_table_entry *lte;
if (ret == 0)
ret = WIMLIB_ERR_WRITE;
}
- w->out_fd = INVALID_FILEDES;
+ w->out_fd = -1;
return ret;
}
#if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
int
-lock_wim(WIMStruct *w, filedes_t fd)
+lock_wim(WIMStruct *w, int fd)
{
int ret = 0;
- if (fd != INVALID_FILEDES && !w->wim_locked) {
+ if (fd != -1 && !w->wim_locked) {
ret = flock(fd, LOCK_EX | LOCK_NB);
if (ret != 0) {
if (errno == EWOULDBLOCK) {
open_wim_writable(WIMStruct *w, const tchar *path, int open_flags)
{
w->out_fd = topen(path, open_flags | O_BINARY, 0644);
- if (w->out_fd == INVALID_FILEDES) {
+ if (w->out_fd == -1) {
ERROR_WITH_ERRNO("Failed to open `%"TS"' for writing", path);
return WIMLIB_ERR_OPEN;
}
void
close_wim_writable(WIMStruct *w)
{
- if (w->out_fd != INVALID_FILEDES) {
+ if (w->out_fd != -1) {
if (close(w->out_fd))
WARNING_WITH_ERRNO("Failed to close output WIM");
- w->out_fd = INVALID_FILEDES;
+ w->out_fd = -1;
}
}
* Reads the XML data from a WIM file.
*/
int
-read_xml_data(filedes_t in_fd,
+read_xml_data(int in_fd,
const struct resource_entry *res_entry,
struct wim_info **info_ret)
{
print_image_info(const struct wim_info *wim_info, int image);
extern int
-read_xml_data(filedes_t in_fd, const struct resource_entry *res,
+read_xml_data(int in_fd, const struct resource_entry *res,
struct wim_info **info_ret);
extern int
-write_xml_data(const struct wim_info *wim_info, int image, filedes_t out_fd,
+write_xml_data(const struct wim_info *wim_info, int image, int out_fd,
u64 total_bytes, struct resource_entry *out_res_entry);
extern void