mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* assorted patches
@ 2011-04-11 14:18 Sascha Hauer
  2011-04-11 14:18 ` [PATCH 1/7] eth: check the result of edev->get_ethaddr Sascha Hauer
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox


Sascha Hauer (7):
      eth: check the result of edev->get_ethaddr
      net: add a context to the packet handler
      environment: make default env path configurable
      move simple_itoa to libbb so that others can use it
      kfifo: kfifo_put takes a const buffer
      copy_file: handle write return value correctly
      cp command: handle directories as last argument

 commands/cp.c         |    3 ++-
 commands/loadenv.c    |    2 +-
 commands/saveenv.c    |    2 +-
 common/environment.c  |    2 ++
 common/hush.c         |   15 +--------------
 common/startup.c      |    7 ++++---
 include/environment.h |    3 +++
 include/kfifo.h       |    2 +-
 include/libbb.h       |    2 ++
 include/net.h         |    8 +++++---
 lib/copy_file.c       |   15 +++++++++++----
 lib/kfifo.c           |    2 +-
 lib/libbb.c           |   13 +++++++++++++
 net/dhcp.c            |    4 ++--
 net/dns.c             |    4 ++--
 net/eth.c             |    6 ++++--
 net/net.c             |   17 ++++++++++-------
 net/netconsole.c      |    4 ++--
 net/nfs.c             |    4 ++--
 net/ping.c            |    4 ++--
 net/tftp.c            |    4 ++--
 21 files changed, 73 insertions(+), 50 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/7] eth: check the result of edev->get_ethaddr
  2011-04-11 14:18 assorted patches Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  2011-04-11 14:18 ` [PATCH 2/7] net: add a context to the packet handler Sascha Hauer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/eth.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/eth.c b/net/eth.c
index 0251e59..c5b346c 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -167,8 +167,10 @@ int eth_register(struct eth_device *edev)
 
 	if (edev->get_ethaddr(edev, ethaddr) == 0) {
 		ethaddr_to_string(ethaddr, ethaddr_str);
-		dev_info(dev, "got MAC address from EEPROM: %s\n", ethaddr_str);
-		dev_set_param(dev, "ethaddr", ethaddr_str);
+		if (is_valid_ether_addr(ethaddr)) {
+			dev_info(dev, "got MAC address from EEPROM: %s\n", ethaddr_str);
+			dev_set_param(dev, "ethaddr", ethaddr_str);
+		}
 	}
 
 	if (!eth_current) {
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/7] net: add a context to the packet handler
  2011-04-11 14:18 assorted patches Sascha Hauer
  2011-04-11 14:18 ` [PATCH 1/7] eth: check the result of edev->get_ethaddr Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  2011-04-11 14:18 ` [PATCH 3/7] environment: make default env path configurable Sascha Hauer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

This is not yet used, but with this the different network
commands can get rid of their global data.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/net.h    |    8 +++++---
 net/dhcp.c       |    4 ++--
 net/dns.c        |    4 ++--
 net/net.c        |   17 ++++++++++-------
 net/netconsole.c |    4 ++--
 net/nfs.c        |    4 ++--
 net/ping.c       |    4 ++--
 net/tftp.c       |    4 ++--
 8 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/include/net.h b/include/net.h
index 33d8a32..31bf6a2 100644
--- a/include/net.h
+++ b/include/net.h
@@ -363,7 +363,7 @@ static inline int is_valid_ether_addr(const u8 *addr)
 	return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
 }
 
-typedef void rx_handler_f(char *packet, unsigned int len);
+typedef void rx_handler_f(void *ctx, char *packet, unsigned int len);
 
 void eth_set_current(struct eth_device *eth);
 struct eth_device *eth_get_current(void);
@@ -388,6 +388,7 @@ struct net_connection {
 	struct list_head list;
 	rx_handler_f *handler;
 	int proto;
+	void *priv;
 };
 
 static inline char *net_alloc_packet(void)
@@ -396,9 +397,10 @@ static inline char *net_alloc_packet(void)
 }
 
 struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
-		rx_handler_f *handler);
+		rx_handler_f *handler, void *ctx);
 
-struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler);
+struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler,
+		void *ctx);
 
 void net_unregister(struct net_connection *con);
 
