[PATCH 1/3] blkid: add UBI volume support

Karel Zak kzak at redhat.com
Thu Sep 24 10:14:33 EDT 2009


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.

> +++ 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.

    Karel

-- 
 Karel Zak  <kzak at redhat.com>



More information about the linux-mtd mailing list