[WinAPI] API 6 [Operation Drive mount Point]

Source: Internet
Author: User

Drive mount points, which can also be called volume mount points. A mount point is actually an operating system or user-set that is used to enter a logical drive or a volume entry. After you set a mount point for a volume, the user or application can use the volume label or the specified mount point to enter the volume. For example, under "C: \" Set a "e\," the volume mount point mnt, then open "e:\" and Open "C:\mnt" is actually into the "e:\" volume.
In general, you can use the Findfirstvolumemountpoint series API to find all the mount points of a volume; Getvolumenameforvolumemountpoint to get the volume name pointed to by the specified mount point, the volume name is "\\?\volume{guid}\", and the new mount point is set with Setvolumemountpoint.

The Disk Management feature of the system allows you to set the mount point of a volume:

◇ "My Computer" icon in the right-click menu, select "Manage".
◇ the "Computer Management" window appears, select "Disk Management".
◇ Select the volume you want to mount, select "Change Drive name and path" in the right-click menu.
◇ Click the "Add" button in the Pop-up dialog box and select "Mount the following blank NTFS folder".
◇ Select the folder (blank) to which you want to mount the volume, and click the OK button.
◇ the volume is loaded into the folder, then you can access the volume and access the folder one.

(1) Findfirstvolumemountpoint.
Gets the first mount point of a specified volume

◇ Parameters
Lpszrootpathname: Enter a parameter that specifies the name of the volume to find and must end with a backslash.
Lpszvolumemountpoint: Output parameter, find the first mount point.
Cchbufferlength. The input parameter, which is used to store the size of the cache for the output mount point.
◇ return value
Returns a handle value, which, for a lookup handle, Findnextvolumemountpoint finds the next mount point with the handle. The error value is INVALLD HANDLE value to obtain a more detailed error message with the GetLastError () function.


(2) Findnextvolumemountpoint
Find a successor mount point for a specified volume

◇ Parameters
Hfindvolumemountpoint: input parameter, find handle, obtained by Findfirstvolumemountpoint.
Lpszvolumemountpoint: Output parameter, find the successor Mount point.
Cchbufferlength: input parameter to store the size of the cache for the output mount point.
◇ return value
Returns a bool value indicating whether the lookup succeeded, failed, and the GetLastError function returned an error no_ more
file$ code indicates that all mount points have been found.


(3) Findvolumemountpointclose.
Closing a findvolumemountpointclose open volume handle

◇ Parameters
Hfindvolumemountpoint: The mount point lookup handle to close.
◇ return value


(4) Getvolumenameforvolumemountpoint.
Gets the corresponding volume device name based on the specified mount point

◇ Parameters
Lpszvolumemountpoint: input parameter, specify the need to find the mount point or root directory, ending with a backslash.
Lpszvolumename: Output parameter, the volume device name corresponding to the mount point, in the form "\\?\volume{guid}\".

Cchbufferlength: input parameter to store the cache size of the output device name.
◇ return value
Returns a bool value that indicates whether the function was successful, and can also use the GetLastError function to obtain more detailed error information.


(5) Setvolumemountpc
Mounts the specified volume to the specified mount point

