[PATCH 1/2] libmtd: add `mtd_dev_present()' library function

Artem Bityutskiy dedekind1 at gmail.com
Thu Feb 2 06:33:24 EST 2012


On Fri, 2012-01-27 at 10:30 -0800, Brian Norris wrote:

> +int mtd_dev_present(libmtd_t desc, int mtd_num) {
> +	struct stat st;
> +	struct libmtd *lib = (struct libmtd *)desc;
> +	char file[strlen(lib->mtd) + 10];
> +
> +	sprintf(file, lib->mtd, mtd_num);
> +	return !stat(file, &st);
> +}

Thanks! However...

This will only work for relatively newer kernels where MTD has sysfs
support (2.6.30+). Older kernels have no MTD sysfs support and the sysfs
file you are stat()'ing won't exist, so this function will always return
an error.

I've added the following stub to 'mtd_dev_present()':

+       if (!lib->sysfs_supported)
+               /* TODO: add legacy_dev_present() function */
+               return 1;

And pushed your patches to mtd-utils.

This means old kernels won't be fixed, but at least they won't be broken
either. Do you have enough juice to add a 'legacy_def_present()'
function? Ideally, it should parse '/proc/mtd', but I think there are
functions already which just check for '/dev/mtdX' node, so you could
just stat it instead of the sysfs file, I guess. See
'legacy_get_dev_info1()' for example.

-- 
Best Regards,
Artem Bityutskiy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20120202/4d8d7099/attachment.sig>


More information about the linux-mtd mailing list