GME  13
apr_arch_file_io.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef FILE_IO_H
00018 #define FILE_IO_H
00019 
00020 #include "apr.h"
00021 #include "apr_private.h"
00022 #include "apr_general.h"
00023 #include "apr_tables.h"
00024 #include "apr_file_io.h"
00025 #include "apr_file_info.h"
00026 #include "apr_errno.h"
00027 #include "apr_lib.h"
00028 #include "apr_poll.h"
00029 
00030 /* System headers the file I/O library needs */
00031 #if APR_HAVE_FCNTL_H
00032 #include <fcntl.h>
00033 #endif
00034 #if APR_HAVE_SYS_TYPES_H
00035 #include <sys/types.h>
00036 #endif
00037 #if APR_HAVE_ERRNO_H
00038 #include <errno.h>
00039 #endif
00040 #if APR_HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 #if APR_HAVE_STRINGS_H
00044 #include <strings.h>
00045 #endif
00046 #if APR_HAVE_DIRENT_H
00047 #include <dirent.h>
00048 #endif
00049 #ifdef HAVE_SYS_STAT_H
00050 #include <sys/stat.h>
00051 #endif
00052 #if APR_HAVE_UNISTD_H
00053 #include <unistd.h>
00054 #endif
00055 #if APR_HAVE_STDIO_H
00056 #include <stdio.h>
00057 #endif
00058 #if APR_HAVE_STDLIB_H
00059 #include <stdlib.h>
00060 #endif
00061 #if APR_HAVE_SYS_UIO_H
00062 #include <sys/uio.h>
00063 #endif
00064 #if APR_HAVE_SYS_TIME_H
00065 #include <sys/time.h>
00066 #endif
00067 
00068 #include <fsio.h>
00069 
00070 /* End System headers */
00071 
00072 #define APR_FILE_DEFAULT_BUFSIZE 4096
00073 /* For backwards compat */
00074 #define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
00075 
00076 #if APR_HAS_THREADS
00077 #define file_lock(f)   do { \
00078                            if ((f)->thlock) \
00079                                apr_thread_mutex_lock((f)->thlock); \
00080                        } while (0)
00081 #define file_unlock(f) do { \
00082                            if ((f)->thlock) \
00083                                apr_thread_mutex_unlock((f)->thlock); \
00084                        } while (0)
00085 #else
00086 #define file_lock(f)   do {} while (0)
00087 #define file_unlock(f) do {} while (0)
00088 #endif
00089 
00090 #if APR_HAS_LARGE_FILES
00091 #define lseek(f,o,w) lseek64(f,o,w)
00092 #define ftruncate(f,l) ftruncate64(f,l)
00093 #endif
00094 
00095 typedef struct stat struct_stat;
00096 
00097 struct apr_file_t {
00098     apr_pool_t *pool;
00099     int filedes;
00100     char *fname;
00101     apr_int32_t flags;
00102     int eof_hit;
00103     int is_pipe;
00104     apr_interval_time_t timeout;
00105     int buffered;
00106     enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
00107     int ungetchar;    /* Last char provided by an unget op. (-1 = no char)*/
00108 
00109     /* if there is a timeout set, then this pollset is used */
00110     apr_pollset_t *pollset;
00111 
00112     /* Stuff for buffered mode */
00113     char *buffer;
00114     apr_size_t bufpos;    /* Read/Write position in buffer */
00115     apr_size_t bufsize;   /* The buffer size */
00116     apr_off_t dataRead;   /* amount of valid data read into buffer */
00117     int direction;            /* buffer being used for 0 = read, 1 = write */
00118     apr_off_t filePtr;    /* position in file of handle */
00119 #if APR_HAS_THREADS
00120     struct apr_thread_mutex_t *thlock;
00121 #endif
00122 };
00123 
00124 struct apr_dir_t {
00125     apr_pool_t *pool;
00126     char *dirname;
00127     DIR *dirstruct;
00128     struct dirent *entry;
00129 };
00130 
00131 typedef struct apr_stat_entry_t apr_stat_entry_t;
00132 
00133 struct apr_stat_entry_t {
00134     struct stat info;
00135     char *casedName;
00136     apr_time_t expire;
00137     NXPathCtx_t pathCtx;
00138 };
00139 
00140 #define MAX_SERVER_NAME     64
00141 #define MAX_VOLUME_NAME     64
00142 #define MAX_PATH_NAME       256
00143 #define MAX_FILE_NAME       256
00144 
00145 #define DRIVE_ONLY          1
00146 
00147 /* If the user passes d: vs. D: (or //mach/share vs. //MACH/SHARE),
00148  * we need to fold the case to canonical form.  This function is
00149  * supposed to do so.
00150  */
00151 apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p);
00152 
00153 /* This function check to see of the given path includes a drive/volume
00154  * specifier.  If the _only_ parameter is set to DRIVE_ONLY then it 
00155  * check to see of the path only contains a drive/volume specifier and
00156  * nothing else.
00157  */
00158 apr_status_t filepath_has_drive(const char *rootpath, int only, apr_pool_t *p);
00159 
00160 /* This function compares the drive/volume specifiers for each given path.
00161  * It returns zero if they match or non-zero if not. 
00162  */
00163 apr_status_t filepath_compare_drive(const char *path1, const char *path2, apr_pool_t *p);
00164 
00165 apr_status_t apr_unix_file_cleanup(void *);
00166 apr_status_t apr_unix_child_file_cleanup(void *);
00167 
00168 mode_t apr_unix_perms2mode(apr_fileperms_t perms);
00169 apr_fileperms_t apr_unix_mode2perms(mode_t mode);
00170 
00171 apr_status_t apr_file_flush_locked(apr_file_t *thefile);
00172 apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted,
00173                                       apr_file_t *thefile);
00174 
00175 #endif  /* ! FILE_IO_H */
00176