From: Eric Biggers Date: Sun, 5 May 2013 03:38:39 +0000 (-0500) Subject: filedes_t => int X-Git-Tag: v1.4.0~129 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=4f8059f2d0a74a9922128b162d9c9343b305999c;hp=1dc6ed6a978ee91dc0be44f70c5dd738696d54fb filedes_t => int --- diff --git a/src/header.c b/src/header.c index 2524793d..70abf2f2 100644 --- a/src/header.c +++ b/src/header.c @@ -33,7 +33,7 @@ static const u8 wim_magic_chars[WIM_MAGIC_LEN] = { /* 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]; diff --git a/src/integrity.c b/src/integrity.c index 37ff7b74..9afec969 100644 --- a/src/integrity.c +++ b/src/integrity.c @@ -46,7 +46,7 @@ struct integrity_table { }; 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]; @@ -100,7 +100,7 @@ calculate_chunk_sha1(filedes_t in_fd, size_t this_chunk_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) { @@ -223,7 +223,7 @@ out: * 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, @@ -354,7 +354,7 @@ calculate_integrity_table(filedes_t in_fd, * 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, @@ -441,7 +441,7 @@ out_free_old_table: * -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) diff --git a/src/join.c b/src/join.c index 1de8b76b..b6bf6ebd 100644 --- a/src/join.c +++ b/src/join.c @@ -127,7 +127,7 @@ join_wims(WIMStruct **swms, unsigned num_swms, 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]); diff --git a/src/lookup_table.c b/src/lookup_table.c index c3bd2acb..e2ca5920 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -534,7 +534,7 @@ write_lookup_table_entry(struct wim_lookup_table_entry *lte, u8 *buf_p) 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; diff --git a/src/lookup_table.h b/src/lookup_table.h index 38b52ea8..921a47c3 100644 --- a/src/lookup_table.h +++ b/src/lookup_table.h @@ -309,7 +309,7 @@ write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry 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 diff --git a/src/metadata_resource.c b/src/metadata_resource.c index b55609e6..3e8b7283 100644 --- a/src/metadata_resource.c +++ b/src/metadata_resource.c @@ -194,7 +194,7 @@ recalculate_security_data_length(struct wim_security_data *sd) * 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]) { @@ -226,7 +226,7 @@ write_metadata_resource(WIMStruct *w) 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")", diff --git a/src/resource.c b/src/resource.c index 8e1fd241..f54ea259 100644 --- a/src/resource.c +++ b/src/resource.c @@ -48,7 +48,7 @@ * 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, @@ -397,7 +397,7 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte, u64 offset) { WIMStruct *wim; - filedes_t in_fd; + int in_fd; int ret; wimlib_assert(lte->resource_location == RESOURCE_IN_WIM); diff --git a/src/split.c b/src/split.c index 8b67079e..5b14b924 100644 --- a/src/split.c +++ b/src/split.c @@ -226,7 +226,7 @@ wimlib_split(WIMStruct *w, const tchar *swm_name, } 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; diff --git a/src/util.c b/src/util.c index 709ba465..5421a6b5 100644 --- a/src/util.c +++ b/src/util.c @@ -696,7 +696,7 @@ full_writev(int fd, struct iovec *iov, int iovcnt) } off_t -filedes_offset(filedes_t fd) +filedes_offset(int fd) { return lseek(fd, 0, SEEK_CUR); } diff --git a/src/util.h b/src/util.h index 935bbba6..660dcf99 100644 --- a/src/util.h +++ b/src/util.h @@ -285,19 +285,17 @@ hash_u64(u64 n) 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 { @@ -308,17 +306,14 @@ 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 */ diff --git a/src/wim.c b/src/wim.c index 07c1a376..c320b311 100644 --- a/src/wim.c +++ b/src/wim.c @@ -66,8 +66,8 @@ new_wim_struct() { 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; } @@ -385,12 +385,12 @@ wimlib_get_boot_idx(const WIMStruct *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; } @@ -401,16 +401,16 @@ do_open_wim(const tchar *filename, filedes_t *fd_ret) 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; } @@ -671,9 +671,9 @@ wimlib_free(WIMStruct *w) 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); diff --git a/src/wimlib_internal.h b/src/wimlib_internal.h index 65dd8a1d..f668dfd6 100644 --- a/src/wimlib_internal.h +++ b/src/wimlib_internal.h @@ -282,12 +282,12 @@ struct WIMStruct { /* 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; @@ -493,10 +493,10 @@ dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list); /* 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); @@ -508,7 +508,7 @@ 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, @@ -689,7 +689,7 @@ extern int 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); @@ -796,10 +796,10 @@ finish_write(WIMStruct *w, int image, int write_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; } diff --git a/src/write.c b/src/write.c index b5954e34..d184a64a 100644 --- a/src/write.c +++ b/src/write.c @@ -178,7 +178,7 @@ get_compress_func(int out_ctype) 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) { @@ -219,7 +219,7 @@ write_wim_resource_chunk(const void * restrict chunk, */ 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; @@ -244,7 +244,7 @@ finish_wim_resource_chunk_tab(struct chunk_table *chunk_tab, } 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)) @@ -280,7 +280,7 @@ finalize_and_check_sha1(SHA_CTX * restrict sha_ctx, 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; }; @@ -324,7 +324,7 @@ write_resource_cb(const void *restrict chunk, size_t chunk_size, */ 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) { @@ -620,7 +620,7 @@ do_write_streams_progress(union wimlib_progress_info *progress, } struct serial_write_stream_ctx { - filedes_t out_fd; + int out_fd; int out_ctype; int write_resource_flags; }; @@ -715,7 +715,7 @@ do_write_stream_list(struct list_head *stream_list, 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, @@ -747,7 +747,7 @@ write_flags_to_resource_flags(int write_flags) 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, @@ -768,7 +768,7 @@ write_stream_list_serial(struct list_head *stream_list, #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++) { @@ -787,7 +787,7 @@ write_wim_chunks(struct message *msg, filedes_t out_fd, 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; @@ -1223,7 +1223,7 @@ get_default_num_threads() 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, @@ -1361,7 +1361,7 @@ out_serial_quiet: 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; @@ -1805,16 +1805,16 @@ out_close_wim: 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) { @@ -1839,7 +1839,7 @@ static int 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; } @@ -1850,10 +1850,10 @@ open_wim_writable(WIMStruct *w, const tchar *path, int open_flags) 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; } } diff --git a/src/xml.c b/src/xml.c index 23a088e7..da47b28e 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1236,7 +1236,7 @@ libxml_global_cleanup() * 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) { diff --git a/src/xml.h b/src/xml.h index 8840d4ea..d784db14 100644 --- a/src/xml.h +++ b/src/xml.h @@ -38,11 +38,11 @@ extern void 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