- DEBUG("Reading root dentry");
-
- /* Allocate memory for the root dentry and read it into memory */
- root = MALLOC(sizeof(struct wim_dentry));
- if (!root) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_security_data;
- }
-
- /* The root directory entry starts after security data, aligned on an
- * 8-byte boundary within the metadata resource. Since
- * security_data->total_length was already rounded up to an 8-byte
- * boundary, its value can be used as the offset of the root directory
- * entry. */
- ret = read_dentry(buf, metadata_len,
- security_data->total_length, root);
-
- if (ret == 0 && root->length == 0) {
- WARNING("Metadata resource begins with end-of-directory entry "
- "(treating as empty image)");
- FREE(root);
- root = NULL;
- goto out_success;
- }
-
- if (ret) {
- FREE(root);
- goto out_free_security_data;
- }
-
- if (dentry_has_long_name(root) || dentry_has_short_name(root)) {
- WARNING("The root directory has a nonempty name (removing it)");
- FREE(root->file_name);
- FREE(root->short_name);
- root->file_name = NULL;
- root->short_name = NULL;
- root->file_name_nbytes = 0;
- root->short_name_nbytes = 0;
- }
-
- if (!dentry_is_directory(root)) {
- ERROR("Root of the WIM image must be a directory!");
- FREE(root);
- ret = WIMLIB_ERR_INVALID_METADATA_RESOURCE;