upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / include / arch / win32 / apr_arch_file_io.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef FILE_IO_H
18 #define FILE_IO_H
19
20 #include "apr.h"
21 #include "apr_private.h"
22 #include "apr_pools.h"
23 #include "apr_general.h"
24 #include "apr_tables.h"
25 #include "apr_thread_mutex.h"
26 #include "apr_file_io.h"
27 #include "apr_file_info.h"
28 #include "apr_errno.h"
29 #include "apr_arch_misc.h"
30
31 #ifdef HAVE_SYS_STAT_H
32 #include <sys/stat.h>
33 #endif
34 #if APR_HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
37 #ifdef HAVE_SYS_FCNTL_H
38 #include <fcntl.h>
39 #endif
40 #ifdef HAVE_TIME_H
41 #include <time.h>
42 #endif
43 #if APR_HAVE_DIRENT_H
44 #include <dirent.h>
45 #endif
46 #ifdef HAVE_MALLOC_H
47 #include <malloc.h>
48 #endif
49
50 #if APR_HAS_UNICODE_FS
51 #include "arch/win32/apr_arch_utf8.h"
52 #include <wchar.h>
53
54 /* Helper functions for the WinNT ApiW() functions.  APR treats all
55  * resource identifiers (files, etc) by their UTF-8 name, to provide 
56  * access to all named identifiers.  [UTF-8 completely maps Unicode 
57  * into char type strings.]
58  *
59  * The _path flavors below provide us fast mappings of the
60  * Unicode filename //?/D:/path and //?/UNC/mach/share/path mappings,
61  * which allow unlimited (well, 32000 wide character) length names.
62  * These prefixes may appear in Unicode, but must not appear in the
63  * Ascii API calls.  So we tack them on in utf8_to_unicode_path, and
64  * strip them right back off in unicode_to_utf8_path.
65  */
66 apr_status_t utf8_to_unicode_path(apr_wchar_t* dststr, apr_size_t dstchars, 
67                                   const char* srcstr);
68 apr_status_t unicode_to_utf8_path(char* dststr, apr_size_t dstchars, 
69                                   const apr_wchar_t* srcstr);
70
71 #endif /* APR_HAS_UNICODE_FS */
72
73 /* Another Helper functions for the WinNT ApiW() functions.  We need to
74  * derive some 'resource' names (max length 255 characters, prefixed with
75  * Global/ or Local/ on WinNT) from something that looks like a filename.
76  * Since 'resource' names never contain slashes, convert these to '_'s
77  * and return the appropriate char* or wchar* for ApiA or ApiW calls.
78  */
79
80 void *res_name_from_filename(const char *file, int global, apr_pool_t *pool);
81
82 #define APR_FILE_MAX MAX_PATH
83
84 #define APR_FILE_BUFSIZE 4096
85
86 /* obscure ommissions from msvc's sys/stat.h */
87 #ifdef _MSC_VER
88 #define S_IFIFO        _S_IFIFO /* pipe */
89 #define S_IFBLK        0060000  /* Block Special */
90 #define S_IFLNK        0120000  /* Symbolic Link */
91 #define S_IFSOCK       0140000  /* Socket */
92 #define S_IFWHT        0160000  /* Whiteout */
93 #endif
94
95 /* Internal Flags for apr_file_open */
96 #define APR_OPENINFO     0x00100000 /* Open without READ or WRITE access */
97 #define APR_OPENLINK     0x00200000 /* Open a link itself, if supported */
98 #define APR_READCONTROL  0x00400000 /* Read the file's owner/perms */
99 #define APR_WRITECONTROL 0x00800000 /* Modifythe file's owner/perms */
100 #define APR_WRITEATTRS   0x01000000 /* Modify the file's attributes */
101 #define APR_STDIN_FLAG   0x02000000 /* Obtained via apr_file_open_stdin() */
102 #define APR_STDOUT_FLAG  0x04000000 /* Obtained via apr_file_open_stdout() */
103 #define APR_STDERR_FLAG  0x06000000 /* Obtained via apr_file_open_stderr() */
104 #define APR_STD_FLAGS    (APR_STDIN_FLAG | APR_STDOUT_FLAG | APR_STDERR_FLAG)
105
106 /* Entries missing from the MSVC 5.0 Win32 SDK:
107  */
108 #ifndef FILE_ATTRIBUTE_DEVICE
109 #define FILE_ATTRIBUTE_DEVICE        0x00000040
110 #endif
111 #ifndef FILE_ATTRIBUTE_REPARSE_POINT
112 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
113 #endif
114 #ifndef FILE_FLAG_OPEN_NO_RECALL
115 #define FILE_FLAG_OPEN_NO_RECALL     0x00100000
116 #endif
117 #ifndef FILE_FLAG_OPEN_REPARSE_POINT
118 #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
119 #endif
120 #ifndef TRUSTEE_IS_WELL_KNOWN_GROUP
121 #define TRUSTEE_IS_WELL_KNOWN_GROUP  5
122 #endif
123
124 /* Information bits available from the WIN32 FindFirstFile function */
125 #define APR_FINFO_WIN32_DIR (APR_FINFO_NAME  | APR_FINFO_TYPE \
126                            | APR_FINFO_CTIME | APR_FINFO_ATIME \
127                            | APR_FINFO_MTIME | APR_FINFO_SIZE)
128
129 /* Sneak the Readonly bit through finfo->protection for internal use _only_ */
130 #define APR_FREADONLY 0x10000000 
131
132 /* Private function for apr_stat/lstat/getfileinfo/dir_read */
133 int fillin_fileinfo(apr_finfo_t *finfo, WIN32_FILE_ATTRIBUTE_DATA *wininfo, 
134                     int byhandle, apr_int32_t wanted);
135
136 /* Private function that extends apr_stat/lstat/getfileinfo/dir_read */
137 apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, 
138                         apr_int32_t wanted, int whatfile);
139
140 /* whatfile types for the ufile arg */
141 #define MORE_OF_HANDLE 0
142 #define MORE_OF_FSPEC  1
143 #define MORE_OF_WFSPEC 2
144
145 /* quick run-down of fields in windows' apr_file_t structure that may have 
146  * obvious uses.
147  * fname --  the filename as passed to the open call.
148  * dwFileAttricutes -- Attributes used to open the file.
149  * append -- Windows doesn't support the append concept when opening files.
150  *           APR needs to keep track of this, and always make sure we append
151  *           correctly when writing to a file with this flag set TRUE.
152  */
153
154 // for apr_poll.c;
155 #define filedes filehand
156
157 struct apr_file_t {
158     apr_pool_t *pool;
159     HANDLE filehand;
160     BOOLEAN pipe;              // Is this a pipe of a file?
161     OVERLAPPED *pOverlapped;
162     apr_interval_time_t timeout;
163     apr_int32_t flags;
164
165     /* File specific info */
166     apr_finfo_t *finfo;
167     char *fname;
168     DWORD dwFileAttributes;
169     int eof_hit;
170     BOOLEAN buffered;          // Use buffered I/O?
171     int ungetchar;             // Last char provided by an unget op. (-1 = no char)
172     int append; 
173
174     /* Stuff for buffered mode */
175     char *buffer;
176     apr_size_t bufpos;         // Read/Write position in buffer
177     apr_size_t dataRead;       // amount of valid data read into buffer
178     int direction;             // buffer being used for 0 = read, 1 = write
179     apr_off_t filePtr;         // position in file of handle
180     apr_thread_mutex_t *mutex; // mutex semaphore, must be owned to access the above fields
181
182     /* Pipe specific info */    
183 };
184
185 struct apr_dir_t {
186     apr_pool_t *pool;
187     HANDLE dirhand;
188     apr_size_t rootlen;
189     char *dirname;
190     char *name;
191     union {
192 #if APR_HAS_UNICODE_FS
193         struct {
194             WIN32_FIND_DATAW *entry;
195         } w;
196 #endif
197 #if APR_HAS_ANSI_FS
198         struct {
199             WIN32_FIND_DATAA *entry;
200         } n;
201 #endif        
202     };
203     int bof;
204 };
205
206 /* There are many goofy characters the filesystem can't accept
207  * or can confound the cmd.exe shell.  Here's the list
208  * [declared in filesys.c]
209  */
210 extern const char apr_c_is_fnchar[256];
211
212 #define IS_FNCHAR(c) (apr_c_is_fnchar[(unsigned char)(c)] & 1)
213 #define IS_SHCHAR(c) ((apr_c_is_fnchar[(unsigned char)(c)] & 2) == 2)
214
215
216 /* If the user passes APR_FILEPATH_TRUENAME to either
217  * apr_filepath_root or apr_filepath_merge, this fn determines
218  * that the root really exists.  It's expensive, wouldn't want
219  * to do this too frequenly.
220  */
221 apr_status_t filepath_root_test(char *path, apr_pool_t *p);
222
223
224 /* The apr_filepath_merge wants to canonicalize the cwd to the 
225  * addpath if the user passes NULL as the old root path (this
226  * isn't true of an empty string "", which won't be concatenated.
227  *
228  * But we need to figure out what the cwd of a given volume is,
229  * when the user passes D:foo.  This fn will determine D:'s cwd.
230  *
231  * If flags includes the bit APR_FILEPATH_NATIVE, the path returned
232  * is in the os-native format.
233  */
234 apr_status_t filepath_drive_get(char **rootpath, char drive, 
235                                 apr_int32_t flags, apr_pool_t *p);
236
237
238 /* If the user passes d: vs. D: (or //mach/share vs. //MACH/SHARE),
239  * we need to fold the case to canonical form.  This function is
240  * supposed to do so.
241  */
242 apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p);
243
244
245 apr_status_t file_cleanup(void *);
246
247 /**
248  * Internal function to create a Win32/NT pipe that respects some async
249  * timeout options.
250  * @param in new read end of the created pipe
251  * @param out new write end of the created pipe
252  * @param blocking_mode one of
253  * <pre>
254  *       APR_FULL_BLOCK
255  *       APR_READ_BLOCK
256  *       APR_WRITE_BLOCK
257  *       APR_FULL_NONBLOCK
258  * </pre>
259  * @remark It so happens that APR_FULL_BLOCK and APR_FULL_NONBLOCK
260  * are common to apr_procattr_io_set() in, out and err modes.
261  * Because APR_CHILD_BLOCK and APR_WRITE_BLOCK share the same value,
262  * as do APR_PARENT_BLOCK and APR_READ_BLOCK, it's possible to use
263  * that value directly for creating the stdout/stderr pipes.  When
264  * creating the stdin pipe, the values must be transposed.
265  * @see apr_procattr_io_set
266  */
267 apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out, 
268                                 apr_int32_t blocking_mode, 
269                                 apr_pool_t *p);
270
271 /** @see apr_create_nt_pipe */
272 #define APR_READ_BLOCK     3
273 /** @see apr_create_nt_pipe */
274 #define APR_WRITE_BLOCK      4
275
276 #endif  /* ! FILE_IO_H */