2004-11-23 14:50:23 +01:00
|
|
|
/*
|
|
|
|
* Drive autodetection code
|
|
|
|
*
|
|
|
|
* Copyright 2004 Mike Hearn
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-11-23 14:50:23 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-02-14 22:03:36 +01:00
|
|
|
#include "config.h"
|
2005-08-03 23:25:10 +02:00
|
|
|
#include "wine/port.h"
|
2005-02-14 22:03:36 +01:00
|
|
|
|
2008-10-20 00:25:49 +02:00
|
|
|
#include <stdarg.h>
|
2004-11-23 14:50:23 +01:00
|
|
|
#include <stdio.h>
|
2004-11-28 15:53:03 +01:00
|
|
|
#ifdef HAVE_MNTENT_H
|
2004-11-23 14:50:23 +01:00
|
|
|
#include <mntent.h>
|
2004-11-28 15:53:03 +01:00
|
|
|
#endif
|
2004-11-23 14:50:23 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2008-10-17 14:11:56 +02:00
|
|
|
#include <windef.h>
|
2004-11-23 14:50:23 +01:00
|
|
|
#include <winbase.h>
|
2008-10-17 14:11:56 +02:00
|
|
|
#include <wine/debug.h>
|
|
|
|
#include <wine/library.h>
|
|
|
|
|
|
|
|
#include "winecfg.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
|
|
|
|
|
|
|
BOOL gui_mode = TRUE;
|
2009-04-02 12:05:35 +02:00
|
|
|
static ULONG working_mask = 0;
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2008-05-19 05:50:19 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *szNode;
|
|
|
|
int nType;
|
|
|
|
} DEV_NODES;
|
|
|
|
|
2004-11-28 15:53:03 +01:00
|
|
|
#ifdef HAVE_MNTENT_H
|
2005-02-25 14:58:45 +01:00
|
|
|
|
2005-06-27 11:48:06 +02:00
|
|
|
static const DEV_NODES sDeviceNodes[] = {
|
2005-02-25 14:58:45 +01:00
|
|
|
{"/dev/fd", DRIVE_REMOVABLE},
|
2006-06-09 23:21:59 +02:00
|
|
|
{"/dev/pf", DRIVE_REMOVABLE},
|
2009-06-26 08:40:59 +02:00
|
|
|
{"/dev/acd", DRIVE_CDROM},
|
2006-06-09 23:21:59 +02:00
|
|
|
{"/dev/aztcd", DRIVE_CDROM},
|
|
|
|
{"/dev/bpcd", DRIVE_CDROM},
|
2009-06-26 08:40:59 +02:00
|
|
|
{"/dev/cd", DRIVE_CDROM},
|
2005-02-25 14:58:45 +01:00
|
|
|
{"/dev/cdrom", DRIVE_CDROM},
|
2006-06-09 23:21:59 +02:00
|
|
|
{"/dev/cdu535", DRIVE_CDROM},
|
|
|
|
{"/dev/cdwriter", DRIVE_CDROM},
|
|
|
|
{"/dev/cm205cd", DRIVE_CDROM},
|
|
|
|
{"/dev/cm206cd", DRIVE_CDROM},
|
|
|
|
{"/dev/gscd", DRIVE_CDROM},
|
|
|
|
{"/dev/hitcd", DRIVE_CDROM},
|
|
|
|
{"/dev/iseries/vcd", DRIVE_CDROM},
|
|
|
|
{"/dev/lmscd", DRIVE_CDROM},
|
|
|
|
{"/dev/mcd", DRIVE_CDROM},
|
|
|
|
{"/dev/optcd", DRIVE_CDROM},
|
|
|
|
{"/dev/pcd", DRIVE_CDROM},
|
|
|
|
{"/dev/sbpcd", DRIVE_CDROM},
|
|
|
|
{"/dev/scd", DRIVE_CDROM},
|
|
|
|
{"/dev/sjcd", DRIVE_CDROM},
|
|
|
|
{"/dev/sonycd", DRIVE_CDROM},
|
|
|
|
{"/dev/sr", DRIVE_CDROM},
|
2005-02-25 14:58:45 +01:00
|
|
|
{"",0}
|
|
|
|
};
|
|
|
|
|
2005-06-27 11:48:06 +02:00
|
|
|
static const char * const ignored_fstypes[] = {
|
2004-11-23 14:50:23 +01:00
|
|
|
"devpts",
|
|
|
|
"tmpfs",
|
|
|
|
"proc",
|
|
|
|
"sysfs",
|
|
|
|
"swap",
|
|
|
|
"usbdevfs",
|
|
|
|
"rpc_pipefs",
|
2005-07-01 17:39:32 +02:00
|
|
|
"binfmt_misc",
|
2004-11-23 14:50:23 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2005-06-27 11:48:06 +02:00
|
|
|
static const char * const ignored_mnt_dirs[] = {
|
2005-02-14 22:03:36 +01:00
|
|
|
"/boot",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2005-02-25 14:58:45 +01:00
|
|
|
static int try_dev_node(char *dev)
|
|
|
|
{
|
|
|
|
const DEV_NODES *pDevNodes = sDeviceNodes;
|
|
|
|
|
|
|
|
while(pDevNodes->szNode[0])
|
|
|
|
{
|
|
|
|
if(!strncmp(dev,pDevNodes->szNode,strlen(pDevNodes->szNode)))
|
|
|
|
return pDevNodes->nType;
|
|
|
|
++pDevNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DRIVE_FIXED;
|
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
static BOOL should_ignore_fstype(char *type)
|
|
|
|
{
|
2005-06-27 11:48:06 +02:00
|
|
|
const char * const *s;
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
for (s = ignored_fstypes; *s; s++)
|
|
|
|
if (!strcmp(*s, type)) return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-14 22:03:36 +01:00
|
|
|
static BOOL should_ignore_mnt_dir(char *dir)
|
|
|
|
{
|
2005-06-27 11:48:06 +02:00
|
|
|
const char * const *s;
|
2005-02-14 22:03:36 +01:00
|
|
|
|
|
|
|
for (s = ignored_mnt_dirs; *s; s++)
|
|
|
|
if (!strcmp(*s, dir)) return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
static BOOL is_drive_defined(char *path)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 26; i++)
|
|
|
|
if (drives[i].in_use && !strcmp(drives[i].unixpath, path)) return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns Z + 1 if there are no more available letters */
|
2006-06-10 04:33:42 +02:00
|
|
|
static char allocate_letter(int type)
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
2006-06-10 04:33:42 +02:00
|
|
|
char letter, start;
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2006-06-10 04:33:42 +02:00
|
|
|
if (type == DRIVE_REMOVABLE)
|
|
|
|
start = 'A';
|
|
|
|
else
|
|
|
|
start = 'C';
|
|
|
|
|
|
|
|
for (letter = start; letter <= 'Z'; letter++)
|
2004-11-23 14:50:23 +01:00
|
|
|
if ((DRIVE_MASK_BIT(letter) & working_mask) != 0) break;
|
|
|
|
|
|
|
|
return letter;
|
|
|
|
}
|
2004-11-28 15:53:03 +01:00
|
|
|
#endif
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
#define FSTAB_OPEN 1
|
|
|
|
#define NO_MORE_LETTERS 2
|
|
|
|
#define NO_ROOT 3
|
|
|
|
#define NO_DRIVE_C 4
|
2005-02-14 22:03:36 +01:00
|
|
|
#define NO_HOME 5
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
static void report_error(int code)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case FSTAB_OPEN:
|
|
|
|
if (gui_mode)
|
|
|
|
{
|
2005-06-27 11:48:06 +02:00
|
|
|
static const char s[] = "Could not open your mountpoint description table.\n\nOpening of /etc/fstab failed: %s";
|
2004-11-23 14:50:23 +01:00
|
|
|
len = snprintf(NULL, 0, s, strerror(errno));
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, len + 1);
|
|
|
|
snprintf(buffer, len, s, strerror(errno));
|
2012-01-20 12:42:33 +01:00
|
|
|
MessageBoxA(NULL, s, "", MB_OK | MB_ICONEXCLAMATION);
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-14 22:03:36 +01:00
|
|
|
fprintf(stderr, "winecfg: could not open fstab: %s\n", strerror(errno));
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NO_MORE_LETTERS:
|
2012-01-20 12:42:33 +01:00
|
|
|
if (gui_mode) MessageBoxA(NULL, "No more letters are available to auto-detect available drives with.", "", MB_OK | MB_ICONEXCLAMATION);
|
2005-02-14 22:03:36 +01:00
|
|
|
fprintf(stderr, "winecfg: no more available letters while scanning /etc/fstab\n");
|
2004-11-23 14:50:23 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NO_ROOT:
|
2012-01-20 12:42:33 +01:00
|
|
|
if (gui_mode) MessageBoxA(NULL, "Could not ensure that the root directory was mapped.\n\n"
|
2004-11-23 14:50:23 +01:00
|
|
|
"This can happen if you run out of drive letters. "
|
|
|
|
"It's important to have the root directory mapped, otherwise Wine"
|
|
|
|
"will not be able to always find the programs you want to run. "
|
|
|
|
"Try unmapping a drive letter then trying again.", "",
|
|
|
|
MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
else fprintf(stderr, "winecfg: unable to map root drive\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NO_DRIVE_C:
|
|
|
|
if (gui_mode)
|
2012-01-20 12:42:33 +01:00
|
|
|
MessageBoxA(NULL, "No virtual drive C mapped!\n", "", MB_OK | MB_ICONEXCLAMATION);
|
2004-11-23 14:50:23 +01:00
|
|
|
else
|
|
|
|
fprintf(stderr, "winecfg: no drive_c directory\n");
|
2011-03-18 22:07:45 +01:00
|
|
|
break;
|
2005-02-14 22:03:36 +01:00
|
|
|
case NO_HOME:
|
|
|
|
if (gui_mode)
|
2012-01-20 12:42:33 +01:00
|
|
|
MessageBoxA(NULL, "Could not ensure that your home directory was mapped.\n\n"
|
2005-02-14 22:03:36 +01:00
|
|
|
"This can happen if you run out of drive letters. "
|
|
|
|
"Try unmapping a drive letter then try again.", "",
|
|
|
|
MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "winecfg: unable to map home drive\n");
|
|
|
|
break;
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void ensure_root_is_mapped(void)
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL mapped = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 26; i++)
|
|
|
|
if (drives[i].in_use && !strcmp(drives[i].unixpath, "/")) mapped = TRUE;
|
|
|
|
|
|
|
|
if (!mapped)
|
|
|
|
{
|
|
|
|
/* work backwards from Z, trying to map it */
|
|
|
|
char letter;
|
|
|
|
|
|
|
|
for (letter = 'Z'; letter >= 'A'; letter--)
|
|
|
|
{
|
2005-02-14 12:01:16 +01:00
|
|
|
if (!drives[letter - 'A'].in_use)
|
|
|
|
{
|
2008-10-23 16:19:36 +02:00
|
|
|
add_drive(letter, "/", NULL, NULL, 0, DRIVE_FIXED);
|
2005-02-14 12:01:16 +01:00
|
|
|
WINE_TRACE("allocated drive %c as the root drive\n", letter);
|
|
|
|
break;
|
|
|
|
}
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (letter == ('A' - 1)) report_error(NO_ROOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void ensure_home_is_mapped(void)
|
2005-02-14 22:03:36 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL mapped = FALSE;
|
|
|
|
char *home = getenv("HOME");
|
|
|
|
|
|
|
|
if (!home) return;
|
|
|
|
|
|
|
|
for (i = 0; i < 26; i++)
|
|
|
|
if (drives[i].in_use && !strcmp(drives[i].unixpath, home)) mapped = TRUE;
|
|
|
|
|
|
|
|
if (!mapped)
|
|
|
|
{
|
|
|
|
char letter;
|
|
|
|
|
|
|
|
for (letter = 'H'; letter <= 'Z'; letter++)
|
|
|
|
{
|
|
|
|
if (!drives[letter - 'A'].in_use)
|
|
|
|
{
|
2008-10-23 16:19:36 +02:00
|
|
|
add_drive(letter, home, NULL, NULL, 0, DRIVE_FIXED);
|
2005-02-14 22:03:36 +01:00
|
|
|
WINE_TRACE("allocated drive %c as the user's home directory\n", letter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (letter == ('Z' + 1)) report_error(NO_HOME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void ensure_drive_c_is_mapped(void)
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
const char *configdir = wine_get_config_dir();
|
|
|
|
int len;
|
|
|
|
char *drive_c_dir;
|
|
|
|
|
|
|
|
if (drives[2].in_use) return;
|
|
|
|
|
|
|
|
len = snprintf(NULL, 0, "%s/../drive_c", configdir);
|
|
|
|
drive_c_dir = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
snprintf(drive_c_dir, len, "%s/../drive_c", configdir);
|
|
|
|
HeapFree(GetProcessHeap(), 0, drive_c_dir);
|
|
|
|
|
|
|
|
if (stat(drive_c_dir, &buf) == 0)
|
|
|
|
{
|
2008-10-17 14:11:56 +02:00
|
|
|
WCHAR label[64];
|
2012-01-20 12:42:33 +01:00
|
|
|
LoadStringW (GetModuleHandleW(NULL), IDS_SYSTEM_DRIVE_LABEL, label,
|
2008-10-17 14:11:56 +02:00
|
|
|
sizeof(label)/sizeof(label[0]));
|
2008-10-23 16:19:36 +02:00
|
|
|
add_drive('C', "../drive_c", NULL, label, 0, DRIVE_FIXED);
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
report_error(NO_DRIVE_C);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-10 22:00:47 +01:00
|
|
|
int autodetect_drives(void)
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
2004-11-28 15:53:03 +01:00
|
|
|
#ifdef HAVE_MNTENT_H
|
2004-11-23 14:50:23 +01:00
|
|
|
struct mntent *ent;
|
|
|
|
FILE *fstab;
|
2004-11-28 15:53:03 +01:00
|
|
|
#endif
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
/* we want to build a list of autodetected drives, then ensure each entry
|
|
|
|
exists in the users setup. so, we superimpose the autodetected drives
|
|
|
|
onto whatever is pre-existing.
|
|
|
|
|
|
|
|
for now let's just rummage around inside the fstab.
|
|
|
|
*/
|
|
|
|
|
|
|
|
load_drives();
|
|
|
|
|
|
|
|
working_mask = drive_available_mask('\0');
|
|
|
|
|
2004-11-28 15:53:03 +01:00
|
|
|
#ifdef HAVE_MNTENT_H
|
2004-11-23 14:50:23 +01:00
|
|
|
fstab = fopen("/etc/fstab", "r");
|
|
|
|
if (!fstab)
|
|
|
|
{
|
|
|
|
report_error(FSTAB_OPEN);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ent = getmntent(fstab)))
|
|
|
|
{
|
|
|
|
char letter;
|
|
|
|
int type;
|
2008-10-23 16:19:36 +02:00
|
|
|
char *device = NULL;
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
WINE_TRACE("ent->mnt_dir=%s\n", ent->mnt_dir);
|
|
|
|
|
|
|
|
if (should_ignore_fstype(ent->mnt_type)) continue;
|
2005-02-14 22:03:36 +01:00
|
|
|
if (should_ignore_mnt_dir(ent->mnt_dir)) continue;
|
2004-11-23 14:50:23 +01:00
|
|
|
if (is_drive_defined(ent->mnt_dir)) continue;
|
|
|
|
|
2006-06-10 04:33:42 +02:00
|
|
|
if (!strcmp(ent->mnt_type, "nfs")) type = DRIVE_REMOTE;
|
|
|
|
else if (!strcmp(ent->mnt_type, "nfs4")) type = DRIVE_REMOTE;
|
|
|
|
else if (!strcmp(ent->mnt_type, "smbfs")) type = DRIVE_REMOTE;
|
|
|
|
else if (!strcmp(ent->mnt_type, "cifs")) type = DRIVE_REMOTE;
|
|
|
|
else if (!strcmp(ent->mnt_type, "coda")) type = DRIVE_REMOTE;
|
|
|
|
else if (!strcmp(ent->mnt_type, "iso9660")) type = DRIVE_CDROM;
|
|
|
|
else if (!strcmp(ent->mnt_type, "ramfs")) type = DRIVE_RAMDISK;
|
|
|
|
else type = try_dev_node(ent->mnt_fsname);
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* allocate a drive for it */
|
2006-06-10 04:33:42 +02:00
|
|
|
letter = allocate_letter(type);
|
2009-01-21 11:02:12 +01:00
|
|
|
if (letter == 'Z' + 1)
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
|
|
|
report_error(NO_MORE_LETTERS);
|
|
|
|
fclose(fstab);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-23 16:19:36 +02:00
|
|
|
if (type == DRIVE_CDROM) device = ent->mnt_fsname;
|
|
|
|
|
|
|
|
WINE_TRACE("adding drive %c for %s, device %s, type %s\n",
|
|
|
|
letter, ent->mnt_dir, device, ent->mnt_type);
|
|
|
|
add_drive(letter, ent->mnt_dir, device, NULL, 0, type);
|
2008-10-17 14:11:56 +02:00
|
|
|
|
2005-02-14 22:03:36 +01:00
|
|
|
/* working_mask is a map of the drive letters still available. */
|
|
|
|
working_mask &= ~DRIVE_MASK_BIT(letter);
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fstab);
|
2004-11-28 15:53:03 +01:00
|
|
|
#endif
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
ensure_root_is_mapped();
|
|
|
|
|
|
|
|
ensure_drive_c_is_mapped();
|
|
|
|
|
2005-02-14 22:03:36 +01:00
|
|
|
ensure_home_is_mapped();
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|