Author eryksun
Recipients Kevin.Norris, eryksun, pitrou, steve.dower, tim.golden, zach.ware
Date 2014-09-07.18:03:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410113032.32.0.36031178343.issue22299@psf.upfronthosting.co.za>
In-reply-to
Content
> If you take "//?/C:/" and join it with e.g. "foo", you get an 
> absolute path (or, if you remove the drive's trailing slash, you 
> get something that's invalid AFAIK).

FYI, DOS device names such as "C:" are NT symlinks. Win32 looks for DOS device links in NT's \Global?? directory, and also per logon-session in \Sessions\0\DosDevices\LOGON_ID. 

A link named "C:foo" is actually possible:

    >>> windll.kernel32.DefineDosDeviceW(0, "C:foo", "C:\\Python34")
    1
    >>> gfpn = os.path._getfinalpathname
    >>> gfpn(r'\\?\C:foo')
    '\\\\?\\C:\\Python34'
    >>> os.listdir(r'\\?\C:foo')
    ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'pythonw.exe', 'README.txt', 'Scripts', 'tcl', 'Tools']

GLOBALROOT links to the native NT root:

    >>> gfpn('\\\\?\\GLOBALROOT\\Global??\C:\\')
    '\\\\?\\C:\\'
    >>> gfpn('\\\\?\\GLOBALROOT\\Device\\HarddiskVolume1\\')   
    '\\\\?\\C:\\'
    >>> gfpn(r'\\?\GLOBALROOT\SystemRoot') 
    '\\\\?\\C:\\Windows'
    >>> p = r'\\?\GLOBALROOT\Sessions\0\DosDevices\00000000-0f341de9\C:foo'        
    >>> gfpn(p)
    '\\\\?\\C:\\Python34'

Without the \\?\ prefix, "C:foo" is relative to the current directory on the C: drive:

    >>> os.chdir('C:\\')
    >>> os.mkdir('foo')
    >>> os.listdir('C:foo')
    []

where the current directory on C: is stored in the "=C:" environment variable:

    >>> buf = (c_wchar * 100)()                
    >>> windll.kernel32.GetEnvironmentVariableW("=C:", buf)
    3
    >>> buf.value
    'C:\\'
History
Date User Action Args
2014-09-07 18:03:52eryksunsetrecipients: + eryksun, pitrou, tim.golden, zach.ware, steve.dower, Kevin.Norris
2014-09-07 18:03:52eryksunsetmessageid: <1410113032.32.0.36031178343.issue22299@psf.upfronthosting.co.za>
2014-09-07 18:03:52eryksunlinkissue22299 messages
2014-09-07 18:03:51eryksuncreate