Friend: gsymichael's column
In the previous article, I wrote something about the SD driver. After the card is identified by the system, the file system will be loaded. This part of work is completed by the storage manager under CE. When the system starts, filesys.exe will be created, which will provide the storager manager function. During the initialization phase of Storage Manager, a PNP thread is created to monitor whether devices with or without PNP are inserted or removed. After the SD card is inserted, the system sends a MSG after monitoring. This msg includes the device name and guid. Then, the PNP thread waits until the MSG starts to load the file system for the newly inserted block device. The mountstore function is used for loading.
Here, Ce designs a class cstore to express this block device. When creating an instance, it executes the constructor to initialize some members. The role of Storage Manager as a manager naturally needs to manage various storage devices in the system. storagemanager constructs a linked list and inserts the previously created store pointer into the linked list. Because the block driverers of Block devices have been loaded by device.exe, that is, the Device Manager, and the device files already exist, the Storage Manager uses createfilew in the opendisk function to obtain the device handle, this handle is also a member variable of cstore. Call deviceiocontrol using the handle to obtain part of the block driver information. What is important here is the string corresponding to the profile. With this, you can get information about the block device in the Registry in the next getstoragemessage (the function name is missing. Including the partition driver and the file system to be loaded by the device.
After obtaining the partition Driver (MS mspart is generally used. DLL) then it involves the partition part. In this part, the partition class will be created. The member of this class includes a series of function pointers, and then calls the loadpartitiondriver function, which is the mspart. the function address in DLL is assigned to the function pointer in the partition class. With the specific implementation of these functions, you can load the partition driver. The entry to the partition driver should be the pd_openstore function. In this function, the device handle and deviceiocontrol are used to read the MBR, And the partition structure is created through this information (this is not the partition class ), several shards have several corresponding structures and are connected with a linked list. The header is assigned to a member of cstore (dwstoreid should be the correct one ), the pointer of the partition class is also assigned to the cstoer Member, which is called m_ppartitionlist. With these pointers, call the loadpartition function in the partition driver to load the partition, after a partition is loaded, the file system on the partition is loaded. We use the FAT file system.
Load the file system after the partition is loaded. Here, a function initex is involved to load the file system. This function creates two structures: FSD and DSK. At the same time, the return value m_pdsk of this function is a member of the partition class. The DSK structure has a pointer to FSD, a pointer to _ DSK, and a _ DSK structure to volume.
As shown above, the actual Storage Management maintains several classes and structures: cstore, cpartition, FSD, DSK, and volume. When the file system is loaded, A registervolume function is called. After successful registration, the SD volume is displayed on the device.
This part involves a resumable data transfer problem. For example, if the suspend device writes data to the SD card, it will then wake up. The previous write operation starts from the breakpoint. Here is the delay time of the PNP device unmount, which is usually set through the registry. After the device is wakeup, it will actually perform an unmount action, and then perform another mount operation. After unmount, the system marks the device to unmount, and then waits for the delay time. After the delay time expires, the storage management will unmount the device that has been marked, if you re-mount when the time is not reached, the system will repeat the previously described actions, however, here we will compare whether the new mounted device is consistent with the previous cstore linked list. This comparison is very strict, such as the device ID and modification time. In this way, the system will not change the card in the middle and the system will still consider the previous card error to occur. If you confirm that the card is the same and the content on the card has not changed, you can assign part of the information in the new cstore to the cstore on the original linked list, but most of the content remains unchanged, and then delete the new cstore instance. During the deletion process, some members need to be set to null, so that these spaces will not be deleted during the delete store operation, because these spaces must be used on the old cstore, because most of the content has not changed, especially the m_pdsk in cpartition has not changed, the content of the volume to which it points has not changed, so that resumable data transfer can be achieved.
Finally, what operations will the system perform during unmount. During unmount, the operations on the store must be completed. Determine whether the c_thread value of the vol member is 0. If the value is 0, it indicates that no thread is operating on the store, and then unmount is normal. If the value is not 0, it indicates that there are other threads that have not exited. In this case, create a thread to determine whether all operations are completed and set vol to unavailable, in this way, operations on the store will not be allowed. These unfinished thread operations will subtract c_thread from 1 at exit. If the variable is 0, setevent will tell the created judgment thread, in this way, the unmount operation will be executed.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/gooogleman/archive/2008/11/20/3339247.aspx