[cpio] Allow for the construction of pure directories

Allow for the possibility of creating empty directories (without
having to include a dummy file inside the directory) using a
zero-length image and a CPIO filename with a trailing slash, such as:

  initrd emptyfile /usr/share/oem/

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-03-12 14:25:05 +00:00
parent d6ee9a9242
commit da3024d257
2 changed files with 21 additions and 6 deletions
+5 -6
View File
@@ -179,17 +179,16 @@ size_t cpio_header ( struct image *image, unsigned int index,
/* Get filename length */
name_len = cpio_name_len ( image, depth );
/* Calculate mode and length */
if ( depth < max ) {
/* Directory */
/* Set directory mode or file mode as appropriate */
if ( name[name_len] == '/' ) {
mode = ( CPIO_MODE_DIR | CPIO_DEFAULT_DIR_MODE );
len = 0;
} else {
/* File */
mode |= CPIO_MODE_FILE;
len = image->len;
}
/* Set length on final header */
len = ( ( depth < max ) ? 0 : image->len );
/* Construct CPIO header */
memset ( cpio, '0', sizeof ( *cpio ) );
memcpy ( cpio->c_magic, CPIO_MAGIC, sizeof ( cpio->c_magic ) );