#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#define BUFSIZE MAX_PATH
#define Filesysnamebufsize MAX_PATH
/**************************************
* Processvolumemountpoint
* Function: List mount point
**************************************/
BOOL Processvolumemountpoint (HANDLE hPt,
TCHAR *ptbuf,dword Dwptbufsize,
TCHAR *buf)
{
BOOL bflag;//Results
TCHAR path[bufsize];//Full path
TCHAR target[bufsize];//mount point Equipment
printf ("\tvolume mount point found is \"%s\ "\ n", ptbuf);
lstrcpy (PATH,BUF);
Lstrcat (PATH,BUF);
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
* Function: Determine volume type, list mount point
*******************************************************/
BOOL Processvolume (HANDLE hvol,tchar *buf,dword ibufsize)
{
BOOL bflag;//return Flag
HANDLE hpt;//Volume handle
TCHAR ptbuf[bufsize];//mount point Path
DWORD dwsysflags;//File System token
TCHAR Filesysnamebuf[filesysnamebufsize];
printf ("Volume found is \"%s\ ". \ n", Buf);
GetVolumeInformation (Buf,null,0,null,null,
&dwsysflags,filesysnamebuf,filesysnamebufsize);
if (! ( Dwsysflags & File_supports_reparse_points))
{
printf ("\tthis file system does not support volume Mount points.\n");
}
Else
{
Mount points in this volume
HPt = Findfirstvolumemountpoint (
Path to the buf,//volume
ptbuf,//mount point Path
BUFSIZE);
if (hPt = = INVALID_HANDLE_VALUE)
{
printf ("\tno Volume mount points found!\n");
}
Else
{
Handling mount points
Bflag = Processvolumemountpoint (HPt,
PTBUF,BUFSIZE,BUF);
while (Bflag)
Bflag = Processvolumemountpoint (HPT,PTBUF,BUFSIZE,BUF);
Findvolumemountpointclose (hPt);
}
}
Next
Bflag = Findnextvolume (hvol,buf,ibufsize);
return bflag;
}
/*********************
* int getmountpoint (void)
* Function: Get mount point
*********************/
int getmountpoint (void)
{
TCHAR buf[bufsize];//Volume identifier
HANDLE hvol;//Volume handle
BOOL bflag;//End Flag
printf ("Volume mount points info of this computer:\n\n");
Hvol = Findfirstvolume (buf,bufsize);
if (Hvol = = INVALID_HANDLE_VALUE)
{
printf ("No volumes found!\n");
return-1;
}
Bflag = Processvolume (hvol,buf,bufsize);
while (Bflag)
{
Bflag = Processvolume (hvol,buf,bufsize);
}
Bflag = Findvolumeclose (Hvol);
return bflag;
}
/***********************
* void Usage (PCHAR argv)
* Function: How to use
***********************/
void Usage (PCHAR argv)
{
printf ("\n\n\t%s,mount a volume at a Mount point.\n", argv);
printf ("\tfor example, \" Mount d:\\mnt\\drives\\e:\\\ "\ n");
}
/*****************************
* Main
* Function: Entry function
*****************************/
int main (int argc,pchar argv[])
{
BOOL Bflag;
CHAR Buf[bufsize];
if (argc! = 3)
{
Getmountpoint ();
Usage (Argv[0]);
return-1;
}
Bflag = Getvolumenameforvolumemountpoint (
argv[2],//input mount point or directory
buf,//Output Volume name
BUFSIZE);
if (bflag! = TRUE)
{
printf ("Retrieving volume name for%s failed.\n");
Return-2;
}
printf ("Volume name of%s is%s\n", argv[2],buf);
Bflag = Setvolumemountpoint (
argv[1],//mount point
buf//a volume that needs to be mounted
);
if (!bflag)
{
printf ("Attempt to mount%s at%s failed.error code is\n", Argv[2],argv[1],getlasterror ());
}
GetChar ();
return bflag;
}
Learning API Sets the mount point of a volume, listing the mount points and paths that are in the specified volume