[coreboot-gerrit] New patch to review for coreboot: cbfstool: Fix removing and adding file with same name

Paul Menzel (paulepanter@users.sourceforge.net) gerrit at coreboot.org
Fri Sep 11 21:42:47 CET 2015


Paul Menzel (paulepanter at users.sourceforge.net) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11632

-gerrit

commit 5694ec710caf22e43fc8544333542f5954ed4809
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Sat Aug 8 20:25:17 2015 +0200

    cbfstool: Fix removing and adding file with same name
    
    Currently, cbfstool regressed that removing a file from CBFS the space
    is marked as empty but the filename is still shown, preventing adding a
    file with the same name again. [1]
    
    ```
    $ echo a > a
    $ echo b > b
    $ ./util/cbfstool/cbfstool  test.rom create -m x86 -s 1024
    Created CBFS (capacity = 920 bytes)
    $ ./util/cbfstool/cbfstool test.rom add -f a -n a -t raw
    $ ./util/cbfstool/cbfstool test.rom add -f b -n b -t raw
    $ cp test.rom test.rom.original
    $ ./util/cbfstool/cbfstool test.rom remove  -n
    $ diff -up <(hexdump -C test.rom.original) <(hexdump -C test.rom)
    --- /dev/fd/63  2015-08-07 08:43:42.118430961 -0500
    +++ /dev/fd/62  2015-08-07 08:43:42.114430961 -0500
    @@ -1,4 +1,4 @@
    -00000000  4c 41 52 43 48 49 56 45  00 00 00 02 00 00 00 50  |LARCHIVE.......P|
    +00000000  4c 41 52 43 48 49 56 45  00 00 00 02 ff ff ff ff  |LARCHIVE........|
     00000010  00 00 00 00 00 00 00 28  61 00 00 00 00 00 00 00  |.......(a.......|
     00000020  00 00 00 00 00 00 00 00  61 0a ff ff ff ff ff ff  |........a.......|
     00000030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
    $ ./util/cbfstool/cbfstool test.rom add -f c -n c -t raw
    
    $ ./util/cbfstool/cbfstool test.rom print
    test.rom: 1 kB, bootblocksize 0, romsize 1024, offset 0x0
    alignment: 64 bytes, architecture: x86
    
    Name                           Offset     Type         Size
    c                              0x0        raw          2
    b                              0x40       raw          2
    (empty)                        0x80       null         792
    ```
    
    So it is “deteled” as the type changed. But the name was not changed to
    match the *(empty)* heuristic.
    
    So also adapt the name when removing a file by writing a null byte to
    the beginning of the name, so that the heuristic works. (Though remove
    doesn't really clear contents.)
    
    ```
    $ ./util/cbfstool/cbfstool test.rom remove  -n c
    $ ./util/cbfstool/cbfstool test.rom print
    test.rom: 1 kB, bootblocksize 0, romsize 1024, offset 0x0
    alignment: 64 bytes, architecture: x86
    
    Name                           Offset     Type         Size
    (empty)                        0x0        null         2
    b                              0x40       raw          2
    (empty)                        0x80       null         792
    ```
    
    [1] http://www.coreboot.org/pipermail/coreboot/2015-August/080201.html
    
    Change-Id: I033456ab10e3e1b402ac2374f3a887cefd3e5abf
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
    Signed-off-by: Paul Menzel <paulepanter at users.sourceforge.net>
---
 util/cbfstool/cbfs_image.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 50b97ef..c47069c 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -884,6 +884,7 @@ int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
 			   unused void *arg)
 {
 	struct cbfs_file *next;
+	uint8_t *name;
 	uint32_t type, addr, last_addr;
 
 	type = ntohl(entry->type);
@@ -891,6 +892,9 @@ int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
 		// Ready to be recycled.
 		type = CBFS_COMPONENT_NULL;
 		entry->type = htonl(type);
+		// Place NUL byte as first byte of name to be viewed as "empty".
+		*name = (void *)&entry[1];
+		*name = '\0';
 	}
 	if (type != CBFS_COMPONENT_NULL)
 		return 0;



More information about the coreboot-gerrit mailing list