mount: make persist optional on mount, default to false
added -p argument to nfs_mount.exe to make the mount persist over reboots when -p is specified, we pass the flag CONNECT_UPDATE_PROFILE to WNetUseConnection(): "If this bit flag is set, the registry will store the connection information and make it available when the system reboots." Signed-off-by: Casey Bodley <cbodley@umich.edu>
This commit is contained in:
parent
62fa60a83a
commit
25ef4d25bb
1 changed files with 14 additions and 3 deletions
|
|
@ -38,6 +38,7 @@ DWORD EnumMounts(
|
||||||
static DWORD DoMount(
|
static DWORD DoMount(
|
||||||
IN LPTSTR pLocalName,
|
IN LPTSTR pLocalName,
|
||||||
IN LPTSTR pRemoteName,
|
IN LPTSTR pRemoteName,
|
||||||
|
IN BOOL bPersistent,
|
||||||
IN PMOUNT_OPTION_LIST pOptions);
|
IN PMOUNT_OPTION_LIST pOptions);
|
||||||
static DWORD DoUnmount(
|
static DWORD DoUnmount(
|
||||||
IN LPTSTR pLocalName,
|
IN LPTSTR pLocalName,
|
||||||
|
|
@ -58,6 +59,7 @@ static VOID PrintUsage(LPTSTR pProcess)
|
||||||
TEXT("\t-h\thelp\n")
|
TEXT("\t-h\thelp\n")
|
||||||
TEXT("\t-d\tunmount\n")
|
TEXT("\t-d\tunmount\n")
|
||||||
TEXT("\t-f\tforce unmount if the drive is in use\n")
|
TEXT("\t-f\tforce unmount if the drive is in use\n")
|
||||||
|
TEXT("\t-p\tmake the mount persist over reboots\n")
|
||||||
TEXT("\t-o <comma-separated mount options>\n")
|
TEXT("\t-o <comma-separated mount options>\n")
|
||||||
TEXT("Mount options:\n")
|
TEXT("Mount options:\n")
|
||||||
TEXT("\tro\tmount as read-only\n")
|
TEXT("\tro\tmount as read-only\n")
|
||||||
|
|
@ -74,6 +76,7 @@ DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
|
||||||
LPTSTR pRemoteName = NULL;
|
LPTSTR pRemoteName = NULL;
|
||||||
BOOL bUnmount = FALSE;
|
BOOL bUnmount = FALSE;
|
||||||
BOOL bForceUnmount = FALSE;
|
BOOL bForceUnmount = FALSE;
|
||||||
|
BOOL bPersistent = FALSE;
|
||||||
MOUNT_OPTION_LIST Options;
|
MOUNT_OPTION_LIST Options;
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
|
|
@ -108,6 +111,10 @@ DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
|
||||||
{
|
{
|
||||||
bForceUnmount = TRUE;
|
bForceUnmount = TRUE;
|
||||||
}
|
}
|
||||||
|
else if (_tcscmp(argv[i], TEXT("-p")) == 0) /* persistent */
|
||||||
|
{
|
||||||
|
bPersistent = TRUE;
|
||||||
|
}
|
||||||
else if (_tcscmp(argv[i], TEXT("-o")) == 0) /* mount option */
|
else if (_tcscmp(argv[i], TEXT("-o")) == 0) /* mount option */
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
|
|
@ -176,7 +183,7 @@ DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = DoMount(szLocalName, pRemoteName, &Options);
|
result = DoMount(szLocalName, pRemoteName, bPersistent, &Options);
|
||||||
if (result)
|
if (result)
|
||||||
PrintErrorMessage(result);
|
PrintErrorMessage(result);
|
||||||
}
|
}
|
||||||
|
|
@ -249,6 +256,7 @@ out:
|
||||||
static DWORD DoMount(
|
static DWORD DoMount(
|
||||||
IN LPTSTR pLocalName,
|
IN LPTSTR pLocalName,
|
||||||
IN LPTSTR pRemoteName,
|
IN LPTSTR pRemoteName,
|
||||||
|
IN BOOL bPersistent,
|
||||||
IN PMOUNT_OPTION_LIST pOptions)
|
IN PMOUNT_OPTION_LIST pOptions)
|
||||||
{
|
{
|
||||||
DWORD result = NO_ERROR;
|
DWORD result = NO_ERROR;
|
||||||
|
|
@ -274,7 +282,7 @@ static DWORD DoMount(
|
||||||
{
|
{
|
||||||
NETRESOURCE NetResource;
|
NETRESOURCE NetResource;
|
||||||
TCHAR szConnection[MAX_PATH];
|
TCHAR szConnection[MAX_PATH];
|
||||||
DWORD ConnectSize = MAX_PATH, ConnectResult;
|
DWORD ConnectSize = MAX_PATH, ConnectResult, Flags = 0;
|
||||||
|
|
||||||
ZeroMemory(&NetResource, sizeof(NETRESOURCE));
|
ZeroMemory(&NetResource, sizeof(NETRESOURCE));
|
||||||
NetResource.dwType = RESOURCETYPE_DISK;
|
NetResource.dwType = RESOURCETYPE_DISK;
|
||||||
|
|
@ -291,8 +299,11 @@ static DWORD DoMount(
|
||||||
NetResource.lpComment = (LPTSTR)pOptions->Buffer;
|
NetResource.lpComment = (LPTSTR)pOptions->Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bPersistent)
|
||||||
|
Flags |= CONNECT_UPDATE_PROFILE;
|
||||||
|
|
||||||
result = WNetUseConnection(NULL,
|
result = WNetUseConnection(NULL,
|
||||||
&NetResource, NULL, NULL, 0,
|
&NetResource, NULL, NULL, Flags,
|
||||||
szConnection, &ConnectSize, &ConnectResult);
|
szConnection, &ConnectSize, &ConnectResult);
|
||||||
|
|
||||||
if (result == NO_ERROR)
|
if (result == NO_ERROR)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue