[ipxe-devel] [PATCH] [hci] Add setdirname command

Nils Carlson nils.carlson at ericsson.com
Fri Jan 21 15:10:56 UTC 2011


Add a setdirname command allowing us to retrieve the directory
from a filename. Simplifies the replacement of pxelinux with
ipxe.

Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
 src/hci/commands/nvo_cmd.c |   52 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/hci/commands/nvo_cmd.c b/src/hci/commands/nvo_cmd.c
index 3513c8d..784c14c 100644
--- a/src/hci/commands/nvo_cmd.c
+++ b/src/hci/commands/nvo_cmd.c
@@ -16,6 +16,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <libgen.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -178,6 +179,53 @@ static int clear_exec ( int argc, char **argv ) {
 	return 0;
 }
 
+/** "setdirname" options */
+struct setdirname_options {};
+
+/** "setdirname" option list */
+static struct option_descriptor setdirname_opts[] = {};
+
+/** "clear" command descriptor */
+static struct command_descriptor setdirname_cmd =
+	COMMAND_DESC ( struct setdirname_options, setdirname_opts, 2, 2,
+		       "<setting> <path>", "" );
+
+/**
+ * "setdirname" command
+ *
+ * @v argc		Argument count
+ * @v argv		Argument list
+ * @ret rc		Return status code
+ */
+static int setdirname_exec ( int argc, char **argv ) {
+	struct setdirname_options opts;
+	int rc;
+	char buf[256];
+	unsigned int len;
+
+	/* Parse options */
+	if ( ( rc = parse_options ( argc, argv, &setdirname_cmd, &opts ) ) != 0 )
+		return rc;
+
+	len = strlen(argv[optind + 1]);
+	if ( len > (sizeof(buf) - 1) ) {
+		printf( "Path %s too long to save dirname\n", argv[optind + 1] );
+		return 1;
+	}
+
+	strncpy( buf, argv[optind + 1], sizeof(buf) - 1 );
+
+	if ( ( rc = storef_named_setting ( argv[optind], dirname(buf) ) ) != 0 ) {
+		printf ( "Could not set \"%s\" to dirname of \"%s\": %s\n",
+			 argv[optind], argv[optind + 1], strerror ( rc ) );
+		return 1;
+	}
+
+	return 0;
+}
+
+
+
 /** Non-volatile option commands */
 struct command nvo_commands[] __command = {
 	{
@@ -192,4 +240,8 @@ struct command nvo_commands[] __command = {
 		.name = "clear",
 		.exec = clear_exec,
 	},
+	{
+		.name = "setdirname",
+		.exec = setdirname_exec,
+	},
 };
-- 
1.6.0.2




More information about the ipxe-devel mailing list