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, John Smith <john@arrows.demon.co.uk>
Cc: Frank Haverkamp <haver@linux.vnet.ibm.com>
Subject: Re: UBI Tools - problem with multiple ubi devices.
Date: Wed, 28 Feb 2007 10:29:34 +0100	[thread overview]
Message-ID: <200702281029.34799.alexs@linux.vnet.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0702272101240.7726-100000@arrows.demon.co.uk>

On Tuesday 27 February 2007, John Smith wrote:
> In
> GIT:      users/haver/mtd-utils.git
> File:     ubi-utils/src/libubi.c
> Function: get_ubi_info
> 
> The code counts the number of UBI volumes by looking for files called
> 
>   /sys/class/ubi0, /sys/class/ubi1, ...
> 
> but the files are actually
> 
>   /sys/class/ubi/ubi0, ...
> 
> The count starts from 1 (probably also wrong), so is usable if there is a
> single UBI device. But if there is more than one UBI device, tools like
> ubimkvol fail.

Hi John,

thanks for pointing this out.

Frank, please review and commit.

Signed-off-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
---
 ubi-utils/src/libubi.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

--- mtd-utils.orig/ubi-utils/src/libubi.c
+++ mtd-utils/ubi-utils/src/libubi.c
@@ -138,7 +138,7 @@ static int
 get_ubi_info(ubi_lib_t desc, struct ubi_info *ubi)
 {
 	int err;
-	int n = 1;
+	int dev_count = 0;
 	char *path;
 	struct stat stat;
 
@@ -147,31 +147,31 @@ get_ubi_info(ubi_lib_t desc, struct ubi_
 		return -1;
 
 	/* Calculate number of UBI devices */
-	do {
+	while (!err) {
 		char dir[20];
 
-		sprintf(&dir[0], "ubi%d", n);
-		path = mkpath(desc->sysfs_root, dir);
+		sprintf(&dir[0], "ubi%d", dev_count);
+		path = mkpath(desc->ubi_root, dir);
 		if (!path)
 			return ENOMEM;
 
 		err = lstat(path, &stat);
 		if (err == 0)
-			n += 1;
+			dev_count += 1;
 		free(path);
-	} while (err == 0);
+	}
 
 	if (errno != ENOENT)
 		return -1;
 
-	if (n == 0) {
+	if (dev_count == 0) {
 		ubi_err("no UBI devices found");
 		errno = EINVAL;
 		return -1;
 	}
 
 	errno = 0;
-	ubi->dev_count = n;
+	ubi->dev_count = dev_count;
 	return 0;
 }
 

  reply	other threads:[~2007-02-28  9:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-27 21:12 UBI Tools - problem with multiple ubi devices John Smith
2007-02-28  9:29 ` Alexander Schmidt [this message]
2007-02-28 22:08   ` Frank Haverkamp
2007-03-07 13:15     ` Josh Boyer
2007-03-14 17:36       ` Josh Boyer

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=200702281029.34799.alexs@linux.vnet.ibm.com \
    --to=alexs@linux.vnet.ibm.com \
    --cc=haver@linux.vnet.ibm.com \
    --cc=john@arrows.demon.co.uk \
    --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