summaryrefslogtreecommitdiffstats
path: root/net/nfs.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-01-04 10:08:52 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2010-02-01 17:25:31 +0100
commit88351d2e4bcf25fef3818c951e89180c764389ed (patch)
tree0fc66d4735edbea3030d266b7ec11b9c56045621 /net/nfs.c
parent085e30b4b03235ea421eb62f29cc0fc759764990 (diff)
downloadbarebox-88351d2e4bcf25fef3818c951e89180c764389ed.tar.gz
barebox-88351d2e4bcf25fef3818c951e89180c764389ed.tar.xz
Move tftp/nfs specific code to net/*
This adds a few bytes of binary space but is done to put the code where it belongs to. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net/nfs.c')
-rw-r--r--net/nfs.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/net/nfs.c b/net/nfs.c
index fe0bc70cbe..f68741a57d 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -29,6 +29,9 @@
#include <malloc.h>
#include <libgen.h>
#include <fs.h>
+#include <libgen.h>
+#include <fcntl.h>
+#include <errno.h>
#include "nfs.h"
/*#define NFS_DEBUG*/
@@ -63,7 +66,7 @@ static char *nfs_filename;
static char *nfs_path;
static char nfs_path_buff[2048];
-extern int net_store_fd;
+static int net_store_fd;
static __inline__ int
store_block (uchar * src, unsigned offset, unsigned len)
@@ -703,3 +706,54 @@ NfsStart (char *p)
NfsSend ();
}
+static int do_nfs (cmd_tbl_t *cmdtp, int argc, char *argv[])
+{
+ int rcode = 0;
+ char *localfile;
+ char *remotefile;
+
+ if (argc < 2)
+ return COMMAND_ERROR_USAGE;
+
+ remotefile = argv[1];
+
+ if (argc == 2)
+ localfile = basename(remotefile);
+ else
+ localfile = argv[2];
+
+ net_store_fd = open(localfile, O_WRONLY | O_CREAT);
+ if (net_store_fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ if (NetLoopInit(NFS) < 0)
+ goto out;
+
+ NfsStart(remotefile);
+
+ rcode = NetLoop();
+ if (rcode < 0) {
+ rcode = 1;
+ goto out;
+ }
+
+ /* NetLoop ok, update environment */
+ netboot_update_env();
+
+out:
+ close(net_store_fd);
+ return rcode;
+}
+
+static const __maybe_unused char cmd_nfs_help[] =
+"Usage: nfs <file> [localfile]\n"
+"Load a file via network using nfs protocol.\n";
+
+BAREBOX_CMD_START(nfs)
+ .cmd = do_nfs,
+ .usage = "boot image via network using nfs protocol",
+ BAREBOX_CMD_HELP(cmd_nfs_help)
+BAREBOX_CMD_END
+