Quantcast

detect SD Card path?

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

detect SD Card path?

moelski
Hi !

How can I get the SD card path?
I know that i can call Environment.ExternalStorageDirectory. But this will result in /mnt/sdcard.
My sd card is mounted to /mnt/sdcard/external_sd.

Has anyone somecode to figure out the correct path for internal and external (sd) storage location?

regards
   Dominik
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
On Jun 7, 2012, at 9:31 AM, moelski wrote:
> How can I get the SD card path?
> I know that i can call Environment.ExternalStorageDirectory. But this will result in /mnt/sdcard.  My sd card is mounted to /mnt/sdcard/external_sd.

What device is this? I've never heard of that before.

What do you get if you use Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic)? What's the value of Environment.ExternalStorageState? Environment.DataDirectory?

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
Hi Jon,

Environment.ExternalStorageDirectory
> /mnt/sdcard
Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic)
> /mnt/sdcard/Music
Environment.ExternalStorageState
> mounted
Environment.DataDirectory
> /data

My device is a galaxy S2 with Android 4.0.3.

If I use adb shell I find my "real" sd card here:
shell@android:/ $ cd mnt/
cd mnt/
shell@android:/mnt $ cd sdcard
cd sdcard
shell@android:/mnt/sdcard $ cd external_sd
cd external_sd
shell@android:/mnt/sdcard/external_sd $ 

Regards
  Dominik
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
On Jun 7, 2012, at 11:36 AM, moelski wrote:

> Environment.ExternalStorageDirectory
>> /mnt/sdcard
> Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic)
>> /mnt/sdcard/Music
> Environment.ExternalStorageState
>> mounted
> Environment.DataDirectory
>> /data
>
> My device is a galaxy S2 with Android 4.0.3.
> If I use adb shell I find my "real" sd card here:

Try this:

        adb shell ls -l /mnt/sdcard

Specifically, does /mnt/sdcard/Music exist? The /mnt/sdcard/external_sd directory may be a red herring, and ignorable.

What's the output of:

        adb shell mount

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
Hi Jon,

>Specifically, does /mnt/sdcard/Music exist?
yes it exists.

>adb shell mount
C:\Dev\Android_Net\AndroidSdk\tools>adb shell mount
rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
/dev/block/mmcblk0p9 /system ext4 ro,relatime,barrier=1,data=ordered 0 0
/dev/block/mmcblk0p7 /cache ext4 rw,nosuid,nodev,noatime,barrier=1,data=ordered 0 0
/dev/block/mmcblk0p1 /efs ext4 rw,nosuid,nodev,noatime,barrier=1,data=ordered 0 0
/dev/block/mmcblk0p10 /data ext4 rw,nosuid,nodev,noatime,barrier=1,data=ordered,noauto_da_alloc 0 0
/dev/block/mmcblk0p4 /mnt/.lfs j4fs rw,relatime 0 0
/sys/kernel/debug /sys/kernel/debug debugfs rw,relatime 0 0
/dev/block/vold/259:3 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime
=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /mnt/sdcard/external_sd tmpfs rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,size=0k,mode=755,gid=1000 0 0
tmpfs /mnt/sdcard/usbStorage tmpfs rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,size=0k,mode=755,gid=1000 0 0
/dev/block/vold/179:25 /mnt/sdcard/external_sd vfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1023,fmask=0002,dmask=000
2,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/179:25 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1023,fmask=0002,dmask=0002,allow
_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /mnt/sdcard/external_sd/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
/dev/block/dm-0 /mnt/asec/com.quoord.tapatalkahilfe.activity-1 vfat ro,dirsync,nosuid,nodev,noatime,nodiratime,uid=1000,fmask=0222,dmask=022
2,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/dm-1 /mnt/asec/com.ArtInGames.AirAttackHD-1 vfat ro,dirsync,nosuid,nodev,noatime,nodiratime,uid=1000,fmask=0222,dmask=0222,codepa
ge=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0


>adb shell ls -l /mnt/sdcard
I know that my sdcard contains some very big files - it´s the wikipedia offline. These files are not in the listing of /mnt/sdcard.

