Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1 | /* |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 2 | * DOS drives handling functions |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1993 Erik Bos |
| 5 | * Copyright 1996 Alexandre Julliard |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 6 | * |
| 7 | * Label & serial number read support. |
| 8 | * (c) 1999 Petr Tomasek <tomasek@etf.cuni.cz> |
| 9 | * (c) 2000 Andreas Mohr (changes) |
| 10 | * |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 13 | #include "config.h" |
| 14 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 15 | #include <assert.h> |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 16 | #include <ctype.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 17 | #include <string.h> |
Alexandre Julliard | aef9a36 | 2000-10-03 04:19:16 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 19 | #include <stdlib.h> |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 20 | #include <sys/types.h> |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 21 | #include <sys/stat.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 22 | #include <fcntl.h> |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 23 | #include <errno.h> |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 25 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 26 | #ifdef HAVE_SYS_PARAM_H |
| 27 | # include <sys/param.h> |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 28 | #endif |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 29 | #ifdef STATFS_DEFINED_BY_SYS_VFS |
| 30 | # include <sys/vfs.h> |
| 31 | #else |
| 32 | # ifdef STATFS_DEFINED_BY_SYS_MOUNT |
| 33 | # include <sys/mount.h> |
| 34 | # else |
| 35 | # ifdef STATFS_DEFINED_BY_SYS_STATFS |
| 36 | # include <sys/statfs.h> |
| 37 | # endif |
| 38 | # endif |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 39 | #endif |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 40 | |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 41 | #include "winbase.h" |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 42 | #include "ntddk.h" |
Michael Veksler | 249d14b | 1999-02-25 16:39:16 +0000 | [diff] [blame] | 43 | #include "wine/winbase16.h" /* for GetCurrentTask */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 44 | #include "winerror.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 45 | #include "drive.h" |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 46 | #include "cdrom.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 47 | #include "file.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 48 | #include "heap.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 49 | #include "msdos.h" |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 50 | #include "options.h" |
Patrik Stridvall | b901021 | 1999-11-13 22:23:35 +0000 | [diff] [blame] | 51 | #include "wine/port.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 52 | #include "task.h" |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 53 | #include "debugtools.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 54 | |
Dimitrie O. Paun | 529da54 | 2000-11-27 23:54:25 +0000 | [diff] [blame] | 55 | DEFAULT_DEBUG_CHANNEL(dosfs); |
| 56 | DECLARE_DEBUG_CHANNEL(file); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 57 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 58 | typedef struct |
| 59 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 60 | char *root; /* root dir in Unix format without trailing / */ |
| 61 | char *dos_cwd; /* cwd in DOS format without leading or trailing \ */ |
| 62 | char *unix_cwd; /* cwd in Unix format without leading or trailing / */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 63 | char *device; /* raw device path */ |
Chris Morgan | e405550 | 2001-01-12 19:55:19 +0000 | [diff] [blame] | 64 | char label_conf[12]; /* drive label as cfg'd in wine config */ |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 65 | char label_read[12]; /* drive label as read from device */ |
Chris Morgan | e405550 | 2001-01-12 19:55:19 +0000 | [diff] [blame] | 66 | DWORD serial_conf; /* drive serial number as cfg'd in wine config */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 67 | UINT type; /* drive type */ |
Andreas Mohr | 91a8e0d | 2000-02-18 19:06:49 +0000 | [diff] [blame] | 68 | UINT flags; /* drive flags */ |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 69 | dev_t dev; /* unix device number */ |
| 70 | ino_t ino; /* unix inode number */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 71 | } DOSDRIVE; |
| 72 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 73 | |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 74 | static const char * const DRIVE_Types[] = |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 75 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 76 | "", /* DRIVE_UNKNOWN */ |
| 77 | "", /* DRIVE_NO_ROOT_DIR */ |
| 78 | "floppy", /* DRIVE_REMOVABLE */ |
| 79 | "hd", /* DRIVE_FIXED */ |
| 80 | "network", /* DRIVE_REMOTE */ |
| 81 | "cdrom", /* DRIVE_CDROM */ |
| 82 | "ramdisk" /* DRIVE_RAMDISK */ |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 86 | /* Known filesystem types */ |
| 87 | |
| 88 | typedef struct |
| 89 | { |
| 90 | const char *name; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 91 | UINT flags; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 92 | } FS_DESCR; |
| 93 | |
| 94 | static const FS_DESCR DRIVE_Filesystems[] = |
| 95 | { |
| 96 | { "unix", DRIVE_CASE_SENSITIVE | DRIVE_CASE_PRESERVING }, |
| 97 | { "msdos", DRIVE_SHORT_NAMES }, |
| 98 | { "dos", DRIVE_SHORT_NAMES }, |
| 99 | { "fat", DRIVE_SHORT_NAMES }, |
| 100 | { "vfat", DRIVE_CASE_PRESERVING }, |
| 101 | { "win95", DRIVE_CASE_PRESERVING }, |
| 102 | { NULL, 0 } |
| 103 | }; |
| 104 | |
| 105 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 106 | static DOSDRIVE DOSDrives[MAX_DOS_DRIVES]; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 107 | static int DRIVE_CurDrive = -1; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 108 | |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 109 | static HTASK16 DRIVE_LastTask = 0; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 110 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 111 | |
| 112 | /*********************************************************************** |
| 113 | * DRIVE_GetDriveType |
| 114 | */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 115 | static UINT DRIVE_GetDriveType( const char *name ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 116 | { |
| 117 | char buffer[20]; |
| 118 | int i; |
| 119 | |
| 120 | PROFILE_GetWineIniString( name, "Type", "hd", buffer, sizeof(buffer) ); |
| 121 | for (i = 0; i < sizeof(DRIVE_Types)/sizeof(DRIVE_Types[0]); i++) |
| 122 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 123 | if (!strcasecmp( buffer, DRIVE_Types[i] )) return i; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 124 | } |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 125 | MESSAGE("%s: unknown drive type '%s', defaulting to 'hd'.\n", |
| 126 | name, buffer ); |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 127 | return DRIVE_FIXED; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 131 | /*********************************************************************** |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 132 | * DRIVE_GetFSFlags |
| 133 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 134 | static UINT DRIVE_GetFSFlags( const char *name, const char *value ) |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 135 | { |
| 136 | const FS_DESCR *descr; |
| 137 | |
| 138 | for (descr = DRIVE_Filesystems; descr->name; descr++) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 139 | if (!strcasecmp( value, descr->name )) return descr->flags; |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 140 | MESSAGE("%s: unknown filesystem type '%s', defaulting to 'win95'.\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 141 | name, value ); |
Andreas Mohr | e3728cd | 1999-02-05 10:16:19 +0000 | [diff] [blame] | 142 | return DRIVE_CASE_PRESERVING; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
| 146 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 147 | * DRIVE_Init |
| 148 | */ |
| 149 | int DRIVE_Init(void) |
| 150 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 151 | int i, len, count = 0; |
| 152 | char name[] = "Drive A"; |
Alexandre Julliard | aef9a36 | 2000-10-03 04:19:16 +0000 | [diff] [blame] | 153 | char drive_env[] = "=A:"; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 154 | char path[MAX_PATHNAME_LEN]; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 155 | char buffer[80]; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 156 | struct stat drive_stat_buffer; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 157 | char *p; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 158 | DOSDRIVE *drive; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 159 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 160 | for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, name[6]++, drive++) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 161 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 162 | PROFILE_GetWineIniString( name, "Path", "", path, sizeof(path)-1 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 163 | if (path[0]) |
| 164 | { |
| 165 | p = path + strlen(path) - 1; |
| 166 | while ((p > path) && ((*p == '/') || (*p == '\\'))) *p-- = '\0'; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 167 | if (!path[0]) strcpy( path, "/" ); |
| 168 | |
| 169 | if (stat( path, &drive_stat_buffer )) |
| 170 | { |
Andreas Mohr | a6d83eb | 2000-12-27 04:02:46 +0000 | [diff] [blame] | 171 | MESSAGE("Could not stat %s (%s), ignoring drive %c:\n", |
| 172 | path, strerror(errno), 'A' + i); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 173 | continue; |
| 174 | } |
| 175 | if (!S_ISDIR(drive_stat_buffer.st_mode)) |
| 176 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 177 | MESSAGE("%s is not a directory, ignoring drive %c:\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 178 | path, 'A' + i ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 179 | continue; |
| 180 | } |
| 181 | |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 182 | drive->root = HEAP_strdupA( GetProcessHeap(), 0, path ); |
| 183 | drive->dos_cwd = HEAP_strdupA( GetProcessHeap(), 0, "" ); |
| 184 | drive->unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, "" ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 185 | drive->type = DRIVE_GetDriveType( name ); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 186 | drive->device = NULL; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 187 | drive->flags = 0; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 188 | drive->dev = drive_stat_buffer.st_dev; |
| 189 | drive->ino = drive_stat_buffer.st_ino; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 190 | |
| 191 | /* Get the drive label */ |
Ryan Cumming | 418e27e | 2001-01-09 20:54:11 +0000 | [diff] [blame] | 192 | PROFILE_GetWineIniString( name, "Label", "", drive->label_conf, 12 ); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 193 | if ((len = strlen(drive->label_conf)) < 11) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 194 | { |
| 195 | /* Pad label with spaces */ |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 196 | memset( drive->label_conf + len, ' ', 11 - len ); |
| 197 | drive->label_conf[11] = '\0'; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* Get the serial number */ |
| 201 | PROFILE_GetWineIniString( name, "Serial", "12345678", |
| 202 | buffer, sizeof(buffer) ); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 203 | drive->serial_conf = strtoul( buffer, NULL, 16 ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 204 | |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 205 | /* Get the filesystem type */ |
Andreas Mohr | e3728cd | 1999-02-05 10:16:19 +0000 | [diff] [blame] | 206 | PROFILE_GetWineIniString( name, "Filesystem", "win95", |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 207 | buffer, sizeof(buffer) ); |
| 208 | drive->flags = DRIVE_GetFSFlags( name, buffer ); |
| 209 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 210 | /* Get the device */ |
| 211 | PROFILE_GetWineIniString( name, "Device", "", |
| 212 | buffer, sizeof(buffer) ); |
| 213 | if (buffer[0]) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 214 | { |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 215 | drive->device = HEAP_strdupA( GetProcessHeap(), 0, buffer ); |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 216 | if (PROFILE_GetWineIniBool( name, "ReadVolInfo", 1)) |
| 217 | drive->flags |= DRIVE_READ_VOL_INFO; |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 218 | } |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 219 | |
| 220 | /* Get the FailReadOnly flag */ |
| 221 | if (PROFILE_GetWineIniBool( name, "FailReadOnly", 0 )) |
| 222 | drive->flags |= DRIVE_FAIL_READ_ONLY; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 223 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 224 | /* Make the first hard disk the current drive */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 225 | if ((DRIVE_CurDrive == -1) && (drive->type == DRIVE_FIXED)) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 226 | DRIVE_CurDrive = i; |
| 227 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 228 | count++; |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 229 | TRACE("%s: path=%s type=%s label='%s' serial=%08lx " |
| 230 | "flags=%08x dev=%x ino=%x\n", |
| 231 | name, path, DRIVE_Types[drive->type], |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 232 | drive->label_conf, drive->serial_conf, drive->flags, |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 233 | (int)drive->dev, (int)drive->ino ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 234 | } |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 235 | else WARN("%s: not defined\n", name ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | if (!count) |
| 239 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 240 | MESSAGE("Warning: no valid DOS drive found, check your configuration file.\n" ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 241 | /* Create a C drive pointing to Unix root dir */ |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 242 | DOSDrives[2].root = HEAP_strdupA( GetProcessHeap(), 0, "/" ); |
| 243 | DOSDrives[2].dos_cwd = HEAP_strdupA( GetProcessHeap(), 0, "" ); |
| 244 | DOSDrives[2].unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, "" ); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 245 | strcpy( DOSDrives[2].label_conf, "Drive C " ); |
| 246 | DOSDrives[2].serial_conf = 12345678; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 247 | DOSDrives[2].type = DRIVE_FIXED; |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 248 | DOSDrives[2].device = NULL; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 249 | DOSDrives[2].flags = 0; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 250 | DRIVE_CurDrive = 2; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 253 | /* Make sure the current drive is valid */ |
| 254 | if (DRIVE_CurDrive == -1) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 255 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 256 | for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, drive++) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 257 | { |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 258 | if (drive->root && !(drive->flags & DRIVE_DISABLED)) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 259 | { |
| 260 | DRIVE_CurDrive = i; |
| 261 | break; |
| 262 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 265 | |
Alexandre Julliard | aef9a36 | 2000-10-03 04:19:16 +0000 | [diff] [blame] | 266 | /* get current working directory info for all drives */ |
| 267 | for (i = 0; i < MAX_DOS_DRIVES; i++, drive_env[1]++) |
| 268 | { |
| 269 | if (!GetEnvironmentVariableA(drive_env, path, sizeof(path))) continue; |
| 270 | /* sanity check */ |
| 271 | if (toupper(path[0]) != drive_env[1] || path[1] != ':') continue; |
| 272 | DRIVE_Chdir( i, path + 2 ); |
| 273 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 274 | return 1; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /*********************************************************************** |
| 279 | * DRIVE_IsValid |
| 280 | */ |
| 281 | int DRIVE_IsValid( int drive ) |
| 282 | { |
| 283 | if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 284 | return (DOSDrives[drive].root && |
| 285 | !(DOSDrives[drive].flags & DRIVE_DISABLED)); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
| 289 | /*********************************************************************** |
| 290 | * DRIVE_GetCurrentDrive |
| 291 | */ |
| 292 | int DRIVE_GetCurrentDrive(void) |
| 293 | { |
Alexandre Julliard | 2ec34e4 | 2001-04-04 00:21:05 +0000 | [diff] [blame] | 294 | TDB *pTask = TASK_GetCurrent(); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 295 | if (pTask && (pTask->curdrive & 0x80)) return pTask->curdrive & ~0x80; |
| 296 | return DRIVE_CurDrive; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | /*********************************************************************** |
| 301 | * DRIVE_SetCurrentDrive |
| 302 | */ |
| 303 | int DRIVE_SetCurrentDrive( int drive ) |
| 304 | { |
Alexandre Julliard | 2ec34e4 | 2001-04-04 00:21:05 +0000 | [diff] [blame] | 305 | TDB *pTask = TASK_GetCurrent(); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 306 | if (!DRIVE_IsValid( drive )) |
| 307 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 308 | SetLastError( ERROR_INVALID_DRIVE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 309 | return 0; |
| 310 | } |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 311 | TRACE("%c:\n", 'A' + drive ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 312 | DRIVE_CurDrive = drive; |
| 313 | if (pTask) pTask->curdrive = drive | 0x80; |
Marcus Meissner | 34ed4fd | 2000-09-27 00:22:16 +0000 | [diff] [blame] | 314 | chdir(DRIVE_GetUnixCwd(drive)); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 315 | return 1; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | /*********************************************************************** |
| 320 | * DRIVE_FindDriveRoot |
| 321 | * |
Peter Ganten | ea5941b | 1999-12-05 23:51:56 +0000 | [diff] [blame] | 322 | * Find a drive for which the root matches the beginning of the given path. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 323 | * This can be used to translate a Unix path into a drive + DOS path. |
| 324 | * Return value is the drive, or -1 on error. On success, path is modified |
| 325 | * to point to the beginning of the DOS path. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 326 | */ |
| 327 | int DRIVE_FindDriveRoot( const char **path ) |
| 328 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 329 | /* idea: check at all '/' positions. |
| 330 | * If the device and inode of that path is identical with the |
| 331 | * device and inode of the current drive then we found a solution. |
| 332 | * If there is another drive pointing to a deeper position in |
| 333 | * the file tree, we want to find that one, not the earlier solution. |
| 334 | */ |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 335 | int drive, rootdrive = -1; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 336 | char buffer[MAX_PATHNAME_LEN]; |
| 337 | char *next = buffer; |
| 338 | const char *p = *path; |
| 339 | struct stat st; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 340 | |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 341 | strcpy( buffer, "/" ); |
| 342 | for (;;) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 343 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 344 | if (stat( buffer, &st ) || !S_ISDIR( st.st_mode )) break; |
| 345 | |
| 346 | /* Find the drive */ |
| 347 | |
| 348 | for (drive = 0; drive < MAX_DOS_DRIVES; drive++) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 349 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 350 | if (!DOSDrives[drive].root || |
| 351 | (DOSDrives[drive].flags & DRIVE_DISABLED)) continue; |
| 352 | |
| 353 | if ((DOSDrives[drive].dev == st.st_dev) && |
| 354 | (DOSDrives[drive].ino == st.st_ino)) |
| 355 | { |
| 356 | rootdrive = drive; |
| 357 | *path = p; |
Andreas Mohr | 91a8e0d | 2000-02-18 19:06:49 +0000 | [diff] [blame] | 358 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 359 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 360 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 361 | |
| 362 | /* Get the next path component */ |
| 363 | |
| 364 | *next++ = '/'; |
| 365 | while ((*p == '/') || (*p == '\\')) p++; |
| 366 | if (!*p) break; |
| 367 | while (!IS_END_OF_NAME(*p)) *next++ = *p++; |
| 368 | *next = 0; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 369 | } |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 370 | *next = 0; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 371 | |
| 372 | if (rootdrive != -1) |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 373 | TRACE("%s -> drive %c:, root='%s', name='%s'\n", |
| 374 | buffer, 'A' + rootdrive, DOSDrives[rootdrive].root, *path ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 375 | return rootdrive; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | |
| 379 | /*********************************************************************** |
| 380 | * DRIVE_GetRoot |
| 381 | */ |
| 382 | const char * DRIVE_GetRoot( int drive ) |
| 383 | { |
| 384 | if (!DRIVE_IsValid( drive )) return NULL; |
| 385 | return DOSDrives[drive].root; |
| 386 | } |
| 387 | |
| 388 | |
| 389 | /*********************************************************************** |
| 390 | * DRIVE_GetDosCwd |
| 391 | */ |
| 392 | const char * DRIVE_GetDosCwd( int drive ) |
| 393 | { |
Alexandre Julliard | 2ec34e4 | 2001-04-04 00:21:05 +0000 | [diff] [blame] | 394 | TDB *pTask = TASK_GetCurrent(); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 395 | if (!DRIVE_IsValid( drive )) return NULL; |
| 396 | |
| 397 | /* Check if we need to change the directory to the new task. */ |
| 398 | if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */ |
| 399 | ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */ |
| 400 | (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */ |
| 401 | { |
| 402 | /* Perform the task-switch */ |
| 403 | if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" ); |
| 404 | DRIVE_LastTask = GetCurrentTask(); |
| 405 | } |
| 406 | return DOSDrives[drive].dos_cwd; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /*********************************************************************** |
| 411 | * DRIVE_GetUnixCwd |
| 412 | */ |
| 413 | const char * DRIVE_GetUnixCwd( int drive ) |
| 414 | { |
Alexandre Julliard | 2ec34e4 | 2001-04-04 00:21:05 +0000 | [diff] [blame] | 415 | TDB *pTask = TASK_GetCurrent(); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 416 | if (!DRIVE_IsValid( drive )) return NULL; |
| 417 | |
| 418 | /* Check if we need to change the directory to the new task. */ |
| 419 | if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */ |
| 420 | ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */ |
| 421 | (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */ |
| 422 | { |
| 423 | /* Perform the task-switch */ |
| 424 | if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" ); |
| 425 | DRIVE_LastTask = GetCurrentTask(); |
| 426 | } |
| 427 | return DOSDrives[drive].unix_cwd; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | /*********************************************************************** |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 432 | * DRIVE_GetDevice |
| 433 | */ |
| 434 | const char * DRIVE_GetDevice( int drive ) |
| 435 | { |
| 436 | return (DRIVE_IsValid( drive )) ? DOSDrives[drive].device : NULL; |
| 437 | } |
| 438 | |
| 439 | |
| 440 | /*********************************************************************** |
| 441 | * DRIVE_ReadSuperblock |
| 442 | * |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 443 | * NOTE |
| 444 | * DRIVE_SetLabel and DRIVE_SetSerialNumber use this in order |
| 445 | * to check, that they are writing on a FAT filesystem ! |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 446 | */ |
| 447 | int DRIVE_ReadSuperblock (int drive, char * buff) |
| 448 | { |
| 449 | #define DRIVE_SUPER 96 |
| 450 | int fd; |
| 451 | off_t offs; |
| 452 | |
| 453 | if (memset(buff,0,DRIVE_SUPER)!=buff) return -1; |
| 454 | if ((fd=open(DOSDrives[drive].device,O_RDONLY)) == -1) |
| 455 | { |
| 456 | struct stat st; |
| 457 | if (!DOSDrives[drive].device) |
| 458 | ERR("No device configured for drive %c: !\n", 'A'+drive); |
| 459 | else |
| 460 | ERR("Couldn't open device '%s' for drive %c: ! (%s)\n", DOSDrives[drive].device, 'A'+drive, |
| 461 | (stat(DOSDrives[drive].device, &st)) ? |
| 462 | "not available or symlink not valid ?" : "no permission"); |
| 463 | ERR("Can't read drive volume info ! Either pre-set it or make sure the device to read it from is accessible !\n"); |
| 464 | PROFILE_UsageWineIni(); |
| 465 | return -1; |
| 466 | } |
| 467 | |
| 468 | switch(DOSDrives[drive].type) |
| 469 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 470 | case DRIVE_REMOVABLE: |
| 471 | case DRIVE_FIXED: |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 472 | offs = 0; |
| 473 | break; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 474 | case DRIVE_CDROM: |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 475 | offs = CDROM_Data_FindBestVoldesc(fd); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 476 | break; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 477 | default: |
| 478 | offs = 0; |
| 479 | break; |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | if ((offs) && (lseek(fd,offs,SEEK_SET)!=offs)) return -4; |
| 483 | if (read(fd,buff,DRIVE_SUPER)!=DRIVE_SUPER) return -2; |
| 484 | |
| 485 | switch(DOSDrives[drive].type) |
| 486 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 487 | case DRIVE_REMOVABLE: |
| 488 | case DRIVE_FIXED: |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 489 | if ((buff[0x26]!=0x29) || /* Check for FAT present */ |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 490 | /* FIXME: do really all FAT have their name beginning with |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 491 | "FAT" ? (At least FAT12, FAT16 and FAT32 have :) */ |
| 492 | memcmp( buff+0x36,"FAT",3)) |
| 493 | { |
| 494 | ERR("The filesystem is not FAT !! (device=%s)\n", |
| 495 | DOSDrives[drive].device); |
| 496 | return -3; |
| 497 | } |
| 498 | break; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 499 | case DRIVE_CDROM: |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 500 | if (strncmp(&buff[1],"CD001",5)) /* Check for iso9660 present */ |
| 501 | return -3; |
| 502 | /* FIXME: do we need to check for "CDROM", too ? (high sierra) */ |
| 503 | break; |
| 504 | default: |
| 505 | return -3; |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | return close(fd); |
| 510 | } |
| 511 | |
| 512 | |
| 513 | /*********************************************************************** |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 514 | * DRIVE_WriteSuperblockEntry |
| 515 | * |
| 516 | * NOTE |
| 517 | * We are writing as little as possible (ie. not the whole SuperBlock) |
| 518 | * not to interfere with kernel. The drive can be mounted ! |
| 519 | */ |
| 520 | int DRIVE_WriteSuperblockEntry (int drive, off_t ofs, size_t len, char * buff) |
| 521 | { |
| 522 | int fd; |
| 523 | |
| 524 | if ((fd=open(DOSDrives[drive].device,O_WRONLY))==-1) |
| 525 | { |
| 526 | ERR("Cannot open the device %s (for writing)\n", |
| 527 | DOSDrives[drive].device); |
| 528 | return -1; |
| 529 | } |
| 530 | if (lseek(fd,ofs,SEEK_SET)!=ofs) |
| 531 | { |
| 532 | ERR("lseek failed on device %s !\n", |
| 533 | DOSDrives[drive].device); |
| 534 | close(fd); |
| 535 | return -2; |
| 536 | } |
| 537 | if (write(fd,buff,len)!=len) |
| 538 | { |
| 539 | close(fd); |
| 540 | ERR("Cannot write on %s !\n", |
| 541 | DOSDrives[drive].device); |
| 542 | return -3; |
| 543 | } |
| 544 | return close (fd); |
| 545 | } |
| 546 | |
| 547 | |
| 548 | |
| 549 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 550 | * DRIVE_GetLabel |
| 551 | */ |
| 552 | const char * DRIVE_GetLabel( int drive ) |
| 553 | { |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 554 | int read = 0; |
| 555 | char buff[DRIVE_SUPER]; |
| 556 | int offs = -1; |
| 557 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 558 | if (!DRIVE_IsValid( drive )) return NULL; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 559 | if (DOSDrives[drive].type == DRIVE_CDROM) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 560 | { |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 561 | read = CDROM_GetLabel(drive, DOSDrives[drive].label_read); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 562 | } |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 563 | else |
| 564 | if (DOSDrives[drive].flags & DRIVE_READ_VOL_INFO) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 565 | { |
| 566 | if (DRIVE_ReadSuperblock(drive,(char *) buff)) |
| 567 | ERR("Invalid or unreadable superblock on %s (%c:).\n", |
| 568 | DOSDrives[drive].device, (char)(drive+'A')); |
| 569 | else { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 570 | if (DOSDrives[drive].type == DRIVE_REMOVABLE || |
| 571 | DOSDrives[drive].type == DRIVE_FIXED) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 572 | offs = 0x2b; |
| 573 | |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 574 | /* FIXME: ISO9660 uses a 32 bytes long label. Should we do also? */ |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 575 | if (offs != -1) memcpy(DOSDrives[drive].label_read,buff+offs,11); |
| 576 | DOSDrives[drive].label_read[11]='\0'; |
| 577 | read = 1; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | return (read) ? |
| 582 | DOSDrives[drive].label_read : DOSDrives[drive].label_conf; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | /*********************************************************************** |
| 587 | * DRIVE_GetSerialNumber |
| 588 | */ |
| 589 | DWORD DRIVE_GetSerialNumber( int drive ) |
| 590 | { |
Andreas Mohr | a16c0e1 | 2000-02-07 16:28:52 +0000 | [diff] [blame] | 591 | DWORD serial = 0; |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 592 | char buff[DRIVE_SUPER]; |
| 593 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 594 | if (!DRIVE_IsValid( drive )) return 0; |
Andreas Mohr | a16c0e1 | 2000-02-07 16:28:52 +0000 | [diff] [blame] | 595 | |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 596 | if (DOSDrives[drive].flags & DRIVE_READ_VOL_INFO) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 597 | { |
Andreas Mohr | a16c0e1 | 2000-02-07 16:28:52 +0000 | [diff] [blame] | 598 | switch(DOSDrives[drive].type) |
| 599 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 600 | case DRIVE_REMOVABLE: |
| 601 | case DRIVE_FIXED: |
| 602 | if (DRIVE_ReadSuperblock(drive,(char *) buff)) |
| 603 | MESSAGE("Invalid or unreadable superblock on %s (%c:)." |
| 604 | " Maybe not FAT?\n" , |
| 605 | DOSDrives[drive].device, 'A'+drive); |
| 606 | else |
| 607 | serial = *((DWORD*)(buff+0x27)); |
| 608 | break; |
| 609 | case DRIVE_CDROM: |
| 610 | serial = CDROM_GetSerial(drive); |
| 611 | break; |
| 612 | default: |
| 613 | FIXME("Serial number reading from file system on drive %c: not supported yet.\n", drive+'A'); |
Andreas Mohr | a16c0e1 | 2000-02-07 16:28:52 +0000 | [diff] [blame] | 614 | } |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 615 | } |
Andreas Mohr | a16c0e1 | 2000-02-07 16:28:52 +0000 | [diff] [blame] | 616 | |
| 617 | return (serial) ? serial : DOSDrives[drive].serial_conf; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
| 621 | /*********************************************************************** |
| 622 | * DRIVE_SetSerialNumber |
| 623 | */ |
| 624 | int DRIVE_SetSerialNumber( int drive, DWORD serial ) |
| 625 | { |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 626 | char buff[DRIVE_SUPER]; |
| 627 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 628 | if (!DRIVE_IsValid( drive )) return 0; |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 629 | |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 630 | if (DOSDrives[drive].flags & DRIVE_READ_VOL_INFO) |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 631 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 632 | if ((DOSDrives[drive].type != DRIVE_REMOVABLE) && |
| 633 | (DOSDrives[drive].type != DRIVE_FIXED)) return 0; |
Petr Tomasek | cd9a633 | 2000-02-27 14:00:14 +0000 | [diff] [blame] | 634 | /* check, if the drive has a FAT filesystem */ |
| 635 | if (DRIVE_ReadSuperblock(drive, buff)) return 0; |
| 636 | if (DRIVE_WriteSuperblockEntry(drive, 0x27, 4, (char *) &serial)) return 0; |
| 637 | return 1; |
| 638 | } |
| 639 | |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 640 | if (DOSDrives[drive].type == DRIVE_CDROM) return 0; |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 641 | DOSDrives[drive].serial_conf = serial; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 642 | return 1; |
| 643 | } |
| 644 | |
| 645 | |
| 646 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 647 | * DRIVE_GetType |
| 648 | */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 649 | static UINT DRIVE_GetType( int drive ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 650 | { |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 651 | if (!DRIVE_IsValid( drive )) return DRIVE_UNKNOWN; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 652 | return DOSDrives[drive].type; |
| 653 | } |
| 654 | |
| 655 | |
| 656 | /*********************************************************************** |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 657 | * DRIVE_GetFlags |
| 658 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 659 | UINT DRIVE_GetFlags( int drive ) |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 660 | { |
| 661 | if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0; |
| 662 | return DOSDrives[drive].flags; |
| 663 | } |
| 664 | |
| 665 | |
| 666 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 667 | * DRIVE_Chdir |
| 668 | */ |
| 669 | int DRIVE_Chdir( int drive, const char *path ) |
| 670 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 671 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 672 | char buffer[MAX_PATHNAME_LEN]; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 673 | LPSTR unix_cwd; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 674 | BY_HANDLE_FILE_INFORMATION info; |
Alexandre Julliard | 2ec34e4 | 2001-04-04 00:21:05 +0000 | [diff] [blame] | 675 | TDB *pTask = TASK_GetCurrent(); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 676 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 677 | strcpy( buffer, "A:" ); |
| 678 | buffer[0] += drive; |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 679 | TRACE("(%s,%s)\n", buffer, path ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 680 | lstrcpynA( buffer + 2, path, sizeof(buffer) - 2 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 681 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 682 | if (!DOSFS_GetFullName( buffer, TRUE, &full_name )) return 0; |
| 683 | if (!FILE_Stat( full_name.long_name, &info )) return 0; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 684 | if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 685 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 686 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 687 | return 0; |
| 688 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 689 | unix_cwd = full_name.long_name + strlen( DOSDrives[drive].root ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 690 | while (*unix_cwd == '/') unix_cwd++; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 691 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 692 | TRACE("(%c:): unix_cwd=%s dos_cwd=%s\n", |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 693 | 'A' + drive, unix_cwd, full_name.short_name + 3 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 694 | |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 695 | HeapFree( GetProcessHeap(), 0, DOSDrives[drive].dos_cwd ); |
| 696 | HeapFree( GetProcessHeap(), 0, DOSDrives[drive].unix_cwd ); |
| 697 | DOSDrives[drive].dos_cwd = HEAP_strdupA( GetProcessHeap(), 0, |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 698 | full_name.short_name + 3 ); |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 699 | DOSDrives[drive].unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, unix_cwd ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 700 | |
| 701 | if (pTask && (pTask->curdrive & 0x80) && |
| 702 | ((pTask->curdrive & ~0x80) == drive)) |
| 703 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 704 | lstrcpynA( pTask->curdir, full_name.short_name + 2, |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 705 | sizeof(pTask->curdir) ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 706 | DRIVE_LastTask = GetCurrentTask(); |
Marcus Meissner | 34ed4fd | 2000-09-27 00:22:16 +0000 | [diff] [blame] | 707 | chdir(unix_cwd); /* Only change if on current drive */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 708 | } |
| 709 | return 1; |
| 710 | } |
| 711 | |
| 712 | |
| 713 | /*********************************************************************** |
| 714 | * DRIVE_Disable |
| 715 | */ |
| 716 | int DRIVE_Disable( int drive ) |
| 717 | { |
| 718 | if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root) |
| 719 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 720 | SetLastError( ERROR_INVALID_DRIVE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 721 | return 0; |
| 722 | } |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 723 | DOSDrives[drive].flags |= DRIVE_DISABLED; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 724 | return 1; |
| 725 | } |
| 726 | |
| 727 | |
| 728 | /*********************************************************************** |
| 729 | * DRIVE_Enable |
| 730 | */ |
| 731 | int DRIVE_Enable( int drive ) |
| 732 | { |
| 733 | if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root) |
| 734 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 735 | SetLastError( ERROR_INVALID_DRIVE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 736 | return 0; |
| 737 | } |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 738 | DOSDrives[drive].flags &= ~DRIVE_DISABLED; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 739 | return 1; |
| 740 | } |
| 741 | |
| 742 | |
| 743 | /*********************************************************************** |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 744 | * DRIVE_SetLogicalMapping |
| 745 | */ |
| 746 | int DRIVE_SetLogicalMapping ( int existing_drive, int new_drive ) |
| 747 | { |
| 748 | /* If new_drive is already valid, do nothing and return 0 |
| 749 | otherwise, copy DOSDrives[existing_drive] to DOSDrives[new_drive] */ |
| 750 | |
| 751 | DOSDRIVE *old, *new; |
| 752 | |
| 753 | old = DOSDrives + existing_drive; |
| 754 | new = DOSDrives + new_drive; |
| 755 | |
| 756 | if ((existing_drive < 0) || (existing_drive >= MAX_DOS_DRIVES) || |
| 757 | !old->root || |
| 758 | (new_drive < 0) || (new_drive >= MAX_DOS_DRIVES)) |
| 759 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 760 | SetLastError( ERROR_INVALID_DRIVE ); |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | if ( new->root ) |
| 765 | { |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 766 | TRACE("Can't map drive %c: to already existing drive %c:\n", |
| 767 | 'A' + existing_drive, 'A' + new_drive ); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 768 | /* it is already mapped there, so return success */ |
| 769 | if (!strcmp(old->root,new->root)) |
| 770 | return 1; |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 774 | new->root = HEAP_strdupA( GetProcessHeap(), 0, old->root ); |
| 775 | new->dos_cwd = HEAP_strdupA( GetProcessHeap(), 0, old->dos_cwd ); |
| 776 | new->unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, old->unix_cwd ); |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 777 | new->device = HEAP_strdupA( GetProcessHeap(), 0, old->device ); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 778 | memcpy ( new->label_conf, old->label_conf, 12 ); |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 779 | memcpy ( new->label_read, old->label_read, 12 ); |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 780 | new->serial_conf = old->serial_conf; |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 781 | new->type = old->type; |
| 782 | new->flags = old->flags; |
| 783 | new->dev = old->dev; |
| 784 | new->ino = old->ino; |
| 785 | |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 786 | TRACE("Drive %c: is now equal to drive %c:\n", |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 787 | 'A' + new_drive, 'A' + existing_drive ); |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 788 | |
| 789 | return 1; |
| 790 | } |
| 791 | |
| 792 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 793 | /*********************************************************************** |
| 794 | * DRIVE_OpenDevice |
| 795 | * |
| 796 | * Open the drive raw device and return a Unix fd (or -1 on error). |
| 797 | */ |
| 798 | int DRIVE_OpenDevice( int drive, int flags ) |
| 799 | { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 800 | if (!DRIVE_IsValid( drive )) return -1; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 801 | return open( DOSDrives[drive].device, flags ); |
| 802 | } |
| 803 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 804 | |
| 805 | /*********************************************************************** |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 806 | * DRIVE_RawRead |
| 807 | * |
| 808 | * Read raw sectors from a device |
| 809 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 810 | int DRIVE_RawRead(BYTE drive, DWORD begin, DWORD nr_sect, BYTE *dataptr, BOOL fake_success) |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 811 | { |
| 812 | int fd; |
| 813 | |
| 814 | if ((fd = DRIVE_OpenDevice( drive, O_RDONLY )) != -1) |
| 815 | { |
| 816 | lseek( fd, begin * 512, SEEK_SET ); |
| 817 | /* FIXME: check errors */ |
| 818 | read( fd, dataptr, nr_sect * 512 ); |
| 819 | close( fd ); |
| 820 | } |
| 821 | else |
| 822 | { |
| 823 | memset(dataptr, 0, nr_sect * 512); |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 824 | if (fake_success) |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 825 | { |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 826 | if (begin == 0 && nr_sect > 1) *(dataptr + 512) = 0xf8; |
| 827 | if (begin == 1) *dataptr = 0xf8; |
| 828 | } |
| 829 | else |
| 830 | return 0; |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 831 | } |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 832 | return 1; |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | |
| 836 | /*********************************************************************** |
| 837 | * DRIVE_RawWrite |
| 838 | * |
| 839 | * Write raw sectors to a device |
| 840 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 841 | int DRIVE_RawWrite(BYTE drive, DWORD begin, DWORD nr_sect, BYTE *dataptr, BOOL fake_success) |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 842 | { |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 843 | int fd; |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 844 | |
| 845 | if ((fd = DRIVE_OpenDevice( drive, O_RDONLY )) != -1) |
| 846 | { |
| 847 | lseek( fd, begin * 512, SEEK_SET ); |
| 848 | /* FIXME: check errors */ |
| 849 | write( fd, dataptr, nr_sect * 512 ); |
| 850 | close( fd ); |
| 851 | } |
| 852 | else |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 853 | if (!(fake_success)) |
| 854 | return 0; |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 855 | |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 856 | return 1; |
Andreas Mohr | cc0248e | 1999-01-03 12:31:51 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
| 860 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 861 | * DRIVE_GetFreeSpace |
| 862 | */ |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 863 | static int DRIVE_GetFreeSpace( int drive, PULARGE_INTEGER size, |
| 864 | PULARGE_INTEGER available ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 865 | { |
| 866 | struct statfs info; |
| 867 | |
| 868 | if (!DRIVE_IsValid(drive)) |
| 869 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 870 | SetLastError( ERROR_INVALID_DRIVE ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 874 | /* FIXME: add autoconf check for this */ |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 875 | #if defined(__svr4__) || defined(_SCO_DS) || defined(__sun) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 876 | if (statfs( DOSDrives[drive].root, &info, 0, 0) < 0) |
| 877 | #else |
| 878 | if (statfs( DOSDrives[drive].root, &info) < 0) |
| 879 | #endif |
| 880 | { |
| 881 | FILE_SetDosError(); |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 882 | WARN("cannot do statfs(%s)\n", DOSDrives[drive].root); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 883 | return 0; |
| 884 | } |
| 885 | |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 886 | size->QuadPart = RtlEnlargedUnsignedMultiply( info.f_bsize, info.f_blocks ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 887 | #ifdef STATFS_HAS_BAVAIL |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 888 | available->QuadPart = RtlEnlargedUnsignedMultiply( info.f_bavail, info.f_bsize ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 889 | #else |
| 890 | # ifdef STATFS_HAS_BFREE |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 891 | available->QuadPart = RtlEnlargedUnsignedMultiply( info.f_bfree, info.f_bsize ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 892 | # else |
| 893 | # error "statfs has no bfree/bavail member!" |
| 894 | # endif |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 895 | #endif |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 896 | if (DOSDrives[drive].type == DRIVE_CDROM) |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 897 | { /* ALWAYS 0, even if no real CD-ROM mounted there !! */ |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 898 | available->QuadPart = 0; |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 899 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 900 | return 1; |
| 901 | } |
| 902 | |
Peter Ganten | ea5941b | 1999-12-05 23:51:56 +0000 | [diff] [blame] | 903 | /*********************************************************************** |
Abey George | 70810d9 | 1999-09-27 11:39:43 +0000 | [diff] [blame] | 904 | * DRIVE_GetCurrentDirectory |
| 905 | * Returns "X:\\path\\etc\\". |
| 906 | * |
| 907 | * Despite the API description, return required length including the |
| 908 | * terminating null when buffer too small. This is the real behaviour. |
| 909 | */ |
| 910 | |
| 911 | static UINT DRIVE_GetCurrentDirectory( UINT buflen, LPSTR buf ) |
| 912 | { |
| 913 | UINT ret; |
| 914 | const char *s = DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() ); |
| 915 | |
| 916 | assert(s); |
| 917 | ret = strlen(s) + 3; /* length of WHOLE current directory */ |
| 918 | if (ret >= buflen) return ret + 1; |
Francois Gouget | 6d77d3a | 2000-03-25 21:44:35 +0000 | [diff] [blame] | 919 | lstrcpynA( buf, "A:\\", min( 4, buflen ) ); |
Abey George | 70810d9 | 1999-09-27 11:39:43 +0000 | [diff] [blame] | 920 | if (buflen) buf[0] += DRIVE_GetCurrentDrive(); |
| 921 | if (buflen > 3) lstrcpynA( buf + 3, s, buflen - 3 ); |
| 922 | return ret; |
| 923 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 924 | |
Alexandre Julliard | aef9a36 | 2000-10-03 04:19:16 +0000 | [diff] [blame] | 925 | |
| 926 | /*********************************************************************** |
| 927 | * DRIVE_BuildEnv |
| 928 | * |
| 929 | * Build the environment array containing the drives current directories. |
| 930 | * Resulting pointer must be freed with HeapFree. |
| 931 | */ |
| 932 | char *DRIVE_BuildEnv(void) |
| 933 | { |
| 934 | int i, length = 0; |
| 935 | const char *cwd[MAX_DOS_DRIVES]; |
| 936 | char *env, *p; |
| 937 | |
| 938 | for (i = 0; i < MAX_DOS_DRIVES; i++) |
| 939 | { |
| 940 | if ((cwd[i] = DRIVE_GetDosCwd(i)) && cwd[i][0]) length += strlen(cwd[i]) + 8; |
| 941 | } |
| 942 | if (!(env = HeapAlloc( GetProcessHeap(), 0, length+1 ))) return NULL; |
| 943 | for (i = 0, p = env; i < MAX_DOS_DRIVES; i++) |
| 944 | { |
| 945 | if (cwd[i] && cwd[i][0]) |
| 946 | p += sprintf( p, "=%c:=%c:\\%s", 'A'+i, 'A'+i, cwd[i] ) + 1; |
| 947 | } |
| 948 | *p = 0; |
| 949 | return env; |
| 950 | } |
| 951 | |
| 952 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 953 | /*********************************************************************** |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 954 | * GetDiskFreeSpace16 (KERNEL.422) |
| 955 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 956 | BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors, |
| 957 | LPDWORD sector_bytes, LPDWORD free_clusters, |
| 958 | LPDWORD total_clusters ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 959 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 960 | return GetDiskFreeSpaceA( root, cluster_sectors, sector_bytes, |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 961 | free_clusters, total_clusters ); |
| 962 | } |
| 963 | |
| 964 | |
| 965 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 966 | * GetDiskFreeSpaceA (KERNEL32.206) |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 967 | * |
| 968 | * Fails if expression resulting from current drive's dir and "root" |
| 969 | * is not a root dir of the target drive. |
| 970 | * |
| 971 | * UNDOC: setting some LPDWORDs to NULL is perfectly possible |
| 972 | * if the corresponding info is unneeded. |
| 973 | * |
| 974 | * FIXME: needs to support UNC names from Win95 OSR2 on. |
| 975 | * |
| 976 | * Behaviour under Win95a: |
| 977 | * CurrDir root result |
| 978 | * "E:\\TEST" "E:" FALSE |
| 979 | * "E:\\" "E:" TRUE |
| 980 | * "E:\\" "E" FALSE |
| 981 | * "E:\\" "\\" TRUE |
| 982 | * "E:\\TEST" "\\" TRUE |
| 983 | * "E:\\TEST" ":\\" FALSE |
| 984 | * "E:\\TEST" "E:\\" TRUE |
| 985 | * "E:\\TEST" "" FALSE |
| 986 | * "E:\\" "" FALSE (!) |
| 987 | * "E:\\" 0x0 TRUE |
| 988 | * "E:\\TEST" 0x0 TRUE (!) |
| 989 | * "E:\\TEST" "C:" TRUE (when CurrDir of "C:" set to "\\") |
| 990 | * "E:\\TEST" "C:" FALSE (when CurrDir of "C:" set to "\\TEST") |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 991 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 992 | BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 993 | LPDWORD sector_bytes, LPDWORD free_clusters, |
| 994 | LPDWORD total_clusters ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 995 | { |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 996 | int drive, sec_size; |
Uwe Bonnes | f3836f5 | 1998-12-10 09:56:06 +0000 | [diff] [blame] | 997 | ULARGE_INTEGER size,available; |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 998 | LPCSTR path; |
| 999 | DWORD cluster_sec; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1000 | |
Peter Schlaile | 6deeedb | 1999-11-04 01:39:59 +0000 | [diff] [blame] | 1001 | if ((!root) || (strcmp(root,"\\") == 0)) |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1002 | drive = DRIVE_GetCurrentDrive(); |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1003 | else |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1004 | if ( (strlen(root) >= 2) && (root[1] == ':')) /* root contains drive tag */ |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1005 | { |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1006 | drive = toupper(root[0]) - 'A'; |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1007 | path = &root[2]; |
| 1008 | if (path[0] == '\0') |
| 1009 | path = DRIVE_GetDosCwd(drive); |
| 1010 | else |
| 1011 | if (path[0] == '\\') |
| 1012 | path++; |
| 1013 | if (strlen(path)) /* oops, we are in a subdir */ |
| 1014 | return FALSE; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1015 | } |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1016 | else |
| 1017 | return FALSE; |
| 1018 | |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1019 | if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE; |
| 1020 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1021 | /* Cap the size and available at 2GB as per specs. */ |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1022 | if ((size.s.HighPart) ||(size.s.LowPart > 0x7fffffff)) |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 1023 | { |
| 1024 | size.s.HighPart = 0; |
| 1025 | size.s.LowPart = 0x7fffffff; |
| 1026 | } |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1027 | if ((available.s.HighPart) ||(available.s.LowPart > 0x7fffffff)) |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 1028 | { |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1029 | available.s.HighPart =0; |
| 1030 | available.s.LowPart = 0x7fffffff; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1031 | } |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1032 | sec_size = (DRIVE_GetType(drive)==DRIVE_CDROM) ? 2048 : 512; |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 1033 | size.s.LowPart /= sec_size; |
| 1034 | available.s.LowPart /= sec_size; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1035 | /* fixme: probably have to adjust those variables too for CDFS */ |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1036 | cluster_sec = 1; |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1037 | while (cluster_sec * 65536 < size.s.LowPart) cluster_sec *= 2; |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1038 | |
| 1039 | if (cluster_sectors) |
| 1040 | *cluster_sectors = cluster_sec; |
Andreas Mohr | bd86d18f | 2000-06-13 03:36:05 +0000 | [diff] [blame] | 1041 | if (sector_bytes) |
| 1042 | *sector_bytes = sec_size; |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1043 | if (free_clusters) |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1044 | *free_clusters = available.s.LowPart / cluster_sec; |
Andreas Mohr | 4ae195a | 1998-11-27 15:02:25 +0000 | [diff] [blame] | 1045 | if (total_clusters) |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1046 | *total_clusters = size.s.LowPart / cluster_sec; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1047 | return TRUE; |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1052 | * GetDiskFreeSpaceW (KERNEL32.207) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1053 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1054 | BOOL WINAPI GetDiskFreeSpaceW( LPCWSTR root, LPDWORD cluster_sectors, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1055 | LPDWORD sector_bytes, LPDWORD free_clusters, |
| 1056 | LPDWORD total_clusters ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1057 | { |
| 1058 | LPSTR xroot; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1059 | BOOL ret; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1060 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1061 | xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1062 | ret = GetDiskFreeSpaceA( xroot,cluster_sectors, sector_bytes, |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1063 | free_clusters, total_clusters ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1064 | HeapFree( GetProcessHeap(), 0, xroot ); |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1070 | * GetDiskFreeSpaceExA (KERNEL32.871) |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1071 | * |
Andreas Mohr | f32f918 | 2001-04-20 18:36:05 +0000 | [diff] [blame] | 1072 | * This function is used to acquire the size of the available and |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1073 | * total space on a logical volume. |
| 1074 | * |
| 1075 | * RETURNS |
| 1076 | * |
| 1077 | * Zero on failure, nonzero upon success. Use GetLastError to obtain |
| 1078 | * detailed error information. |
| 1079 | * |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1080 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1081 | BOOL WINAPI GetDiskFreeSpaceExA( LPCSTR root, |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 1082 | PULARGE_INTEGER avail, |
| 1083 | PULARGE_INTEGER total, |
| 1084 | PULARGE_INTEGER totalfree) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1085 | { |
| 1086 | int drive; |
Uwe Bonnes | f3836f5 | 1998-12-10 09:56:06 +0000 | [diff] [blame] | 1087 | ULARGE_INTEGER size,available; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1088 | |
| 1089 | if (!root) drive = DRIVE_GetCurrentDrive(); |
| 1090 | else |
| 1091 | { |
| 1092 | if ((root[1]) && ((root[1] != ':') || (root[2] != '\\'))) |
| 1093 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1094 | FIXME("there are valid root names which are not supported yet\n"); |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1095 | /* ..like UNC names, for instance. */ |
| 1096 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1097 | WARN("invalid root '%s'\n", root ); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1098 | return FALSE; |
| 1099 | } |
| 1100 | drive = toupper(root[0]) - 'A'; |
| 1101 | } |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1102 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1103 | if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE; |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1104 | |
| 1105 | if (total) |
| 1106 | { |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1107 | total->s.HighPart = size.s.HighPart; |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1108 | total->s.LowPart = size.s.LowPart; |
Eric Pouech | 6ec6492 | 1999-02-02 10:25:41 +0000 | [diff] [blame] | 1109 | } |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1110 | |
| 1111 | if (totalfree) |
| 1112 | { |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1113 | totalfree->s.HighPart = available.s.HighPart; |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1114 | totalfree->s.LowPart = available.s.LowPart; |
Eric Pouech | 6ec6492 | 1999-02-02 10:25:41 +0000 | [diff] [blame] | 1115 | } |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1116 | |
| 1117 | if (avail) |
| 1118 | { |
Morten Eriksen | 467845a | 1999-08-15 14:20:18 +0000 | [diff] [blame] | 1119 | if (FIXME_ON(dosfs)) |
| 1120 | { |
| 1121 | /* On Windows2000, we need to check the disk quota |
| 1122 | allocated for the user owning the calling process. We |
| 1123 | don't want to be more obtrusive than necessary with the |
| 1124 | FIXME messages, so don't print the FIXME unless Wine is |
| 1125 | actually masquerading as Windows2000. */ |
| 1126 | |
| 1127 | OSVERSIONINFOA ovi; |
| 1128 | ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); |
| 1129 | if (GetVersionExA(&ovi)) |
| 1130 | { |
| 1131 | if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT && ovi.dwMajorVersion > 4) |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1132 | FIXME("no per-user quota support yet\n"); |
Morten Eriksen | 467845a | 1999-08-15 14:20:18 +0000 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /* Quick hack, should eventually be fixed to work 100% with |
| 1137 | Windows2000 (see comment above). */ |
Patrik Stridvall | 311e456 | 1999-09-19 14:20:33 +0000 | [diff] [blame] | 1138 | avail->s.HighPart = available.s.HighPart; |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1139 | avail->s.LowPart = available.s.LowPart; |
Morten Eriksen | 1563e83 | 1999-08-07 12:29:04 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1142 | return TRUE; |
| 1143 | } |
| 1144 | |
| 1145 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1146 | * GetDiskFreeSpaceExW (KERNEL32.873) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1147 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1148 | BOOL WINAPI GetDiskFreeSpaceExW( LPCWSTR root, PULARGE_INTEGER avail, |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 1149 | PULARGE_INTEGER total, |
| 1150 | PULARGE_INTEGER totalfree) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1151 | { |
| 1152 | LPSTR xroot; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1153 | BOOL ret; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1154 | |
| 1155 | xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1156 | ret = GetDiskFreeSpaceExA( xroot, avail, total, totalfree); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1157 | HeapFree( GetProcessHeap(), 0, xroot ); |
| 1158 | return ret; |
| 1159 | } |
| 1160 | |
| 1161 | /*********************************************************************** |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1162 | * GetDriveType16 (KERNEL.136) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 1163 | * This function returns the type of a drive in Win16. |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1164 | * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the |
Andreas Mohr | 91a8e0d | 2000-02-18 19:06:49 +0000 | [diff] [blame] | 1165 | * remote drive API. The return value DRIVE_REMOTE for CD-ROMs has been |
| 1166 | * verified on Win 3.11 and Windows 95. Some programs rely on it, so don't |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1167 | * do any pseudo-clever changes. |
| 1168 | * |
| 1169 | * RETURNS |
| 1170 | * drivetype DRIVE_xxx |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1171 | */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1172 | UINT16 WINAPI GetDriveType16( UINT16 drive ) /* [in] number (NOT letter) of drive */ |
| 1173 | { |
| 1174 | UINT type = DRIVE_GetType(drive); |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1175 | TRACE("(%c:)\n", 'A' + drive ); |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1176 | if (type == DRIVE_CDROM) type = DRIVE_REMOTE; |
| 1177 | return type; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1178 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1179 | |
| 1180 | |
| 1181 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1182 | * GetDriveTypeA (KERNEL32.208) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1183 | * |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1184 | * Returns the type of the disk drive specified. If root is NULL the |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1185 | * root of the current directory is used. |
| 1186 | * |
| 1187 | * RETURNS |
| 1188 | * |
| 1189 | * Type of drive (from Win32 SDK): |
| 1190 | * |
| 1191 | * DRIVE_UNKNOWN unable to find out anything about the drive |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1192 | * DRIVE_NO_ROOT_DIR nonexistent root dir |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1193 | * DRIVE_REMOVABLE the disk can be removed from the machine |
| 1194 | * DRIVE_FIXED the disk can not be removed from the machine |
| 1195 | * DRIVE_REMOTE network disk |
| 1196 | * DRIVE_CDROM CDROM drive |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1197 | * DRIVE_RAMDISK virtual disk in RAM |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1198 | */ |
Patrik Stridvall | 2b3aa61 | 2000-12-01 23:58:28 +0000 | [diff] [blame] | 1199 | UINT WINAPI GetDriveTypeA(LPCSTR root) /* [in] String describing drive */ |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1200 | { |
Petter Reinholdtsen | 0dce5b7 | 1998-10-11 14:26:25 +0000 | [diff] [blame] | 1201 | int drive; |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1202 | TRACE("(%s)\n", debugstr_a(root)); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1203 | |
Petter Reinholdtsen | 0dce5b7 | 1998-10-11 14:26:25 +0000 | [diff] [blame] | 1204 | if (NULL == root) drive = DRIVE_GetCurrentDrive(); |
| 1205 | else |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1206 | { |
Petter Reinholdtsen | 0dce5b7 | 1998-10-11 14:26:25 +0000 | [diff] [blame] | 1207 | if ((root[1]) && (root[1] != ':')) |
| 1208 | { |
Francois Gouget | ee285b7 | 2001-05-11 20:03:40 +0000 | [diff] [blame^] | 1209 | WARN("invalid root %s\n", debugstr_a(root)); |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1210 | return DRIVE_NO_ROOT_DIR; |
Petter Reinholdtsen | 0dce5b7 | 1998-10-11 14:26:25 +0000 | [diff] [blame] | 1211 | } |
| 1212 | drive = toupper(root[0]) - 'A'; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1213 | } |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1214 | return DRIVE_GetType(drive); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1219 | * GetDriveTypeW (KERNEL32.209) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1220 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1221 | UINT WINAPI GetDriveTypeW( LPCWSTR root ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1222 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1223 | LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, root ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1224 | UINT ret = GetDriveTypeA( xpath ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1225 | HeapFree( GetProcessHeap(), 0, xpath ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1226 | return ret; |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | /*********************************************************************** |
| 1231 | * GetCurrentDirectory16 (KERNEL.411) |
| 1232 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1233 | UINT16 WINAPI GetCurrentDirectory16( UINT16 buflen, LPSTR buf ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1234 | { |
Abey George | 70810d9 | 1999-09-27 11:39:43 +0000 | [diff] [blame] | 1235 | return (UINT16)DRIVE_GetCurrentDirectory(buflen, buf); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
| 1239 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1240 | * GetCurrentDirectoryA (KERNEL32.196) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1241 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1242 | UINT WINAPI GetCurrentDirectoryA( UINT buflen, LPSTR buf ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1243 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1244 | UINT ret; |
Abey George | 70810d9 | 1999-09-27 11:39:43 +0000 | [diff] [blame] | 1245 | char longname[MAX_PATHNAME_LEN]; |
Peter Ganten | ea5941b | 1999-12-05 23:51:56 +0000 | [diff] [blame] | 1246 | char shortname[MAX_PATHNAME_LEN]; |
| 1247 | ret = DRIVE_GetCurrentDirectory(MAX_PATHNAME_LEN, shortname); |
| 1248 | if ( ret > MAX_PATHNAME_LEN ) { |
| 1249 | ERR_(file)("pathnamelength (%d) > MAX_PATHNAME_LEN!\n", ret ); |
| 1250 | return ret; |
| 1251 | } |
| 1252 | GetLongPathNameA(shortname, longname, MAX_PATHNAME_LEN); |
Alexandre Julliard | cb10fda | 2000-08-06 02:41:16 +0000 | [diff] [blame] | 1253 | ret = strlen( longname ) + 1; |
Peter Ganten | ea5941b | 1999-12-05 23:51:56 +0000 | [diff] [blame] | 1254 | if (ret > buflen) return ret; |
Alexandre Julliard | cb10fda | 2000-08-06 02:41:16 +0000 | [diff] [blame] | 1255 | strcpy(buf, longname); |
Peter Ganten | ea5941b | 1999-12-05 23:51:56 +0000 | [diff] [blame] | 1256 | return ret - 1; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1259 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1260 | * GetCurrentDirectoryW (KERNEL32.197) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1261 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1262 | UINT WINAPI GetCurrentDirectoryW( UINT buflen, LPWSTR buf ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1263 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1264 | LPSTR xpath = HeapAlloc( GetProcessHeap(), 0, buflen+1 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1265 | UINT ret = GetCurrentDirectoryA( buflen, xpath ); |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1266 | if (ret < buflen) ret = MultiByteToWideChar( CP_ACP, 0, xpath, -1, buf, buflen ) - 1; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1267 | HeapFree( GetProcessHeap(), 0, xpath ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1268 | return ret; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | /*********************************************************************** |
| 1273 | * SetCurrentDirectory (KERNEL.412) |
| 1274 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1275 | BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1276 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1277 | return SetCurrentDirectoryA( dir ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1278 | } |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1279 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1280 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1281 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1282 | * SetCurrentDirectoryA (KERNEL32.479) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1283 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1284 | BOOL WINAPI SetCurrentDirectoryA( LPCSTR dir ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1285 | { |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1286 | int drive, olddrive = DRIVE_GetCurrentDrive(); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1287 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1288 | if (!dir) { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1289 | ERR_(file)("(NULL)!\n"); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1290 | return FALSE; |
| 1291 | } |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1292 | if (dir[0] && (dir[1]==':')) |
| 1293 | { |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1294 | drive = toupper( *dir ) - 'A'; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1295 | dir += 2; |
| 1296 | } |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1297 | else |
| 1298 | drive = olddrive; |
Andreas Mohr | fe6dfb0 | 1998-10-11 17:36:06 +0000 | [diff] [blame] | 1299 | |
| 1300 | /* WARNING: we need to set the drive before the dir, as DRIVE_Chdir |
| 1301 | sets pTask->curdir only if pTask->curdrive is drive */ |
Andreas Mohr | fe6dfb0 | 1998-10-11 17:36:06 +0000 | [diff] [blame] | 1302 | if (!(DRIVE_SetCurrentDrive( drive ))) |
| 1303 | return FALSE; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1304 | /* FIXME: what about empty strings? Add a \\ ? */ |
Andreas Mohr | fe6dfb0 | 1998-10-11 17:36:06 +0000 | [diff] [blame] | 1305 | if (!DRIVE_Chdir( drive, dir )) { |
| 1306 | DRIVE_SetCurrentDrive(olddrive); |
| 1307 | return FALSE; |
| 1308 | } |
| 1309 | return TRUE; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1312 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1313 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1314 | * SetCurrentDirectoryW (KERNEL32.480) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1315 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1316 | BOOL WINAPI SetCurrentDirectoryW( LPCWSTR dirW ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1317 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1318 | LPSTR dir = HEAP_strdupWtoA( GetProcessHeap(), 0, dirW ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1319 | BOOL res = SetCurrentDirectoryA( dir ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1320 | HeapFree( GetProcessHeap(), 0, dir ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1321 | return res; |
| 1322 | } |
| 1323 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1324 | |
| 1325 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1326 | * GetLogicalDriveStringsA (KERNEL32.231) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1327 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1328 | UINT WINAPI GetLogicalDriveStringsA( UINT len, LPSTR buffer ) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1329 | { |
| 1330 | int drive, count; |
| 1331 | |
| 1332 | for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++) |
| 1333 | if (DRIVE_IsValid(drive)) count++; |
Uwe Bonnes | c25e715 | 1999-10-13 13:57:38 +0000 | [diff] [blame] | 1334 | if ((count * 4) + 1 <= len) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1335 | { |
| 1336 | LPSTR p = buffer; |
| 1337 | for (drive = 0; drive < MAX_DOS_DRIVES; drive++) |
| 1338 | if (DRIVE_IsValid(drive)) |
| 1339 | { |
| 1340 | *p++ = 'a' + drive; |
| 1341 | *p++ = ':'; |
| 1342 | *p++ = '\\'; |
| 1343 | *p++ = '\0'; |
| 1344 | } |
| 1345 | *p = '\0'; |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1346 | return count * 4; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1347 | } |
Uwe Bonnes | c25e715 | 1999-10-13 13:57:38 +0000 | [diff] [blame] | 1348 | else |
Andreas Mohr | 3084b58 | 2000-07-25 20:59:59 +0000 | [diff] [blame] | 1349 | return (count * 4) + 1; /* account for terminating null */ |
Uwe Bonnes | c25e715 | 1999-10-13 13:57:38 +0000 | [diff] [blame] | 1350 | /* The API tells about these different return values */ |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1355 | * GetLogicalDriveStringsW (KERNEL32.232) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1356 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1357 | UINT WINAPI GetLogicalDriveStringsW( UINT len, LPWSTR buffer ) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1358 | { |
| 1359 | int drive, count; |
| 1360 | |
| 1361 | for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++) |
| 1362 | if (DRIVE_IsValid(drive)) count++; |
| 1363 | if (count * 4 * sizeof(WCHAR) <= len) |
| 1364 | { |
| 1365 | LPWSTR p = buffer; |
| 1366 | for (drive = 0; drive < MAX_DOS_DRIVES; drive++) |
| 1367 | if (DRIVE_IsValid(drive)) |
| 1368 | { |
| 1369 | *p++ = (WCHAR)('a' + drive); |
| 1370 | *p++ = (WCHAR)':'; |
| 1371 | *p++ = (WCHAR)'\\'; |
| 1372 | *p++ = (WCHAR)'\0'; |
| 1373 | } |
| 1374 | *p = (WCHAR)'\0'; |
| 1375 | } |
| 1376 | return count * 4 * sizeof(WCHAR); |
| 1377 | } |
| 1378 | |
| 1379 | |
| 1380 | /*********************************************************************** |
| 1381 | * GetLogicalDrives (KERNEL32.233) |
| 1382 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1383 | DWORD WINAPI GetLogicalDrives(void) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1384 | { |
| 1385 | DWORD ret = 0; |
| 1386 | int drive; |
| 1387 | |
| 1388 | for (drive = 0; drive < MAX_DOS_DRIVES; drive++) |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 1389 | { |
| 1390 | if ( (DRIVE_IsValid(drive)) || |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1391 | (DOSDrives[drive].type == DRIVE_CDROM)) /* audio CD is also valid */ |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 1392 | ret |= (1 << drive); |
| 1393 | } |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1394 | return ret; |
| 1395 | } |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1396 | |
| 1397 | |
| 1398 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1399 | * GetVolumeInformationA (KERNEL32.309) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1400 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1401 | BOOL WINAPI GetVolumeInformationA( LPCSTR root, LPSTR label, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1402 | DWORD label_len, DWORD *serial, |
| 1403 | DWORD *filename_len, DWORD *flags, |
| 1404 | LPSTR fsname, DWORD fsname_len ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1405 | { |
| 1406 | int drive; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 1407 | char *cp; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1408 | |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 1409 | /* FIXME, SetLastError()s missing */ |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1410 | |
| 1411 | if (!root) drive = DRIVE_GetCurrentDrive(); |
| 1412 | else |
| 1413 | { |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1414 | if ((root[1]) && (root[1] != ':')) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1415 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1416 | WARN("invalid root '%s'\n",root); |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1417 | return FALSE; |
| 1418 | } |
| 1419 | drive = toupper(root[0]) - 'A'; |
| 1420 | } |
| 1421 | if (!DRIVE_IsValid( drive )) return FALSE; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 1422 | if (label) |
| 1423 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1424 | lstrcpynA( label, DRIVE_GetLabel(drive), label_len ); |
Alexandre Julliard | 566a52a | 2001-03-05 19:34:17 +0000 | [diff] [blame] | 1425 | cp = label + strlen(label); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 1426 | while (cp != label && *(cp-1) == ' ') cp--; |
| 1427 | *cp = '\0'; |
| 1428 | } |
Petter Reinholdtsen | 6ca3f79 | 1998-10-20 14:25:50 +0000 | [diff] [blame] | 1429 | if (serial) *serial = DRIVE_GetSerialNumber(drive); |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1430 | |
| 1431 | /* Set the filesystem information */ |
Andreas Mohr | 1fe9334 | 2000-01-29 21:11:47 +0000 | [diff] [blame] | 1432 | /* Note: we only emulate a FAT fs at present */ |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1433 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1434 | if (filename_len) { |
| 1435 | if (DOSDrives[drive].flags & DRIVE_SHORT_NAMES) |
| 1436 | *filename_len = 12; |
| 1437 | else |
| 1438 | *filename_len = 255; |
| 1439 | } |
Uwe Bonnes | 2723342 | 1999-02-11 10:23:05 +0000 | [diff] [blame] | 1440 | if (flags) |
| 1441 | { |
| 1442 | *flags=0; |
| 1443 | if (DOSDrives[drive].flags & DRIVE_CASE_SENSITIVE) |
| 1444 | *flags|=FS_CASE_SENSITIVE; |
| 1445 | if (DOSDrives[drive].flags & DRIVE_CASE_PRESERVING) |
Andreas Mohr | 91a8e0d | 2000-02-18 19:06:49 +0000 | [diff] [blame] | 1446 | *flags|=FS_CASE_IS_PRESERVED; |
Uwe Bonnes | 2723342 | 1999-02-11 10:23:05 +0000 | [diff] [blame] | 1447 | } |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1448 | if (fsname) { |
| 1449 | /* Diablo checks that return code ... */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1450 | if (DOSDrives[drive].type == DRIVE_CDROM) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1451 | lstrcpynA( fsname, "CDFS", fsname_len ); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1452 | else |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1453 | lstrcpynA( fsname, "FAT", fsname_len ); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1454 | } |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1455 | return TRUE; |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1460 | * GetVolumeInformationW (KERNEL32.310) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1461 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1462 | BOOL WINAPI GetVolumeInformationW( LPCWSTR root, LPWSTR label, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1463 | DWORD label_len, DWORD *serial, |
| 1464 | DWORD *filename_len, DWORD *flags, |
| 1465 | LPWSTR fsname, DWORD fsname_len ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1466 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1467 | LPSTR xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root ); |
| 1468 | LPSTR xvolname = label ? HeapAlloc(GetProcessHeap(),0,label_len) : NULL; |
| 1469 | LPSTR xfsname = fsname ? HeapAlloc(GetProcessHeap(),0,fsname_len) : NULL; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1470 | BOOL ret = GetVolumeInformationA( xroot, xvolname, label_len, serial, |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1471 | filename_len, flags, xfsname, |
| 1472 | fsname_len ); |
| 1473 | if (ret) |
| 1474 | { |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1475 | if (label) MultiByteToWideChar( CP_ACP, 0, xvolname, -1, label, label_len ); |
| 1476 | if (fsname) MultiByteToWideChar( CP_ACP, 0, xfsname, -1, fsname, fsname_len ); |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1477 | } |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1478 | HeapFree( GetProcessHeap(), 0, xroot ); |
| 1479 | HeapFree( GetProcessHeap(), 0, xvolname ); |
| 1480 | HeapFree( GetProcessHeap(), 0, xfsname ); |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1481 | return ret; |
| 1482 | } |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1483 | |
Dave Pickles | 18d3ad8 | 1999-06-05 15:19:30 +0000 | [diff] [blame] | 1484 | /*********************************************************************** |
| 1485 | * SetVolumeLabelA (KERNEL32.675) |
| 1486 | */ |
Ove Kaaven | a01e289 | 2000-01-15 23:28:26 +0000 | [diff] [blame] | 1487 | BOOL WINAPI SetVolumeLabelA( LPCSTR root, LPCSTR volname ) |
Dave Pickles | 18d3ad8 | 1999-06-05 15:19:30 +0000 | [diff] [blame] | 1488 | { |
Ove Kaaven | a01e289 | 2000-01-15 23:28:26 +0000 | [diff] [blame] | 1489 | int drive; |
| 1490 | |
| 1491 | /* FIXME, SetLastErrors missing */ |
| 1492 | |
| 1493 | if (!root) drive = DRIVE_GetCurrentDrive(); |
| 1494 | else |
| 1495 | { |
| 1496 | if ((root[1]) && (root[1] != ':')) |
| 1497 | { |
| 1498 | WARN("invalid root '%s'\n",root); |
| 1499 | return FALSE; |
| 1500 | } |
| 1501 | drive = toupper(root[0]) - 'A'; |
| 1502 | } |
| 1503 | if (!DRIVE_IsValid( drive )) return FALSE; |
| 1504 | |
| 1505 | /* some copy protection stuff check this */ |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1506 | if (DOSDrives[drive].type == DRIVE_CDROM) return FALSE; |
Ove Kaaven | a01e289 | 2000-01-15 23:28:26 +0000 | [diff] [blame] | 1507 | |
| 1508 | FIXME("(%s,%s),stub!\n", root, volname); |
| 1509 | return TRUE; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1510 | } |
Dave Pickles | 18d3ad8 | 1999-06-05 15:19:30 +0000 | [diff] [blame] | 1511 | |
| 1512 | /*********************************************************************** |
| 1513 | * SetVolumeLabelW (KERNEL32.676) |
| 1514 | */ |
| 1515 | BOOL WINAPI SetVolumeLabelW(LPCWSTR rootpath,LPCWSTR volname) |
| 1516 | { |
| 1517 | LPSTR xroot, xvol; |
| 1518 | BOOL ret; |
| 1519 | |
| 1520 | xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, rootpath); |
| 1521 | xvol = HEAP_strdupWtoA( GetProcessHeap(), 0, volname); |
| 1522 | ret = SetVolumeLabelA( xroot, xvol ); |
| 1523 | HeapFree( GetProcessHeap(), 0, xroot ); |
| 1524 | HeapFree( GetProcessHeap(), 0, xvol ); |
| 1525 | return ret; |
| 1526 | } |