Android2.3 the method of realizing the automatic mount of SD card and U disk _android

Source: Internet
Author: User

This paper illustrates the method of Android2.3 to realize the automatic mounting of SD card and U disk. Share to everyone for your reference, specific as follows:

The SD card is always not mounted automatically when porting the android2.3 on the s3c6410 platform. Check the relevant information, know in android2.3 is the Vold program is responsible for checking the kernel of the Sysfs file system, found that there is an SD card inserted, automatic mount. In the file system directory/system/etc/has a vold.fstab file, the file is the interface between the system and the user hardware platform, the user according to their own platform to configure the file, the content is relatively simple, only need you to specify the SYS vold program needs to query the folder path, When the SD card is inserted into the device, the corresponding file will be generated under this path, and vold can check it.

The contents of my Vold.fstab file are as follows:

# # Vold 2.0 fstab for OK6410
# #
#######################
# Regular device Mount
# #
# format:dev_ Mount <label> <mount_point> <part> <sysfs_path1...> 
# # label    -label for the volume
# # Mount_point-where The volume is mounted
# # part     -Partition # (1 based), or ' auto ' for the E partition.
# <sysfs_path>-List of SYSFS paths to source devices
######################
# mounts The A-usable p Artition of the specified device
dev_mount sdcard/mnt/sdcard auto/devices/platform/goldfish_mmc.0/devices/ Platform/s3c-sdhci.0/mmc_host/mmc0

Above all are comments, help, the most critical is the last sentence, where auto represents the first partition mounted SD card, followed by the Vold monitoring path, when inserting SD,/DEVICES/PLATFORM/S3C-SDHCI.0/MMC_HOST/MMC0 There will be more than one folder under the path, please confirm the corresponding path of your hardware platform.

Finally, there are a few things to focus on besides configuring this file:

1 If you insert the SD card into the Development Board , under the/dev/block/directory more than a few device nodes, proof SD card driver successfully loaded, my directory below will form mmcblk0 and MMCBLK0P1 nodes, note: These two nodes meaning, Mmcblk0 represents the first SD card device, MMCBLK0P1 represents the first partition of the first SD card device. The user cannot mount the/dev/block/mmcblk0 to the file system, but instead mount the partition of the SD card to the file system as follows:

# mount-t vfat/dev/block/mmcblk0   /sdcard/
<3>fat:utf8 is isn't a recommended IO charset for FAT filesystems , filesystem Wil
l is case sensitive!
Fat:utf8 is isn't a recommended IO charset for FAT filesystems, filesystem'll b
e case sensitive!
<7>mmc0:starting CMD17 Arg 00000000 Flags 000000b5
<7>mmc0:   blksz, blocks 1 flags 00000200 TSAC 10 0 Ms Nsac 0
<7>SDHCI [Sdhci_irq ()]: * * * mmc0 got interrupt:0x00000001 <7>sdhci
[Sdhci_irq ()]: * * * m Mc0 got interrupt:0x00000002
<7>mmc0:req done (CMD17): 0:00000900 00000000 00000000 00000000
<7> Mmc0:   bytes transferred:0
mount:invalid argument

Mount Mmcblk0 will appear such error prompts, and Mount Mmcblk0p1 will succeed, of course, under the Android should not be manually mounted, otherwise in the upper application software will appear to find the SD card,

2 in the Android kernel configuration (Linux kernel configuration) , note: The general Setup-> enable deprecated Sysfs features to support old Userspac E tools can be canceled, otherwise it may affect the Vold detection SD card.

This has a certain impact on user-space software, and if selected, the/DEVICES/PLATFORM/S3C-SDHCI.0/MMC_HOST:MMC0/MMC0 directory is generated in the SYS directory, not the path we need/devices/ PLATFORM/S3C-SDHCI.0/MMC_HOST/MMC0, do not select this is SYSFS file system support for older user space programs.

Vold successfully mounted SD, in the Android application can be checked, such as image browsing program, you can watch the image file on the SD card.

U disk mount also so, U disk inserted into the development Board of the USB interface, under the/SYS/DEVICES/PLATFORM/S3C2410-OHCI/USB1 will be more than one folder appears, you just need to add this path to the list of monitoring paths, My final vold.fstab is as follows:

Dev_mount Sdcard/mnt/sdcard auto/devices/platform/s3c2410-ohci/usb1/devices/platform/s3c-sdhci.0/mmc_host/mmc0

Note: The TAB key must be split between each parameter, otherwise the Vold program will not read the parameters correctly.

This way when the USB disk inserted, the Android interface program will identify, prompted to have SD card insert (why not Tip u disk, this if you are interested in your own research), you can use the picture browser, audio player to open the file inside the U disk. I have tried to get vold to mount the U disk to the/mnt/udisk directory below, this can be modified Vold.fstab file, it is easy to implement, the command environment show has been mounted successfully, But Android's image browser and audio playback software (android2.3) can not detect U disk, so the U disk mounted to the/mnt/sdcard directory, so that the upper program can identify u disk.

You can modify the Vold software, let him detect/mnt/udisk directory, at the same time modify the interface hint, prompted to find "U disk", so relatively formal some, do not have to give U disk with SD card hat, hehe.

Above is oneself in transplant android2.3 process Sd,u disk part encounters the question, gives everybody to share, hoped that has the help to the Netizen.

More interested readers of Android-related content can view this site: Android Development Primer and Advanced tutorial, Android resource Operation tips Summary, Android View view tips Summary and Android control usage summary

I hope this article will help you with the Android program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.