Convert DeviceLanmanRedirectorservernamesharenameFile.ext to DeviceHaddiskVolume1File.ext

Hello!

Please explaine how to convert shared file name, like:

\Device\LanmanRedirector\servername\sharename\File.ext

to local path, like:

\Device\HaddiskVolume1\File.ext

Thanks,
Max.

It’s impossible, because of the two paths don’t relate each other anyway.
The first one is a correct file name for a network file, while the other is
for a file stored on a local drive.

Best regards,
Valeriy Glushkov

ïÔ: “ëÒÉ×ÏÈÉÖÁ íÁËÓÉÍ”
ëÏÍÕ: “Windows File Systems Devs Interest List”
ïÔÐÒÁ×ÌÅÎÏ: 7 ÓÅÎÔÑÂÒÑ 2005 Ç. 16:57
ôÅÍÁ: [ntfsd] Convert DeviceLanmanRedirectorservernamesharenameFile.ext to
DeviceHaddiskVolume1File.ext

> Hello!
>
> Please explaine how to convert shared file name, like:
>
> \Device\LanmanRedirector\servername\sharename\File.ext
>
> to local path, like:
>
> \Device\HaddiskVolume1\File.ext
>
> Thanks,
> Max.
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: gvvua@ua.fm
> To unsubscribe send a blank email to xxxxx@lists.osr.com

> Please explaine how to convert shared file name, like:

\Device\LanmanRedirector\servername\sharename\File.ext
to local path, like:
\Device\HaddiskVolume1\File.ext

Below is my rather naive attempt of a user-mode implementation of something
close to what you are asking.

I had to discard it along the way because I hate things that “kinda work” (=
work sometimes), but if it helps [possibly to see what NOT to do:-)]…

The code compiles/links in a console project under VS7.1 on /W4.

Regards,
Alex Shvedov

// MakePathLocal.h
#pragma once
#include <windows.h>
#include
std::wstring MakePathLocal(std::wstring& path);

// MakePathLocal.cpp
#include “MakePathLocal.h”
//#pragma message(“Compiling " FILE” last modified on " TIMESTAMP )
/ wsa
#include <winsock2.h> // should go BEFORE <windows.h> !!!
#pragma comment(lib, “Ws2_32”)
wsa /
#include <windows.h>
#include
#define Elts(array) (sizeof(array) / sizeof(array[0]))
#define SLASH_LANMAN_SLASH L"\Device\LanmanRedirector\“
#define SLASH_LANMAN_SLASH_L (Elts(SLASH_LANMAN_SLASH) - 1)
#define SLASH_DEVICE_SLASH L”\Device\“
#define SLASH_DEVICE_SLASH_L (Elts(SLASH_DEVICE_SLASH) - 1)
#define SLASH_QQ_SLASH L”\??\“
#define SLASH_QQ_SLASH_L (Elts(SLASH_QQ_SLASH) - 1)
int FindSbstrNoCase(wchar_t* str, wchar_t* substr) {
int strPos, substrL = (int)wcslen(substr);
for(strPos = 0; str[strPos]; ++strPos) {
if(!_wcsnicmp(&str[strPos], substr, substrL)) {
return strPos + substrL;
}
}
return -1;
}
std::wstring TryToCorrectInNetUseCase(wchar_t* bbb, wchar_t* hstname,
std::wstring& path) {
int pos;
std::wstring newOne;
if((pos = FindSbstrNoCase(bbb, hstname)) != -1) {
if(pos + 2 >= (int)wcslen(bbb)) {
return newOne; // error
}
if(bbb[pos + 2] != L’$') {
return newOne; // error
}
bbb[pos + 2] = 0;
newOne = &bbb[pos + 1]; // just the frive letter so far
newOne.append(&path.c_str()[1]); // now add :.…
}
return newOne;
}
std::wstring MakePathLocal(std::wstring& path) {
// path = “W:!ClientSolutions\VolInExts\Debug\VolInExts.sys”
/ wsa
struct hostent* eee = 0;
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
if(WSAStartup(wVersionRequested, &wsaData))
return 0; // winsock init error
eee = gethostbyname(“localhost”); // eee->h_name = “alshvedov.xpoint.com
WSACleanup();
wsa /
std::wstring newOne;
if(path.length() < 3)
return newOne; // error, I expect a FULL path, “C:\a” at least
wchar_t bbb[_MAX_PATH + 1] = {0}; // _MAX_PATH does not have any special
DWORD bbbl = 666; // meaning - it’s just “long enough”
wchar_t driveName = L” :";
driveName[0] = path[0];
SetLastError(ERROR_SUCCESS);
bbbl = QueryDosDeviceW(driveName, bbb, Elts(bbb) - 1);
// bbb = “??\F:\wutemp” after subst
// bbb = “\Device\LanmanRedirector;V:000000000000bcef\alshvedov\f$”
// after “net use v: \alshvedov\f$”
// or “\Device\LanmanRedirector;P:00000000000181dd\localhost\d$”
// after “net use p: \localhost\d$”
// for “normal” devices
// logical drive <a:>:
// device name #1: <\Device\Floppy0>
// or
// logical drive <f:>:
// device name #1: <\Device\HarddiskVolume4>
if(!bbbl)
return newOne; // error in QueryDosDeviceW
if(wcsncmp(bbb, SLASH_LANMAN_SLASH, SLASH_LANMAN_SLASH_L)
&& !wcsncmp(bbb, SLASH_DEVICE_SLASH, SLASH_DEVICE_SLASH_L)) { // “normal”
drive case
return path; // (hard or floppy)
}
if(!wcsncmp(bbb, SLASH_QQ_SLASH, SLASH_QQ_SLASH_L)) { // “subst” case
newOne = &bbb[SLASH_QQ_SLASH_L];
newOne.append(&path.c_str()[2]);
} else if(!wcsncmp(bbb, SLASH_LANMAN_SLASH, SLASH_LANMAN_SLASH_L)) { // “net
use” case
wchar_t netBiosName[MAX_COMPUTERNAME_LENGTH + 1], localhost = L"localhost";
// try “localhost” first:
newOne = TryToCorrectInNetUseCase(bbb, localhost, path);
if(!newOne.length()) {
// if it fails, try NetBIOS name:
DWORD netBiosNameL = Elts(netBiosName);
if(!GetComputerNameW(netBiosName, &netBiosNameL)) { // netBiosName =
“ALSHVEDOV”
return newOne; // error in GetComputerNameW
}
newOne = TryToCorrectInNetUseCase(bbb, netBiosName, path);
}
}
return newOne;
}
/

