Index: uspace/app/bdsh/cmds/modules/mkfile/entry.h
===================================================================
--- uspace/app/bdsh/cmds/modules/mkfile/entry.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
+++ uspace/app/bdsh/cmds/modules/mkfile/entry.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
@@ -0,0 +1,9 @@
+#ifndef MKFILE_ENTRY_H
+#define MKFILE_ENTRY_H
+
+/* Entry points for the mkfile command */
+extern int cmd_mkfile(char **);
+extern void help_cmd_mkfile(unsigned int);
+
+#endif /* MKFILE_ENTRY_H */
+
Index: uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mkfile/mkfile.c	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
+++ uspace/app/bdsh/cmds/modules/mkfile/mkfile.c	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <macros.h>
+#include <getopt.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "errors.h"
+#include "util.h"
+#include "entry.h"
+#include "mkfile.h"
+#include "cmds.h"
+
+/** Number of bytes to write at a time */
+#define BUFFER_SIZE 16384
+
+static char *cmdname = "mkfile";
+
+static struct option const long_options[] = {
+	{"size", required_argument, 0, 's'},
+	{"help", no_argument, 0, 'h'},
+	{0, 0, 0, 0}
+};
+
+void help_cmd_mkfile(unsigned int level)
+{
+	if (level == HELP_SHORT) {
+		printf("`%s' creates a new zero-filled file\n", cmdname);
+	} else {
+		help_cmd_mkfile(HELP_SHORT);
+		printf(
+		"Usage:  %s [options] <path>\n"
+		"Options:\n"
+		"  -h, --help       A short option summary\n"
+		"  -s, --size sz    Size of the file\n"
+		"\n"
+		"Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n"
+		"E.g. 100k, 2m, 1g.\n",
+		cmdname);
+	}
+
+	return;
+}
+
+/** Parse size specification.
+ *
+ * Size specification is in the form <decimal_number><unit> where
+ * <unit> is 'k', 'm' or 'g' for kB, MB, GB.
+ *
+ * @param str	String containing the size specification.
+ * @return	Non-negative size in bytes on success, -1 on failure.
+ */
+static ssize_t read_size(const char *str)
+{
+	ssize_t number, unit;
+	char *ep;
+
+	number = strtol(str, &ep, 10);
+	if (ep[0] == '\0')
+		return number;
+
+	if (ep[1] != '\0')
+		    return -1;
+
+	switch (tolower(ep[0])) {
+	case 'k': unit = 1024; break;
+	case 'm': unit = 1024*1024; break;
+	case 'g': unit = 1024*1024*1024; break;
+	default: return -1;
+	}
+
+	return number * unit;
+}
+
+int cmd_mkfile(char **argv)
+{
+	unsigned int argc;
+	int c, opt_ind;
+	int fd;
+	ssize_t file_size;
+	ssize_t total_written;
+	ssize_t to_write, rc;
+	char *file_name;
+	void *buffer;
+
+	file_size = 0;
+
+	argc = cli_count_args(argv);
+
+	for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
+		c = getopt_long(argc, argv, "pvhVfm:", long_options, &opt_ind);
+		switch (c) {
+		case 'h':
+			help_cmd_mkfile(HELP_LONG);
+			return CMD_SUCCESS;
+		case 's':
+			file_size = read_size(optarg);
+			if (file_size < 0) {
+				printf("%s: Invalid file size specification.\n",
+				    cmdname);
+				return CMD_FAILURE;
+			}
+			break;
+		}
+	}
+
+	argc -= optind;
+
+	if (argc != 1) {
+		printf("%s: incorrect number of arguments. Try `%s --help'\n",
+			cmdname, cmdname);
+		return CMD_FAILURE;
+	}
+
+	file_name = argv[optind];
+
+	fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, 0666);
+	if (fd < 0) {
+		printf("%s: failed to create file %s.\n", cmdname, file_name);
+		return CMD_FAILURE;
+	}
+
+	buffer = calloc(BUFFER_SIZE, 1);
+	if (buffer == NULL) {
+		printf("%s: Error, out of memory.\n", cmdname);
+		return CMD_FAILURE;
+	}
+
+	total_written = 0;
+	while (total_written < file_size) {
+		to_write = min(file_size - total_written, BUFFER_SIZE);
+		rc = write(fd, buffer, to_write);
+		if (rc <= 0) {
+			printf("%s: Error writing file (%d).\n", cmdname, rc);
+			close(fd);
+			return CMD_FAILURE;
+		}
+		total_written += rc;
+	}
+
+	rc = close(fd);
+	if (rc != 0) {
+		printf("%s: Error writing file (%d).\n", cmdname, rc);
+		return CMD_FAILURE;
+	}
+
+	free(buffer);
+
+	return CMD_SUCCESS;
+}
Index: uspace/app/bdsh/cmds/modules/mkfile/mkfile.h
===================================================================
--- uspace/app/bdsh/cmds/modules/mkfile/mkfile.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
+++ uspace/app/bdsh/cmds/modules/mkfile/mkfile.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
@@ -0,0 +1,8 @@
+#ifndef MKFILE_H
+#define MKFILE_H
+
+/* Prototypes for the mkfile command, excluding entry points */
+
+
+#endif /* MKFILE_H */
+
Index: uspace/app/bdsh/cmds/modules/mkfile/mkfile_def.h
===================================================================
--- uspace/app/bdsh/cmds/modules/mkfile/mkfile_def.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
+++ uspace/app/bdsh/cmds/modules/mkfile/mkfile_def.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
@@ -0,0 +1,8 @@
+{
+	"mkfile",
+	"Create new file",
+	&cmd_mkfile,
+	&help_cmd_mkfile,
+},
+
+
Index: uspace/app/bdsh/cmds/modules/modules.h
===================================================================
--- uspace/app/bdsh/cmds/modules/modules.h	(revision 1313ee92979dd133fd0dd0717213410aada3df10)
+++ uspace/app/bdsh/cmds/modules/modules.h	(revision c77a64ff173c6b97e1f85ac22e9fe1760cb720cc)
@@ -20,4 +20,5 @@
 #include "help/entry.h"
 #include "mkdir/entry.h"
+#include "mkfile/entry.h"
 #include "rm/entry.h"
 #include "bdd/entry.h"
@@ -39,4 +40,5 @@
 #include "help/help_def.h"
 #include "mkdir/mkdir_def.h"
+#include "mkfile/mkfile_def.h"
 #include "rm/rm_def.h"
 #include "bdd/bdd_def.h"
