]> wimlib.net Git - wimlib/blobdiff - tests/wlfuzz.c
win32: update WOF ioctl definitions
[wimlib] / tests / wlfuzz.c
index dc62d44d3b64ff688384c1b06e02df37c8a72cfa..7b3589b99e0fe4dc4e235c5375de35a07390ec18 100644 (file)
@@ -3,7 +3,7 @@
  */
 
 /*
- * Copyright (C) 2015-2016 Eric Biggers
+ * Copyright (C) 2015-2021 Eric Biggers
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -498,48 +498,67 @@ get_random_write_flags(void)
        return write_flags;
 }
 
+static uint32_t
+get_random_chunk_size(int min_order, int max_order)
+{
+       return 1 << (min_order + (rand32() % (max_order - min_order + 1)));
+}
+
 static void
 op__create_new_wim(void)
 {
        printf(":::op__create_new_wim\n");
 
        const tchar *wimfile;
-       WIMStruct *wim;
+       enum wimlib_compression_type ctype = WIMLIB_COMPRESSION_TYPE_NONE;
+       uint32_t chunk_size = 0;
+       uint32_t solid_chunk_size = 0;
        int write_flags;
+       WIMStruct *wim;
 
        if (num_wimfiles_in_use == MAX_NUM_WIMS)
                return;
 
        wimfile = select_new_wimfile();
 
-       CHECK_RET(wimlib_create_new_wim(WIMLIB_COMPRESSION_TYPE_NONE, &wim));
-
        /* Select a random compression type and chunk size.  */
-       switch (rand32() % 8) {
-       default:
-               CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_NONE));
+       switch (rand32() % 4) {
+       case 0:
                break;
-       case 3 ... 4:
-               CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_XPRESS));
-               CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << (12 + rand32() % 5)));
+       case 1:
+               ctype = WIMLIB_COMPRESSION_TYPE_XPRESS;
+               chunk_size = get_random_chunk_size(12, 16);
                break;
-       case 5 ... 6:
-               CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_LZX));
+       case 2:
+               ctype = WIMLIB_COMPRESSION_TYPE_LZX;
                if (randbool())
-                       CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << 15));
+                       chunk_size = 1 << 15;
                else
-                       CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << (15 + rand32() % 7)));
+                       chunk_size = get_random_chunk_size(15, 21);
                break;
-       case 7:
-               CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_LZMS));
-               CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << (15 + rand32() % 12)));
+       case 3:
+               ctype = WIMLIB_COMPRESSION_TYPE_LZMS;
+               chunk_size = get_random_chunk_size(15, 28);
+               if (randbool())
+                       solid_chunk_size = get_random_chunk_size(15, 26);
+               else
+                       solid_chunk_size = get_random_chunk_size(26, 28);
                break;
        }
 
        /* Select random write flags.  */
        write_flags = get_random_write_flags();
 
-       printf("Creating %"TS" with write flags 0x%08x\n", wimfile, write_flags);
+       printf("Creating %"TS" with write flags 0x%08x, compression_type=%"TS", chunk_size=%u, solid_chunk_size=%u\n",
+              wimfile, write_flags,
+              wimlib_get_compression_type_string(ctype),
+              chunk_size, solid_chunk_size);
+
+       CHECK_RET(wimlib_create_new_wim(ctype, &wim));
+       if (chunk_size != 0)
+               CHECK_RET(wimlib_set_output_chunk_size(wim, chunk_size));
+       if (solid_chunk_size != 0)
+               CHECK_RET(wimlib_set_output_pack_chunk_size(wim, solid_chunk_size));
 
        CHECK_RET(wimlib_write(wim, wimfile, WIMLIB_ALL_IMAGES, write_flags, 0));
 
@@ -801,10 +820,10 @@ unregister_all_backing_wims(const tchar drive_letter)
        HANDLE h;
        void *overlay_list;
        DWORD bytes_returned;
-       const struct wim_provider_overlay_entry *entry;
+       const WIM_PROVIDER_OVERLAY_ENTRY *entry;
        struct {
-               struct wof_external_info wof_info;
-               struct wim_provider_remove_overlay_input wim;
+               WOF_EXTERNAL_INFO wof_info;
+               WIM_PROVIDER_REMOVE_OVERLAY_INPUT wim;
        } in;
 
        wsprintf(volume, L"\\\\.\\%lc:", drive_letter);
@@ -818,11 +837,11 @@ unregister_all_backing_wims(const tchar drive_letter)
        overlay_list = malloc(32768);
        ASSERT(overlay_list != NULL, "out of memory");
 
-       in.wof_info.version = WOF_CURRENT_VERSION;
-       in.wof_info.provider = WOF_PROVIDER_WIM;
+       in.wof_info.Version = WOF_CURRENT_VERSION;
+       in.wof_info.Provider = WOF_PROVIDER_WIM;
 
        if (!DeviceIoControl(h, FSCTL_ENUM_OVERLAY,
-                            &in, sizeof(struct wof_external_info),
+                            &in, sizeof(WOF_EXTERNAL_INFO),
                             overlay_list, 32768, &bytes_returned, NULL))
        {
                ASSERT(GetLastError() == ERROR_INVALID_FUNCTION ||
@@ -835,16 +854,16 @@ unregister_all_backing_wims(const tchar drive_letter)
        entry = overlay_list;
        for (;;) {
                printf("Unregistering data source ID %"PRIu64"\n",
-                      entry->data_source_id);
-               in.wim.data_source_id = entry->data_source_id;
+                      entry->DataSourceId.QuadPart);
+               in.wim.DataSourceId = entry->DataSourceId;
                ASSERT(DeviceIoControl(h, FSCTL_REMOVE_OVERLAY, &in, sizeof(in),
                                       NULL, 0, &bytes_returned, NULL),
                       "FSCTL_REMOVE_OVERLAY failed; error=%u",
                       (unsigned )GetLastError());
-               if (entry->next_entry_offset == 0)
+               if (entry->NextEntryOffset == 0)
                        break;
-               entry = (const struct wim_provider_overlay_entry *)
-                       ((const uint8_t *)entry + entry->next_entry_offset);
+               entry = (const WIM_PROVIDER_OVERLAY_ENTRY *)
+                       ((const uint8_t *)entry + entry->NextEntryOffset);
        }
        free(overlay_list);
        CloseHandle(h);