Part 2: attach a virtual disk using truecrypt Mount
After creating an encrypted volume, how can I use a virtual disk? At this time, you need to load the virtual disk. After loading the virtual disk, an extra partition will be added to the disk partition. For example, you can see a new local disk (L :) on my computer :). So how is it implemented in truecrypt? First, select the encrypted volume we created in the previous step and select a partition to be loaded. In fact, this is to select one in the unused partition volume label, and then click load and load, at this time, you will find the encrypted volume for loading. At this time, you need to enter the password you set when creating the encrypted volume. After loading, you will be able to see the new virtual disk.
Therefore, another core function of truecrypt to load a virtual disk is to accept parameters such as encrypted volumes, disk partitions, and user passwords. In the prototype of truecrypt, this function is
Int mountvolume (hwnd hwnddlg, <br/> int driveno, <br/> char * volumepath, <br/> password * password, <br/> bool cachepassword, <br/> bool sharedaccess, <br/> mountoptions * mountoptions, <br/> bool quiet, <br/> bool breportwrongpassword)
Next, let's take a look at the specific meaning of each parameter.
Parameters |
Type |
Description |
Example |
Hwnddlg |
Hwnd |
Input window handle |
Null |
Driveno |
Int |
Partition Number of the attached Disk |
8 |
Volumepath |
Char * |
Encrypted volume file selected |
C: // 1.txt |
Password |
Password |
Password entered by the user |
123456 |
Cachepassword |
Bool |
Indicates whether a cache password is used. |
False |
Sharedaccess |
Bool |
|
False |
Mountoptions |
Mountoptions |
Loading options |
|
Quiet |
Bool |
|
False |
Breportwrongpassword |
Bool |
Indicates whether an incorrect password is reported. |
True |
The result returned by the mountvolume function is
-1. The user terminates loading.
0 failed to load
1 loaded successfully
2. Shared Mode loaded successfully
Next let's look at the specific example
Int Mount (char * szfile, char * szpassword, int ndriveno, hwnd hwnddlg) <br/>{< br/> int ndosdriveno; <br/> char szfilename [tc_max_path + 1];/* the file selected by the user */<br/> password volumepassword; /* password used for mounting volumes */<br/> bool bcacheindriver = false;/* cache any passwords we see */<br/> bool bforcemount = false; /* Mount volume even if host file/device already in use */<br/> mountoptions; <br/> int mounted = 0; <br/> // ndosdriveno = 8; <br/> ndosdriveno = ndriveno; <br/> // strcpy (szfilename, "C: // 1.txt "); <br/> // szfilename [8] = 0; <br/> strcpy (szfilename, szfile); <br/> szfilename [strlen (szfile)] = 0; <br/> bcacheindriver = false; <br/> bforcemount = false; <br/> // strcpy (volumepassword. text, "123456"); <br/> strcpy (volumepassword. text, szpassword); <br/> volumepassword. length = strlen (volumepassword. text); <br/> mountoptions. persistentvolume = 0; <br/> mountoptions. preservetimestamp = 1; <br/> strcpy (mountoptions. protectedhidvolpassword. text, ""); <br/> mountoptions. protectedhidvolpassword. length = 0; <br/> mountoptions. protecthiddenvolume = 0; <br/> mountoptions. readonly = 0; <br/> mountoptions. removable = 0; <br/> mountoptions. systemvolume = 0; <br/> mounted = mountvolume (hwnddlg, ndosdriveno, szfilename, & volumepassword, bcacheindriver, <br/> bforcemount, & mountoptions, false, true ); <br/> If (mounted = 1) <br/> return 1; <br/> else <br/> return 0; <br/> return 1; <br/>}
After the virtual disk is successfully created, a virtual disk is displayed. You can create files in the virtual disk. Files in the Virtual Disk are encrypted to the encrypted volume file specified by the user, anyone who wants to see the files in the Virtual Disk needs to load the virtual disk and enter the correct password.