[ipxe-devel] [PATCH] wimboot syslinux kludge 2/4: provide common read_mem_file cpio handler

Friedemann Gerold f.gerold at b-c-s.de
Fri Nov 2 14:25:01 UTC 2018


For the next patch that will add cpio support for efi,
we want to use a common read_mem_file() as cpio handler.
This patch moves the private read_file() from main.c to
vdisk.c as read_mem_file() so it can shared.

Signed-off-by: Friedemann Gerold <f.gerold at b-c-s.de>
---
--- wimbootorig/src/vdisk.h	2018-11-02 12:29:14.343297008 +0100
+++ wimboot/src/vdisk.h	2018-11-02 12:28:48.071166732 +0100
@@ -610,11 +610,15 @@

  extern struct vdisk_file vdisk_files[VDISK_MAX_FILES];

+
  extern void vdisk_read ( uint64_t lba, unsigned int count, void *data );
  extern struct vdisk_file *
  vdisk_add_file ( const char *name, void *opaque, size_t len,
  		 void ( * read ) ( struct vdisk_file *file, void *data,
  				   size_t offset, size_t len ) );
+
+extern void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len );
+
  extern void
  vdisk_patch_file ( struct vdisk_file *file,
  		   void ( * patch ) ( struct vdisk_file *file, void *data,
--- wimbootorig/src/vdisk.c	2018-11-02 12:29:14.343297008 +0100
+++ wimboot/src/vdisk.c	2018-11-02 12:28:48.071166732 +0100
@@ -614,6 +614,19 @@
  }

  /**
+ * Read from file
+ *
+ * @v file              Virtual file
+ * @v data              Data buffer
+ * @v offset            Offset
+ * @v len               Length
+ */
+void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len ) {
+        memcpy ( data, ( file->opaque + offset ), len );
+}
+
+
+/**
   * Add file to virtual disk
   *
   * @v name		Name
--- wimbootorig/src/main.c	2018-11-02 12:29:14.343297008 +0100
+++ wimboot/src/main.c	2018-11-02 12:28:48.071166732 +0100
@@ -197,20 +197,6 @@
  }

  /**
- * Read from file
- *
- * @v file		Virtual file
- * @v data		Data buffer
- * @v offset		Offset
- * @v len		Length
- */
-static void read_file ( struct vdisk_file *file, void *data, size_t offset,
-			size_t len ) {
-
-	memcpy ( data, ( file->opaque + offset ), len );
-}
-
-/**
   * Add embedded bootmgr.exe extracted from bootmgr
   *
   * @v data		File data
@@ -305,8 +291,7 @@
  		decompress ( compressed, compressed_len, initrd );

  		/* Add decompressed image */
-		return vdisk_add_file ( "bootmgr.exe", initrd,
-					decompressed_len, read_file );
+		return vdisk_add_file ( "bootmgr.exe", initrd, decompressed_len, read_mem_file );
  	}

  	DBG ( "...no embedded bootmgr.exe found\n" );
@@ -325,7 +310,7 @@
  	struct vdisk_file *file;

  	/* Store file */
-	file = vdisk_add_file ( name, data, len, read_file );
+	file = vdisk_add_file ( name, data, len, read_mem_file );

  	/* Check for special-case files */
  	if ( strcasecmp ( name, "bootmgr.exe" ) == 0 ) {
@@ -378,7 +363,7 @@
  	/* Read bootmgr.exe into memory */
  	if ( ! bootmgr )
  		die ( "FATAL: no bootmgr.exe\n" );
-	if ( bootmgr->read == read_file ) {
+	if ( bootmgr->read == read_mem_file ) {
  		raw_pe = bootmgr->opaque;
  	} else {
  		padded_len = ( ( bootmgr->len + PAGE_SIZE - 1 ) &
cinap_lenrek at bonaparte ~/wimboot/src $ cat readmemfile.patch
--- wimbootorig/src/vdisk.h	2018-11-02 12:29:14.343297008 +0100
+++ wimboot/src/vdisk.h	2018-11-02 12:28:48.071166732 +0100
@@ -610,11 +610,15 @@

  extern struct vdisk_file vdisk_files[VDISK_MAX_FILES];

+
  extern void vdisk_read ( uint64_t lba, unsigned int count, void *data );
  extern struct vdisk_file *
  vdisk_add_file ( const char *name, void *opaque, size_t len,
  		 void ( * read ) ( struct vdisk_file *file, void *data,
  				   size_t offset, size_t len ) );
+
+extern void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len );
+
  extern void
  vdisk_patch_file ( struct vdisk_file *file,
  		   void ( * patch ) ( struct vdisk_file *file, void *data,
--- wimbootorig/src/vdisk.c	2018-11-02 12:29:14.343297008 +0100
+++ wimboot/src/vdisk.c	2018-11-02 12:28:48.071166732 +0100
@@ -614,6 +614,19 @@
  }

  /**
+ * Read from file
+ *
+ * @v file              Virtual file
+ * @v data              Data buffer
+ * @v offset            Offset
+ * @v len               Length
+ */
+void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len ) {
+        memcpy ( data, ( file->opaque + offset ), len );
+}
+
+
+/**
   * Add file to virtual disk
   *
   * @v name		Name
--- wimbootorig/src/main.c	2018-11-02 12:29:14.343297008 +0100
+++ wimboot/src/main.c	2018-11-02 12:28:48.071166732 +0100
@@ -197,20 +197,6 @@
  }

  /**
- * Read from file
- *
- * @v file		Virtual file
- * @v data		Data buffer
- * @v offset		Offset
- * @v len		Length
- */
-static void read_file ( struct vdisk_file *file, void *data, size_t offset,
-			size_t len ) {
-
-	memcpy ( data, ( file->opaque + offset ), len );
-}
-
-/**
   * Add embedded bootmgr.exe extracted from bootmgr
   *
   * @v data		File data
@@ -305,8 +291,7 @@
  		decompress ( compressed, compressed_len, initrd );

  		/* Add decompressed image */
-		return vdisk_add_file ( "bootmgr.exe", initrd,
-					decompressed_len, read_file );
+		return vdisk_add_file ( "bootmgr.exe", initrd, decompressed_len, read_mem_file );
  	}

  	DBG ( "...no embedded bootmgr.exe found\n" );
@@ -325,7 +310,7 @@
  	struct vdisk_file *file;

  	/* Store file */
-	file = vdisk_add_file ( name, data, len, read_file );
+	file = vdisk_add_file ( name, data, len, read_mem_file );

  	/* Check for special-case files */
  	if ( strcasecmp ( name, "bootmgr.exe" ) == 0 ) {
@@ -378,7 +363,7 @@
  	/* Read bootmgr.exe into memory */
  	if ( ! bootmgr )
  		die ( "FATAL: no bootmgr.exe\n" );
-	if ( bootmgr->read == read_file ) {
+	if ( bootmgr->read == read_mem_file ) {
  		raw_pe = bootmgr->opaque;
  	} else {
  		padded_len = ( ( bootmgr->len + PAGE_SIZE - 1 ) &



More information about the ipxe-devel mailing list