Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apr_arch_file_io.h
Go to the documentation of this file.
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 #include "apr_poll.h"
31 
32 #ifdef HAVE_SYS_STAT_H
33 #include <sys/stat.h>
34 #endif
35 #if APR_HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38 #ifdef HAVE_SYS_FCNTL_H
39 #include <fcntl.h>
40 #endif
41 #ifdef HAVE_TIME_H
42 #include <time.h>
43 #endif
44 #if APR_HAVE_DIRENT_H
45 #include <dirent.h>
46 #endif
47 #ifdef HAVE_MALLOC_H
48 #include <malloc.h>
49 #endif
50 
51 #if APR_HAS_UNICODE_FS
53 #include <wchar.h>
54 
55 /* Helper functions for the WinNT ApiW() functions. APR treats all
56  * resource identifiers (files, etc) by their UTF-8 name, to provide
57  * access to all named identifiers. [UTF-8 completely maps Unicode
58  * into char type strings.]
59  *
60  * The _path flavors below provide us fast mappings of the
61  * Unicode filename //?/D:/path and //?/UNC/mach/share/path mappings,
62  * which allow unlimited (well, 32000 wide character) length names.
63  * These prefixes may appear in Unicode, but must not appear in the
64  * Ascii API calls. So we tack them on in utf8_to_unicode_path, and
65  * strip them right back off in unicode_to_utf8_path.
66  */
68  const char* srcstr);
69 apr_status_t unicode_to_utf8_path(char* dststr, apr_size_t dstchars,
70  const apr_wchar_t* srcstr);
71 
72 #endif /* APR_HAS_UNICODE_FS */
73 
74 /* Another Helper functions for the WinNT ApiW() functions. We need to
75  * derive some 'resource' names (max length 255 characters, prefixed with
76  * Global/ or Local/ on WinNT) from something that looks like a filename.
77  * Since 'resource' names never contain slashes, convert these to '_'s
78  * and return the appropriate char* or wchar* for ApiA or ApiW calls.
79  */
80 
81 void *res_name_from_filename(const char *file, int global, apr_pool_t *pool);
82 
83 #define APR_FILE_MAX MAX_PATH
84 
85 #define APR_FILE_DEFAULT_BUFSIZE 4096
86 /* For backwards-compat */
87 #define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
88 
89 /* obscure ommissions from msvc's sys/stat.h */
90 #ifdef _MSC_VER
91 #define S_IFIFO _S_IFIFO /* pipe */
92 #define S_IFBLK 0060000 /* Block Special */
93 #define S_IFLNK 0120000 /* Symbolic Link */
94 #define S_IFSOCK 0140000 /* Socket */
95 #define S_IFWHT 0160000 /* Whiteout */
96 #endif
97 
98 /* Internal Flags for apr_file_open */
99 #define APR_OPENINFO 0x00100000 /* Open without READ or WRITE access */
100 #define APR_OPENLINK 0x00200000 /* Open a link itself, if supported */
101 #define APR_READCONTROL 0x00400000 /* Read the file's owner/perms */
102 #define APR_WRITECONTROL 0x00800000 /* Modify the file's owner/perms */
103 /* #define APR_INHERIT 0x01000000 -- Defined in apr_arch_inherit.h! */
104 #define APR_STDIN_FLAG 0x02000000 /* Obtained via apr_file_open_stdin() */
105 #define APR_STDOUT_FLAG 0x04000000 /* Obtained via apr_file_open_stdout() */
106 #define APR_STDERR_FLAG 0x06000000 /* Obtained via apr_file_open_stderr() */
107 #define APR_STD_FLAGS (APR_STDIN_FLAG | APR_STDOUT_FLAG | APR_STDERR_FLAG)
108 #define APR_WRITEATTRS 0x08000000 /* Modify the file's attributes */
109 
110 /* Entries missing from the MSVC 5.0 Win32 SDK:
111  */
112 #ifndef FILE_ATTRIBUTE_DEVICE
113 #define FILE_ATTRIBUTE_DEVICE 0x00000040
114 #endif
115 #ifndef FILE_ATTRIBUTE_REPARSE_POINT
116 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
117 #endif
118 #ifndef FILE_FLAG_OPEN_NO_RECALL
119 #define FILE_FLAG_OPEN_NO_RECALL 0x00100000
120 #endif
121 #ifndef FILE_FLAG_OPEN_REPARSE_POINT
122 #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
123 #endif
124 #ifndef TRUSTEE_IS_WELL_KNOWN_GROUP
125 #define TRUSTEE_IS_WELL_KNOWN_GROUP 5
126 #endif
127 
128 /* Information bits available from the WIN32 FindFirstFile function */
129 #define APR_FINFO_WIN32_DIR (APR_FINFO_NAME | APR_FINFO_TYPE \
130  | APR_FINFO_CTIME | APR_FINFO_ATIME \
131  | APR_FINFO_MTIME | APR_FINFO_SIZE)
132 
133 /* Sneak the Readonly bit through finfo->protection for internal use _only_ */
134 #define APR_FREADONLY 0x10000000
135 
136 /* Private function for apr_stat/lstat/getfileinfo/dir_read */
137 int fillin_fileinfo(apr_finfo_t *finfo, WIN32_FILE_ATTRIBUTE_DATA *wininfo,
138  int byhandle, int finddata, const char *fname,
139  apr_int32_t wanted);
140 
141 /* Private function that extends apr_stat/lstat/getfileinfo/dir_read */
142 apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile,
143  apr_int32_t wanted, int whatfile);
144 
145 /* whatfile types for the ufile arg */
146 #define MORE_OF_HANDLE 0
147 #define MORE_OF_FSPEC 1
148 #define MORE_OF_WFSPEC 2
149 
150 /* quick run-down of fields in windows' apr_file_t structure that may have
151  * obvious uses.
152  * fname -- the filename as passed to the open call.
153  * dwFileAttricutes -- Attributes used to open the file.
154  * append -- Windows doesn't support the append concept when opening files.
155  * APR needs to keep track of this, and always make sure we append
156  * correctly when writing to a file with this flag set TRUE.
157  */
158 
159 /* for apr_poll.c */
160 #define filedes filehand
161 
162 struct apr_file_t {
163  apr_pool_t *pool;
164  HANDLE filehand;
165  BOOLEAN pipe; /* Is this a pipe of a file? */
166  OVERLAPPED *pOverlapped;
169 
170  /* File specific info */
172  char *fname;
174  int eof_hit;
175  BOOLEAN buffered; /* Use buffered I/O? */
176  int ungetchar; /* Last char provided by an unget op. (-1 = no char) */
177  int append;
178 
179  /* Stuff for buffered mode */
180  char *buffer;
181  apr_size_t bufpos; /* Read/Write position in buffer */
182  apr_size_t bufsize; /* The size of the buffer */
183  apr_size_t dataRead; /* amount of valid data read into buffer */
184  int direction; /* buffer being used for 0 = read, 1 = write */
185  apr_off_t filePtr; /* position in file of handle */
186  apr_thread_mutex_t *mutex; /* mutex semaphore, must be owned to access
187  the above fields */
188 
189 #if APR_FILES_AS_SOCKETS
190  /* if there is a timeout set, then this pollset is used */
192 #endif
193  /* Pipe specific info */
194 };
195 
196 struct apr_dir_t {
197  apr_pool_t *pool;
198  HANDLE dirhand;
200  char *dirname;
201  char *name;
202  WIN32_FIND_DATAW *entry;
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  */
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,
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 
248  apr_file_t **out,
249  apr_pool_t *p);
250 
252 
253 #endif /* ! FILE_IO_H */
const char apr_c_is_fnchar[256]
size_t apr_size_t
Definition: apr.h:393
apr_off_t filePtr
Definition: apr_arch_file_io.h:128
apr_status_t file_cleanup(void *)
HANDLE filehand
Definition: apr_arch_file_io.h:164
char * fname
Definition: apr_arch_file_io.h:110
Definition: apr_arch_thread_mutex.h:28
Definition: apr_arch_file_io.h:107
apr_status_t filepath_drive_get(char **rootpath, char drive, apr_int32_t flags, apr_pool_t *p)
APR File Information.
apr_status_t file_socket_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *p)
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:555
char * dirname
Definition: apr_arch_file_io.h:137
apr_pool_t * pool
Definition: apr_arch_file_io.h:136
int fillin_fileinfo(apr_finfo_t *finfo, WIN32_FILE_ATTRIBUTE_DATA *wininfo, int byhandle, int finddata, const char *fname, apr_int32_t wanted)
apr_finfo_t * finfo
Definition: apr_arch_file_io.h:171
apr_pool_t * pool
Definition: apr_arch_file_io.h:108
Definition: apr_arch_file_io.h:135
APR File I/O Handling.
APR Thread Mutex Routines.
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
APR Miscellaneous library routines.
APR Poll interface.
int ungetchar
Definition: apr_arch_file_io.h:117
APR memory allocation.
int eof_hit
Definition: apr_arch_file_io.h:112
apr_size_t rootlen
Definition: apr_arch_file_io.h:199
apr_status_t filepath_root_test(char *path, apr_pool_t *p)
APR Table library.
int direction
Definition: apr_arch_file_io.h:127
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
APR Error Codes.
char * buffer
Definition: apr_arch_file_io.h:123
APR Platform Definitions.
apr_interval_time_t timeout
Definition: apr_arch_file_io.h:114
apr_pool_t * p
int append
Definition: apr_arch_file_io.h:177
apr_size_t dataRead
Definition: apr_arch_file_io.h:183
DWORD dwFileAttributes
Definition: apr_arch_file_io.h:173
apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, apr_int32_t wanted, int whatfile)
apr_size_t bufsize
Definition: apr_arch_file_io.h:125
apr_status_t unicode_to_utf8_path(char *dststr, apr_size_t dstchars, const apr_wchar_t *srcstr)
BOOLEAN buffered
Definition: apr_arch_file_io.h:175
BOOLEAN pipe
Definition: apr_arch_file_io.h:165
apr_thread_mutex_t * mutex
Definition: apr_arch_file_io.h:57
OVERLAPPED * pOverlapped
Definition: apr_arch_file_io.h:166
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
WIN32_FIND_DATAW * entry
Definition: apr_arch_file_io.h:202
int apr_status_t
Definition: apr_errno.h:44
HANDLE dirhand
Definition: apr_arch_file_io.h:198
apr_pollset_t * pollset
Definition: apr_arch_file_io.h:120
apr_int32_t flags
Definition: apr_arch_file_io.h:111
char * name
Definition: apr_arch_file_io.h:201
int bof
Definition: apr_arch_file_io.h:203
void * res_name_from_filename(const char *file, int global, apr_pool_t *pool)
apr_status_t file_socket_pipe_close(apr_file_t *file)
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1452
apr_uint16_t apr_wchar_t
Definition: apr_arch_utf8.h:26
off_t apr_off_t
Definition: apr.h:395
Definition: apr_file_info.h:174
apr_status_t utf8_to_unicode_path(apr_wchar_t *dststr, apr_size_t dstchars, const char *srcstr)
apr_size_t bufpos
Definition: apr_arch_file_io.h:124
int apr_int32_t
Definition: apr.h:346
Definition: apr_arch_poll_private.h:119