This time in order to make an MMC block as SDcard built-in, learning the next Android Vold disk Mount module, record (Android 4.2.2).
Writing is not easy, reproduced please specify the source: http://blog.csdn.net/jscese/article/details/38068441
One: Vold compilation and start-up
Vold source location in the Android root directory/system/vold file, first look at the following android.mk:
Common_src_files: = VolumeManager.cpp CommandListener.cpp VoldCommand.cpp NetlinkManager.cpp NetlinkHandler.cpp Volume.cpp DirectVolume.cpp logwrapper.c Process.cpp Ext4.cpp Fat.cpp Loop.cpp Devmapper.cpp ResponseCode.cpp Xwarp.cpp cryptfs.c ... local_module:= voldlocal_src_files: = main.cpp $ (common_src_files) Local_c_includes: = $ (common_c_ Includes) Local_cflags: =-werror=formatlocal_shared_libraries: = $ (common_shared_libraries) LOCAL_STATIC_LIBRARIES: = Libfs_mgrinclude $ (build_executable) ...
An Android executable file will eventually be generated under the System/bin in the Out project directory vold!
There is one more place to note about compilation, which is the configuration file that the Vold mechanism will parse Vold.fstab The compilation configuration of this file in/system/core/rootdir/android.mk:
Ifeq ($ (target_product), full) Copy_from + = Etc/vold.fstabendififeq ($ (target_product), full_x86) Copy_from + = etc/ Vold.fstabendififeq ($ (target_product), full_mips) Copy_from + = Etc/vold.fstabendif
Need to need vold.fstab, or want to add their own configuration file, you can add their own target_product here, compiled into the system for Vold parsing use.
Starting in/system/core/rootdir/init.rc as a service process, the role of Init.rc in Android startup can be referenced in the android--startup process
Service Vold/system/bin/vold class core socket vold stream 0660 root mount Ioprio be 2
The syntax rules for INIT.RC can be consulted
/system/core/init/readme.txtwhich
Class <name> Specify a class name for the service. All services with a named class may started or stopped together. A service is in the class "default" If one are not specified via the class Option....socket <name> <TYPE&G T <perm> [<user> [<group>]] Create a UNIX domain socket named/dev/socket/<name> and Pass
its FD to the launched process. <type> must be "Dgram", "stream" or "Seqpacket". User and group default to 0.
II: Vold Entrance
On the top of this daemon, starting with INIT, the entry is the main function in/system/vold/main.cpp:
int main () {Volumemanager *vm; Commandlistener *CL; Netlinkmanager *nm; Slogi ("Vold 2.1 (The Revenge) firing up"), mkdir ("/dev/block/vold", 0755);//Storage device Node/* Create our Singleton managers */if (! VM = Volumemanager::instance ()) {Sloge ("Unable to create Volumemanager"); exit (1);}; if (! ( NM = Netlinkmanager::instance ())) {Sloge ("Unable to create Netlinkmanager"); exit (1);}; CL = new Commandlistener (); Constructs an instance of Commandlistener and its parent class, registering Commandvm->setbroadcaster ((SocketListener *) cl); Nm->setbroadcaster ( SocketListener *) CL);//Set Volumemanager netlinkmanager A variable that sends a broadcast in these two instances, through an implicit conversion, the variable type is a pointer to the SocketListener class if (vm-> Start ()) {//No actual operation Sloge ("Unable to start Volumemanager (%s)", Strerror (errno)); exit (1);} Parse the configuration file as mentioned above, then vold.fstab the parsed content to a new instance of the abstract class (Directvolume) and save it to a container in Volumemanager, backing up using if (Process_config (VM ) {Sloge ("Error reading configuration (%s) ... continuing anyways", strerror (errno));} if (Nm->start ()) {//create socket to receive kernel, instantiate Netlinkhandler and parent class instance, turn on socket detection Sloge ("Unable to STart Netlinkmanager (%s) ", Strerror (errno)); exit (1);} Coldboot ("/sys/block");//traverse all device information, send an Add uevent//coldboot ("/sys/class/switch");/** now that we ' re up, we can Respond to Commands*/if (Cl->startlistener ()) {//switch on vold socket and detect sloge ("Unable to start Commandlistener (%s)", Strerror (errno)); exit (1);} Eventually we ' ll become the monitoring Threadwhile (1) {sleep (1000);} Slogi ("Vold exiting"); exit (0);}
VolumemanagerAs a management class for volume,
CommandlistenerRegisters a listener execution-related class as a command,
NetlinkmanagerAs a class to receive kernel Uevent events
The main structure of the vold is basically this way, and then analyze each function detail and association in turn!