filesetup: fix win raw disk access and improve dir creation failure msg
authorSitsofe Wheeler <sitsofe@yahoo.com>
Sun, 1 Mar 2020 18:27:19 +0000 (18:27 +0000)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Sun, 1 Mar 2020 22:12:27 +0000 (22:12 +0000)
commit7273058c66b82508c5935f8c59c382db225383ae
treeb7105ecf816b1b68ac428d476b086ff0537bb399
parent58d3994d9be0783990af82571cea819b499d526c
filesetup: fix win raw disk access and improve dir creation failure msg

The commit df18600fd06258b96ae6f6b530ecdff541c2a82d ("filesetup: fix
directory creation issues") broke Windows raw/physical disk access
because Windows doesn't consider a path that only consists of a
namespace (such as the device namespace "\\.\" - see
https://docs.microsoft.com/en-gb/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#namespaces
for information on Windows' namespaces) to exist as a directory(!).

Workaround the issue for raw devices by explicitly considering the
device namespace subcomponent to always be valid. Further, intermediate
path components in UNC paths or paths starting with a namespace might
also not "exist" so introduce backwards scanning for the longest
pre-existing directory to sidestep this. The function doing this is made
available for non-windows platforms so a similar code path is used
everywhere.

Tests done:

Windows:
> ./fio.exe --name=dtest --thread --size=16k --rw=write `
  --filename 'fio.tmp'
> ./fio.exe --name=dtest --thread --size=16k --rw=write `
  --filename '\\?\C\:\Windows\Temp\fio\fio.tmp'
> Clear-Disk 1 -RemoveData -Confirm:$false # Destroys partition data!
> ./fio.exe --name=dtest --thread --size=16k --rw=write `
   --filename '\\.\PhysicalDrive1'
> ./fio.exe --name=dtest --thread --size=16k --rw=write `
  --filename '\fio.tmp'
> ./fio.exe --name=dtest --thread --size=16k --rw=write `
  --filename '\\LOCALHOST\Users\User\fio\fio.tmp'

macOS:
$ rm -rf /tmp/fio
$ ./fio --name=dtest --size=16k --filename /tmp/fio/fio.tmp \
  --rw=write

Finally, change the directory creation error message to give a human
error message rather than just an errno.

Fixes: https://github.com/axboe/fio/issues/916
Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
filesetup.c
os/os-windows.h