Apache2
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_general.h"
23 #include "apr_tables.h"
24 #include "apr_file_io.h"
25 #include "apr_file_info.h"
26 #include "apr_errno.h"
27 #include "apr_lib.h"
28 #include "apr_poll.h"
29 #include "apr_time.h"
30 
31 /* System headers the file I/O library needs */
32 #if APR_HAVE_FCNTL_H
33 #include <fcntl.h>
34 #endif
35 #if APR_HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38 #if APR_HAVE_ERRNO_H
39 #include <errno.h>
40 #endif
41 #if APR_HAVE_STRING_H
42 #include <string.h>
43 #endif
44 #if APR_HAVE_STRINGS_H
45 #include <strings.h>
46 #endif
47 #if APR_HAVE_DIRENT_H
48 #include <dirent.h>
49 #endif
50 #ifdef HAVE_SYS_STAT_H
51 #include <sys/stat.h>
52 #endif
53 #if APR_HAVE_UNISTD_H
54 #include <unistd.h>
55 #endif
56 #if APR_HAVE_STDIO_H
57 #include <stdio.h>
58 #endif
59 #if APR_HAVE_STDLIB_H
60 #include <stdlib.h>
61 #endif
62 #if APR_HAVE_SYS_UIO_H
63 #include <sys/uio.h>
64 #endif
65 #if APR_HAVE_SYS_TIME_H
66 #include <sys/time.h>
67 #endif
68 
69 #include <fsio.h>
70 
71 /* End System headers */
72 
73 #define APR_FILE_DEFAULT_BUFSIZE 4096
74 /* For backwards compat */
75 #define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
76 
77 #if APR_HAS_THREADS
78 #define file_lock(f) do { \
79  if ((f)->thlock) \
80  apr_thread_mutex_lock((f)->thlock); \
81  } while (0)
82 #define file_unlock(f) do { \
83  if ((f)->thlock) \
84  apr_thread_mutex_unlock((f)->thlock); \
85  } while (0)
86 #else
87 #define file_lock(f) do {} while (0)
88 #define file_unlock(f) do {} while (0)
89 #endif
90 
91 #if APR_HAS_LARGE_FILES
92 #define lseek(f,o,w) lseek64(f,o,w)
93 #define ftruncate(f,l) ftruncate64(f,l)
94 #endif
95 
96 typedef struct stat struct_stat;
97 
98 typedef struct apr_rotating_info_t {
102  int oflags;
103  int manual;
106 
107 struct apr_file_t {
109  int filedes;
110  char *fname;
112  int eof_hit;
113  int is_pipe;
115  int buffered;
117  int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/
118 
119  /* if there is a timeout set, then this pollset is used */
121 
122  /* Stuff for buffered mode */
123  char *buffer;
124  apr_size_t bufpos; /* Read/Write position in buffer */
125  apr_size_t bufsize; /* The buffer size */
126  apr_off_t dataRead; /* amount of valid data read into buffer */
127  int direction; /* buffer being used for 0 = read, 1 = write */
128  apr_off_t filePtr; /* position in file of handle */
129 #if APR_HAS_THREADS
131 #endif
133 };
134 
135 struct apr_dir_t {
137  char *dirname;
138  DIR *dirstruct;
139  struct dirent *entry;
140 };
141 
142 typedef struct apr_stat_entry_t apr_stat_entry_t;
143 
145  struct stat info;
146  char *casedName;
148  NXPathCtx_t pathCtx;
149 };
150 
151 #define MAX_SERVER_NAME 64
152 #define MAX_VOLUME_NAME 64
153 #define MAX_PATH_NAME 256
154 #define MAX_FILE_NAME 256
155 
156 #define DRIVE_ONLY 1
157 
158 /* If the user passes d: vs. D: (or //mach/share vs. //MACH/SHARE),
159  * we need to fold the case to canonical form. This function is
160  * supposed to do so.
161  */
162 apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p);
163 
164 /* This function check to see of the given path includes a drive/volume
165  * specifier. If the _only_ parameter is set to DRIVE_ONLY then it
166  * check to see of the path only contains a drive/volume specifier and
167  * nothing else.
168  */
169 apr_status_t filepath_has_drive(const char *rootpath, int only, apr_pool_t *p);
170 
171 /* This function compares the drive/volume specifiers for each given path.
172  * It returns zero if they match or non-zero if not.
173  */
174 apr_status_t filepath_compare_drive(const char *path1, const char *path2, apr_pool_t *p);
175 
178 
181 
184  apr_file_t *thefile);
185 
186 #endif /* ! FILE_IO_H */
187 
APR Platform Definitions.
APR Error Codes.
APR File Information.
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Poll interface.
APR Table library.
APR Time Library.
apr_bucket_brigade ap_input_mode_t mode
Definition: mod_dav.h:2662
int apr_status_t
Definition: apr_errno.h:44
apr_int32_t apr_fileperms_t
Definition: apr_file_info.h:125
int apr_int32_t
Definition: apr.h:347
off_t apr_off_t
Definition: apr.h:396
size_t apr_size_t
Definition: apr.h:394
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
apr_int64_t apr_time_t
Definition: apr_time.h:45
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
mode_t apr_unix_perms2mode(apr_fileperms_t perms)
struct stat struct_stat
Definition: apr_arch_file_io.h:96
apr_status_t apr_unix_file_cleanup(void *)
struct apr_rotating_info_t apr_rotating_info_t
apr_status_t filepath_compare_drive(const char *path1, const char *path2, apr_pool_t *p)
apr_status_t filepath_has_drive(const char *rootpath, int only, apr_pool_t *p)
apr_fileperms_t apr_unix_mode2perms(mode_t mode)
apr_status_t apr_unix_child_file_cleanup(void *)
apr_status_t apr_file_flush_locked(apr_file_t *thefile)
apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted, apr_file_t *thefile)
Definition: apr_arch_file_io.h:135
char * dirname
Definition: apr_arch_file_io.h:137
struct dirent * entry
Definition: apr_arch_file_io.h:139
apr_pool_t * pool
Definition: apr_arch_file_io.h:136
DIR * dirstruct
Definition: apr_arch_file_io.h:138
Definition: apr_arch_file_io.h:107
apr_pollset_t * pollset
Definition: apr_arch_file_io.h:120
int direction
Definition: apr_arch_file_io.h:127
apr_int32_t flags
Definition: apr_arch_file_io.h:111
int is_pipe
Definition: apr_arch_file_io.h:113
apr_interval_time_t timeout
Definition: apr_arch_file_io.h:114
apr_size_t bufpos
Definition: apr_arch_file_io.h:124
apr_off_t filePtr
Definition: apr_arch_file_io.h:128
int filedes
Definition: apr_arch_file_io.h:109
apr_off_t dataRead
Definition: apr_arch_file_io.h:126
int ungetchar
Definition: apr_arch_file_io.h:117
char * buffer
Definition: apr_arch_file_io.h:123
apr_pool_t * pool
Definition: apr_arch_file_io.h:108
@ BLK_OFF
Definition: apr_arch_file_io.h:116
@ BLK_ON
Definition: apr_arch_file_io.h:116
@ BLK_UNKNOWN
Definition: apr_arch_file_io.h:116
apr_rotating_info_t * rotating
Definition: apr_arch_file_io.h:132
struct apr_thread_mutex_t * thlock
Definition: apr_arch_file_io.h:130
char * fname
Definition: apr_arch_file_io.h:110
int buffered
Definition: apr_arch_file_io.h:115
enum apr_file_t::@20 blocking
apr_size_t bufsize
Definition: apr_arch_file_io.h:125
int eof_hit
Definition: apr_arch_file_io.h:112
Definition: apr_file_info.h:174
Definition: apr_arch_poll_private.h:124
Definition: apr_arch_file_io.h:98
apr_interval_time_t timeout
Definition: apr_arch_file_io.h:100
int manual
Definition: apr_arch_file_io.h:103
apr_finfo_t finfo
Definition: apr_arch_file_io.h:99
apr_fileperms_t perm
Definition: apr_arch_file_io.h:104
int oflags
Definition: apr_arch_file_io.h:102
apr_time_t lastcheck
Definition: apr_arch_file_io.h:101
Definition: apr_arch_file_io.h:144
char * casedName
Definition: apr_arch_file_io.h:146
apr_time_t expire
Definition: apr_arch_file_io.h:147
NXPathCtx_t pathCtx
Definition: apr_arch_file_io.h:148
struct stat info
Definition: apr_arch_file_io.h:145
Definition: apr_arch_thread_mutex.h:28
apr_pool_t * p