Android4.4kitkat supports U-disk function

Source: Internet
Author: User

Android4.4kitkat Support U-disk function Release date: 2014-05-14 23:16:13 I'll say two sentences (0)0 Tag tag:Function
  • Android USB drive feature implementation and analysis
    The U-disk function realizes the result: the U disk will be displayed as USB storage in Settings storage.
    The ready-to-work kernel needs to support USB host,Need to support FUSE file system,Configure it in the FS option (config_fuse_fs=y).
    Configuration configuration for Android init.<board>.rc
        Mkdir/storage/udisk0 0000 System System    Mkdir/mnt/media_rw/udisk0 0700 MEDIA_RW MEDIA_RW

    Service fuse_udisk0/system/bin/sdcard-u 1023-g 1023-w 1023-d/mnt/media_rw/udisk0/storage/udisk0    class Late_star T    disabled

    Configure Fstab.<board>
    /BLOCK/SDA      /mnt/media_rw/udisk0  vfat  defaults  voldmanaged=udisk0:auto

    Configure Overlay
       <storage android:mountpoint= "/storage/udisk0"             android:storagedescription= "@string/storage_usb"             Android:primary= "false"             android:removable= "true"/>

    Mount Process:
    /dev/block/vold/8:1/mnt/media_rw/udisk0 vfat rw,dirsync,nosuid,nodev,noexec ,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_ utime=0020, codepage=437,iocharset=iso8859-1,shortname=mixed,UTF8 ,errors=remount-ro 0 0/dev/fuse/storage/udisk0 fuse rw,nosuid,nodev, Relatime, user_id=1023,group_id=1023,default_permissions,allow_ Other 0 0

    [email protected]:/# logcat-s Vold mountservice---------beginning Of/dev/log/main---------beginning Of/dev/log /systemi/vold (820): Vold 2.1 (The Revenge) firing Upd/vold (820): Volume sdcard1 State changing-1 (Initializin g), 0 (No-media) d/vold (820): Volume sdcard1 State changing-1 (Initializing), 0 (No-media) d/vold (820 ): Volume udisk0 State changing-1 (Initializing), 0 (No-media) d/vold (820): Volume udisk0 State changing 0 (no- Media), 2 (Pending) D/vold (820): Volume udisk0 State changing 2 (Pending), 1 (idle-unmounted) D/vold (8 : Volume sdcard1 State changing 0 (No-media), 2 (Pending) D/vold (820): Volume sdcard1 State changing 2 (Pendi NG), 1 (idle-unmounted) D/mountservice (1587): Got storage path:/storage/sdcard0 description:internal storage Primar Y:true removable:false emulated:true mtpreserve:50 allowmassstorage:false maxfilesize:0d/mountservice (1587): AddVol Umelocked () Storagevolume:D/mountservice (1587): mstorageid=65537 mpath=/storage/emulated/0 mdescriptionid=17040662 D/MountService (1587): Mprimary=true mremovable=false memulated=true mmtpreservespace=50 d/mountservice (1587): MAllowMassStorage=false MMax Filesize=0 mowner=userhandle{0} muuid=null d/mountservice (1587): Muserlabel=null mstate=null D/MountService (1587): g OT storage path:/storage/sdcard1 DESCRIPTION:SD card primary:false removable:true emulated:false mtpreserve:0 AllowM Assstorage:false Maxfilesize:4294967296d/mountservice (1587): addvolumelocked () Storagevolume:d/mountservice (1587) : Mstorageid=0 mpath=/storage/sdcard1 mdescriptionid=17040663 mprimary=false d/mountservice (1587): MRemovable=tru E memulated=false mmtpreservespace=0 mallowmassstorage=false d/mountservice (1587): mmaxfilesize=4294967296 mOwner=nu ll Muuid=null muserlabel=null mstate=null D/mountservice (1587): Got storage path:/storage/udisk0 description:usb Storag E Primary:false Removable:truE emulated:false mtpreserve:0 allowmassstorage:false maxfilesize:0d/mountservice (1587): addVolumeLocked () StorageVol Ume:d/mountservice (1587): mstorageid=0 mpath=/storage/udisk0 mdescriptionid=17040664 mPrimary=false D/MountService ( 1587): Mremovable=true memulated=false mmtpreservespace=0 mallowmassstorage=false D/MountService (1587): MMaxFileS Ize=0 mowner=null muuid=null muserlabel=null mstate=null w/mountservice (1587): Duplicate state Transition (unmounted-&G T unmounted) For/storage/sdcard1d/mountservice (1587): Volume State changed for/storage/sdcard1 (unmounted-removed) W/mountservice (1587): Duplicate state Transition (unmounted-unmounted) For/storage/udisk0i/vold (820):/dev/b  Lock/vold/8:1 being considered for volume Udisk0d/vold (820): Volume udisk0 State changing 1 (idle-unmounted)-3 (Checking) D/mountservice (1587): Volume State changed for/storage/udisk0 (unmounted) checking (d/mountservice): 1587 Ageintent Intent {act=android.intent.action.media_checking dat=file:///storage/udisk0 (have extras)} to Userhandle{-1}i/vold (820): Filesystem Check completed Okd/vold (820): Blkid identified as/dev/block/vold/8:1:uuid= "402e-0ee3" type= "VFAT" d/v  Old (820): Volume udisk0 State changing 3 (Checking), 4 (mounted) D/mountservice (1587): Volume state changed for /storage/udisk0 (checking-mounted) D/mountservice (1587): sendstorageintent Intent {act= Android.intent.action.MEDIA_MOUNTED Dat=file:///storage/udisk0 (have extras)} to Userhandle{-1}w/mountservice (1587): Duplicate state Transition (mounted-mounted) for/storage/emulated/0

    Vold parsing fstab files in Android 4.4,Vold will parse the vold.
       Property_get ("ro.hardware", propbuf, "");    snprintf (fstab_filename, sizeof (fstab_filename), fstab_prefix "%s", propbuf);    Fstab = Fs_mgr_read_fstab (fstab_filename);    if (!fstab) {        Sloge ("Failed to open%s\n", fstab_filename);        return-1;    }

    Which #define FSTAB_PREFIX "/fstab." So,The configured Fatab file must be placed in the root directory,Vold is a background process for Android,Will always listen to items marked as voldmanaged in Fatab if there are no marks,is skipped. Items that are not marked. Can be handed to Init's mount command processing,But it won't listen.,So you can put the recovery and the cache directory so just start up is the Mount directory item placed in Fatab and handed to Init for the Mount command processing,such as Samsung Device/samsung/manta/fstab.manta
    # Android Fstab file.#<src> <mnt_point> <type> <mnt_flags and Options> <fs_mgr_flags># the filesystem that contains the filesystem C Hecker binary (typically/system) cannot# Specify Mf_check,and must come before any filesystems this do specify Mf_check/dev/block/platform/dw_mmc.0/by-name/system/system EXT4 RO Wait/dev/block/platform/dw_mmc.0/by-name/cache/cache Ext 4 Noatime,Nosuid,Nodev,Nomblk_io_submit,Errors=panic wait,Check/dev/block/platform/dw_mmc.0/by-name/userdata/data Ext4 Noatime,Nosuid,Nodev,Nomblk_io_submit,Errors=panic wait,Check,Encryptable=/dev/block/platform/dw_mmc.0/by-name/metadata/dev/block/platform/dw_mmc.0/by-name/efs/factory Ext4 Noatime,Nosuid,Nodev,RO wait/dev/block/platform/dw_mmc.0/by-name/boot/boot eMMC Defaults                            Defaults/dev/block/platform/dw_mmc.0/by-name/recovery/recovery eMMC Defaults                            Defaults/dev/block/platform/dw_mmc.0/by-name/misc/misc eMMC Defaults                            Defaults/dev/block/mmcblk0boot0/bootloader eMMC Defaults Defaults

    Call mount on system boot:
    On FS    mkdir/factory 0775 Radio Radio    Mount_all/fstab.manta

    Similarly,Init's mount also ignores items marked as voldmanaged. The Mount command for a project Init is significantly different from the Mount management of Vold,The two cannot be mixed.
    Mountservice and Vold Joint mounting U-disk Mountservice and Vold will establish socket communication,The specific mount operation is issued by the command,Give it to Vold to finish. Mountservice will parse our configured storage_list.xml.
       private void readstoragelistlocked () {        mvolumes.clear ();        Mvolumestates.clear ();        Resources resources = Mcontext.getresources ();        int id = com.android.internal.r.xml.storage_list;        Xmlresourceparser parser = resources.getxml (ID);        AttributeSet attrs = xml.asattributeset (parser);        try {            xmlutils.begindocument (parser, tag_storage_list);            while (true) {                xmlutils.nextelement (parser);

    Vold gets a change to the device in the list will send the state changed event,Mountservice in OnEvent handles a variety of different state,Which gets to the device insert,The mount operation will be performed:
                if (code = = voldresponsecode.volumediskinserted) {                new Thread ("mountservice#volumediskinserted") {                    @Override Public                    void Run () {                        try {                            int rc;                            if (rc = domountvolume (path)) = storageresultcode.operationsucceeded) {                                SLOG.W (TAG, String.Format (" Insertion mount failed (%d) ", RC));                            }                        } catch (Exception ex) {                            SLOG.W (TAG, "Failed to mount Media on insertion", ex);                        }                    }                }.start ();

    Domountvolume just sends the Mount command to Vold
       private int Domountvolume (String path) {        int rc = storageresultcode.operationsucceeded;        Final Storagevolume volume;        Synchronized (Mvolumeslock) {            volume = mvolumesbypath.get (path);        }        if (debug_events) slog.i (TAG, "domountvolume:mouting" + path);        try {            Mconnector.execute ("volume", "mount", Path);

    The final Vold inside performs the corresponding mount operation,Our U-disk is VFAT format,I only tested this format.,The format under Linux is not tested,Because Vold only supports fat and EXT4
    int Volumemanager::mountvolume (const char *label) {    Volume *v = lookupvolume (label);    if (!v) {        errno = ENOENT;        return-1;    }    return V->mountvol ();}

           if (Fat::d omount (DevicePath, getmountpoint (), false, false , false ,                aid_media_rw, aid_media_rw, 0007, true)) {            Sloge ("%s failed to mount via VFAT (%s) \ n", devicePath, strerror (errno));            Continue

Android4.4kitkat supports U-disk function

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.