public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Alexander Schmidt <alexs@linux.vnet.ibm.com>
To: "linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Cc: Andreas Arnez <arnez@linux.vnet.ibm.com>,
	Frank Haverkamp <haver@linux.vnet.ibm.com>
Subject: Re: [PATCH 1/4 try3] ubi-utils: migrate pddcustomize
Date: Tue, 2 Oct 2007 14:17:39 +0200	[thread overview]
Message-ID: <200710021417.40075.alexs@linux.vnet.ibm.com> (raw)
In-Reply-To: <200710021416.02621.alexs@linux.vnet.ibm.com>

Migrate pddcustomize to the new libubi.

Signed-off-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
---
 ubi-utils/Makefile           |    2 -
 ubi-utils/src/pddcustomize.c |   47 ++++++++++++++++++++++++++-----------------
 2 files changed, 30 insertions(+), 19 deletions(-)

Index: mtd-utils/ubi-utils/Makefile
===================================================================
--- mtd-utils.orig/ubi-utils/Makefile	2007-10-02 12:19:11.000000000 +0200
+++ mtd-utils/ubi-utils/Makefile	2007-10-02 13:49:01.000000000 +0200
@@ -43,7 +43,7 @@
 	$(CC) $(LDFLAGS) -o $@ $^
 
 pddcustomize: pddcustomize.o error.o libubimirror.o bootenv.o hashmap.o \
-		libubiold.o libubiold_sysfs.o crc32.o
+		libubi.o crc32.o
 	$(CC) $(LDFLAGS) -o $@ $^
 
 pfiflash: pfiflash.o libpfiflash.o list.o reader.o error.o libubimirror.o \
Index: mtd-utils/ubi-utils/src/pddcustomize.c
===================================================================
--- mtd-utils.orig/ubi-utils/src/pddcustomize.c	2007-10-02 12:19:11.000000000 +0200
+++ mtd-utils/ubi-utils/src/pddcustomize.c	2007-10-02 13:50:08.000000000 +0200
@@ -26,6 +26,7 @@
  *
  * 1.3 Removed argp because we want to use uClibc.
  * 1.4 Minor cleanups
+ * 1.5 Migrated to new libubi
  */
 
 #include <stdio.h>
@@ -34,6 +35,7 @@
 #include <string.h>
 #include <getopt.h>
 #include <unistd.h>
+#include <limits.h>
 #include <errno.h>
 #include <mtd/ubi-header.h>
 
@@ -41,10 +43,13 @@
 #include "bootenv.h"
 #include "error.h"
 #include "example_ubi.h"
-#include "libubiold.h"
+#include "libubi.h"
 #include "ubimirror.h"
 
-#define PROGRAM_VERSION "1.4"
+#define PROGRAM_VERSION "1.5"
+
+#define DEFAULT_DEV_PATTERN    "/dev/ubi%d"
+#define DEFAULT_VOL_PATTERN    "/dev/ubi%d_%d"
 
 typedef enum action_t {
 	ACT_NORMAL   = 0,
@@ -299,17 +304,20 @@
 static int
 ubi_read_bootenv(uint32_t devno, uint32_t id, bootenv_t env)
 {
-	ubi_lib_t ulib = NULL;
+	libubi_t ulib;
 	int rc = 0;
+	char path[PATH_MAX];
 	FILE* fp_in = NULL;
 
-	rc = ubi_open(&ulib);
-	if( rc ){
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		err_msg("Cannot allocate ubi structure\n");
-		return rc;
+		return -1;
 	}
 
-	fp_in = ubi_vol_fopen_read(ulib, devno, id);
+	snprintf(path, PATH_MAX, DEFAULT_VOL_PATTERN, devno, id);
+
+	fp_in = fopen(path, "r");
 	if (fp_in == NULL) {
 		err_msg("Cannot open volume:%d number:%d\n", devno, id);
 		goto err;
@@ -322,9 +330,9 @@
 	}
 
 err:
-	if( fp_in )
+	if (fp_in)
 		fclose(fp_in);
-	ubi_close(&ulib);
+	libubi_close(ulib);
 	return rc;
 }
 
@@ -357,25 +365,28 @@
 static int
 ubi_write_bootenv(uint32_t devno, uint32_t id, bootenv_t env)
 {
-	ubi_lib_t ulib = NULL;
+	libubi_t ulib;
 	int rc = 0;
-	FILE* fp_out;
+	char path[PATH_MAX];
+	FILE* fp_out = NULL;
 	size_t nbytes ;
 
 	rc = bootenv_size(env, &nbytes);
-	if( rc ){
+	if (rc) {
 		err_msg("Cannot determine size of bootenv structure\n");
 		return rc;
 	}
-	rc = ubi_open(&ulib);
-	if( rc ){
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		err_msg("Cannot allocate ubi structure\n");
 		return rc;
 	}
-	fp_out = ubi_vol_fopen_update(ulib, devno, id,
-			(unsigned long long)nbytes);
+
+	snprintf(path, PATH_MAX, DEFAULT_VOL_PATTERN, devno, id);
+
+	fp_out = fopen(path, "r+");
 	if (fp_out == NULL) {
-		err_msg("Cannot open volume:%d number:%d\n", devno, id);
+		err_msg("Cannot fopen volume:%d number:%d\n", devno, id);
 		goto err;
 	}
 
@@ -389,7 +400,7 @@
 err:
 	if( fp_out )
 		fclose(fp_out);
-	ubi_close(&ulib);
+	libubi_close(ulib);
 	return rc;
 }
 

  reply	other threads:[~2007-10-02 12:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-02 12:16 [PATCH 0/4 try3] ubi-utils: migrate to new libubi Alexander Schmidt
2007-10-02 12:17 ` Alexander Schmidt [this message]
2007-10-02 12:18 ` [PATCH 2/4 try3] ubi-utils: migrate ubimirror Alexander Schmidt
2007-10-02 12:19 ` [PATCH 3/4 try3] ubi-utils: migrate pfiflash Alexander Schmidt
2007-10-02 12:19 ` [PATCH 4/4 try3] ubi-utils: remove libubiold Alexander Schmidt
2007-10-03  5:49 ` [PATCH 0/4 try3] ubi-utils: migrate to new libubi Artem Bityutskiy

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=200710021417.40075.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox