[PATCH 1/3] blkid: add UBI volume support
Artem Bityutskiy
dedekind1 at gmail.com
Fri Sep 25 03:19:19 EDT 2009
On Thu, 2009-09-24 at 23:57 +0200, Corentin Chary wrote:
> >> + if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
> >> + free(device);
> >> + continue ;
> >> + }
> >
> > Wouldn't be better to
> >
> > #define is_ubi_device(s) (S_ISCHR(s->st_mode) && (s->st_rdev & 0xFF))
> >
> > (or major() instead magic 0xFF constant?) and use it everywhere in
> > code? I guess UBI is always a char device.
>
> Maybe something like that:
> #define is_ubi_device(s) (S_ISCHR(s->st_mode) && !minor(s->st_rdev))
Well, if you want to be really nice, you may implement this as a
function which scans sysfs or looks at /proc/devices and makes sure the
device really belongs to UBI. See below.
>
> >> +++ b/shlibs/blkid/src/probe.c
> >> @@ -284,6 +284,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
> >>
> >> if (S_ISBLK(sb.st_mode))
> >> blkdev_get_size(fd, (unsigned long long *) &pr->size);
> >> + else if (S_ISCHR(sb.st_mode))
> >> + pr->size = 1;
> >> else
> >> pr->size = sb.st_size;
> >> }
> >
> > this is the same situation, this code will for all char devices, but we
> > want to support UBI only.
>
> I don't know if there is a "good" way to detect an ubi device using
> only struct stat.
>
> Artem, any idea ?
UBI char devices' major:minor numbers are allocated dynamically, so they
cannot be used.
To check whether this char. device node is an UBI volume and not
something else, you should scan all /sys/class/ubi/ubiX/Y/dev files, and
see if there is a device with the same major:minor.
The other possibility would be to look at /proc/devices, and make sure
there is an ubiX device with the same major number as your /dev/ubiX_Y
device.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
More information about the linux-mtd
mailing list