mountDevice :: FilePath -> FilePath -> Bool -> IO ExitCode
mountDevice dev path writable = do
    e1 <- tryCommand ("mkdir " ++ path)
    case e1 of
        ExitSuccess -> do
            if writable
            then do
                e2 <- tryCommand ("mount -o rw " ++ dev ++ " " ++ path)
                return e2
            else do
                e2 <- tryCommand ("mount -o ro " ++ dev ++ " " ++ path)
                return e2
        ExitFailure a -> do
            return e1
mountDevice :: FilePath -> FilePath -> Bool -> IO ExitCode
mountDevice dev path writable = do
    e1 <- tryCommand ("mkdir " ++ path)
    case e1 of
        ExitSuccess -> do
            if writable
            then do
                e2 <- tryCommand ("mount -o rw " ++ dev ++ " " ++ path)
                return e2
            else do
                e2 <- tryCommand ("mount -o ro " ++ dev ++ " " ++ path)
                return e2
        ExitFailure a -> do
            return e1
mountDevice dev path writable = do
    e1 <- tryCommand ("mkdir " ++ path)
    case e1 of
        ExitSuccess -> do
            if writable
            then do
                e2 <- tryCommand ("mount -o rw " ++ dev ++ " " ++ path)
                return e2
            else do
                e2 <- tryCommand ("mount -o ro " ++ dev ++ " " ++ path)
                return e2
        ExitFailure a -> do
            return e1