UPSTREAM: cbfstool: correct size left calculation for "empty" entries
After removing a file sandwiched between two other files, that file could no longer be re-added at the same location. cbfstool tried to add the file, and a new "empty" entry, which, together, would no longer fit, so it continued checking for the next available space. Change the behavior to add the file if there is enough space for the file alone, then only add the "empty" entry if there is enough space for it. Change-Id: I885bb574bb230905bd42ca0fb6d4a6ef9b0cae03 Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/186983
This commit is contained in:
parent
8d1ab5de1d
commit
5300f53755
1 changed files with 14 additions and 0 deletions
|
|
@ -377,6 +377,10 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
|
|||
|
||||
DEBUG("cbfs_add_entry: space at 0x%x+0x%x(%d) bytes\n",
|
||||
addr, addr_next - addr, addr_next - addr);
|
||||
|
||||
/* Will the file fit? Don't yet worry if we have space for a new
|
||||
* "empty" entry. We take care of that later.
|
||||
*/
|
||||
if (addr + need_size > addr_next)
|
||||
continue;
|
||||
|
||||
|
|
@ -396,6 +400,16 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
|
|||
entry = cbfs_find_next_entry(image, entry);
|
||||
new_size = (cbfs_get_entry_addr(image, next) -
|
||||
cbfs_get_entry_addr(image, entry));
|
||||
|
||||
/* Entry was added and no space for new "empty" entry */
|
||||
if (new_size < cbfs_calculate_file_header_size("")) {
|
||||
DEBUG("No need for new \"empty\" entry\n");
|
||||
/* No need to increase the size of the just
|
||||
* stored file to extend to next file. Alignment
|
||||
* of next file takes care of this.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
new_size -= cbfs_calculate_file_header_size("");
|
||||
DEBUG("new size: %d\n", new_size);
|
||||
cbfs_create_empty_entry(image, entry, new_size, "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue