public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 0/5] ubi-utils: migrate to new libubi
@ 2007-07-27 15:23 Alexander Schmidt
  2007-07-27 15:28 ` [PATCH 1/5] ubi-utils: introduction of libubi_common Alexander Schmidt
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Alexander Schmidt @ 2007-07-27 15:23 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Frank Haverkamp, Andreas Arnez

This patchset migrates the remaining tools (pddcustomize, ubimirror and
pfiflash) to the new libubi. It also introduces a new libubi_common.c
file which contains some helper functions for the tools.

I've tested the new version with the scripts in ubi-utils/scripts/ubi_*
and everything works fine.

 mtd-utils.orig/ubi-utils/inc/libubiold.h       |  310 ----------
 mtd-utils.orig/ubi-utils/src/libubiold.c       |  768 -------------------------
 mtd-utils.orig/ubi-utils/src/libubiold_int.h   |  119 ---
 mtd-utils.orig/ubi-utils/src/libubiold_sysfs.c |  232 -------
 mtd-utils.orig/ubi-utils/src/libubiold_sysfs.h |  109 ---
 mtd-utils/ubi-utils/src/libubi_common.c        |   93 +++
 mtd-utils/ubi-utils/src/libubi_common.h        |   78 ++
 ubi-utils/Makefile                             |    6
 ubi-utils/src/libpfiflash.c                    |  132 ++--
 ubi-utils/src/libubimirror.c                   |   21
 ubi-utils/src/pddcustomize.c                   |   44 -
 ubi-utils/src/pfiflash.c                       |    3
 ubi-utils/src/ubimirror.c                      |    3
 13 files changed, 306 insertions(+), 1612 deletions(-)

Kind regards,
Alexander Schmidt

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] ubi-utils: introduction of libubi_common
  2007-07-27 15:23 [PATCH 0/5] ubi-utils: migrate to new libubi Alexander Schmidt
@ 2007-07-27 15:28 ` Alexander Schmidt
  2007-07-28 12:51   ` Artem Bityutskiy
  2007-07-27 15:29 ` [PATCH 2/5] ubi-utils: migrate pddcustomize Alexander Schmidt
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Alexander Schmidt @ 2007-07-27 15:28 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Frank Haverkamp, Andreas Arnez

libubi_common provides helper functions for ubi utils.

Signed-off-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
---
ubi-utils/src/libubi_common.c |   93 ++++++++++++++++++++++++++++++++++++++++++
ubi-utils/src/libubi_common.h |   78 +++++++++++++++++++++++++++++++++++
2 files changed, 171 insertions(+)

--- /dev/null
+++ mtd-utils/ubi-utils/src/libubi_common.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright International Business Machines Corp., 2007
+ *
+ * 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.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Alexander Schmidt
+ *
+ * This library provides helper functions for accessing UBI volumes.
+ * The paths to UBI device nodes is hardcoded, see below.
+ *
+ * 1.0 Initial commit
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define DEFAULT_DEV_PATTERN    "/dev/ubi%d"
+#define DEFAULT_VOL_PATTERN    "/dev/ubi%d_%d"
+
+#define MAXPATH          1024
+
+int ubi_vol_open(int devn, int vol_id, int flags)
+{
+	char path[MAXPATH];
+	int fd;
+
+	snprintf(path, MAXPATH, DEFAULT_VOL_PATTERN, devn, vol_id);
+
+	fd = open(path, flags);
+
+	return fd;
+}
+
+int ubi_vol_close(int vol_fd)
+{
+	return close(vol_fd);
+}
+
+FILE* ubi_vol_fopen_read(int devn, int vol_id)
+{
+	FILE *fp;
+	int fd;
+
+	fd = ubi_vol_open(devn, vol_id, O_RDONLY);
+	if (fd == -1)
+		return NULL;
+
+	fp = fdopen(fd, "r");
+	if (fp == NULL)
+		ubi_vol_close(fd);
+
+	return fp;
+}
+
+int ubi_get_cdev_path(int devn, char *buf, size_t buf_size)
+{
+	int rc;
+
+	if (buf == NULL)
+		return -EINVAL;
+
+	rc = snprintf(buf, buf_size, DEFAULT_DEV_PATTERN, devn);
+
+	return rc;
+}
+
+
+int ubi_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;
+}
--- /dev/null
+++ mtd-utils/ubi-utils/src/libubi_common.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright International Business Machines Corp., 2007
+ *
+ * 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.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Alexander Schmidt
+ *
+ * This library provides helper functions for accessing UBI volumes.
+ * The paths to UBI device nodes is hardcoded.
+ *
+ * 1.0 Initial commit
+ */
+
+
+/**
+ * ubi_vol_open - open a UBI volume
+ *
+ * @devn	Number of UBI device on which to open the volume
+ * @vol_id	Number of UBI device on which to open the volume
+ * @flags	Flags to pass to open()
+ *
+ * This function opens a UBI volume on a given UBI device.  It returns
+ * the file descriptor of the opened volume device.  In case of an
+ * error %-1 is returned and errno is set appropriately.
+ */
+int ubi_vol_open(int devn, int vol_id, int flags);
+
+/**
+ * ubi_vol_close - close a UBI volume
+ *
+ * @vol_fd	file descriptor of UBI volume to close
+ *
+ * This function closes the given UBI device.
+ */
+int ubi_vol_close(int vol_fd);
+
+/**
+ * ubi_vol_fopen_read - open a volume for reading, returning a FILE *
+ * @devn	UBI device number
+ * @vol_id	volume ID to read
+ *
+ * Opens a volume for reading.  Reading itself can then be performed
+ * with fread().  The stream can be closed with fclose().  Returns a
+ * stream on success, else NULL.
+ */
+FILE *
+ubi_vol_fopen_read(int devn, uint32_t vol_id);
+
+/**
+ * ubi_get_cdev_path - get a device path for a given device number
+ *
+ * @devn	UBI device number
+ * @buf		buffer for device path
+ * @buf_size	size of buffer
+ */
+int ubi_get_cdev_path(int devn, char *buf, size_t buf_size);
+
+/**
+ * ubi_vol_get_used_bytes - determine used bytes in a UBI volume
+ * @vol_fd	File descriptor of UBI volume
+ * @bytes	Pointer to result
+ *
+ * Returns 0 on success, else error.
+ */
+int ubi_vol_get_used_bytes(int vol_fd, unsigned long long *bytes);
+

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/5] ubi-utils: migrate pddcustomize
  2007-07-27 15:23 [PATCH 0/5] ubi-utils: migrate to new libubi Alexander Schmidt
  2007-07-27 15:28 ` [PATCH 1/5] ubi-utils: introduction of libubi_common Alexander Schmidt
@ 2007-07-27 15:29 ` Alexander Schmidt
  2007-07-27 15:30 ` [PATCH 3/5] ubi-utils: migrate ubimirror Alexander Schmidt
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Alexander Schmidt @ 2007-07-27 15:29 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Frank Haverkamp, Andreas Arnez

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 |   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;
 }
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/5] ubi-utils: migrate ubimirror
  2007-07-27 15:23 [PATCH 0/5] ubi-utils: migrate to new libubi Alexander Schmidt
  2007-07-27 15:28 ` [PATCH 1/5] ubi-utils: introduction of libubi_common Alexander Schmidt
  2007-07-27 15:29 ` [PATCH 2/5] ubi-utils: migrate pddcustomize Alexander Schmidt
@ 2007-07-27 15:30 ` Alexander Schmidt
  2007-07-27 15:31 ` [PATCH 4/5] ubi-utils: migrate pfiflash Alexander Schmidt
  2007-07-27 15:31 ` [PATCH 5/5] ubi-utils: remove dead code Alexander Schmidt
  4 siblings, 0 replies; 9+ messages in thread
From: Alexander Schmidt @ 2007-07-27 15:30 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Frank Haverkamp, Andreas Arnez

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 |   21 +++++++++++----------
 ubi-utils/src/ubimirror.c    |    3 ++-
 3 files changed, 14 insertions(+), 12 deletions(-)

--- mtd-utils.orig/ubi-utils/Makefile
+++ mtd-utils/ubi-utils/Makefile
@@ -57,7 +57,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 libubi_common.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,7 +22,8 @@
 #include <memory.h>
 #include <fcntl.h>
 
-#include <libubiold.h>
+#include <libubi.h>
+#include <libubi_common.h>
 #include "ubimirror.h"
 
 #define COMPARE_BUF_SIZE    (128 * 1024)
@@ -125,14 +126,14 @@ static int compare_files(int fd_a, int f
 	return rc;
 }
 
-static int copy_files(int fd_in, int fd_out)
+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)
+	    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 +153,7 @@ int ubimirror(uint32_t devno, int seqnum
 {
 	int rc = 0;
 	uint32_t src_id;
-	ubi_lib_t ulib = NULL;
+	libubi_t ulib;
 	int fd_in = -1, i = 0, fd_out = -1;
 
 	if (ids_size == 0)
@@ -165,11 +166,11 @@ 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);
+	fd_in = ubi_vol_open(devno, src_id, O_RDONLY);
 	if (fd_in == -1) {
 		EBUF("open error source volume %d", ids[i]);
 		rc = open_error;
@@ -180,7 +181,7 @@ 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);
+		fd_out = ubi_vol_open(devno, ids[i], O_RDWR);
 		if (fd_out == -1){
 			EBUF("open error destination volume %d", ids[i]);
 			rc = open_error;
@@ -191,7 +192,7 @@ 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]);
@@ -211,6 +212,6 @@ err:
 	if (fd_in != -1)
 		ubi_vol_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,

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/5] ubi-utils: migrate pfiflash
  2007-07-27 15:23 [PATCH 0/5] ubi-utils: migrate to new libubi Alexander Schmidt
                   ` (2 preceding siblings ...)
  2007-07-27 15:30 ` [PATCH 3/5] ubi-utils: migrate ubimirror Alexander Schmidt
@ 2007-07-27 15:31 ` Alexander Schmidt
  2007-07-27 15:31 ` [PATCH 5/5] ubi-utils: remove dead code Alexander Schmidt
  4 siblings, 0 replies; 9+ messages in thread
From: Alexander Schmidt @ 2007-07-27 15:31 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Frank Haverkamp, Andreas Arnez

Migrate pfiflash to the new libubi.

Signed-off-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
---
 ubi-utils/Makefile          |    2 
 ubi-utils/src/libpfiflash.c |  132 ++++++++++++++++++++++++++++++--------------
 ubi-utils/src/pfiflash.c    |    3 -
 3 files changed, 94 insertions(+), 43 deletions(-)

--- mtd-utils.orig/ubi-utils/Makefile
+++ mtd-utils/ubi-utils/Makefile
@@ -53,7 +53,7 @@ pddcustomize: pddcustomize.o error.o lib
 	$(CC) $(LDFLAGS) -o $@ $^
 
 pfiflash: pfiflash.o libpfiflash.o list.o reader.o error.o libubimirror.o \
-		bootenv.o hashmap.o pfi.o libubiold.o libubiold_sysfs.o crc32.o
+		bootenv.o hashmap.o pfi.o libubi.o libubi_common.o crc32.o
 	$(CC) $(LDFLAGS) -o $@ $^
 
 ubimirror: ubimirror.o error.o libubimirror.o bootenv.o hashmap.o \
--- mtd-utils.orig/ubi-utils/src/libpfiflash.c
+++ mtd-utils/ubi-utils/src/libpfiflash.c
@@ -36,7 +36,8 @@
 #include <stdlib.h>
 #include <sys/ioctl.h>
 
-#include <libubiold.h>
+#include <libubi.h>
+#include <libubi_common.h>
 #include <pfiflash.h>
 
 #include <mtd/ubi-user.h>	/* FIXME Is this ok here? */
@@ -56,6 +57,7 @@
 #define __unused __attribute__((unused))
 
 #define COMPARE_BUFFER_SIZE 2048
+#define MAXPATH             1024
 
 static const char copyright [] __unused =
 	"Copyright International Business Machines Corp., 2006, 2007";
@@ -153,7 +155,9 @@ my_ubi_mkvol(int devno, int s, pfi_ubi_t
 	     char *err_buf, size_t err_buf_size)
 {
 	int rc, type;
-	ubi_lib_t ulib;
+	char path[MAXPATH];
+	libubi_t ulib;
+	struct ubi_mkvol_request req;
 
 	rc = 0;
 	ulib = NULL;
@@ -163,8 +167,8 @@ my_ubi_mkvol(int devno, int s, pfi_ubi_t
 		u->ids[s], u->size, u->data_size, u->type, u->alignment,
 		strnlen(u->names[s], PFI_UBI_VOL_NAME_LEN), u->names[s]);
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc]);
 		goto err;
@@ -178,8 +182,20 @@ my_ubi_mkvol(int devno, int s, pfi_ubi_t
 		type = UBI_DYNAMIC_VOLUME;
 	}
 
-	rc = ubi_mkvol(ulib, devno, u->ids[s], type, u->size, u->alignment,
-		       u->names[s]);
+	rc = ubi_get_cdev_path(devno, path, MAXPATH);
+	if (rc < 0) {
+		rc = -PFIFLASH_ERR_UBI_MKVOL;
+		EBUF(PFIFLASH_ERRSTR[-rc], u->ids[s]);
+		goto err;
+	}
+
+	req.vol_id = u->ids[s];
+	req.alignment = u->alignment;
+	req.bytes = u->size;
+	req.vol_type = type;
+	req.name = u->names[s];
+
+	rc = ubi_mkvol(ulib, path, &req);
 	if (rc != 0) {
 		rc = -PFIFLASH_ERR_UBI_MKVOL;
 		EBUF(PFIFLASH_ERRSTR[-rc], u->ids[s]);
@@ -188,7 +204,7 @@ my_ubi_mkvol(int devno, int s, pfi_ubi_t
 
  err:
 	if (ulib != NULL)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 
 	return rc;
 }
@@ -214,26 +230,29 @@ my_ubi_rmvol(int devno, uint32_t id,
 	     char *err_buf, size_t err_buf_size)
 {
 	int rc, fd;
-	ubi_lib_t ulib;
+	char path[MAXPATH];
+	libubi_t ulib;
 
 	rc = 0;
 	ulib = NULL;
 
 	log_msg("[ ubirmvol id=%d", id);
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc]);
 		goto err;
 	}
 
 	/* truncate whether it exist or not */
-	fd = ubi_vol_open(ulib, devno, id, O_RDWR);
-	if (fd == -1)
+	fd = ubi_vol_open(devno, id, O_RDWR);
+	if (fd < 0) {
+		libubi_close(ulib);
 		return 0;	/* not existent, return 0 */
+	}
 
-	rc = ubi_vol_update(fd, 0);
+	rc = ubi_update_start(ulib, fd, 0);
 	ubi_vol_close(fd);
 	if (rc < 0) {
 		rc = -PFIFLASH_ERR_UBI_VOL_UPDATE;
@@ -241,7 +260,14 @@ my_ubi_rmvol(int devno, uint32_t id,
 		goto err;	/* if EBUSY than empty device, continue */
 	}
 
-	rc = ubi_rmvol(ulib, devno, id);
+	rc = ubi_get_cdev_path(devno, path, MAXPATH);
+	if (rc < 0) {
+		rc = -PFIFLASH_ERR_UBI_RMVOL;
+		EBUF(PFIFLASH_ERRSTR[-rc], id);
+		goto err;
+	}
+
+	rc = ubi_rmvol(ulib, path, id);
 	if (rc != 0) {
 #ifdef DEBUG
 		int rc_old = rc;
@@ -266,7 +292,7 @@ my_ubi_rmvol(int devno, uint32_t id,
 
  err:
 	if (ulib != NULL)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 
 	return rc;
 }
@@ -292,20 +318,20 @@ read_bootenv_volume(int devno, uint32_t 
 {
 	int rc;
 	FILE* fp_in;
-	ubi_lib_t ulib;
+	libubi_t ulib;
 
 	rc = 0;
 	fp_in = NULL;
 	ulib = NULL;
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc]);
 		goto err;
 	}
 
-	fp_in = ubi_vol_fopen_read(ulib, devno, id);
+	fp_in = ubi_vol_fopen_read(devno, id);
 	if (!fp_in) {
 		rc = -PFIFLASH_ERR_UBI_VOL_FOPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc], id);
@@ -326,7 +352,7 @@ read_bootenv_volume(int devno, uint32_t 
 	if (fp_in)
 		fclose(fp_in);
 	if (ulib)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 
 	return rc;
 }
@@ -366,12 +392,12 @@ write_bootenv_volume(int devno, uint32_t
 		     uint32_t pfi_crc,
 		     char *err_buf, size_t err_buf_size)
 {
-	int rc, warnings;
+	int rc, warnings, fd_out;
 	uint32_t crc;
 	size_t update_size;
 	FILE *fp_out;
 	bootenv_t bootenv_new, bootenv_res;
-	ubi_lib_t ulib;
+	libubi_t ulib;
 
 	rc = 0;
 	warnings = 0;
@@ -393,8 +419,8 @@ write_bootenv_volume(int devno, uint32_t
 	 * 4. Write to FILE*
 	 */
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc]);
 		goto err;
@@ -443,12 +469,24 @@ write_bootenv_volume(int devno, uint32_t
 		goto err;
 	}
 
-	fp_out = ubi_vol_fopen_update(ulib, devno, id, update_size);
+	fd_out = ubi_vol_open(devno, id, O_RDWR);
+	if (fd_out < 0) {
+		rc = -PFIFLASH_ERR_UBI_VOL_FOPEN;
+		EBUF(PFIFLASH_ERRSTR[-rc], id);
+		goto err;
+	}
+	fp_out = fdopen(fd_out, "r+");
 	if (!fp_out) {
 		rc = -PFIFLASH_ERR_UBI_VOL_FOPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc], id);
 		goto err;
 	}
+	rc = ubi_update_start(ulib, fd_out, update_size);
+	if (rc < 0) {
+		rc = -PFIFLASH_ERR_UBI_VOL_UPDATE;
+		EBUF(PFIFLASH_ERRSTR[-rc], id);
+		goto err;
+	}
 
 	rc = bootenv_write(fp_out, bootenv_res);
 	if (rc != 0) {
@@ -459,7 +497,7 @@ write_bootenv_volume(int devno, uint32_t
 
  err:
 	if (ulib != NULL)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 	if (bootenv_new != NULL)
 		bootenv_destroy(&bootenv_new);
 	if (bootenv_res != NULL)
@@ -496,11 +534,11 @@ write_normal_volume(int devno, uint32_t 
 		    uint32_t pfi_crc,
 		    char *err_buf, size_t err_buf_size)
 {
-	int rc;
+	int rc, fd_out;
 	uint32_t crc, crc32_table[256];
 	size_t bytes_left;
 	FILE* fp_out;
-	ubi_lib_t ulib;
+	libubi_t ulib;
 
 	rc = 0;
 	crc = UBI_CRC32_INIT;
@@ -511,19 +549,31 @@ write_normal_volume(int devno, uint32_t 
 	log_msg("[ ubiupdatevol id=%d, update_size=%d fp_in=%p",
 		id, update_size, fp_in);
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc]);
 		goto err;
 	}
 
-	fp_out = ubi_vol_fopen_update(ulib, devno, id, update_size);
+	fd_out = ubi_vol_open(devno, id, O_RDWR);
+	if (fd_out < 0) {
+		rc = -PFIFLASH_ERR_UBI_VOL_FOPEN;
+		EBUF(PFIFLASH_ERRSTR[-rc], id);
+		goto err;
+	}
+	fp_out = fdopen(fd_out, "r+");
 	if (!fp_out) {
 		rc = -PFIFLASH_ERR_UBI_VOL_FOPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc], id);
 		goto err;
 	}
