[PATCH 2/5] ubi-utils: migrate pddcustomize

Alexander Schmidt alexs at linux.vnet.ibm.com
Fri Jul 27 11:29:28 EDT 2007


Migrate pddcustomize to the new libubi.

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

--- mtd-utils.orig/ubi-utils/Makefile
+++ mtd-utils/ubi-utils/Makefile
@@ -49,7 +49,7 @@ ubirmvol: ubirmvol.o error.o libubi.o
 	$(CC) $(LDFLAGS) -o $@ $^
 
 pddcustomize: pddcustomize.o error.o libubimirror.o bootenv.o hashmap.o \
-		libubiold.o libubiold_sysfs.o crc32.o
+		libubi.o libubi_common.o crc32.o
 	$(CC) $(LDFLAGS) -o $@ $^
 
 pfiflash: pfiflash.o libpfiflash.o list.o reader.o error.o libubimirror.o \
--- mtd-utils.orig/ubi-utils/src/pddcustomize.c
+++ mtd-utils/ubi-utils/src/pddcustomize.c
@@ -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>
@@ -35,16 +36,18 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <mtd/ubi-header.h>
 
 #include "config.h"
 #include "bootenv.h"
 #include "error.h"
 #include "example_ubi.h"
-#include "libubiold.h"
+#include "libubi.h"
+#include "libubi_common.h"
 #include "ubimirror.h"
 
-#define PROGRAM_VERSION "1.4"
+#define PROGRAM_VERSION "1.5"
 
 typedef enum action_t {
 	ACT_NORMAL   = 0,
@@ -301,17 +304,17 @@ err:
 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;
 	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);
+	fp_in = ubi_vol_fopen_read(devno, id);
 	if (fp_in == NULL) {
 		err_msg("Cannot open volume:%d number:%d\n", devno, id);
 		goto err;
@@ -326,7 +329,7 @@ ubi_read_bootenv(uint32_t devno, uint32_
 err:
 	if( fp_in )
 		fclose(fp_in);
-	ubi_close(&ulib);
+	libubi_close(ulib);
 	return rc;
 }
 
@@ -359,27 +362,32 @@ err:
 static int
 ubi_write_bootenv(uint32_t devno, uint32_t id, bootenv_t env)
 {
-	ubi_lib_t ulib = NULL;
-	int rc = 0;
-	FILE* fp_out;
+	libubi_t ulib;
+	int fd_out, rc = 0;
+	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);
-	if (fp_out == NULL) {
+
+	fd_out = ubi_vol_open(devno, id, O_RDWR);
+	if (fd_out < 0) {
 		err_msg("Cannot open volume:%d number:%d\n", devno, id);
 		goto err;
 	}
+	fp_out = fdopen(fd_out, "r+");
+	if (fp_out == NULL) {
+		err_msg("Cannot fdopen volume:%d number:%d\n", devno, id);
+		goto err;
+	}
 
 	rc = bootenv_write(fp_out, env);
 	if (rc != 0) {
@@ -391,7 +399,7 @@ ubi_write_bootenv(uint32_t devno, uint32
 err:
 	if( fp_out )
 		fclose(fp_out);
-	ubi_close(&ulib);
+	libubi_close(ulib);
 	return rc;
 }
 



More information about the linux-mtd mailing list