Platform SDK: Files and I/O |
The following sample demonstrates how to mount a file system.
This sample uses the following functions: GetVolumeNameForVolumeMountPoint and SetVolumeMountPoint.
#define _WIN32_WINNT 0x0500 #include <windows.h> #include <stdio.h> #define BUFSIZE 1024 // ample space for our string buffer void Syntax (char *argv) { printf( "%s, mount a volume at a mount point.\n", argv ); printf( "For example, \"mount c:\\mnt\\fdrive\\ f:\\\"\n" ); } int main( int argc, char *argv[] ) { BOOL bFlag; char Buf[BUFSIZE]; // temporary buffer for volume name if( argc != 3 ) { Syntax( argv[0] ); return( -1 ); } // We should do some error checking on the inputs. Make sure // there are colons and backslashes in the right places, etc. bFlag = GetVolumeNameForVolumeMountPoint( argv[2], // input volume mount point or directory Buf, // output volume name buffer BUFSIZE // size of volume name buffer ); if (bFlag != TRUE) { printf( "Retrieving volume name for %s failed.\n", argv[2] ); return (-2); } printf( "Volume name of %s is %s\n", argv[2], Buf ); bFlag = SetVolumeMountPoint( argv[1], // mount point Buf // volume to be mounted ); if (!bFlag) printf ("Attempt to mount %s at %s failed.\n", argv[2], argv[1]); return (bFlag); }