5/4/2019»»Saturday

Micro Sd Card Serial Number

5/4/2019
    32 - Comments

In some versions of Android, and other variants of Linux, it's possible to get the serial number of a mounted SD card, e.g. by reading the contents of /sys/class/mmc_host/mmc0/mmc0:0001/serial or /sys/block/mmcblk0/device/serial (specific numbers may vary). In my testing this has worked pretty reliably, as long as the SD card is inserted in a built-in SD card slot (not mounted via USB adapter).

  1. Micro Sd Card Serial Number Free

But as of Android 7.0 Nougat, the OS is said to be blocking access to this information, at least on some devices. I tested this by running a test app on a new Alcatel A30 GSM (Android 7.0), and in fact the above approach fails with a permission error:

For future reference, we (testing from an adb shell) have permissions to ls -ld the following:

  • /sys/class/mmc_host but not /sys/class/mmc_host/mmc0
  • /sys/block but not /sys/block/mmcblk0

Re-write the number, separating the numbers into pairs. For example, if the number is 5224656B then you would write “52 24 65 6B.” Put the number into reverse format to get the SD card ID. So, “52 24 65 6B” would be “6B652452.” This final number is the SD card ID.

Micro sd card serial number linux

Since the above approach no longer works,

  • Is there another way to obtain the serial number of a mounted SD card in Android 7.0 or later?

  • Failing that, is there any documentation or other statement from Google on plans for providing or not providing this function? I haven't found anything in the Android issue tracker, but maybe I'm not searching right.

To make sure the question is clear, I'm talking about what an ordinary (non-system) app running on a non-rooted device can do, with any permissions that an app can normally request and receive.

FYI, the /sbin directory doesn't seem to be readable, so commands like /sbin/udevadm aren't an option.

LarsH
LarsHLarsH

4 Answers

In Android N access to /sys nad /proc was significantly restricted, this was done to provide stricter sandboxes where applications run. This is explained in https://issuetracker.google.com/issues/37091475 as intentional. Actually its not said that all the data in /sys is not accessible, and Google is open to allow access to other files from this location:

If there are specific files in /sys you believe should be available to applications, but are not, please file a new bug where the request can be evaluated. For instance, /sys/devices/system/cpu is available to all processes, so it's inaccurate to say all of /sys is restricted.

I have a bad feeling that google is making changes similar to Apple where it is not allowed to gain hardware id-s. If that is not resolved then the solution is to use google account IDs instead. But I am aware it is not always possible, and will require major changes in business logic (licensing etc.).

Hopefully your bug report will be considered positively.

another related SO I found : File system changes in Android Nougat

Ignition lyrics william singe. No I'm not tryin to be rude, But hey pretty girl I'm feelin you The way you do the things you do Remind me of my Lexus coup Thats why im all up in yo grill Tryina get you to a hotel You must be a football coach The way you got me playin the field So baby gimme that toot toot Lemme give you that beep beep Runnin her hands through my 'fro Bouncin on 24's While they say on the radio. Now,um,usually I dont do this but uh. Go head' on and break em off wit a lil' preview of the remix.

Community
marcinjmarcinj

Use StorageVolume.getUuid() on StorageVolume which you get from StorageManager.

The value is volume ID assigned during formatting of the card, and its length/format differs depending on file system type. For FAT32 it is XXXX-XXXX, for NTFS it's longer hex string, for Internal mass storage it returns null.

Pointer NullPointer Null

try this: reference original link :Android get id of SD Card programmatically

Community
Vasudev VyasVasudev Vyas

adb shell cat /sys/class/mmc_host/mmc1/mmc1:*/cid

You can also try

sudo hwinfo --disk

to get information on your disks, including SD Cards.

Also try

sudo hdparm -I /dev/sdb more

ZedZed

Not the answer you're looking for? Browse other questions tagged androidsd-cardserial-number or ask your own question.

How can I programatically read the SD Card's CID register, which contains a Serial Number and other information? Can I do it through Android Java, or Native code?

Thanks in advance,Eric

Eric HamiltonEric Hamilton

11 Answers

Dinesh PrajapatiDinesh Prajapati

I managed to find my SD card CID by plugging my phone to my computer via usb and using the adb tool (Android SDK)

My phone is rooted so I'm not sure if this is accessible on non-rooted phones.

Also try

These are explained in the kernel documentation http://www.mjmwired.net/kernel/Documentation/mmc/mmc-dev-attrs.txt

delcypherdelcypher

I made this one.. it worked for me.. hope it makes u clear!

Aditya NikhadeAditya Nikhade