logical drive <v:>: (after net use v: \alshvedov\f$)
device name #1: <\Device\LanmanRedirector;V:000000000000bcef\alshvedov\f$>
V:\ - volume name=, FS=NTFS flags=0x700ff serial=1018613722
maxFileNameLength=255
GetVolumeNameForVolumeMountPoint for V:\ failed with code 0x3
logical drive <w:>: (after subst w: f;\wutemp)
device name #1: <??\F:\wutemp>
W:\ - volume name=, FS=NTFS flags=0x700ff serial=1018613722
maxFileNameLength=255
GetVolumeNameForVolumeMountPoint for W:\ failed with code 0x57
*/

----- Original Message -----
From: “Valeriy Glushkov”
To: “Windows File Systems Devs Interest List”
Sent: Thursday, September 08, 2005 4:42 AM
Subject: Re: [ntfsd] Convert
DeviceLanmanRedirectorservernamesharenameFile.ext to
DeviceHaddiskVolume1File.ext

> It’s impossible, because of the two paths don’t relate each other anyway.
> The first one is a correct file name for a network file, while the other
> is
> for a file stored on a local drive.
>
> Best regards,
> Valeriy Glushkov
>
> ïÔ: “ëÒÉ×ÏÈÉÖÁ íÁËÓÉÍ”
> ëÏÍÕ: “Windows File Systems Devs Interest List”
> ïÔÐÒÁ×ÌÅÎÏ: 7 ÓÅÎÔÑÂÒÑ 2005 Ç. 16:57
> ôÅÍÁ: [ntfsd] Convert DeviceLanmanRedirectorservernamesharenameFile.ext to
> DeviceHaddiskVolume1File.ext
>
>
>> Hello!
>>
>> Please explaine how to convert shared file name, like:
>>
>> \Device\LanmanRedirector\servername\sharename\File.ext
>>
>> to local path, like:
>>
>> \Device\HaddiskVolume1\File.ext
>>
>> Thanks,
>> Max.
>>
>> —
>> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: gvvua@ua.fm
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@bellsouth.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
></w:></v:></f:></a:></windows.h></windows.h></winsock2.h></windows.h>

You cannot.

The file is not local by definition, and you know nothing about the server
except that it supports the SMB protocol.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “ëÒÉ×ÏÈÉÖÁ íÁËÓÉÍ”
To: “Windows File Systems Devs Interest List”
Sent: Wednesday, September 07, 2005 5:57 PM
Subject: [ntfsd] Convert DeviceLanmanRedirectorservernamesharenameFile.ext to
DeviceHaddiskVolume1File.ext

> Hello!
>
> Please explaine how to convert shared file name, like:
>
> \Device\LanmanRedirector\servername\sharename\File.ext
>
> to local path, like:
>
> \Device\HaddiskVolume1\File.ext
>
> Thanks,
> Max.
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com