+ int ret;
+
+ if (which & WIMLIB_CHANGE_READONLY_FLAG) {
+ if (info->is_marked_readonly)
+ wim->hdr.flags |= WIM_HDR_FLAG_READONLY;
+ else
+ wim->hdr.flags &= ~WIM_HDR_FLAG_READONLY;
+ }
+
+ if ((which & ~WIMLIB_CHANGE_READONLY_FLAG) == 0)
+ return 0;
+
+ ret = can_modify_wim(wim);
+ if (ret)
+ return ret;
+
+ if (which & WIMLIB_CHANGE_GUID)
+ memcpy(wim->hdr.guid, info->guid, WIM_GID_LEN);
+
+ if (which & WIMLIB_CHANGE_BOOT_INDEX) {
+ if (info->boot_index < 0 || info->boot_index > wim->hdr.image_count)
+ {
+ ERROR("%u is not 0 or a valid image in the WIM to mark as bootable",
+ info->boot_index);
+ return WIMLIB_ERR_INVALID_IMAGE;
+ }
+ wim->hdr.boot_idx = info->boot_index;
+ }
+
+ if (which & WIMLIB_CHANGE_RPFIX_FLAG) {
+ if (info->has_rpfix)
+ wim->hdr.flags |= WIM_HDR_FLAG_RP_FIX;
+ else
+ wim->hdr.flags &= ~WIM_HDR_FLAG_RP_FIX;
+ }
+ return 0;
+}
+
+/* Deprecated */
+WIMLIBAPI int
+wimlib_set_boot_idx(WIMStruct *wim, int boot_idx)
+{
+ struct wimlib_wim_info info;
+
+ info.boot_index = boot_idx;
+ return wimlib_set_wim_info(wim, &info, WIMLIB_CHANGE_BOOT_INDEX);
+}
+
+static int
+do_open_wim(const tchar *filename, int *fd_ret)
+{
+ int fd;
+
+ fd = topen(filename, O_RDONLY | O_BINARY);
+ if (fd == -1) {
+ ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename);
+ return WIMLIB_ERR_OPEN;
+ }
+ *fd_ret = fd;
+ return 0;
+}
+
+int
+reopen_wim(WIMStruct *w)
+{
+ wimlib_assert(w->in_fd == -1);
+ return do_open_wim(w->filename, &w->in_fd);
+}
+
+int
+close_wim(WIMStruct *w)
+{
+ if (w->in_fd != -1) {
+ close(w->in_fd);
+ w->in_fd = -1;
+ }
+ return 0;