diff --git a/net/dhcp.c b/net/dhcp.c
index 0771964..d1781bc 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -381,7 +381,7 @@ static void dhcp_send_request_packet(struct bootp *bp_offer)
 /*
  *	Handle DHCP received packets.
  */
-static void dhcp_handler(char *packet, unsigned int len)
+static void dhcp_handler(void *ctx, char *packet, unsigned int len)
 {
 	char *pkt = net_eth_to_udp_payload(packet);
 	struct udphdr *udp = net_eth_to_udphdr(packet);
@@ -439,7 +439,7 @@ static int do_dhcp(struct command *cmdtp, int argc, char *argv[])
 {
 	int ret;
 
-	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler);
+	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
 	if (IS_ERR(dhcp_con)) {
 		ret = PTR_ERR(dhcp_con);
 		goto out;
diff --git a/net/dns.c b/net/dns.c
index 1ee270b..4db5bbc 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -116,7 +116,7 @@ static int dns_send(char *name)
 	return ret;
 }
 
-static void dns_handler(char *packet, unsigned len)
+static void dns_handler(void *ctx, char *packet, unsigned len)
 {
 	struct header *header;
 	unsigned char *p, *e, *s;
@@ -211,7 +211,7 @@ IPaddr_t resolv(char *host)
 
 	debug("resolving host %s via nameserver %s\n", host, getenv("nameserver"));
 
-	dns_con = net_udp_new(ip, DNS_PORT, dns_handler);
+	dns_con = net_udp_new(ip, DNS_PORT, dns_handler, NULL);
 	if (IS_ERR(dns_con))
 		return PTR_ERR(dns_con);
 	dns_timer_start = get_time_ns();
diff --git a/net/net.c b/net/net.c
index 7495357..f1ab667 100644
--- a/net/net.c
+++ b/net/net.c
@@ -343,7 +343,8 @@ void net_set_gateway(IPaddr_t gw)
 
 static LIST_HEAD(connection_list);
 
-static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
+static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
+		void *ctx)
 {
 	struct eth_device *edev = eth_get_current();
 	struct net_connection *con;
@@ -366,6 +367,7 @@ static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
 
 	con = xzalloc(sizeof(*con));
 	con->packet = xmemalign(32, PKTSIZE);
+	con->priv = ctx;
 	memset(con->packet, 0, PKTSIZE);
 
 	con->et = (struct ethernet *)con->packet;
@@ -402,9 +404,9 @@ out:
 }
 
 struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
-		rx_handler_f *handler)
+		rx_handler_f *handler, void *ctx)
 {
-	struct net_connection *con = net_new(dest, handler);
+	struct net_connection *con = net_new(dest, handler, ctx);
 
 	if (IS_ERR(con))
 		return con;
@@ -417,9 +419,10 @@ struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
 	return con;
 }
 
-struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler)
+struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler,
+		void *ctx)
 {
-	struct net_connection *con = net_new(dest, handler);
+	struct net_connection *con = net_new(dest, handler, ctx);
 
 	if (IS_ERR(con))
 		return con;
@@ -564,7 +567,7 @@ static int net_handle_udp(unsigned char *pkt, int len)
 	port = ntohs(udp->uh_dport);
 	list_for_each_entry(con, &connection_list, list) {
 		if (con->proto == IPPROTO_UDP && port == ntohs(con->udp->uh_sport)) {
-			con->handler(pkt, len);
+			con->handler(con->priv, pkt, len);
 			return 0;
 		}
 	}
@@ -579,7 +582,7 @@ static int net_handle_icmp(unsigned char *pkt, int len)
 
 	list_for_each_entry(con, &connection_list, list) {
 		if (con->proto == IPPROTO_ICMP) {
-			con->handler(pkt, len);
+			con->handler(con->priv, pkt, len);
 			return 0;
 		}
 	}
diff --git a/net/netconsole.c b/net/netconsole.c
index fda524e..2ac3e64 100644
--- a/net/netconsole.c
+++ b/net/netconsole.c
@@ -50,7 +50,7 @@ struct nc_priv {
 
 static struct nc_priv *g_priv;
 
-static void nc_handler(char *pkt, unsigned len)
+static void nc_handler(void *ctx, char *pkt, unsigned len)
 {
 	struct nc_priv *priv = g_priv;
 	unsigned char *packet = net_eth_to_udp_payload(pkt);
@@ -65,7 +65,7 @@ static int nc_init(void)
 	if (priv->con)
 		net_unregister(priv->con);
 
-	priv->con = net_udp_new(priv->ip, priv->port, nc_handler);
+	priv->con = net_udp_new(priv->ip, priv->port, nc_handler, NULL);
 	if (IS_ERR(priv->con)) {
 		int ret = PTR_ERR(priv->con);
 		priv->con = NULL;
diff --git a/net/nfs.c b/net/nfs.c
index 4ca1d6e..0a4b787 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -562,7 +562,7 @@ static int nfs_read_reply(unsigned char *pkt, unsigned len)
 Interfaces of barebox
 **************************************************************************/
 
-static void nfs_handler(char *packet, unsigned len)
+static void nfs_handler(void *ctx, char *packet, unsigned len)
 {
 	char *pkt = net_eth_to_udp_payload(packet);
 	int ret;
@@ -689,7 +689,7 @@ static int do_nfs(struct command *cmdtp, int argc, char *argv[])
 		return 1;
 	}
 
-	nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler);
+	nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler, NULL);
 	if (IS_ERR(nfs_con)) {
 		nfs_err = PTR_ERR(nfs_con);
 		goto err_udp;
diff --git a/net/ping.c b/net/ping.c
index d414784..8aad7af 100644
--- a/net/ping.c
+++ b/net/ping.c
@@ -40,7 +40,7 @@ static int ping_send(void)
 	return net_icmp_send(ping_con, 9);
 }
 
-static void ping_handler(char *pkt, unsigned len)
+static void ping_handler(void *ctx, char *pkt, unsigned len)
 {
 	IPaddr_t tmp;
 	struct iphdr *ip = net_eth_to_iphdr(pkt);
@@ -66,7 +66,7 @@ static int do_ping(struct command *cmdtp, int argc, char *argv[])
 		return 1;
 	}
 
-	ping_con = net_icmp_new(net_ping_ip, ping_handler);
+	ping_con = net_icmp_new(net_ping_ip, ping_handler, NULL);
 	if (IS_ERR(ping_con)) {
 		ret = PTR_ERR(ping_con);
 		goto out;
diff --git a/net/tftp.c b/net/tftp.c
index 0f38b6b..ee11468 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -141,7 +141,7 @@ static int tftp_send(void)
 	return ret;
 }
 
-static void tftp_handler(char *packet, unsigned len)
+static void tftp_handler(void *ctx, char *packet, unsigned len)
 {
 	uint16_t proto;
 	uint16_t *s;
@@ -314,7 +314,7 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 		return 1;
 	}
 
-	tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
+	tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler, NULL);
 	if (IS_ERR(tftp_con)) {
 		tftp_err = PTR_ERR(tftp_con);
 		goto out_close;
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/7] environment: make default env path configurable
  2011-04-11 14:18 assorted patches Sascha Hauer
  2011-04-11 14:18 ` [PATCH 1/7] eth: check the result of edev->get_ethaddr Sascha Hauer
  2011-04-11 14:18 ` [PATCH 2/7] net: add a context to the packet handler Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  2011-04-11 14:18 ` [PATCH 4/7] move simple_itoa to libbb so that others can use it Sascha Hauer
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

Normally the default path to save the environment is /dev/env0. However,
we can't map a file in a fat filesystem to /dev/env0. So if we want to
store the environment in a file in fat we have to make it configurable.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadenv.c    |    2 +-
 commands/saveenv.c    |    2 +-
 common/environment.c  |    2 ++
 common/startup.c      |    7 ++++---
 include/environment.h |    3 +++
 5 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/commands/loadenv.c b/commands/loadenv.c
index c33c34f..5568ace 100644
--- a/commands/loadenv.c
+++ b/commands/loadenv.c
@@ -36,7 +36,7 @@ static int do_loadenv(struct command *cmdtp, int argc, char *argv[])
 	else
 		dirname = argv[2];
 	if (argc < 2)
-		filename = "/dev/env0";
+		filename = default_environment_path;
 	else
 		filename = argv[1];
 	printf("loading environment from %s\n", filename);
diff --git a/commands/saveenv.c b/commands/saveenv.c
index 2f969fe..11a9fee 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -41,7 +41,7 @@ static int do_saveenv(struct command *cmdtp, int argc, char *argv[])
 	else
 		dirname = argv[2];
 	if (argc < 2)
-		filename = "/dev/env0";
+		filename = default_environment_path;
 	else
 		filename = argv[1];
 
diff --git a/common/environment.c b/common/environment.c
index e5f24ec..0fdbd03 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -44,6 +44,8 @@
 #define EXPORT_SYMBOL(x)
 #endif
 
+char *default_environment_path = "/dev/env0";
+
 int file_size_action(const char *filename, struct stat *statbuf,
 			    void *userdata, int depth)
 {
diff --git a/common/startup.c b/common/startup.c
index 3808709..00bc9a0 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -144,10 +144,11 @@ void start_barebox (void)
 	display_meminfo();
 
 #ifdef CONFIG_ENV_HANDLING
-	if (envfs_load("/dev/env0", "/env")) {
+	if (envfs_load(default_environment_path, "/env")) {
 #ifdef CONFIG_DEFAULT_ENVIRONMENT
-		printf("no valid environment found on /dev/env0. "
-			"Using default environment\n");
+		printf("no valid environment found on %s. "
+			"Using default environment\n",
+			default_environment_path);
 		envfs_load("/dev/defaultenv", "/env");
 #endif
 	}
diff --git a/include/environment.h b/include/environment.h
index 1f22fcb..da032e2 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -62,6 +62,9 @@ static inline int setenv(const char *var, const char *val)
 int env_pop_context(void);
 int env_push_context(void);
 
+/* defaults to /dev/env0 */
+extern char *default_environment_path;
+
 int envfs_load(char *filename, char *dirname);
 int envfs_save(char *filename, char *dirname);
 
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/7] move simple_itoa to libbb so that others can use it
  2011-04-11 14:18 assorted patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2011-04-11 14:18 ` [PATCH 3/7] environment: make default env path configurable Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  2011-04-11 14:18 ` [PATCH 5/7] kfifo: kfifo_put takes a const buffer Sascha Hauer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/hush.c   |   15 +--------------
 include/libbb.h |    2 ++
 lib/libbb.c     |   13 +++++++++++++
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index 77610bb..573bd3e 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -121,6 +121,7 @@
 #include <libbb.h>
 #include <glob.h>
 #include <getopt.h>
+#include <libbb.h>
 #include <linux/list.h>
 
 /*cmd_boot.c*/
@@ -361,20 +362,6 @@ static int b_addqchr(o_string *o, int ch, int quote)
 	return b_addchr(o, ch);
 }
 
-/* belongs in utility.c */
-static char *simple_itoa(unsigned int i)
-{
-	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
-	static char local[22];
-	char *p = &local[21];
-	*p-- = '\0';
-	do {
-		*p-- = '0' + i % 10;
-		i /= 10;
-	} while (i > 0);
-	return p + 1;
-}
-
 static int b_adduint(o_string *o, unsigned int i)
 {
 	int r;
diff --git a/include/libbb.h b/include/libbb.h
index 4151230..0962969 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -30,4 +30,6 @@ int copy_file(const char *src, const char *dst);
 
 int process_escape_sequence(const char *source, char *dest, int destlen);
 
+char *simple_itoa(unsigned int i);
+
 #endif /* __LIBBB_H */
diff --git a/lib/libbb.c b/lib/libbb.c
index 4d532f6..3d02202 100644
--- a/lib/libbb.c
+++ b/lib/libbb.c
@@ -114,3 +114,16 @@ char * safe_strncpy(char *dst, const char *src, size_t size)
 }
 EXPORT_SYMBOL(safe_strncpy);
 
+char *simple_itoa(unsigned int i)
+{
+	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
+	static char local[22];
+	char *p = &local[21];
+	*p-- = '\0';
+	do {
+		*p-- = '0' + i % 10;
+		i /= 10;
+	} while (i > 0);
+	return p + 1;
+}
+EXPORT_SYMBOL(simple_itoa);
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/7] kfifo: kfifo_put takes a const buffer
  2011-04-11 14:18 assorted patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2011-04-11 14:18 ` [PATCH 4/7] move simple_itoa to libbb so that others can use it Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  2011-04-11 14:18 ` [PATCH 6/7] copy_file: handle write return value correctly Sascha Hauer
  2011-04-11 14:18 ` [PATCH 7/7] cp command: handle directories as last argument Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/kfifo.h |    2 +-
 lib/kfifo.c     |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/kfifo.h b/include/kfifo.h
index 6f8be10..3eb03cb 100644
--- a/include/kfifo.h
+++ b/include/kfifo.h
@@ -43,7 +43,7 @@ void kfifo_free(struct kfifo *fifo);
  * bytes copied.
  */
 unsigned int kfifo_put(struct kfifo *fifo,
-				unsigned char *buffer, unsigned int len);
+				const unsigned char *buffer, unsigned int len);
 
 /**
  * kfifo_get - gets some data from the FIFO
diff --git a/lib/kfifo.c b/lib/kfifo.c
index bf5cee1..27d44e9 100644
--- a/lib/kfifo.c
+++ b/lib/kfifo.c
@@ -96,7 +96,7 @@ void kfifo_free(struct kfifo *fifo)
  *
  */
 unsigned int kfifo_put(struct kfifo *fifo,
-			 unsigned char *buffer, unsigned int len)
+			 const unsigned char *buffer, unsigned int len)
 {
 	unsigned int l;
 
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 6/7] copy_file: handle write return value correctly
  2011-04-11 14:18 assorted patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2011-04-11 14:18 ` [PATCH 5/7] kfifo: kfifo_put takes a const buffer Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  2011-04-11 14:18 ` [PATCH 7/7] cp command: handle directories as last argument Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