◇ Parameters
Lpszvolumemountpoint: input parameter, specified mount point, mount point must be either a root path or a path on an existing volume, must end with a backslash.
Lpszvolumename: Input parameters, volume device name, in the form of "\\?\volume{guid}\".
◇ return value
Returning a bool value indicates whether the function was successful, and you can also use the GetLastError () function to obtain more detailed error information.

  1 #define _WIN32_WINNT 0x0501 2 #include <windows.h> 3 #include <stdio.h> 4 #include <tchar.h> 5 #  Define BUFSIZE MAX_PATH 6 #define FILESYSNAMEBUFSIZE MAX_PATH 7 8/* ************************************ 9 * Processvolumemountpoint 10 * Function List mount point one **************************************/processvolumemountpoint BOOL (HAND LE hPt, TCHAR *ptbuf, DWORD dwptbufsize, TCHAR, *buf) 15      {Bflag BOOL; Results TCHAR Path[bufsize];   Full path TCHAR target[bufsize]; mount point device, printf ("\tvolume mount points found is \"%s\ "\ n", ptbuf); lstrcpy (Path, Buf); Lstrcat (Path, ptbuf); Bflag = Getvolumenameforvolumemountpoint (path,target,bufsize); if (!bflag), printf ("\tattempt to get volume name for%s failed.\n", Path); else-printf ("\ttarget of the volume mount point is%s.\n", Target); -BFlag = Findnextvolumemountpoint (hpt,ptbuf,dwptbufsize); return (Bflag); * * * ************************************ * Processvolume 37 * Function to determine the volume type, listing mount point 38 ********************************           /processvolume bool (HANDLE hvol, TCHAR *buf, DWORD ibufsize), +------+--bool bflag;           return sign HANDLE hPt; Volume handle TCHAR ptbuf[bufsize];     mount point path: DWORD dwsysflags; File system tag TCHAR filesysnamebuf[filesysnamebufsize]; printf ("Volume found is \"%s\ ". \ n", Buf); 48 49//whether NTFS getvolumeinformation (Buf, NULL, 0, NULL, NULL, Wuyi &dwsysflags, Filesysnamebuf, 5 2 filesysnamebufsize); if (!  (Dwsysflags & File_supports_reparse_points))  ("\tthis file system does not support volume Mount points.\n"); 60//mount point in this volume hPt = Findfirstvolumemountpoint (Buf,//volume with Trace ptbuf,//Hang Load Point path 64 BUFSIZE 65); if (hPt = = Invalid_handle_value) ("\tno Volume mount points found!\n")  + {73//processing mount point bflag = Processvolumemountpoint (HPt, Ptbuf, BUFSIZE, Buf); 78//Cyclic (bflag) bflag = Bayi Processvolumemountpoint (HPt, Ptbuf, BUFSIZE, Buf); 82//End Findvolumemountpointclose (hPt); 84} 85} 86 87//Next bflag = Findnextvolume (Hvol, Buf, ibufsize);  (Bflag); * * * ************************************ 94 * int getmountpoint (void) 95 * function Get mount point 96 ****************************   /Getmountpoint int (void) 98 {TCHAR buf[bufsize];      Volume identifier: HANDLE Hvol;      Volume handle 101 BOOL bflag; Result Flag 102 103 printf("Volume mount points info of this computer:\n\n"); 104//Open Volume Hvol = Findfirstvolume (buf, BUFSIZE); 106 if (Hvol = = invalid_handle_value) 107 {108 printf ("No volumes found!\n"); 109 return (-1); 110}111 11 2 bflag = Processvolume (Hvol, buf, BUFSIZE), 113 while (Bflag), {bflag = Processvolume (Hvol, b UF, BUFSIZE);}117 118 bflag = Findvolumeclose (Hvol); 119 return (bflag); 120}121 122/* ***************** 123 * void usage (PCHAR argv) 124 * Function usage method **************************************/126 void usage (PC HAR argv) 127 {$ printf ("\n\n\t%s, mount a volume at a Mount point.\n", argv); 129 printf ("\tfor example, \" MoU NT d:\\mnt\\drives\\ e:\\\ "\ n"),}131/* ************************************133 * main134 * function entry function 135 **********    /136 int main (int argc, PCHAR argv[]) 137 {138 BOOL bflag;139 CHAR buf[bufsize]; 141 if (argc! = 3 ) 142 {143 getmountpoint (); 144 Usage (argv[0]); 145 return (-1); 146}147 148 bflag =         Getvolumenameforvolumemountpointa (149 argv[2],//input mount point or directory Buf,//output volume name 151 BUFSIZE152 ); 153 154 if (bflag! = TRUE) 155 {156 printf ("Retrieving volume name for%s failed.\n", argv[2]); 1 ( -2); 158}159 ("Volume name of%s is%s\n", argv[2], Buf); 161 bflag = Setvolumem         Ountpointa (162 argv[1],//mount point 163 Buf//volume to be mounted 164); 165 166 if (!bflag) 167 {168 printf ("Attempt to mount%s at%s failed. Error code is\n, 169 argv[2], argv[1], GetLastError ());}171 172 return (bflag); 173}

Http://www.cnblogs.com/zjutlitao/p/3585462.html

[WinAPI] API 6 [Operation Drive mount Point]

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.