The only code I've found thus far to provide the id is C++ or C#http://jo0ls-dotnet-stuff.blogspot.com/2008/12/read-secure-digital-sd-card-serial.html
http://jo0ls-dotnet-stuff.blogspot.com/2008/12/read-cid-and-csd-c-implementation.html
If you are a C++ developer you may be able to take this and make it work on Android.

Paul GregoirePaul Gregoire

As BMB wrote, you cannot know the real path of the SD card in the /sys filesystem. However, /sys implements aliases as well, and you may be able to retrieve the CID through /sys/block/mmcblk0/device/cid.

For example, on a Tattoo running 2.2, /sys/block/mmcblk0 is a soft link (established automatically by the system) to /sys/devices/platform/msm_sdcc.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk0.

Samuel TardieuSamuel Tardieu

There is api in android for getting sd card serial id. The method is called getFatVolumeId(String mountPoint), where 'mountPoint' is sd card name (you can get this name by calling Environment.getExternalStorageDirectory()). But getFatVolumeId is kindof hidden function (or forgotten), so you want to create package in your project named android.os and the class in it to reference the native method, to be able to call it:

And the code is:

Also see the links

http://groups.google.com/group/android-framework/browse_thread/thread/1abd18435ba20a67?pli=1http://markmail.org/message/rdl4bhwywywhhiau#query:+page:1+mid:rdl4bhwywywhhiau+state:results

southertonsoutherton

There is no Android API that can do this that I am aware of and for a general solution that is needed. To provide some background the SD card is connected to a hw-controller that is specific to the device platform. It is possible to read out the cid value from the linux /sys file system if you know your platform. The following snippet works on my droid (TI omap based platform) but not on Qualcomm MSM based platforms.

On a another platform the sys file we are looking for is different. It may even differ between different cards on the same platform since I was not able to test that. On MSM based devices the path would be something like /sys/devices/platform/msm_sdcc.1/mmc_host/..

Since we have this hardware dependence on reading out the SD-card CID there would have to be an update to the Android API:s that provides general access. This API would then have to be implemented by each device manufacturer to map to the correct sd card controller driver.

BMBBMB

I was looking for this function too but could never get a home brewed solution. I ended up finding a company that makes an SID reader. Go to nexcopy.com and look in their SD or microSD duplicator section. It can read up to 20 cards at a time.

JesusJesus

for mmcblk0, just write in shell as:

you can implement it in java easily.

ref:
https://www.kernel.org/doc/Documentation/mmc/mmc-dev-attrs.txt
https://www.kernel.org/doc/Documentation/sysfs-rules.txt
http://www.cameramemoryspeed.com/sd-memory-card-faq/reading-sd-card-cid-serial-psn-internal-numbers/

Micro Sd Card Serial Number Free

yurenchenyurenchen

Even though the relatively ancient Palm OS and Windows Mobile OS devices are able to read the SD card ID, AFAIK Android devices aren't capable of doing that yet. This is particularly troubling given the problems with the Settings.Secure.ANDROID_ID discussed here.

gregSgregS

Building on Dinesh's answer..

Dinesh suggested looking in the directory/sys/class/mmc_host/mmc1/mmc1:*/ (where * is a number) for the file named cid, which gives us the contents of the card's CID register. This is does work in many cases, and is a very helpful start.

But mmc1 is not always the removable SD card. Sometimes, e.g. on a Motorola Droid Pro with Android API level 10, mmc0 is the removable SD card, and mmc1 is something else. I'm guessing that mmc1, when present, points to internal storage of some sort (possibly a non-removable microSD card). On a cheap Android tablet we tested, mmc0 is the SD card and there is no mmc1.

So you can't just assume that mmc1 is the SD card.

A glimmer of hope: It seems (so far) that by looking at the type file in the same directory as the cid file (e.g. /sys/class/mmc_host/mmc1/mmc1:0007/type), we can determine which is which: a type value of SD indicates a removable SD card, while MMC is not.

However, that's just from testing on a few Android devices. I can't find any specifications about the contents of the type file, so if somebody else knows of relevant documentation, please let me know.

Of course, MMC and SD are just two different storage technology standards, and SD is backward-compatible with MMC. So it's not necessarily the case that type SD always corresponds to an external microSD card. It doesn't seem likely that MMC could indicate a microSD card at all (if the type field is populated accurately); but on the other hand, it's conceivable that a non-removable SD card could have type SD.

For further research: Does this approach work when an microSD card is connected via a USB adapter? My one test on this, with a tablet, had the USB-connected microSD card show up as mmc1, with type SD.

LarsHLarsH
Number

Not the answer you're looking for? Browse other questions tagged androidc++windowsmfc or ask your own question.