write() does not necessarily consume all input, handle this
case correctly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/copy_file.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/copy_file.c b/lib/copy_file.c
index 7083531..809befe 100644
--- a/lib/copy_file.c
+++ b/lib/copy_file.c
@@ -17,6 +17,7 @@ int copy_file(const char *src, const char *dst)
 	int srcfd = 0, dstfd = 0;
 	int r, w;
 	int ret = 1;
+	void *buf;
 
 	rw_buf = xmalloc(RW_BUF_SIZE);
 
@@ -40,10 +41,16 @@ int copy_file(const char *src, const char *dst)
 		}
 		if (!r)
 			break;
-		w = write(dstfd, rw_buf, r);
-		if (w < 0) {
-			perror("write");
-			goto out;
+
+		buf = rw_buf;
+		while (r) {
+			w = write(dstfd, buf, r);
+			if (w < 0) {
+				perror("write");
+				goto out;
+			}
+			buf += w;
+			r -= w;
 		}
 	}
 
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 7/7] cp command: handle directories as last argument
  2011-04-11 14:18 assorted patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2011-04-11 14:18 ` [PATCH 6/7] copy_file: handle write return value correctly Sascha Hauer
@ 2011-04-11 14:18 ` Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-04-11 14:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/cp.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/commands/cp.c b/commands/cp.c
index ae8719b..3428105 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -31,6 +31,7 @@
 #include <libbb.h>
 #include <fs.h>
 #include <malloc.h>
