+ if (!wim_chunk_size_valid(chunk_size, wim->out_compression_type)) {
+ ERROR("Invalid chunk size (%"PRIu32" bytes) "
+ "for compression type %"TS"!",
+ chunk_size,
+ wimlib_get_compression_type_string(wim->out_compression_type));
+ switch (wim->out_compression_type) {
+ case WIMLIB_COMPRESSION_TYPE_XPRESS:
+ ERROR("Valid chunk sizes for XPRESS are "
+ "32768, 65536, 131072, ..., 67108864.");
+ break;
+ case WIMLIB_COMPRESSION_TYPE_LZX:
+ ERROR("Valid chunk sizes for LZX are "
+ "32768, 65536, 131072, ..., 2097152.");
+ break;
+ case WIMLIB_COMPRESSION_TYPE_LZMS:
+ ERROR("Valid chunk sizes for LZMS are 131072.");
+ break;
+ }
+ return WIMLIB_ERR_INVALID_CHUNK_SIZE;
+ }
+ if (chunk_size != 32768) {
+ WARNING ("Changing the compression chunk size to any value other than\n"
+ " the default of 32768 bytes eliminates compatibility with\n"
+ " Microsoft's software!");
+ }
+ wim->out_chunk_size = chunk_size;
+ return 0;
+}
+
+static int
+do_open_wim(const tchar *filename, struct filedes *fd_ret)
+{
+ int raw_fd;
+
+ raw_fd = topen(filename, O_RDONLY | O_BINARY);
+ if (raw_fd < 0) {
+ ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename);
+ return WIMLIB_ERR_OPEN;
+ }
+ filedes_init(fd_ret, raw_fd);
+ return 0;
+}
+
+int
+reopen_wim(WIMStruct *wim)
+{
+ wimlib_assert(!filedes_valid(&wim->in_fd));
+ return do_open_wim(wim->filename, &wim->in_fd);
+}
+
+int
+close_wim(WIMStruct *wim)
+{
+ if (filedes_valid(&wim->in_fd)) {
+ filedes_close(&wim->in_fd);
+ filedes_invalidate(&wim->in_fd);
+ }
+ return 0;