MinGW-w64 – no disk in drive

I have downloaded and installed mingw-w64 (64bit/gcc 4.9.1) tool chains.

Mingw-w64/Targetting 64Bit/MinGW-Builds/4.9.1/Win32Thread/SEH

The problem is that ‘No Disk In Drive D:’ dialog is appear when I execute gcc.exe.
It is caused by hard coded reference ‘D:/msys64’.

I made tiny patch program to resolve this issue.
It will change the path string ‘D:/msys’ to ‘C:/msys’.

How to apply.

  1. Save patch program. mingwpatch.zip
  2. change directory to mingw64 installed folder.
    ex. cd /D C:\MinGW64\
  3. execute patch program with Lua 5.1, 5.2 or LuaJIT 2.0.
    ex. lua mingwpatch.lua

I hope this will help you.

-- search text must be short < = 8bytes
local illegal_path = '[a-zA-Z]:/msys'

local function GetCurrentDir()
    local cwd = io.popen('cmd /c cd', 'r')
    current_directory = cwd:read('*l')
    cwd:close()
    return current_directory
end

local function GetAllFiles(path)
    local files = io.popen('cmd /c dir /a-d /b /s ' .. path, 'r')
    local result = {}
    for file in files:lines() do
        if file and file ~= '' then
            table.insert(result, file)
        end
    end
    files:close()

    return result
end

local function ConfirmMessage(msg)
    io.stdout:write(tostring(msg) .. ' [yes/No]: ')
    local confirm = io.read('*l')
    confirm = confirm and string.lower(confirm)

    if confirm == 'y' or confirm == 'yes' then
        return true
    end

    return false
end

local function CheckFile(file)
    local f = io.open(file, 'rb')
    if not f then
        return false
    end

    local b = f:read('*all')
    f:close()

    local s,e
    s = 1
    while s < #b do
        s,e = string.find(b, illegal_path, s)
        if not s then
            return false
        end

        local drive_letter = string.sub(b, s, s)
        if (drive_letter ~= 'c') and (drive_letter ~= 'C') then
--~             io.stdout:write('f(' .. string.sub(b, s, e) .. ')')
            return true
        end
        s = s + 1
    end

    return false
end

local function SearchTargetFiles(files)
    local result = {}

    for _,file in ipairs(files) do
        if CheckFile(file) then
            table.insert(result, file)
        end
    end

    return result
end

local function Patch(file)
    local f = io.open(file, 'rb')
    if not f then
        return false
    end

    local b = f:read('*all')
    f:close()

    local s,e,l,t,p
    s = 1
    l = #b
    t = {}
    p = false
    while s < l do
        local found,e = string.find(b, illegal_path, s)
        if not found then
            table.insert(t, string.sub(b, s))
            break
        end

        table.insert(t, string.sub(b, s, found - 1))

        local drive_letter = string.sub(b, s, s)
        if (drive_letter ~= 'c') and (drive_letter ~= 'C') then
            drive_letter = 'C'
            p = true
        end

        table.insert(t, drive_letter)
        s = found + 1
    end

    if not p then
        print('Warning: there is no need to patch - ' .. file)
        return true
    end

    -- concatenate buffer --
    t = table.concat(t)

    if #t ~= #b then
        print('Internal Error: buffer size is not match.')
        return false
    end

    -- make backup --
    local cmdline = 'copy /-Y /V /B "' .. file .. '" "' .. file .. '.orig"'
    if not os.execute(cmdline) then
        print('Error: cannot make backup original file - ' .. file)
        return false
    end

    f = io.open(file, 'wb')
    if not f then
        print('Error: cannot write - ' .. file)
        return false
    end

    f:write(t)
    f:close()
    return true
end

local function PatchAll(files)
    for _,file in ipairs(files) do
        print('File ... ' .. file)
        Patch(file)
    end
end

-- main --

print ('Current directory ... ' .. GetCurrentDir())
print ('Warning: This program will patch all the files in current directory.')
print ('         It includes junction point directories and symbolic linked directories additionally.')
if not ConfirmMessage('Are you sure?') then
    return 1
end

print ('\n\nGrub all files in the directory.')
local files = GetAllFiles('.')
print ('done.')

if #files < 1 then
    print('There are no files need to patch.')
    return 0
end

print ('There are ' .. #files .. ' files.')
print ('\n\nSearch string literals that contains illegual drive letters.')

io.stdout:write('Searching ...')
local patch_files = SearchTargetFiles(files)
print (' done.')

print (tostring(#patch_files) .. ' files are going to be patched.')
print ('\n\n')

print ('**** Final confirmation ****')
if not ConfirmMessage('May I proceed to patch these files?') then
    return 1
end

io.stdout:write('Patching ...')
PatchAll(patch_files)

Leave a Reply

Your email address will not be published. Required fields are marked *