+#include <libgen.h>
 
 /**
  * @param[in] cmdtp FIXME
@@ -60,7 +61,7 @@ static int do_cp(struct command *cmdtp, int argc, char *argv[])
 	for (i = 1; i < argc - 1; i++) {
 		if (last_is_dir) {
 			char *dst;
-			dst = concat_path_file(argv[argc - 1], argv[i]);
+			dst = concat_path_file(argv[argc - 1], basename(argv[i]));
 			ret = copy_file(argv[i], dst);
 			if (ret)
 				goto out;
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-04-11 14:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-11 14:18 assorted patches Sascha Hauer
2011-04-11 14:18 ` [PATCH 1/7] eth: check the result of edev->get_ethaddr Sascha Hauer
2011-04-11 14:18 ` [PATCH 2/7] net: add a context to the packet handler Sascha Hauer
2011-04-11 14:18 ` [PATCH 3/7] environment: make default env path configurable Sascha Hauer
2011-04-11 14:18 ` [PATCH 4/7] move simple_itoa to libbb so that others can use it Sascha Hauer
2011-04-11 14:18 ` [PATCH 5/7] kfifo: kfifo_put takes a const buffer Sascha Hauer
2011-04-11 14:18 ` [PATCH 6/7] copy_file: handle write return value correctly Sascha Hauer
2011-04-11 14:18 ` [PATCH 7/7] cp command: handle directories as last argument Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox