Android SDCard Mount Process Analysis (1)

Source: Internet
Author: User

Some time ago, I made a few brief analyses on the Android SDCard unmount process. Since it was just a conversation on paper and there was no actual follow-up, there may be some misleading or minor errors. Today, I reorganized my mind and analyzed the mount process again.

Outline

 

  • How does the android system start listening to the mount service?
  • Which directory of the Android system is the default mount point?
  • Analysis of vold. fstab configuration file
  • In vold, what does main do on the startup page?
How does the android system start listening to the mount service?

Android sdcard hot swapping monitoring and execution operations are governed by a Startup File vold. The system opens the opportunity to read the Initialization Configuration File init. rc. The file is located in the device/ti/omap3evm/init directory. rc, which can be found on your own platform. There is a code that starts the vold service by default, as shown below:

Service vold/system/bin/vold
Socket vold stream 0660 root mount
Ioprio be 2 Copy code

If you want to modify the file, re-compile the boot. img image file and install it in the android system. Then you can find the init. rc file in the root directory of the android file system. The above code is used to start the vold Startup file. You can also add more file directories in init. rc, such as adding a directory that can store multi-partition mounting.

 

Which directory of the Android system is the default mount point?

When USB disk or sdcard is hot-swappable, the kernel will issue a command to execute the mount or unmount operation, but this is all driver-level. The mount directory is generated by vold in the/dev/block/vold directory of the android file system to store all USB disks or sdcard mount points. Code execution is the highest priority in main:

 

Mkdir ("/dev/block/vold", 0755 );

 

You can find the following nodes in the directory:

Sh-4.1 # ls/dev/block/vold/
179: 0 179: 1 copy the code

Node introduction:

0 indicates the current entire device. 1 code indicates the partition name of the current device.

So you will find that sdcard has only one partition, But it generates two shards, for example, 179: 0 179: 1.

USB disk has four partitions, which generates five mount points.

 

 

Analysis of vold. fstab configuration file

Vold reads the pre-configured sdcard or multi-partition configuration file by specifying a file, which is located in

/System/core/rootdir/etc/vold. fstab

The following configuration files are as follows:

Dev_mount sdcard/mnt/sdcard auto/devices/platform/goldfish_mmc.0/devices/platform/msm_sdcc.2/mmc_host/mmc1

 

Dev_mount indicates the mounting format

Sdcard indicates the mounted tag

/Mnt/sdcard indicates the mount point

Auto can be any of the custom options, but it must be determined by itself in the main. For example, this indicates automatic mounting.

The following two directories are the device paths. If the first directory is occupied, the second directory is selected.

 

The configuration file can be compiled according to your own needs. It is not fixed, but it is best to follow the format of google vold Startup File code, otherwise it will bring us a lot of trouble to modify the code or add the multi-partition function, as shown in the following multi-partition mounting support vold. fstab configuration file:

 

Dev_mount sdcard external/mnt/sdcard auto/devices/platform/mmci-omap-hs.0/mmc_host/mmc0/devices/platform/mmci-omap-hs.0/mmc_host/mmc1
Dev_mount usb1 external/mnt/usbdisk/usb1-disk % d all/devices/platform/ehci-omap.0/usb1/1-2/1-2.1/
Dev_mount usb2 external/mnt/usbdisk/usb2-disk % d all/devices/platform/ehci-omap.0/usb1/1-2/1-2.2/
Dev_mount usb3 external/mnt/usbdisk/usb3-disk % d all/devices/platform/ehci-omap.0/usb1/1-2/1-2.3/copy code

After the file is modified, it will be found in the/system/etc/vold. fstab directory of the android system.

/Devices/platform/ehci-omap.0/usb1/1-2/1-2.1/Represents the USB port to be mounted.

Vold. fstab is only a simple configuration file. The process_config function in main is used to read and retrieve data. Check the Code. There is a section in it to read the configuration file:

If (! (Fp = fopen ("/etc/vold. fstab", "r "))){
Return-1;
}
Copy code

In this function, the data is stored Based on the read data and the operation is performed when the conditions are met. For example, in the Code:

 

If (! Strcmp (type, "dev_mount ")){
DirectVolume * dv = NULL;
Char * part;

If (! (Part = strtok_r (NULL, delim, & save_ptr ))){
SLOGE ("Error parsing partition ");
Goto out_syntax;
}
If (strcmp (part, "auto") & atoi (part) = 0 ){
SLOGE ("Partition must either be 'auto' or 1 based index instead of '% S'", part );
Goto out_syntax;
}

If (! Strcmp (part, "auto ")){
Dv = new DirectVolume (vm, label, mount_point,-1 );
} Else {
Dv = new DirectVolume (vm, label, mount_point, atoi (part ));
}

While (sysfs_path = strtok_r (NULL, delim, & save_ptr ))){
If (* sysfs_path! = '/'){
/* If the first character is not a'/', it must be flags */
Break;
}
If (dv-> addPath (sysfs_path )){
SLOGE ("Failed to add devpath % s to volume % s", sysfs_path,
Label );
Goto out_fail;
}
}

/* If sysfs_path is non-null at this point, then it contains
* The optional flags for this volume
*/
If (sysfs_path)
Flags = parse_mount_flags (sysfs_path );
Else
Flags = 0;
Dv-> setFlags (flags );

Vm-> addVolume (dv );
} Copy the code

 

The execution of mount and unmount is done later in DirectVolume.

In addition, there may be problems when reading the configuration file later, because it reads the configuration file progressively by index subscript. If there is a problem, you can trace and print the configuration file to see where to modify it.

 

In vold, what does main do on the startup page?

Main is mainly used to initialize the socket connection listening data changes. It is started as soon as the system is up, and the device address of USB port or sdcard is identified by reading the configuration file to mount or unmount. Other operations such as mount, unmount, or delete a node are performed by the upper layer or framework to send a command to main to notify volumeManage to execute corresponding operations.

This article is from the "Terry _ Dragon" blog, please be sure to keep this source http://terryblog.blog.51cto.com/1764499/826656

Related Article

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.