Exemple #1
0
/* API function documented in wimlib.h  */
WIMLIBAPI void
wimlib_free(WIMStruct *wim)
{
    if (!wim)
        return;

    while (!list_empty(&wim->subwims)) {
        WIMStruct *subwim;

        subwim = list_entry(wim->subwims.next, WIMStruct, subwim_node);
        list_del(&subwim->subwim_node);
        wimlib_free(subwim);
    }

    if (filedes_valid(&wim->in_fd))
        filedes_close(&wim->in_fd);
    if (filedes_valid(&wim->out_fd))
        filedes_close(&wim->out_fd);

    free_blob_table(wim->blob_table);

    wimlib_free_decompressor(wim->decompressor);

    FREE(wim->filename);
    free_wim_info(wim->wim_info);
    if (wim->image_metadata) {
        for (unsigned i = 0; i < wim->hdr.image_count; i++)
            put_image_metadata(wim->image_metadata[i], NULL);
        FREE(wim->image_metadata);
    }
    FREE(wim);
}
Exemple #2
0
int
open_wim_as_WIMStruct(const void *wim_filename_or_fd, int open_flags,
                      WIMStruct **wim_ret,
                      wimlib_progress_func_t progfunc, void *progctx)
{
    WIMStruct *wim;
    int ret;

    ret = wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
    if (ret)
        return ret;

    wim = new_wim_struct();
    if (!wim)
        return WIMLIB_ERR_NOMEM;

    wim->progfunc = progfunc;
    wim->progctx = progctx;

    ret = begin_read(wim, wim_filename_or_fd, open_flags);
    if (ret) {
        wimlib_free(wim);
        return ret;
    }

    *wim_ret = wim;
    return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{
	int ret;
	WIMStruct *wim = NULL;
	const char *srcdir;
	const char *wimpath;

	/* Check for the correct number of arguments.  */
	if (argc != 3) {
		fprintf(stderr, "Usage: capturewim DIR WIM\n");
		return 2;
	}

	srcdir = argv[1];
	wimpath = argv[2];

	/* Create a WIMStruct for a WIM.  */
	ret = wimlib_create_new_wim(WIMLIB_COMPRESSION_TYPE_LZX, &wim);
	if (ret != 0)  /* Always should check the error codes.  */
		goto out;

	/* Register our progress function.  */
	wimlib_register_progress_function(wim, write_progress, NULL);

	/* Add the directory tree to the WIMStruct as an image.  */

	ret = wimlib_add_image(wim,     /* WIMStruct to which to add the image    */
			       srcdir,  /* Directory from which to add the image  */
			       NULL,    /* Name to give the image (NULL means none)  */
			       NULL,    /* Capture configuration structure (NULL means none)  */
			       0);      /* WIMLIB_ADD_FLAG_* flags (0 means all defaults)  */
	if (ret != 0)
		goto out;

	/* Write the WIM file.  */

	ret = wimlib_write(wim,      /* WIMStruct from which to write a WIM  */
			   wimpath,  /* Path to write the WIM to             */
			   WIMLIB_ALL_IMAGES, /*  Image(s) in the WIM to write */
			   0,        /* WIMLIB_WRITE_FLAG_* flags (0 means all defaults)   */
			   0);       /* Number of compressor threads (0 means default)  */

out:
	/* Free the WIMStruct.  Has no effect if the pointer to it is NULL.  */
	wimlib_free(wim);

	/* Check for error status.  */
	if (ret != 0) {
		fprintf(stderr, "wimlib error %d: %s\n",
			ret, wimlib_get_error_string(ret));
	}

	/* Free global memory (optional).  */
	wimlib_global_cleanup();

	return ret;
}
Exemple #4
0
/* API function documented in wimlib.h  */
WIMLIBAPI int
wimlib_create_new_wim(enum wimlib_compression_type ctype, WIMStruct **wim_ret)
{
    int ret;
    WIMStruct *wim;

    ret = wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
    if (ret)
        return ret;

    if (!wim_ret)
        return WIMLIB_ERR_INVALID_PARAM;

    if (!wim_compression_type_valid(ctype))
        return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;

    wim = new_wim_struct();
    if (!wim)
        return WIMLIB_ERR_NOMEM;

    wim->blob_table = new_blob_table(9001);
    if (!wim->blob_table) {
        wimlib_free(wim);
        return WIMLIB_ERR_NOMEM;
    }

    /* Fill in wim->hdr with default values  */
    wim->hdr.magic = WIM_MAGIC;
    wim->hdr.wim_version = WIM_VERSION_DEFAULT;
    wim->hdr.flags = 0;
    wim->hdr.chunk_size = 0;
    generate_guid(wim->hdr.guid);
    wim->hdr.part_number = 1;
    wim->hdr.total_parts = 1;
    wim->hdr.image_count = 0;
    wim->hdr.boot_idx = 0;

    wim->compression_type = WIMLIB_COMPRESSION_TYPE_NONE;
    wim->chunk_size = wim->hdr.chunk_size;

    /* Set the output compression type  */
    wim->out_compression_type = ctype;
    wim->out_chunk_size = wim_default_nonsolid_chunk_size(ctype);

    *wim_ret = wim;
    return 0;
}