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 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 21 | * TODO: |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 22 | * Fix the CopyFileEx methods to implement the "extended" functionality. |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 23 | * Right now, they simply call the CopyFile method. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 26 | #include "config.h" |
Marcus Meissner | 3f1ed52 | 2001-05-14 20:09:37 +0000 | [diff] [blame] | 27 | #include "wine/port.h" |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 28 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 29 | #include <assert.h> |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 30 | #include <ctype.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 31 | #include <errno.h> |
| 32 | #include <fcntl.h> |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 33 | #include <stdlib.h> |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 34 | #include <stdio.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 35 | #include <string.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 36 | #ifdef HAVE_SYS_ERRNO_H |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 37 | #include <sys/errno.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 38 | #endif |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 39 | #include <sys/types.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 40 | #include <sys/stat.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 41 | #ifdef HAVE_SYS_MMAN_H |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 42 | #include <sys/mman.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 43 | #endif |
Marcus Meissner | 7d123bf | 1998-12-11 09:13:29 +0000 | [diff] [blame] | 44 | #include <sys/time.h> |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 45 | #include <sys/poll.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 46 | #include <time.h> |
| 47 | #include <unistd.h> |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 48 | #include <utime.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 49 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 50 | #include "winerror.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 51 | #include "windef.h" |
| 52 | #include "winbase.h" |
| 53 | #include "wine/winbase16.h" |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 54 | #include "wine/server.h" |
| 55 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 56 | #include "drive.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 57 | #include "file.h" |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 58 | #include "async.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 59 | #include "heap.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 60 | #include "msdos.h" |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 61 | #include "wincon.h" |
Mike McCormack | fc93261 | 2002-03-12 19:24:04 +0000 | [diff] [blame] | 62 | |
| 63 | #include "smb.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 64 | #include "wine/debug.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 65 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 66 | WINE_DEFAULT_DEBUG_CHANNEL(file); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 67 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 68 | #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) |
| 69 | #define MAP_ANON MAP_ANONYMOUS |
| 70 | #endif |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 71 | |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 72 | /* Size of per-process table of DOS handles */ |
| 73 | #define DOS_TABLE_SIZE 256 |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 74 | |
Martin Wilck | 718b1b7 | 2002-01-07 21:02:15 +0000 | [diff] [blame] | 75 | /* Macro to derive file offset from OVERLAPPED struct */ |
| 76 | #define OVERLAPPED_OFFSET(overlapped) ((off_t) (overlapped)->Offset + ((off_t) (overlapped)->OffsetHigh << 32)) |
| 77 | |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 78 | static HANDLE dos_handles[DOS_TABLE_SIZE]; |
| 79 | |
Francois Gouget | 34372dc | 2002-03-29 18:17:35 +0000 | [diff] [blame] | 80 | mode_t FILE_umask; |
| 81 | |
Stefan Leichter | f25efa0 | 2002-04-11 17:34:46 +0000 | [diff] [blame] | 82 | extern HANDLE WINAPI FILE_SmbOpen(LPCSTR name); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 83 | |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 84 | /*********************************************************************** |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 85 | * Asynchronous file I/O * |
| 86 | */ |
| 87 | static DWORD fileio_get_async_status (const async_private *ovp); |
| 88 | static DWORD fileio_get_async_count (const async_private *ovp); |
| 89 | static void fileio_set_async_status (async_private *ovp, const DWORD status); |
| 90 | static void CALLBACK fileio_call_completion_func (ULONG_PTR data); |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 91 | static void fileio_async_cleanup (async_private *ovp); |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 92 | |
| 93 | static async_ops fileio_async_ops = |
| 94 | { |
| 95 | fileio_get_async_status, /* get_status */ |
| 96 | fileio_set_async_status, /* set_status */ |
| 97 | fileio_get_async_count, /* get_count */ |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 98 | fileio_call_completion_func, /* call_completion */ |
| 99 | fileio_async_cleanup /* cleanup */ |
| 100 | }; |
| 101 | |
| 102 | static async_ops fileio_nocomp_async_ops = |
| 103 | { |
| 104 | fileio_get_async_status, /* get_status */ |
| 105 | fileio_set_async_status, /* set_status */ |
| 106 | fileio_get_async_count, /* get_count */ |
| 107 | NULL, /* call_completion */ |
| 108 | fileio_async_cleanup /* cleanup */ |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | typedef struct async_fileio |
| 112 | { |
| 113 | struct async_private async; |
| 114 | LPOVERLAPPED lpOverlapped; |
| 115 | LPOVERLAPPED_COMPLETION_ROUTINE completion_func; |
| 116 | char *buffer; |
| 117 | int count; |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 118 | enum fd_type fd_type; |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 119 | } async_fileio; |
| 120 | |
| 121 | static DWORD fileio_get_async_status (const struct async_private *ovp) |
| 122 | { |
| 123 | return ((async_fileio*) ovp)->lpOverlapped->Internal; |
| 124 | } |
| 125 | |
| 126 | static void fileio_set_async_status (async_private *ovp, const DWORD status) |
| 127 | { |
| 128 | ((async_fileio*) ovp)->lpOverlapped->Internal = status; |
| 129 | } |
| 130 | |
| 131 | static DWORD fileio_get_async_count (const struct async_private *ovp) |
| 132 | { |
| 133 | async_fileio *fileio = (async_fileio*) ovp; |
| 134 | DWORD ret = fileio->count - fileio->lpOverlapped->InternalHigh; |
| 135 | return (ret < 0 ? 0 : ret); |
| 136 | } |
| 137 | |
| 138 | static void CALLBACK fileio_call_completion_func (ULONG_PTR data) |
| 139 | { |
| 140 | async_fileio *ovp = (async_fileio*) data; |
| 141 | TRACE ("data: %p\n", ovp); |
| 142 | |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 143 | ovp->completion_func( ovp->lpOverlapped->Internal, |
| 144 | ovp->lpOverlapped->InternalHigh, |
| 145 | ovp->lpOverlapped ); |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 146 | |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 147 | fileio_async_cleanup ( &ovp->async ); |
| 148 | } |
| 149 | |
| 150 | static void fileio_async_cleanup ( struct async_private *ovp ) |
| 151 | { |
| 152 | HeapFree ( GetProcessHeap(), 0, ovp ); |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /*********************************************************************** |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 156 | * FILE_ConvertOFMode |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 157 | * |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 158 | * Convert OF_* mode into flags for CreateFile. |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 159 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 160 | static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing ) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 161 | { |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 162 | switch(mode & 0x03) |
| 163 | { |
| 164 | case OF_READ: *access = GENERIC_READ; break; |
| 165 | case OF_WRITE: *access = GENERIC_WRITE; break; |
| 166 | case OF_READWRITE: *access = GENERIC_READ | GENERIC_WRITE; break; |
| 167 | default: *access = 0; break; |
| 168 | } |
| 169 | switch(mode & 0x70) |
| 170 | { |
| 171 | case OF_SHARE_EXCLUSIVE: *sharing = 0; break; |
| 172 | case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break; |
| 173 | case OF_SHARE_DENY_READ: *sharing = FILE_SHARE_WRITE; break; |
| 174 | case OF_SHARE_DENY_NONE: |
| 175 | case OF_SHARE_COMPAT: |
| 176 | default: *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break; |
| 177 | } |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 180 | |
| 181 | /*********************************************************************** |
Aric Stewart | e4d0932 | 2000-12-03 03:14:29 +0000 | [diff] [blame] | 182 | * FILE_strcasecmp |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 183 | * |
Aric Stewart | e4d0932 | 2000-12-03 03:14:29 +0000 | [diff] [blame] | 184 | * locale-independent case conversion for file I/O |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 185 | */ |
Aric Stewart | e4d0932 | 2000-12-03 03:14:29 +0000 | [diff] [blame] | 186 | int FILE_strcasecmp( const char *str1, const char *str2 ) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 187 | { |
Aric Stewart | e4d0932 | 2000-12-03 03:14:29 +0000 | [diff] [blame] | 188 | for (;;) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 189 | { |
Aric Stewart | e4d0932 | 2000-12-03 03:14:29 +0000 | [diff] [blame] | 190 | int ret = FILE_toupper(*str1) - FILE_toupper(*str2); |
| 191 | if (ret || !*str1) return ret; |
| 192 | str1++; |
| 193 | str2++; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 194 | } |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 195 | } |
Aric Stewart | e4d0932 | 2000-12-03 03:14:29 +0000 | [diff] [blame] | 196 | |
| 197 | |
| 198 | /*********************************************************************** |
| 199 | * FILE_strncasecmp |
| 200 | * |
| 201 | * locale-independent case conversion for file I/O |
| 202 | */ |
| 203 | int FILE_strncasecmp( const char *str1, const char *str2, int len ) |
| 204 | { |
| 205 | int ret = 0; |
| 206 | for ( ; len > 0; len--, str1++, str2++) |
| 207 | if ((ret = FILE_toupper(*str1) - FILE_toupper(*str2)) || !*str1) break; |
| 208 | return ret; |
| 209 | } |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 210 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 211 | |
| 212 | /*********************************************************************** |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 213 | * FILE_GetNtStatus(void) |
| 214 | * |
| 215 | * Retrieve the Nt Status code from errno. |
| 216 | * Try to be consistent with FILE_SetDosError(). |
| 217 | */ |
| 218 | DWORD FILE_GetNtStatus(void) |
| 219 | { |
| 220 | int err = errno; |
| 221 | DWORD nt; |
| 222 | TRACE ( "errno = %d\n", errno ); |
| 223 | switch ( err ) |
| 224 | { |
| 225 | case EAGAIN: nt = STATUS_SHARING_VIOLATION; break; |
| 226 | case EBADF: nt = STATUS_INVALID_HANDLE; break; |
| 227 | case ENOSPC: nt = STATUS_DISK_FULL; break; |
| 228 | case EPERM: |
| 229 | case EROFS: |
| 230 | case EACCES: nt = STATUS_ACCESS_DENIED; break; |
| 231 | case ENOENT: nt = STATUS_SHARING_VIOLATION; break; |
| 232 | case EISDIR: nt = STATUS_FILE_IS_A_DIRECTORY; break; |
| 233 | case EMFILE: |
| 234 | case ENFILE: nt = STATUS_NO_MORE_FILES; break; |
| 235 | case EINVAL: |
| 236 | case ENOTEMPTY: nt = STATUS_DIRECTORY_NOT_EMPTY; break; |
| 237 | case EPIPE: nt = STATUS_PIPE_BROKEN; break; |
| 238 | case ENOEXEC: /* ?? */ |
| 239 | case ESPIPE: /* ?? */ |
| 240 | case EEXIST: /* ?? */ |
| 241 | default: |
| 242 | FIXME ( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err ); |
| 243 | nt = STATUS_UNSUCCESSFUL; |
| 244 | } |
| 245 | return nt; |
| 246 | } |
| 247 | |
| 248 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 249 | * FILE_SetDosError |
| 250 | * |
| 251 | * Set the DOS error code from errno. |
| 252 | */ |
| 253 | void FILE_SetDosError(void) |
| 254 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 255 | int save_errno = errno; /* errno gets overwritten by printf */ |
| 256 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 257 | TRACE("errno = %d %s\n", errno, strerror(errno)); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 258 | switch (save_errno) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 259 | { |
| 260 | case EAGAIN: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 261 | SetLastError( ERROR_SHARING_VIOLATION ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 262 | break; |
| 263 | case EBADF: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 264 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 265 | break; |
| 266 | case ENOSPC: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 267 | SetLastError( ERROR_HANDLE_DISK_FULL ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 268 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 269 | case EACCES: |
| 270 | case EPERM: |
| 271 | case EROFS: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 272 | SetLastError( ERROR_ACCESS_DENIED ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 273 | break; |
| 274 | case EBUSY: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 275 | SetLastError( ERROR_LOCK_VIOLATION ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 276 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 277 | case ENOENT: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 278 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 279 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 280 | case EISDIR: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 281 | SetLastError( ERROR_CANNOT_MAKE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 282 | break; |
| 283 | case ENFILE: |
| 284 | case EMFILE: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 285 | SetLastError( ERROR_NO_MORE_FILES ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 286 | break; |
| 287 | case EEXIST: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 288 | SetLastError( ERROR_FILE_EXISTS ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 289 | break; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 290 | case EINVAL: |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 291 | case ESPIPE: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 292 | SetLastError( ERROR_SEEK ); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 293 | break; |
| 294 | case ENOTEMPTY: |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 295 | SetLastError( ERROR_DIR_NOT_EMPTY ); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 296 | break; |
Alexandre Julliard | 045d81f | 2000-05-01 16:20:23 +0000 | [diff] [blame] | 297 | case ENOEXEC: |
| 298 | SetLastError( ERROR_BAD_FORMAT ); |
| 299 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 300 | default: |
Andreas Mohr | c9cf70d | 2001-01-26 20:40:50 +0000 | [diff] [blame] | 301 | WARN("unknown file error: %s\n", strerror(save_errno) ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 302 | SetLastError( ERROR_GEN_FAILURE ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 303 | break; |
| 304 | } |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 305 | errno = save_errno; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
| 309 | /*********************************************************************** |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 310 | * FILE_DupUnixHandle |
| 311 | * |
| 312 | * Duplicate a Unix handle into a task handle. |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 313 | * Returns 0 on failure. |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 314 | */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 315 | HANDLE FILE_DupUnixHandle( int fd, DWORD access, BOOL inherit ) |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 316 | { |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 317 | HANDLE ret; |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 318 | |
| 319 | wine_server_send_fd( fd ); |
| 320 | |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 321 | SERVER_START_REQ( alloc_file_handle ) |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 322 | { |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 323 | req->access = access; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 324 | req->inherit = inherit; |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 325 | req->fd = fd; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 326 | wine_server_call( req ); |
| 327 | ret = reply->handle; |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 328 | } |
| 329 | SERVER_END_REQ; |
| 330 | return ret; |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
| 334 | /*********************************************************************** |
Mike McCormack | ff58be5 | 2001-10-04 16:18:15 +0000 | [diff] [blame] | 335 | * FILE_GetUnixHandleType |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 336 | * |
| 337 | * Retrieve the Unix handle corresponding to a file handle. |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 338 | * Returns -1 on failure. |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 339 | */ |
Martin Wilck | af16c98 | 2002-04-25 21:34:24 +0000 | [diff] [blame] | 340 | static int FILE_GetUnixHandleType( HANDLE handle, DWORD access, enum fd_type *type, int *flags_ptr ) |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 341 | { |
Martin Wilck | af16c98 | 2002-04-25 21:34:24 +0000 | [diff] [blame] | 342 | int ret, flags, fd = -1; |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 343 | |
Martin Wilck | af16c98 | 2002-04-25 21:34:24 +0000 | [diff] [blame] | 344 | ret = wine_server_handle_to_fd( handle, access, &fd, type, &flags ); |
| 345 | if (flags_ptr) *flags_ptr = flags; |
Alexandre Julliard | 8d1550d | 2002-03-23 18:48:12 +0000 | [diff] [blame] | 346 | if (ret) SetLastError( RtlNtStatusToDosError(ret) ); |
Martin Wilck | af16c98 | 2002-04-25 21:34:24 +0000 | [diff] [blame] | 347 | else if (((access & GENERIC_READ) && (flags & FD_FLAG_RECV_SHUTDOWN)) || |
| 348 | ((access & GENERIC_WRITE) && (flags & FD_FLAG_SEND_SHUTDOWN))) |
| 349 | { |
| 350 | close (fd); |
| 351 | SetLastError ( ERROR_PIPE_NOT_CONNECTED ); |
| 352 | return -1; |
| 353 | } |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 354 | return fd; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Mike McCormack | ff58be5 | 2001-10-04 16:18:15 +0000 | [diff] [blame] | 357 | /*********************************************************************** |
| 358 | * FILE_GetUnixHandle |
| 359 | * |
| 360 | * Retrieve the Unix handle corresponding to a file handle. |
| 361 | * Returns -1 on failure. |
| 362 | */ |
| 363 | int FILE_GetUnixHandle( HANDLE handle, DWORD access ) |
| 364 | { |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 365 | return FILE_GetUnixHandleType( handle, access, NULL, NULL ); |
Mike McCormack | ff58be5 | 2001-10-04 16:18:15 +0000 | [diff] [blame] | 366 | } |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 367 | |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 368 | /************************************************************************* |
| 369 | * FILE_OpenConsole |
| 370 | * |
| 371 | * Open a handle to the current process console. |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 372 | * Returns 0 on failure. |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 373 | */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 374 | static HANDLE FILE_OpenConsole( BOOL output, DWORD access, DWORD sharing, LPSECURITY_ATTRIBUTES sa ) |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 375 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 376 | HANDLE ret; |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 377 | |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 378 | SERVER_START_REQ( open_console ) |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 379 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 380 | req->from = output; |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 381 | req->access = access; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 382 | req->share = sharing; |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 383 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 384 | SetLastError(0); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 385 | wine_server_call_err( req ); |
| 386 | ret = reply->handle; |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 387 | } |
| 388 | SERVER_END_REQ; |
| 389 | return ret; |
| 390 | } |
| 391 | |
| 392 | |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 393 | /*********************************************************************** |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 394 | * FILE_CreateFile |
| 395 | * |
| 396 | * Implementation of CreateFile. Takes a Unix path name. |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 397 | * Returns 0 on failure. |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 398 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 399 | HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 400 | LPSECURITY_ATTRIBUTES sa, DWORD creation, |
Ove Kaaven | 708a846 | 2001-10-24 00:23:25 +0000 | [diff] [blame] | 401 | DWORD attributes, HANDLE template, BOOL fail_read_only, |
| 402 | UINT drive_type ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 403 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 404 | unsigned int err; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 405 | HANDLE ret; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 406 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 407 | for (;;) |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 408 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 409 | SERVER_START_REQ( create_file ) |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 410 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 411 | req->access = access; |
| 412 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 413 | req->sharing = sharing; |
| 414 | req->create = creation; |
| 415 | req->attrs = attributes; |
| 416 | req->drive_type = drive_type; |
| 417 | wine_server_add_data( req, filename, strlen(filename) ); |
| 418 | SetLastError(0); |
| 419 | err = wine_server_call( req ); |
| 420 | ret = reply->handle; |
Alexandre Julliard | fbace6e | 2000-04-04 20:35:45 +0000 | [diff] [blame] | 421 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 422 | SERVER_END_REQ; |
| 423 | |
| 424 | /* If write access failed, retry without GENERIC_WRITE */ |
| 425 | |
| 426 | if (!ret && !fail_read_only && (access & GENERIC_WRITE)) |
| 427 | { |
| 428 | if ((err == STATUS_MEDIA_WRITE_PROTECTED) || (err == STATUS_ACCESS_DENIED)) |
| 429 | { |
| 430 | TRACE("Write access failed for file '%s', trying without " |
| 431 | "write access\n", filename); |
| 432 | access &= ~GENERIC_WRITE; |
| 433 | continue; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if (err) SetLastError( RtlNtStatusToDosError(err) ); |
| 438 | |
| 439 | if (!ret) WARN("Unable to create file '%s' (GLE %ld)\n", filename, GetLastError()); |
| 440 | return ret; |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 441 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | |
| 445 | /*********************************************************************** |
| 446 | * FILE_CreateDevice |
| 447 | * |
| 448 | * Same as FILE_CreateFile but for a device |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 449 | * Returns 0 on failure. |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 450 | */ |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 451 | HANDLE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 452 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 453 | HANDLE ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 454 | SERVER_START_REQ( create_device ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 455 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 456 | req->access = access; |
| 457 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 458 | req->id = client_id; |
| 459 | SetLastError(0); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 460 | wine_server_call_err( req ); |
| 461 | ret = reply->handle; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 462 | } |
| 463 | SERVER_END_REQ; |
| 464 | return ret; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 467 | static HANDLE FILE_OpenPipe(LPCSTR name, DWORD access) |
| 468 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 469 | WCHAR buffer[MAX_PATH]; |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 470 | HANDLE ret; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 471 | DWORD len = 0; |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 472 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 473 | if (name && !(len = MultiByteToWideChar( CP_ACP, 0, name, strlen(name), buffer, MAX_PATH ))) |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 474 | { |
| 475 | SetLastError( ERROR_FILENAME_EXCED_RANGE ); |
| 476 | return 0; |
| 477 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 478 | SERVER_START_REQ( open_named_pipe ) |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 479 | { |
| 480 | req->access = access; |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 481 | SetLastError(0); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 482 | wine_server_add_data( req, buffer, len * sizeof(WCHAR) ); |
| 483 | wine_server_call_err( req ); |
| 484 | ret = reply->handle; |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 485 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 486 | SERVER_END_REQ; |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 487 | TRACE("Returned %d\n",ret); |
| 488 | return ret; |
| 489 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 490 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 491 | /************************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 492 | * CreateFileA [KERNEL32.@] Creates or opens a file or other object |
Uwe Bonnes | a370ab4 | 1998-10-24 09:16:44 +0000 | [diff] [blame] | 493 | * |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 494 | * Creates or opens an object, and returns a handle that can be used to |
| 495 | * access that object. |
Uwe Bonnes | a370ab4 | 1998-10-24 09:16:44 +0000 | [diff] [blame] | 496 | * |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 497 | * PARAMS |
| 498 | * |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 499 | * filename [in] pointer to filename to be accessed |
| 500 | * access [in] access mode requested |
| 501 | * sharing [in] share mode |
| 502 | * sa [in] pointer to security attributes |
| 503 | * creation [in] how to create the file |
| 504 | * attributes [in] attributes for newly created file |
| 505 | * template [in] handle to file with extended attributes to copy |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 506 | * |
| 507 | * RETURNS |
| 508 | * Success: Open handle to specified file |
| 509 | * Failure: INVALID_HANDLE_VALUE |
| 510 | * |
| 511 | * NOTES |
| 512 | * Should call SetLastError() on failure. |
| 513 | * |
| 514 | * BUGS |
| 515 | * |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 516 | * Doesn't support character devices, template files, or a |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 517 | * lot of the 'attributes' flags yet. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 518 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 519 | HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing, |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 520 | LPSECURITY_ATTRIBUTES sa, DWORD creation, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 521 | DWORD attributes, HANDLE template ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 522 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 523 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 524 | HANDLE ret; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 525 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 526 | if (!filename) |
| 527 | { |
| 528 | SetLastError( ERROR_INVALID_PARAMETER ); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 529 | return INVALID_HANDLE_VALUE; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 530 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 531 | TRACE("%s %s%s%s%s%s%s%s\n",filename, |
Uwe Bonnes | e4f46dc | 1999-06-06 17:08:13 +0000 | [diff] [blame] | 532 | ((access & GENERIC_READ)==GENERIC_READ)?"GENERIC_READ ":"", |
| 533 | ((access & GENERIC_WRITE)==GENERIC_WRITE)?"GENERIC_WRITE ":"", |
| 534 | (!access)?"QUERY_ACCESS ":"", |
| 535 | ((sharing & FILE_SHARE_READ)==FILE_SHARE_READ)?"FILE_SHARE_READ ":"", |
| 536 | ((sharing & FILE_SHARE_WRITE)==FILE_SHARE_WRITE)?"FILE_SHARE_WRITE ":"", |
| 537 | ((sharing & FILE_SHARE_DELETE)==FILE_SHARE_DELETE)?"FILE_SHARE_DELETE ":"", |
| 538 | (creation ==CREATE_NEW)?"CREATE_NEW": |
| 539 | (creation ==CREATE_ALWAYS)?"CREATE_ALWAYS ": |
| 540 | (creation ==OPEN_EXISTING)?"OPEN_EXISTING ": |
| 541 | (creation ==OPEN_ALWAYS)?"OPEN_ALWAYS ": |
| 542 | (creation ==TRUNCATE_EXISTING)?"TRUNCATE_EXISTING ":""); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 543 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 544 | /* If the name starts with '\\?\', ignore the first 4 chars. */ |
| 545 | if (!strncmp(filename, "\\\\?\\", 4)) |
| 546 | { |
| 547 | filename += 4; |
| 548 | if (!strncmp(filename, "UNC\\", 4)) |
| 549 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 550 | FIXME("UNC name (%s) not supported.\n", filename ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 551 | SetLastError( ERROR_PATH_NOT_FOUND ); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 552 | return INVALID_HANDLE_VALUE; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 555 | |
Marcus Meissner | dd7523d | 2000-01-23 02:18:27 +0000 | [diff] [blame] | 556 | if (!strncmp(filename, "\\\\.\\", 4)) { |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 557 | if(!strncasecmp(&filename[4],"pipe\\",5)) |
| 558 | { |
| 559 | TRACE("Opening a pipe: %s\n",filename); |
Ove Kaaven | 7efa8e2 | 2001-09-25 22:37:32 +0000 | [diff] [blame] | 560 | ret = FILE_OpenPipe(filename,access); |
| 561 | goto done; |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 562 | } |
Eric Pouech | 5cc6105 | 2002-01-13 01:44:00 +0000 | [diff] [blame] | 563 | else if (isalpha(filename[4]) && filename[5] == ':' && filename[6] == '\0') |
| 564 | { |
| 565 | ret = FILE_CreateDevice( (toupper(filename[4]) - 'A') | 0x20000, access, sa ); |
| 566 | goto done; |
| 567 | } |
Mike McCormack | de7c300 | 2001-07-10 19:16:49 +0000 | [diff] [blame] | 568 | else if (!DOSFS_GetDevice( filename )) |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 569 | { |
| 570 | ret = DEVICE_Open( filename+4, access, sa ); |
| 571 | goto done; |
| 572 | } |
Marcus Meissner | dd7523d | 2000-01-23 02:18:27 +0000 | [diff] [blame] | 573 | else |
| 574 | filename+=4; /* fall into DOSFS_Device case below */ |
| 575 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 576 | |
| 577 | /* If the name still starts with '\\', it's a UNC name. */ |
| 578 | if (!strncmp(filename, "\\\\", 2)) |
| 579 | { |
Mike McCormack | fc93261 | 2002-03-12 19:24:04 +0000 | [diff] [blame] | 580 | ret = SMB_CreateFileA(filename, access, sharing, sa, creation, attributes, template ); |
| 581 | goto done; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Francois Boisvert | 567bcf1 | 1999-09-20 18:31:21 +0000 | [diff] [blame] | 584 | /* If the name contains a DOS wild card (* or ?), do no create a file */ |
| 585 | if(strchr(filename,'*') || strchr(filename,'?')) |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 586 | return INVALID_HANDLE_VALUE; |
Francois Boisvert | 567bcf1 | 1999-09-20 18:31:21 +0000 | [diff] [blame] | 587 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 588 | /* Open a console for CONIN$ or CONOUT$ */ |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 589 | if (!strcasecmp(filename, "CONIN$")) |
| 590 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 591 | ret = FILE_OpenConsole( FALSE, access, sharing, sa ); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 592 | goto done; |
| 593 | } |
| 594 | if (!strcasecmp(filename, "CONOUT$")) |
| 595 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 596 | ret = FILE_OpenConsole( TRUE, access, sharing, sa ); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 597 | goto done; |
| 598 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 599 | |
| 600 | if (DOSFS_GetDevice( filename )) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 601 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 602 | TRACE("opening device '%s'\n", filename ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 603 | |
Eric Pouech | 3bbeb72 | 2001-10-14 16:08:45 +0000 | [diff] [blame] | 604 | if (!(ret = DOSFS_OpenDevice( filename, access, attributes, sa ))) |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 605 | { |
| 606 | /* Do not silence this please. It is a critical error. -MM */ |
| 607 | ERR("Couldn't open device '%s'!\n",filename); |
| 608 | SetLastError( ERROR_FILE_NOT_FOUND ); |
| 609 | } |
| 610 | goto done; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 611 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 612 | |
| 613 | /* check for filename, don't check for last entry if creating */ |
| 614 | if (!DOSFS_GetFullName( filename, |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 615 | (creation == OPEN_EXISTING) || |
| 616 | (creation == TRUNCATE_EXISTING), |
| 617 | &full_name )) { |
| 618 | WARN("Unable to get full filename from '%s' (GLE %ld)\n", |
| 619 | filename, GetLastError()); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 620 | return INVALID_HANDLE_VALUE; |
Matthew Cline | 8bfd825 | 2000-02-18 19:05:11 +0000 | [diff] [blame] | 621 | } |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 622 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 623 | ret = FILE_CreateFile( full_name.long_name, access, sharing, |
| 624 | sa, creation, attributes, template, |
Ove Kaaven | 708a846 | 2001-10-24 00:23:25 +0000 | [diff] [blame] | 625 | DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY, |
| 626 | GetDriveTypeA( full_name.short_name ) ); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 627 | done: |
| 628 | if (!ret) ret = INVALID_HANDLE_VALUE; |
| 629 | return ret; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 633 | |
| 634 | /************************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 635 | * CreateFileW (KERNEL32.@) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 636 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 637 | HANDLE WINAPI CreateFileW( LPCWSTR filename, DWORD access, DWORD sharing, |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 638 | LPSECURITY_ATTRIBUTES sa, DWORD creation, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 639 | DWORD attributes, HANDLE template) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 640 | { |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 641 | LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 642 | HANDLE res = CreateFileA( afn, access, sharing, sa, creation, attributes, template ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 643 | HeapFree( GetProcessHeap(), 0, afn ); |
| 644 | return res; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | |
| 648 | /*********************************************************************** |
| 649 | * FILE_FillInfo |
| 650 | * |
| 651 | * Fill a file information from a struct stat. |
| 652 | */ |
Marcus Meissner | 6bb990f | 2001-05-29 20:55:21 +0000 | [diff] [blame] | 653 | static void FILE_FillInfo( struct stat *st, BY_HANDLE_FILE_INFORMATION *info ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 654 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 655 | if (S_ISDIR(st->st_mode)) |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 656 | info->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; |
| 657 | else |
| 658 | info->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 659 | if (!(st->st_mode & S_IWUSR)) |
| 660 | info->dwFileAttributes |= FILE_ATTRIBUTE_READONLY; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 661 | |
Alexandre Julliard | e101f6d | 2000-08-14 14:42:41 +0000 | [diff] [blame] | 662 | RtlSecondsSince1970ToTime( st->st_mtime, &info->ftCreationTime ); |
| 663 | RtlSecondsSince1970ToTime( st->st_mtime, &info->ftLastWriteTime ); |
| 664 | RtlSecondsSince1970ToTime( st->st_atime, &info->ftLastAccessTime ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 665 | |
| 666 | info->dwVolumeSerialNumber = 0; /* FIXME */ |
| 667 | info->nFileSizeHigh = 0; |
Marcus Meissner | 3f1ed52 | 2001-05-14 20:09:37 +0000 | [diff] [blame] | 668 | info->nFileSizeLow = 0; |
| 669 | if (!S_ISDIR(st->st_mode)) { |
| 670 | info->nFileSizeHigh = st->st_size >> 32; |
| 671 | info->nFileSizeLow = st->st_size & 0xffffffff; |
| 672 | } |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 673 | info->nNumberOfLinks = st->st_nlink; |
| 674 | info->nFileIndexHigh = 0; |
| 675 | info->nFileIndexLow = st->st_ino; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | |
| 679 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 680 | * FILE_Stat |
| 681 | * |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 682 | * Stat a Unix path name. Return TRUE if OK. |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 683 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 684 | BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 685 | { |
Marcus Meissner | 6bb990f | 2001-05-29 20:55:21 +0000 | [diff] [blame] | 686 | struct stat st; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 687 | |
Marcus Meissner | 6bb990f | 2001-05-29 20:55:21 +0000 | [diff] [blame] | 688 | if (lstat( unixName, &st ) == -1) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 689 | { |
| 690 | FILE_SetDosError(); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 691 | return FALSE; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 692 | } |
Andreas Mohr | 220312e | 2000-10-19 20:38:38 +0000 | [diff] [blame] | 693 | if (!S_ISLNK(st.st_mode)) FILE_FillInfo( &st, info ); |
| 694 | else |
| 695 | { |
| 696 | /* do a "real" stat to find out |
| 697 | about the type of the symlink destination */ |
Marcus Meissner | 6bb990f | 2001-05-29 20:55:21 +0000 | [diff] [blame] | 698 | if (stat( unixName, &st ) == -1) |
Andreas Mohr | 220312e | 2000-10-19 20:38:38 +0000 | [diff] [blame] | 699 | { |
| 700 | FILE_SetDosError(); |
| 701 | return FALSE; |
| 702 | } |
| 703 | FILE_FillInfo( &st, info ); |
| 704 | info->dwFileAttributes |= FILE_ATTRIBUTE_SYMLINK; |
| 705 | } |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 706 | return TRUE; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | |
| 710 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 711 | * GetFileInformationByHandle (KERNEL32.@) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 712 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 713 | DWORD WINAPI GetFileInformationByHandle( HANDLE hFile, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 714 | BY_HANDLE_FILE_INFORMATION *info ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 715 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 716 | DWORD ret; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 717 | if (!info) return 0; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 718 | |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 719 | SERVER_START_REQ( get_file_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 720 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 721 | req->handle = hFile; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 722 | if ((ret = !wine_server_call_err( req ))) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 723 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 724 | /* FIXME: which file types are supported ? |
| 725 | * Serial ports (FILE_TYPE_CHAR) are not, |
| 726 | * and MSDN also says that pipes are not supported. |
| 727 | * FILE_TYPE_REMOTE seems to be supported according to |
| 728 | * MSDN q234741.txt */ |
| 729 | if ((reply->type == FILE_TYPE_DISK) || (reply->type == FILE_TYPE_REMOTE)) |
| 730 | { |
| 731 | RtlSecondsSince1970ToTime( reply->write_time, &info->ftCreationTime ); |
| 732 | RtlSecondsSince1970ToTime( reply->write_time, &info->ftLastWriteTime ); |
| 733 | RtlSecondsSince1970ToTime( reply->access_time, &info->ftLastAccessTime ); |
| 734 | info->dwFileAttributes = reply->attr; |
| 735 | info->dwVolumeSerialNumber = reply->serial; |
| 736 | info->nFileSizeHigh = reply->size_high; |
| 737 | info->nFileSizeLow = reply->size_low; |
| 738 | info->nNumberOfLinks = reply->links; |
| 739 | info->nFileIndexHigh = reply->index_high; |
| 740 | info->nFileIndexLow = reply->index_low; |
| 741 | } |
| 742 | else |
| 743 | { |
| 744 | SetLastError(ERROR_NOT_SUPPORTED); |
| 745 | ret = 0; |
| 746 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | SERVER_END_REQ; |
| 750 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
| 754 | /************************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 755 | * GetFileAttributes (KERNEL.420) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 756 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 757 | DWORD WINAPI GetFileAttributes16( LPCSTR name ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 758 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 759 | return GetFileAttributesA( name ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
| 763 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 764 | * GetFileAttributesA (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 765 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 766 | DWORD WINAPI GetFileAttributesA( LPCSTR name ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 767 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 768 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 769 | BY_HANDLE_FILE_INFORMATION info; |
| 770 | |
Jon Griffiths | 0cfa278 | 2001-02-14 00:26:46 +0000 | [diff] [blame] | 771 | if (name == NULL) |
| 772 | { |
| 773 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 774 | return -1; |
| 775 | } |
Gerard Patel | d52e1c4 | 2001-02-16 19:05:42 +0000 | [diff] [blame] | 776 | if (!DOSFS_GetFullName( name, TRUE, &full_name) ) |
Jon Griffiths | 0cfa278 | 2001-02-14 00:26:46 +0000 | [diff] [blame] | 777 | return -1; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 778 | if (!FILE_Stat( full_name.long_name, &info )) return -1; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 779 | return info.dwFileAttributes; |
| 780 | } |
| 781 | |
| 782 | |
| 783 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 784 | * GetFileAttributesW (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 785 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 786 | DWORD WINAPI GetFileAttributesW( LPCWSTR name ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 787 | { |
| 788 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 789 | DWORD res = GetFileAttributesA( nameA ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 790 | HeapFree( GetProcessHeap(), 0, nameA ); |
| 791 | return res; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | |
Francois Gouget | 34372dc | 2002-03-29 18:17:35 +0000 | [diff] [blame] | 795 | /************************************************************************** |
| 796 | * SetFileAttributes (KERNEL.421) |
| 797 | */ |
| 798 | BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes ) |
| 799 | { |
| 800 | return SetFileAttributesA( lpFileName, attributes ); |
| 801 | } |
| 802 | |
| 803 | |
| 804 | /************************************************************************** |
| 805 | * SetFileAttributesA (KERNEL32.@) |
| 806 | */ |
| 807 | BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD attributes) |
| 808 | { |
| 809 | struct stat buf; |
| 810 | DOS_FULL_NAME full_name; |
| 811 | |
| 812 | if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name )) |
| 813 | return FALSE; |
| 814 | |
| 815 | TRACE("(%s,%lx)\n",lpFileName,attributes); |
| 816 | if (attributes & FILE_ATTRIBUTE_NORMAL) { |
| 817 | attributes &= ~FILE_ATTRIBUTE_NORMAL; |
| 818 | if (attributes) |
| 819 | FIXME("(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n", lpFileName,attributes); |
| 820 | } |
| 821 | if(stat(full_name.long_name,&buf)==-1) |
| 822 | { |
| 823 | FILE_SetDosError(); |
| 824 | return FALSE; |
| 825 | } |
| 826 | if (attributes & FILE_ATTRIBUTE_READONLY) |
| 827 | { |
| 828 | if(S_ISDIR(buf.st_mode)) |
| 829 | /* FIXME */ |
| 830 | WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n"); |
| 831 | else |
| 832 | buf.st_mode &= ~0222; /* octal!, clear write permission bits */ |
| 833 | attributes &= ~FILE_ATTRIBUTE_READONLY; |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | /* add write permission */ |
| 838 | buf.st_mode |= (0600 | ((buf.st_mode & 044) >> 1)) & (~FILE_umask); |
| 839 | } |
| 840 | if (attributes & FILE_ATTRIBUTE_DIRECTORY) |
| 841 | { |
| 842 | if (!S_ISDIR(buf.st_mode)) |
| 843 | FIXME("SetFileAttributes expected the file '%s' to be a directory", |
| 844 | lpFileName); |
| 845 | attributes &= ~FILE_ATTRIBUTE_DIRECTORY; |
| 846 | } |
| 847 | attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM); |
| 848 | if (attributes) |
| 849 | FIXME("(%s):%lx attribute(s) not implemented.\n", lpFileName,attributes); |
| 850 | if (-1==chmod(full_name.long_name,buf.st_mode)) |
| 851 | { |
| 852 | if(GetDriveTypeA(lpFileName) == DRIVE_CDROM) { |
| 853 | SetLastError( ERROR_ACCESS_DENIED ); |
| 854 | return FALSE; |
| 855 | } |
| 856 | |
| 857 | /* |
| 858 | * FIXME: We don't return FALSE here because of differences between |
| 859 | * Linux and Windows privileges. Under Linux only the owner of |
| 860 | * the file is allowed to change file attributes. Under Windows, |
| 861 | * applications expect that if you can write to a file, you can also |
| 862 | * change its attributes (see GENERIC_WRITE). We could try to be |
| 863 | * clever here but that would break multi-user installations where |
| 864 | * users share read-only DLLs. This is because some installers like |
| 865 | * to change attributes of already installed DLLs. |
| 866 | */ |
| 867 | FIXME("Couldn't set file attributes for existing file \"%s\".\n" |
| 868 | "Check permissions or set VFAT \"quiet\" mount flag\n", full_name.long_name); |
| 869 | } |
| 870 | return TRUE; |
| 871 | } |
| 872 | |
| 873 | |
| 874 | /************************************************************************** |
| 875 | * SetFileAttributesW (KERNEL32.@) |
| 876 | */ |
| 877 | BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD attributes) |
| 878 | { |
| 879 | BOOL res; |
| 880 | DWORD len = WideCharToMultiByte( CP_ACP, 0, lpFileName, -1, NULL, 0, NULL, NULL ); |
| 881 | LPSTR afn = HeapAlloc( GetProcessHeap(), 0, len ); |
| 882 | |
| 883 | WideCharToMultiByte( CP_ACP, 0, lpFileName, -1, afn, len, NULL, NULL ); |
| 884 | res = SetFileAttributesA( afn, attributes ); |
| 885 | HeapFree( GetProcessHeap(), 0, afn ); |
| 886 | return res; |
| 887 | } |
| 888 | |
| 889 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 890 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 891 | * GetFileSize (KERNEL32.@) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 892 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 893 | DWORD WINAPI GetFileSize( HANDLE hFile, LPDWORD filesizehigh ) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 894 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 895 | BY_HANDLE_FILE_INFORMATION info; |
Andreas Mohr | 12bf7f1 | 2001-03-05 19:30:52 +0000 | [diff] [blame] | 896 | if (!GetFileInformationByHandle( hFile, &info )) return -1; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 897 | if (filesizehigh) *filesizehigh = info.nFileSizeHigh; |
| 898 | return info.nFileSizeLow; |
| 899 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 900 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 901 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 902 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 903 | * GetFileTime (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 904 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 905 | BOOL WINAPI GetFileTime( HANDLE hFile, FILETIME *lpCreationTime, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 906 | FILETIME *lpLastAccessTime, |
| 907 | FILETIME *lpLastWriteTime ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 908 | { |
| 909 | BY_HANDLE_FILE_INFORMATION info; |
| 910 | if (!GetFileInformationByHandle( hFile, &info )) return FALSE; |
| 911 | if (lpCreationTime) *lpCreationTime = info.ftCreationTime; |
| 912 | if (lpLastAccessTime) *lpLastAccessTime = info.ftLastAccessTime; |
| 913 | if (lpLastWriteTime) *lpLastWriteTime = info.ftLastWriteTime; |
| 914 | return TRUE; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 917 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 918 | * CompareFileTime (KERNEL32.@) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 919 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 920 | INT WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y ) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 921 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 922 | if (!x || !y) return -1; |
| 923 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 924 | if (x->dwHighDateTime > y->dwHighDateTime) |
| 925 | return 1; |
| 926 | if (x->dwHighDateTime < y->dwHighDateTime) |
| 927 | return -1; |
| 928 | if (x->dwLowDateTime > y->dwLowDateTime) |
| 929 | return 1; |
| 930 | if (x->dwLowDateTime < y->dwLowDateTime) |
| 931 | return -1; |
| 932 | return 0; |
| 933 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 934 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 935 | /*********************************************************************** |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 936 | * FILE_GetTempFileName : utility for GetTempFileName |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 937 | */ |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 938 | static UINT FILE_GetTempFileName( LPCSTR path, LPCSTR prefix, UINT unique, |
| 939 | LPSTR buffer, BOOL isWin16 ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 940 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 941 | static UINT unique_temp; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 942 | DOS_FULL_NAME full_name; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 943 | int i; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 944 | LPSTR p; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 945 | UINT num; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 946 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 947 | if ( !path || !prefix || !buffer ) return 0; |
| 948 | |
Uwe Bonnes | 2e52589 | 1998-11-01 15:04:52 +0000 | [diff] [blame] | 949 | if (!unique_temp) unique_temp = time(NULL) & 0xffff; |
| 950 | num = unique ? (unique & 0xffff) : (unique_temp++ & 0xffff); |
| 951 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 952 | strcpy( buffer, path ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 953 | p = buffer + strlen(buffer); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 954 | |
| 955 | /* add a \, if there isn't one and path is more than just the drive letter ... */ |
| 956 | if ( !((strlen(buffer) == 2) && (buffer[1] == ':')) |
| 957 | && ((p == buffer) || (p[-1] != '\\'))) *p++ = '\\'; |
| 958 | |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 959 | if (isWin16) *p++ = '~'; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 960 | for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++; |
| 961 | sprintf( p, "%04x.tmp", num ); |
| 962 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 963 | /* Now try to create it */ |
| 964 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 965 | if (!unique) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 966 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 967 | do |
| 968 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 969 | HFILE handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL, |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 970 | CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 971 | if (handle != INVALID_HANDLE_VALUE) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 972 | { /* We created it */ |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 973 | TRACE("created %s\n", |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 974 | buffer); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 975 | CloseHandle( handle ); |
| 976 | break; |
| 977 | } |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 978 | if (GetLastError() != ERROR_FILE_EXISTS) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 979 | break; /* No need to go on */ |
| 980 | num++; |
| 981 | sprintf( p, "%04x.tmp", num ); |
| 982 | } while (num != (unique & 0xffff)); |
| 983 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 984 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 985 | /* Get the full path name */ |
| 986 | |
| 987 | if (DOSFS_GetFullName( buffer, FALSE, &full_name )) |
| 988 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 989 | /* Check if we have write access in the directory */ |
| 990 | if ((p = strrchr( full_name.long_name, '/' ))) *p = '\0'; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 991 | if (access( full_name.long_name, W_OK ) == -1) |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 992 | WARN("returns '%s', which doesn't seem to be writeable.\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 993 | buffer); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 994 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 995 | TRACE("returning %s\n", buffer ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 996 | return unique ? unique : num; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | |
| 1000 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1001 | * GetTempFileNameA (KERNEL32.@) |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 1002 | */ |
| 1003 | UINT WINAPI GetTempFileNameA( LPCSTR path, LPCSTR prefix, UINT unique, |
| 1004 | LPSTR buffer) |
| 1005 | { |
| 1006 | return FILE_GetTempFileName(path, prefix, unique, buffer, FALSE); |
| 1007 | } |
| 1008 | |
| 1009 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1010 | * GetTempFileNameW (KERNEL32.@) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1011 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1012 | UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1013 | LPWSTR buffer ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1014 | { |
| 1015 | LPSTR patha,prefixa; |
| 1016 | char buffera[144]; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1017 | UINT ret; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1018 | |
| 1019 | if (!path) return 0; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1020 | patha = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
| 1021 | prefixa = HEAP_strdupWtoA( GetProcessHeap(), 0, prefix ); |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 1022 | ret = FILE_GetTempFileName( patha, prefixa, unique, buffera, FALSE ); |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1023 | MultiByteToWideChar( CP_ACP, 0, buffera, -1, buffer, MAX_PATH ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1024 | HeapFree( GetProcessHeap(), 0, patha ); |
| 1025 | HeapFree( GetProcessHeap(), 0, prefixa ); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1026 | return ret; |
| 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1031 | * GetTempFileName (KERNEL.97) |
Gerard Patel | c465e19 | 1999-10-24 20:48:54 +0000 | [diff] [blame] | 1032 | */ |
| 1033 | UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique, |
| 1034 | LPSTR buffer ) |
| 1035 | { |
| 1036 | char temppath[144]; |
| 1037 | |
| 1038 | if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */ |
| 1039 | drive |= DRIVE_GetCurrentDrive() + 'A'; |
| 1040 | |
| 1041 | if ((drive & TF_FORCEDRIVE) && |
| 1042 | !DRIVE_IsValid( toupper(drive & ~TF_FORCEDRIVE) - 'A' )) |
| 1043 | { |
| 1044 | drive &= ~TF_FORCEDRIVE; |
| 1045 | WARN("invalid drive %d specified\n", drive ); |
| 1046 | } |
| 1047 | |
| 1048 | if (drive & TF_FORCEDRIVE) |
| 1049 | sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE ); |
| 1050 | else |
| 1051 | GetTempPathA( 132, temppath ); |
| 1052 | return (UINT16)FILE_GetTempFileName( temppath, prefix, unique, buffer, TRUE ); |
| 1053 | } |
| 1054 | |
| 1055 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1056 | * FILE_DoOpenFile |
| 1057 | * |
| 1058 | * Implementation of OpenFile16() and OpenFile32(). |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1059 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1060 | static HFILE FILE_DoOpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode, |
| 1061 | BOOL win32 ) |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1062 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1063 | HFILE hFileRet; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1064 | FILETIME filetime; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1065 | WORD filedatetime[2]; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1066 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1067 | DWORD access, sharing; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1068 | char *p; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1069 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1070 | if (!ofs) return HFILE_ERROR; |
Uwe Bonnes | e4f46dc | 1999-06-06 17:08:13 +0000 | [diff] [blame] | 1071 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1072 | 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] | 1073 | ((mode & 0x3 )==OF_READ)?"OF_READ": |
| 1074 | ((mode & 0x3 )==OF_WRITE)?"OF_WRITE": |
| 1075 | ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown", |
| 1076 | ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT": |
| 1077 | ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE": |
| 1078 | ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ": |
| 1079 | ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE": |
| 1080 | ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown", |
| 1081 | ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"", |
| 1082 | ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"", |
| 1083 | ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"", |
| 1084 | ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"", |
| 1085 | ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"", |
| 1086 | ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"", |
| 1087 | ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"", |
| 1088 | ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"", |
| 1089 | ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":"" |
| 1090 | ); |
| 1091 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1092 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1093 | ofs->cBytes = sizeof(OFSTRUCT); |
| 1094 | ofs->nErrCode = 0; |
| 1095 | if (mode & OF_REOPEN) name = ofs->szPathName; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1096 | |
| 1097 | if (!name) { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1098 | ERR("called with `name' set to NULL ! Please debug.\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1099 | return HFILE_ERROR; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1100 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1101 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1102 | TRACE("%s %04x\n", name, mode ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1103 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1104 | /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName |
| 1105 | Are there any cases where getting the path here is wrong? |
| 1106 | Uwe Bonnes 1997 Apr 2 */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1107 | if (!GetFullPathNameA( name, sizeof(ofs->szPathName), |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1108 | ofs->szPathName, NULL )) goto error; |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1109 | FILE_ConvertOFMode( mode, &access, &sharing ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1110 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1111 | /* OF_PARSE simply fills the structure */ |
| 1112 | |
| 1113 | if (mode & OF_PARSE) |
| 1114 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1115 | ofs->fFixedDisk = (GetDriveType16( ofs->szPathName[0]-'A' ) |
| 1116 | != DRIVE_REMOVABLE); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1117 | TRACE("(%s): OF_PARSE, res = '%s'\n", |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1118 | name, ofs->szPathName ); |
| 1119 | return 0; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /* OF_CREATE is completely different from all other options, so |
| 1123 | handle it first */ |
| 1124 | |
| 1125 | if (mode & OF_CREATE) |
| 1126 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1127 | if ((hFileRet = CreateFileA( name, GENERIC_READ | GENERIC_WRITE, |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1128 | sharing, NULL, CREATE_ALWAYS, |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 1129 | FILE_ATTRIBUTE_NORMAL, 0 ))== INVALID_HANDLE_VALUE) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1130 | goto error; |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1131 | goto success; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1134 | /* If OF_SEARCH is set, ignore the given path */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1135 | |
| 1136 | if ((mode & OF_SEARCH) && !(mode & OF_REOPEN)) |
| 1137 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1138 | /* First try the file name as is */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1139 | if (DOSFS_GetFullName( name, TRUE, &full_name )) goto found; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1140 | /* Now remove the path */ |
| 1141 | if (name[0] && (name[1] == ':')) name += 2; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1142 | if ((p = strrchr( name, '\\' ))) name = p + 1; |
| 1143 | if ((p = strrchr( name, '/' ))) name = p + 1; |
| 1144 | if (!name[0]) goto not_found; |
| 1145 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1146 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1147 | /* Now look for the file */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1148 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1149 | if (!DIR_SearchPath( NULL, name, NULL, &full_name, win32 )) goto not_found; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1150 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1151 | found: |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1152 | TRACE("found %s = %s\n", |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1153 | full_name.long_name, full_name.short_name ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1154 | lstrcpynA( ofs->szPathName, full_name.short_name, |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1155 | sizeof(ofs->szPathName) ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1156 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1157 | if (mode & OF_SHARE_EXCLUSIVE) |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 1158 | /* Some InstallShield version uses OF_SHARE_EXCLUSIVE |
| 1159 | on the file <tempdir>/_ins0432._mp to determine how |
| 1160 | far installation has proceeded. |
| 1161 | _ins0432._mp is an executable and while running the |
| 1162 | application expects the open with OF_SHARE_ to fail*/ |
| 1163 | /* Probable FIXME: |
| 1164 | As our loader closes the files after loading the executable, |
| 1165 | we can't find the running executable with FILE_InUse. |
Andreas Mohr | c9cf70d | 2001-01-26 20:40:50 +0000 | [diff] [blame] | 1166 | The loader should keep the file open, as Windows does that, too. |
| 1167 | */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1168 | { |
| 1169 | char *last = strrchr(full_name.long_name,'/'); |
| 1170 | if (!last) |
| 1171 | last = full_name.long_name - 1; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1172 | if (GetModuleHandle16(last+1)) |
| 1173 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1174 | TRACE("Denying shared open for %s\n",full_name.long_name); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1175 | return HFILE_ERROR; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1176 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1179 | if (mode & OF_DELETE) |
| 1180 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1181 | if (unlink( full_name.long_name ) == -1) goto not_found; |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1182 | TRACE("(%s): OF_DELETE return = OK\n", name); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1183 | return 1; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 1186 | hFileRet = FILE_CreateFile( full_name.long_name, access, sharing, |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 1187 | NULL, OPEN_EXISTING, 0, 0, |
Ove Kaaven | 708a846 | 2001-10-24 00:23:25 +0000 | [diff] [blame] | 1188 | DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY, |
| 1189 | GetDriveTypeA( full_name.short_name ) ); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 1190 | if (!hFileRet) goto not_found; |
Uwe Bonnes | e6b5e38 | 1998-10-18 14:48:31 +0000 | [diff] [blame] | 1191 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1192 | GetFileTime( hFileRet, NULL, NULL, &filetime ); |
| 1193 | FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1194 | if ((mode & OF_VERIFY) && (mode & OF_REOPEN)) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1195 | { |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1196 | if (memcmp( ofs->reserved, filedatetime, sizeof(ofs->reserved) )) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1197 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1198 | CloseHandle( hFileRet ); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1199 | WARN("(%s): OF_VERIFY failed\n", name ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1200 | /* FIXME: what error here? */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1201 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1202 | goto error; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1203 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1204 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1205 | memcpy( ofs->reserved, filedatetime, sizeof(ofs->reserved) ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1206 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1207 | success: /* We get here if the open was successful */ |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1208 | TRACE("(%s): OK, return = %d\n", name, hFileRet ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1209 | if (win32) |
| 1210 | { |
| 1211 | if (mode & OF_EXIST) /* Return the handle, but close it first */ |
| 1212 | CloseHandle( hFileRet ); |
| 1213 | } |
| 1214 | else |
| 1215 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1216 | hFileRet = Win32HandleToDosFileHandle( hFileRet ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1217 | if (hFileRet == HFILE_ERROR16) goto error; |
| 1218 | if (mode & OF_EXIST) /* Return the handle, but close it first */ |
| 1219 | _lclose16( hFileRet ); |
| 1220 | } |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1221 | return hFileRet; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1222 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1223 | not_found: /* We get here if the file does not exist */ |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 1224 | WARN("'%s' not found or sharing violation\n", name ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1225 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1226 | /* fall through */ |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1227 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1228 | error: /* We get here if there was an error opening the file */ |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1229 | ofs->nErrCode = GetLastError(); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1230 | WARN("(%s): return = HFILE_ERROR error= %d\n", |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1231 | name,ofs->nErrCode ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1232 | return HFILE_ERROR; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 1235 | |
| 1236 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1237 | * OpenFile (KERNEL.74) |
| 1238 | * OpenFileEx (KERNEL.360) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 1239 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1240 | HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1241 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1242 | return FILE_DoOpenFile( name, ofs, mode, FALSE ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 1243 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1244 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1245 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1246 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1247 | * OpenFile (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1248 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1249 | HFILE WINAPI OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1250 | { |
| 1251 | return FILE_DoOpenFile( name, ofs, mode, TRUE ); |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | /*********************************************************************** |
Marcus Meissner | b12e72d | 1999-01-23 14:01:08 +0000 | [diff] [blame] | 1256 | * FILE_InitProcessDosHandles |
| 1257 | * |
| 1258 | * Allocates the default DOS handles for a process. Called either by |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1259 | * Win32HandleToDosFileHandle below or by the DOSVM stuff. |
Marcus Meissner | b12e72d | 1999-01-23 14:01:08 +0000 | [diff] [blame] | 1260 | */ |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1261 | static void FILE_InitProcessDosHandles( void ) |
| 1262 | { |
| 1263 | dos_handles[0] = GetStdHandle(STD_INPUT_HANDLE); |
| 1264 | dos_handles[1] = GetStdHandle(STD_OUTPUT_HANDLE); |
| 1265 | dos_handles[2] = GetStdHandle(STD_ERROR_HANDLE); |
| 1266 | dos_handles[3] = GetStdHandle(STD_ERROR_HANDLE); |
| 1267 | dos_handles[4] = GetStdHandle(STD_ERROR_HANDLE); |
Marcus Meissner | b12e72d | 1999-01-23 14:01:08 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | /*********************************************************************** |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1271 | * Win32HandleToDosFileHandle (KERNEL32.21) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1272 | * |
| 1273 | * Allocate a DOS handle for a Win32 handle. The Win32 handle is no |
| 1274 | * longer valid after this function (even on failure). |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1275 | * |
| 1276 | * Note: this is not exactly right, since on Win95 the Win32 handles |
| 1277 | * are on top of DOS handles and we do it the other way |
| 1278 | * around. Should be good enough though. |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1279 | */ |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1280 | HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle ) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1281 | { |
| 1282 | int i; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1283 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1284 | if (!handle || (handle == INVALID_HANDLE_VALUE)) |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1285 | return HFILE_ERROR; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1286 | |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1287 | for (i = 5; i < DOS_TABLE_SIZE; i++) |
| 1288 | if (!dos_handles[i]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1289 | { |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1290 | dos_handles[i] = handle; |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1291 | TRACE("Got %d for h32 %d\n", i, handle ); |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1292 | return (HFILE)i; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1293 | } |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1294 | CloseHandle( handle ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1295 | SetLastError( ERROR_TOO_MANY_OPEN_FILES ); |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1296 | return HFILE_ERROR; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | /*********************************************************************** |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1301 | * DosFileHandleToWin32Handle (KERNEL32.20) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1302 | * |
| 1303 | * Return the Win32 handle for a DOS handle. |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1304 | * |
| 1305 | * Note: this is not exactly right, since on Win95 the Win32 handles |
| 1306 | * are on top of DOS handles and we do it the other way |
| 1307 | * around. Should be good enough though. |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1308 | */ |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1309 | HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle ) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1310 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1311 | HFILE16 hfile = (HFILE16)handle; |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1312 | if (hfile < 5 && !dos_handles[hfile]) FILE_InitProcessDosHandles(); |
| 1313 | if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1314 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1315 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1316 | return INVALID_HANDLE_VALUE; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1317 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1318 | return dos_handles[hfile]; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | |
| 1322 | /*********************************************************************** |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1323 | * DisposeLZ32Handle (KERNEL32.22) |
| 1324 | * |
| 1325 | * Note: this is not entirely correct, we should only close the |
| 1326 | * 32-bit handle and not the 16-bit one, but we cannot do |
| 1327 | * this because of the way our DOS handles are implemented. |
| 1328 | * It shouldn't break anything though. |
| 1329 | */ |
| 1330 | void WINAPI DisposeLZ32Handle( HANDLE handle ) |
| 1331 | { |
| 1332 | int i; |
| 1333 | |
| 1334 | if (!handle || (handle == INVALID_HANDLE_VALUE)) return; |
| 1335 | |
| 1336 | for (i = 5; i < DOS_TABLE_SIZE; i++) |
| 1337 | if (dos_handles[i] == handle) |
| 1338 | { |
| 1339 | dos_handles[i] = 0; |
| 1340 | CloseHandle( handle ); |
| 1341 | break; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | /*********************************************************************** |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1347 | * FILE_Dup2 |
| 1348 | * |
| 1349 | * dup2() function for DOS handles. |
| 1350 | */ |
| 1351 | HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) |
| 1352 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1353 | HANDLE new_handle; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1354 | |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1355 | if (hFile1 < 5 && !dos_handles[hFile1]) FILE_InitProcessDosHandles(); |
| 1356 | |
| 1357 | if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) || !dos_handles[hFile1]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1358 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1359 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1360 | return HFILE_ERROR16; |
| 1361 | } |
| 1362 | if (hFile2 < 5) |
| 1363 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1364 | FIXME("stdio handle closed, need proper conversion\n" ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1365 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1366 | return HFILE_ERROR16; |
| 1367 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1368 | if (!DuplicateHandle( GetCurrentProcess(), dos_handles[hFile1], |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1369 | GetCurrentProcess(), &new_handle, |
| 1370 | 0, FALSE, DUPLICATE_SAME_ACCESS )) |
| 1371 | return HFILE_ERROR16; |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1372 | if (dos_handles[hFile2]) CloseHandle( dos_handles[hFile2] ); |
| 1373 | dos_handles[hFile2] = new_handle; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1374 | return hFile2; |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1379 | * _lclose (KERNEL.81) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1380 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1381 | HFILE16 WINAPI _lclose16( HFILE16 hFile ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1382 | { |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1383 | if (hFile < 5) |
| 1384 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1385 | FIXME("stdio handle closed, need proper conversion\n" ); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1386 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1387 | return HFILE_ERROR16; |
| 1388 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1389 | if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile]) |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1390 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 1391 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1392 | return HFILE_ERROR16; |
| 1393 | } |
Alexandre Julliard | 231674d | 2000-08-09 22:30:18 +0000 | [diff] [blame] | 1394 | TRACE("%d (handle32=%d)\n", hFile, dos_handles[hFile] ); |
| 1395 | CloseHandle( dos_handles[hFile] ); |
| 1396 | dos_handles[hFile] = 0; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 1397 | return 0; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1402 | * _lclose (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1403 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1404 | HFILE WINAPI _lclose( HFILE hFile ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1405 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1406 | TRACE("handle %d\n", hFile ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1407 | return CloseHandle( hFile ) ? 0 : HFILE_ERROR; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
Moshe Vainer | 0ea089b | 1999-11-10 19:51:01 +0000 | [diff] [blame] | 1410 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1411 | * GetOverlappedResult (KERNEL32.@) |
Mike McCormack | ad72e71 | 2000-12-29 19:44:18 +0000 | [diff] [blame] | 1412 | * |
| 1413 | * Check the result of an Asynchronous data transfer from a file. |
| 1414 | * |
| 1415 | * RETURNS |
| 1416 | * TRUE on success |
| 1417 | * FALSE on failure |
| 1418 | * |
Francois Gouget | 3bb9a36 | 2001-10-22 19:04:32 +0000 | [diff] [blame] | 1419 | * If successful (and relevant) lpTransferred will hold the number of |
| 1420 | * bytes transferred during the async operation. |
Mike McCormack | ad72e71 | 2000-12-29 19:44:18 +0000 | [diff] [blame] | 1421 | * |
| 1422 | * BUGS |
| 1423 | * |
| 1424 | * Currently only works for WaitCommEvent, ReadFile, WriteFile |
| 1425 | * with communications ports. |
| 1426 | * |
Moshe Vainer | 0ea089b | 1999-11-10 19:51:01 +0000 | [diff] [blame] | 1427 | */ |
Mike McCormack | ad72e71 | 2000-12-29 19:44:18 +0000 | [diff] [blame] | 1428 | BOOL WINAPI GetOverlappedResult( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 1429 | HANDLE hFile, /* [in] handle of file to check on */ |
| 1430 | LPOVERLAPPED lpOverlapped, /* [in/out] pointer to overlapped */ |
Francois Gouget | 3bb9a36 | 2001-10-22 19:04:32 +0000 | [diff] [blame] | 1431 | LPDWORD lpTransferred, /* [in/out] number of bytes transferred */ |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 1432 | BOOL bWait /* [in] wait for the transfer to complete ? */ |
Mike McCormack | ad72e71 | 2000-12-29 19:44:18 +0000 | [diff] [blame] | 1433 | ) { |
| 1434 | DWORD r; |
| 1435 | |
| 1436 | TRACE("(%d %p %p %x)\n", hFile, lpOverlapped, lpTransferred, bWait); |
| 1437 | |
| 1438 | if(lpOverlapped==NULL) |
| 1439 | { |
| 1440 | ERR("lpOverlapped was null\n"); |
| 1441 | return FALSE; |
| 1442 | } |
| 1443 | if(!lpOverlapped->hEvent) |
| 1444 | { |
| 1445 | ERR("lpOverlapped->hEvent was null\n"); |
| 1446 | return FALSE; |
| 1447 | } |
| 1448 | |
| 1449 | do { |
| 1450 | TRACE("waiting on %p\n",lpOverlapped); |
| 1451 | r = WaitForSingleObjectEx(lpOverlapped->hEvent, bWait?INFINITE:0, TRUE); |
| 1452 | TRACE("wait on %p returned %ld\n",lpOverlapped,r); |
| 1453 | } while (r==STATUS_USER_APC); |
| 1454 | |
| 1455 | if(lpTransferred) |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 1456 | *lpTransferred = lpOverlapped->InternalHigh; |
Mike McCormack | ad72e71 | 2000-12-29 19:44:18 +0000 | [diff] [blame] | 1457 | |
Martin Wilck | e0587d4 | 2002-04-17 16:46:06 +0000 | [diff] [blame] | 1458 | SetLastError ( lpOverlapped->Internal == STATUS_PENDING ? |
Martin Wilck | af16c98 | 2002-04-25 21:34:24 +0000 | [diff] [blame] | 1459 | ERROR_IO_INCOMPLETE : RtlNtStatusToDosError ( lpOverlapped->Internal ) ); |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1460 | |
Mike McCormack | ad72e71 | 2000-12-29 19:44:18 +0000 | [diff] [blame] | 1461 | return (r==WAIT_OBJECT_0); |
Moshe Vainer | 0ea089b | 1999-11-10 19:51:01 +0000 | [diff] [blame] | 1462 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1463 | |
Mike McCormack | 6f011c0 | 2001-12-20 00:07:05 +0000 | [diff] [blame] | 1464 | /*********************************************************************** |
Mike McCormack | b473a0f | 2001-08-22 18:02:39 +0000 | [diff] [blame] | 1465 | * CancelIo (KERNEL32.@) |
| 1466 | */ |
| 1467 | BOOL WINAPI CancelIo(HANDLE handle) |
| 1468 | { |
Mike McCormack | de339f3 | 2002-01-07 18:06:59 +0000 | [diff] [blame] | 1469 | async_private *ovp,*t; |
| 1470 | |
| 1471 | TRACE("handle = %x\n",handle); |
| 1472 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1473 | for (ovp = NtCurrentTeb()->pending_list; ovp; ovp = t) |
Mike McCormack | de339f3 | 2002-01-07 18:06:59 +0000 | [diff] [blame] | 1474 | { |
| 1475 | t = ovp->next; |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1476 | if ( ovp->handle == handle ) |
| 1477 | cancel_async ( ovp ); |
Mike McCormack | de339f3 | 2002-01-07 18:06:59 +0000 | [diff] [blame] | 1478 | } |
| 1479 | WaitForMultipleObjectsEx(0,NULL,FALSE,1,TRUE); |
| 1480 | return TRUE; |
Mike McCormack | b473a0f | 2001-08-22 18:02:39 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /*********************************************************************** |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1484 | * FILE_AsyncReadService (INTERNAL) |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1485 | * |
| 1486 | * This function is called while the client is waiting on the |
| 1487 | * server, so we can't make any server calls here. |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1488 | */ |
Mike McCormack | 6f011c0 | 2001-12-20 00:07:05 +0000 | [diff] [blame] | 1489 | static void FILE_AsyncReadService(async_private *ovp) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1490 | { |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1491 | async_fileio *fileio = (async_fileio*) ovp; |
| 1492 | LPOVERLAPPED lpOverlapped = fileio->lpOverlapped; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1493 | int result, r; |
Martin Wilck | 718b1b7 | 2002-01-07 21:02:15 +0000 | [diff] [blame] | 1494 | int already = lpOverlapped->InternalHigh; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1495 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1496 | TRACE("%p %p\n", lpOverlapped, fileio->buffer ); |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1497 | |
| 1498 | /* check to see if the data is ready (non-blocking) */ |
Martin Wilck | 718b1b7 | 2002-01-07 21:02:15 +0000 | [diff] [blame] | 1499 | |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1500 | if ( fileio->fd_type == FD_TYPE_SOCKET ) |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1501 | result = read (ovp->fd, &fileio->buffer[already], fileio->count - already); |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1502 | else |
| 1503 | { |
| 1504 | result = pread (ovp->fd, &fileio->buffer[already], fileio->count - already, |
| 1505 | OVERLAPPED_OFFSET (lpOverlapped) + already); |
| 1506 | if ((result < 0) && (errno == ESPIPE)) |
| 1507 | result = read (ovp->fd, &fileio->buffer[already], fileio->count - already); |
| 1508 | } |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1509 | |
| 1510 | if ( (result<0) && ((errno == EAGAIN) || (errno == EINTR))) |
| 1511 | { |
| 1512 | TRACE("Deferred read %d\n",errno); |
| 1513 | r = STATUS_PENDING; |
| 1514 | goto async_end; |
| 1515 | } |
| 1516 | |
| 1517 | /* check to see if the transfer is complete */ |
| 1518 | if(result<0) |
| 1519 | { |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1520 | r = FILE_GetNtStatus (); |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1521 | goto async_end; |
| 1522 | } |
| 1523 | |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 1524 | lpOverlapped->InternalHigh += result; |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1525 | TRACE("read %d more bytes %ld/%d so far\n",result,lpOverlapped->InternalHigh,fileio->count); |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1526 | |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1527 | if(lpOverlapped->InternalHigh >= fileio->count || fileio->fd_type == FD_TYPE_SOCKET ) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1528 | r = STATUS_SUCCESS; |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1529 | else |
| 1530 | r = STATUS_PENDING; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1531 | |
| 1532 | async_end: |
| 1533 | lpOverlapped->Internal = r; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1534 | } |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1535 | |
Mike McCormack | ea4f32c | 2001-10-17 17:45:11 +0000 | [diff] [blame] | 1536 | /*********************************************************************** |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1537 | * FILE_ReadFileEx (INTERNAL) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1538 | */ |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1539 | static BOOL FILE_ReadFileEx(HANDLE hFile, LPVOID buffer, DWORD bytesToRead, |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1540 | LPOVERLAPPED overlapped, |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1541 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, |
| 1542 | HANDLE hEvent) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1543 | { |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1544 | async_fileio *ovp; |
Mike McCormack | 6f011c0 | 2001-12-20 00:07:05 +0000 | [diff] [blame] | 1545 | int fd; |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1546 | int flags; |
| 1547 | enum fd_type type; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1548 | |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1549 | TRACE("file %d to buf %p num %ld %p func %p\n", |
| 1550 | hFile, buffer, bytesToRead, overlapped, lpCompletionRoutine); |
| 1551 | |
Mike McCormack | 9119543 | 2002-01-01 01:11:32 +0000 | [diff] [blame] | 1552 | /* check that there is an overlapped struct */ |
| 1553 | if (overlapped==NULL) |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1554 | { |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1555 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1556 | return FALSE; |
| 1557 | } |
| 1558 | |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1559 | fd = FILE_GetUnixHandleType ( hFile, GENERIC_READ, &type, &flags); |
| 1560 | if ( fd < 0 ) |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1561 | { |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1562 | WARN ( "Couldn't get FD\n" ); |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1563 | return FALSE; |
| 1564 | } |
| 1565 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1566 | ovp = (async_fileio*) HeapAlloc(GetProcessHeap(), 0, sizeof (async_fileio)); |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1567 | if(!ovp) |
| 1568 | { |
| 1569 | TRACE("HeapAlloc Failed\n"); |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1570 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1571 | goto error; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1572 | } |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1573 | |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1574 | ovp->async.ops = ( lpCompletionRoutine ? &fileio_async_ops : &fileio_nocomp_async_ops ); |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1575 | ovp->async.handle = hFile; |
| 1576 | ovp->async.fd = fd; |
| 1577 | ovp->async.type = ASYNC_TYPE_READ; |
| 1578 | ovp->async.func = FILE_AsyncReadService; |
| 1579 | ovp->async.event = hEvent; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1580 | ovp->lpOverlapped = overlapped; |
Mike McCormack | e61ad3a | 2001-07-12 22:29:41 +0000 | [diff] [blame] | 1581 | ovp->count = bytesToRead; |
| 1582 | ovp->completion_func = lpCompletionRoutine; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1583 | ovp->buffer = buffer; |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1584 | ovp->fd_type = type; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1585 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1586 | return !register_new_async (&ovp->async); |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1587 | |
| 1588 | error: |
| 1589 | close (fd); |
| 1590 | return FALSE; |
| 1591 | |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1592 | } |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1593 | |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1594 | /*********************************************************************** |
| 1595 | * ReadFileEx (KERNEL32.@) |
| 1596 | */ |
| 1597 | BOOL WINAPI ReadFileEx(HANDLE hFile, LPVOID buffer, DWORD bytesToRead, |
| 1598 | LPOVERLAPPED overlapped, |
| 1599 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) |
| 1600 | { |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1601 | overlapped->InternalHigh = 0; |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1602 | return FILE_ReadFileEx(hFile,buffer,bytesToRead,overlapped,lpCompletionRoutine, INVALID_HANDLE_VALUE); |
Mike McCormack | 27cf4a4 | 2001-12-19 18:48:29 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | static BOOL FILE_TimeoutRead(HANDLE hFile, LPVOID buffer, DWORD bytesToRead, LPDWORD bytesRead) |
| 1606 | { |
| 1607 | OVERLAPPED ov; |
| 1608 | BOOL r = FALSE; |
| 1609 | |
| 1610 | TRACE("%d %p %ld %p\n", hFile, buffer, bytesToRead, bytesRead ); |
| 1611 | |
| 1612 | ZeroMemory(&ov, sizeof (OVERLAPPED)); |
| 1613 | if(STATUS_SUCCESS==NtCreateEvent(&ov.hEvent, SYNCHRONIZE, NULL, 0, 0)) |
| 1614 | { |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1615 | if(FILE_ReadFileEx(hFile, buffer, bytesToRead, &ov, NULL, ov.hEvent)) |
Mike McCormack | 27cf4a4 | 2001-12-19 18:48:29 +0000 | [diff] [blame] | 1616 | { |
| 1617 | r = GetOverlappedResult(hFile, &ov, bytesRead, TRUE); |
| 1618 | } |
| 1619 | } |
| 1620 | CloseHandle(ov.hEvent); |
| 1621 | return r; |
| 1622 | } |
| 1623 | |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1624 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1625 | * ReadFile (KERNEL32.@) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1626 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1627 | BOOL WINAPI ReadFile( HANDLE hFile, LPVOID buffer, DWORD bytesToRead, |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1628 | LPDWORD bytesRead, LPOVERLAPPED overlapped ) |
| 1629 | { |
Alexandre Julliard | 8d1550d | 2002-03-23 18:48:12 +0000 | [diff] [blame] | 1630 | int unix_handle, result, flags; |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1631 | enum fd_type type; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1632 | |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1633 | TRACE("%d %p %ld %p %p\n", hFile, buffer, bytesToRead, |
| 1634 | bytesRead, overlapped ); |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1635 | |
| 1636 | if (bytesRead) *bytesRead = 0; /* Do this before anything else */ |
| 1637 | if (!bytesToRead) return TRUE; |
| 1638 | |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1639 | unix_handle = FILE_GetUnixHandleType( hFile, GENERIC_READ, &type, &flags ); |
Mike McCormack | 9e1fc62 | 2001-10-10 20:26:58 +0000 | [diff] [blame] | 1640 | |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1641 | if (flags & FD_FLAG_OVERLAPPED) |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1642 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1643 | if (unix_handle == -1) return FALSE; |
Mike McCormack | 9119543 | 2002-01-01 01:11:32 +0000 | [diff] [blame] | 1644 | if ( (overlapped==NULL) || NtResetEvent( overlapped->hEvent, NULL ) ) |
Mike McCormack | 9e1fc62 | 2001-10-10 20:26:58 +0000 | [diff] [blame] | 1645 | { |
Mike McCormack | 9119543 | 2002-01-01 01:11:32 +0000 | [diff] [blame] | 1646 | TRACE("Overlapped not specified or invalid event flag\n"); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1647 | close(unix_handle); |
Mike McCormack | 9e1fc62 | 2001-10-10 20:26:58 +0000 | [diff] [blame] | 1648 | SetLastError(ERROR_INVALID_PARAMETER); |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1649 | return FALSE; |
Mike McCormack | 9e1fc62 | 2001-10-10 20:26:58 +0000 | [diff] [blame] | 1650 | } |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1651 | |
Martin Wilck | e0587d4 | 2002-04-17 16:46:06 +0000 | [diff] [blame] | 1652 | close(unix_handle); |
| 1653 | overlapped->InternalHigh = 0; |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1654 | |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1655 | if(!FILE_ReadFileEx(hFile, buffer, bytesToRead, overlapped, NULL, overlapped->hEvent)) |
Mike McCormack | 6f030e8 | 2001-08-20 18:01:17 +0000 | [diff] [blame] | 1656 | return FALSE; |
| 1657 | |
Martin Wilck | e0587d4 | 2002-04-17 16:46:06 +0000 | [diff] [blame] | 1658 | if ( !GetOverlappedResult (hFile, overlapped, bytesRead, FALSE) ) |
| 1659 | { |
| 1660 | if ( GetLastError() == ERROR_IO_INCOMPLETE ) |
| 1661 | SetLastError ( ERROR_IO_PENDING ); |
| 1662 | return FALSE; |
| 1663 | } |
| 1664 | |
| 1665 | return TRUE; |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1666 | } |
| 1667 | if (flags & FD_FLAG_TIMEOUT) |
| 1668 | { |
Mike McCormack | 27cf4a4 | 2001-12-19 18:48:29 +0000 | [diff] [blame] | 1669 | close(unix_handle); |
| 1670 | return FILE_TimeoutRead(hFile, buffer, bytesToRead, bytesRead); |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1671 | } |
| 1672 | switch(type) |
| 1673 | { |
Mike McCormack | fc93261 | 2002-03-12 19:24:04 +0000 | [diff] [blame] | 1674 | case FD_TYPE_SMB: |
| 1675 | return SMB_ReadFile(hFile, buffer, bytesToRead, bytesRead, NULL); |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1676 | case FD_TYPE_CONSOLE: |
| 1677 | return ReadConsoleA(hFile, buffer, bytesToRead, bytesRead, NULL); |
Mike McCormack | 27cf4a4 | 2001-12-19 18:48:29 +0000 | [diff] [blame] | 1678 | |
Mike McCormack | 9e1fc62 | 2001-10-10 20:26:58 +0000 | [diff] [blame] | 1679 | default: |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1680 | /* normal unix files */ |
| 1681 | if (unix_handle == -1) |
| 1682 | return FALSE; |
| 1683 | if (overlapped) |
| 1684 | { |
| 1685 | close(unix_handle); |
| 1686 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1687 | return FALSE; |
| 1688 | } |
| 1689 | break; |
Mike McCormack | 9e1fc62 | 2001-10-10 20:26:58 +0000 | [diff] [blame] | 1690 | } |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1691 | |
| 1692 | /* code for synchronous reads */ |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1693 | while ((result = read( unix_handle, buffer, bytesToRead )) == -1) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1694 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1695 | if ((errno == EAGAIN) || (errno == EINTR)) continue; |
| 1696 | if ((errno == EFAULT) && !IsBadWritePtr( buffer, bytesToRead )) continue; |
| 1697 | FILE_SetDosError(); |
| 1698 | break; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1699 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1700 | close( unix_handle ); |
| 1701 | if (result == -1) return FALSE; |
| 1702 | if (bytesRead) *bytesRead = result; |
| 1703 | return TRUE; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1706 | |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1707 | /*********************************************************************** |
| 1708 | * FILE_AsyncWriteService (INTERNAL) |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1709 | * |
| 1710 | * This function is called while the client is waiting on the |
| 1711 | * server, so we can't make any server calls here. |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1712 | */ |
Mike McCormack | 6f011c0 | 2001-12-20 00:07:05 +0000 | [diff] [blame] | 1713 | static void FILE_AsyncWriteService(struct async_private *ovp) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1714 | { |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1715 | async_fileio *fileio = (async_fileio *) ovp; |
| 1716 | LPOVERLAPPED lpOverlapped = fileio->lpOverlapped; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1717 | int result, r; |
Martin Wilck | 718b1b7 | 2002-01-07 21:02:15 +0000 | [diff] [blame] | 1718 | int already = lpOverlapped->InternalHigh; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1719 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1720 | TRACE("(%p %p)\n",lpOverlapped,fileio->buffer); |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1721 | |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1722 | /* write some data (non-blocking) */ |
Martin Wilck | 718b1b7 | 2002-01-07 21:02:15 +0000 | [diff] [blame] | 1723 | |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1724 | if ( fileio->fd_type == FD_TYPE_SOCKET ) |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1725 | result = write(ovp->fd, &fileio->buffer[already], fileio->count - already); |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1726 | else |
| 1727 | { |
| 1728 | result = pwrite(ovp->fd, &fileio->buffer[already], fileio->count - already, |
| 1729 | OVERLAPPED_OFFSET (lpOverlapped) + already); |
| 1730 | if ((result < 0) && (errno == ESPIPE)) |
| 1731 | result = write(ovp->fd, &fileio->buffer[already], fileio->count - already); |
| 1732 | } |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1733 | |
| 1734 | if ( (result<0) && ((errno == EAGAIN) || (errno == EINTR))) |
| 1735 | { |
| 1736 | r = STATUS_PENDING; |
| 1737 | goto async_end; |
| 1738 | } |
| 1739 | |
| 1740 | /* check to see if the transfer is complete */ |
| 1741 | if(result<0) |
| 1742 | { |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1743 | r = FILE_GetNtStatus (); |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1744 | goto async_end; |
| 1745 | } |
| 1746 | |
Mike McCormack | eb3e38e | 2001-01-12 19:57:38 +0000 | [diff] [blame] | 1747 | lpOverlapped->InternalHigh += result; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1748 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1749 | TRACE("wrote %d more bytes %ld/%d so far\n",result,lpOverlapped->InternalHigh,fileio->count); |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1750 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1751 | if(lpOverlapped->InternalHigh < fileio->count) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1752 | r = STATUS_PENDING; |
| 1753 | else |
| 1754 | r = STATUS_SUCCESS; |
| 1755 | |
| 1756 | async_end: |
| 1757 | lpOverlapped->Internal = r; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1758 | } |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1759 | |
| 1760 | /*********************************************************************** |
Alexandre Julliard | 45342a3 | 2002-01-21 17:37:24 +0000 | [diff] [blame] | 1761 | * FILE_WriteFileEx |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1762 | */ |
Alexandre Julliard | 45342a3 | 2002-01-21 17:37:24 +0000 | [diff] [blame] | 1763 | static BOOL FILE_WriteFileEx(HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, |
| 1764 | LPOVERLAPPED overlapped, |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1765 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, |
| 1766 | HANDLE hEvent) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1767 | { |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1768 | async_fileio *ovp; |
| 1769 | int fd; |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1770 | int flags; |
| 1771 | enum fd_type type; |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1772 | |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1773 | TRACE("file %d to buf %p num %ld %p func %p handle %d\n", |
| 1774 | hFile, buffer, bytesToWrite, overlapped, lpCompletionRoutine, hEvent); |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1775 | |
Mike McCormack | 9119543 | 2002-01-01 01:11:32 +0000 | [diff] [blame] | 1776 | if (overlapped == NULL) |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1777 | { |
| 1778 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1779 | return FALSE; |
| 1780 | } |
| 1781 | |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1782 | fd = FILE_GetUnixHandleType ( hFile, GENERIC_WRITE, &type, &flags ); |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1783 | if ( fd < 0 ) |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1784 | { |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1785 | TRACE( "Couldn't get FD\n" ); |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1786 | return FALSE; |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1787 | } |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1788 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1789 | ovp = (async_fileio*) HeapAlloc(GetProcessHeap(), 0, sizeof (async_fileio)); |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1790 | if(!ovp) |
| 1791 | { |
| 1792 | TRACE("HeapAlloc Failed\n"); |
| 1793 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1794 | goto error; |
Mike McCormack | a38e5e5 | 2001-07-08 20:29:26 +0000 | [diff] [blame] | 1795 | } |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1796 | |
Martin Wilck | ef79c38e | 2002-04-23 19:27:51 +0000 | [diff] [blame] | 1797 | ovp->async.ops = ( lpCompletionRoutine ? &fileio_async_ops : &fileio_nocomp_async_ops ); |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1798 | ovp->async.handle = hFile; |
Martin Wilck | ef79c38e | 2002-04-23 19:27:51 +0000 | [diff] [blame] | 1799 | ovp->async.fd = fd; |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1800 | ovp->async.type = ASYNC_TYPE_WRITE; |
| 1801 | ovp->async.func = FILE_AsyncWriteService; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1802 | ovp->lpOverlapped = overlapped; |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1803 | ovp->async.event = hEvent; |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1804 | ovp->buffer = (LPVOID) buffer; |
Mike McCormack | e61ad3a | 2001-07-12 22:29:41 +0000 | [diff] [blame] | 1805 | ovp->count = bytesToWrite; |
| 1806 | ovp->completion_func = lpCompletionRoutine; |
Martin Wilck | 9ca4285 | 2002-04-25 22:58:59 +0000 | [diff] [blame] | 1807 | ovp->fd_type = type; |
Mike McCormack | 6f011c0 | 2001-12-20 00:07:05 +0000 | [diff] [blame] | 1808 | |
Martin Wilck | 2b47fb3 | 2002-04-05 22:53:57 +0000 | [diff] [blame] | 1809 | return !register_new_async (&ovp->async); |
Martin Wilck | 08867f7 | 2002-04-14 19:34:57 +0000 | [diff] [blame] | 1810 | |
| 1811 | error: |
| 1812 | close (fd); |
| 1813 | return FALSE; |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1814 | } |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1815 | |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1816 | /*********************************************************************** |
| 1817 | * WriteFileEx (KERNEL32.@) |
| 1818 | */ |
| 1819 | BOOL WINAPI WriteFileEx(HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, |
| 1820 | LPOVERLAPPED overlapped, |
| 1821 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) |
| 1822 | { |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1823 | overlapped->InternalHigh = 0; |
| 1824 | |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1825 | return FILE_WriteFileEx(hFile, buffer, bytesToWrite, overlapped, lpCompletionRoutine, INVALID_HANDLE_VALUE); |
Mike McCormack | 838a361 | 2001-07-02 18:56:01 +0000 | [diff] [blame] | 1826 | } |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1827 | |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1828 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1829 | * WriteFile (KERNEL32.@) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1830 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1831 | BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1832 | LPDWORD bytesWritten, LPOVERLAPPED overlapped ) |
| 1833 | { |
Alexandre Julliard | 8d1550d | 2002-03-23 18:48:12 +0000 | [diff] [blame] | 1834 | int unix_handle, result, flags; |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1835 | enum fd_type type; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1836 | |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1837 | TRACE("%d %p %ld %p %p\n", hFile, buffer, bytesToWrite, |
| 1838 | bytesWritten, overlapped ); |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1839 | |
| 1840 | if (bytesWritten) *bytesWritten = 0; /* Do this before anything else */ |
| 1841 | if (!bytesToWrite) return TRUE; |
| 1842 | |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1843 | unix_handle = FILE_GetUnixHandleType( hFile, GENERIC_WRITE, &type, &flags ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1844 | |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1845 | if (flags & FD_FLAG_OVERLAPPED) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1846 | { |
Mike McCormack | 9119543 | 2002-01-01 01:11:32 +0000 | [diff] [blame] | 1847 | if (unix_handle == -1) return FALSE; |
| 1848 | if ( (overlapped==NULL) || NtResetEvent( overlapped->hEvent, NULL ) ) |
| 1849 | { |
| 1850 | TRACE("Overlapped not specified or invalid event flag\n"); |
| 1851 | close(unix_handle); |
| 1852 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1853 | return FALSE; |
| 1854 | } |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1855 | |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1856 | close(unix_handle); |
Martin Wilck | e0587d4 | 2002-04-17 16:46:06 +0000 | [diff] [blame] | 1857 | overlapped->InternalHigh = 0; |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1858 | |
Mike McCormack | 4a6b990 | 2002-03-11 01:19:29 +0000 | [diff] [blame] | 1859 | if(!FILE_WriteFileEx(hFile, buffer, bytesToWrite, overlapped, NULL, overlapped->hEvent)) |
Mike McCormack | 99a5cfe | 2002-01-07 18:11:28 +0000 | [diff] [blame] | 1860 | return FALSE; |
| 1861 | |
Martin Wilck | e0587d4 | 2002-04-17 16:46:06 +0000 | [diff] [blame] | 1862 | if ( !GetOverlappedResult (hFile, overlapped, bytesWritten, FALSE) ) |
| 1863 | { |
| 1864 | if ( GetLastError() == ERROR_IO_INCOMPLETE ) |
| 1865 | SetLastError ( ERROR_IO_PENDING ); |
| 1866 | return FALSE; |
| 1867 | } |
| 1868 | |
| 1869 | return TRUE; |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1870 | } |
Mike McCormack | 9119543 | 2002-01-01 01:11:32 +0000 | [diff] [blame] | 1871 | |
Martin Wilck | 88cd32b | 2002-01-09 20:30:51 +0000 | [diff] [blame] | 1872 | switch(type) |
| 1873 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1874 | case FD_TYPE_CONSOLE: |
| 1875 | TRACE("%d %s %ld %p %p\n", hFile, debugstr_an(buffer, bytesToWrite), bytesToWrite, |
| 1876 | bytesWritten, overlapped ); |
| 1877 | return WriteConsoleA(hFile, buffer, bytesToWrite, bytesWritten, NULL); |
| 1878 | default: |
| 1879 | if (unix_handle == -1) |
| 1880 | return FALSE; |
| 1881 | } |
Mike McCormack | f21aac0 | 2001-01-10 22:45:03 +0000 | [diff] [blame] | 1882 | |
| 1883 | /* synchronous file write */ |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1884 | while ((result = write( unix_handle, buffer, bytesToWrite )) == -1) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1885 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1886 | if ((errno == EAGAIN) || (errno == EINTR)) continue; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 1887 | if ((errno == EFAULT) && !IsBadReadPtr( buffer, bytesToWrite )) continue; |
Gerard Patel | 8f3c0a3 | 1999-06-27 15:26:37 +0000 | [diff] [blame] | 1888 | if (errno == ENOSPC) |
| 1889 | SetLastError( ERROR_DISK_FULL ); |
| 1890 | else |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1891 | FILE_SetDosError(); |
| 1892 | break; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1893 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 1894 | close( unix_handle ); |
| 1895 | if (result == -1) return FALSE; |
| 1896 | if (bytesWritten) *bytesWritten = result; |
| 1897 | return TRUE; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
Michael McCormack | 1c32a46 | 2001-03-22 20:09:34 +0000 | [diff] [blame] | 1900 | |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1901 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1902 | * _hread (KERNEL.349) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1903 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1904 | LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1905 | { |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1906 | LONG maxlen; |
| 1907 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1908 | TRACE("%d %08lx %ld\n", |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1909 | hFile, (DWORD)buffer, count ); |
| 1910 | |
| 1911 | /* Some programs pass a count larger than the allocated buffer */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1912 | maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1913 | if (count > maxlen) count = maxlen; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 1914 | return _lread(DosFileHandleToWin32Handle(hFile), MapSL(buffer), count ); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1919 | * _lread (KERNEL.82) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1920 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1921 | UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1922 | { |
| 1923 | return (UINT16)WIN16_hread( hFile, buffer, (LONG)count ); |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1928 | * _lread (KERNEL32.@) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1929 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1930 | UINT WINAPI _lread( HFILE handle, LPVOID buffer, UINT count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1931 | { |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 1932 | DWORD result; |
| 1933 | if (!ReadFile( handle, buffer, count, &result, NULL )) return -1; |
| 1934 | return result; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | |
| 1938 | /*********************************************************************** |
| 1939 | * _lread16 (KERNEL.82) |
| 1940 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1941 | UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 1942 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1943 | return (UINT16)_lread(DosFileHandleToWin32Handle(hFile), buffer, (LONG)count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | |
| 1947 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1948 | * _lcreat (KERNEL.83) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1949 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1950 | HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1951 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 1952 | return Win32HandleToDosFileHandle( _lcreat( path, attr ) ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | |
| 1956 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1957 | * _lcreat (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1958 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1959 | HFILE WINAPI _lcreat( LPCSTR path, INT attr ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1960 | { |
Alexandre Julliard | d5240f1 | 1999-04-03 13:54:51 +0000 | [diff] [blame] | 1961 | /* Mask off all flags not explicitly allowed by the doc */ |
| 1962 | attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1963 | TRACE("%s %02x\n", path, attr ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1964 | return CreateFileA( path, GENERIC_READ | GENERIC_WRITE, |
Alexandre Julliard | d5240f1 | 1999-04-03 13:54:51 +0000 | [diff] [blame] | 1965 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 1966 | CREATE_ALWAYS, attr, 0 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1971 | * SetFilePointer (KERNEL32.@) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1972 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1973 | DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1974 | DWORD method ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1975 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1976 | DWORD ret = 0xffffffff; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1977 | |
Marcus Meissner | 3f1ed52 | 2001-05-14 20:09:37 +0000 | [diff] [blame] | 1978 | TRACE("handle %d offset %ld high %ld origin %ld\n", |
| 1979 | hFile, distance, highword?*highword:0, method ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1980 | |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 1981 | SERVER_START_REQ( set_file_pointer ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1982 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1983 | req->handle = hFile; |
| 1984 | req->low = distance; |
| 1985 | req->high = highword ? *highword : (distance >= 0) ? 0 : -1; |
| 1986 | /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */ |
| 1987 | req->whence = method; |
| 1988 | SetLastError( 0 ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1989 | if (!wine_server_call_err( req )) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1990 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1991 | ret = reply->new_low; |
| 1992 | if (highword) *highword = reply->new_high; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | SERVER_END_REQ; |
| 1996 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | |
| 2000 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2001 | * _llseek (KERNEL.84) |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 2002 | * |
| 2003 | * FIXME: |
| 2004 | * Seeking before the start of the file should be allowed for _llseek16, |
| 2005 | * but cause subsequent I/O operations to fail (cf. interrupt list) |
| 2006 | * |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2007 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2008 | LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2009 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 2010 | return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | |
| 2014 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2015 | * _llseek (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2016 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2017 | LONG WINAPI _llseek( HFILE hFile, LONG lOffset, INT nOrigin ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2018 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2019 | return SetFilePointer( hFile, lOffset, NULL, nOrigin ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | |
| 2023 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2024 | * _lopen (KERNEL.85) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2025 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2026 | HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2027 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 2028 | return Win32HandleToDosFileHandle( _lopen( path, mode ) ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | |
| 2032 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2033 | * _lopen (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2034 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2035 | HFILE WINAPI _lopen( LPCSTR path, INT mode ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2036 | { |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 2037 | DWORD access, sharing; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2038 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2039 | TRACE("('%s',%04x)\n", path, mode ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 2040 | FILE_ConvertOFMode( mode, &access, &sharing ); |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 2041 | return CreateFileA( path, access, sharing, NULL, OPEN_EXISTING, 0, 0 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | |
| 2045 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2046 | * _lwrite (KERNEL.86) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2047 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2048 | UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2049 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 2050 | return (UINT16)_hwrite( DosFileHandleToWin32Handle(hFile), buffer, (LONG)count ); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2054 | * _lwrite (KERNEL32.@) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 2055 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2056 | UINT WINAPI _lwrite( HFILE hFile, LPCSTR buffer, UINT count ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 2057 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2058 | return (UINT)_hwrite( hFile, buffer, (LONG)count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | |
| 2062 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2063 | * _hread16 (KERNEL.349) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2064 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2065 | LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2066 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 2067 | return _lread( DosFileHandleToWin32Handle(hFile), buffer, count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2072 | * _hread (KERNEL32.@) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2073 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2074 | LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2075 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2076 | return _lread( hFile, buffer, count ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | |
| 2080 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2081 | * _hwrite (KERNEL.350) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2082 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2083 | LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2084 | { |
Alexandre Julliard | 5ce902b | 2000-11-27 21:59:08 +0000 | [diff] [blame] | 2085 | return _hwrite( DosFileHandleToWin32Handle(hFile), buffer, count ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | |
| 2089 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2090 | * _hwrite (KERNEL32.@) |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 2091 | * |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 2092 | * experimentation yields that _lwrite: |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 2093 | * o truncates the file at the current position with |
| 2094 | * a 0 len write |
| 2095 | * o returns 0 on a 0 length write |
| 2096 | * o works with console handles |
| 2097 | * |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2098 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2099 | LONG WINAPI _hwrite( HFILE handle, LPCSTR buffer, LONG count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2100 | { |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 2101 | DWORD result; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2102 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2103 | TRACE("%d %p %ld\n", handle, buffer, count ); |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 2104 | |
| 2105 | if (!count) |
| 2106 | { |
| 2107 | /* Expand or truncate at current position */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2108 | if (!SetEndOfFile( handle )) return HFILE_ERROR; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 2109 | return 0; |
| 2110 | } |
| 2111 | if (!WriteFile( handle, buffer, count, &result, NULL )) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2112 | return HFILE_ERROR; |
Alexandre Julliard | fbe63ad | 1998-12-30 12:10:06 +0000 | [diff] [blame] | 2113 | return result; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | |
| 2117 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2118 | * SetHandleCount (KERNEL.199) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2119 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2120 | UINT16 WINAPI SetHandleCount16( UINT16 count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2121 | { |
Alexandre Julliard | 7d5bc5c | 2001-01-15 20:09:09 +0000 | [diff] [blame] | 2122 | return SetHandleCount( count ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 2123 | } |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 2124 | |
| 2125 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2126 | /************************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2127 | * SetHandleCount (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2128 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2129 | UINT WINAPI SetHandleCount( UINT count ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2130 | { |
Francois Gouget | 6d77d3a | 2000-03-25 21:44:35 +0000 | [diff] [blame] | 2131 | return min( 256, count ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 2135 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2136 | * FlushFileBuffers (KERNEL32.@) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 2137 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2138 | BOOL WINAPI FlushFileBuffers( HANDLE hFile ) |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 2139 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2140 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 2141 | SERVER_START_REQ( flush_file ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2142 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2143 | req->handle = hFile; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2144 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2145 | } |
| 2146 | SERVER_END_REQ; |
| 2147 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | |
| 2151 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2152 | * SetEndOfFile (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2153 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2154 | BOOL WINAPI SetEndOfFile( HANDLE hFile ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2155 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2156 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 2157 | SERVER_START_REQ( truncate_file ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2158 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2159 | req->handle = hFile; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2160 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2161 | } |
| 2162 | SERVER_END_REQ; |
| 2163 | return ret; |
Alexandre Julliard | 339eefc | 1996-06-23 14:56:20 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2168 | * DeleteFile (KERNEL.146) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2169 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2170 | BOOL16 WINAPI DeleteFile16( LPCSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2171 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2172 | return DeleteFileA( path ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | |
| 2176 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2177 | * DeleteFileA (KERNEL32.@) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2178 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2179 | BOOL WINAPI DeleteFileA( LPCSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2180 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2181 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2182 | |
Uwe Bonnes | ef3d022 | 2001-10-02 17:40:33 +0000 | [diff] [blame] | 2183 | if (!path) |
| 2184 | { |
| 2185 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2186 | return FALSE; |
| 2187 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2188 | TRACE("'%s'\n", path ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2189 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 2190 | if (!*path) |
| 2191 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2192 | ERR("Empty path passed\n"); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 2193 | return FALSE; |
| 2194 | } |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 2195 | if (DOSFS_GetDevice( path )) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2196 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2197 | WARN("cannot remove DOS device '%s'!\n", path); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 2198 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2199 | return FALSE; |
| 2200 | } |
| 2201 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2202 | if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE; |
| 2203 | if (unlink( full_name.long_name ) == -1) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2204 | { |
| 2205 | FILE_SetDosError(); |
| 2206 | return FALSE; |
| 2207 | } |
| 2208 | return TRUE; |
| 2209 | } |
| 2210 | |
| 2211 | |
| 2212 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2213 | * DeleteFileW (KERNEL32.@) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2214 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2215 | BOOL WINAPI DeleteFileW( LPCWSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2216 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 2217 | LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2218 | BOOL ret = DeleteFileA( xpath ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 2219 | HeapFree( GetProcessHeap(), 0, xpath ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 2220 | return ret; |
| 2221 | } |
| 2222 | |
| 2223 | |
| 2224 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2225 | * GetFileType (KERNEL32.@) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 2226 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2227 | DWORD WINAPI GetFileType( HANDLE hFile ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 2228 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2229 | DWORD ret = FILE_TYPE_UNKNOWN; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 2230 | SERVER_START_REQ( get_file_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2231 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2232 | req->handle = hFile; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2233 | if (!wine_server_call_err( req )) ret = reply->type; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2234 | } |
| 2235 | SERVER_END_REQ; |
| 2236 | return ret; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 2237 | } |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 2238 | |
| 2239 | |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2240 | /* check if a file name is for an executable file (.exe or .com) */ |
| 2241 | inline static BOOL is_executable( const char *name ) |
| 2242 | { |
| 2243 | int len = strlen(name); |
| 2244 | |
| 2245 | if (len < 4) return FALSE; |
| 2246 | return (!strcasecmp( name + len - 4, ".exe" ) || |
| 2247 | !strcasecmp( name + len - 4, ".com" )); |
| 2248 | } |
| 2249 | |
| 2250 | |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2251 | /*********************************************************************** |
| 2252 | * FILE_AddBootRenameEntry |
| 2253 | * |
| 2254 | * Adds an entry to the registry that is loaded when windows boots and |
| 2255 | * checks if there are some files to be removed or renamed/moved. |
| 2256 | * <fn1> has to be valid and <fn2> may be NULL. If both pointers are |
| 2257 | * non-NULL then the file is moved, otherwise it is deleted. The |
| 2258 | * entry of the registrykey is always appended with two zero |
| 2259 | * terminated strings. If <fn2> is NULL then the second entry is |
| 2260 | * simply a single 0-byte. Otherwise the second filename goes |
| 2261 | * there. The entries are prepended with \??\ before the path and the |
| 2262 | * second filename gets also a '!' as the first character if |
| 2263 | * MOVEFILE_REPLACE_EXISTING is set. After the final string another |
| 2264 | * 0-byte follows to indicate the end of the strings. |
| 2265 | * i.e.: |
| 2266 | * \??\D:\test\file1[0] |
| 2267 | * !\??\D:\test\file1_renamed[0] |
| 2268 | * \??\D:\Test|delete[0] |
| 2269 | * [0] <- file is to be deleted, second string empty |
| 2270 | * \??\D:\test\file2[0] |
| 2271 | * !\??\D:\test\file2_renamed[0] |
| 2272 | * [0] <- indicates end of strings |
| 2273 | * |
| 2274 | * or: |
| 2275 | * \??\D:\test\file1[0] |
| 2276 | * !\??\D:\test\file1_renamed[0] |
| 2277 | * \??\D:\Test|delete[0] |
| 2278 | * [0] <- file is to be deleted, second string empty |
| 2279 | * [0] <- indicates end of strings |
| 2280 | * |
| 2281 | */ |
| 2282 | static BOOL FILE_AddBootRenameEntry( const char *fn1, const char *fn2, DWORD flags ) |
| 2283 | { |
| 2284 | static const char PreString[] = "\\??\\"; |
| 2285 | static const char ValueName[] = "PendingFileRenameOperations"; |
| 2286 | |
| 2287 | BOOL rc = FALSE; |
| 2288 | HKEY Reboot = 0; |
| 2289 | DWORD Type, len1, len2, l; |
| 2290 | DWORD DataSize = 0; |
| 2291 | BYTE *Buffer = NULL; |
| 2292 | |
| 2293 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager", |
| 2294 | &Reboot) != ERROR_SUCCESS) |
| 2295 | { |
| 2296 | WARN("Error creating key for reboot managment [%s]\n", |
| 2297 | "SYSTEM\\CurrentControlSet\\Control\\Session Manager"); |
| 2298 | return FALSE; |
| 2299 | } |
| 2300 | |
| 2301 | l = strlen(PreString); |
| 2302 | len1 = strlen(fn1) + l + 1; |
| 2303 | if (fn2) |
| 2304 | { |
| 2305 | len2 = strlen(fn2) + l + 1; |
| 2306 | if (flags & MOVEFILE_REPLACE_EXISTING) len2++; /* Plus 1 because of the leading '!' */ |
| 2307 | } |
| 2308 | else len2 = 1; /* minimum is the 0 byte for the empty second string */ |
| 2309 | |
| 2310 | /* First we check if the key exists and if so how many bytes it already contains. */ |
| 2311 | if (RegQueryValueExA(Reboot, ValueName, NULL, &Type, NULL, &DataSize) == ERROR_SUCCESS) |
| 2312 | { |
| 2313 | if (Type != REG_MULTI_SZ) goto Quit; |
| 2314 | if (!(Buffer = HeapAlloc( GetProcessHeap(), 0, DataSize + len1 + len2 + 1 ))) goto Quit; |
| 2315 | if (RegQueryValueExA(Reboot, ValueName, NULL, &Type, Buffer, &DataSize) != ERROR_SUCCESS) |
| 2316 | goto Quit; |
| 2317 | if (DataSize) DataSize--; /* remove terminating null (will be added back later) */ |
| 2318 | } |
| 2319 | else |
| 2320 | { |
| 2321 | if (!(Buffer = HeapAlloc( GetProcessHeap(), 0, len1 + len2 + 1 ))) goto Quit; |
| 2322 | DataSize = 0; |
| 2323 | } |
| 2324 | sprintf( Buffer + DataSize, "%s%s", PreString, fn1 ); |
| 2325 | DataSize += len1; |
| 2326 | if (fn2) |
| 2327 | { |
| 2328 | sprintf( Buffer + DataSize, "%s%s%s", |
| 2329 | (flags & MOVEFILE_REPLACE_EXISTING) ? "!" : "", PreString, fn2 ); |
| 2330 | DataSize += len2; |
| 2331 | } |
| 2332 | else Buffer[DataSize++] = 0; |
| 2333 | |
| 2334 | Buffer[DataSize++] = 0; /* add final null */ |
| 2335 | rc = !RegSetValueExA( Reboot, ValueName, 0, REG_MULTI_SZ, Buffer, DataSize ); |
| 2336 | |
| 2337 | Quit: |
| 2338 | if (Reboot) RegCloseKey(Reboot); |
| 2339 | if (Buffer) HeapFree( GetProcessHeap(), 0, Buffer ); |
| 2340 | return(rc); |
| 2341 | } |
| 2342 | |
| 2343 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2344 | /************************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 2345 | * MoveFileExA (KERNEL32.@) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2346 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2347 | BOOL WINAPI MoveFileExA( LPCSTR fn1, LPCSTR fn2, DWORD flag ) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2348 | { |
| 2349 | DOS_FULL_NAME full_name1, full_name2; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2350 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2351 | TRACE("(%s,%s,%04lx)\n", fn1, fn2, flag); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2352 | |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2353 | /* FIXME: <Gerhard W. Gruber>sparhawk@gmx.at |
| 2354 | In case of W9x and lesser this function should return 120 (ERROR_CALL_NOT_IMPLEMENTED) |
| 2355 | to be really compatible. Most programs wont have any problems though. In case |
| 2356 | you encounter one, this is what you should return here. I don't know what's up |
| 2357 | with NT 3.5. Is this function available there or not? |
| 2358 | Does anybody really care about 3.5? :) |
| 2359 | */ |
| 2360 | |
| 2361 | /* Filename1 has to be always set to a valid path. Filename2 may be NULL |
| 2362 | if the source file has to be deleted. |
| 2363 | */ |
Ove Kaaven | 72f4044 | 2001-10-01 20:52:00 +0000 | [diff] [blame] | 2364 | if (!fn1) { |
| 2365 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2366 | return FALSE; |
| 2367 | } |
| 2368 | |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2369 | /* This function has to be run through in order to process the name properly. |
| 2370 | If the BOOTDELAY flag is set, the file doesn't need to exist though. At least |
| 2371 | that is the behaviour on NT 4.0. The operation accepts the filenames as |
| 2372 | they are given but it can't reply with a reasonable returncode. Success |
| 2373 | means in that case success for entering the values into the registry. |
| 2374 | */ |
| 2375 | if(!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) |
| 2376 | { |
| 2377 | if(!(flag & MOVEFILE_DELAY_UNTIL_REBOOT)) |
| 2378 | return FALSE; |
| 2379 | } |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2380 | |
| 2381 | if (fn2) /* !fn2 means delete fn1 */ |
| 2382 | { |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2383 | if (DOSFS_GetFullName( fn2, TRUE, &full_name2 )) |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2384 | { |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2385 | if(!(flag & MOVEFILE_DELAY_UNTIL_REBOOT)) |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2386 | { |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2387 | /* target exists, check if we may overwrite */ |
| 2388 | if (!(flag & MOVEFILE_REPLACE_EXISTING)) |
| 2389 | { |
| 2390 | /* FIXME: Use right error code */ |
| 2391 | SetLastError( ERROR_ACCESS_DENIED ); |
| 2392 | return FALSE; |
| 2393 | } |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2394 | } |
| 2395 | } |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2396 | else |
| 2397 | { |
| 2398 | if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) |
| 2399 | { |
| 2400 | if(!(flag & MOVEFILE_DELAY_UNTIL_REBOOT)) |
| 2401 | return FALSE; |
| 2402 | } |
| 2403 | } |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2404 | |
| 2405 | /* Source name and target path are valid */ |
| 2406 | |
| 2407 | if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) |
| 2408 | { |
| 2409 | /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706) |
| 2410 | Perhaps we should queue these command and execute it |
| 2411 | when exiting... What about using on_exit(2) |
| 2412 | */ |
| 2413 | FIXME("Please move existing file '%s' to file '%s' when Wine has finished\n", |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2414 | fn1, fn2); |
| 2415 | return FILE_AddBootRenameEntry( fn1, fn2, flag ); |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | if (full_name1.drive != full_name2.drive) |
| 2419 | { |
| 2420 | /* use copy, if allowed */ |
| 2421 | if (!(flag & MOVEFILE_COPY_ALLOWED)) |
| 2422 | { |
| 2423 | /* FIXME: Use right error code */ |
| 2424 | SetLastError( ERROR_FILE_EXISTS ); |
| 2425 | return FALSE; |
| 2426 | } |
| 2427 | return CopyFileA( fn1, fn2, !(flag & MOVEFILE_REPLACE_EXISTING) ); |
| 2428 | } |
| 2429 | if (rename( full_name1.long_name, full_name2.long_name ) == -1) |
| 2430 | { |
| 2431 | FILE_SetDosError(); |
| 2432 | return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2433 | } |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2434 | if (is_executable( full_name1.long_name ) != is_executable( full_name2.long_name )) |
| 2435 | { |
| 2436 | struct stat fstat; |
| 2437 | if (stat( full_name2.long_name, &fstat ) != -1) |
| 2438 | { |
| 2439 | if (is_executable( full_name2.long_name )) |
| 2440 | /* set executable bit where read bit is set */ |
| 2441 | fstat.st_mode |= (fstat.st_mode & 0444) >> 2; |
| 2442 | else |
| 2443 | fstat.st_mode &= ~0111; |
| 2444 | chmod( full_name2.long_name, fstat.st_mode ); |
| 2445 | } |
| 2446 | } |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2447 | return TRUE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2448 | } |
| 2449 | else /* fn2 == NULL means delete source */ |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2450 | { |
| 2451 | if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) |
| 2452 | { |
| 2453 | if (flag & MOVEFILE_COPY_ALLOWED) { |
| 2454 | WARN("Illegal flag\n"); |
| 2455 | SetLastError( ERROR_GEN_FAILURE ); |
| 2456 | return FALSE; |
| 2457 | } |
| 2458 | /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706) |
| 2459 | Perhaps we should queue these command and execute it |
| 2460 | when exiting... What about using on_exit(2) |
| 2461 | */ |
Gerhard W. Gruber | 814a3fa | 2002-02-22 21:30:22 +0000 | [diff] [blame] | 2462 | FIXME("Please delete file '%s' when Wine has finished\n", fn1); |
| 2463 | return FILE_AddBootRenameEntry( fn1, NULL, flag ); |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2464 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2465 | |
Alexandre Julliard | 86a7553 | 1999-11-21 02:11:48 +0000 | [diff] [blame] | 2466 | if (unlink( full_name1.long_name ) == -1) |
| 2467 | { |
| 2468 | FILE_SetDosError(); |
| 2469 | return FALSE; |
| 2470 | } |
| 2471 | return TRUE; /* successfully deleted */ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2472 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | /************************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 2476 | * MoveFileExW (KERNEL32.@) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2477 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2478 | BOOL WINAPI MoveFileExW( LPCWSTR fn1, LPCWSTR fn2, DWORD flag ) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2479 | { |
| 2480 | LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 ); |
| 2481 | LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2482 | BOOL res = MoveFileExA( afn1, afn2, flag ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2483 | HeapFree( GetProcessHeap(), 0, afn1 ); |
| 2484 | HeapFree( GetProcessHeap(), 0, afn2 ); |
| 2485 | return res; |
| 2486 | } |
| 2487 | |
| 2488 | |
| 2489 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2490 | * MoveFileA (KERNEL32.@) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2491 | * |
| 2492 | * Move file or directory |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2493 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2494 | BOOL WINAPI MoveFileA( LPCSTR fn1, LPCSTR fn2 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2495 | { |
| 2496 | DOS_FULL_NAME full_name1, full_name2; |
Marcus Meissner | 6bb990f | 2001-05-29 20:55:21 +0000 | [diff] [blame] | 2497 | struct stat fstat; |
Marcus Meissner | 3f1ed52 | 2001-05-14 20:09:37 +0000 | [diff] [blame] | 2498 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2499 | TRACE("(%s,%s)\n", fn1, fn2 ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2500 | |
| 2501 | if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE; |
Marcus Meissner | 242d23e | 2000-08-21 03:18:32 +0000 | [diff] [blame] | 2502 | if (DOSFS_GetFullName( fn2, TRUE, &full_name2 )) { |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2503 | /* The new name must not already exist */ |
Marcus Meissner | 242d23e | 2000-08-21 03:18:32 +0000 | [diff] [blame] | 2504 | SetLastError(ERROR_ALREADY_EXISTS); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2505 | return FALSE; |
Marcus Meissner | 242d23e | 2000-08-21 03:18:32 +0000 | [diff] [blame] | 2506 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2507 | if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2508 | |
| 2509 | if (full_name1.drive == full_name2.drive) /* move */ |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2510 | return MoveFileExA( fn1, fn2, MOVEFILE_COPY_ALLOWED ); |
| 2511 | |
| 2512 | /* copy */ |
| 2513 | if (stat( full_name1.long_name, &fstat )) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2514 | { |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2515 | WARN("Invalid source file %s\n", |
| 2516 | full_name1.long_name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2517 | FILE_SetDosError(); |
| 2518 | return FALSE; |
| 2519 | } |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2520 | if (S_ISDIR(fstat.st_mode)) { |
| 2521 | /* No Move for directories across file systems */ |
| 2522 | /* FIXME: Use right error code */ |
| 2523 | SetLastError( ERROR_GEN_FAILURE ); |
| 2524 | return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2525 | } |
Bernhard Rosenkraenzer | 5dda1f7 | 2001-07-23 18:09:41 +0000 | [diff] [blame] | 2526 | return CopyFileA(fn1, fn2, TRUE); /*fail, if exist */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | |
| 2530 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2531 | * MoveFileW (KERNEL32.@) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2532 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2533 | BOOL WINAPI MoveFileW( LPCWSTR fn1, LPCWSTR fn2 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2534 | { |
| 2535 | LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 ); |
| 2536 | LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2537 | BOOL res = MoveFileA( afn1, afn2 ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2538 | HeapFree( GetProcessHeap(), 0, afn1 ); |
| 2539 | HeapFree( GetProcessHeap(), 0, afn2 ); |
| 2540 | return res; |
| 2541 | } |
| 2542 | |
| 2543 | |
| 2544 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2545 | * CopyFileA (KERNEL32.@) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2546 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2547 | BOOL WINAPI CopyFileA( LPCSTR source, LPCSTR dest, BOOL fail_if_exists ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2548 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2549 | HFILE h1, h2; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2550 | BY_HANDLE_FILE_INFORMATION info; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2551 | UINT count; |
| 2552 | BOOL ret = FALSE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2553 | int mode; |
| 2554 | char buffer[2048]; |
| 2555 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2556 | if ((h1 = _lopen( source, OF_READ )) == HFILE_ERROR) return FALSE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2557 | if (!GetFileInformationByHandle( h1, &info )) |
| 2558 | { |
| 2559 | CloseHandle( h1 ); |
| 2560 | return FALSE; |
| 2561 | } |
| 2562 | mode = (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2563 | 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] | 2564 | fail_if_exists ? CREATE_NEW : CREATE_ALWAYS, |
François Gouget | 4b4f69a | 2001-01-09 20:51:19 +0000 | [diff] [blame] | 2565 | info.dwFileAttributes, h1 )) == INVALID_HANDLE_VALUE) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2566 | { |
| 2567 | CloseHandle( h1 ); |
| 2568 | return FALSE; |
| 2569 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2570 | while ((count = _lread( h1, buffer, sizeof(buffer) )) > 0) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2571 | { |
| 2572 | char *p = buffer; |
| 2573 | while (count > 0) |
| 2574 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2575 | INT res = _lwrite( h2, p, count ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2576 | if (res <= 0) goto done; |
| 2577 | p += res; |
| 2578 | count -= res; |
| 2579 | } |
| 2580 | } |
| 2581 | ret = TRUE; |
| 2582 | done: |
| 2583 | CloseHandle( h1 ); |
| 2584 | CloseHandle( h2 ); |
| 2585 | return ret; |
| 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2590 | * CopyFileW (KERNEL32.@) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2591 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2592 | BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2593 | { |
| 2594 | LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, source ); |
| 2595 | LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, dest ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2596 | BOOL ret = CopyFileA( sourceA, destA, fail_if_exists ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2597 | HeapFree( GetProcessHeap(), 0, sourceA ); |
| 2598 | HeapFree( GetProcessHeap(), 0, destA ); |
| 2599 | return ret; |
| 2600 | } |
| 2601 | |
| 2602 | |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2603 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2604 | * CopyFileExA (KERNEL32.@) |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2605 | * |
| 2606 | * This implementation ignores most of the extra parameters passed-in into |
| 2607 | * the "ex" version of the method and calls the CopyFile method. |
| 2608 | * It will have to be fixed eventually. |
| 2609 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2610 | BOOL WINAPI CopyFileExA(LPCSTR sourceFilename, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2611 | LPCSTR destFilename, |
| 2612 | LPPROGRESS_ROUTINE progressRoutine, |
| 2613 | LPVOID appData, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2614 | LPBOOL cancelFlagPointer, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2615 | DWORD copyFlags) |
| 2616 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2617 | BOOL failIfExists = FALSE; |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2618 | |
| 2619 | /* |
| 2620 | * Interpret the only flag that CopyFile can interpret. |
| 2621 | */ |
| 2622 | if ( (copyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0) |
| 2623 | { |
| 2624 | failIfExists = TRUE; |
| 2625 | } |
| 2626 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2627 | return CopyFileA(sourceFilename, destFilename, failIfExists); |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2631 | * CopyFileExW (KERNEL32.@) |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2632 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2633 | BOOL WINAPI CopyFileExW(LPCWSTR sourceFilename, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2634 | LPCWSTR destFilename, |
| 2635 | LPPROGRESS_ROUTINE progressRoutine, |
| 2636 | LPVOID appData, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2637 | LPBOOL cancelFlagPointer, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2638 | DWORD copyFlags) |
| 2639 | { |
| 2640 | LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, sourceFilename ); |
| 2641 | LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, destFilename ); |
| 2642 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2643 | BOOL ret = CopyFileExA(sourceA, |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 2644 | destA, |
| 2645 | progressRoutine, |
| 2646 | appData, |
| 2647 | cancelFlagPointer, |
| 2648 | copyFlags); |
| 2649 | |
| 2650 | HeapFree( GetProcessHeap(), 0, sourceA ); |
| 2651 | HeapFree( GetProcessHeap(), 0, destA ); |
| 2652 | |
| 2653 | return ret; |
| 2654 | } |
| 2655 | |
| 2656 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 2657 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2658 | * SetFileTime (KERNEL32.@) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 2659 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2660 | BOOL WINAPI SetFileTime( HANDLE hFile, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2661 | const FILETIME *lpCreationTime, |
| 2662 | const FILETIME *lpLastAccessTime, |
| 2663 | const FILETIME *lpLastWriteTime ) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 2664 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2665 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 2666 | SERVER_START_REQ( set_file_time ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2667 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2668 | req->handle = hFile; |
| 2669 | if (lpLastAccessTime) |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 2670 | RtlTimeToSecondsSince1970( lpLastAccessTime, (DWORD *)&req->access_time ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2671 | else |
| 2672 | req->access_time = 0; /* FIXME */ |
| 2673 | if (lpLastWriteTime) |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 2674 | RtlTimeToSecondsSince1970( lpLastWriteTime, (DWORD *)&req->write_time ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2675 | else |
| 2676 | req->write_time = 0; /* FIXME */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2677 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2678 | } |
| 2679 | SERVER_END_REQ; |
| 2680 | return ret; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 2681 | } |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2682 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2683 | |
| 2684 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2685 | * LockFile (KERNEL32.@) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2686 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2687 | BOOL WINAPI LockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2688 | DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh ) |
| 2689 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2690 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 2691 | SERVER_START_REQ( lock_file ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2692 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2693 | req->handle = hFile; |
| 2694 | req->offset_low = dwFileOffsetLow; |
| 2695 | req->offset_high = dwFileOffsetHigh; |
| 2696 | req->count_low = nNumberOfBytesToLockLow; |
| 2697 | req->count_high = nNumberOfBytesToLockHigh; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2698 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2699 | } |
| 2700 | SERVER_END_REQ; |
| 2701 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2704 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2705 | * LockFileEx [KERNEL32.@] |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2706 | * |
| 2707 | * Locks a byte range within an open file for shared or exclusive access. |
| 2708 | * |
| 2709 | * RETURNS |
| 2710 | * success: TRUE |
| 2711 | * failure: FALSE |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2712 | * |
Andreas Mohr | c9cf70d | 2001-01-26 20:40:50 +0000 | [diff] [blame] | 2713 | * NOTES |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2714 | * Per Microsoft docs, the third parameter (reserved) must be set to 0. |
| 2715 | */ |
| 2716 | BOOL WINAPI LockFileEx( HANDLE hFile, DWORD flags, DWORD reserved, |
| 2717 | DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, |
| 2718 | LPOVERLAPPED pOverlapped ) |
| 2719 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2720 | 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] | 2721 | hFile, flags, reserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, |
| 2722 | pOverlapped); |
| 2723 | if (reserved == 0) |
| 2724 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 2725 | else |
| 2726 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2727 | ERR("reserved == %ld: Supposed to be 0??\n", reserved); |
James Juran | e8df90b | 1999-06-05 08:57:37 +0000 | [diff] [blame] | 2728 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2729 | } |
| 2730 | |
| 2731 | return FALSE; |
| 2732 | } |
| 2733 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2734 | |
| 2735 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2736 | * UnlockFile (KERNEL32.@) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2737 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 2738 | BOOL WINAPI UnlockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2739 | DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh ) |
| 2740 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2741 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 2742 | SERVER_START_REQ( unlock_file ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2743 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2744 | req->handle = hFile; |
| 2745 | req->offset_low = dwFileOffsetLow; |
| 2746 | req->offset_high = dwFileOffsetHigh; |
| 2747 | req->count_low = nNumberOfBytesToUnlockLow; |
| 2748 | req->count_high = nNumberOfBytesToUnlockHigh; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2749 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 2750 | } |
| 2751 | SERVER_END_REQ; |
| 2752 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | |
Andreas Mohr | e00114c | 1999-07-03 11:56:07 +0000 | [diff] [blame] | 2756 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2757 | * UnlockFileEx (KERNEL32.@) |
Andreas Mohr | e00114c | 1999-07-03 11:56:07 +0000 | [diff] [blame] | 2758 | */ |
| 2759 | BOOL WINAPI UnlockFileEx( |
| 2760 | HFILE hFile, |
| 2761 | DWORD dwReserved, |
| 2762 | DWORD nNumberOfBytesToUnlockLow, |
| 2763 | DWORD nNumberOfBytesToUnlockHigh, |
| 2764 | LPOVERLAPPED lpOverlapped |
| 2765 | ) |
| 2766 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2767 | 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] | 2768 | hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, |
| 2769 | lpOverlapped); |
| 2770 | if (dwReserved == 0) |
| 2771 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 2772 | else |
| 2773 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2774 | ERR("reserved == %ld: Supposed to be 0??\n", dwReserved); |
Andreas Mohr | e00114c | 1999-07-03 11:56:07 +0000 | [diff] [blame] | 2775 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2776 | } |
| 2777 | |
| 2778 | return FALSE; |
| 2779 | } |
| 2780 | |
| 2781 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2782 | #if 0 |
| 2783 | |
| 2784 | struct DOS_FILE_LOCK { |
| 2785 | struct DOS_FILE_LOCK * next; |
| 2786 | DWORD base; |
| 2787 | DWORD len; |
| 2788 | DWORD processId; |
| 2789 | FILE_OBJECT * dos_file; |
| 2790 | /* char * unix_name;*/ |
| 2791 | }; |
| 2792 | |
| 2793 | typedef struct DOS_FILE_LOCK DOS_FILE_LOCK; |
| 2794 | |
| 2795 | static DOS_FILE_LOCK *locks = NULL; |
| 2796 | static void DOS_RemoveFileLocks(FILE_OBJECT *file); |
| 2797 | |
| 2798 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2799 | /* Locks need to be mirrored because unix file locking is based |
| 2800 | * on the pid. Inside of wine there can be multiple WINE processes |
| 2801 | * that share the same unix pid. |
| 2802 | * Read's and writes should check these locks also - not sure |
| 2803 | * how critical that is at this point (FIXME). |
| 2804 | */ |
| 2805 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2806 | static BOOL DOS_AddLock(FILE_OBJECT *file, struct flock *f) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2807 | { |
| 2808 | DOS_FILE_LOCK *curr; |
| 2809 | DWORD processId; |
| 2810 | |
| 2811 | processId = GetCurrentProcessId(); |
| 2812 | |
| 2813 | /* check if lock overlaps a current lock for the same file */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2814 | #if 0 |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2815 | for (curr = locks; curr; curr = curr->next) { |
| 2816 | if (strcmp(curr->unix_name, file->unix_name) == 0) { |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 2817 | if ((f->l_start == curr->base) && (f->l_len == curr->len)) |
| 2818 | return TRUE;/* region is identic */ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2819 | if ((f->l_start < (curr->base + curr->len)) && |
| 2820 | ((f->l_start + f->l_len) > curr->base)) { |
| 2821 | /* region overlaps */ |
| 2822 | return FALSE; |
| 2823 | } |
| 2824 | } |
| 2825 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2826 | #endif |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2827 | |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2828 | curr = HeapAlloc( GetProcessHeap(), 0, sizeof(DOS_FILE_LOCK) ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2829 | curr->processId = GetCurrentProcessId(); |
| 2830 | curr->base = f->l_start; |
| 2831 | curr->len = f->l_len; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2832 | /* curr->unix_name = HEAP_strdupA( GetProcessHeap(), 0, file->unix_name);*/ |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2833 | curr->next = locks; |
| 2834 | curr->dos_file = file; |
| 2835 | locks = curr; |
| 2836 | return TRUE; |
| 2837 | } |
| 2838 | |
| 2839 | static void DOS_RemoveFileLocks(FILE_OBJECT *file) |
| 2840 | { |
| 2841 | DWORD processId; |
| 2842 | DOS_FILE_LOCK **curr; |
| 2843 | DOS_FILE_LOCK *rem; |
| 2844 | |
| 2845 | processId = GetCurrentProcessId(); |
| 2846 | curr = &locks; |
| 2847 | while (*curr) { |
| 2848 | if ((*curr)->dos_file == file) { |
| 2849 | rem = *curr; |
| 2850 | *curr = (*curr)->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2851 | /* HeapFree( GetProcessHeap(), 0, rem->unix_name );*/ |
| 2852 | HeapFree( GetProcessHeap(), 0, rem ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2853 | } |
| 2854 | else |
| 2855 | curr = &(*curr)->next; |
| 2856 | } |
| 2857 | } |
| 2858 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2859 | static BOOL DOS_RemoveLock(FILE_OBJECT *file, struct flock *f) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2860 | { |
| 2861 | DWORD processId; |
| 2862 | DOS_FILE_LOCK **curr; |
| 2863 | DOS_FILE_LOCK *rem; |
| 2864 | |
| 2865 | processId = GetCurrentProcessId(); |
| 2866 | for (curr = &locks; *curr; curr = &(*curr)->next) { |
| 2867 | if ((*curr)->processId == processId && |
| 2868 | (*curr)->dos_file == file && |
| 2869 | (*curr)->base == f->l_start && |
| 2870 | (*curr)->len == f->l_len) { |
| 2871 | /* this is the same lock */ |
| 2872 | rem = *curr; |
| 2873 | *curr = (*curr)->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 2874 | /* HeapFree( GetProcessHeap(), 0, rem->unix_name );*/ |
| 2875 | HeapFree( GetProcessHeap(), 0, rem ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2876 | return TRUE; |
| 2877 | } |
| 2878 | } |
| 2879 | /* no matching lock found */ |
| 2880 | return FALSE; |
| 2881 | } |
| 2882 | |
| 2883 | |
| 2884 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2885 | * LockFile (KERNEL32.@) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2886 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2887 | BOOL WINAPI LockFile( |
| 2888 | HFILE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh, |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2889 | DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh ) |
| 2890 | { |
| 2891 | struct flock f; |
| 2892 | FILE_OBJECT *file; |
| 2893 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2894 | TRACE("handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n", |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2895 | hFile, dwFileOffsetLow, dwFileOffsetHigh, |
| 2896 | nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh); |
| 2897 | |
| 2898 | if (dwFileOffsetHigh || nNumberOfBytesToLockHigh) { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2899 | FIXME("Unimplemented bytes > 32bits\n"); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2900 | return FALSE; |
| 2901 | } |
| 2902 | |
| 2903 | f.l_start = dwFileOffsetLow; |
| 2904 | f.l_len = nNumberOfBytesToLockLow; |
| 2905 | f.l_whence = SEEK_SET; |
| 2906 | f.l_pid = 0; |
| 2907 | f.l_type = F_WRLCK; |
| 2908 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 2909 | if (!(file = FILE_GetFile(hFile,0,NULL))) return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2910 | |
| 2911 | /* shadow locks internally */ |
| 2912 | if (!DOS_AddLock(file, &f)) { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 2913 | SetLastError( ERROR_LOCK_VIOLATION ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2914 | return FALSE; |
| 2915 | } |
| 2916 | |
| 2917 | /* FIXME: Unix locking commented out for now, doesn't work with Excel */ |
| 2918 | #ifdef USE_UNIX_LOCKS |
| 2919 | if (fcntl(file->unix_handle, F_SETLK, &f) == -1) { |
| 2920 | if (errno == EACCES || errno == EAGAIN) { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 2921 | SetLastError( ERROR_LOCK_VIOLATION ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2922 | } |
| 2923 | else { |
| 2924 | FILE_SetDosError(); |
| 2925 | } |
| 2926 | /* remove our internal copy of the lock */ |
| 2927 | DOS_RemoveLock(file, &f); |
| 2928 | return FALSE; |
| 2929 | } |
| 2930 | #endif |
| 2931 | return TRUE; |
| 2932 | } |
| 2933 | |
| 2934 | |
| 2935 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2936 | * UnlockFile (KERNEL32.@) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2937 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2938 | BOOL WINAPI UnlockFile( |
| 2939 | HFILE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh, |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2940 | DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh ) |
| 2941 | { |
| 2942 | FILE_OBJECT *file; |
| 2943 | struct flock f; |
| 2944 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2945 | TRACE("handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n", |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2946 | hFile, dwFileOffsetLow, dwFileOffsetHigh, |
| 2947 | nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh); |
| 2948 | |
| 2949 | if (dwFileOffsetHigh || nNumberOfBytesToUnlockHigh) { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 2950 | WARN("Unimplemented bytes > 32bits\n"); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2951 | return FALSE; |
| 2952 | } |
| 2953 | |
| 2954 | f.l_start = dwFileOffsetLow; |
| 2955 | f.l_len = nNumberOfBytesToUnlockLow; |
| 2956 | f.l_whence = SEEK_SET; |
| 2957 | f.l_pid = 0; |
| 2958 | f.l_type = F_UNLCK; |
| 2959 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 2960 | if (!(file = FILE_GetFile(hFile,0,NULL))) return FALSE; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2961 | |
| 2962 | DOS_RemoveLock(file, &f); /* ok if fails - may be another wine */ |
| 2963 | |
| 2964 | /* FIXME: Unix locking commented out for now, doesn't work with Excel */ |
| 2965 | #ifdef USE_UNIX_LOCKS |
| 2966 | if (fcntl(file->unix_handle, F_SETLK, &f) == -1) { |
| 2967 | FILE_SetDosError(); |
| 2968 | return FALSE; |
| 2969 | } |
| 2970 | #endif |
| 2971 | return TRUE; |
| 2972 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 2973 | #endif |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 2974 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2975 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 2976 | * GetFileAttributesExA [KERNEL32.@] |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2977 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2978 | BOOL WINAPI GetFileAttributesExA( |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 2979 | LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, |
| 2980 | LPVOID lpFileInformation) |
| 2981 | { |
| 2982 | DOS_FULL_NAME full_name; |
| 2983 | BY_HANDLE_FILE_INFORMATION info; |
| 2984 | |
| 2985 | if (lpFileName == NULL) return FALSE; |
| 2986 | if (lpFileInformation == NULL) return FALSE; |
| 2987 | |
| 2988 | if (fInfoLevelId == GetFileExInfoStandard) { |
| 2989 | LPWIN32_FILE_ATTRIBUTE_DATA lpFad = |
| 2990 | (LPWIN32_FILE_ATTRIBUTE_DATA) lpFileInformation; |
| 2991 | if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name )) return FALSE; |
| 2992 | if (!FILE_Stat( full_name.long_name, &info )) return FALSE; |
| 2993 | |
| 2994 | lpFad->dwFileAttributes = info.dwFileAttributes; |
| 2995 | lpFad->ftCreationTime = info.ftCreationTime; |
| 2996 | lpFad->ftLastAccessTime = info.ftLastAccessTime; |
| 2997 | lpFad->ftLastWriteTime = info.ftLastWriteTime; |
| 2998 | lpFad->nFileSizeHigh = info.nFileSizeHigh; |
| 2999 | lpFad->nFileSizeLow = info.nFileSizeLow; |
| 3000 | } |
| 3001 | else { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 3002 | FIXME("invalid info level %d!\n", fInfoLevelId); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 3003 | return FALSE; |
| 3004 | } |
| 3005 | |
| 3006 | return TRUE; |
| 3007 | } |
| 3008 | |
| 3009 | |
| 3010 | /************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 3011 | * GetFileAttributesExW [KERNEL32.@] |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 3012 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 3013 | BOOL WINAPI GetFileAttributesExW( |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 3014 | LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, |
| 3015 | LPVOID lpFileInformation) |
| 3016 | { |
| 3017 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 3018 | BOOL res = |
| 3019 | GetFileAttributesExA( nameA, fInfoLevelId, lpFileInformation); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 3020 | HeapFree( GetProcessHeap(), 0, nameA ); |
| 3021 | return res; |
| 3022 | } |