The findfirststore function reads Windows Mobile Data by sector

Source: Internet
Author: User

Read Windows Mobile Data by sector

Http://dev.mmarket.com/cmdn/bbs/redirect.php? Tid = 114 & goto = lastpost

In mobile device program development, we can refer to the development methods of desktop computers in many places. For example, MFC not only supports desktop computers, but also supports Windows Mobile 5 mobile devices.
/E: l) M # D5 S6 Y % S0 D ~ : S3 L; y0 h # d
Because the architecture of mobile devices is similar to that of desktop computers, they are composed of CPU, memory, and non-volatile memory. Therefore, for file system management, introducing a file system on a PC to a mobile device is a good choice. For example, Windows Mobile 5 (based on Windows CE 5.0 kernel) adopts the tfat32 file format. Compared with the FAT32 file system, tfat32 enhances security. China Mobile developer community; M4 I) M1 F! K! M
7 U! Q #? 7 M8 F +/8? /^ * P
Microsoft's API provides the createfile function, which should be very familiar to programmers. The createfile function can not only operate files, but also various Io devices, such as disks and comports. Windows Mobile 5 divides the entire non-volatile memory (often flash) into several logical partitions, which are roughly treated as flash, there are usually three operating system areas, data backup areas, and user areas. Therefore, you can use the createfile function to operate these logical disks. & I! G2 P3 N3 S1 W8 Z/| # H
Developer community forum: t x;] 6 D0 J6 G: O
First, you can use the findfirststore and findnextstore functions to find the storage device. These functions need to use storemgr. H and storeapi. lib file, both of which are available in the Windows Mobile 5 SDK. The above function can be used to obtain the device name of the storage device, such as DSK: 1. These will be used as parameters of createfile. After the SD card is inserted to my device, four device names are obtained: dsk1 to dsk4, where dsk1 is the partition where the system is located, the file format is unknown, and dsk2 is the backup zone, this is the region used to restore the factory settings. dsk3 is the user data zone. We usually store text messages and music files here, which is the only place users can use, dsk4 is the SD card. Dev.mmarket.com * m2 s "?! /& W & P
6 B4 p! @ 7 F-D! G
When you use createfile to open the device, you cannot use readfile to read data. The specific reason is unclear. It may be that the file system driver does not provide support. How to read data? Use the deviceiocontrol function to set the read flag disk_ioctl_read. At the same time, use sg_req as the third parameter of the function. sg_req is a struct, it specifies the start sector of the disk to be read and the number of read sector. This struct is contained in diskio. h, but diskio. windows Mobile 5.0 SDK does not have an H file. I copied it from the directory in pb5.0. "I (q0 t" l % J "[4 f
7 d "A $ F5 Q2 @ $'6 T5 B) T )? @
The findfirststore function and findnextstore function can be called to obtain the number of disk sectors. Therefore, you only need to read the data of each disk of Windows Mobile based on the number of sectors obtained. And then write it into the USB flash drive and other devices, then open the USB flash drive is like opening the windows mobile device. However, a problem was found. After reading the data in the user zone, you must remove the 512*2 bytes in the header and then write the data to the USB flash drive to enable the USB flash drive. Otherwise, the system will prompt that the USB flash drive is not formatted. I don't know why. Maybe it's the difference between tfat and fat. From: http://blog.163.com/wu_congchao/blog/static/354264720088253476730/

Void enumstore ()
{
Storeinfo stinfo = {0 };
Handle hpart = invalid_handle_value;
Handle hstore;
Tchar szinfo [100] = _ T ("");

Stinfo. cbsize = sizeof (storeinfo );

Hstore = findfirststore (& stinfo );
If (hstore! = Invalid_handle_value)
{
Do {
Retailmsg (1, (text ("partion number: % LD/N"), stinfo. dwpartitioncount ));
Size2string (stinfo. snnumsectors * stinfo. dwbytespersector, szinfo, 100 );
Retailmsg (1, (text ("enumpartion: % s szinfo = % s/n"), stinfo. szdevicename, szinfo ));
Size2string (stinfo. dwbytespersector, szinfo, 100 );
Retailmsg (1, (text ("enumpartion: % s dwbytespersector = % s/n"), stinfo. szdevicename, szinfo ));

Enumpartion (stinfo. szdevicename, "// hard disk2 //");

} While (findnextstore (hstore, & stinfo ));
}
Findclosestore (hstore );
}
Longlong enumpartion (lpctstr devicename, cstring szpartionname)
{
Partinfo = {0 };
Storeinfo stinfo = {0 };
Handle hpart = invalid_handle_value;
Handle hstore = invalid_handle_value;

Tchar szinfo [100] = _ T ("");
 
Stinfo. cbsize = sizeof (storeinfo );
Partinfo. cbsize = sizeof (partinfo );
 
Hstore = openstore (devicename );
 
If (invalid_handle_value! = Hstore)
{
 
If (getstoreinfo (hstore, & stinfo) = false)

Return 0;

Hpart = findfirstpartition (hstore, & partinfo );
If (hpart = invalid_handle_value)
Retailmsg (1, (text ("no find partion Info ")));
If (hpart! = Invalid_handle_value)
{
 
Do {
Retailmsg (1, (text ("enumpartion: % s/n"), partinfo. szvolumename ));
If (szpartionname. Right (1). Compare (_ T ("//") = 0)

Szpartionname = szpartionname. Left (szpartionname. getlength ()-1 );
If (szpartionname. Compare (partinfo. szvolumename) = 0)
{
Closehandle (hstore );
Findclosepartition (hpart );
Return partinfo. snnumsectors * stinfo. dwbytespersector;
}
} While (findnextpartition (hpart, & partinfo ));
}
}
Closehandle (hstore );
Findclosepartition (hpart );
Return 0l;

}
//

Get disk space: http://blog.163.com/wu_congchao/blog/static/354264720088253465799/

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.