Recover corrupted SD card - android

A friend of mine gave me a corrupted SD card. My windows 10 cannot detect it and on android it asks to format the corrupted SD card. Is there a way to partially or, best case, fully recover the data on this card?
Kind regards
Kurt

First thing you need to determine is if it's detected with correct capacity in disk management:
This is what to look for in Disk Management
If not then this is probably not DIY-able. A data recovery lab still could get the data by scraping off the back layer and soldering wires to a special reader.
If it is detected, my advise would be to create a sector by sector image file. Then, any decent file recovery software should be able to scan that image file as if it were a regular drive and recover the data.
To create such an image in Windows you could use Win32 Disk Imager, in Linux ddrescue. Any decent file recovery tool would allow you to create a drive image too.
I'll mention DMDE as an example as it is also a very good tool to analyze the image file with and recovers upto 4000 files for free (as long as they're in the same folder).

Related

What is the expected behaviour of Adoptable Storage on Android M and how it should be handled by apps?

I am experimenting with the “Adoptable storage” introduced in Android Marshmallow and I need some guidance on the expected behaviour and how the apps should handle the “Adoptable storage”.
Format “micro SD” card as Adoptable storage by using “Format as Internal”
Once Format is done, there are 2 options given to the user as follows:
Move Now
Move Later
a. Move Now:
When this option is chosen by the user, the path returned by the getExternalFilesDirs
is “/storage/emulated/0/Android/data/PACKAGE_NAME/files” and it actually points to the file system of micro SD card.
b. Move Later:
When this option is chosen by the user, the path returned by the getExternalFilesDirs
is “/storage/emulated/0/Android/data/PACKAGE_NAME/files” and it actually points to the file system of Internal embedded memory.
In both the cases, the apps can see only one storage and the other storage is completely not accessible by the Apps to store data such as Photos, Videos, etc. Is there any way to access the storage paths of both the Internal and micro SD card when the micro SD card is formatted as “Adoptable storage” ?
Apart from this documentation ,I could not find a detailed documentation on how the apps should handle this adopted storage. Is there any API that app needs to use?
Example:
Let say, if the user phone has Internal memory of 32 GB and micro SD card of 32 GB.
If the card is formatted as “Portable storage”, both 32GB(Internal) and 32GB(micro SD card) are available to user to store data.
But If the user format the card as “Internal Memory”, the user can save data(photos/video/music,etc) only to any of this 32 GB storage location, but not to the both location. The system is providing an option of “Migrating data” between the storage locations(Internal to micro SD card and viceversa), but the apps can use only 32 GB of storage(The user effectively loses his 32 GB of storage to store Media files and can be only used to install the apps ?).
Is this the expected behaviour ?
Note: Test devices used - Moto X Play & HTC 10 - Both running Android 6.0.1
getExternalFilesDir() always points to the external storage, which may or may not be available. Use getFilesDir() to dynamically get the path to wherever the App is currently stored.
Don't store the result of this since Adoptable Storage may move your app around at any time. From the docs:
The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

LOST.DIR problems with flash drive

I'll try to sum this up briefly. I have an app that can synchronize its data with a USB flash drive connected via an OTG adapter. The problem is this: some files will end up in a folder called LOST.DIR in the root of the flash drive. They are all exactly 4KB large and have random, 3-number names with no file extension. I know they contain data from my app because if I open them in notepad, I can see the data that my app is outputting. This data, however, is sometimes mixed with random symbols. Based on my rudimentary knowledge of file systems, the consistent size of the files and random content makes me think these are blocks of memory marked bad by Android and moved to this folder.
There is one caveat: I am treating the flash drives as if they are hot-swappable, as they would be on a Windows device. I understand that it may not be valid to think of them as this. To get around this, I'm calling running the sync command via su after I finish reading and writing to and from the flash drive. My understanding is that this should sync the in-RAM buffer/cache with the physical flash drive, thereby making it safe to remove. This may be a faulty assumption.
So, my question is two-fold:
What is causing data to randomly disappear and be moved to LOST.DIR?
Is it safe to be treating flash drives as hot swappable? If not, is there a way to make them behave that way?
If my question is not clear enough or you need more information, I can clarify things for you. Thank you.
What comes to mind is that you are not the only one accessing the flash drive (media scanner, for instance), so sync will flush buffers but something could be ongoing, and sync exits anyway. I think you should also unmount it (and it will fail until it's really safe to remove).

Which is faster to access a file in android, sdcard or system partition?

I have one simple question. If i have one file in system partition of android and if i copy the same file on sdcard, which will be faster to access?
Please answer this question.
Thanks in advance
The difference will be negligible. In any case, most newer devices have just one storage onboard the device, which is partitioned. In such devices, the need to access a separate SD Card goes away, as the memory is the same as the system storage.
On devices with an SD Card, there may be a very minute delay in accessing the file, but it will be negligible in pretty much any scenario.
You will not be able to really notice the access speed difference between accessing file from internal memory and SD Card.
With internal memory you will get added advantage of a security as it won't be accessible for other applications or you cannot access it by mounting.
The answer is Internal phone memory
because disk management(for phone ) is always better for internal memory as compared to SD card, So it is faster to access internal memory but you will not be able to notice the because difference is in mili seconds
With internal memory you will get advantage like user can't see your file until unless device is not rooted.
As stated, the time difference is not noticeable. However, a simple law of physics (and EE) will tell you that the longer the distance is (in this case the I/O bus), the longer it will take in time. Thus, the SDCard is slower than anything on the motherboard, even though it is measured in miliseconds.
I have found the SDCard is best used for static storage of your media files, and apps should be installed on the phone making them run as fast as possible, even though you can move some apps to the SDCard.
The speed is not noticeable unless you are coping the very large video files. The SD card speed is measured by class like:(Class 4, 6 or 10), the class 10 have higher speed as 10MB/S and class 2 have speed around 2MB/S. So, for good class of SD card, the speed gap is less. However, normally phone memory is faster than the SD card.

File IO performance on SD card

all
When I try to read some media file from sd card after the first time I insert to the device, the read performance is much worse than the second time, does anybody have any idea about this phenomena, and how can I avoid this problem, I tried open and fopen, but the results are the same, I just want read performance is the same, no matter when I insert SD card, thanks
Using O_DIRECT (see open(2)) when opening the file will bypass the buffer cache. This is often not a good idea, but I would expect it to be more consistent from run to run.
Keep in mind that using O_DIRECT requires that the memory read into be SC_PAGESIZE aligned and read in blocks which are multiples of SC_PAGESIZE.
Are you saying it's worse for the first read than subsequent reads before you remove the device? If so, this is normal - it's due to buffering. Basically the system is using the system RAM to speed up the perceived speed of the device.
If you remove the card after unmounting it and then put it back and remount it I would expect the first read would again be slower, then subsequent reads would appear to be faster again.

what is the exact path to store files in SD card

I have a requirement that I need to copy some files to the SD card programatically.
I have used
Environment.getExternalStorageDirectory()
to refer the SD card but In some devices it is referring to internal memory of the device.
Then I tried "/mnt/sdcard/" this path also still referring to Internal memory of the device.
I have done some investigation and came to know that "Environment.getExternalStorageDirectory()" will refer to internal memory of the device.
But I want to always store my files in SD card for all the devices.
I just want to know the path which should always refer to the Sd card in all the devices.
Is there any hard coded way to do this..??
Please help me.
Android doesn't know anything about the way the data is physically stored (could be a SD card, a CD, a chipset, etc). The only thing it knows is about whether the storage is "internal" or "external" (more details here).
So the way you are doing is fine: if the system gives you a path to an internal chipset when you call getExternalStorageDirectory(), this means that your physical device is built that way. There is no workaround for that.

Categories

Resources