Search code examples
clinuxudevsysfs

How to get usb mass storage size programmatically in linux?


I am finding out information related to usb mass storage using udev library functions like (vendor ID, product ID, Manufacturer, Product, Serial etc).

Can any one suggest how to get usb mass storage size using udev.


Solution

  • Size is apparently not among the property values. It is, however, one of the sysfs attributes but I don't know how long it has been there. It is not mentioned in Documentation/ABI/testing/sysfs-block for some reason.

    You can get the value as a string like any other sysattr:

    blocks_string = udev_device_get_sysattr_value(dev, "size");