* [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep
@ 2014-10-08 14:24 Sascha Hauer
2014-10-08 14:24 ` [PATCH 2/6] fs: do not lookup global FILE * when the file is already available Sascha Hauer
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-10-08 14:24 UTC (permalink / raw)
To: barebox
The struct device_d * in struct filep is never of interest, instead
it is always converted to a struct fs_device_d *, so simplify the code
by storing the struct fs_device_d * directly.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/devfs.c | 4 ++--
fs/fs.c | 75 ++++++++++++++++++++++--------------------------------------
include/fs.h | 3 +--
3 files changed, 30 insertions(+), 52 deletions(-)
diff --git a/fs/devfs.c b/fs/devfs.c
index f089c6f..872e19b 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -168,9 +168,9 @@ static int devfs_ioctl(struct device_d *_dev, FILE *f, int request, void *buf)
static int devfs_truncate(struct device_d *dev, FILE *f, ulong size)
{
- if (f->dev->num_resources < 1)
+ if (f->fsdev->dev.num_resources < 1)
return -ENOSPC;
- if (size > resource_size(&f->dev->resource[0]))
+ if (size > resource_size(&f->fsdev->dev.resource[0]))
return -ENOSPC;
return 0;
}
diff --git a/fs/fs.c b/fs/fs.c
index fd3d353..014a36a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -653,7 +653,7 @@ int open(const char *pathname, int flags, ...)
fsdrv = fsdev->driver;
- f->dev = &fsdev->dev;
+ f->fsdev = fsdev;
f->flags = flags;
if ((flags & O_ACCMODE) && !fsdrv->write) {
@@ -705,7 +705,6 @@ EXPORT_SYMBOL(creat);
int ioctl(int fd, int request, void *buf)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
int ret;
@@ -714,12 +713,11 @@ int ioctl(int fd, int request, void *buf)
return -errno;
f = &files[fd];
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (fsdrv->ioctl)
- ret = fsdrv->ioctl(dev, f, request, buf);
+ ret = fsdrv->ioctl(&f->fsdev->dev, f, request, buf);
else
ret = -ENOSYS;
if (ret)
@@ -729,13 +727,10 @@ int ioctl(int fd, int request, void *buf)
static ssize_t __read(FILE *f, void *buf, size_t count)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
int ret;
- dev = f->dev;
-
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (f->size != FILE_SIZE_STREAM && f->pos + count > f->size)
count = f->size - f->pos;
@@ -743,7 +738,7 @@ static ssize_t __read(FILE *f, void *buf, size_t count)
if (!count)
return 0;
- ret = fsdrv->read(dev, f, buf, count);
+ ret = fsdrv->read(&f->fsdev->dev, f, buf, count);
if (ret < 0)
errno = -ret;
@@ -790,15 +785,12 @@ EXPORT_SYMBOL(read);
static ssize_t __write(FILE *f, const void *buf, size_t count)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
int ret;
- dev = f->dev;
-
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (f->size != FILE_SIZE_STREAM && f->pos + count > f->size) {
- ret = fsdrv->truncate(dev, f, f->pos + count);
+ ret = fsdrv->truncate(&f->fsdev->dev, f, f->pos + count);
if (ret) {
if (ret != -ENOSPC)
goto out;
@@ -809,7 +801,7 @@ static ssize_t __write(FILE *f, const void *buf, size_t count)
f->size = f->pos + count;
}
}
- ret = fsdrv->write(dev, f, buf, count);
+ ret = fsdrv->write(&f->fsdev->dev, f, buf, count);
out:
if (ret < 0)
errno = -ret;
@@ -856,7 +848,6 @@ EXPORT_SYMBOL(write);
int flush(int fd)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
int ret;
@@ -865,11 +856,10 @@ int flush(int fd)
return -errno;
f = &files[fd];
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (fsdrv->flush)
- ret = fsdrv->flush(dev, f);
+ ret = fsdrv->flush(&f->fsdev->dev, f);
else
ret = 0;
@@ -881,7 +871,6 @@ int flush(int fd)
loff_t lseek(int fildes, loff_t offset, int whence)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
loff_t pos;
@@ -891,8 +880,7 @@ loff_t lseek(int fildes, loff_t offset, int whence)
return -1;
f = &files[fildes];
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (!fsdrv->lseek) {
ret = -ENOSYS;
goto out;
@@ -920,7 +908,7 @@ loff_t lseek(int fildes, loff_t offset, int whence)
goto out;
}
- return fsdrv->lseek(dev, f, pos);
+ return fsdrv->lseek(&f->fsdev->dev, f, pos);
out:
if (ret)
@@ -932,7 +920,6 @@ EXPORT_SYMBOL(lseek);
int erase(int fd, size_t count, unsigned long offset)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
int ret;
@@ -945,10 +932,9 @@ int erase(int fd, size_t count, unsigned long offset)
if (count > f->size - offset)
count = f->size - offset;
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (fsdrv->erase)
- ret = fsdrv->erase(dev, f, count, offset);
+ ret = fsdrv->erase(&f->fsdev->dev, f, count, offset);
else
ret = -ENOSYS;
@@ -961,7 +947,6 @@ EXPORT_SYMBOL(erase);
int protect(int fd, size_t count, unsigned long offset, int prot)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
int ret;
@@ -974,10 +959,9 @@ int protect(int fd, size_t count, unsigned long offset, int prot)
if (count > f->size - offset)
count = f->size - offset;
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (fsdrv->protect)
- ret = fsdrv->protect(dev, f, count, offset, prot);
+ ret = fsdrv->protect(&f->fsdev->dev, f, count, offset, prot);
else
ret = -ENOSYS;
@@ -1005,7 +989,6 @@ int protect_file(const char *file, int prot)
void *memmap(int fd, int flags)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
void *retp = (void *)-1;
@@ -1015,12 +998,11 @@ void *memmap(int fd, int flags)
return retp;
f = &files[fd];
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = f->fsdev->driver;
if (fsdrv->memmap)
- ret = fsdrv->memmap(dev, f, &retp, flags);
+ ret = fsdrv->memmap(&f->fsdev->dev, f, &retp, flags);
else
ret = -EINVAL;
@@ -1033,7 +1015,6 @@ EXPORT_SYMBOL(memmap);
int close(int fd)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f;
int ret;
@@ -1042,10 +1023,9 @@ int close(int fd)
return -errno;
f = &files[fd];
- dev = f->dev;
- fsdrv = dev_to_fs_driver(dev);
- ret = fsdrv->close(dev, f);
+ fsdrv = f->fsdev->driver;
+ ret = fsdrv->close(&f->fsdev->dev, f);
put_file(f);
@@ -1152,7 +1132,8 @@ static int fs_match(struct device_d *dev, struct driver_d *drv)
static int fs_probe(struct device_d *dev)
{
struct fs_device_d *fsdev = dev_to_fs_device(dev);
- struct fs_driver_d *fsdrv = dev_to_fs_driver(dev);
+ struct driver_d *drv = dev->driver;
+ struct fs_driver_d *fsdrv = container_of(drv, struct fs_driver_d, drv);
int ret;
ret = dev->driver->probe(dev);
@@ -1449,7 +1430,6 @@ EXPORT_SYMBOL(stat);
int lstat(const char *filename, struct stat *s)
{
- struct device_d *dev;
struct fs_driver_d *fsdrv;
struct fs_device_d *fsdev;
char *f = normalise_path(filename);
@@ -1466,18 +1446,17 @@ int lstat(const char *filename, struct stat *s)
goto out;
}
- if (fsdev != fs_dev_root && strcmp(f, fsdev->path)) {
+ if (fsdev != fs_dev_root && strcmp(f, fsdev->path))
f += strlen(fsdev->path);
- dev = &fsdev->dev;
- } else
- dev = &fs_dev_root->dev;
+ else
+ fsdev = fs_dev_root;
- fsdrv = dev_to_fs_driver(dev);
+ fsdrv = fsdev->driver;
if (*f == 0)
f = "/";
- ret = fsdrv->stat(dev, f, s);
+ ret = fsdrv->stat(&fsdev->dev, f, s);
out:
free(freep);
diff --git a/include/fs.h b/include/fs.h
index b2541a4..c3ce81a 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -23,7 +23,7 @@ typedef struct dir {
} DIR;
typedef struct filep {
- struct device_d *dev; /* The device this FILE belongs to */
+ struct fs_device_d *fsdev; /* The device this FILE belongs to */
loff_t pos; /* current position in stream */
#define FILE_SIZE_STREAM ((loff_t) -1)
loff_t size; /* The size of this inode */
@@ -82,7 +82,6 @@ struct fs_driver_d {
unsigned long flags;
};
-#define dev_to_fs_driver(d) container_of(d->driver, struct fs_driver_d, drv)
#define dev_to_fs_device(d) container_of(d, struct fs_device_d, dev)
extern struct list_head fs_device_list;
--
2.1.0
_______________________________________________
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/6] fs: do not lookup global FILE * when the file is already available
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
@ 2014-10-08 14:24 ` Sascha Hauer
2014-10-08 14:24 ` [PATCH 3/6] fs: Store the path in struct filep Sascha Hauer
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-10-08 14:24 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/fs.c b/fs/fs.c
index 014a36a..04b6408 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -251,7 +251,7 @@ static FILE *get_file(void)
static void put_file(FILE *f)
{
- files[f->no].in_use = 0;
+ f->in_use = 0;
}
static int check_fd(int fd)
--
2.1.0
_______________________________________________
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/6] fs: Store the path in struct filep
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
2014-10-08 14:24 ` [PATCH 2/6] fs: do not lookup global FILE * when the file is already available Sascha Hauer
@ 2014-10-08 14:24 ` Sascha Hauer
2014-10-08 14:24 ` [PATCH 4/6] fs: implement fstat Sascha Hauer
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-10-08 14:24 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 5 +++++
include/fs.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 04b6408..436f5cb 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -251,6 +251,8 @@ static FILE *get_file(void)
static void put_file(FILE *f)
{
+ free(f->path);
+ f->path = NULL;
f->in_use = 0;
}
@@ -670,6 +672,9 @@ int open(const char *pathname, int flags, ...)
if (ret)
goto out;
}
+
+ f->path = xstrdup(path);
+
ret = fsdrv->open(&fsdev->dev, f, path);
if (ret)
goto out;
diff --git a/include/fs.h b/include/fs.h
index c3ce81a..6eddb23 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -24,6 +24,7 @@ typedef struct dir {
typedef struct filep {
struct fs_device_d *fsdev; /* The device this FILE belongs to */
+ char *path;
loff_t pos; /* current position in stream */
#define FILE_SIZE_STREAM ((loff_t) -1)
loff_t size; /* The size of this inode */
--
2.1.0
_______________________________________________
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/6] fs: implement fstat
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
2014-10-08 14:24 ` [PATCH 2/6] fs: do not lookup global FILE * when the file is already available Sascha Hauer
2014-10-08 14:24 ` [PATCH 3/6] fs: Store the path in struct filep Sascha Hauer
@ 2014-10-08 14:24 ` Sascha Hauer
2014-10-08 14:24 ` [PATCH 5/6] libfile: add diff_file function Sascha Hauer
2014-10-08 14:24 ` [PATCH 6/6] commands: implement 'diff' command Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-10-08 14:24 UTC (permalink / raw)
To: barebox
fstat is useful to get information about an already opened file. Add
it to barebox.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 16 ++++++++++++++++
include/fs.h | 1 +
2 files changed, 17 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 436f5cb..ffdfa2c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1472,6 +1472,22 @@ out:
}
EXPORT_SYMBOL(lstat);
+int fstat(int fd, struct stat *s)
+{
+ FILE *f;
+ struct fs_device_d *fsdev;
+
+ if (check_fd(fd))
+ return -errno;
+
+ f = &files[fd];
+
+ fsdev = f->fsdev;
+
+ return fsdev->driver->stat(&fsdev->dev, f->path, s);
+}
+EXPORT_SYMBOL(fstat);
+
int mkdir (const char *pathname, mode_t mode)
{
struct fs_driver_d *fsdrv;
diff --git a/include/fs.h b/include/fs.h
index 6eddb23..63e35ca 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -114,6 +114,7 @@ int close(int fd);
int flush(int fd);
int lstat(const char *filename, struct stat *s);
int stat(const char *filename, struct stat *s);
+int fstat(int fd, struct stat *s);
ssize_t read(int fd, void *buf, size_t count);
ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
int ioctl(int fd, int request, void *buf);
--
2.1.0
_______________________________________________
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/6] libfile: add diff_file function
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
` (2 preceding siblings ...)
2014-10-08 14:24 ` [PATCH 4/6] fs: implement fstat Sascha Hauer
@ 2014-10-08 14:24 ` Sascha Hauer
2014-10-08 14:24 ` [PATCH 6/6] commands: implement 'diff' command Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-10-08 14:24 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/libfile.h | 2 ++
lib/libfile.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
diff --git a/include/libfile.h b/include/libfile.h
index 4a25a91..315adb2 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -15,4 +15,6 @@ int write_file(const char *filename, void *buf, size_t size);
int copy_file(const char *src, const char *dst, int verbose);
+int diff_file(const char *f1, const char *f2);
+
#endif /* __LIBFILE_H */
diff --git a/lib/libfile.c b/lib/libfile.c
index c626e2f..1d773e3 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -331,3 +331,74 @@ out:
return ret;
}
EXPORT_SYMBOL(copy_file);
+
+/**
+ * diff_file - Compare two files
+ * @f1: The first file
+ * @f2: The second file
+ *
+ * Return: 0 if both files are identical, 1 if they differ,
+ * a negative error code if some error occured
+ */
+int diff_file(const char *f1, const char *f2)
+{
+ int fd1, fd2, ret;
+ struct stat s1, s2;
+ void *buf1, *buf2;
+ loff_t left;
+
+ fd1 = open(f1, O_RDONLY);
+ if (fd1 < 0)
+ return -errno;
+
+ fd2 = open(f2, O_RDONLY);
+ if (fd2 < 0) {
+ ret = -errno;
+ goto err_out1;
+ }
+
+ ret = fstat(fd1, &s1);
+ if (ret)
+ goto err_out2;
+
+ ret = fstat(fd2, &s2);
+ if (ret)
+ goto err_out2;
+
+ if (s1.st_size != s2.st_size)
+ return 1;
+
+ buf1 = xmalloc(RW_BUF_SIZE);
+ buf2 = xmalloc(RW_BUF_SIZE);
+
+ left = s1.st_size;
+ while (left) {
+ loff_t now = min(left, (loff_t)RW_BUF_SIZE);
+
+ ret = read_full(fd1, buf1, now);
+ if (ret < 0)
+ goto err_out3;
+
+ ret = read_full(fd2, buf2, now);
+ if (ret < 0)
+ goto err_out3;
+
+ if (memcmp(buf1, buf2, now)) {
+ ret = 1;
+ goto err_out3;
+ }
+
+ left -= now;
+ }
+
+ ret = 0;
+
+err_out3:
+ free(buf1);
+ free(buf2);
+err_out2:
+ close(fd2);
+err_out1:
+ close(fd1);
+ return ret;
+}
--
2.1.0
_______________________________________________
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/6] commands: implement 'diff' command
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
` (3 preceding siblings ...)
2014-10-08 14:24 ` [PATCH 5/6] libfile: add diff_file function Sascha Hauer
@ 2014-10-08 14:24 ` Sascha Hauer
2014-10-08 15:32 ` Antony Pavlov
4 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2014-10-08 14:24 UTC (permalink / raw)
To: barebox
This command compares two files. It does not show the differences,
it only returns successfully if both files are identical and with
an error if they differ.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 10 ++++++++++
commands/Makefile | 1 +
commands/diff.c | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
create mode 100644 commands/diff.c
diff --git a/commands/Kconfig b/commands/Kconfig
index d73a393..05d5426 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -811,6 +811,16 @@ config CMD_CP
Options:
-v verbose
+config CMD_DIFF
+ tristate
+ prompt "diff"
+ help
+ compare two files
+
+ Usage: diff FILE1 FILE2
+
+ Returns successfully if the two files are the same, return with an error if not
+
config CMD_DIRNAME
tristate
prompt "dirname"
diff --git a/commands/Makefile b/commands/Makefile
index b1cdf33..e53bdde 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -106,3 +106,4 @@ obj-$(CONFIG_CMD_IMD) += imd.o
obj-$(CONFIG_CMD_HWCLOCK) += hwclock.o
obj-$(CONFIG_CMD_USBGADGET) += usbgadget.o
obj-$(CONFIG_CMD_FIRMWARELOAD) += firmwareload.o
+obj-$(CONFIG_CMD_DIFF) += diff.o
diff --git a/commands/diff.c b/commands/diff.c
new file mode 100644
index 0000000..26eaf88
--- /dev/null
+++ b/commands/diff.c
@@ -0,0 +1,42 @@
+/*
+ * diff - determine if two files differ
+ *
+ * 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 as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <complete.h>
+#include <libfile.h>
+
+static int do_diff(int argc, char *argv[])
+{
+ if (argc != 3)
+ return COMMAND_ERROR_USAGE;
+
+ return diff_file(argv[1], argv[2]);
+}
+
+BAREBOX_CMD_HELP_START(diff)
+BAREBOX_CMD_HELP_TEXT("Returns successfully if the two files are the same, return with an error if not")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(diff)
+ .cmd = do_diff,
+ BAREBOX_CMD_DESC("compare two files")
+ BAREBOX_CMD_OPTS("FILE1 FILE2")
+ BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+ BAREBOX_CMD_HELP(cmd_diff_help)
+BAREBOX_CMD_END
--
2.1.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 6/6] commands: implement 'diff' command
2014-10-08 14:24 ` [PATCH 6/6] commands: implement 'diff' command Sascha Hauer
@ 2014-10-08 15:32 ` Antony Pavlov
2014-10-09 6:50 ` Sascha Hauer
0 siblings, 1 reply; 8+ messages in thread
From: Antony Pavlov @ 2014-10-08 15:32 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Wed, 8 Oct 2014 16:24:15 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:
> This command compares two files. It does not show the differences,
> it only returns successfully if both files are identical and with
> an error if they differ.
Here are my two comments:
1. there is the 'cmp' command for simple comparing two files from Unix cmdline.
Can we use 'cmp' name instead of 'diff'?
2. we already can use
memcmp -s FILE1 -d FILE2 0 0
for comparing files :)
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> commands/Kconfig | 10 ++++++++++
> commands/Makefile | 1 +
> commands/diff.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 53 insertions(+)
> create mode 100644 commands/diff.c
>
> diff --git a/commands/Kconfig b/commands/Kconfig
> index d73a393..05d5426 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -811,6 +811,16 @@ config CMD_CP
> Options:
> -v verbose
>
> +config CMD_DIFF
> + tristate
> + prompt "diff"
> + help
> + compare two files
> +
> + Usage: diff FILE1 FILE2
> +
> + Returns successfully if the two files are the same, return with an error if not
> +
> config CMD_DIRNAME
> tristate
> prompt "dirname"
> diff --git a/commands/Makefile b/commands/Makefile
> index b1cdf33..e53bdde 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -106,3 +106,4 @@ obj-$(CONFIG_CMD_IMD) += imd.o
> obj-$(CONFIG_CMD_HWCLOCK) += hwclock.o
> obj-$(CONFIG_CMD_USBGADGET) += usbgadget.o
> obj-$(CONFIG_CMD_FIRMWARELOAD) += firmwareload.o
> +obj-$(CONFIG_CMD_DIFF) += diff.o
> diff --git a/commands/diff.c b/commands/diff.c
> new file mode 100644
> index 0000000..26eaf88
> --- /dev/null
> +++ b/commands/diff.c
> @@ -0,0 +1,42 @@
> +/*
> + * diff - determine if two files differ
> + *
> + * 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 as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * 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.
> + *
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <complete.h>
> +#include <libfile.h>
> +
> +static int do_diff(int argc, char *argv[])
> +{
> + if (argc != 3)
> + return COMMAND_ERROR_USAGE;
> +
> + return diff_file(argv[1], argv[2]);
> +}
> +
> +BAREBOX_CMD_HELP_START(diff)
> +BAREBOX_CMD_HELP_TEXT("Returns successfully if the two files are the same, return with an error if not")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(diff)
> + .cmd = do_diff,
> + BAREBOX_CMD_DESC("compare two files")
> + BAREBOX_CMD_OPTS("FILE1 FILE2")
> + BAREBOX_CMD_GROUP(CMD_GRP_FILE)
> + BAREBOX_CMD_HELP(cmd_diff_help)
> +BAREBOX_CMD_END
> --
> 2.1.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 6/6] commands: implement 'diff' command
2014-10-08 15:32 ` Antony Pavlov
@ 2014-10-09 6:50 ` Sascha Hauer
0 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-10-09 6:50 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Wed, Oct 08, 2014 at 07:32:26PM +0400, Antony Pavlov wrote:
> On Wed, 8 Oct 2014 16:24:15 +0200
> Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> > This command compares two files. It does not show the differences,
> > it only returns successfully if both files are identical and with
> > an error if they differ.
>
> Here are my two comments:
>
> 1. there is the 'cmp' command for simple comparing two files from Unix cmdline.
> Can we use 'cmp' name instead of 'diff'?
Yes, good idea. 'cmp' seems a better name. I changed it.
>
> 2. we already can use
> memcmp -s FILE1 -d FILE2 0 0
> for comparing files :)
I know. Admittedly I'm working on stuff where I need the diff_file (now
compare_file) C function. The cmp command is merely a vehicle to not
have the compare_file function unused in the tree until this work is
done ;)
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
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:[~2014-10-09 6:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
2014-10-08 14:24 ` [PATCH 2/6] fs: do not lookup global FILE * when the file is already available Sascha Hauer
2014-10-08 14:24 ` [PATCH 3/6] fs: Store the path in struct filep Sascha Hauer
2014-10-08 14:24 ` [PATCH 4/6] fs: implement fstat Sascha Hauer
2014-10-08 14:24 ` [PATCH 5/6] libfile: add diff_file function Sascha Hauer
2014-10-08 14:24 ` [PATCH 6/6] commands: implement 'diff' command Sascha Hauer
2014-10-08 15:32 ` Antony Pavlov
2014-10-09 6:50 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox