Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * File handling functions |
| 3 | * |
| 4 | * Copyright 1993 John Burton |
| 5 | * Copyright 1996 Alexandre Julliard |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 6 | * |
| 7 | * TODO: |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 8 | * Fix the CopyFileEx methods to implement the "extended" functionality. |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 9 | * Right now, they simply call the CopyFile method. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 12 | #include "config.h" |
| 13 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 14 | #include <assert.h> |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 15 | #include <ctype.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 16 | #include <errno.h> |
| 17 | #include <fcntl.h> |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 20 | #include <string.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 21 | #ifdef HAVE_SYS_ERRNO_H |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 22 | #include <sys/errno.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 23 | #endif |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 24 | #include <sys/types.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 25 | #include <sys/stat.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 26 | #ifdef HAVE_SYS_MMAN_H |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 27 | #include <sys/mman.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 28 | #endif |
Marcus Meissner | 7d123bf | 1998-12-11 09:13:29 +0000 | [diff] [blame] | 29 | #include <sys/time.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 30 | #include <time.h> |
| 31 | #include <unistd.h> |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 32 | #include <utime.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 33 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 34 | #include "winerror.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 35 | #include "windef.h" |
| 36 | #include "winbase.h" |
| 37 | #include "wine/winbase16.h" |
| 38 | #include "wine/winestring.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 39 | #include "drive.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 40 | #include "file.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 41 | #include "global.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 42 | #include "heap.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 43 | #include "msdos.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 44 | #include "ldt.h" |
| 45 | #include "task.h" |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 46 | #include "wincon.h" |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 47 | #include "debugtools.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 48 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 49 | #include "server.h" |
| 50 | |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 51 | DEFAULT_DEBUG_CHANNEL(file); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 52 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 53 | #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) |
| 54 | #define MAP_ANON MAP_ANONYMOUS |
| 55 | #endif |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 56 | |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 57 | /* Size of per-process table of DOS handles */ |
| 58 | #define DOS_TABLE_SIZE 256 |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 59 | |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 60 | static HANDLE dos_handles[DOS_TABLE_SIZE]; |
| 61 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 62 | |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 63 | /*********************************************************************** |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 64 | * FILE_ConvertOFMode |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 65 | * |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 66 | * Convert OF_* mode into flags for CreateFile. |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 67 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 68 | static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing ) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 69 | { |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 70 | switch(mode & 0x03) |
| 71 | { |
| 72 | case OF_READ: *access = GENERIC_READ; break; |
| 73 | case OF_WRITE: *access = GENERIC_WRITE; break; |
| 74 | case OF_READWRITE: *access = GENERIC_READ | GENERIC_WRITE; break; |
| 75 | default: *access = 0; break; |
| 76 | } |
| 77 | switch(mode & 0x70) |
| 78 | { |
| 79 | case OF_SHARE_EXCLUSIVE: *sharing = 0; break; |
| 80 | case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break; |
| 81 | case OF_SHARE_DENY_READ: *sharing = FILE_SHARE_WRITE; break; |
| 82 | case OF_SHARE_DENY_NONE: |
| 83 | case OF_SHARE_COMPAT: |
| 84 | default: *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break; |
| 85 | } |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 88 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 89 | #if 0 |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 90 | /*********************************************************************** |
| 91 | * FILE_ShareDeny |
| 92 | * |
| 93 | * PARAMS |
| 94 | * oldmode[I] mode how file was first opened |
| 95 | * mode[I] mode how the file should get opened |
| 96 | * RETURNS |
| 97 | * TRUE: deny open |
| 98 | * FALSE: allow open |
| 99 | * |
| 100 | * Look what we have to do with the given SHARE modes |
| 101 | * |
| 102 | * Ralph Brown's interrupt list gives following explication, I guess |
| 103 | * the same holds for Windows, DENY ALL should be OF_SHARE_COMPAT |
| 104 | * |
| 105 | * FIXME: Validate this function |
| 106 | ========from Ralph Brown's list ========= |
| 107 | (Table 0750) |
| 108 | Values of DOS file sharing behavior: |
| 109 | | Second and subsequent Opens |
| 110 | First |Compat Deny Deny Deny Deny |
| 111 | Open | All Write Read None |
| 112 | |R W RW R W RW R W RW R W RW R W RW |
| 113 | - - - - -| - - - - - - - - - - - - - - - - - |
| 114 | Compat R |Y Y Y N N N 1 N N N N N 1 N N |
| 115 | W |Y Y Y N N N N N N N N N N N N |
| 116 | RW|Y Y Y N N N N N N N N N N N N |
| 117 | - - - - -| |
| 118 | Deny R |C C C N N N N N N N N N N N N |
| 119 | All W |C C C N N N N N N N N N N N N |
| 120 | RW|C C C N N N N N N N N N N N N |
| 121 | - - - - -| |
| 122 | Deny R |2 C C N N N Y N N N N N Y N N |
| 123 | Write W |C C C N N N N N N Y N N Y N N |
| 124 | RW|C C C N N N N N N N N N Y N N |
| 125 | - - - - -| |
| 126 | Deny R |C C C N N N N Y N N N N N Y N |
| 127 | Read W |C C C N N N N N N N Y N N Y N |
| 128 | RW|C C C N N N N N N N N N N Y N |
| 129 | - - - - -| |
| 130 | Deny R |2 C C N N N Y Y Y N N N Y Y Y |
| 131 | None W |C C C N N N N N N Y Y Y Y Y Y |
| 132 | RW|C C C N N N N N N N N N Y Y Y |
| 133 | Legend: Y = open succeeds, N = open fails with error code 05h |
| 134 | C = open fails, INT 24 generated |
| 135 | 1 = open succeeds if file read-only, else fails with error code |
| 136 | 2 = open succeeds if file read-only, else fails with INT 24 |
| 137 | ========end of description from Ralph Brown's List ===== |
| 138 | For every "Y" in the table we return FALSE |
| 139 | For every "N" we set the DOS_ERROR and return TRUE |
| 140 | For all other cases we barf,set the DOS_ERROR and return TRUE |
| 141 | |
| 142 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 143 | static BOOL FILE_ShareDeny( int mode, int oldmode) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 144 | { |
| 145 | int oldsharemode = oldmode & 0x70; |
| 146 | int sharemode = mode & 0x70; |
| 147 | int oldopenmode = oldmode & 3; |
| 148 | int openmode = mode & 3; |
| 149 | |
| 150 | switch (oldsharemode) |
| 151 | { |
| 152 | case OF_SHARE_COMPAT: |
| 153 | if (sharemode == OF_SHARE_COMPAT) return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 154 | if (openmode == OF_READ) goto test_ro_err05; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 155 | goto fail_error05; |
| 156 | case OF_SHARE_EXCLUSIVE: |
| 157 | if (sharemode == OF_SHARE_COMPAT) goto fail_int24; |
| 158 | goto fail_error05; |
| 159 | case OF_SHARE_DENY_WRITE: |
| 160 | if (openmode != OF_READ) |
| 161 | { |
| 162 | if (sharemode == OF_SHARE_COMPAT) goto fail_int24; |
| 163 | goto fail_error05; |
| 164 | } |
| 165 | switch (sharemode) |
| 166 | { |
| 167 | case OF_SHARE_COMPAT: |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 168 | if (oldopenmode == OF_READ) goto test_ro_int24; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 169 | goto fail_int24; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 170 | case OF_SHARE_DENY_NONE: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 171 | return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 172 | case OF_SHARE_DENY_WRITE: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 173 | if (oldopenmode == OF_READ) return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 174 | case OF_SHARE_DENY_READ: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 175 | if (oldopenmode == OF_WRITE) return FALSE; |
| 176 | case OF_SHARE_EXCLUSIVE: |
| 177 | default: |
| 178 | goto fail_error05; |
| 179 | } |
| 180 | break; |
| 181 | case OF_SHARE_DENY_READ: |
| 182 | if (openmode != OF_WRITE) |
| 183 | { |
| 184 | if (sharemode == OF_SHARE_COMPAT) goto fail_int24; |
| 185 | goto fail_error05; |
| 186 | } |
| 187 | switch (sharemode) |
| 188 | { |
| 189 | case OF_SHARE_COMPAT: |
| 190 | goto fail_int24; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 191 | case OF_SHARE_DENY_NONE: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 192 | return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 193 | case OF_SHARE_DENY_WRITE: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 194 | if (oldopenmode == OF_READ) return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 195 | case OF_SHARE_DENY_READ: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 196 | if (oldopenmode == OF_WRITE) return FALSE; |
| 197 | case OF_SHARE_EXCLUSIVE: |
| 198 | default: |
| 199 | goto fail_error05; |
| 200 | } |
| 201 | break; |
| 202 | case OF_SHARE_DENY_NONE: |
| 203 | switch (sharemode) |
| 204 | { |
| 205 | case OF_SHARE_COMPAT: |
| 206 | goto fail_int24; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 207 | case OF_SHARE_DENY_NONE: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 208 | return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 209 | case OF_SHARE_DENY_WRITE: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 210 | if (oldopenmode == OF_READ) return FALSE; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 211 | case OF_SHARE_DENY_READ: |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 212 | if (oldopenmode == OF_WRITE) return FALSE; |
| 213 | case OF_SHARE_EXCLUSIVE: |
| 214 | default: |
| 215 | goto fail_error05; |
| 216 | } |
| 217 | default: |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 218 | ERR("unknown mode\n"); |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 219 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 220 | ERR("shouldn't happen\n"); |
| 221 | ERR("Please report to bon@elektron.ikp.physik.tu-darmstadt.de\n"); |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 222 | return TRUE; |
| 223 | |
| 224 | test_ro_int24: |
Uwe Bonnes | 99f1d37 | 1998-11-06 16:39:57 +0000 | [diff] [blame] | 225 | if (oldmode == OF_READ) |
Uwe Bonnes | 2e52589 | 1998-11-01 15:04:52 +0000 | [diff] [blame] | 226 | return FALSE; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 227 | /* Fall through */ |
| 228 | fail_int24: |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 229 | FIXME("generate INT24 missing\n"); |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 230 | /* Is this the right error? */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 231 | SetLastError( ERROR_ACCESS_DENIED ); |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 232 | return TRUE; |
| 233 | |
| 234 | test_ro_err05: |
Uwe Bonnes | 99f1d37 | 1998-11-06 16:39:57 +0000 | [diff] [blame] | 235 | if (oldmode == OF_READ) |
Uwe Bonnes | 2e52589 | 1998-11-01 15:04:52 +0000 | [diff] [blame] | 236 | return FALSE; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 237 | /* fall through */ |
| 238 | fail_error05: |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 239 | TRACE("Access Denied, oldmode 0x%02x mode 0x%02x\n",oldmode,mode); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 240 | SetLastError( ERROR_ACCESS_DENIED ); |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 241 | return TRUE; |
| 242 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 243 | #endif |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 244 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 245 | |
| 246 | /*********************************************************************** |
| 247 | * FILE_SetDosError |
| 248 | * |
| 249 | * Set the DOS error code from errno. |
| 250 | */ |
| 251 | void FILE_SetDosError(void) |
| 252 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 253 | int save_errno = errno; /* errno gets overwritten by printf */ |
| 254 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 255 | TRACE("errno = %d %s\n", errno, strerror(errno)); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 256 | switch (save_errno) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 257 | { |
| 258 | case EAGAIN: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 259 | SetLastError( ERROR_SHARING_VIOLATION ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 260 | break; |
| 261 | case EBADF: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 262 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 263 | break; |
| 264 | case ENOSPC: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 265 | SetLastError( ERROR_HANDLE_DISK_FULL ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 266 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 267 | case EACCES: |
| 268 | case EPERM: |
| 269 | case EROFS: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 270 | SetLastError( ERROR_ACCESS_DENIED ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 271 | break; |
| 272 | case EBUSY: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 273 | SetLastError( ERROR_LOCK_VIOLATION ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 274 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 275 | case ENOENT: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 276 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 277 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 278 | case EISDIR: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 279 | SetLastError( ERROR_CANNOT_MAKE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 280 | break; |
| 281 | case ENFILE: |
| 282 | case EMFILE: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 283 | SetLastError( ERROR_NO_MORE_FILES ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 284 | break; |
| 285 | case EEXIST: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 286 | SetLastError( ERROR_FILE_EXISTS ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 287 | break; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 288 | case EINVAL: |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 289 | case ESPIPE: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 290 | SetLastError( ERROR_SEEK ); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 291 | break; |
| 292 | case ENOTEMPTY: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 293 | SetLastError( ERROR_DIR_NOT_EMPTY ); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 294 | break; |
Alexandre Julliard | 045d81f | 2000-05-01 16:20:23 +0000 | [diff] [blame] | 295 | case ENOEXEC: |
| 296 | SetLastError( ERROR_BAD_FORMAT ); |
| 297 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 298 | default: |
Alexandre Julliard | 045d81f | 2000-05-01 16:20:23 +0000 | [diff] [blame] | 299 | perror( "FILE_SetDosError: unknown errno" ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 300 | SetLastError( ERROR_GEN_FAILURE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 301 | break; |
| 302 | } |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 303 | errno = save_errno; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
| 307 | /*********************************************************************** |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 308 | * FILE_DupUnixHandle |
| 309 | * |
| 310 | * Duplicate a Unix handle into a task handle. |
| 311 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 312 | HFILE FILE_DupUnixHandle( int fd, DWORD access ) |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 313 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 314 | struct alloc_file_handle_request *req = get_req_buffer(); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 315 | req->access = access; |
Alexandre Julliard | 8a971bf | 2000-04-04 19:57:23 +0000 | [diff] [blame] | 316 | server_call_fd( REQ_ALLOC_FILE_HANDLE, fd, NULL ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 317 | return req->handle; |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | |
| 321 | /*********************************************************************** |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 322 | * FILE_GetUnixHandle |
| 323 | * |
| 324 | * Retrieve the Unix handle corresponding to a file handle. |
| 325 | */ |
| 326 | int FILE_GetUnixHandle( HANDLE handle, DWORD access ) |
| 327 | { |
| 328 | int unix_handle = -1; |
| 329 | if (access == GENERIC_READ) |
| 330 | { |
| 331 | struct get_read_fd_request *req = get_req_buffer(); |
| 332 | req->handle = handle; |
| 333 | server_call_fd( REQ_GET_READ_FD, -1, &unix_handle ); |
| 334 | } |
| 335 | else if (access == GENERIC_WRITE) |
| 336 | { |
| 337 | struct get_write_fd_request *req = get_req_buffer(); |
| 338 | req->handle = handle; |
| 339 | server_call_fd( REQ_GET_WRITE_FD, -1, &unix_handle ); |
| 340 | } |
| 341 | else ERR( "bad access %08lx\n", access ); |
| 342 | return unix_handle; |
| 343 | } |
| 344 | |
| 345 | |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 346 | /************************************************************************* |
| 347 | * FILE_OpenConsole |
| 348 | * |
| 349 | * Open a handle to the current process console. |
| 350 | */ |
| 351 | static HANDLE FILE_OpenConsole( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES sa ) |
| 352 | { |
| 353 | int ret = -1; |
| 354 | |
| 355 | SERVER_START_REQ |
| 356 | { |
| 357 | struct open_console_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 358 | |
| 359 | req->output = output; |
| 360 | req->access = access; |
| 361 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 362 | SetLastError(0); |
| 363 | if (!server_call( REQ_OPEN_CONSOLE )) ret = req->handle; |
| 364 | } |
| 365 | SERVER_END_REQ; |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 370 | /*********************************************************************** |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 371 | * FILE_CreateFile |
| 372 | * |
| 373 | * Implementation of CreateFile. Takes a Unix path name. |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 374 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 375 | HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 376 | LPSECURITY_ATTRIBUTES sa, DWORD creation, |
| 377 | DWORD attributes, HANDLE template, BOOL fail_read_only ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 378 | { |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 379 | DWORD err; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 380 | HANDLE ret; |
| 381 | size_t len = strlen(filename); |
| 382 | |
| 383 | if (len > REQUEST_MAX_VAR_SIZE) |
| 384 | { |
| 385 | FIXME("filename '%s' too long\n", filename ); |
| 386 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 387 | return -1; |
| 388 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 389 | |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 390 | restart: |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 391 | SERVER_START_REQ |
| 392 | { |
| 393 | struct create_file_request *req = server_alloc_req( sizeof(*req), len ); |
| 394 | req->access = access; |
| 395 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 396 | req->sharing = sharing; |
| 397 | req->create = creation; |
| 398 | req->attrs = attributes; |
| 399 | memcpy( server_data_ptr(req), filename, len ); |
| 400 | SetLastError(0); |
| 401 | err = server_call( REQ_CREATE_FILE ); |
| 402 | ret = req->handle; |
| 403 | } |
| 404 | SERVER_END_REQ; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 405 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 406 | /* If write access failed, retry without GENERIC_WRITE */ |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 407 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 408 | if ((ret == -1) && !fail_read_only && (access & GENERIC_WRITE)) |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 409 | { |
Andreas Mohr | af7e1ae | 2000-04-13 15:58:30 +0000 | [diff] [blame] | 410 | if ((err == STATUS_MEDIA_WRITE_PROTECTED) || (err == STATUS_ACCESS_DENIED)) |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 411 | { |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 412 | TRACE("Write access failed for file '%s', trying without " |
Andreas Mohr | 2caee71 | 2000-07-16 15:44:22 +0000 | [diff] [blame] | 413 | "write access\n", filename); |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 414 | access &= ~GENERIC_WRITE; |
| 415 | goto restart; |
| 416 | } |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 419 | if (ret == -1) |
Andreas Mohr | 2caee71 | 2000-07-16 15:44:22 +0000 | [diff] [blame] | 420 | WARN("Unable to create file '%s' (GLE %ld)\n", filename, |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 421 | GetLastError()); |
| 422 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 423 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | |
| 427 | /*********************************************************************** |
| 428 | * FILE_CreateDevice |
| 429 | * |
| 430 | * Same as FILE_CreateFile but for a device |
| 431 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 432 | HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 433 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 434 | HFILE ret; |
| 435 | SERVER_START_REQ |
| 436 | { |
| 437 | struct create_device_request *req = server_alloc_req( sizeof(*req), 0 ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 438 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 439 | req->access = access; |
| 440 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 441 | req->id = client_id; |
| 442 | SetLastError(0); |
| 443 | server_call( REQ_CREATE_DEVICE ); |
| 444 | ret = req->handle; |
| 445 | } |
| 446 | SERVER_END_REQ; |
| 447 | return ret; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 451 | /************************************************************************* |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 452 | * CreateFileA [KERNEL32.45] Creates or opens a file or other object |
Uwe Bonnes | a370ab4 | 1998-10-24 09:16:44 +0000 | [diff] [blame] | 453 | * |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 454 | * Creates or opens an object, and returns a handle that can be used to |
| 455 | * access that object. |
Uwe Bonnes | a370ab4 | 1998-10-24 09:16:44 +0000 | [diff] [blame] | 456 | * |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 457 | * PARAMS |
| 458 | * |
| 459 | * filename [I] pointer to filename to be accessed |
| 460 | * access [I] access mode requested |
| 461 | * sharing [I] share mode |
| 462 | * sa [I] pointer to security attributes |
| 463 | * creation [I] how to create the file |
| 464 | * attributes [I] attributes for newly created file |
| 465 | * template [I] handle to file with extended attributes to copy |
| 466 | * |
| 467 | * RETURNS |
| 468 | * Success: Open handle to specified file |
| 469 | * Failure: INVALID_HANDLE_VALUE |
| 470 | * |
| 471 | * NOTES |
| 472 | * Should call SetLastError() on failure. |
| 473 | * |
| 474 | * BUGS |
| 475 | * |
| 476 | * Doesn't support character devices, pipes, template files, or a |
| 477 | * lot of the 'attributes' flags yet. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 478 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 479 | HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing, |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 480 | LPSECURITY_ATTRIBUTES sa, DWORD creation, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 481 | DWORD attributes, HANDLE template ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 482 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 483 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 484 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 485 | if (!filename) |
| 486 | { |
| 487 | SetLastError( ERROR_INVALID_PARAMETER ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 488 | return HFILE_ERROR; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 489 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 490 | TRACE("%s %s%s%s%s%s%s%s\n",filename, |
Uwe Bonnes | e4f46dc | 1999-06-06 17:08:13 +0000 | [diff] [blame] | 491 | ((access & GENERIC_READ)==GENERIC_READ)?"GENERIC_READ ":"", |
| 492 | ((access & GENERIC_WRITE)==GENERIC_WRITE)?"GENERIC_WRITE ":"", |
| 493 | (!access)?"QUERY_ACCESS ":"", |
| 494 | ((sharing & FILE_SHARE_READ)==FILE_SHARE_READ)?"FILE_SHARE_READ ":"", |
| 495 | ((sharing & FILE_SHARE_WRITE)==FILE_SHARE_WRITE)?"FILE_SHARE_WRITE ":"", |
| 496 | ((sharing & FILE_SHARE_DELETE)==FILE_SHARE_DELETE)?"FILE_SHARE_DELETE ":"", |
| 497 | (creation ==CREATE_NEW)?"CREATE_NEW": |
| 498 | (creation ==CREATE_ALWAYS)?"CREATE_ALWAYS ": |
| 499 | (creation ==OPEN_EXISTING)?"OPEN_EXISTING ": |
| 500 | (creation ==OPEN_ALWAYS)?"OPEN_ALWAYS ": |
| 501 | (creation ==TRUNCATE_EXISTING)?"TRUNCATE_EXISTING ":""); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 502 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 503 | /* If the name starts with '\\?\', ignore the first 4 chars. */ |
| 504 | if (!strncmp(filename, "\\\\?\\", 4)) |
| 505 | { |
| 506 | filename += 4; |
| 507 | if (!strncmp(filename, "UNC\\", 4)) |
| 508 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 509 | FIXME("UNC name (%s) not supported.\n", filename ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 510 | SetLastError( ERROR_PATH_NOT_FOUND ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 511 | return HFILE_ERROR; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 512 | } |
| 513 | } |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 514 | |
Marcus Meissner | dd7523d | 2000-01-23 02:18:27 +0000 | [diff] [blame] | 515 | if (!strncmp(filename, "\\\\.\\", 4)) { |
| 516 | if (!DOSFS_GetDevice( filename )) |
| 517 | return DEVICE_Open( filename+4, access, sa ); |
| 518 | else |
| 519 | filename+=4; /* fall into DOSFS_Device case below */ |
| 520 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 521 | |
| 522 | /* If the name still starts with '\\', it's a UNC name. */ |
| 523 | if (!strncmp(filename, "\\\\", 2)) |
| 524 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 525 | FIXME("UNC name (%s) not supported.\n", filename ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 526 | SetLastError( ERROR_PATH_NOT_FOUND ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 527 | return HFILE_ERROR; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Francois Boisvert | 567bcf1 | 1999-09-20 18:31:21 +0000 | [diff] [blame] | 530 | /* If the name contains a DOS wild card (* or ?), do no create a file */ |
| 531 | if(strchr(filename,'*') || strchr(filename,'?')) |
| 532 | return HFILE_ERROR; |
| 533 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 534 | /* Open a console for CONIN$ or CONOUT$ */ |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 535 | if (!strcasecmp(filename, "CONIN$")) return FILE_OpenConsole( FALSE, access, sa ); |
| 536 | if (!strcasecmp(filename, "CONOUT$")) return FILE_OpenConsole( TRUE, access, sa ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 537 | |
| 538 | if (DOSFS_GetDevice( filename )) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 539 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 540 | HFILE ret; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 541 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 542 | TRACE("opening device '%s'\n", filename ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 543 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 544 | if (HFILE_ERROR!=(ret=DOSFS_OpenDevice( filename, access ))) |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 545 | return ret; |
| 546 | |
| 547 | /* Do not silence this please. It is a critical error. -MM */ |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 548 | ERR("Couldn't open device '%s'!\n",filename); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 549 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 550 | return HFILE_ERROR; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 551 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 552 | |
| 553 | /* check for filename, don't check for last entry if creating */ |
| 554 | if (!DOSFS_GetFullName( filename, |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 555 | (creation == OPEN_EXISTING) || |
| 556 | (creation == TRUNCATE_EXISTING), |
| 557 | &full_name )) { |
| 558 | WARN("Unable to get full filename from '%s' (GLE %ld)\n", |
| 559 | filename, GetLastError()); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 560 | return HFILE_ERROR; |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 561 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 562 | |
| 563 | return FILE_CreateFile( full_name.long_name, access, sharing, |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 564 | sa, creation, attributes, template, |
| 565 | DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 569 | |
| 570 | /************************************************************************* |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 571 | * CreateFileW (KERNEL32.48) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 572 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 573 | HANDLE WINAPI CreateFileW( LPCWSTR filename, DWORD access, DWORD sharing, |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 574 | LPSECURITY_ATTRIBUTES sa, DWORD creation, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 575 | DWORD attributes, HANDLE template) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 576 | { |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 577 | LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 578 | HANDLE res = CreateFileA( afn, access, sharing, sa, creation, attributes, template ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 579 | HeapFree( GetProcessHeap(), 0, afn ); |
| 580 | return res; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | |
| 584 | /*********************************************************************** |
| 585 | * FILE_FillInfo |
| 586 | * |
| 587 | * Fill a file information from a struct stat. |
| 588 | */ |
| 589 | static void FILE_FillInfo( struct stat *st, BY_HANDLE_FILE_INFORMATION *info ) |
| 590 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 591 | if (S_ISDIR(st->st_mode)) |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 592 | info->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; |
| 593 | else |
| 594 | info->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 595 | if (!(st->st_mode & S_IWUSR)) |
| 596 | info->dwFileAttributes |= FILE_ATTRIBUTE_READONLY; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 597 | |
Alexandre Julliard | e101f6d | 2000-08-14 14:42:41 +0000 | [diff] [blame] | 598 | RtlSecondsSince1970ToTime( st->st_mtime, &info->ftCreationTime ); |
| 599 | RtlSecondsSince1970ToTime( st->st_mtime, &info->ftLastWriteTime ); |
| 600 | RtlSecondsSince1970ToTime( st->st_atime, &info->ftLastAccessTime ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 601 | |
| 602 | info->dwVolumeSerialNumber = 0; /* FIXME */ |
| 603 | info->nFileSizeHigh = 0; |
| 604 | info->nFileSizeLow = S_ISDIR(st->st_mode) ? 0 : st->st_size; |
| 605 | info->nNumberOfLinks = st->st_nlink; |
| 606 | info->nFileIndexHigh = 0; |
| 607 | info->nFileIndexLow = st->st_ino; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | |
| 611 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 612 | * FILE_Stat |
| 613 | * |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 614 | * Stat a Unix path name. Return TRUE if OK. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 615 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 616 | BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 617 | { |
| 618 | struct stat st; |
| 619 | |
Andreas Mohr | 220312e | 2000-10-19 20:38:38 +0000 | [diff] [blame^] | 620 | if (lstat( unixName, &st ) == -1) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 621 | { |
| 622 | FILE_SetDosError(); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 623 | return FALSE; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 624 | } |
Andreas Mohr | 220312e | 2000-10-19 20:38:38 +0000 | [diff] [blame^] | 625 | if (!S_ISLNK(st.st_mode)) FILE_FillInfo( &st, info ); |
| 626 | else |
| 627 | { |
| 628 | /* do a "real" stat to find out |
| 629 | about the type of the symlink destination */ |
| 630 | if (stat( unixName, &st ) == -1) |
| 631 | { |
| 632 | FILE_SetDosError(); |
| 633 | return FALSE; |
| 634 | } |
| 635 | FILE_FillInfo( &st, info ); |
| 636 | info->dwFileAttributes |= FILE_ATTRIBUTE_SYMLINK; |
| 637 | } |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 638 | return TRUE; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | |
| 642 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 643 | * GetFileInformationByHandle (KERNEL32.219) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 644 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 645 | DWORD WINAPI GetFileInformationByHandle( HANDLE hFile, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 646 | BY_HANDLE_FILE_INFORMATION *info ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 647 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 648 | DWORD ret; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 649 | if (!info) return 0; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 650 | |
| 651 | SERVER_START_REQ |
| 652 | { |
| 653 | struct get_file_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 654 | req->handle = hFile; |
| 655 | if ((ret = !server_call( REQ_GET_FILE_INFO ))) |
| 656 | { |
| 657 | RtlSecondsSince1970ToTime( req->write_time, &info->ftCreationTime ); |
| 658 | RtlSecondsSince1970ToTime( req->write_time, &info->ftLastWriteTime ); |
| 659 | RtlSecondsSince1970ToTime( req->access_time, &info->ftLastAccessTime ); |
| 660 | info->dwFileAttributes = req->attr; |
| 661 | info->dwVolumeSerialNumber = req->serial; |
| 662 | info->nFileSizeHigh = req->size_high; |
| 663 | info->nFileSizeLow = req->size_low; |
| 664 | info->nNumberOfLinks = req->links; |
| 665 | info->nFileIndexHigh = req->index_high; |
| 666 | info->nFileIndexLow = req->index_low; |
| 667 | } |
| 668 | } |
| 669 | SERVER_END_REQ; |
| 670 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | |
| 674 | /************************************************************************** |
| 675 | * GetFileAttributes16 (KERNEL.420) |
| 676 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 677 | DWORD WINAPI GetFileAttributes16( LPCSTR name ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 678 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 679 | return GetFileAttributesA( name ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
| 683 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 684 | * GetFileAttributesA (KERNEL32.217) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 685 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 686 | DWORD WINAPI GetFileAttributesA( LPCSTR name ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 687 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 688 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 689 | BY_HANDLE_FILE_INFORMATION info; |
| 690 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 691 | if (name == NULL || *name=='\0') return -1; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 692 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 693 | if (!DOSFS_GetFullName( name, TRUE, &full_name )) return -1; |
| 694 | if (!FILE_Stat( full_name.long_name, &info )) return -1; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 695 | return info.dwFileAttributes; |
| 696 | } |
| 697 | |
| 698 | |
| 699 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 700 | * GetFileAttributesW (KERNEL32.218) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 701 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 702 | DWORD WINAPI GetFileAttributesW( LPCWSTR name ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 703 | { |
| 704 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 705 | DWORD res = GetFileAttributesA( nameA ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 706 | HeapFree( GetProcessHeap(), 0, nameA ); |
| 707 | return res; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | |
| 711 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 712 | * GetFileSize (KERNEL32.220) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 713 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 714 | DWORD WINAPI GetFileSize( HANDLE hFile, LPDWORD filesizehigh ) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 715 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 716 | BY_HANDLE_FILE_INFORMATION info; |
| 717 | if (!GetFileInformationByHandle( hFile, &info )) return 0; |
| 718 | if (filesizehigh) *filesizehigh = info.nFileSizeHigh; |
| 719 | return info.nFileSizeLow; |
| 720 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 721 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 722 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 723 | /*********************************************************************** |
| 724 | * GetFileTime (KERNEL32.221) |
| 725 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 726 | BOOL WINAPI GetFileTime( HANDLE hFile, FILETIME *lpCreationTime, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 727 | FILETIME *lpLastAccessTime, |
| 728 | FILETIME *lpLastWriteTime ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 729 | { |
| 730 | BY_HANDLE_FILE_INFORMATION info; |
| 731 | if (!GetFileInformationByHandle( hFile, &info )) return FALSE; |
| 732 | if (lpCreationTime) *lpCreationTime = info.ftCreationTime; |
| 733 | if (lpLastAccessTime) *lpLastAccessTime = info.ftLastAccessTime; |
| 734 | if (lpLastWriteTime) *lpLastWriteTime = info.ftLastWriteTime; |
| 735 | return TRUE; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 738 | /*********************************************************************** |
| 739 | * CompareFileTime (KERNEL32.28) |
| 740 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 741 | INT WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y ) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 742 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 743 | if (!x || !y) return -1; |
| 744 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 745 | if (x->dwHighDateTime > y->dwHighDateTime) |
| 746 | return 1; |
| 747 | if (x->dwHighDateTime < y->dwHighDateTime) |
| 748 | return -1; |
| 749 | if (x->dwLowDateTime > y->dwLowDateTime) |
| 750 | return 1; |
| 751 | if (x->dwLowDateTime < y->dwLowDateTime) |
| 752 | return -1; |
| 753 | return 0; |
| 754 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 755 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 756 | /*********************************************************************** |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 757 | * FILE_GetTempFileName : utility for GetTempFileName |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 758 | */ |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 759 | static UINT FILE_GetTempFileName( LPCSTR path, LPCSTR prefix, UINT unique, |
| 760 | LPSTR buffer, BOOL isWin16 ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 761 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 762 | static UINT unique_temp; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 763 | DOS_FULL_NAME full_name; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 764 | int i; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 765 | LPSTR p; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 766 | UINT num; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 767 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 768 | if ( !path || !prefix || !buffer ) return 0; |
| 769 | |
Uwe Bonnes | 2e52589 | 1998-11-01 15:04:52 +0000 | [diff] [blame] | 770 | if (!unique_temp) unique_temp = time(NULL) & 0xffff; |
| 771 | num = unique ? (unique & 0xffff) : (unique_temp++ & 0xffff); |
| 772 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 773 | strcpy( buffer, path ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 774 | p = buffer + strlen(buffer); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 775 | |
| 776 | /* add a \, if there isn't one and path is more than just the drive letter ... */ |
| 777 | if ( !((strlen(buffer) == 2) && (buffer[1] == ':')) |
| 778 | && ((p == buffer) || (p[-1] != '\\'))) *p++ = '\\'; |
| 779 | |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 780 | if (isWin16) *p++ = '~'; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 781 | for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++; |
| 782 | sprintf( p, "%04x.tmp", num ); |
| 783 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 784 | /* Now try to create it */ |
| 785 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 786 | if (!unique) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 787 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 788 | do |
| 789 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 790 | HFILE handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL, |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 791 | CREATE_NEW, FILE_ATTRIBUTE_NORMAL, -1 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 792 | if (handle != INVALID_HANDLE_VALUE) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 793 | { /* We created it */ |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 794 | TRACE("created %s\n", |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 795 | buffer); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 796 | CloseHandle( handle ); |
| 797 | break; |
| 798 | } |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 799 | if (GetLastError() != ERROR_FILE_EXISTS) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 800 | break; /* No need to go on */ |
| 801 | num++; |
| 802 | sprintf( p, "%04x.tmp", num ); |
| 803 | } while (num != (unique & 0xffff)); |
| 804 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 805 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 806 | /* Get the full path name */ |
| 807 | |
| 808 | if (DOSFS_GetFullName( buffer, FALSE, &full_name )) |
| 809 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 810 | /* Check if we have write access in the directory */ |
| 811 | if ((p = strrchr( full_name.long_name, '/' ))) *p = '\0'; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 812 | if (access( full_name.long_name, W_OK ) == -1) |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 813 | WARN("returns '%s', which doesn't seem to be writeable.\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 814 | buffer); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 815 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 816 | TRACE("returning %s\n", buffer ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 817 | return unique ? unique : num; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | |
| 821 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 822 | * GetTempFileNameA (KERNEL32.290) |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 823 | */ |
| 824 | UINT WINAPI GetTempFileNameA( LPCSTR path, LPCSTR prefix, UINT unique, |
| 825 | LPSTR buffer) |
| 826 | { |
| 827 | return FILE_GetTempFileName(path, prefix, unique, buffer, FALSE); |
| 828 | } |
| 829 | |
| 830 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 831 | * GetTempFileNameW (KERNEL32.291) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 832 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 833 | UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 834 | LPWSTR buffer ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 835 | { |
| 836 | LPSTR patha,prefixa; |
| 837 | char buffera[144]; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 838 | UINT ret; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 839 | |
| 840 | if (!path) return 0; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 841 | patha = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
| 842 | prefixa = HEAP_strdupWtoA( GetProcessHeap(), 0, prefix ); |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 843 | ret = FILE_GetTempFileName( patha, prefixa, unique, buffera, FALSE ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 844 | lstrcpyAtoW( buffer, buffera ); |
| 845 | HeapFree( GetProcessHeap(), 0, patha ); |
| 846 | HeapFree( GetProcessHeap(), 0, prefixa ); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 847 | return ret; |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /*********************************************************************** |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 852 | * GetTempFileName16 (KERNEL.97) |
| 853 | */ |
| 854 | UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique, |
| 855 | LPSTR buffer ) |
| 856 | { |
| 857 | char temppath[144]; |
| 858 | |
| 859 | if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */ |
| 860 | drive |= DRIVE_GetCurrentDrive() + 'A'; |
| 861 | |
| 862 | if ((drive & TF_FORCEDRIVE) && |
| 863 | !DRIVE_IsValid( toupper(drive & ~TF_FORCEDRIVE) - 'A' )) |
| 864 | { |
| 865 | drive &= ~TF_FORCEDRIVE; |
| 866 | WARN("invalid drive %d specified\n", drive ); |
| 867 | } |
| 868 | |
| 869 | if (drive & TF_FORCEDRIVE) |
| 870 | sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE ); |
| 871 | else |
| 872 | GetTempPathA( 132, temppath ); |
| 873 | return (UINT16)FILE_GetTempFileName( temppath, prefix, unique, buffer, TRUE ); |
| 874 | } |
| 875 | |
| 876 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 877 | * FILE_DoOpenFile |
| 878 | * |
| 879 | * Implementation of OpenFile16() and OpenFile32(). |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 880 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 881 | static HFILE FILE_DoOpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode, |
| 882 | BOOL win32 ) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 883 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 884 | HFILE hFileRet; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 885 | FILETIME filetime; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 886 | WORD filedatetime[2]; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 887 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 888 | DWORD access, sharing; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 889 | char *p; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 890 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 891 | if (!ofs) return HFILE_ERROR; |
Uwe Bonnes | e4f46dc | 1999-06-06 17:08:13 +0000 | [diff] [blame] | 892 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 893 | TRACE("%s %s %s %s%s%s%s%s%s%s%s%s\n",name, |
Uwe Bonnes | e4f46dc | 1999-06-06 17:08:13 +0000 | [diff] [blame] | 894 | ((mode & 0x3 )==OF_READ)?"OF_READ": |
| 895 | ((mode & 0x3 )==OF_WRITE)?"OF_WRITE": |
| 896 | ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown", |
| 897 | ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT": |
| 898 | ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE": |
| 899 | ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ": |
| 900 | ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE": |
| 901 | ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown", |
| 902 | ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"", |
| 903 | ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"", |
| 904 | ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"", |
| 905 | ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"", |
| 906 | ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"", |
| 907 | ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"", |
| 908 | ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"", |
| 909 | ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"", |
| 910 | ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":"" |
| 911 | ); |
| 912 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 913 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 914 | ofs->cBytes = sizeof(OFSTRUCT); |
| 915 | ofs->nErrCode = 0; |
| 916 | if (mode & OF_REOPEN) name = ofs->szPathName; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 917 | |
| 918 | if (!name) { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 919 | ERR("called with `name' set to NULL ! Please debug.\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 920 | return HFILE_ERROR; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 921 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 922 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 923 | TRACE("%s %04x\n", name, mode ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 924 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 925 | /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName |
| 926 | Are there any cases where getting the path here is wrong? |
| 927 | Uwe Bonnes 1997 Apr 2 */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 928 | if (!GetFullPathNameA( name, sizeof(ofs->szPathName), |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 929 | ofs->szPathName, NULL )) goto error; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 930 | FILE_ConvertOFMode( mode, &access, &sharing ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 931 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 932 | /* OF_PARSE simply fills the structure */ |
| 933 | |
| 934 | if (mode & OF_PARSE) |
| 935 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 936 | ofs->fFixedDisk = (GetDriveType16( ofs->szPathName[0]-'A' ) |
| 937 | != DRIVE_REMOVABLE); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 938 | TRACE("(%s): OF_PARSE, res = '%s'\n", |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 939 | name, ofs->szPathName ); |
| 940 | return 0; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /* OF_CREATE is completely different from all other options, so |
| 944 | handle it first */ |
| 945 | |
| 946 | if (mode & OF_CREATE) |
| 947 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 948 | if ((hFileRet = CreateFileA( name, GENERIC_READ | GENERIC_WRITE, |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 949 | sharing, NULL, CREATE_ALWAYS, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 950 | FILE_ATTRIBUTE_NORMAL, -1 ))== INVALID_HANDLE_VALUE) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 951 | goto error; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 952 | goto success; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 955 | /* If OF_SEARCH is set, ignore the given path */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 956 | |
| 957 | if ((mode & OF_SEARCH) && !(mode & OF_REOPEN)) |
| 958 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 959 | /* First try the file name as is */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 960 | if (DOSFS_GetFullName( name, TRUE, &full_name )) goto found; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 961 | /* Now remove the path */ |
| 962 | if (name[0] && (name[1] == ':')) name += 2; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 963 | if ((p = strrchr( name, '\\' ))) name = p + 1; |
| 964 | if ((p = strrchr( name, '/' ))) name = p + 1; |
| 965 | if (!name[0]) goto not_found; |
| 966 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 967 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 968 | /* Now look for the file */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 969 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 970 | if (!DIR_SearchPath( NULL, name, NULL, &full_name, win32 )) goto not_found; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 971 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 972 | found: |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 973 | TRACE("found %s = %s\n", |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 974 | full_name.long_name, full_name.short_name ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 975 | lstrcpynA( ofs->szPathName, full_name.short_name, |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 976 | sizeof(ofs->szPathName) ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 977 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 978 | if (mode & OF_SHARE_EXCLUSIVE) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 979 | /* Some InstallShield version uses OF_SHARE_EXCLUSIVE |
| 980 | on the file <tempdir>/_ins0432._mp to determine how |
| 981 | far installation has proceeded. |
| 982 | _ins0432._mp is an executable and while running the |
| 983 | application expects the open with OF_SHARE_ to fail*/ |
| 984 | /* Probable FIXME: |
| 985 | As our loader closes the files after loading the executable, |
| 986 | we can't find the running executable with FILE_InUse. |
| 987 | Perhaps the loader should keep the file open. |
| 988 | Recheck against how Win handles that case */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 989 | { |
| 990 | char *last = strrchr(full_name.long_name,'/'); |
| 991 | if (!last) |
| 992 | last = full_name.long_name - 1; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 993 | if (GetModuleHandle16(last+1)) |
| 994 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 995 | TRACE("Denying shared open for %s\n",full_name.long_name); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 996 | return HFILE_ERROR; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 997 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1000 | if (mode & OF_DELETE) |
| 1001 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1002 | if (unlink( full_name.long_name ) == -1) goto not_found; |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1003 | TRACE("(%s): OF_DELETE return = OK\n", name); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1004 | return 1; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1007 | hFileRet = FILE_CreateFile( full_name.long_name, access, sharing, |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 1008 | NULL, OPEN_EXISTING, 0, -1, |
| 1009 | DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1010 | if (hFileRet == HFILE_ERROR) goto not_found; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 1011 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1012 | GetFileTime( hFileRet, NULL, NULL, &filetime ); |
| 1013 | FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1014 | if ((mode & OF_VERIFY) && (mode & OF_REOPEN)) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1015 | { |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1016 | if (memcmp( ofs->reserved, filedatetime, sizeof(ofs->reserved) )) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1017 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1018 | CloseHandle( hFileRet ); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1019 | WARN("(%s): OF_VERIFY failed\n", name ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1020 | /* FIXME: what error here? */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1021 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1022 | goto error; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1023 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1024 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1025 | memcpy( ofs->reserved, filedatetime, sizeof(ofs->reserved) ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1026 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1027 | success: /* We get here if the open was successful */ |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1028 | TRACE("(%s): OK, return = %d\n", name, hFileRet ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1029 | if (win32) |
| 1030 | { |
| 1031 | if (mode & OF_EXIST) /* Return the handle, but close it first */ |
| 1032 | CloseHandle( hFileRet ); |
| 1033 | } |
| 1034 | else |
| 1035 | { |
| 1036 | hFileRet = FILE_AllocDosHandle( hFileRet ); |
| 1037 | if (hFileRet == HFILE_ERROR16) goto error; |
| 1038 | if (mode & OF_EXIST) /* Return the handle, but close it first */ |
| 1039 | _lclose16( hFileRet ); |
| 1040 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1041 | return hFileRet; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1042 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1043 | not_found: /* We get here if the file does not exist */ |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 1044 | WARN("'%s' not found or sharing violation\n", name ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1045 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1046 | /* fall through */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1047 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1048 | error: /* We get here if there was an error opening the file */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1049 | ofs->nErrCode = GetLastError(); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1050 | WARN("(%s): return = HFILE_ERROR error= %d\n", |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1051 | name,ofs->nErrCode ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1052 | return HFILE_ERROR; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 1055 | |
| 1056 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1057 | * OpenFile16 (KERNEL.74) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 1058 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1059 | HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1060 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1061 | return FILE_DoOpenFile( name, ofs, mode, FALSE ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 1062 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1063 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1064 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1065 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1066 | * OpenFile (KERNEL32.396) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1067 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1068 | HFILE WINAPI OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1069 | { |
| 1070 | return FILE_DoOpenFile( name, ofs, mode, TRUE ); |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | /*********************************************************************** |
Marcus Meissner | b12e72d | 1999-01-23 14:01:08 +0000 | [diff] [blame] | 1075 | * FILE_InitProcessDosHandles |
| 1076 | * |
| 1077 | * Allocates the default DOS handles for a process. Called either by |
| 1078 | * AllocDosHandle below or by the DOSVM stuff. |
| 1079 | */ |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1080 | static void FILE_InitProcessDosHandles( void ) |
| 1081 | { |
| 1082 | dos_handles[0] = GetStdHandle(STD_INPUT_HANDLE); |
| 1083 | dos_handles[1] = GetStdHandle(STD_OUTPUT_HANDLE); |
| 1084 | dos_handles[2] = GetStdHandle(STD_ERROR_HANDLE); |
| 1085 | dos_handles[3] = GetStdHandle(STD_ERROR_HANDLE); |
| 1086 | dos_handles[4] = GetStdHandle(STD_ERROR_HANDLE); |
Marcus Meissner | b12e72d | 1999-01-23 14:01:08 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /*********************************************************************** |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1090 | * FILE_AllocDosHandle |
| 1091 | * |
| 1092 | * Allocate a DOS handle for a Win32 handle. The Win32 handle is no |
| 1093 | * longer valid after this function (even on failure). |
| 1094 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1095 | HFILE16 FILE_AllocDosHandle( HANDLE handle ) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1096 | { |
| 1097 | int i; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1098 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1099 | if (!handle || (handle == INVALID_HANDLE_VALUE)) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1100 | return INVALID_HANDLE_VALUE16; |
| 1101 | |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1102 | for (i = 5; i < DOS_TABLE_SIZE; i++) |
| 1103 | if (!dos_handles[i]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1104 | { |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1105 | dos_handles[i] = handle; |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1106 | TRACE("Got %d for h32 %d\n", i, handle ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1107 | return i; |
| 1108 | } |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1109 | CloseHandle( handle ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1110 | SetLastError( ERROR_TOO_MANY_OPEN_FILES ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1111 | return INVALID_HANDLE_VALUE16; |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1116 | * FILE_GetHandle |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1117 | * |
| 1118 | * Return the Win32 handle for a DOS handle. |
| 1119 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1120 | HANDLE FILE_GetHandle( HFILE16 hfile ) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1121 | { |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1122 | if (hfile < 5 && !dos_handles[hfile]) FILE_InitProcessDosHandles(); |
| 1123 | if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1124 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1125 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1126 | return INVALID_HANDLE_VALUE; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1127 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1128 | return dos_handles[hfile]; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | /*********************************************************************** |
| 1133 | * FILE_Dup2 |
| 1134 | * |
| 1135 | * dup2() function for DOS handles. |
| 1136 | */ |
| 1137 | HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) |
| 1138 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1139 | HANDLE new_handle; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1140 | |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1141 | if (hFile1 < 5 && !dos_handles[hFile1]) FILE_InitProcessDosHandles(); |
| 1142 | |
| 1143 | if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) || !dos_handles[hFile1]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1144 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1145 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1146 | return HFILE_ERROR16; |
| 1147 | } |
| 1148 | if (hFile2 < 5) |
| 1149 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1150 | FIXME("stdio handle closed, need proper conversion\n" ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1151 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1152 | return HFILE_ERROR16; |
| 1153 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1154 | if (!DuplicateHandle( GetCurrentProcess(), dos_handles[hFile1], |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1155 | GetCurrentProcess(), &new_handle, |
| 1156 | 0, FALSE, DUPLICATE_SAME_ACCESS )) |
| 1157 | return HFILE_ERROR16; |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1158 | if (dos_handles[hFile2]) CloseHandle( dos_handles[hFile2] ); |
| 1159 | dos_handles[hFile2] = new_handle; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1160 | return hFile2; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1165 | * _lclose16 (KERNEL.81) |
| 1166 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1167 | HFILE16 WINAPI _lclose16( HFILE16 hFile ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1168 | { |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1169 | if (hFile < 5) |
| 1170 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1171 | FIXME("stdio handle closed, need proper conversion\n" ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1172 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1173 | return HFILE_ERROR16; |
| 1174 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1175 | if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1176 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1177 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1178 | return HFILE_ERROR16; |
| 1179 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1180 | TRACE("%d (handle32=%d)\n", hFile, dos_handles[hFile] ); |
| 1181 | CloseHandle( dos_handles[hFile] ); |
| 1182 | dos_handles[hFile] = 0; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1183 | return 0; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1188 | * _lclose (KERNEL32.592) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1189 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1190 | HFILE WINAPI _lclose( HFILE hFile ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1191 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1192 | TRACE("handle %d\n", hFile ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1193 | return CloseHandle( hFile ) ? 0 : HFILE_ERROR; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Moshe Vainer | 0ea089b | 1999-11-10 19:51:01 +0000 | [diff] [blame] | 1196 | /*********************************************************************** |
| 1197 | * GetOverlappedResult (KERNEL32.360) |
| 1198 | */ |
| 1199 | BOOL WINAPI GetOverlappedResult(HANDLE hFile,LPOVERLAPPED lpOverlapped, |
| 1200 | LPDWORD lpNumberOfBytesTransferred, |
| 1201 | BOOL bWait) |
| 1202 | { |
Andreas Mohr | 2caee71 | 2000-07-16 15:44:22 +0000 | [diff] [blame] | 1203 | /* Since all i/o is currently synchronous, |
Moshe Vainer | 0ea089b | 1999-11-10 19:51:01 +0000 | [diff] [blame] | 1204 | * return true, assuming ReadFile/WriteFile |
| 1205 | * have completed the operation */ |
| 1206 | FIXME("NO Asynch I/O, assuming Read/Write succeeded\n" ); |
| 1207 | return TRUE; |
| 1208 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1209 | |
| 1210 | /*********************************************************************** |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1211 | * ReadFile (KERNEL32.428) |
| 1212 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1213 | BOOL WINAPI ReadFile( HANDLE hFile, LPVOID buffer, DWORD bytesToRead, |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1214 | LPDWORD bytesRead, LPOVERLAPPED overlapped ) |
| 1215 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1216 | int unix_handle, result; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1217 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1218 | TRACE("%d %p %ld\n", hFile, buffer, bytesToRead ); |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1219 | |
| 1220 | if (bytesRead) *bytesRead = 0; /* Do this before anything else */ |
| 1221 | if (!bytesToRead) return TRUE; |
| 1222 | |
Peter Ganten | f6c4388 | 1999-12-11 23:08:00 +0000 | [diff] [blame] | 1223 | if ( overlapped ) { |
| 1224 | SetLastError ( ERROR_INVALID_PARAMETER ); |
| 1225 | return FALSE; |
| 1226 | } |
| 1227 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 1228 | unix_handle = FILE_GetUnixHandle( hFile, GENERIC_READ ); |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1229 | if (unix_handle == -1) return FALSE; |
| 1230 | while ((result = read( unix_handle, buffer, bytesToRead )) == -1) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1231 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1232 | if ((errno == EAGAIN) || (errno == EINTR)) continue; |
Gerard Patel | f69c150 | 2000-05-07 18:26:19 +0000 | [diff] [blame] | 1233 | if ((errno == EFAULT) && !VIRTUAL_HandleFault( buffer )) continue; |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1234 | FILE_SetDosError(); |
| 1235 | break; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1236 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1237 | close( unix_handle ); |
| 1238 | if (result == -1) return FALSE; |
| 1239 | if (bytesRead) *bytesRead = result; |
| 1240 | return TRUE; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | /*********************************************************************** |
| 1245 | * WriteFile (KERNEL32.578) |
| 1246 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1247 | BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1248 | LPDWORD bytesWritten, LPOVERLAPPED overlapped ) |
| 1249 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1250 | int unix_handle, result; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1251 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1252 | TRACE("%d %p %ld\n", hFile, buffer, bytesToWrite ); |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1253 | |
| 1254 | if (bytesWritten) *bytesWritten = 0; /* Do this before anything else */ |
| 1255 | if (!bytesToWrite) return TRUE; |
| 1256 | |
Peter Ganten | f6c4388 | 1999-12-11 23:08:00 +0000 | [diff] [blame] | 1257 | if ( overlapped ) { |
| 1258 | SetLastError ( ERROR_INVALID_PARAMETER ); |
| 1259 | return FALSE; |
| 1260 | } |
| 1261 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 1262 | unix_handle = FILE_GetUnixHandle( hFile, GENERIC_WRITE ); |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1263 | if (unix_handle == -1) return FALSE; |
| 1264 | while ((result = write( unix_handle, buffer, bytesToWrite )) == -1) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1265 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1266 | if ((errno == EAGAIN) || (errno == EINTR)) continue; |
Gerard Patel | f69c150 | 2000-05-07 18:26:19 +0000 | [diff] [blame] | 1267 | if ((errno == EFAULT) && !VIRTUAL_HandleFault( buffer )) continue; |
Gerard Patel | 8f3c0a3 | 1999-06-27 15:26:37 +0000 | [diff] [blame] | 1268 | if (errno == ENOSPC) |
| 1269 | SetLastError( ERROR_DISK_FULL ); |
| 1270 | else |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1271 | FILE_SetDosError(); |
| 1272 | break; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1273 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1274 | close( unix_handle ); |
| 1275 | if (result == -1) return FALSE; |
| 1276 | if (bytesWritten) *bytesWritten = result; |
| 1277 | return TRUE; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | |
| 1281 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1282 | * WIN16_hread |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1283 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1284 | LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1285 | { |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1286 | LONG maxlen; |
| 1287 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1288 | TRACE("%d %08lx %ld\n", |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1289 | hFile, (DWORD)buffer, count ); |
| 1290 | |
| 1291 | /* Some programs pass a count larger than the allocated buffer */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1292 | maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1293 | if (count > maxlen) count = maxlen; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1294 | return _lread(FILE_GetHandle(hFile), PTR_SEG_TO_LIN(buffer), count ); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | /*********************************************************************** |
| 1299 | * WIN16_lread |
| 1300 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1301 | UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1302 | { |
| 1303 | return (UINT16)WIN16_hread( hFile, buffer, (LONG)count ); |
| 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1308 | * _lread (KERNEL32.596) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1309 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1310 | UINT WINAPI _lread( HFILE handle, LPVOID buffer, UINT count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1311 | { |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1312 | DWORD result; |
| 1313 | if (!ReadFile( handle, buffer, count, &result, NULL )) return -1; |
| 1314 | return result; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | /*********************************************************************** |
| 1319 | * _lread16 (KERNEL.82) |
| 1320 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1321 | UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1322 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1323 | return (UINT16)_lread(FILE_GetHandle(hFile), buffer, (LONG)count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | |
| 1327 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1328 | * _lcreat16 (KERNEL.83) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1329 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1330 | HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1331 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1332 | return FILE_AllocDosHandle( _lcreat( path, attr ) ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | /*********************************************************************** |
Alexandre Julliard | d5240f1 | 1999-04-03 13:54:51 +0000 | [diff] [blame] | 1337 | * _lcreat (KERNEL32.593) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1338 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1339 | HFILE WINAPI _lcreat( LPCSTR path, INT attr ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1340 | { |
Alexandre Julliard | d5240f1 | 1999-04-03 13:54:51 +0000 | [diff] [blame] | 1341 | /* Mask off all flags not explicitly allowed by the doc */ |
| 1342 | attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1343 | TRACE("%s %02x\n", path, attr ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1344 | return CreateFileA( path, GENERIC_READ | GENERIC_WRITE, |
Alexandre Julliard | d5240f1 | 1999-04-03 13:54:51 +0000 | [diff] [blame] | 1345 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
| 1346 | CREATE_ALWAYS, attr, -1 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | /*********************************************************************** |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1351 | * SetFilePointer (KERNEL32.492) |
| 1352 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1353 | DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1354 | DWORD method ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1355 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1356 | DWORD ret = 0xffffffff; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1357 | |
Hidenori Takeshima | 66791af | 2000-07-31 23:26:50 +0000 | [diff] [blame] | 1358 | if (highword && |
| 1359 | ((distance >= 0 && *highword != 0) || (distance < 0 && *highword != -1))) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1360 | { |
Hidenori Takeshima | 66791af | 2000-07-31 23:26:50 +0000 | [diff] [blame] | 1361 | FIXME("64-bit offsets not supported yet\n" |
| 1362 | "SetFilePointer(%08x,%08lx,%08lx,%08lx)\n", |
| 1363 | hFile,distance,*highword,method); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1364 | SetLastError( ERROR_INVALID_PARAMETER ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1365 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1366 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1367 | TRACE("handle %d offset %ld origin %ld\n", |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1368 | hFile, distance, method ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1369 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1370 | SERVER_START_REQ |
| 1371 | { |
| 1372 | struct set_file_pointer_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 1373 | req->handle = hFile; |
| 1374 | req->low = distance; |
| 1375 | req->high = highword ? *highword : (distance >= 0) ? 0 : -1; |
| 1376 | /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */ |
| 1377 | req->whence = method; |
| 1378 | SetLastError( 0 ); |
| 1379 | if (!server_call( REQ_SET_FILE_POINTER )) |
| 1380 | { |
| 1381 | ret = req->new_low; |
| 1382 | if (highword) *highword = req->new_high; |
| 1383 | } |
| 1384 | } |
| 1385 | SERVER_END_REQ; |
| 1386 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1391 | * _llseek16 (KERNEL.84) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1392 | * |
| 1393 | * FIXME: |
| 1394 | * Seeking before the start of the file should be allowed for _llseek16, |
| 1395 | * but cause subsequent I/O operations to fail (cf. interrupt list) |
| 1396 | * |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1397 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1398 | LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1399 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1400 | return SetFilePointer( FILE_GetHandle(hFile), lOffset, NULL, nOrigin ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1405 | * _llseek (KERNEL32.594) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1406 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1407 | LONG WINAPI _llseek( HFILE hFile, LONG lOffset, INT nOrigin ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1408 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1409 | return SetFilePointer( hFile, lOffset, NULL, nOrigin ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | |
| 1413 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1414 | * _lopen16 (KERNEL.85) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1415 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1416 | HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1417 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1418 | return FILE_AllocDosHandle( _lopen( path, mode ) ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1423 | * _lopen (KERNEL32.595) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1424 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1425 | HFILE WINAPI _lopen( LPCSTR path, INT mode ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1426 | { |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1427 | DWORD access, sharing; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1428 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1429 | TRACE("('%s',%04x)\n", path, mode ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1430 | FILE_ConvertOFMode( mode, &access, &sharing ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1431 | return CreateFileA( path, access, sharing, NULL, OPEN_EXISTING, 0, -1 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1436 | * _lwrite16 (KERNEL.86) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1437 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1438 | UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1439 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1440 | return (UINT16)_hwrite( FILE_GetHandle(hFile), buffer, (LONG)count ); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1444 | * _lwrite (KERNEL32.761) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1445 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1446 | UINT WINAPI _lwrite( HFILE hFile, LPCSTR buffer, UINT count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1447 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1448 | return (UINT)_hwrite( hFile, buffer, (LONG)count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1453 | * _hread16 (KERNEL.349) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1454 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1455 | LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1456 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1457 | return _lread( FILE_GetHandle(hFile), buffer, count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | |
| 1461 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1462 | * _hread (KERNEL32.590) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1463 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1464 | LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1465 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1466 | return _lread( hFile, buffer, count ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | /*********************************************************************** |
| 1471 | * _hwrite16 (KERNEL.350) |
| 1472 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1473 | LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1474 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1475 | return _hwrite( FILE_GetHandle(hFile), buffer, count ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1480 | * _hwrite (KERNEL32.591) |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 1481 | * |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1482 | * experimentation yields that _lwrite: |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 1483 | * o truncates the file at the current position with |
| 1484 | * a 0 len write |
| 1485 | * o returns 0 on a 0 length write |
| 1486 | * o works with console handles |
| 1487 | * |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1488 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1489 | LONG WINAPI _hwrite( HFILE handle, LPCSTR buffer, LONG count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1490 | { |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1491 | DWORD result; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1492 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1493 | TRACE("%d %p %ld\n", handle, buffer, count ); |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1494 | |
| 1495 | if (!count) |
| 1496 | { |
| 1497 | /* Expand or truncate at current position */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1498 | if (!SetEndOfFile( handle )) return HFILE_ERROR; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |
| 1501 | if (!WriteFile( handle, buffer, count, &result, NULL )) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1502 | return HFILE_ERROR; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1503 | return result; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | |
| 1507 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1508 | * SetHandleCount16 (KERNEL.199) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1509 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1510 | UINT16 WINAPI SetHandleCount16( UINT16 count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1511 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1512 | HGLOBAL16 hPDB = GetCurrentPDB16(); |
| 1513 | PDB16 *pdb = (PDB16 *)GlobalLock16( hPDB ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1514 | BYTE *files = PTR_SEG_TO_LIN( pdb->fileHandlesPtr ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1515 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1516 | TRACE("(%d)\n", count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1517 | |
| 1518 | if (count < 20) count = 20; /* No point in going below 20 */ |
| 1519 | else if (count > 254) count = 254; |
| 1520 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1521 | if (count == 20) |
| 1522 | { |
| 1523 | if (pdb->nbFiles > 20) |
| 1524 | { |
| 1525 | memcpy( pdb->fileHandles, files, 20 ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1526 | GlobalFree16( pdb->hFileHandles ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1527 | pdb->fileHandlesPtr = (SEGPTR)MAKELONG( 0x18, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1528 | GlobalHandleToSel16( hPDB ) ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1529 | pdb->hFileHandles = 0; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1530 | pdb->nbFiles = 20; |
| 1531 | } |
| 1532 | } |
| 1533 | else /* More than 20, need a new file handles table */ |
| 1534 | { |
| 1535 | BYTE *newfiles; |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 1536 | HGLOBAL16 newhandle = GlobalAlloc16( GMEM_MOVEABLE, count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1537 | if (!newhandle) |
| 1538 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1539 | SetLastError( ERROR_NOT_ENOUGH_MEMORY ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1540 | return pdb->nbFiles; |
| 1541 | } |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1542 | newfiles = (BYTE *)GlobalLock16( newhandle ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1543 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1544 | if (count > pdb->nbFiles) |
| 1545 | { |
| 1546 | memcpy( newfiles, files, pdb->nbFiles ); |
| 1547 | memset( newfiles + pdb->nbFiles, 0xff, count - pdb->nbFiles ); |
| 1548 | } |
| 1549 | else memcpy( newfiles, files, count ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1550 | if (pdb->nbFiles > 20) GlobalFree16( pdb->hFileHandles ); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1551 | pdb->fileHandlesPtr = WIN16_GlobalLock16( newhandle ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1552 | pdb->hFileHandles = newhandle; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1553 | pdb->nbFiles = count; |
| 1554 | } |
| 1555 | return pdb->nbFiles; |
| 1556 | } |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1557 | |
| 1558 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1559 | /************************************************************************* |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1560 | * SetHandleCount (KERNEL32.494) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1561 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1562 | UINT WINAPI SetHandleCount( UINT count ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1563 | { |
Francois Gouget | 6d77d3a | 2000-03-25 21:44:35 +0000 | [diff] [blame] | 1564 | return min( 256, count ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1568 | /*********************************************************************** |
| 1569 | * FlushFileBuffers (KERNEL32.133) |
| 1570 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1571 | BOOL WINAPI FlushFileBuffers( HANDLE hFile ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1572 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1573 | BOOL ret; |
| 1574 | SERVER_START_REQ |
| 1575 | { |
| 1576 | struct flush_file_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 1577 | req->handle = hFile; |
| 1578 | ret = !server_call( REQ_FLUSH_FILE ); |
| 1579 | } |
| 1580 | SERVER_END_REQ; |
| 1581 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | /************************************************************************** |
| 1586 | * SetEndOfFile (KERNEL32.483) |
| 1587 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1588 | BOOL WINAPI SetEndOfFile( HANDLE hFile ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1589 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1590 | BOOL ret; |
| 1591 | SERVER_START_REQ |
| 1592 | { |
| 1593 | struct truncate_file_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 1594 | req->handle = hFile; |
| 1595 | ret = !server_call( REQ_TRUNCATE_FILE ); |
| 1596 | } |
| 1597 | SERVER_END_REQ; |
| 1598 | return ret; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | |
| 1602 | /*********************************************************************** |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1603 | * DeleteFile16 (KERNEL.146) |
| 1604 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1605 | BOOL16 WINAPI DeleteFile16( LPCSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1606 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1607 | return DeleteFileA( path ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | |
| 1611 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1612 | * DeleteFileA (KERNEL32.71) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1613 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1614 | BOOL WINAPI DeleteFileA( LPCSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1615 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1616 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1617 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1618 | TRACE("'%s'\n", path ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1619 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1620 | if (!*path) |
| 1621 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1622 | ERR("Empty path passed\n"); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1623 | return FALSE; |
| 1624 | } |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 1625 | if (DOSFS_GetDevice( path )) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1626 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1627 | WARN("cannot remove DOS device '%s'!\n", path); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1628 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1629 | return FALSE; |
| 1630 | } |
| 1631 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1632 | if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE; |
| 1633 | if (unlink( full_name.long_name ) == -1) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1634 | { |
| 1635 | FILE_SetDosError(); |
| 1636 | return FALSE; |
| 1637 | } |
| 1638 | return TRUE; |
| 1639 | } |
| 1640 | |
| 1641 | |
| 1642 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1643 | * DeleteFileW (KERNEL32.72) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1644 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1645 | BOOL WINAPI DeleteFileW( LPCWSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1646 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1647 | LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1648 | BOOL ret = DeleteFileA( xpath ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1649 | HeapFree( GetProcessHeap(), 0, xpath ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1650 | return ret; |
| 1651 | } |
| 1652 | |
| 1653 | |
| 1654 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1655 | * GetFileType (KERNEL32.222) |
| 1656 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1657 | DWORD WINAPI GetFileType( HANDLE hFile ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1658 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1659 | DWORD ret = FILE_TYPE_UNKNOWN; |
| 1660 | SERVER_START_REQ |
| 1661 | { |
| 1662 | struct get_file_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 1663 | req->handle = hFile; |
| 1664 | if (!server_call( REQ_GET_FILE_INFO )) ret = req->type; |
| 1665 | } |
| 1666 | SERVER_END_REQ; |
| 1667 | return ret; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1668 | } |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1669 | |
| 1670 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1671 | /************************************************************************** |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 1672 | * MoveFileExA (KERNEL32.???) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1673 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1674 | BOOL WINAPI MoveFileExA( LPCSTR fn1, LPCSTR fn2, DWORD flag ) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1675 | { |
| 1676 | DOS_FULL_NAME full_name1, full_name2; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1677 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1678 | TRACE("(%s,%s,%04lx)\n", fn1, fn2, flag); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1679 | |
| 1680 | if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE; |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 1681 | |
| 1682 | if (fn2) /* !fn2 means delete fn1 */ |
| 1683 | { |
| 1684 | if (DOSFS_GetFullName( fn2, TRUE, &full_name2 )) |
| 1685 | { |
| 1686 | /* target exists, check if we may overwrite */ |
| 1687 | if (!(flag & MOVEFILE_REPLACE_EXISTING)) |
| 1688 | { |
| 1689 | /* FIXME: Use right error code */ |
| 1690 | SetLastError( ERROR_ACCESS_DENIED ); |
| 1691 | return FALSE; |
| 1692 | } |
| 1693 | } |
| 1694 | else if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE; |
| 1695 | |
| 1696 | /* Source name and target path are valid */ |
| 1697 | |
| 1698 | if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) |
| 1699 | { |
| 1700 | /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706) |
| 1701 | Perhaps we should queue these command and execute it |
| 1702 | when exiting... What about using on_exit(2) |
| 1703 | */ |
| 1704 | FIXME("Please move existing file '%s' to file '%s' when Wine has finished\n", |
| 1705 | full_name1.long_name, full_name2.long_name); |
| 1706 | return TRUE; |
| 1707 | } |
| 1708 | |
| 1709 | if (full_name1.drive != full_name2.drive) |
| 1710 | { |
| 1711 | /* use copy, if allowed */ |
| 1712 | if (!(flag & MOVEFILE_COPY_ALLOWED)) |
| 1713 | { |
| 1714 | /* FIXME: Use right error code */ |
| 1715 | SetLastError( ERROR_FILE_EXISTS ); |
| 1716 | return FALSE; |
| 1717 | } |
| 1718 | return CopyFileA( fn1, fn2, !(flag & MOVEFILE_REPLACE_EXISTING) ); |
| 1719 | } |
| 1720 | if (rename( full_name1.long_name, full_name2.long_name ) == -1) |
| 1721 | { |
| 1722 | FILE_SetDosError(); |
| 1723 | return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1724 | } |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 1725 | return TRUE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1726 | } |
| 1727 | else /* fn2 == NULL means delete source */ |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 1728 | { |
| 1729 | if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) |
| 1730 | { |
| 1731 | if (flag & MOVEFILE_COPY_ALLOWED) { |
| 1732 | WARN("Illegal flag\n"); |
| 1733 | SetLastError( ERROR_GEN_FAILURE ); |
| 1734 | return FALSE; |
| 1735 | } |
| 1736 | /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706) |
| 1737 | Perhaps we should queue these command and execute it |
| 1738 | when exiting... What about using on_exit(2) |
| 1739 | */ |
| 1740 | FIXME("Please delete file '%s' when Wine has finished\n", |
| 1741 | full_name1.long_name); |
| 1742 | return TRUE; |
| 1743 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1744 | |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 1745 | if (unlink( full_name1.long_name ) == -1) |
| 1746 | { |
| 1747 | FILE_SetDosError(); |
| 1748 | return FALSE; |
| 1749 | } |
| 1750 | return TRUE; /* successfully deleted */ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1751 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1755 | * MoveFileExW (KERNEL32.???) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1756 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1757 | BOOL WINAPI MoveFileExW( LPCWSTR fn1, LPCWSTR fn2, DWORD flag ) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1758 | { |
| 1759 | LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 ); |
| 1760 | LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1761 | BOOL res = MoveFileExA( afn1, afn2, flag ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1762 | HeapFree( GetProcessHeap(), 0, afn1 ); |
| 1763 | HeapFree( GetProcessHeap(), 0, afn2 ); |
| 1764 | return res; |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1769 | * MoveFileA (KERNEL32.387) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1770 | * |
| 1771 | * Move file or directory |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1772 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1773 | BOOL WINAPI MoveFileA( LPCSTR fn1, LPCSTR fn2 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1774 | { |
| 1775 | DOS_FULL_NAME full_name1, full_name2; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1776 | struct stat fstat; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1777 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1778 | TRACE("(%s,%s)\n", fn1, fn2 ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1779 | |
| 1780 | if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE; |
Marcus Meissner | 242d23e | 2000-08-21 03:18:32 +0000 | [diff] [blame] | 1781 | if (DOSFS_GetFullName( fn2, TRUE, &full_name2 )) { |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1782 | /* The new name must not already exist */ |
Marcus Meissner | 242d23e | 2000-08-21 03:18:32 +0000 | [diff] [blame] | 1783 | SetLastError(ERROR_ALREADY_EXISTS); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1784 | return FALSE; |
Marcus Meissner | 242d23e | 2000-08-21 03:18:32 +0000 | [diff] [blame] | 1785 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1786 | if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1787 | |
| 1788 | if (full_name1.drive == full_name2.drive) /* move */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1789 | if (rename( full_name1.long_name, full_name2.long_name ) == -1) |
| 1790 | { |
| 1791 | FILE_SetDosError(); |
| 1792 | return FALSE; |
| 1793 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1794 | else return TRUE; |
| 1795 | else /*copy */ { |
| 1796 | if (stat( full_name1.long_name, &fstat )) |
| 1797 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1798 | WARN("Invalid source file %s\n", |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1799 | full_name1.long_name); |
| 1800 | FILE_SetDosError(); |
| 1801 | return FALSE; |
| 1802 | } |
| 1803 | if (S_ISDIR(fstat.st_mode)) { |
| 1804 | /* No Move for directories across file systems */ |
| 1805 | /* FIXME: Use right error code */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1806 | SetLastError( ERROR_GEN_FAILURE ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1807 | return FALSE; |
| 1808 | } |
| 1809 | else |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1810 | return CopyFileA(fn1, fn2, TRUE); /*fail, if exist */ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1811 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1816 | * MoveFileW (KERNEL32.390) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1817 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1818 | BOOL WINAPI MoveFileW( LPCWSTR fn1, LPCWSTR fn2 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1819 | { |
| 1820 | LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 ); |
| 1821 | LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1822 | BOOL res = MoveFileA( afn1, afn2 ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1823 | HeapFree( GetProcessHeap(), 0, afn1 ); |
| 1824 | HeapFree( GetProcessHeap(), 0, afn2 ); |
| 1825 | return res; |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1830 | * CopyFileA (KERNEL32.36) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1831 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1832 | BOOL WINAPI CopyFileA( LPCSTR source, LPCSTR dest, BOOL fail_if_exists ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1833 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1834 | HFILE h1, h2; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1835 | BY_HANDLE_FILE_INFORMATION info; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1836 | UINT count; |
| 1837 | BOOL ret = FALSE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1838 | int mode; |
| 1839 | char buffer[2048]; |
| 1840 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1841 | if ((h1 = _lopen( source, OF_READ )) == HFILE_ERROR) return FALSE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1842 | if (!GetFileInformationByHandle( h1, &info )) |
| 1843 | { |
| 1844 | CloseHandle( h1 ); |
| 1845 | return FALSE; |
| 1846 | } |
| 1847 | mode = (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1848 | if ((h2 = CreateFileA( dest, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1849 | fail_if_exists ? CREATE_NEW : CREATE_ALWAYS, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1850 | info.dwFileAttributes, h1 )) == HFILE_ERROR) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1851 | { |
| 1852 | CloseHandle( h1 ); |
| 1853 | return FALSE; |
| 1854 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1855 | while ((count = _lread( h1, buffer, sizeof(buffer) )) > 0) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1856 | { |
| 1857 | char *p = buffer; |
| 1858 | while (count > 0) |
| 1859 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1860 | INT res = _lwrite( h2, p, count ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1861 | if (res <= 0) goto done; |
| 1862 | p += res; |
| 1863 | count -= res; |
| 1864 | } |
| 1865 | } |
| 1866 | ret = TRUE; |
| 1867 | done: |
| 1868 | CloseHandle( h1 ); |
| 1869 | CloseHandle( h2 ); |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1875 | * CopyFileW (KERNEL32.37) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1876 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1877 | BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1878 | { |
| 1879 | LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, source ); |
| 1880 | LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, dest ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1881 | BOOL ret = CopyFileA( sourceA, destA, fail_if_exists ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1882 | HeapFree( GetProcessHeap(), 0, sourceA ); |
| 1883 | HeapFree( GetProcessHeap(), 0, destA ); |
| 1884 | return ret; |
| 1885 | } |
| 1886 | |
| 1887 | |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1888 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1889 | * CopyFileExA (KERNEL32.858) |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1890 | * |
| 1891 | * This implementation ignores most of the extra parameters passed-in into |
| 1892 | * the "ex" version of the method and calls the CopyFile method. |
| 1893 | * It will have to be fixed eventually. |
| 1894 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1895 | BOOL WINAPI CopyFileExA(LPCSTR sourceFilename, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1896 | LPCSTR destFilename, |
| 1897 | LPPROGRESS_ROUTINE progressRoutine, |
| 1898 | LPVOID appData, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1899 | LPBOOL cancelFlagPointer, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1900 | DWORD copyFlags) |
| 1901 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1902 | BOOL failIfExists = FALSE; |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1903 | |
| 1904 | /* |
| 1905 | * Interpret the only flag that CopyFile can interpret. |
| 1906 | */ |
| 1907 | if ( (copyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0) |
| 1908 | { |
| 1909 | failIfExists = TRUE; |
| 1910 | } |
| 1911 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1912 | return CopyFileA(sourceFilename, destFilename, failIfExists); |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1916 | * CopyFileExW (KERNEL32.859) |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1917 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1918 | BOOL WINAPI CopyFileExW(LPCWSTR sourceFilename, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1919 | LPCWSTR destFilename, |
| 1920 | LPPROGRESS_ROUTINE progressRoutine, |
| 1921 | LPVOID appData, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1922 | LPBOOL cancelFlagPointer, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1923 | DWORD copyFlags) |
| 1924 | { |
| 1925 | LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, sourceFilename ); |
| 1926 | LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, destFilename ); |
| 1927 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1928 | BOOL ret = CopyFileExA(sourceA, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 1929 | destA, |
| 1930 | progressRoutine, |
| 1931 | appData, |
| 1932 | cancelFlagPointer, |
| 1933 | copyFlags); |
| 1934 | |
| 1935 | HeapFree( GetProcessHeap(), 0, sourceA ); |
| 1936 | HeapFree( GetProcessHeap(), 0, destA ); |
| 1937 | |
| 1938 | return ret; |
| 1939 | } |
| 1940 | |
| 1941 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1942 | /*********************************************************************** |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1943 | * SetFileTime (KERNEL32.650) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1944 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1945 | BOOL WINAPI SetFileTime( HANDLE hFile, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1946 | const FILETIME *lpCreationTime, |
| 1947 | const FILETIME *lpLastAccessTime, |
| 1948 | const FILETIME *lpLastWriteTime ) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1949 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1950 | BOOL ret; |
| 1951 | SERVER_START_REQ |
| 1952 | { |
| 1953 | struct set_file_time_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 1954 | req->handle = hFile; |
| 1955 | if (lpLastAccessTime) |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 1956 | RtlTimeToSecondsSince1970( lpLastAccessTime, (DWORD *)&req->access_time ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1957 | else |
| 1958 | req->access_time = 0; /* FIXME */ |
| 1959 | if (lpLastWriteTime) |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 1960 | RtlTimeToSecondsSince1970( lpLastWriteTime, (DWORD *)&req->write_time ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1961 | else |
| 1962 | req->write_time = 0; /* FIXME */ |
| 1963 | ret = !server_call( REQ_SET_FILE_TIME ); |
| 1964 | } |
| 1965 | SERVER_END_REQ; |
| 1966 | return ret; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1967 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1968 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1969 | |
| 1970 | /************************************************************************** |
| 1971 | * LockFile (KERNEL32.511) |
| 1972 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1973 | BOOL WINAPI LockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1974 | DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh ) |
| 1975 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1976 | BOOL ret; |
| 1977 | SERVER_START_REQ |
| 1978 | { |
| 1979 | struct lock_file_request *req = server_alloc_req( sizeof(*req), 0 ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1980 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1981 | req->handle = hFile; |
| 1982 | req->offset_low = dwFileOffsetLow; |
| 1983 | req->offset_high = dwFileOffsetHigh; |
| 1984 | req->count_low = nNumberOfBytesToLockLow; |
| 1985 | req->count_high = nNumberOfBytesToLockHigh; |
| 1986 | ret = !server_call( REQ_LOCK_FILE ); |
| 1987 | } |
| 1988 | SERVER_END_REQ; |
| 1989 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 1992 | /************************************************************************** |
| 1993 | * LockFileEx [KERNEL32.512] |
| 1994 | * |
| 1995 | * Locks a byte range within an open file for shared or exclusive access. |
| 1996 | * |
| 1997 | * RETURNS |
| 1998 | * success: TRUE |
| 1999 | * failure: FALSE |
| 2000 | * NOTES |
| 2001 | * |
| 2002 | * Per Microsoft docs, the third parameter (reserved) must be set to 0. |
| 2003 | */ |
| 2004 | BOOL WINAPI LockFileEx( HANDLE hFile, DWORD flags, DWORD reserved, |
| 2005 | DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, |
| 2006 | LPOVERLAPPED pOverlapped ) |
| 2007 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2008 | FIXME("hFile=%d,flags=%ld,reserved=%ld,lowbytes=%ld,highbytes=%ld,overlapped=%p: stub.\n", |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2009 | hFile, flags, reserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, |
| 2010 | pOverlapped); |
| 2011 | if (reserved == 0) |
| 2012 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 2013 | else |
| 2014 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2015 | ERR("reserved == %ld: Supposed to be 0??\n", reserved); |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2016 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2017 | } |
| 2018 | |
| 2019 | return FALSE; |
| 2020 | } |
| 2021 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2022 | |
| 2023 | /************************************************************************** |
| 2024 | * UnlockFile (KERNEL32.703) |
| 2025 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2026 | BOOL WINAPI UnlockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2027 | DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh ) |
| 2028 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2029 | BOOL ret; |
| 2030 | SERVER_START_REQ |
| 2031 | { |
| 2032 | struct unlock_file_request *req = server_alloc_req( sizeof(*req), 0 ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2033 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2034 | req->handle = hFile; |
| 2035 | req->offset_low = dwFileOffsetLow; |
| 2036 | req->offset_high = dwFileOffsetHigh; |
| 2037 | req->count_low = nNumberOfBytesToUnlockLow; |
| 2038 | req->count_high = nNumberOfBytesToUnlockHigh; |
| 2039 | ret = !server_call( REQ_UNLOCK_FILE ); |
| 2040 | } |
| 2041 | SERVER_END_REQ; |
| 2042 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | |
Andreas Mohr | e00114c | 1999-07-03 11:56:07 +0000 | [diff] [blame] | 2046 | /************************************************************************** |
| 2047 | * UnlockFileEx (KERNEL32.705) |
| 2048 | */ |
| 2049 | BOOL WINAPI UnlockFileEx( |
| 2050 | HFILE hFile, |
| 2051 | DWORD dwReserved, |
| 2052 | DWORD nNumberOfBytesToUnlockLow, |
| 2053 | DWORD nNumberOfBytesToUnlockHigh, |
| 2054 | LPOVERLAPPED lpOverlapped |
| 2055 | ) |
| 2056 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2057 | FIXME("hFile=%d,reserved=%ld,lowbytes=%ld,highbytes=%ld,overlapped=%p: stub.\n", |
Andreas Mohr | e00114c | 1999-07-03 11:56:07 +0000 | [diff] [blame] | 2058 | hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, |
| 2059 | lpOverlapped); |
| 2060 | if (dwReserved == 0) |
| 2061 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 2062 | else |
| 2063 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2064 | ERR("reserved == %ld: Supposed to be 0??\n", dwReserved); |
Andreas Mohr | e00114c | 1999-07-03 11:56:07 +0000 | [diff] [blame] | 2065 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2066 | } |
| 2067 | |
| 2068 | return FALSE; |
| 2069 | } |
| 2070 | |
| 2071 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2072 | #if 0 |
| 2073 | |
| 2074 | struct DOS_FILE_LOCK { |
| 2075 | struct DOS_FILE_LOCK * next; |
| 2076 | DWORD base; |
| 2077 | DWORD len; |
| 2078 | DWORD processId; |
| 2079 | FILE_OBJECT * dos_file; |
| 2080 | /* char * unix_name;*/ |
| 2081 | }; |
| 2082 | |
| 2083 | typedef struct DOS_FILE_LOCK DOS_FILE_LOCK; |
| 2084 | |
| 2085 | static DOS_FILE_LOCK *locks = NULL; |
| 2086 | static void DOS_RemoveFileLocks(FILE_OBJECT *file); |
| 2087 | |
| 2088 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2089 | /* Locks need to be mirrored because unix file locking is based |
| 2090 | * on the pid. Inside of wine there can be multiple WINE processes |
| 2091 | * that share the same unix pid. |
| 2092 | * Read's and writes should check these locks also - not sure |
| 2093 | * how critical that is at this point (FIXME). |
| 2094 | */ |
| 2095 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2096 | static BOOL DOS_AddLock(FILE_OBJECT *file, struct flock *f) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2097 | { |
| 2098 | DOS_FILE_LOCK *curr; |
| 2099 | DWORD processId; |
| 2100 | |
| 2101 | processId = GetCurrentProcessId(); |
| 2102 | |
| 2103 | /* check if lock overlaps a current lock for the same file */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2104 | #if 0 |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2105 | for (curr = locks; curr; curr = curr->next) { |
| 2106 | if (strcmp(curr->unix_name, file->unix_name) == 0) { |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 2107 | if ((f->l_start == curr->base) && (f->l_len == curr->len)) |
| 2108 | return TRUE;/* region is identic */ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2109 | if ((f->l_start < (curr->base + curr->len)) && |
| 2110 | ((f->l_start + f->l_len) > curr->base)) { |
| 2111 | /* region overlaps */ |
| 2112 | return FALSE; |
| 2113 | } |
| 2114 | } |
| 2115 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2116 | #endif |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2117 | |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2118 | curr = HeapAlloc( GetProcessHeap(), 0, sizeof(DOS_FILE_LOCK) ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2119 | curr->processId = GetCurrentProcessId(); |
| 2120 | curr->base = f->l_start; |
| 2121 | curr->len = f->l_len; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2122 | /* curr->unix_name = HEAP_strdupA( GetProcessHeap(), 0, file->unix_name);*/ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2123 | curr->next = locks; |
| 2124 | curr->dos_file = file; |
| 2125 | locks = curr; |
| 2126 | return TRUE; |
| 2127 | } |
| 2128 | |
| 2129 | static void DOS_RemoveFileLocks(FILE_OBJECT *file) |
| 2130 | { |
| 2131 | DWORD processId; |
| 2132 | DOS_FILE_LOCK **curr; |
| 2133 | DOS_FILE_LOCK *rem; |
| 2134 | |
| 2135 | processId = GetCurrentProcessId(); |
| 2136 | curr = &locks; |
| 2137 | while (*curr) { |
| 2138 | if ((*curr)->dos_file == file) { |
| 2139 | rem = *curr; |
| 2140 | *curr = (*curr)->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2141 | /* HeapFree( GetProcessHeap(), 0, rem->unix_name );*/ |
| 2142 | HeapFree( GetProcessHeap(), 0, rem ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2143 | } |
| 2144 | else |
| 2145 | curr = &(*curr)->next; |
| 2146 | } |
| 2147 | } |
| 2148 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2149 | static BOOL DOS_RemoveLock(FILE_OBJECT *file, struct flock *f) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2150 | { |
| 2151 | DWORD processId; |
| 2152 | DOS_FILE_LOCK **curr; |
| 2153 | DOS_FILE_LOCK *rem; |
| 2154 | |
| 2155 | processId = GetCurrentProcessId(); |
| 2156 | for (curr = &locks; *curr; curr = &(*curr)->next) { |
| 2157 | if ((*curr)->processId == processId && |
| 2158 | (*curr)->dos_file == file && |
| 2159 | (*curr)->base == f->l_start && |
| 2160 | (*curr)->len == f->l_len) { |
| 2161 | /* this is the same lock */ |
| 2162 | rem = *curr; |
| 2163 | *curr = (*curr)->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2164 | /* HeapFree( GetProcessHeap(), 0, rem->unix_name );*/ |
| 2165 | HeapFree( GetProcessHeap(), 0, rem ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2166 | return TRUE; |
| 2167 | } |
| 2168 | } |
| 2169 | /* no matching lock found */ |
| 2170 | return FALSE; |
| 2171 | } |
| 2172 | |
| 2173 | |
| 2174 | /************************************************************************** |
| 2175 | * LockFile (KERNEL32.511) |
| 2176 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2177 | BOOL WINAPI LockFile( |
| 2178 | HFILE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh, |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2179 | DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh ) |
| 2180 | { |
| 2181 | struct flock f; |
| 2182 | FILE_OBJECT *file; |
| 2183 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2184 | TRACE("handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n", |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2185 | hFile, dwFileOffsetLow, dwFileOffsetHigh, |
| 2186 | nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh); |
| 2187 | |
| 2188 | if (dwFileOffsetHigh || nNumberOfBytesToLockHigh) { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2189 | FIXME("Unimplemented bytes > 32bits\n"); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2190 | return FALSE; |
| 2191 | } |
| 2192 | |
| 2193 | f.l_start = dwFileOffsetLow; |
| 2194 | f.l_len = nNumberOfBytesToLockLow; |
| 2195 | f.l_whence = SEEK_SET; |
| 2196 | f.l_pid = 0; |
| 2197 | f.l_type = F_WRLCK; |
| 2198 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 2199 | if (!(file = FILE_GetFile(hFile,0,NULL))) return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2200 | |
| 2201 | /* shadow locks internally */ |
| 2202 | if (!DOS_AddLock(file, &f)) { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 2203 | SetLastError( ERROR_LOCK_VIOLATION ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2204 | return FALSE; |
| 2205 | } |
| 2206 | |
| 2207 | /* FIXME: Unix locking commented out for now, doesn't work with Excel */ |
| 2208 | #ifdef USE_UNIX_LOCKS |
| 2209 | if (fcntl(file->unix_handle, F_SETLK, &f) == -1) { |
| 2210 | if (errno == EACCES || errno == EAGAIN) { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 2211 | SetLastError( ERROR_LOCK_VIOLATION ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2212 | } |
| 2213 | else { |
| 2214 | FILE_SetDosError(); |
| 2215 | } |
| 2216 | /* remove our internal copy of the lock */ |
| 2217 | DOS_RemoveLock(file, &f); |
| 2218 | return FALSE; |
| 2219 | } |
| 2220 | #endif |
| 2221 | return TRUE; |
| 2222 | } |
| 2223 | |
| 2224 | |
| 2225 | /************************************************************************** |
| 2226 | * UnlockFile (KERNEL32.703) |
| 2227 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2228 | BOOL WINAPI UnlockFile( |
| 2229 | HFILE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh, |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2230 | DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh ) |
| 2231 | { |
| 2232 | FILE_OBJECT *file; |
| 2233 | struct flock f; |
| 2234 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2235 | TRACE("handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n", |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2236 | hFile, dwFileOffsetLow, dwFileOffsetHigh, |
| 2237 | nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh); |
| 2238 | |
| 2239 | if (dwFileOffsetHigh || nNumberOfBytesToUnlockHigh) { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2240 | WARN("Unimplemented bytes > 32bits\n"); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2241 | return FALSE; |
| 2242 | } |
| 2243 | |
| 2244 | f.l_start = dwFileOffsetLow; |
| 2245 | f.l_len = nNumberOfBytesToUnlockLow; |
| 2246 | f.l_whence = SEEK_SET; |
| 2247 | f.l_pid = 0; |
| 2248 | f.l_type = F_UNLCK; |
| 2249 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 2250 | if (!(file = FILE_GetFile(hFile,0,NULL))) return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2251 | |
| 2252 | DOS_RemoveLock(file, &f); /* ok if fails - may be another wine */ |
| 2253 | |
| 2254 | /* FIXME: Unix locking commented out for now, doesn't work with Excel */ |
| 2255 | #ifdef USE_UNIX_LOCKS |
| 2256 | if (fcntl(file->unix_handle, F_SETLK, &f) == -1) { |
| 2257 | FILE_SetDosError(); |
| 2258 | return FALSE; |
| 2259 | } |
| 2260 | #endif |
| 2261 | return TRUE; |
| 2262 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2263 | #endif |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2264 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2265 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 2266 | * GetFileAttributesExA [KERNEL32.874] |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2267 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2268 | BOOL WINAPI GetFileAttributesExA( |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2269 | LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, |
| 2270 | LPVOID lpFileInformation) |
| 2271 | { |
| 2272 | DOS_FULL_NAME full_name; |
| 2273 | BY_HANDLE_FILE_INFORMATION info; |
| 2274 | |
| 2275 | if (lpFileName == NULL) return FALSE; |
| 2276 | if (lpFileInformation == NULL) return FALSE; |
| 2277 | |
| 2278 | if (fInfoLevelId == GetFileExInfoStandard) { |
| 2279 | LPWIN32_FILE_ATTRIBUTE_DATA lpFad = |
| 2280 | (LPWIN32_FILE_ATTRIBUTE_DATA) lpFileInformation; |
| 2281 | if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name )) return FALSE; |
| 2282 | if (!FILE_Stat( full_name.long_name, &info )) return FALSE; |
| 2283 | |
| 2284 | lpFad->dwFileAttributes = info.dwFileAttributes; |
| 2285 | lpFad->ftCreationTime = info.ftCreationTime; |
| 2286 | lpFad->ftLastAccessTime = info.ftLastAccessTime; |
| 2287 | lpFad->ftLastWriteTime = info.ftLastWriteTime; |
| 2288 | lpFad->nFileSizeHigh = info.nFileSizeHigh; |
| 2289 | lpFad->nFileSizeLow = info.nFileSizeLow; |
| 2290 | } |
| 2291 | else { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2292 | FIXME("invalid info level %d!\n", fInfoLevelId); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2293 | return FALSE; |
| 2294 | } |
| 2295 | |
| 2296 | return TRUE; |
| 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 2301 | * GetFileAttributesExW [KERNEL32.875] |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2302 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2303 | BOOL WINAPI GetFileAttributesExW( |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2304 | LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, |
| 2305 | LPVOID lpFileInformation) |
| 2306 | { |
| 2307 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2308 | BOOL res = |
| 2309 | GetFileAttributesExA( nameA, fInfoLevelId, lpFileInformation); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2310 | HeapFree( GetProcessHeap(), 0, nameA ); |
| 2311 | return res; |
| 2312 | } |