Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_file_info.h

Go to the documentation of this file.
00001 /* Copyright 2000-2004 The Apache Software Foundation 00002 * 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 */ 00015 00016 #ifndef APR_FILE_INFO_H 00017 #define APR_FILE_INFO_H 00018 00019 /** 00020 * @file apr_file_info.h 00021 * @brief APR File Information 00022 */ 00023 00024 #include "apr.h" 00025 #include "apr_user.h" 00026 #include "apr_pools.h" 00027 #include "apr_tables.h" 00028 #include "apr_time.h" 00029 #include "apr_errno.h" 00030 00031 #if APR_HAVE_SYS_UIO_H 00032 #include <sys/uio.h> 00033 #endif 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif /* __cplusplus */ 00038 00039 /** 00040 * @defgroup apr_file_info File Information 00041 * @ingroup APR 00042 * @{ 00043 */ 00044 00045 /* Many applications use the type member to determine the 00046 * existance of a file or initialization of the file info, 00047 * so the APR_NOFILE value must be distinct from APR_UNKFILE. 00048 */ 00049 00050 /** apr_filetype_e values for the filetype member of the 00051 * apr_file_info_t structure 00052 * @warning: Not all of the filetypes below can be determined. 00053 * For example, a given platform might not correctly report 00054 * a socket descriptor as APR_SOCK if that type isn't 00055 * well-identified on that platform. In such cases where 00056 * a filetype exists but cannot be described by the recognized 00057 * flags below, the filetype will be APR_UNKFILE. If the 00058 * filetype member is not determined, the type will be APR_NOFILE. 00059 */ 00060 00061 typedef enum { 00062 APR_NOFILE = 0, /**< no file type determined */ 00063 APR_REG, /**< a regular file */ 00064 APR_DIR, /**< a directory */ 00065 APR_CHR, /**< a character device */ 00066 APR_BLK, /**< a block device */ 00067 APR_PIPE, /**< a FIFO / pipe */ 00068 APR_LNK, /**< a symbolic link */ 00069 APR_SOCK, /**< a [unix domain] socket */ 00070 APR_UNKFILE = 127 /**< a file of some other unknown type */ 00071 } apr_filetype_e; 00072 00073 /** 00074 * @defgroup apr_file_permissions File Permissions flags 00075 * @{ 00076 */ 00077 00078 #define APR_USETID 0x8000 /**< Set user id */ 00079 #define APR_UREAD 0x0400 /**< Read by user */ 00080 #define APR_UWRITE 0x0200 /**< Write by user */ 00081 #define APR_UEXECUTE 0x0100 /**< Execute by user */ 00082 00083 #define APR_GSETID 0x4000 /**< Set group id */ 00084 #define APR_GREAD 0x0040 /**< Read by group */ 00085 #define APR_GWRITE 0x0020 /**< Write by group */ 00086 #define APR_GEXECUTE 0x0010 /**< Execute by group */ 00087 00088 #define APR_WSTICKY 0x2000 /**< Sticky bit */ 00089 #define APR_WREAD 0x0004 /**< Read by others */ 00090 #define APR_WWRITE 0x0002 /**< Write by others */ 00091 #define APR_WEXECUTE 0x0001 /**< Execute by others */ 00092 00093 #define APR_OS_DEFAULT 0x0FFF /**< use OS's default permissions */ 00094 00095 /* additional permission flags for apr_file_copy and apr_file_append */ 00096 #define APR_FILE_SOURCE_PERMS 0x1000 /**< Copy source file's permissions */ 00097 00098 /** @} */ 00099 00100 00101 /** 00102 * Structure for referencing directories. 00103 */ 00104 typedef struct apr_dir_t apr_dir_t; 00105 /** 00106 * Structure for determining file permissions. 00107 */ 00108 typedef apr_int32_t apr_fileperms_t; 00109 #if (defined WIN32) || (defined NETWARE) 00110 /** 00111 * Structure for determining the inode of the file. 00112 */ 00113 typedef apr_uint64_t apr_ino_t; 00114 /** 00115 * Structure for determining the device the file is on. 00116 */ 00117 typedef apr_uint32_t apr_dev_t; 00118 #else 00119 /** The inode of the file. */ 00120 typedef ino_t apr_ino_t; 00121 /** 00122 * Structure for determining the device the file is on. 00123 */ 00124 typedef dev_t apr_dev_t; 00125 #endif 00126 00127 /** 00128 * @defgroup apr_file_stat Stat Functions 00129 * @{ 00130 */ 00131 /** file info structure */ 00132 typedef struct apr_finfo_t apr_finfo_t; 00133 00134 #define APR_FINFO_LINK 0x00000001 /**< Stat the link not the file itself if it is a link */ 00135 #define APR_FINFO_MTIME 0x00000010 /**< Modification Time */ 00136 #define APR_FINFO_CTIME 0x00000020 /**< Creation or inode-changed time */ 00137 #define APR_FINFO_ATIME 0x00000040 /**< Access Time */ 00138 #define APR_FINFO_SIZE 0x00000100 /**< Size of the file */ 00139 #define APR_FINFO_CSIZE 0x00000200 /**< Storage size consumed by the file */ 00140 #define APR_FINFO_DEV 0x00001000 /**< Device */ 00141 #define APR_FINFO_INODE 0x00002000 /**< Inode */ 00142 #define APR_FINFO_NLINK 0x00004000 /**< Number of links */ 00143 #define APR_FINFO_TYPE 0x00008000 /**< Type */ 00144 #define APR_FINFO_USER 0x00010000 /**< User */ 00145 #define APR_FINFO_GROUP 0x00020000 /**< Group */ 00146 #define APR_FINFO_UPROT 0x00100000 /**< User protection bits */ 00147 #define APR_FINFO_GPROT 0x00200000 /**< Group protection bits */ 00148 #define APR_FINFO_WPROT 0x00400000 /**< World protection bits */ 00149 #define APR_FINFO_ICASE 0x01000000 /**< if dev is case insensitive */ 00150 #define APR_FINFO_NAME 0x02000000 /**< ->name in proper case */ 00151 00152 #define APR_FINFO_MIN 0x00008170 /**< type, mtime, ctime, atime, size */ 00153 #define APR_FINFO_IDENT 0x00003000 /**< dev and inode */ 00154 #define APR_FINFO_OWNER 0x00030000 /**< user and group */ 00155 #define APR_FINFO_PROT 0x00700000 /**< all protections */ 00156 #define APR_FINFO_NORM 0x0073b170 /**< an atomic unix apr_stat() */ 00157 #define APR_FINFO_DIRENT 0x02000000 /**< an atomic unix apr_dir_read() */ 00158 00159 /** 00160 * The file information structure. This is analogous to the POSIX 00161 * stat structure. 00162 */ 00163 struct apr_finfo_t { 00164 /** Allocates memory and closes lingering handles in the specified pool */ 00165 apr_pool_t *pool; 00166 /** The bitmask describing valid fields of this apr_finfo_t structure 00167 * including all available 'wanted' fields and potentially more */ 00168 apr_int32_t valid; 00169 /** The access permissions of the file. Mimics Unix access rights. */ 00170 apr_fileperms_t protection; 00171 /** The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE, 00172 * APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE. 00173 * If the type cannot be determined, the value is APR_UNKFILE. 00174 */ 00175 apr_filetype_e filetype; 00176 /** The user id that owns the file */ 00177 apr_uid_t user; 00178 /** The group id that owns the file */ 00179 apr_gid_t group; 00180 /** The inode of the file. */ 00181 apr_ino_t inode; 00182 /** The id of the device the file is on. */ 00183 apr_dev_t device; 00184 /** The number of hard links to the file. */ 00185 apr_int32_t nlink; 00186 /** The size of the file */ 00187 apr_off_t size; 00188 /** The storage size consumed by the file */ 00189 apr_off_t csize; 00190 /** The time the file was last accessed */ 00191 apr_time_t atime; 00192 /** The time the file was last modified */ 00193 apr_time_t mtime; 00194 /** The time the file was created, or the inode was last changed */ 00195 apr_time_t ctime; 00196 /** The pathname of the file (possibly unrooted) */ 00197 const char *fname; 00198 /** The file's name (no path) in filesystem case */ 00199 const char *name; 00200 /** The file's handle, if accessed (can be submitted to apr_duphandle) */ 00201 struct apr_file_t *filehand; 00202 }; 00203 00204 /** 00205 * get the specified file's stats. The file is specified by filename, 00206 * instead of using a pre-opened file. 00207 * @param finfo Where to store the information about the file, which is 00208 * never touched if the call fails. 00209 * @param fname The name of the file to stat. 00210 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values 00211 * @param pool the pool to use to allocate the new file. 00212 */ 00213 APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, 00214 apr_int32_t wanted, apr_pool_t *pool); 00215 00216 /** @} */ 00217 /** 00218 * @defgroup apr_dir Directory Manipulation Functions 00219 * @{ 00220 */ 00221 00222 /** 00223 * Open the specified directory. 00224 * @param new_dir The opened directory descriptor. 00225 * @param dirname The full path to the directory (use / on all systems) 00226 * @param pool The pool to use. 00227 */ 00228 APR_DECLARE(apr_status_t) apr_dir_open(apr_dir_t **new_dir, 00229 const char *dirname, 00230 apr_pool_t *pool); 00231 00232 /** 00233 * close the specified directory. 00234 * @param thedir the directory descriptor to close. 00235 */ 00236 APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir); 00237 00238 /** 00239 * Read the next entry from the specified directory. 00240 * @param finfo the file info structure and filled in by apr_dir_read 00241 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values 00242 * @param thedir the directory descriptor returned from apr_dir_open 00243 * @remark No ordering is guaranteed for the entries read. 00244 */ 00245 APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, 00246 apr_dir_t *thedir); 00247 00248 /** 00249 * Rewind the directory to the first entry. 00250 * @param thedir the directory descriptor to rewind. 00251 */ 00252 APR_DECLARE(apr_status_t) apr_dir_rewind(apr_dir_t *thedir); 00253 /** @} */ 00254 00255 /** 00256 * @defgroup apr_filepath Filepath Manipulation Functions 00257 * @{ 00258 */ 00259 00260 /** Cause apr_filepath_merge to fail if addpath is above rootpath */ 00261 #define APR_FILEPATH_NOTABOVEROOT 0x01 00262 00263 /** internal: Only meaningful with APR_FILEPATH_NOTABOVEROOT */ 00264 #define APR_FILEPATH_SECUREROOTTEST 0x02 00265 00266 /** Cause apr_filepath_merge to fail if addpath is above rootpath, 00267 * even given a rootpath /foo/bar and an addpath ../bar/bash 00268 */ 00269 #define APR_FILEPATH_SECUREROOT 0x03 00270 00271 /** Fail apr_filepath_merge if the merged path is relative */ 00272 #define APR_FILEPATH_NOTRELATIVE 0x04 00273 00274 /** Fail apr_filepath_merge if the merged path is absolute */ 00275 #define APR_FILEPATH_NOTABSOLUTE 0x08 00276 00277 /** Return the file system's native path format (e.g. path delimiters 00278 * of ':' on MacOS9, '\' on Win32, etc.) */ 00279 #define APR_FILEPATH_NATIVE 0x10 00280 00281 /** Resolve the true case of existing directories and file elements 00282 * of addpath, (resolving any aliases on Win32) and append a proper 00283 * trailing slash if a directory 00284 */ 00285 #define APR_FILEPATH_TRUENAME 0x20 00286 00287 /** 00288 * Extract the rootpath from the given filepath 00289 * @param rootpath the root file path returned with APR_SUCCESS or APR_EINCOMPLETE 00290 * @param filepath the pathname to parse for its root component 00291 * @param flags the desired rules to apply, from 00292 * <PRE> 00293 * APR_FILEPATH_NATIVE Use native path seperators (e.g. '\' on Win32) 00294 * APR_FILEPATH_TRUENAME Tests that the root exists, and makes it proper 00295 * </PRE> 00296 * @param p the pool to allocate the new path string from 00297 * @remark on return, filepath points to the first non-root character in the 00298 * given filepath. In the simplest example, given a filepath of "/foo", 00299 * returns the rootpath of "/" and filepath points at "foo". This is far 00300 * more complex on other platforms, which will canonicalize the root form 00301 * to a consistant format, given the APR_FILEPATH_TRUENAME flag, and also 00302 * test for the validity of that root (e.g., that a drive d:/ or network 00303 * share //machine/foovol/). 00304 * The function returns APR_ERELATIVE if filepath isn't rooted (an 00305 * error), APR_EINCOMPLETE if the root path is ambigious (but potentially 00306 * legitimate, e.g. "/" on Windows is incomplete because it doesn't specify 00307 * the drive letter), or APR_EBADPATH if the root is simply invalid. 00308 * APR_SUCCESS is returned if filepath is an absolute path. 00309 */ 00310 APR_DECLARE(apr_status_t) apr_filepath_root(const char **rootpath, 00311 const char **filepath, 00312 apr_int32_t flags, 00313 apr_pool_t *p); 00314 00315 /** 00316 * Merge additional file path onto the previously processed rootpath 00317 * @param newpath the merged paths returned 00318 * @param rootpath the root file path (NULL uses the current working path) 00319 * @param addpath the path to add to the root path 00320 * @param flags the desired APR_FILEPATH_ rules to apply when merging 00321 * @param p the pool to allocate the new path string from 00322 * @remark if the flag APR_FILEPATH_TRUENAME is given, and the addpath 00323 * contains wildcard characters ('*', '?') on platforms that don't support 00324 * such characters within filenames, the paths will be merged, but the 00325 * result code will be APR_EPATHWILD, and all further segments will not 00326 * reflect the true filenames including the wildcard and following segments. 00327 */ 00328 APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, 00329 const char *rootpath, 00330 const char *addpath, 00331 apr_int32_t flags, 00332 apr_pool_t *p); 00333 00334 /** 00335 * Split a search path into separate components 00336 * @param pathelts the returned components of the search path 00337 * @param liststr the search path (e.g., <tt>getenv("PATH")</tt>) 00338 * @param p the pool to allocate the array and path components from 00339 * @remark empty path componenta do not become part of @a pathelts. 00340 * @remark the path separator in @a liststr is system specific; 00341 * e.g., ':' on Unix, ';' on Windows, etc. 00342 */ 00343 APR_DECLARE(apr_status_t) apr_filepath_list_split(apr_array_header_t **pathelts, 00344 const char *liststr, 00345 apr_pool_t *p); 00346 00347 /** 00348 * Merge a list of search path components into a single search path 00349 * @param liststr the returned search path; may be NULL if @a pathelts is empty 00350 * @param pathelts the components of the search path 00351 * @param p the pool to allocate the search path from 00352 * @remark emtpy strings in the source array are ignored. 00353 * @remark the path separator in @a liststr is system specific; 00354 * e.g., ':' on Unix, ';' on Windows, etc. 00355 */ 00356 APR_DECLARE(apr_status_t) apr_filepath_list_merge(char **liststr, 00357 apr_array_header_t *pathelts, 00358 apr_pool_t *p); 00359 00360 /** 00361 * Return the default file path (for relative file names) 00362 * @param path the default path string returned 00363 * @param flags optional flag APR_FILEPATH_NATIVE to retrieve the 00364 * default file path in os-native format. 00365 * @param p the pool to allocate the default path string from 00366 */ 00367 APR_DECLARE(apr_status_t) apr_filepath_get(char **path, apr_int32_t flags, 00368 apr_pool_t *p); 00369 00370 /** 00371 * Set the default file path (for relative file names) 00372 * @param path the default path returned 00373 * @param p the pool to allocate any working storage 00374 */ 00375 APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p); 00376 00377 /** The FilePath character encoding is unknown */ 00378 #define APR_FILEPATH_ENCODING_UNKNOWN 0 00379 00380 /** The FilePath character encoding is locale-dependent */ 00381 #define APR_FILEPATH_ENCODING_LOCALE 1 00382 00383 /** The FilePath character encoding is UTF-8 */ 00384 #define APR_FILEPATH_ENCODING_UTF8 2 00385 00386 /** 00387 * Determine the encoding used internally by the FilePath functions 00388 * @param style points to a variable which receives the encoding style flag 00389 * @param p the pool to allocate any working storage 00390 * @remark Use @c apr_os_locale_encoding and/or @c apr_os_default_encoding 00391 * to get the name of the path encoding if it's not UTF-8. 00392 */ 00393 APR_DECLARE(apr_status_t) apr_filepath_encoding(int *style, apr_pool_t *p); 00394 /** @} */ 00395 00396 /** @} */ 00397 00398 #ifdef __cplusplus 00399 } 00400 #endif 00401 00402 #endif /* ! APR_FILE_INFO_H */

Generated on Thu Sep 16 13:47:09 2004 for Apache Portable Runtime by doxygen 1.3.7