So /mnt/sdcard should be my internal device storage.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
On Jun 7, 2012, at 12:10 PM, moelski wrote:
>> adb shell mount

Your SD card is in fact mounted at /mnt/sdcard:

        /dev/block/vold/259:3 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime

/mnt/sdcard/external_sd is ignorable;

        tmpfs /mnt/sdcard/external_sd tmpfs rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,size=0k,mode=755,gid=1000 0 0

`tmpfs` is the filesystem type, and in this case means that the contents will be removed when the filesystem is unmounted. Thus, you wouldn't want to store anything on it anyway.


>> adb shell ls -l /mnt/sdcard
> I know that my sdcard contains some very big files - it´s the wikipedia
> offline. These files are not in the listing of /mnt/sdcard.
>
> So /mnt/sdcard should be my internal device storage.

No, /data is your internal storage device:

        /dev/block/mmcblk0p10 /data ext4 rw,nosuid,nodev,noatime,barrier=1,data=ordered,noauto_da_alloc 0 0

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
Hi Jon,

now I got confused

>Your SD card is in fact mounted at /mnt/sdcard:
Ok I removed my SD card from my phone and put it in my card reader of my laptop.

There I can find a file which is named "wiki_prefix_like_enwiki_1.lwk". This is a 476 MB file which belongs to wikipedia offline.

And I can´t find this file in the folder "/mnt/sdcard".
In fact /mnt/sdcard contains all which is on my phones internal memory.

>No, /data is your internal storage device:
Possible ... It´s not accessible by adb shell
shell@android:/data $ ls
ls
opendir failed, Permission denied
255|shell@android:/data $

What about this line:
/dev/block/vold/179:25 /mnt/sdcard/external_sd vfat rw,dirsync,nosuid,nodev,noexec,noatim
It´s not a tmpfs ...

Dominik
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
On Jun 7, 2012, at 12:46 PM, moelski wrote:
> now I got confused

Aren't we all....

>
>> Your SD card is in fact mounted at /mnt/sdcard:
> Ok I removed my SD card from my phone and put it in my card reader of my laptop.
>
> There I can find a file which is named "wiki_prefix_like_enwiki_1.lwk". This is a 476 MB file which belongs to wikipedia offline.

What directory is it in?

> And I can´t find this file in the folder "/mnt/sdcard".
> In fact /mnt/sdcard contains all which is on my phones internal memory.

How are you defining "internal memory"? I suspect we may be talking about different things...

> What about this line:
> /dev/block/vold/179:25 /mnt/sdcard/external_sd *vfat *rw,dirsync,nosuid,nodev,noexec,noatim

Strange; /mnt/sdcard/external_sd is mounted twice:

        tmpfs /mnt/sdcard/external_sd tmpfs rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,size=0k,mode=755,gid=1000 0 0
        /dev/block/vold/179:25 /mnt/sdcard/external_sd vfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1023,fmask=0002,dmask=000

I'm not sure how that works; /dev/block/vold appears to be the volume manager daemon, so I'm not sure where those files are physically stored. Very strange.

Let's try a different experiment: from your desktop machine, put a file into the Download directory of the SD card. Move the SD card back to your Android device, and see if the file is in /mnt/sdcard/Download. It should...

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
Hi Jon,

first of all let´s clarify what I mean by "internal storage" and "sd card" ...
Internal storage - Thats the memory which is offered by my phone itself. Some flash memory inside my phone which could be used as storage.
SD card - that´s a micro sd card which I can put into my phone. This offers additional storage space to my phone. It looks like this one
SD card :-)

>What directory is it in?
shell@android:/mnt/sdcard/external_sd $ ls
ls
wiki_prefix_like_enwiki_1.lwk

the file is within /mnt/sdcard/external_sd

>Let's try a different experiment: from your desktop machine, put a file into the Download directory of the SD card. Move the SD card back to your Android device, and see if the file is in /mnt/sdcard/Download. It should...
The file can be found in : /mnt/sdcard/external_sd/download
shell@android:/mnt/sdcard/external_sd $ cd download
cd download
shell@android:/mnt/sdcard/external_sd/download $ ls
ls
MyFile.txt
shell@android:/mnt/sdcard/external_sd/download $


Take a look at this link ... They have similar problems ...
http://stackoverflow.com/questions/5694933/find-an-external-sd-card-location
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
On Jun 7, 2012, at 2:26 PM, moelski wrote:
>> Let's try a different experiment: from your desktop machine, put a file into the Download directory of the SD card. Move the SD card back to your Android device, and see if the file is in /mnt/sdcard/Download. It should...
> The file can be found in : /mnt/sdcard/*external_sd*/download

It sounds like your hardware vendor (Samsung) is crazy. (Then again, they are the ones with a busted Android v2.1 install that prevents JITs from working...)

The whole point to android.os.Environment is to provide directories to external storage, yet they're making it worthless.

Case in point: Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic) _should_ return the SD card directory that the user has access to, so that the user can sanely add music to the SD card and then have the music available to apps via the public directory. Yet on your device, the public Music directory is /mnt/sdcard/Music, NOT /mnt/sdcard/external_sd/Music, so apps will NOT see anything that the user adds.

Crazy. Absolutely crazy.

Furthermore, as your stackoverflow.com url shows, there's no public way to get the external_sd directory, because it shouldn't exist; it SHOULD be /mnt/sdcard.

In short, you are getting the SD card path, it's just that Samsung has screwed things up so that the public APIs don't work properly on your device. I foresee lots of hackish workarounds...

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
This post was updated on .
Hi Jon,

ok let´s make thing even more crazy ...
My wife has a brand new Samsung Galaxy S3. And I took a look at the device ...
There you have 2 folders in /mnt
/mnt/sdcard  >> that is the internal flash storage
/mnt/sdextcard  >> that is the inserted sd card

So this is again a new "solution" ...  

But what can I do now (and I think there are a lot of people with the same problem ...)?
It´s hard for a normal user to find the correct mounting points in order to use the sd card storage

Dominik
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Tomasz Cielecki

My Samsung Galaxy S2 mounts the internal sdcard on /mnt/emmc and the micro sdcard at /mnt/sdcard. Though I am using CyanogenMod 9 on it, so I don't know how the factory rom does it.

On Jun 7, 2012 8:48 PM, "moelski" <[hidden email]> wrote:
Hi Jon,

ok let´s make thing even more crazy ...
My wife has a brand new Samsung Galaxy S3. And I took a look at the device
...
There you have 2 folders in /mnt
/mnt/sdcard  >> taht is the internal flash storage
/mnt/sdextcard  >> that is the inserted sd card

So this is again a new "solution" ...

But what can I do now (and I think there are a lot of people with the same
problem ...)?
It´s hard for a normal user to find the correct mounting points in order to
use the sd crad storage

Dominik

--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-tp5710218p5710239.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
This post was updated on .
Hi !

I use the factory rom ...

This is even more strange ... I have a Huawei X3, too.
This one has a /HWUserData which represents the internal storage.

And the mocro sd card is mounted to /mnt/sdcard.



/dev/block/loop0 /HWUserData vfat rw,relatime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0


So at the moment I think it is the best way to "parse" the mount output to get the correct pathes, isn´t it?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
In reply to this post by moelski
What is this i don't even...

So...  The android.os.Environment API is designed with _one_ external storage directory in mind. Samsung has decided that it'll have _two_ (or more?!), and is returning the internal one in preference to the external one. That appears to be the short of it.

What do you do? I have no idea. I would suggest going to the Samsung developer portal and asking them how your Java app is supposed to use the Environment API to e.g. access Music files when Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) returns the internal directory and not the external one. (If you contact their forums, I'd suggest using Java terminology; no sense complicating matters with C#/Mono for Android unless it's actually relevant, and in this case I doubt that Mono for Android is relevant.)

Really, what they _should_ have done was union-mount the two filesystems into one mount point. At least then you could read both internal and external storage without going crazy. (Writing would be...problematic -- which would you write to, internal or external? -- but at least reading would be sane.)

 - Jon

On Jun 7, 2012, at 2:48 PM, moelski wrote:

> Hi Jon,
>
> ok let´s make thing even more crazy ...
> My wife has a brand new Samsung Galaxy S3. And I took a look at the device
> ...
> There you have 2 folders in /mnt
> /mnt/sdcard  >> taht is the internal flash storage
> /mnt/sdextcard  >> that is the inserted sd card
>
> So this is again a new "solution" ...  
>
> But what can I do now (and I think there are a lot of people with the same
> problem ...)?
> It´s hard for a normal user to find the correct mounting points in order to
> use the sd crad storage
>
> Dominik
>
> --
> View this message in context: http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-tp5710218p5710239.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> [hidden email]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

Jonathan Pryor-2
In reply to this post by Tomasz Cielecki
On Jun 7, 2012, at 2:54 PM, Tomasz Cielecki wrote:
> My Samsung Galaxy S2 mounts the internal sdcard on /mnt/emmc and the micro sdcard at /mnt/sdcard. Though I am using CyanogenMod 9 on it, so I don't know how the factory rom does it.

As before, what is the result of:

        Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic)

Does it return the internal SD card or the micro SD card?

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

moelski
Hi !

Maybe this is not the complete trick but I started with a posting in the thread:
http://stackoverflow.com/questions/5694933/find-an-external-sd-card-location

After some testing on these devices:
* Huawei X3 (stock rom)
* Galaxy S2 (stock rom)
* Galaxy S3 (stock rom)
it seems to work as expected.

        public string getStorage()
        {
            try
            {
                var procb = new ProcessBuilder();
                procb.Command("mount");
                procb.RedirectErrorStream(true);
                Java.Lang.Process proc = procb.Start();

                proc.WaitFor();

                var resi = proc.InputStream;
                var rdr = new StreamReader(resi);
                string str = rdr.ReadToEnd();

                string[] lines = str.Split('\n');

                str = string.Empty;
                foreach (var line in lines)
                {
                    if (line.ToLower().Contains("fuse"))
                    {
                        string[] entry = line.Split(' ');
                        Android.Util.Log.Info("DSService", entry[1]);
                        str += entry[1] + "\r\n";
                    }
                    
                    if (line.ToLower().Contains("vfat") &&  // Only vfat 
                        line.ToLower().Contains("vold") &&  // Only Volume Manager entries
                        !line.ToLower().Contains("asec"))   // No Remove Ap2SD
                    {
                        string[] entry = line.Split(' '); 
                        Android.Util.Log.Info("DSService", entry[1]);
                        str += entry[1] + "\r\n";
                    }
                }

                return str;
            }
            catch (Exception ex)
            {
                Android.Util.Log.Error("DSService", ex.Message);
                return null;
            }
        }

I use the mount command to get the mounted devices. And then I look for fuse and vfat devices.

What di you think about that?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

ledz
That is the closest option to "try" and find the external sd card... I just don't know how well it will behave with all the different hardware schemes out there.

On 8 June 2012 07:22, moelski <[hidden email]> wrote:
Hi !

Maybe this is not the complete trick but I started with a posting in the
thread:
http://stackoverflow.com/questions/5694933/find-an-external-sd-card-location
http://stackoverflow.com/questions/5694933/find-an-external-sd-card-location

After some testing on these devices:
* Huawei X3 (stock rom)
* Galaxy S2 (stock rom)
* Galaxy S3 (stock rom)
it seems to work as expected.



I use the mount command to get the mounted devices. And then I look for fuse
and vfat devices.

What di you think about that?

--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-tp5710218p5710250.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid



--
Gonçalo Oliveira

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect SD Card path?

johnHolmes
I had a similar issue, finding available space on external storage.

See here for details:

http://mono-for-android.1047100.n5.nabble.com/Wrong-StatsFs-JellyBean-tp5711813.html;cid=1347100160930-247
Loading...