| 1695 | } |
| 1696 | |
| 1697 | static enum ifwi_ret ifwi_dir_replace(int type) |
| 1698 | { |
| 1699 | if (!(subparts[type].attr & CONTAINS_DIR)) { |
| 1700 | ERROR("Sub-Partition %s(%d) does not support dir ops.\n", |
| 1701 | subparts[type].name, type); |
| 1702 | return COMMAND_ERR; |
| 1703 | } |
| 1704 | |
| 1705 | if (!param.dentry_name) { |
| 1706 | ERROR("%s: -e option required.\n", __func__); |
| 1707 | return COMMAND_ERR; |
| 1708 | } |
| 1709 | |
| 1710 | struct buffer subpart_dir_buf; |
| 1711 | parse_subpart_dir(&subpart_dir_buf, &ifwi_image.subpart_buf[type], |
| 1712 | subparts[type].name); |
| 1713 | |
| 1714 | uint32_t i; |
| 1715 | struct subpart_dir *s = buffer_get(&subpart_dir_buf); |
| 1716 | |
| 1717 | for (i = 0; i < s->h.num_entries; i++) { |
| 1718 | if (!strcmp((char *)s->e[i].name, param.dentry_name)) |
| 1719 | break; |
| 1720 | } |
| 1721 | |
| 1722 | if (i == s->h.num_entries) { |
| 1723 | ERROR("Entry %s not found in subpartition for %s.\n", |
| 1724 | param.dentry_name, param.subpart_name); |
| 1725 | exit(-1); |
| 1726 | } |
| 1727 | |
| 1728 | struct buffer b; |
| 1729 | if (buffer_from_file(&b, param.file_name)) { |
| 1730 | ERROR("Failed to read %s\n", param.file_name); |
| 1731 | exit(-1); |
| 1732 | } |
| 1733 | |
| 1734 | struct buffer dst; |
| 1735 | size_t dst_size = buffer_size(&ifwi_image.subpart_buf[type]) + |
| 1736 | buffer_size(&b) - s->e[i].length; |
| 1737 | size_t subpart_start = s->e[i].offset; |
| 1738 | size_t subpart_end = s->e[i].offset + s->e[i].length; |
| 1739 | |
| 1740 | alloc_buffer(&dst, dst_size, ifwi_image.subpart_buf[type].name); |
| 1741 | |
| 1742 | uint8_t *src_data = buffer_get(&ifwi_image.subpart_buf[type]); |
| 1743 | uint8_t *dst_data = buffer_get(&dst); |
| 1744 | size_t curr_offset = 0; |
| 1745 | |
| 1746 | /* Copy data before the sub-partition entry. */ |
| 1747 | memcpy(dst_data + curr_offset, src_data, subpart_start); |
| 1748 | curr_offset += subpart_start; |
| 1749 | |
| 1750 | /* Copy sub-partition entry. */ |
| 1751 | memcpy(dst_data + curr_offset, buffer_get(&b), buffer_size(&b)); |
| 1752 | curr_offset += buffer_size(&b); |
| 1753 | |
| 1754 | /* Copy remaining data. */ |
no test coverage detected