Browse Source

[bzimage] Allow file mode to be specified for standalone initrd files

Allow the file mode to be specified using a "mode=" command line
parameter.  For example:

  initrd http://web/boot/bootlocal.sh /opt/bootlocal.sh mode=755

Requested-by: Bryce Zimmerman <bryce.zimmerman@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
d97c6a321e
1 changed files with 37 additions and 3 deletions
  1. 37
    3
      src/arch/i386/image/bzimage.c

+ 37
- 3
src/arch/i386/image/bzimage.c View File

@@ -322,6 +322,32 @@ static int bzimage_set_cmdline ( struct image *image,
322 322
 	return 0;
323 323
 }
324 324
 
325
+/**
326
+ * Parse standalone image command line for cpio parameters
327
+ *
328
+ * @v image		bzImage file
329
+ * @v cpio		CPIO header
330
+ * @v cmdline		Command line
331
+ */
332
+static void bzimage_parse_cpio_cmdline ( struct image *image,
333
+					 struct cpio_header *cpio,
334
+					 const char *cmdline ) {
335
+	char *arg;
336
+	char *end;
337
+	unsigned int mode;
338
+
339
+	/* Look for "mode=" */
340
+	if ( ( arg = strstr ( cmdline, "mode=" ) ) ) {
341
+		arg += 5;
342
+		mode = strtoul ( arg, &end, 8 /* Octal for file mode */ );
343
+		if ( *end && ( *end != ' ' ) ) {
344
+			DBGC ( image, "bzImage %p strange \"mode=\""
345
+			       "terminator '%c'\n", image, *end );
346
+		}
347
+		cpio_set_field ( cpio->c_mode, ( 0100000 | mode ) );
348
+	}
349
+}
350
+
325 351
 /**
326 352
  * Load initrd
327 353
  *
@@ -334,8 +360,10 @@ static size_t bzimage_load_initrd ( struct image *image,
334 360
 				    struct image *initrd,
335 361
 				    userptr_t address ) {
336 362
 	char *filename = initrd->cmdline;
363
+	char *cmdline;
337 364
 	struct cpio_header cpio;
338 365
         size_t offset = 0;
366
+	size_t name_len;
339 367
 
340 368
 	/* Do not include kernel image itself as an initrd */
341 369
 	if ( initrd == image )
@@ -343,24 +371,30 @@ static size_t bzimage_load_initrd ( struct image *image,
343 371
 
344 372
 	/* Create cpio header before non-prebuilt images */
345 373
 	if ( filename && filename[0] ) {
346
-		size_t name_len = ( strlen ( filename ) + 1 );
347
-
348 374
 		DBGC ( image, "bzImage %p inserting initrd %p as %s\n",
349 375
 		       image, initrd, filename );
376
+		cmdline = strchr ( filename, ' ' );
377
+		name_len = ( ( cmdline ? ( ( size_t ) ( cmdline - filename ) )
378
+			       : strlen ( filename ) ) + 1 /* NUL */ );
350 379
 		memset ( &cpio, '0', sizeof ( cpio ) );
351 380
 		memcpy ( cpio.c_magic, CPIO_MAGIC, sizeof ( cpio.c_magic ) );
352 381
 		cpio_set_field ( cpio.c_mode, 0100644 );
353 382
 		cpio_set_field ( cpio.c_nlink, 1 );
354 383
 		cpio_set_field ( cpio.c_filesize, initrd->len );
355 384
 		cpio_set_field ( cpio.c_namesize, name_len );
385
+		if ( cmdline ) {
386
+			bzimage_parse_cpio_cmdline ( image, &cpio,
387
+						     ( cmdline + 1 /* ' ' */ ));
388
+		}
356 389
 		if ( address ) {
357 390
 			copy_to_user ( address, offset, &cpio,
358 391
 				       sizeof ( cpio ) );
359 392
 		}
360 393
 		offset += sizeof ( cpio );
361 394
 		if ( address ) {
395
+			memset_user ( address, offset, 0, name_len );
362 396
 			copy_to_user ( address, offset, filename,
363
-				       name_len );
397
+				       ( name_len - 1 /* NUL (or space) */ ) );
364 398
 		}
365 399
 		offset += name_len;
366 400
 		offset = ( ( offset + 0x03 ) & ~0x03 );

Loading…
Cancel
Save