[PATCH 1/3] blkid: add UBI volume support
Corentin Chary
corentin.chary at gmail.com
Thu Sep 24 17:57:14 EDT 2009
On Thu, Sep 24, 2009 at 4:14 PM, Karel Zak <kzak at redhat.com> wrote:
> On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
>> --- a/shlibs/blkid/src/devname.c
>> +static void
>> +ubi_probe_all(blkid_cache cache, int only_if_new)
>> +{
>> + const char **dirname;
>> +
>> + for (dirname = dirlist; *dirname; dirname++) {
>> + DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
>> + *dirname));
>> +
>> + DIR *dir;
>> + struct dirent *iter;
>> +
>> + dir = opendir(*dirname);
>> + if (dir == NULL)
>> + continue ;
>> +
>> + while ((iter = readdir(dir)) != NULL) {
>> + char *name, *device;
>> + struct stat st;
>> + dev_t dev;
>> +
>> + name = iter->d_name;
>> +
>> + if (!strcmp(name, ".") || !strcmp(name, "..") ||
>> + !strstr(name, "ubi"))
>> + continue;
>> + if (!strcmp(name, "ubi_ctrl"))
>> + continue;
>> + device = malloc(strlen(*dirname) + strlen(name) + 2);
>> + if (!device)
>> + break ;
>> + sprintf(device, "%s/%s", *dirname, name);
>> + if (stat(device, &st))
>> + break ;
>> +
>> + 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))
>> +++ 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 ?
--
Corentin Chary
http://xf.iksaif.net
More information about the linux-mtd
mailing list