diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/Kconfig | 14 | ||||
-rw-r--r-- | commands/Makefile | 2 | ||||
-rw-r--r-- | commands/basename.c | 47 | ||||
-rw-r--r-- | commands/crc.c | 4 | ||||
-rw-r--r-- | commands/digest.c | 4 | ||||
-rw-r--r-- | commands/dirname.c | 47 | ||||
-rw-r--r-- | commands/flash.c | 4 | ||||
-rw-r--r-- | commands/ls.c | 2 | ||||
-rw-r--r-- | commands/mem.c | 49 | ||||
-rw-r--r-- | commands/uncompress.c | 4 |
10 files changed, 143 insertions, 34 deletions
diff --git a/commands/Kconfig b/commands/Kconfig index 52e1f171bb..4555b71893 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -198,6 +198,20 @@ config CMD_AUTOMOUNT this directory available (discover USB devices, bring network interface up and finally mount the filesystem). +config CMD_BASENAME + tristate + prompt "basename" + help + Strip directory and suffix from filenames and store the result in a + environment variable + +config CMD_DIRNAME + tristate + prompt "dirname" + help + Strip last component of file name and store the result in a + environment variable + endmenu menu "console " diff --git a/commands/Makefile b/commands/Makefile index 4c8a0a9595..3f5f166de1 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -66,3 +66,5 @@ obj-$(CONFIG_CMD_IOMEM) += iomem.o obj-$(CONFIG_CMD_LINUX_EXEC) += linux_exec.o obj-$(CONFIG_CMD_AUTOMOUNT) += automount.o obj-$(CONFIG_CMD_GLOBAL) += global.o +obj-$(CONFIG_CMD_BASENAME) += basename.o +obj-$(CONFIG_CMD_DIRNAME) += dirname.o diff --git a/commands/basename.c b/commands/basename.c new file mode 100644 index 0000000000..b47ff8ca9c --- /dev/null +++ b/commands/basename.c @@ -0,0 +1,47 @@ +/* + * basename.c - strip directory and suffix from filenames + * + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <common.h> +#include <command.h> +#include <libgen.h> +#include <environment.h> + +static int do_basename(int argc, char *argv[]) +{ + if (argc != 3) + return COMMAND_ERROR_USAGE; + + setenv(argv[2], basename(argv[1])); + + return 0; +} + +BAREBOX_CMD_HELP_START(basename) +BAREBOX_CMD_HELP_USAGE("basename NAME BASENAME\n") +BAREBOX_CMD_HELP_SHORT("strip NAME and store into $BASENAME\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(basename) + .cmd = do_basename, + .usage = "strip directory and suffix from filenames", + BAREBOX_CMD_HELP(cmd_basename_help) +BAREBOX_CMD_END diff --git a/commands/crc.c b/commands/crc.c index df229410f6..09af6aa3f9 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -84,8 +84,8 @@ out: static int do_crc(int argc, char *argv[]) { - ulong start = 0, size = ~0, total = 0; - ulong crc = 0, vcrc = 0; + loff_t start = 0, size = ~0; + ulong crc = 0, vcrc = 0, total = 0; char *filename = "/dev/mem"; #ifdef CONFIG_CMD_CRC_CMP char *vfilename = NULL; diff --git a/commands/digest.c b/commands/digest.c index 84329144c7..07cbec9907 100644 --- a/commands/digest.c +++ b/commands/digest.c @@ -51,7 +51,7 @@ static int do_digest(char *algorithm, int argc, char *argv[]) argv++; while (*argv) { char *filename = "/dev/mem"; - ulong start = 0, size = ~0; + loff_t start = 0, size = ~0; /* arguments are either file, file+area or area */ if (parse_area_spec(*argv, &start, &size)) { @@ -66,7 +66,7 @@ static int do_digest(char *algorithm, int argc, char *argv[]) for (i = 0; i < d->length; i++) printf("%02x", hash[i]); - printf(" %s\t0x%08lx ... 0x%08lx\n", filename, start, start + size); + printf(" %s\t0x%08llx ... 0x%08llx\n", filename, start, start + size); argv++; } diff --git a/commands/dirname.c b/commands/dirname.c new file mode 100644 index 0000000000..cf1d0a022d --- /dev/null +++ b/commands/dirname.c @@ -0,0 +1,47 @@ +/* + * dirname.c - strip directory and suffix from filenames + * + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <common.h> +#include <command.h> +#include <libgen.h> +#include <environment.h> + +static int do_dirname(int argc, char *argv[]) +{ + if (argc != 3) + return COMMAND_ERROR_USAGE; + + setenv(argv[2], dirname(argv[1])); + + return 0; +} + +BAREBOX_CMD_HELP_START(dirname) +BAREBOX_CMD_HELP_USAGE("dirname NAME DIRNAME\n") +BAREBOX_CMD_HELP_SHORT("strip last componext of NAME and store into $DIRNAME\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(dirname) + .cmd = do_dirname, + .usage = "strip last component from file name", + BAREBOX_CMD_HELP(cmd_dirname_help) +BAREBOX_CMD_END diff --git a/commands/flash.c b/commands/flash.c index 1fcb1cff00..d71349a192 100644 --- a/commands/flash.c +++ b/commands/flash.c @@ -41,7 +41,7 @@ static int do_flerase(int argc, char *argv[]) int fd; char *filename = NULL; struct stat s; - unsigned long start = 0, size = ~0; + loff_t start = 0, size = ~0; int ret = 0; if (argc == 1) @@ -109,7 +109,7 @@ static int do_protect(int argc, char *argv[]) char *filename = NULL; struct stat s; int prot = 1; - unsigned long start = 0, size = ~0; + loff_t start = 0, size = ~0; int ret = 0, err; if (argc == 1) diff --git a/commands/ls.c b/commands/ls.c index ad609f3133..fbcbadcd08 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -35,7 +35,7 @@ static void ls_one(const char *path, struct stat *s) unsigned int namelen = strlen(path); mkmodestr(s->st_mode, modestr); - printf("%s %10lu %*.*s\n", modestr, s->st_size, namelen, namelen, path); + printf("%s %10llu %*.*s\n", modestr, s->st_size, namelen, namelen, path); } int ls(const char *path, ulong flags) diff --git a/commands/mem.c b/commands/mem.c index 080bfdef3f..b8e3bc43b8 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -43,7 +43,7 @@ #define PRINTF(fmt,args...) #endif -#define RW_BUF_SIZE (ulong)4096 +#define RW_BUF_SIZE 4096 static char *rw_buf; static char *DEVMEM = "/dev/mem"; @@ -55,7 +55,7 @@ static char *DEVMEM = "/dev/mem"; */ #define DISP_LINE_LEN 16 -int memory_display(char *addr, ulong offs, ulong nbytes, int size) +int memory_display(char *addr, loff_t offs, ulong nbytes, int size) { ulong linebytes, i; u_char *cp; @@ -72,7 +72,7 @@ int memory_display(char *addr, ulong offs, ulong nbytes, int size) u_char *ucp = (u_char *)linebuf; uint count = 52; - printf("%08lx:", offs); + printf("%08llx:", offs); linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; for (i = 0; i < linebytes; i += size) { @@ -108,7 +108,7 @@ int memory_display(char *addr, ulong offs, ulong nbytes, int size) return 0; } -static int open_and_lseek(const char *filename, int mode, off_t pos) +static int open_and_lseek(const char *filename, int mode, loff_t pos) { int fd, ret; @@ -163,7 +163,7 @@ static int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, static int do_mem_md(int argc, char *argv[]) { - ulong start = 0, size = 0x100; + loff_t start = 0, size = 0x100; int r, now; int ret = 0; int fd; @@ -187,7 +187,7 @@ static int do_mem_md(int argc, char *argv[]) return 1; do { - now = min(size, RW_BUF_SIZE); + now = min(size, (loff_t)RW_BUF_SIZE); r = read(fd, rw_buf, now); if (r < 0) { perror("read"); @@ -240,7 +240,7 @@ static int do_mem_mw(int argc, char *argv[]) int fd; char *filename = DEVMEM; int mode = O_RWSIZE_4; - ulong adr; + loff_t adr; if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &filename) < 0) return 1; @@ -248,7 +248,7 @@ static int do_mem_mw(int argc, char *argv[]) if (optind + 1 >= argc) return COMMAND_ERROR_USAGE; - adr = strtoul_suffix(argv[optind++], NULL, 0); + adr = strtoull_suffix(argv[optind++], NULL, 0); fd = open_and_lseek(filename, mode | O_WRONLY, adr); if (fd < 0) @@ -300,7 +300,7 @@ BAREBOX_CMD_END static int do_mem_cmp(int argc, char *argv[]) { - ulong addr1, addr2, count = ~0; + loff_t addr1, addr2, count = ~0; int mode = O_RWSIZE_1; char *sourcefile = DEVMEM; char *destfile = DEVMEM; @@ -316,8 +316,8 @@ static int do_mem_cmp(int argc, char *argv[]) if (optind + 2 > argc) return COMMAND_ERROR_USAGE; - addr1 = strtoul_suffix(argv[optind], NULL, 0); - addr2 = strtoul_suffix(argv[optind + 1], NULL, 0); + addr1 = strtoull_suffix(argv[optind], NULL, 0); + addr2 = strtoull_suffix(argv[optind + 1], NULL, 0); if (optind + 2 == argc) { if (sourcefile == DEVMEM) { @@ -330,7 +330,7 @@ static int do_mem_cmp(int argc, char *argv[]) } count = statbuf.st_size - addr1; } else { - count = strtoul_suffix(argv[optind + 2], NULL, 0); + count = strtoull_suffix(argv[optind + 2], NULL, 0); } sourcefd = open_and_lseek(sourcefile, mode | O_RDONLY, addr1); @@ -348,7 +348,7 @@ static int do_mem_cmp(int argc, char *argv[]) while (count > 0) { int now, r1, r2, i; - now = min(RW_BUF_SIZE, count); + now = min((loff_t)RW_BUF_SIZE, count); r1 = read(sourcefd, rw_buf, now); if (r1 < 0) { @@ -409,8 +409,7 @@ BAREBOX_CMD_END static int do_mem_cp(int argc, char *argv[]) { - ulong count; - ulong dest, src; + loff_t count, dest, src; char *sourcefile = DEVMEM; char *destfile = DEVMEM; int sourcefd, destfd; @@ -424,8 +423,8 @@ static int do_mem_cp(int argc, char *argv[]) if (optind + 2 > argc) return COMMAND_ERROR_USAGE; - src = strtoul_suffix(argv[optind], NULL, 0); - dest = strtoul_suffix(argv[optind + 1], NULL, 0); + src = strtoull_suffix(argv[optind], NULL, 0); + dest = strtoull_suffix(argv[optind + 1], NULL, 0); if (optind + 2 == argc) { if (sourcefile == DEVMEM) { @@ -438,7 +437,7 @@ static int do_mem_cp(int argc, char *argv[]) } count = statbuf.st_size - src; } else { - count = strtoul_suffix(argv[optind + 2], NULL, 0); + count = strtoull_suffix(argv[optind + 2], NULL, 0); } sourcefd = open_and_lseek(sourcefile, mode | O_RDONLY, src); @@ -454,7 +453,7 @@ static int do_mem_cp(int argc, char *argv[]) while (count > 0) { int now, r, w, tmp; - now = min(RW_BUF_SIZE, count); + now = min((loff_t)RW_BUF_SIZE, count); r = read(sourcefd, rw_buf, now); if (r < 0) { @@ -516,7 +515,7 @@ BAREBOX_CMD_END static int do_memset(int argc, char *argv[]) { - ulong s, c, n; + loff_t s, c, n; int fd; char *buf; int mode = O_RWSIZE_1; @@ -529,9 +528,9 @@ static int do_memset(int argc, char *argv[]) if (optind + 3 > argc) return COMMAND_ERROR_USAGE; - s = strtoul_suffix(argv[optind], NULL, 0); - c = strtoul_suffix(argv[optind + 1], NULL, 0); - n = strtoul_suffix(argv[optind + 2], NULL, 0); + s = strtoull_suffix(argv[optind], NULL, 0); + c = strtoull_suffix(argv[optind + 1], NULL, 0); + n = strtoull_suffix(argv[optind + 2], NULL, 0); fd = open_and_lseek(file, mode | O_WRONLY, s); if (fd < 0) @@ -543,7 +542,7 @@ static int do_memset(int argc, char *argv[]) while (n > 0) { int now; - now = min(RW_BUF_SIZE, n); + now = min((loff_t)RW_BUF_SIZE, n); ret = write(fd, buf, now); if (ret < 0) { @@ -624,7 +623,7 @@ static int mem_init(void) device_initcall(mem_init); -static ssize_t zero_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags) +static ssize_t zero_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags) { memset(buf, 0, count); return count; diff --git a/commands/uncompress.c b/commands/uncompress.c index e96928b4c3..179d525749 100644 --- a/commands/uncompress.c +++ b/commands/uncompress.c @@ -1,5 +1,5 @@ /* - * uncompress.c - uncompress a lzo compressed file + * uncompress.c - uncompress a compressed file * * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix * @@ -64,7 +64,7 @@ static const __maybe_unused char cmd_uncompress_help[] = BAREBOX_CMD_START(uncompress) .cmd = do_uncompress, - .usage = "lzop <infile> <outfile>", + .usage = "uncompress a compressed file", BAREBOX_CMD_HELP(cmd_uncompress_help) BAREBOX_CMD_END |