0

Possible Duplicate:
SDCard content exist but cant see them

Phone running Linux Kernel(2.6.31) with SD card inserted.

[ISSUE] When data is written to SD card (write syscall) the write returns successfully. However, when the card (via phone) is accessed as a mass storage device on PC, the data is not seen.

Only after physically removing the card and reinserting it and then accessing it on PC as a mass storage device will show the data that was written. Tried fsync() after writing the data. Still it wont show.

Is the kernel maintaining a cache before writing the data to SD card? If so, how do I make sure it is flushed to the SD card?

[edit] removed tag MMC

Udo
  • 449
  • 3
  • 13
spitfire88
  • 1,596
  • 3
  • 19
  • 31
  • For me it sounds like you have a Filesystem which your Phone cannot read. Can you tell us what Filesystem your SD card is formatted in? – Oliver Sep 04 '12 at 12:06
  • SD card is formatted using the mkfs.vfat command. One more thing id like to point out about the issue is that it is not always seen. for example after first booting the phone the contents added to the card are seen properly on PC. subsequent additions to SD card are not seen. – spitfire88 Sep 04 '12 at 12:13
  • Did you try another one to make sure your SD isn't defect? Most of the time I had such issues it was a driver problem, an additional question would be, do you see the files directly with your phone on the sd? – Oliver Sep 04 '12 at 12:20
  • Yes i tried with multiple sd cards/phones. The newly added content is seen on the phone, i also see it on the command line (ls /sdcard). – spitfire88 Sep 04 '12 at 12:24
  • Your problem is most likely caused by the connection from the PC <-> Phone; not from Phone <-> SD Card. If you disconnect and reconnect the phone the file will most likely appear on the PC. – Anya Shenanigans Sep 04 '12 at 13:14
  • @Petesh i agree with you, but it is not clear for me if sanrioalvares has actually acces to the sd on his phone. – Oliver Sep 04 '12 at 16:23
  • @Petesh Tried disconnecting the phone and reconnecting it to PC. File doesnt show. – spitfire88 Sep 05 '12 at 05:41

1 Answers1

0

Your problem is an exact duplicate of SDCard content exist but cant see them - the PC is displaying the content as returned from the MTP interface.

Stub code to do what you need to make the file appear:

imports:

import android.media.MediaScannerConnection;
import android.os.Environment;
import android.util.Log;
import java.io.File;

stub code:

File f = new File(Environment.getExternalStorageDirectory().getPath() + "/hello_nurse.txt");
if (! f.exists()) {
    try {
        f.createNewFile();
        String[] files = new String[1];
        files[0] = Environment.getExternalStorageDirectory().getPath() + "/hello_nurse.txt";
        String[] mimes = new String[1];
        mimes[0] = "text/plain";
        MediaScannerConnection.scanFile(getApplicationContext(), files, mimes, null);
    } catch (Exception ex) {
        Log.e("SD Create", "Failed to create file", ex);
        return;
    }
} else {
    Log.e("SD Create", "File is already present");
}
Community
  • 1
  • 1
Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122