X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwim.c;h=8022423c98c52dc2796ed5244ef1f616ffc7b82f;hb=794ecd09fc527e3328e469c14e563d42a7a70a39;hp=c82730c8a5e9e126b2dc8ea49658578503fc6705;hpb=4f953b223bed60d71a7689d414ccb5cc60be537f;p=wimlib diff --git a/src/wim.c b/src/wim.c index c82730c8..8022423c 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; } @@ -197,7 +197,7 @@ select_wim_image(WIMStruct *w, int image) } w->current_image = image; imd = wim_get_current_image_metadata(w); - if (imd->root_dentry) { + if (imd->root_dentry || imd->modified) { ret = 0; } else { #ifdef ENABLE_DEBUG @@ -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); - if (fd == INVALID_FILEDES) { + fd = topen(filename, O_RDONLY | O_BINARY); + 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; } @@ -453,7 +453,7 @@ begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags, return WIMLIB_ERR_OPEN; } - ret = read_header(w->in_fd, &w->hdr, open_flags); + ret = read_header(w->filename, w->in_fd, &w->hdr, open_flags); if (ret) return ret; @@ -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);