+	rc = ubi_update_start(ulib, fd_out, update_size);
+	if (rc < 0) {
+		rc = -PFIFLASH_ERR_UBI_VOL_UPDATE;
+		EBUF(PFIFLASH_ERRSTR[-rc], id);
+		goto err;
+	}
 
 	init_crc32_table(crc32_table);
 	while (bytes_left) {
@@ -554,7 +604,7 @@ write_normal_volume(int devno, uint32_t 
 	if (fp_out)
 		fclose(fp_out);
 	if (ulib)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 
 	return rc;
 }
@@ -684,11 +734,11 @@ static int compare_volumes(int devno, pf
 {
 	int rc, is_bootenv = 0;
 	unsigned int i;
-	ubi_lib_t ulib = NULL;
+	libubi_t ulib = NULL;
 	FILE *fp_flash[u->ids_size];
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		goto err;
 	}
@@ -698,7 +748,7 @@ static int compare_volumes(int devno, pf
 		    u->ids[i] == EXAMPLE_BOOTENV_VOL_ID_2)
 			is_bootenv = 1;
 
-		fp_flash[i] = ubi_vol_fopen_read(ulib, devno, u->ids[i]);
+		fp_flash[i] = ubi_vol_fopen_read(devno, u->ids[i]);
 		if (fp_flash[i] == NULL) {
 			rc = -PFIFLASH_ERR_UBI_OPEN;
 			goto err;
@@ -718,7 +768,7 @@ err:
 	for (i = 0; i < u->ids_size; i++)
 		fclose(fp_flash[i]);
 	if (ulib)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 
 	return rc;
 }
@@ -1070,15 +1120,15 @@ mirror_ubi_volumes(uint32_t devno, list_
 	uint32_t j;
 	list_t ptr;
 	pfi_ubi_t i;
-	ubi_lib_t ulib;
+	libubi_t ulib;
 
 	rc = 0;
 	ulib = NULL;
 
 	log_msg("[ mirror ...");
 
-	rc = ubi_open(&ulib);
-	if (rc != 0) {
+	ulib = libubi_open();
+	if (ulib == NULL) {
 		rc = -PFIFLASH_ERR_UBI_OPEN;
 		EBUF(PFIFLASH_ERRSTR[-rc]);
 		goto err;
@@ -1118,7 +1168,7 @@ mirror_ubi_volumes(uint32_t devno, list_
 
  err:
 	if (ulib != NULL)
-		ubi_close(&ulib);
+		libubi_close(ulib);
 
 	return rc;
 }
--- mtd-utils.orig/ubi-utils/src/pfiflash.c
+++ mtd-utils/ubi-utils/src/pfiflash.c
@@ -27,6 +27,7 @@
  * 1.3 removed argp parsing to be able to use uClib.
  * 1.4 Minor cleanups.
  * 1.5 Forgot to delete raw block before updating it.
+ * 1.6 Migrated to new libubi.
  */
 
 #include <unistd.h>
@@ -43,7 +44,7 @@
 #include "error.h"
 #include "config.h"
 
-#define PROGRAM_VERSION  "1.5"
+#define PROGRAM_VERSION  "1.6"
 
 static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on "
 	BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/5] ubi-utils: remove dead code
  2007-07-27 15:23 [PATCH 0/5] ubi-utils: migrate to new libubi Alexander Schmidt
                   ` (3 preceding siblings ...)
  2007-07-27 15:31 ` [PATCH 4/5] ubi-utils: migrate pfiflash Alexander Schmidt
@ 2007-07-27 15:31 ` Alexander Schmidt
  4 siblings, 0 replies; 9+ messages in thread
From: Alexander Schmidt @ 2007-07-27 15:31 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Frank Haverkamp, Andreas Arnez

Remove the old libubi.

Signed-off-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
---
 ubi-utils/inc/libubiold.h       |  310 ----------------
 ubi-utils/src/libubiold.c       |  768 ----------------------------------------
 ubi-utils/src/libubiold_int.h   |  119 ------
 ubi-utils/src/libubiold_sysfs.c |  232 ------------
 ubi-utils/src/libubiold_sysfs.h |  109 -----
 5 files changed, 1538 deletions(-)

--- mtd-utils.orig/ubi-utils/inc/libubiold.h
+++ /dev/null
@@ -1,310 +0,0 @@
-#ifndef __UBI_H__
-#define __UBI_H__
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * UBI (Unsorted Block Images) library.
- * @file	libubi.h
- * @author	Artem B. Bityutskiy
- * @author      Additions: Oliver Lohmann
- * @version	1.0
- */
-
-#include <stdint.h>
-#include <mtd/ubi-user.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @section eh Error Handling
- * The following error indication policy is used: in case of success, all
- * library functions return 0, in case of failure they either return UBI error
- * codes, or -1 if a system error occured; in the latter case the exact error
- * code has to be in the errno variable.
- *
- * @def UBI_ENOTFOUND
- *	@brief UBI was not found in the system.
- * @def UBI_EBUG
- *	@brief An error due to bug in kernel part of UBI in UBI library.
- * @def UBI_EINVAL
- *	@brief Invalid argument.
- * @def UBI_EMACS
- *	@brief Highest error value.
- */
-#define UBI_ENOTFOUND	1
-#define UBI_EBUG	2
-#define UBI_EINVAL	3
-#define UBI_EMAX	4
-
-
-/**
- * UBI library descriptor, vague for library users.
- */
-typedef struct ubi_lib *ubi_lib_t;
-
-/**
- * struct ubi_info - general information about UBI.
- *
- * @version    UBI version
- * @nlen_max   maximum length of names of volumes
- * @dev_count  count UBI devices in the system
- */
-struct ubi_info
-{
-	unsigned int version;
-	unsigned int nlen_max;
-	unsigned int dev_count;
-};
-
-/**
- * struct ubi_dev_info - information about an UBI device
- *
- * @wear       average number of erasures of flash erasable blocks
- * @major      major number of the corresponding character device
- * @minor      minor number of the corresponding character device
- * @eb_size    size of eraseblocks
- * @total_ebs  total count of eraseblocks
- * @avail_ebs  count of unused eraseblock available for new volumes
- * @vol_count  total count of volumes in this UBI device
- */
-struct ubi_dev_info
-{
-	unsigned long long wear;
-	unsigned int major;
-	unsigned int minor;
-	unsigned int eb_size;
-	unsigned int total_ebs;
-	unsigned int avail_ebs;
-	unsigned int vol_count;
-};
-
-/**
- * struct ubi_vol_info - information about an UBI volume
- *
- * @bytes        volume size in bytes
- * @eraseblocks  volume size in eraseblocks
- * @major        major number of the corresponding character device
- * @minor        minor number of the corresponding character device
- * @type         volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
- * @dev_path	 device path to volume
- * @name         volume name
- */
-struct ubi_vol_info
-{
-	unsigned long long bytes;
-	unsigned int eraseblocks;
-	unsigned int major;
-	unsigned int minor;
-	int type;
-	char *dev_path;
-	char *name;
-};
-
-/**
- * ubi_mkvol - create a dynamic UBI volume.
- *
- * @desc       UBI library descriptor
- * @devn       Number of UBI device to create new volume on
- * @vol_id     volume ID to assign to the new volume
- * @vol_type   volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
- * @bytes      volume size in bytes
- * @alignment  volume alignment
- * @name       volume name
- *
- * This function creates new UBI volume. If @vol_id is %UBI_VOLN_AUTO, then
- * volume number is assigned automatically. This function returns positive
- * volume number of the new volume in case of success or %-1 in case of
- * failure.
- */
-int ubi_mkvol(ubi_lib_t desc, int devn, int vol_id, int vol_type,
-	      long long bytes, int alignment, const char *name);
-
-/**
- * ubi_rmvol - remove a volume.
- *
- * @desc       UBI library descriptor
- * @devn       Number of UBI device to remove volume from
- * @vol_id     volume ID to remove
- *
- * This function returns zero in case of success or %-1 in case of failure.
- */
-int ubi_rmvol(ubi_lib_t desc, int devn, int vol_id);
-
-/**
- * ubi_get_info - get UBI information.
- *
- * @desc  UBI library descriptor
- * @ubi   UBI information is returned here
- *
- * This function retrieves information about UBI and puts it to @ubi. Returns
- * zero in case of success and %-1 in case of failure.
- */
-int ubi_get_info(ubi_lib_t desc, struct ubi_info *ubi);
-
-/**
- * ubi_vol_open - open a UBI volume
- *
- * @desc	UBI library descriptor
- * @devn	Number of UBI device on which to open the volume
- * @vol_id	Number of UBI device on which to open the volume
- * @flags	Flags to pass to open()
- *
- * This function opens a UBI volume on a given UBI device.  It returns
- * the file descriptor of the opened volume device.  In case of an
- * error %-1 is returned and errno is set appropriately.
- */
-int ubi_vol_open(ubi_lib_t desc, int devn, int vol_id, int flags);
-
-/**
- * ubi_vol_close - close a UBI volume
- *
- * @vol_fd	file descriptor of UBI volume to close
- *
- * This function closes the given UBI device.
- */
-int ubi_vol_close(int vol_fd);
-
-/**
- * ubi_vol_update - initiate volume update on a UBI volume
- * @vol_fd	File descriptor of UBI volume to update
- * @bytes	No. of bytes which shall be written.
- *
- * Initiates a volume update on a given volume.  The caller must then
- * actually write the appropriate number of bytes to the volume by
- * calling write().  Returns 0 on success, else error.
- */
-int ubi_vol_update(int vol_fd, unsigned long long bytes);
-
-/**
- * ubi_vol_fopen_read - open a volume for reading, returning a FILE *
- * @desc	UBI library descriptor
- * @devn	UBI device number
- * @vol_id	volume ID to read
- *
- * Opens a volume for reading.  Reading itself can then be performed
- * with fread().  The stream can be closed with fclose().  Returns a
- * stream on success, else NULL.
- */
-FILE *
-ubi_vol_fopen_read(ubi_lib_t desc, int devn, uint32_t vol_id);
-
-/**
- * ubi_vol_fopen_update - open a volume for writing, returning a FILE *
- * @desc	UBI library descriptor
- * @devn	UBI device number
- * @vol_id	volume ID to update
- * @bytes	No. of bytes which shall be written.
- *
- * Initiates a volume update on a given volume.  The caller must then
- * actually write the appropriate number of bytes to the volume by
- * calling fwrite().  The file can be closed with fclose().  Returns a
- * stream on success, else NULL.
- */
-FILE *
-ubi_vol_fopen_update(ubi_lib_t desc, int devn, uint32_t vol_id,
-		     unsigned long long bytes);
-
-/**
- * ubi_vol_get_used_bytes - determine used bytes in a UBI volume
- * @vol_fd	File descriptor of UBI volume
- * @bytes	Pointer to result
- *
- * Returns 0 on success, else error.
- */
-int ubi_vol_get_used_bytes(int vol_fd, unsigned long long *bytes);
-
-/**
- * ubi_open - open UBI library.
- *
- * @desc  A pointer to an UBI library descriptor
- *
- * Returns zero in case of success.
- */
-int ubi_open(ubi_lib_t *desc);
-
-/**
- * ubi_close - close UBI library.
- *
- * @desc  A pointer to an UBI library descriptor
- */
-int ubi_close(ubi_lib_t *desc);
-
-
-/**
- * ubi_perror - print UBI error.
- *
- * @prefix  a prefix string to prepend to the error message
- * @code    error code
- *
- * If @code is %-1, this function calls 'perror()'
- */
-void ubi_perror(const char *prefix, int code);
-
-/**
- * ubi_set_cdev_pattern - set 'sprintf()'-like pattern of paths to UBI
- * character devices.
- *
- * @desc     UBI library descriptor
- * @pattern  the pattern to set
- *
- * The default UBI character device path is "/dev/ubi%u".
- */
-int ubi_set_cdev_pattern(ubi_lib_t desc, const char *pattern);
-
-/**
- * ubi_get_dev_info get information about an UBI device.
- *
- * @desc  UBI library descriptor
- * @devn  UBI device number
- * @di    the requested information is returned here
- */
-int ubi_get_dev_info(ubi_lib_t desc, unsigned int devn,
-		struct ubi_dev_info *di);
-
-/**
- * ubi_set_vol_cdev_pattern - set 'sprintf()'-like pattµern ofpaths to UBI
- * volume character devices.
- *
- * @desc     UBI library descriptor
- * @pattern  the pattern to set
- *
- * The default UBI character device path is "/dev/ubi%u_%u".
- */
-int ubi_set_vol_cdev_pattern(ubi_lib_t desc, const char *pattern);
-
-/**
- * ubi_get_vol_info - get information about an UBI volume
- *
- * @desc  UBI library descriptor
- * @devn  UBI device number the volume belongs to
- * @vol_id  the requested volume number
- * @vi    volume information is returned here
- *
- * Users must free the volume name string @vi->name.
- */
-int ubi_get_vol_info(ubi_lib_t desc, unsigned int devn, unsigned int vol_id,
-		struct ubi_vol_info *vi);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !__UBI_H__ */
--- mtd-utils.orig/ubi-utils/src/libubiold.c
+++ /dev/null
@@ -1,768 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * UBI (Unsorted Block Images) library.
- *
- * Author: Artem B. Bityutskiy
- *         Oliver Lohmann
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <stdint.h>
-#include <mtd/ubi-user.h>
-#include <mtd/ubi-header.h>
-
-#include "libubiold.h"
-#include "libubiold_int.h"
-#include "libubiold_sysfs.h"
-
-/**
- * struct ubi_lib - UBI library descriptor.
- *
- * @ubi		    general UBI information
- *
- * @sysfs_root	    sysfs root directory
- * @ubi_root	    UBI root directory in sysfs
- *
- * @version	    full path to the "UBI version" sysfs file
- *
- * @cdev_path	    path pattern to UBI character devices
- * @cdev_path_len   maximum length of the @cdev_path string after substitution
- * @udev_path	    path to sysfs directories corresponding to UBI devices
- * @wear_path	    path to sysfs file containing UBI wear information
- * @vol_count_path  path to sysfs file containing the number of volumes in an
- *		    UBI device
- * @tot_ebs_path    path to sysfs file containing the total number of
- *		    eraseblock on an UBI device
- * @avail_ebs_path  path to sysfs file containing the number of unused
- *		    eraseblocks on an UBI device, available for new volumes
- * @eb_size_path    path to sysfs file containing size of UBI eraseblocks
- * @nums_path	    path to sysfs file containing major and minor number of an
- *		    UBI device
- * @vol_cdev_path   path to UBI volume character devices
- * @vdev_path	    path to sysfs directories corresponding to UBI volume
- *		    devices
- * @vol_nums_path   path to sysfs file containing major and minor number of an
- *		    UBI volume device
- * @vol_bytes_path  path to sysfs file containing size of an UBI volume device
- *		    in bytes
- * @vol_ebs_path    path to sysfs file containing the number of eraseblocks in
- *		    an UBI volume device
- * @vol_type_path   path to sysfs file containing type of an UBI volume
- * @vol_name_path   @FIXME: Describe me.
- *
- * This structure is created and initialized by 'ubi_init()' and is passed to
- * all UBI library calls.
- */
-struct ubi_lib
-{
-	struct ubi_info ubi;
-
-	char *sysfs_root;
-	char *ubi_root;
-
-	char *version;
-	char *cdev_path;
-	int  cdev_path_len;
-	char *udev_path;
-	char *wear_path;
-	char *vol_count_path;
-	char *tot_ebs_path;
-	char *avail_ebs_path;
-	char *eb_size_path;
-	char *nums_path;
-	int  vol_cdev_path_len;
-	char *vol_cdev_path;
-	char *vdev_path;
-	char *vol_nums_path;
-	char *vol_bytes_path;
-	char *vol_ebs_path;
-	char *vol_type_path;
-	char *vol_name_path;
-};
-
-
-/**
- * mkpath - compose full path from 2 given components.
- *
- * @path  first component @name	 second component
- *
- * Returns the resulting path in case of success and %NULL in case of failure.
- * Callers have to take care the resulting path is freed.
- */
-static char*
-mkpath(const char *path, const char *name)
-{
-	char *n;
-	int len1 = strlen(path);
-	int len2 = strlen(name);
-
-	n = malloc(len1 + len2 + 2);
-	if (!n)
-		return NULL;
-
-	memcpy(n, path, len1);
-	if (n[len1 - 1] != '/')
-		n[len1++] = '/';
-
-	memcpy(n + len1, name, len2 + 1);
-	return n;
-}
-
-
-static int
-get_ubi_info(ubi_lib_t desc, struct ubi_info *ubi)
-{
-	int err;
-	int dev_count = 0;
-	char *path;
-	struct stat stat;
-
-	err = sysfs_read_int(desc->version, (int*) &ubi->version);
-	if (err)
-		return -1;
-
-	/* Calculate number of UBI devices */
-	while (!err) {
-		char dir[20];
-
-		sprintf(&dir[0], "ubi%d", dev_count);
-		path = mkpath(desc->ubi_root, dir);
-		if (!path)
-			return ENOMEM;
-
-		err = lstat(path, &stat);
-		if (err == 0)
-			dev_count += 1;
-		free(path);
-	}
-
-	if (errno != ENOENT)
-		return -1;
-
-	if (dev_count == 0) {
-		ubi_err("no UBI devices found");
-		errno = EINVAL;
-		return -1;
-	}
-
-	errno = 0;
-	ubi->dev_count = dev_count;
-	return 0;
-}
-
-void
-ubi_dump_handler(ubi_lib_t desc)
-{
-	ubi_lib_t d = desc;
-	printf(	"UBI Library Descriptor:\n"
-		"ubi_root:	 %s\n"
-		"version:	 %s\n"
-		"cdev_path:	 %s\n"
-		"udev_path:	 %s\n"
-		"wear_path:	 %s\n"
-		"vol_count_path: %s\n"
-		"tot_ebs_path:	 %s\n"
-		"avail_ebs_path: %s\n"
-		"eb_size_path:	 %s\n"
-		"nums_path:	 %s\n"
-		"vol_cdev_path:	 %s\n"
-		"vdev_path:	 %s\n"
-		"vol_nums_path:	 %s\n"
-		"vol_bytes_path: %s\n"
-		"vol_ebs_path:	 %s\n"
-		"vol_type_path:	 %s\n"
-		"vol_name_path:	 %s\n"
-		"cdev_path_len:	 %d\n\n",
-	       d->ubi_root, d->version, d->cdev_path, d->udev_path,
-	       d->wear_path, d->vol_count_path, d->tot_ebs_path,
-	       d->avail_ebs_path, d->eb_size_path, d->nums_path,
-	       d->vol_cdev_path, d->vdev_path, d->vol_nums_path,
-	       d->vol_bytes_path, d->vol_ebs_path, d->vol_type_path,
-	       d->vol_name_path, d->cdev_path_len);
-}
-
-int
-ubi_set_cdev_pattern(ubi_lib_t desc, const char *pattern)
-{
-	char *patt;
-
-	patt = strdup(pattern);
-	if (!patt) {
-		ubi_err("cannot allocate memory");
-		return -1;
-	}
-
-	if (desc->cdev_path)
-		free(desc->cdev_path);
-
-	desc->cdev_path = patt;
-	desc->cdev_path_len = strlen(patt) + 1 + UBI_MAX_ID_SIZE;
-
-	ubi_dbg("ubi dev pattern is now \"%s\"", patt);
-
-	return 0;
-}
-
-int
-ubi_set_vol_cdev_pattern(ubi_lib_t desc, const char *pattern)
-{
-	char *patt;
-
-	patt = strdup(pattern);
-	if (!patt) {
-		ubi_err("cannot allocate memory");
-		return -1;
-	}
-
-	free(desc->vol_cdev_path);
-	desc->vol_cdev_path = patt;
-	desc->vol_cdev_path_len = strlen(patt) + 1 + 2 * UBI_MAX_ID_SIZE;
-
-	ubi_dbg("ubi volume dev pattern is now \"%s\"", patt);
-
-	return 0;
-}
-
-int
-ubi_open(ubi_lib_t *desc)
-{
-	int err = -1;
-	ubi_lib_t res;
-	struct stat stat;
-
-	res = calloc(1, sizeof(struct ubi_lib));
-	if (!res) {
-		ubi_err("cannot allocate memory");
-		return -1;
-	}
-
-	res->cdev_path = NULL;
-	err = ubi_set_cdev_pattern(res, UBI_CDEV_PATH);
-	if (err)
-		goto error;
-
-	/* TODO: this actually has to be discovered */
-	res->sysfs_root = strdup(UBI_SYSFS_ROOT);
-	if (!res->sysfs_root)
-		goto error;
-
-	res->ubi_root = mkpath(res->sysfs_root, UBI_ROOT);
-	if (!res->ubi_root)
-		goto error;
-
-	res->version =	mkpath(res->ubi_root, UBI_VER);
-	if (!res->version)
-		goto error;
-
-	res->udev_path = mkpath(res->ubi_root, "ubi%d/");
-	if (!res->udev_path)
-		goto error;
-
-	res->wear_path = mkpath(res->udev_path, UBI_WEAR);
-	if (!res->wear_path)
-		goto error;
-
-	res->vol_count_path = mkpath(res->udev_path, UBI_VOL_COUNT);
-	if (!res->vol_count_path)
-		goto error;
-
-	res->tot_ebs_path = mkpath(res->udev_path, UBI_AVAIL_EBS);
-	if (!res->tot_ebs_path)
-		goto error;
-
-	res->avail_ebs_path = mkpath(res->udev_path, UBI_TOT_EBS);
-	if (!res->avail_ebs_path)
-		goto error;
-
-	res->eb_size_path = mkpath(res->udev_path, UBI_EB_SIZE);
-	if (!res->eb_size_path)
-		goto error;
-
-	res->nums_path = mkpath(res->udev_path, UBI_NUMS);
-	if (!res->nums_path)
-		goto error;
-
-	err = ubi_set_vol_cdev_pattern(res, UBI_VOL_CDEV_PATH);
-	if (err)
-		goto error;
-
-	res->vdev_path = mkpath(res->ubi_root, "ubi%d_%d/");
-	if (!res->vdev_path)
-		goto error;
-
-	res->vol_nums_path = mkpath(res->vdev_path, UBI_NUMS);
-	if (!res->vol_nums_path)
-		goto error;
-
-	res->vol_bytes_path = mkpath(res->vdev_path, UBI_VBYTES);
-	if (!res->vol_bytes_path)
-		goto error;
-
-	res->vol_ebs_path = mkpath(res->vdev_path, UBI_VEBS);
-	if (!res->vol_ebs_path)
-		goto error;
-
-	res->vol_type_path = mkpath(res->vdev_path, UBI_VTYPE);
-	if (!res->vol_type_path)
-		goto error;
-
-	res->vol_name_path = mkpath(res->vdev_path, UBI_VNAME);
-	if (!res->vol_name_path)
-		goto error;
-
-	/* Check if UBI exists in the system */
-	err = lstat(res->ubi_root, &stat);
-	if (err) {
-		perror("lstat");
-		fprintf(stderr, "%s\n", res->ubi_root);
-		err = UBI_ENOTFOUND;
-		goto error;
-	}
-
-	err = get_ubi_info(res, &res->ubi);
-	if (err)
-		goto error;
-
-	*desc = res;
-
-	ubi_dbg("opened library successfully.");
-
-	return 0;
-
-error:
-	ubi_close(&res);
-
-	if (err == -1 && errno == ENOMEM)
-		ubi_err("Cannot allocate memory");
-
-	return err;
-}
-
-int
-ubi_close(ubi_lib_t *desc)
-{
-	ubi_lib_t tmp = *desc;
-
-	free(tmp->vol_name_path);
-	free(tmp->vol_type_path);
-	free(tmp->vol_ebs_path);
-	free(tmp->vol_bytes_path);
-	free(tmp->vol_nums_path);
-	free(tmp->vdev_path);
-	free(tmp->vol_cdev_path);
-	free(tmp->nums_path);
-	free(tmp->eb_size_path);
-	free(tmp->avail_ebs_path);
-	free(tmp->tot_ebs_path);
-	free(tmp->vol_count_path);
-	free(tmp->wear_path);
-	free(tmp->udev_path);
-	free(tmp->cdev_path);
-	free(tmp->version);
-	free(tmp->ubi_root);
-	free(tmp->sysfs_root);
-	free(tmp);
-
-	*desc = NULL;
-
-	return 0;
-}
-
-void
-ubi_perror(const char *prefix, int code)
-{
-	if (code == 0)
-		return;
-
-	fprintf(stderr, "%s: ", prefix);
-
-	switch (code) {
-	case UBI_ENOTFOUND:
-		fprintf(stderr, "UBI was not found in system\n");
-		break;
-	case UBI_EBUG:
-		fprintf(stderr, "an UBI or UBI library bug\n");
-		break;
-	case UBI_EINVAL:
-		fprintf(stderr, "invalid parameter\n");
-		break;
-	case -1:
-		perror(prefix);
-		break;
-	default:
-		ubi_err("unknown error code %d", code);
-		break;
-	}
-}
-
-int
-ubi_get_dev_info(ubi_lib_t desc, unsigned int devn, struct ubi_dev_info *di)
-{
-	int err;
-
-	if (devn >= desc->ubi.dev_count) {
-		ubi_err("bad device number, max is %d\n",
-			desc->ubi.dev_count - 1);
-		return UBI_EINVAL;
-	}
-
-	err = sysfs_read_dev_subst(desc->nums_path, &di->major,
-				   &di->minor, 1, devn);
-	if (err)
-		return -1;
-
-	err = sysfs_read_ull_subst(desc->wear_path, &di->wear, 1, devn);
-	if (err)
-		return -1;
-
-	err = sysfs_read_uint_subst(desc->vol_count_path,
-				    &di->vol_count, 1, devn);
-	if (err)
-		return -1;
-
-	err = sysfs_read_uint_subst(desc->eb_size_path, &di->eb_size, 1, devn);
-	if (err)
-		return -1;
-
-	err = sysfs_read_uint_subst(desc->tot_ebs_path, &di->total_ebs, 1, devn);
-	if (err)
-		return -1;
-
-	err = sysfs_read_uint_subst(desc->avail_ebs_path,
-				    &di->avail_ebs, 1, devn);
-	if (err)
-		return -1;
-
-#if 0
-	ubi_dbg("major:minor %d:%d, wear %llu, EB size %d, "
-		"vol. count %d, tot. EBs %d, avail. EBs %d",
-		di->major, di->minor, di->wear, di->eb_size,
-		di->vol_count, di->total_ebs, di->avail_ebs);
-#endif
-
-	return err;
-}
-
-int
-ubi_get_vol_info(ubi_lib_t desc, unsigned int devn, unsigned int vol_id,
-		struct ubi_vol_info *req)
-{
-	int err;
-	int len;
-	char buf1[10];
-	char buf2[UBI_MAX_VOLUME_NAME];
-
-	err = sysfs_read_dev_subst(desc->vol_nums_path, &req->major,
-				   &req->minor, 2, devn, vol_id);
-	if (err)
-		return -1;
-
-	err = sysfs_read_ull_subst(desc->vol_bytes_path,
-				   &req->bytes, 2, devn, vol_id);
-	if (err)
-		return -1;
-
-	err = sysfs_read_uint_subst(desc->vol_ebs_path,
-				    &req->eraseblocks, 2, devn, vol_id);
-	if (err)
-		return -1;
-
-	len = sysfs_read_data_subst(desc->vol_type_path, &buf1[0],
-				    10, 2,  devn, vol_id);
-	if (len == -1)
-		return -1;
-
-	if (buf1[len - 1] != '\n') {
-		ubi_err("bad volume type");
-		return UBI_EBUG;
-	}
-
-	if (!strncmp(&buf1[0], "static", sizeof("static") - 1)) {
-		req->type = UBI_STATIC_VOLUME;
-	} else if (!strncmp(&buf1[0], "dynamic", sizeof("dynamic") - 1)) {
-		req->type = UBI_DYNAMIC_VOLUME;
-	} else {
-		ubi_err("bad type %s", &buf1[0]);
-		return -1;
-	}
-
-	len = sysfs_read_data_subst(desc->vol_name_path, &buf2[0],
-				    UBI_MAX_VOLUME_NAME, 2,  devn, vol_id);
-	if (len == -1)
-		return -1;
-
-	if (buf2[len - 1] != '\n') {
-		ubi_err("bad volume name");
-		return UBI_EBUG;
-	}
-
-	req->name = malloc(len);
-	if (!req->name) {
-		ubi_err("cannot allocate memory");
-		return -1;
-	}
-
-	memcpy(req->name, &buf2[0], len - 1);
-	req->name[len - 1] = '\0';
-
-	return 0;
-}
-
-/**
- * ubi_cdev_open - open a UBI device
- *
- * @desc	UBI library descriptor
- * @devn	Number of UBI device to open
- * @flags	Flags to pass to open()
- *
- * This function opens a UBI device by number and returns a file
- * descriptor.  In case of an error %-1 is returned and errno is set
- * appropriately.
- */
-static int
-ubi_cdev_open(ubi_lib_t desc, int devn, int flags)
-{
-	char *buf;
-	int fd;
-
-	ubi_dbg("desc=%p, devn=%d, flags=%08x\n", desc, devn, flags);
-
-	if (desc == NULL) {
-		ubi_err("desc is NULL\n");
-		return -1;
-	}
-	if (desc->vol_cdev_path_len == 0) {
-		ubi_err("path_len == 0\n");
-		return -1;
-	}
-	buf = malloc(desc->cdev_path_len);
-
-	sprintf(buf, desc->cdev_path, devn);
-
-	fd = open(buf, flags);
-	if (fd == -1)
-		ubi_dbg("cannot open %s", buf);
-
-	free(buf);
-	return fd;
-}
-
-/**
- * ubi_cdev_close - close a UBI device
- *
- * @dev_fd	file descriptor of UBI device to close
- *
- * This function closes the given UBI device.
- */
-static int
-ubi_cdev_close(int dev_fd)
-{
-	return close(dev_fd);
-}
-
-/**
- * @size is now in bytes.
- */
-int
-ubi_mkvol(ubi_lib_t desc, int devn, int vol_id, int vol_type,
-	  long long bytes, int alignment, const char *name)
-{
-	int fd;
-	int err;
-	struct ubi_mkvol_req req;
-	size_t n;
-
-	n = strlen(name);
-	if (n > UBI_MAX_VOLUME_NAME)
-		return -1;
-
-	if ((fd = ubi_cdev_open(desc, devn, O_RDWR)) == -1)
-		return -1;
-
-	req.vol_id = vol_id;
-	req.bytes = bytes;
-	req.vol_type = vol_type;
-	req.alignment = alignment;
-
-	strncpy(req.name, name, UBI_MAX_VOLUME_NAME + 1);
-	req.name_len = n;
-
-	/* printf("DBG: %s(vol_id=%d, bytes=%lld, type=%d, alig=%d, nlen=%d, "
-	       "name=%s)\n", __func__, vol_id, bytes, vol_type, alignment,
-	       strlen(name), name);*/
-
-	err = ioctl(fd, UBI_IOCMKVOL, &req);
-	if (err < 0) {
-		ubi_err("ioctl returned %d errno=%d\n", err, errno);
-		goto out_close;
-	}
-
-	ubi_dbg("created volume %d, size %lld, name \"%s\" "
-		"at UBI dev %d\n", vol_id, bytes, name, devn);
-
-	close(fd);
-	return err;
- out_close:
-	ubi_cdev_close(fd);
-	return err;
-}
-
-int
-ubi_rmvol(ubi_lib_t desc, int devn, int vol_id)
-{
-	int fd;
-	int err;
-
-	if ((fd = ubi_cdev_open(desc, devn, O_RDWR)) == -1)
-		return -1;
-
-	err = ioctl(fd, UBI_IOCRMVOL, &vol_id);
-	if (err < 0)
-		goto out_close;
-
-	ubi_dbg("removed volume %d", vol_id);
-
- out_close:
-	ubi_cdev_close(fd);
-	return err;
-}
-
-int
-ubi_get_info(ubi_lib_t desc, struct ubi_info *ubi)
-{
-	memcpy(ubi, &desc->ubi, sizeof(struct ubi_info));
-	return 0;
-}
-
-
-int
-ubi_vol_open(ubi_lib_t desc, int devn, int vol_id, int flags)
-{
-	char *buf;
-	int fd;
-
-	ubi_dbg("desc=%p, devn=%d, vol_id=%d, flags=%08x\n",
-		desc, devn, vol_id, flags);
-
-	if (desc == NULL) {
-		ubi_err("desc is NULL\n");
-		return -1;
-	}
-	if (desc->vol_cdev_path_len == 0) {
-		ubi_err("path_len == 0\n");
-		return -1;
-	}
-	buf = malloc(desc->cdev_path_len);
-
-	sprintf(buf, desc->vol_cdev_path, devn, vol_id);
-
-	fd = open(buf, flags);
-	if (fd == -1)
-		ubi_dbg("cannot open %s", buf);
-
-	free(buf);
-	return fd;
-}
-
-int
-ubi_vol_close(int vol_fd)
-{
-	return close(vol_fd);
-}
-
-
-int
-ubi_vol_update(int vol_fd, unsigned long long bytes)
-{
-	int err;
-
-	err = ioctl(vol_fd, UBI_IOCVOLUP, &bytes);
-	if (err) {
-		ubi_err("%s failure calling update ioctl\n"
-			"    IOCTL(%08lx) err=%d errno=%d\n",
-			__func__, (long unsigned int)UBI_IOCVOLUP, err, errno);
-	}
-	return err;
-}
-
-FILE *
-ubi_vol_fopen_read(ubi_lib_t desc, int devn, uint32_t vol_id)
-{
-	FILE *fp;
-	int fd;
-
-	fd = ubi_vol_open(desc, devn, vol_id, O_RDONLY);
-	if (fd == -1)
-		return NULL;
-
-	fp = fdopen(fd, "r");
-	if (fp == NULL)
-		ubi_vol_close(fd);
-
-	return fp;
-}
-
-FILE *
-ubi_vol_fopen_update(ubi_lib_t desc, int devn, uint32_t vol_id,
-		     unsigned long long bytes)
-{
-	FILE *fp;
-	int fd;
-	int err;
-
-	fd = ubi_vol_open(desc, devn, vol_id, O_RDWR);
-	if (fd == -1)
-		return NULL;
-
-	fp = fdopen(fd, "r+");
-	if (fp == NULL) {
-		printf("DBG: %s(errno=%d)\n", __func__, errno);
-		ubi_vol_close(fd);
-		return NULL;
-	}
-	err = ubi_vol_update(fd, bytes);
-	if (err < 0) {
-		printf("DBG: %s() fd=%d err=%d\n", __func__, fd, err);
-		fclose(fp);
-		return NULL;
-	}
-	return fp;
-}
-
-int
-ubi_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;
-}
--- mtd-utils.orig/ubi-utils/src/libubiold_int.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * UBI (Unsorted Block Images) library.
- *
- * Author: Artem B. Bityutskiy
- */
-
-#ifndef __UBI_INT_H__
-#define __UBI_INT_H__
-/*
- * Enable/disable UBI library debugging messages.
- */
-#undef UBILIB_DEBUG
-
-/*
- * UBI library error message.
- */
-#define ubi_err(fmt, ...) do {						\
-		fprintf(stderr, "UBI Library Error at %s: ", __func__); \
-		fprintf(stderr, fmt, ##__VA_ARGS__);			\
-		fprintf(stderr, "\n");					\
-	} while (0)
-
-#ifdef UBILIB_DEBUG
-#define ubi_dbg(fmt, ...) do {						\
-		fprintf(stderr, "UBI Debug: %s: ", __func__);		\
-		fprintf(stderr, fmt, ##__VA_ARGS__);			\
-		fprintf(stderr, "\n");					\
-	} while (0)
-
-#else
-#define ubi_dbg(fmt, ...) do { } while (0)
-#endif
-
-/**
- * SYSFS Entries.
- *
- * @def UBI_ROOT
- *	@brief Name of the root UBI directory in sysfs.
- *
- * @def UBI_NLEN_MAX
- *	@brief Name of syfs file containing the maximum UBI volume name length.
- *
- * @def UBI_VER
- *      @brief Name of sysfs file containing UBI version.
- *
- * @def UBI_WEAR
- *	@brief Name of sysfs file containing wear level of an UBI device.
- *
- * @def UBI_VOL_COUNT
- *	@brief Name of sysfs file contaning the of volume on an UBI device
- *
- * @def UBI_TOT_EBS
- *	@brief Name of sysfs file contaning the total number of
- *	eraseblocks on an UBI device.
- *
- * @def UBI_AVAIL_EBS
- *	@brief Name of sysfs file contaning the number of unused eraseblocks on
- *	an UBI device.
- *
- * @def UBI_EB_SIZE
- *	@brief Name of sysfs file containing size of UBI eraseblocks.
- *
- * @def UBI_NUMS
- *      @brief Name of sysfs file containing major and minor numbers
- *      of an UBI device or an UBI volume device.
- *
- * @def UBI_VBYTES
- *	@brief Name of sysfs file containing size of an UBI volume device in
- *	bytes.
- *
- * @def UBI_VEBS
- *	@brief Name of sysfs file containing size of an UBI volume device in
- *	eraseblocks.
- *
- * @def UBI_VTYPE
- *	@brief Name of sysfs file containing type of an UBI volume device.
- *
- * @def UBI_VNAME
- *	@brief Name of sysfs file containing name of an UBI volume device.
- **/
-#define UBI_ROOT	"ubi"
-#define UBI_NLEN_MAX	"volume_name_max"
-#define UBI_VER		"version"
-#define UBI_WEAR	"wear"
-#define UBI_VOL_COUNT	"volumes_count"
-#define UBI_TOT_EBS	"total_eraseblocks"
-#define UBI_AVAIL_EBS	"avail_eraseblocks"
-#define UBI_EB_SIZE	"eraseblock_size"
-#define UBI_NUMS	"dev"
-#define UBI_VBYTES	"bytes"
-#define UBI_VEBS	"eraseblocks"
-#define UBI_VTYPE	"type"
-#define UBI_VNAME	"name"
-
-#define UBI_CDEV_PATH	"/dev/ubi%d"
-#define UBI_VOL_CDEV_PATH "/dev/ubi%d_%d"
-#define UBI_SYSFS_ROOT	"/sys/class"
-
-#define UBI_MAX_ID_SIZE	9
-
-#endif /* !__UBI_INT_H__ */
--- mtd-utils.orig/ubi-utils/src/libubiold_sysfs.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * UBI (Unsorted Block Images) library.
- *
- * Author: Artem B. Bityutskiy
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdarg.h>
-
-#include "config.h"
-#include "libubiold_int.h"
-
-int
-sysfs_read_data(const char *file, void *buf, int len)
-{
-	int fd;
-	ssize_t rd;
-
-	fd = open(file, O_RDONLY);
-	if (fd == -1) {
-		ubi_err("cannot open file %s", file);
-		return -1;
-	}
-
-	rd = read(fd, buf, len);
-	if (rd == -1)
-		ubi_err("cannot read file %s", file);
-
-	close(fd);
-
-	return rd;
-}
-
-int
-sysfs_read_data_subst(const char *patt, void *buf, int len, int n, ...)
-{
-	va_list args;
-	char buf1[strlen(patt) + 20 * n];
-
-	va_start(args, n);
-	vsprintf(&buf1[0], patt, args);
-	va_end(args);
-
-	return sysfs_read_data(&buf1[0], buf, len);
-}
-
-int
-sysfs_read_dev(const char *file, unsigned int *major, unsigned int *minor)
-{
-	int fd;
-	int ret;
-	ssize_t rd;
-	int err = -1;
-	char buf[40];
-
-	fd = open(file, O_RDONLY);
-	if (fd == -1) {
-		ubi_err("cannot open file %s", file);
-		return -1;
-	}
-
-	rd = read(fd, &buf[0], 20);
-	if (rd == -1) {
-		ubi_err("cannot read file %s", file);
-		goto error;
-	}
-	if (rd < 4) {
-		ubi_err("bad contents of file %s:", file);
-		goto error;
-	}
-
-	err = -1;
-	if (buf[rd -1] != '\n') {
-		ubi_err("bad contents of file %s", file);
-		goto error;
-	}
-
-	ret = sscanf(&buf[0], "%d:%d\n", major, minor);
-	if (ret != 2) {
-		ubi_err("bad contents of file %s", file);
-		goto error;
-	}
-
-	err = 0;
-
-error:
-	close(fd);
-
-	return err;
-}
-
-int
-sysfs_read_dev_subst(const char *patt, unsigned int *major,
-		unsigned int *minor, int n, ...)
-{
-	va_list args;
-	char buf[strlen(patt) + 20 * n];
-
-	va_start(args, n);
-	vsprintf(&buf[0], patt, args);
-	va_end(args);
-
-	return sysfs_read_dev(&buf[0], major, minor);
-}
-
-static int
-sysfs_read_ull(const char *file __unused, unsigned long long *num __unused)
-{
-	return 0;
-}
-
-int
-sysfs_read_ull_subst(const char *patt, unsigned long long *num, int n, ...)
-{
-	va_list args;
-	char buf[strlen(patt) + 20 * n];
-
-	va_start(args, n);
-	vsprintf(&buf[0], patt, args);
-	va_end(args);
-
-	return	sysfs_read_ull(&buf[0], num);
-}
-
-static int
-sysfs_read_uint(const char *file __unused, unsigned int *num __unused)
-{
-	return 0;
-}
-
-int
-sysfs_read_uint_subst(const char *patt, unsigned int *num, int n, ...)
-{
-	va_list args;
-	char buf[strlen(patt) + 20 * n];
-
-	va_start(args, n);
-	vsprintf(&buf[0], patt, args);
-	va_end(args);
-
-	return	sysfs_read_uint(&buf[0], num);
-}
-
-int
-sysfs_read_ll(const char *file, long long *num)
-{
-	int fd;
-	ssize_t rd;
-	int err = -1;
-	char buf[20];
-	char *endptr;
-
-	fd = open(file, O_RDONLY);
-	if (fd == -1)
-		return -1;
-
-	rd = read(fd, &buf[0], 20);
-	if (rd == -1)
-		goto out;
-
-	if (rd < 2) {
-		ubi_err("bad contents in file %s: \"%c%c...\"",
-			file, buf[0], buf[1]);
-		goto out_errno;
-	}
-
-	*num = strtoll(&buf[0], &endptr, 10);
-	if (endptr == &buf[0] || *endptr != '\n') {
-		ubi_err("bad contents in file %s: \"%c%c...\"",
-			file, buf[0], buf[1]);
-		goto out_errno;
-	}
-
-	if  (*num < 0) {
-		ubi_err("bad number in file %s: %lld", file, *num);
-		goto out_errno;
-	}
-
-	err = 0;
-
-out_errno:
-	errno = EINVAL;
-
-out:
-	close(fd);
-	return err;
-}
-
-int
-sysfs_read_int(const char *file, int *num)
-{
-	int err;
-	long long res = 0;
-
-	err = sysfs_read_ll(file, &res);
-	if (err)
-		return err;
-
-	if (res < 0 || res > INT_MAX) {
-		ubi_err("bad number in file %s: %lld", file, res);
-		errno = EINVAL;
-		return -1;
-	}
-
-	*num = res;
-	return 0;
-}
--- mtd-utils.orig/ubi-utils/src/libubiold_sysfs.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * UBI (Unsorted Block Images) library.
- *
- * Author: Artem B. Bityutskiy
- */
-
-/**
- * sysfs_read_data - read data from a sysfs file.
- *
- * @file  path to the file to read from
- * @buf	  furrer where to store read data
- * @len	  length of provided buffer @buf
- *
- * This function returns the number of read bytes or -1 in case of error.
- */
-int sysfs_read_data(const char *file, void *buf, int len);
-
-/**
- * sysfs_read_data_subst - form path to a sysfs file and read data from it.
- *
- * @patt  path to the file to read from
- * @buf	  furrer where to store read data
- * @len	  length of provided buffer @buf
- * @n	  number of parameters to substitute to @patt
- *
- * This function forms path to a sysfs file by means of substituting parameters
- * to @patt and then reads @len bytes from this file and stores the read data
- * to @buf. This function returns the number of read bytes or -1 in case of
- * error.
- */
-int sysfs_read_data_subst(const char *patt, void *buf, int len, int n, ...);
-
-/**
- * sysfs_read_dev - read major and minor number from a sysfs file.
- *
- * @file   path to the file to read from
- * @major  major number is returned here
- * @minor  minor number is returned here
- */
-int sysfs_read_dev(const char *file, unsigned int *major,
-		unsigned int *minor);
-/**
- * sysfs_read_dev_subst - for path to a file and read major and minor number
- * from it.
- *
- * @patt   pattern of the path to the file to read from
- * @major  major number is returned here
- * @minor  minor number is returned here
- * @n	   number of arguments to substitute
- *
- * This function substitures arguments to the @patt file path pattern and reads
- * major and minor numbers from the resulting file.
- */
-int sysfs_read_dev_subst(const char *patt, unsigned int *major,
-		unsigned int *minor, int n, ...);
-
-/**
- * sysfs_read_ull_subst - form path to a sysfs file and read an unsigned long
- * long value from there.
- *
- * @patt  pattern of file path
- * @num	  the read value is returned here
- * @n	  number of parameters to substitute
- *
- *
- * This function first forms the path to a sysfs file by means of substituting
- * passed parameters to the @patt string, and then read an 'unsigned long long'
- * value from this file.
- */
-int sysfs_read_ull_subst(const char *patt, unsigned long long *num,
-		int n, ...);
-
-/**
- * sysfs_read_uint_subst - the same as 'sysfs_read_uint_subst()' but reads an
- * unsigned int value.
- */
-int sysfs_read_uint_subst(const char *patt, unsigned int *num,
-		int n, ...);
-
-/**
- * sysfs_read_ll - read a long long integer from an UBI sysfs file.
- *
- * @file  file name from where to read
- * @num	  the result is returned here
- */
-int sysfs_read_ll(const char *file, long long *num);
-
-/**
- * sysfs_read_int - the same as 'sysfs_read_ll()' but reads an 'int' value.
- */
-int sysfs_read_int(const char *file, int *num);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] ubi-utils: introduction of libubi_common
  2007-07-27 15:28 ` [PATCH 1/5] ubi-utils: introduction of libubi_common Alexander Schmidt
@ 2007-07-28 12:51   ` Artem Bityutskiy
  2007-08-02  8:33     ` Alexander Schmidt
  0 siblings, 1 reply; 9+ messages in thread
From: Artem Bityutskiy @ 2007-07-28 12:51 UTC (permalink / raw)
  To: Alexander Schmidt
  Cc: linux-mtd@lists.infradead.org, Andreas Arnez, Frank Haverkamp

On Fri, 2007-07-27 at 17:28 +0200, Alexander Schmidt wrote:
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#define DEFAULT_DEV_PATTERN    "/dev/ubi%d"
> +#define DEFAULT_VOL_PATTERN    "/dev/ubi%d_%d"

Is it possible to make any patterns like this part of _utilities_?
UBI devices may have any names and it is defined by udev. The
library should not assume any UBI device name.

Whole this file should be out of libubi,not part of it.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] ubi-utils: introduction of libubi_common
  2007-07-28 12:51   ` Artem Bityutskiy
@ 2007-08-02  8:33     ` Alexander Schmidt
  2007-08-04  9:03       ` Artem Bityutskiy
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Schmidt @ 2007-08-02  8:33 UTC (permalink / raw)
  To: linux-mtd, dedekind; +Cc: Frank Haverkamp, Andreas Arnez

Hi Artem,

On Saturday 28 July 2007, Artem Bityutskiy wrote:
> Is it possible to make any patterns like this part of _utilities_?
> UBI devices may have any names and it is defined by udev. The
> library should not assume any UBI device name.
> 
> Whole this file should be out of libubi,not part of it.

I think this issue is caused by the command line interface we have at
the moment, where only device numbers are specified and a path
to a custom device cannot be specified. So even if we move this
hardcoded path to the utils, the user is still not able to specify a
custom device path in _any_ of the utils.

What we have to do to resolve this issue IMO is to change the cli
(while preserving the old one for legacy), which is a more intrusive
change than migrating the tools to the new libubi, and which should
be a separate patch. However, even this change seems easier to me
when the device path is hardcoded only in one place...

Regards,
Alex

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] ubi-utils: introduction of libubi_common
  2007-08-02  8:33     ` Alexander Schmidt
@ 2007-08-04  9:03       ` Artem Bityutskiy
  0 siblings, 0 replies; 9+ messages in thread
From: Artem Bityutskiy @ 2007-08-04  9:03 UTC (permalink / raw)
  To: Alexander Schmidt; +Cc: linux-mtd, Frank Haverkamp, Andreas Arnez

Hi Alex,

On Thu, 2007-08-02 at 10:33 +0200, Alexander Schmidt wrote:
> On Saturday 28 July 2007, Artem Bityutskiy wrote:
> > Is it possible to make any patterns like this part of _utilities_?
> > UBI devices may have any names and it is defined by udev. The
> > library should not assume any UBI device name.
> > 
> > Whole this file should be out of libubi,not part of it.
> 
> I think this issue is caused by the command line interface we have at
> the moment, where only device numbers are specified and a path
> to a custom device cannot be specified. 

Right, and I think it is trivial to add one more parameter to the
tools's cli - device node name.

> So even if we move this
> hardcoded path to the utils, the user is still not able to specify a
> custom device path in _any_ of the utils.

Just improve cli then or leave this hardcoded in the tools.

> What we have to do to resolve this issue IMO is to change the cli
> (while preserving the old one for legacy), which is a more intrusive

There is nothing intrusive actually, it is just simple parameter
addition. It is really easy.

>  However, even this change seems easier to me
> when the device path is hardcoded only in one place...

Alex, it is not really easier. And it is actually silly. Look at this
lububi_common.c, look at the functions. All functions are tiny wrappers
over a libc call:

Just look again at what you sent:

+int ubi_vol_open(int devn, int vol_id, int flags)
+{
+       char path[MAXPATH];
+       int fd;
+
+       snprintf(path, MAXPATH, DEFAULT_VOL_PATTERN, devn, vol_id);
+
+       fd = open(path, flags);
+
+       return fd;
+}
+
+int ubi_vol_close(int vol_fd)
+{
+       return close(vol_fd);
+}

And these are library calls. Users are able to call open() themselves.
And close() too. No need to wrap that at all. It does not worth it
to add library interfaces for these tiny things. Similar to other
functions in that file.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-08-04  9:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-27 15:23 [PATCH 0/5] ubi-utils: migrate to new libubi Alexander Schmidt
2007-07-27 15:28 ` [PATCH 1/5] ubi-utils: introduction of libubi_common Alexander Schmidt
2007-07-28 12:51   ` Artem Bityutskiy
2007-08-02  8:33     ` Alexander Schmidt
2007-08-04  9:03       ` Artem Bityutskiy
2007-07-27 15:29 ` [PATCH 2/5] ubi-utils: migrate pddcustomize Alexander Schmidt
2007-07-27 15:30 ` [PATCH 3/5] ubi-utils: migrate ubimirror Alexander Schmidt
2007-07-27 15:31 ` [PATCH 4/5] ubi-utils: migrate pfiflash Alexander Schmidt
2007-07-27 15:31 ` [PATCH 5/5] ubi-utils: remove dead code Alexander Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox