External SD Card Root Folder

tdocs2

Well-Known Member
Licensed User
Longtime User
How do I get the name of the External SD Card Root Folder? I have searched for hours and experimented with my own code, but to no avail.

The File.DirRootExternal returns the internal storage root folder name.

My objective is:

In any device, I want to get a file list in a folder in the external SD card.
I can do this in the internal storage by using File.DirRootExternal.

Thank you.
 

margret

Well-Known Member
Licensed User
Longtime User
Results I've seen so far:

Kindle Fire

Jost aus Soest's code returned: /sdcard1 - wrong

Djembefola's code returned: /mnt/sdcard - correct

Galaxy S2

Jost aus Soest's code returned: /mnt/sdcard/external_sd - correct

Djembefola's code returned: /mnt/sdcard/external_sd - correct

Nook Devices

Jost aus Soest's code returned: /mnt/sdcard - correct

Djembefola's code returned: /mnt/media - wrong

ASUS Transformer

Jost aus Soest's code returned: /Removable/MicroSD - correct

Djembefola's code returned: /Removable/MicroSD - correct


As NJDude stated, I don't think we can rely on this completely.
 
Last edited:
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
Not sure, I get the same results with and without the card inserted.

This is not a bug, it's a feature. The code returns the correct sd card path always, with or without a card inserted.


Using a system browser I see that when the card is inserted a new entry appears on the system: "/mnt/sdcard/udi" no matter which port I insert the card into, but in the browser I see it labels the cards "UDisk1" and "UDisk2" accordingly, this by the way applies to SDCards and USBDrives attached to that tab.

A drawback of the existing code is, that it only returns the first available external sd card slot. But it would be easy to modify it to find all other card slots and usb sticks.

One more thing, like I stated on my post, I don't get "/mnt/sdcard/sdcard1" but only "/sdcard1"

Please make sure that you use the code in post 13. It should work.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Yes it has a SDCard Slot and here is the contents:

## Vold 2.0 Generic fstab
## - San Mehat ([email protected])
##

#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <lun_syspath> <sysfs_path1...>
## label - Label for the volume
## mount_point - Where the volume will be mounted
## part - Partition # (1 based), or 'auto' for first usable partition.
## perm_mask - Mount permission mask: octal integer or 'auto' for default permission.
## <lun_syspath> - LUN for the device
## <sysfs_path> - List of sysfs paths to source devices
######################

dev_mount sdcard /mnt/sdcard auto auto /devices/platform/usb_mass_storage/lun1 /devices/platform/mmci-omap-hs.0/mmc_host/mmc1
dev_mount media /mnt/media 8 002 /devices/platform/usb_mass_storage/lun0 /devices/platform/mmci-omap-hs.1/mmc_host/mmc0
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
Yes it has a SDCard Slot and here is the contents:

dev_mount sdcard /mnt/sdcard auto auto /devices/platform/usb_mass_storage/lun1 /devices/platform/mmci-omap-hs.0/mmc_host/mmc1
dev_mount media /mnt/media 8 002 /devices/platform/usb_mass_storage/lun0 /devices/platform/mmci-omap-hs.1/mmc_host/mmc0

Thanks for posting the content, Margret.

The code in post #13 extracts two directories from your vold.fstab file :
/mnt/sdcard
/mnt/media

Both directories seem to be correct.

The code returns the first directory, if it is not equal to File.DirRootExternal
Else it returns the second directory.

Assumed that /mnt/sdcard is equivalent to File.DirRootExternal,
the second directory /mnt/media should be returned.

Are you sure that /mnt/media is not your sd card slot? What else could it be?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Djembefola: I do not know why you insist your code is correct when it does not return the correct path for the SD card most of the time.
I tested your code on 3 different devices, all equipped with SD cards in them. See results below:

I ran it on a 7"tablet with OS4.03. It showed: /mnt/sdcard where it should be /mnt/extsd
I ran it on a Razr smar phone OS4.04. It returned /mnt/sdcard-ext:none:lun1. It is partially correct as the card is: /mnt/sdcard-ext
I ran it on another 7" tablet with OS4.03. It returned /mnt/external_sd which says:file not found exception when I tried to copy a file to the SD using that name.
If you want us to use your code reliably, you might want to check it again.
Thank you
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
If you want us to use your code reliably, you might want to check it again.
Thank you

???
Why should i want you to use my code?
You are completely misunderstanding my intentions.
I am trying to find a solution. If you have a better one, let me know.
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
I am 100% sure that /mnt/media is the Internal memory and that /mnt/sdcard is the sdcard. I can write a test file to /mnt/sdcard and pull it out and place it in the PC and the file I wrote is there. I haven't looked at your code other than testing it, but on this device it is pulling the wrong path for the SDCard.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I think I have a possible solution, if you look closely at the contents of the vold.fstab file, you will see that the "correct" ones are the entries that contain the word "auto", so, when parsing the lines we should ask if the word "auto" is in it and grab those, however, if you look at my post where I have attached the contents of that tab with 2 ports I would get 4 results, CRAZY!!.

However, Margret's seems to break my theory.

It seems like a challenge to me :D
 
Last edited:
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I can do this all day with no issues:

B4X:
File.MakeDir("/mnt/media", "myfolder")
File.WriteString("/mnt/media/myfolder", "xyz.dat", "bla bla bla")
Well it was worth mentioning to clarify :)

How else do you propose you can identify which entry is internal and external without comparing to what is returned by File.DirRootExternal?

Also remember that Kindle and Nook use a fork of Android, there is no guarantee they will return File.DirRootExternal as per Google's specifications.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Maybe this will work? If you look at the second block from the Nook the lines end with mmc0 or mmc1. 0 is from the Media line and 1 from the SDCard. From NJDude's block they also end with 0,1 or 2. Maybe this is something we can key off of and can be used.

dev_mount inner_sdcard /mnt/sdcard 6 /devices/platform/imapx200_sdi0.0/mmc_host/mmc0
dev_mount up_sdcard /mnt/sdcard/sdcard1 auto /devices/platform/imapx200_sdi1.1/mmc_host/mmc1
dev_mount down_sdcard /mnt/sdcard/sdcard2 auto /devices/platform/imapx200_sdi2.2/mmc_host/mmc2

dev_mount sdcard /mnt/sdcard auto auto /devices/platform/usb_mass_storage/lun1 /devices/platform/mmci-omap-hs.0/mmc_host/mmc1
dev_mount media /mnt/media 8 002 /devices/platform/usb_mass_storage/lun0 /devices/platform/mmci-omap-hs.1/mmc_host/mmc0


So it looks like NJDude's would be:
/mnt/sdcard
/mnt/sdcard/sdcard1
/mnt/sdcard/sdcard2

and mine

/mnt/media
/mnt/sdcard
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is the vold.fstab file from my 7" Aluratek tablet 4.03: I confirmed that the SD card proper is definitely: /mnt/extsd and FileDirExternal is the internal memory: /mnt/sdcard.

B4X:
## Vold 2.0 fstab for HTC Passion
#
## - San Mehat ([email protected])
## 
#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...> 
## label        - Label for the volume
## mount_point  - Where the volume will be mounted
## part         - Partition # (1 based), or 'auto' for first usable partition.
## <sysfs_path> - List of sysfs paths to source devices
######################

# Mounts the first usable partition of the specified device
#/devices/platform/awsmc.3/mmc_host for sdio
dev_mount   sdcard   /mnt/sdcard   auto   /devices/virtual/block/nandj
dev_mount   extsd   /mnt/extsd   auto   /devices/platform/sunxi-mmc.1/mmc_host   /devices/platform/sunxi-mmc.0/mmc_host
dev_mount   usbhost1   /mnt/usbhost1   auto   /devices/platform/sw-ehci.1   /devices/platform/sw_hcd_host0   /devices/platform/sw-ehci.2
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Based on my guess from post #36, I wrote this block of code and it returns the correct info on all my devices, but I am sure others may/will see issues. I thought I had something until Mahares just posted. It seems his does not contain the mmc0/1 I was using. You can test this block of code and see what it does.

B4X:
Sub DevicePaths
   Dim lp As List : Dim mInternal, mSDCard1, mSDCard2, ChkVal, CK As String
   lp = File.ReadList("/system/etc/", "vold.fstab")
   For i = 0 To lp.Size -1 
      ChkVal = lp.get(i) 
      If ChkVal.ToLowerCase.StartsWith("dev_mount") Then 
         CK = ChkVal.SubString2(ChkVal.IndexOf("/mn"), ChkVal.Length -1)
         If ChkVal.Trim.ToLowerCase.EndsWith("mmc0") Then mInternal = CK.SubString2(0, CK.IndexOf(" "))
         If ChkVal.Trim.ToLowerCase.EndsWith("mmc1") Then mSDCard1 = CK.SubString2(0, CK.IndexOf(" "))
         If ChkVal.Trim.ToLowerCase.EndsWith("mmc2") Then mSDCard2 = CK.SubString2(0, CK.IndexOf(" "))
      End If
   Next
   Msgbox("Internal = " & mInternal & CRLF & "SDCard 1 = " & mSDCard1 & CRLF & "SDCard 2 = " & mSDCard2, "")
End Sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Margret, cloese but no cigar, on my tab with dual ports I get:

Internal = /mnt/sdcard
SDCard 1 = /mnt/sdcard/sdcard1
SDCard 2 = /mnt/sdcard/sdcard2

Which seems to be correct, however, on all my other devices I get all those fields blank.

Getting close though :D

I guess the key is to get the strings containing these 2 words: "auto" and "mmc_host"
 
Last edited:
Upvote 0
Top