libubi: make `ubi_dev_present()' a library function
PATCH 1/2 libubi: make `ubi_dev_present()' a library function
We will use this function in ubinfo.
--- ubi-utils/include/libubi.h | 9 +++++++++ ubi-utils/libubi.c | 12 +++--------- 2 files changed, 12 insertions(+), 9 deletions(-)
ubi-utils/include/libubi.h +9 -0
@@ -346,6 +346,15 @@ int ubi_get_dev_info(libubi_t desc, const char *node, struct ubi_dev_info *info);/** +* ubi_dev_present - check whether an UBI device is present. +* @desc: UBI library descriptor +* @dev_num: UBI device number to check +* +* This function returns %1 if UBI device is present and %0 if not. +*/ +int ubi_dev_present (libubi_t desc,int dev_num); + +/** * ubi_get_dev_info1 - get UBI device information. * @desc: UBI library descriptor * @dev_num: UBI device number to fetch information about
ubi-utils/libubi.c +3 -9
@@ -1121,16 +1121,10 @@ int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes, int dtype)return 0 ; } -/** -* dev_present - check whether an UBI device is present. -* @lib: libubi descriptor -* @dev_num: UBI device number to check -* -* This function returns %1 if UBI device is present and %0 if not. -*/ -static int dev_present (struct libubi *lib,int dev_num) +int ubi_dev_present (libubi_t desc,int dev_num) {struct stat st; +struct libubi *lib = (struct libubi *)desc;char file[strlen (lib->ubi_dev) +50 ];sprintf (file, lib->ubi_dev, dev_num);
@@ -1146,7 +1140,7 @@ int ubi_get_dev_info1(libubi_t desc, int dev_num, struct ubi_dev_info *info)memset (info,0 ,sizeof (struct ubi_dev_info )); info->dev_num = dev_num; -if (!dev_present (lib, dev_num)) +if (!ubi_dev_present (desc, dev_num))return -1 ; sysfs_ubi =opendir (lib->sysfs_ubi);
Signature · 1 line
1.7.5.4
PATCH 2/2 ubinfo: fix `--all' for non-consecutive device numbers
When we have assigned non-consecutive device numbers to our UBI devices, then we run `ubinfo --all', we get errors once ubinfo tries to process the devices in the "hole". For instance, suppose there are two UBI devices, /dev/ubi0 and /dev/ubi10; then, ubinfo will fail trying to open /dev/ubi1 with:
ubinfo: error!: cannot get information about UBI device 1
error 2 (No such file or directory)
This patch adds a check to first see if device is present, then continue to the next ID if it doesn't exist.
--- ubi-utils/ubinfo.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
ubi-utils/ubinfo.c +2 -0
@@ -362,6 +362,8 @@ static int print_general_info(libubi_t libubi, int all)for (i = ubi_info.lowest_dev_num; i <= ubi_info.highest_dev_num; i++) { +if (!ubi_dev_present (libubi, i)) +continue ;if (!first)printf ("\n===================================\n\n" ); first =0 ;
Signature · 1 line
1.7.5.4
Re: [PATCH 2/2] ubinfo: fix `--all' for non-consecutive device numbers
Quoted 4 lines · On Thursday 26 January 2012 08:31:50 Brian Norris wrote:
When we have assigned non-consecutive device numbers to our UBI devices [...] This patch adds a check to first see if device is present, then continue to the next ID if it doesn't exist.
[ ... ]
Looks Ok to me (when used with part 1).
However, looking at the mtd-utils v1.4.6 ‘mtdinfo.c’, is there a similar issue there? But I have no idea how you could get non-consecutive MTD device numbers?
cheers!
-blf-
Signature · 3 lines
Brian Foster Principal MTS, Software | La Ciotat, France Maxim Integrated Products | Web: http://www.maxim-ic.com/
Re: [PATCH 2/2] ubinfo: fix `--all' for non-consecutive device numbers
Quoted 11 lines · Brian Foster
Quoted 4 lines · On Thursday 26 January 2012 08:31:50 Brian Norris wrote:
When we have assigned non-consecutive device numbers to our UBI devices [...] This patch adds a check to first see if device is present, then continue to the next ID if it doesn't exist.
[ ... ]Looks Ok to me (when used with part 1).
However, looking at the mtd-utils v1.4.6 ‘mtdinfo.c’, is there a similar issue there? But I have no idea how you could get non-consecutive MTD device numbers?
Yeah, there is a problem there. It's a little more difficult to see, but it can happen.
Suppose you have /dev/mtd0 on your system, then you can get an error with the following sequence:
# modprobe mtdram # modprobe nandsim # rmmod mtdram # mtdinfo --all ... mtdinfo: error!: mtd1 does not correspond to any existing MTD device
I'm sending a quick patch set for this.
Brian
Re: [PATCH 2/2] ubinfo: fix `--all' for non-consecutive device numbers
Quoted 11 lines · On Friday 27 January 2012 19:28:59 Brian Norris wrote:
Quoted 3 lines · Brian Foster
[ ... ] looking at the mtd-utils v1.4.6 ‘mtdinfo.c’,
is there a similar issue there? But I have no idea how you could get non-consecutive MTD device numbers?Yeah, there is a problem there. It's a little more difficult to see, but it can happen.
Suppose you have
/dev/mtd0on your system, then you can get an error with the following sequence:
Quoted 6 lines
# modprobe mtdram # modprobe nandsim # rmmod mtdram # mtdinfo --all ... mtdinfo: error!: mtd1 does not correspond to any existing MTD device
Ah, Ok! I had a similar thought over the weekend, and before seeing your e-mail tried to set-up the situation up on one of our SoC evaluation boards, using our H/W drivers. But for some reason those drivers won't unload — I should look into that — and then saw your e-mails ....
Quoted 1 line
I'm sending a quick patch set for this.
Yeah, saw it, seemed Ok to me. Thanks.
cheers!
-blf-
Signature · 3 lines
Brian Foster Principal MTS, Software | La Ciotat, France Maxim Integrated Products | Web: http://www.maxim-ic.com/
Quoted 3 lines · Brian Norris
We will use this function in ubinfo.
Signed-off-by Brian Norris <[email protected]>
Many thanks Brian for the fixes, pushed to mtd-utils.git!
Signature · 2 lines
Best Regards, Artem Bityutskiy