All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Schmidt <alexs@linux.vnet.ibm.com>
To: linux-mtd@lists.infradead.org
Cc: Andreas Arnez <arnez@linux.vnet.ibm.com>,
	Frank Haverkamp <haver@linux.vnet.ibm.com>
Subject: [PATCH 2/4 try2] ubi-utils: migrate ubimirror
Date: Thu, 27 Sep 2007 18:15:32 -0000	[thread overview]
Message-ID: <200709272014.35040.alexs@linux.vnet.ibm.com> (raw)
In-Reply-To: <200709271952.06870.alexs@linux.vnet.ibm.com>

Migrate ubimirror to the new libubi.

Signed-off-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
---
 ubi-utils/Makefile           |    2 -
 ubi-utils/src/libubimirror.c |   51 ++++++++++++++++++++++++++++++-------------
 ubi-utils/src/ubimirror.c    |    3 +-
 3 files changed, 39 insertions(+), 17 deletions(-)

--- mtd-utils.orig/ubi-utils/Makefile
+++ mtd-utils/ubi-utils/Makefile
@@ -51,7 +51,7 @@ pfiflash: pfiflash.o libpfiflash.o list.
 	$(CC) $(LDFLAGS) -o $@ $^
 
 ubimirror: ubimirror.o error.o libubimirror.o bootenv.o hashmap.o \
-		libubiold.o libubiold_sysfs.o crc32.o
+		libubi.o crc32.o
 	$(CC) $(LDFLAGS) -o $@ $^
 
 nand2bin: nand2bin.o nandecc.o nandcorr.o
--- mtd-utils.orig/ubi-utils/src/libubimirror.c
+++ mtd-utils/ubi-utils/src/libubimirror.c
@@ -22,11 +22,15 @@
 #include <memory.h>
 #include <fcntl.h>
 
-#include <libubiold.h>
+#include <libubi.h>
 #include "ubimirror.h"
 
 #define COMPARE_BUF_SIZE    (128 * 1024)
 
+#define DEFAULT_DEV_PATTERN    "/dev/ubi%d"
+#define DEFAULT_VOL_PATTERN    "/dev/ubi%d_%d"
+#define MAXPATH          1024
+
 #define EBUF(fmt...) do {			\
 	snprintf(err_buf, err_buf_size, fmt);	\
 } while (0)
@@ -125,14 +129,26 @@ static int compare_files(int fd_a, int f
 	return rc;
 }
 
-static int copy_files(int fd_in, int fd_out)
+int vol_get_used_bytes(int vol_fd, unsigned long long *bytes)
+{
+	off_t res;
+
+	res = lseek(vol_fd, 0, SEEK_END);
+	if (res == (off_t)-1)
+		return -1;
+	*bytes = (unsigned long long) res;
+	res = lseek(vol_fd, 0, SEEK_SET);
+	return res == (off_t)-1 ? -1 : 0;
+}
+
+static int copy_files(libubi_t ulib, int fd_in, int fd_out)
 {
 	unsigned char buf_a[COMPARE_BUF_SIZE];
 	ssize_t len_a, len_b;
 	unsigned long long update_size, copied;
 
-	if (ubi_vol_get_used_bytes(fd_in, &update_size) == -1 ||
-	    ubi_vol_update(fd_out, update_size) == -1)
+	if (vol_get_used_bytes(fd_in, &update_size) == -1 ||
+	    ubi_update_start(ulib, fd_out, update_size) == -1)
 		return update_error;
 	for (copied = 0; copied < update_size; copied += len_b ) {
 		len_a = fill_buffer(fd_in, buf_a, sizeof(buf_a));
@@ -152,7 +168,8 @@ int ubimirror(uint32_t devno, int seqnum
 {
 	int rc = 0;
 	uint32_t src_id;
-	ubi_lib_t ulib = NULL;
+	char path[MAXPATH];
+	libubi_t ulib;
 	int fd_in = -1, i = 0, fd_out = -1;
 
 	if (ids_size == 0)
@@ -165,11 +182,13 @@ int ubimirror(uint32_t devno, int seqnum
 		src_id = ids[seqnum];
 	}
 
-	rc = ubi_open(&ulib);
-	if (rc != 0)
+	ulib = libubi_open();
+	if (ulib == NULL)
 		return ubi_error;
 
-	fd_in = ubi_vol_open(ulib, devno, src_id, O_RDONLY);
+	snprintf(path, MAXPATH, DEFAULT_VOL_PATTERN, devno, src_id);
+
+	fd_in = open(path, O_RDONLY);
 	if (fd_in == -1) {
 		EBUF("open error source volume %d", ids[i]);
 		rc = open_error;
@@ -180,8 +199,10 @@ int ubimirror(uint32_t devno, int seqnum
 		if (ids[i] == src_id)		/* skip self-mirror */
 			continue;
 
-		fd_out = ubi_vol_open(ulib, devno, ids[i], O_RDWR);
-		if (fd_out == -1){
+		snprintf(path, MAXPATH, DEFAULT_VOL_PATTERN, devno, ids[i]);
+
+		fd_out = open(path, O_RDWR);
+		if (fd_out < 0){
 			EBUF("open error destination volume %d", ids[i]);
 			rc = open_error;
 			goto err;
@@ -191,14 +212,14 @@ int ubimirror(uint32_t devno, int seqnum
 			EBUF("compare error volume %d and %d", src_id, ids[i]);
 			goto err;
 		} else if (rc == compare_different) {
-			rc = copy_files(fd_in, fd_out);
+			rc = copy_files(ulib, fd_in, fd_out);
 			if (rc != 0) {
 				EBUF("mirror error volume %d to %d", src_id,
 						ids[i]);
 				goto err;
 			}
 		}
-		if ((rc = ubi_vol_close(fd_out)) == -1) {
+		if ((rc = close(fd_out)) == -1) {
 			EBUF("close error volume %d", ids[i]);
 			rc = close_error;
 			goto err;
@@ -207,10 +228,10 @@ int ubimirror(uint32_t devno, int seqnum
 	}
 err:
 	if (fd_out != -1)
-		ubi_vol_close(fd_out);
+		close(fd_out);
 	if (fd_in != -1)
-		ubi_vol_close(fd_in);
+		close(fd_in);
 	if (ulib != NULL)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 	return rc;
 }
--- mtd-utils.orig/ubi-utils/src/ubimirror.c
+++ mtd-utils/ubi-utils/src/ubimirror.c
@@ -19,6 +19,7 @@
  *
  * 1.2 Removed argp because we want to use uClibc.
  * 1.3 Minor cleanups
+ * 1.4 Migrated to new libubi
  */
 
 #include <stdio.h>
@@ -35,7 +36,7 @@
 #include "example_ubi.h"
 #include "ubimirror.h"
 
-#define PROGRAM_VERSION "1.3"
+#define PROGRAM_VERSION "1.4"
 
 typedef enum action_t {
 	ACT_NORMAL = 0,

  parent reply	other threads:[~2007-09-27 18:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27 17:52 [PATCH 0/4 try2] ubi-utils: migrate to new libubi Alexander Schmidt
2007-09-27 18:15 ` [PATCH 1/4 try2] ubi-utils: migrate pddcustomize Alexander Schmidt
2007-09-27 18:15 ` Alexander Schmidt [this message]
2007-09-27 18:30   ` [PATCH 2/4 try2] ubi-utils: migrate ubimirror Frank Haverkamp
2007-09-28  7:41     ` Alexander Schmidt
2007-09-29  8:55       ` Artem Bityutskiy
2007-10-02 11:40         ` Alexander Schmidt
2007-10-13 14:29         ` David Woodhouse
2007-10-14  8:17         ` Jörn Engel
2007-09-27 18:17 ` [PATCH 3/4 try2] ubi-utils: migrate pfiflash Alexander Schmidt
2007-09-27 18:17 ` [PATCH 4/4 try2] ubi-utils: remove libubiold Alexander Schmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200709272014.35040.alexs@linux.vnet.ibm.com \
    --to=alexs@linux.vnet.ibm.com \
    --cc=arnez@linux.vnet.ibm.com \
    --cc=haver@linux.vnet.ibm.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.