2
0

fspr_file_info.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. #ifndef APR_FILE_INFO_H
  17. #define APR_FILE_INFO_H
  18. /**
  19. * @file fspr_file_info.h
  20. * @brief APR File Information
  21. */
  22. #include "fspr.h"
  23. #include "fspr_user.h"
  24. #include "fspr_pools.h"
  25. #include "fspr_tables.h"
  26. #include "fspr_time.h"
  27. #include "fspr_errno.h"
  28. #if APR_HAVE_SYS_UIO_H
  29. #include <sys/uio.h>
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif /* __cplusplus */
  34. /**
  35. * @defgroup fspr_file_info File Information
  36. * @ingroup APR
  37. * @{
  38. */
  39. /* Many applications use the type member to determine the
  40. * existance of a file or initialization of the file info,
  41. * so the APR_NOFILE value must be distinct from APR_UNKFILE.
  42. */
  43. /** fspr_filetype_e values for the filetype member of the
  44. * fspr_file_info_t structure
  45. * @warning: Not all of the filetypes below can be determined.
  46. * For example, a given platform might not correctly report
  47. * a socket descriptor as APR_SOCK if that type isn't
  48. * well-identified on that platform. In such cases where
  49. * a filetype exists but cannot be described by the recognized
  50. * flags below, the filetype will be APR_UNKFILE. If the
  51. * filetype member is not determined, the type will be APR_NOFILE.
  52. */
  53. typedef enum {
  54. APR_NOFILE = 0, /**< no file type determined */
  55. APR_REG, /**< a regular file */
  56. APR_DIR, /**< a directory */
  57. APR_CHR, /**< a character device */
  58. APR_BLK, /**< a block device */
  59. APR_PIPE, /**< a FIFO / pipe */
  60. APR_LNK, /**< a symbolic link */
  61. APR_SOCK, /**< a [unix domain] socket */
  62. APR_UNKFILE = 127 /**< a file of some other unknown type */
  63. } fspr_filetype_e;
  64. /**
  65. * @defgroup fspr_file_permissions File Permissions flags
  66. * @{
  67. */
  68. #define APR_FPROT_USETID 0x8000 /**< Set user id */
  69. #define APR_FPROT_UREAD 0x0400 /**< Read by user */
  70. #define APR_FPROT_UWRITE 0x0200 /**< Write by user */
  71. #define APR_FPROT_UEXECUTE 0x0100 /**< Execute by user */
  72. #define APR_FPROT_GSETID 0x4000 /**< Set group id */
  73. #define APR_FPROT_GREAD 0x0040 /**< Read by group */
  74. #define APR_FPROT_GWRITE 0x0020 /**< Write by group */
  75. #define APR_FPROT_GEXECUTE 0x0010 /**< Execute by group */
  76. #define APR_FPROT_WSTICKY 0x2000 /**< Sticky bit */
  77. #define APR_FPROT_WREAD 0x0004 /**< Read by others */
  78. #define APR_FPROT_WWRITE 0x0002 /**< Write by others */
  79. #define APR_FPROT_WEXECUTE 0x0001 /**< Execute by others */
  80. #define APR_FPROT_OS_DEFAULT 0x0FFF /**< use OS's default permissions */
  81. /* additional permission flags for fspr_file_copy and fspr_file_append */
  82. #define APR_FPROT_FILE_SOURCE_PERMS 0x1000 /**< Copy source file's permissions */
  83. /* backcompat */
  84. #define APR_USETID APR_FPROT_USETID /**< @deprecated @see APR_FPROT_USETID */
  85. #define APR_UREAD APR_FPROT_UREAD /**< @deprecated @see APR_FPROT_UREAD */
  86. #define APR_UWRITE APR_FPROT_UWRITE /**< @deprecated @see APR_FPROT_UWRITE */
  87. #define APR_UEXECUTE APR_FPROT_UEXECUTE /**< @deprecated @see APR_FPROT_UEXECUTE */
  88. #define APR_GSETID APR_FPROT_GSETID /**< @deprecated @see APR_FPROT_GSETID */
  89. #define APR_GREAD APR_FPROT_GREAD /**< @deprecated @see APR_FPROT_GREAD */
  90. #define APR_GWRITE APR_FPROT_GWRITE /**< @deprecated @see APR_FPROT_GWRITE */
  91. #define APR_GEXECUTE APR_FPROT_GEXECUTE /**< @deprecated @see APR_FPROT_GEXECUTE */
  92. #define APR_WSTICKY APR_FPROT_WSTICKY /**< @deprecated @see APR_FPROT_WSTICKY */
  93. #define APR_WREAD APR_FPROT_WREAD /**< @deprecated @see APR_FPROT_WREAD */
  94. #define APR_WWRITE APR_FPROT_WWRITE /**< @deprecated @see APR_FPROT_WWRITE */
  95. #define APR_WEXECUTE APR_FPROT_WEXECUTE /**< @deprecated @see APR_FPROT_WEXECUTE */
  96. #define APR_OS_DEFAULT APR_FPROT_OS_DEFAULT /**< @deprecated @see APR_FPROT_OS_DEFAULT */
  97. #define APR_FILE_SOURCE_PERMS APR_FPROT_FILE_SOURCE_PERMS /**< @deprecated @see APR_FPROT_FILE_SOURCE_PERMS */
  98. /** @} */
  99. /**
  100. * Structure for referencing directories.
  101. */
  102. typedef struct fspr_dir_t fspr_dir_t;
  103. /**
  104. * Structure for determining file permissions.
  105. */
  106. typedef fspr_int32_t fspr_fileperms_t;
  107. #if (defined WIN32) || (defined NETWARE)
  108. /**
  109. * Structure for determining the inode of the file.
  110. */
  111. typedef fspr_uint64_t fspr_ino_t;
  112. /**
  113. * Structure for determining the device the file is on.
  114. */
  115. typedef fspr_uint32_t fspr_dev_t;
  116. #else
  117. /** The inode of the file. */
  118. typedef ino_t fspr_ino_t;
  119. /**
  120. * Structure for determining the device the file is on.
  121. */
  122. typedef dev_t fspr_dev_t;
  123. #endif
  124. /**
  125. * @defgroup fspr_file_stat Stat Functions
  126. * @{
  127. */
  128. /** file info structure */
  129. typedef struct fspr_finfo_t fspr_finfo_t;
  130. #define APR_FINFO_LINK 0x00000001 /**< Stat the link not the file itself if it is a link */
  131. #define APR_FINFO_MTIME 0x00000010 /**< Modification Time */
  132. #define APR_FINFO_CTIME 0x00000020 /**< Creation or inode-changed time */
  133. #define APR_FINFO_ATIME 0x00000040 /**< Access Time */
  134. #define APR_FINFO_SIZE 0x00000100 /**< Size of the file */
  135. #define APR_FINFO_CSIZE 0x00000200 /**< Storage size consumed by the file */
  136. #define APR_FINFO_DEV 0x00001000 /**< Device */
  137. #define APR_FINFO_INODE 0x00002000 /**< Inode */
  138. #define APR_FINFO_NLINK 0x00004000 /**< Number of links */
  139. #define APR_FINFO_TYPE 0x00008000 /**< Type */
  140. #define APR_FINFO_USER 0x00010000 /**< User */
  141. #define APR_FINFO_GROUP 0x00020000 /**< Group */
  142. #define APR_FINFO_UPROT 0x00100000 /**< User protection bits */
  143. #define APR_FINFO_GPROT 0x00200000 /**< Group protection bits */
  144. #define APR_FINFO_WPROT 0x00400000 /**< World protection bits */
  145. #define APR_FINFO_ICASE 0x01000000 /**< if dev is case insensitive */
  146. #define APR_FINFO_NAME 0x02000000 /**< ->name in proper case */
  147. #define APR_FINFO_MIN 0x00008170 /**< type, mtime, ctime, atime, size */
  148. #define APR_FINFO_IDENT 0x00003000 /**< dev and inode */
  149. #define APR_FINFO_OWNER 0x00030000 /**< user and group */
  150. #define APR_FINFO_PROT 0x00700000 /**< all protections */
  151. #define APR_FINFO_NORM 0x0073b170 /**< an atomic unix fspr_stat() */
  152. #define APR_FINFO_DIRENT 0x02000000 /**< an atomic unix fspr_dir_read() */
  153. /**
  154. * The file information structure. This is analogous to the POSIX
  155. * stat structure.
  156. */
  157. struct fspr_finfo_t {
  158. /** Allocates memory and closes lingering handles in the specified pool */
  159. fspr_pool_t *pool;
  160. /** The bitmask describing valid fields of this fspr_finfo_t structure
  161. * including all available 'wanted' fields and potentially more */
  162. fspr_int32_t valid;
  163. /** The access permissions of the file. Mimics Unix access rights. */
  164. fspr_fileperms_t protection;
  165. /** The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE,
  166. * APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE.
  167. * If the type cannot be determined, the value is APR_UNKFILE.
  168. */
  169. fspr_filetype_e filetype;
  170. /** The user id that owns the file */
  171. fspr_uid_t user;
  172. /** The group id that owns the file */
  173. fspr_gid_t group;
  174. /** The inode of the file. */
  175. fspr_ino_t inode;
  176. /** The id of the device the file is on. */
  177. fspr_dev_t device;
  178. /** The number of hard links to the file. */
  179. fspr_int32_t nlink;
  180. /** The size of the file */
  181. fspr_off_t size;
  182. /** The storage size consumed by the file */
  183. fspr_off_t csize;
  184. /** The time the file was last accessed */
  185. fspr_time_t atime;
  186. /** The time the file was last modified */
  187. fspr_time_t mtime;
  188. /** The time the file was created, or the inode was last changed */
  189. fspr_time_t ctime;
  190. /** The pathname of the file (possibly unrooted) */
  191. const char *fname;
  192. /** The file's name (no path) in filesystem case */
  193. const char *name;
  194. /** The file's handle, if accessed (can be submitted to fspr_duphandle) */
  195. struct fspr_file_t *filehand;
  196. };
  197. /**
  198. * get the specified file's stats. The file is specified by filename,
  199. * instead of using a pre-opened file.
  200. * @param finfo Where to store the information about the file, which is
  201. * never touched if the call fails.
  202. * @param fname The name of the file to stat.
  203. * @param wanted The desired fspr_finfo_t fields, as a bit flag of APR_FINFO_
  204. values
  205. * @param pool the pool to use to allocate the new file.
  206. *
  207. * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
  208. * not be filled in, and you need to check the @c finfo->valid bitmask
  209. * to verify that what you're looking for is there.
  210. */
  211. APR_DECLARE(fspr_status_t) fspr_stat(fspr_finfo_t *finfo, const char *fname,
  212. fspr_int32_t wanted, fspr_pool_t *pool);
  213. /** @} */
  214. /**
  215. * @defgroup fspr_dir Directory Manipulation Functions
  216. * @{
  217. */
  218. /**
  219. * Open the specified directory.
  220. * @param new_dir The opened directory descriptor.
  221. * @param dirname The full path to the directory (use / on all systems)
  222. * @param pool The pool to use.
  223. */
  224. APR_DECLARE(fspr_status_t) fspr_dir_open(fspr_dir_t **new_dir,
  225. const char *dirname,
  226. fspr_pool_t *pool);
  227. /**
  228. * close the specified directory.
  229. * @param thedir the directory descriptor to close.
  230. */
  231. APR_DECLARE(fspr_status_t) fspr_dir_close(fspr_dir_t *thedir);
  232. /**
  233. * Read the next entry from the specified directory.
  234. * @param finfo the file info structure and filled in by fspr_dir_read
  235. * @param wanted The desired fspr_finfo_t fields, as a bit flag of APR_FINFO_
  236. values
  237. * @param thedir the directory descriptor returned from fspr_dir_open
  238. * @remark No ordering is guaranteed for the entries read.
  239. *
  240. * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
  241. * not be filled in, and you need to check the @c finfo->valid bitmask
  242. * to verify that what you're looking for is there.
  243. */
  244. APR_DECLARE(fspr_status_t) fspr_dir_read(fspr_finfo_t *finfo, fspr_int32_t wanted,
  245. fspr_dir_t *thedir);
  246. /**
  247. * Rewind the directory to the first entry.
  248. * @param thedir the directory descriptor to rewind.
  249. */
  250. APR_DECLARE(fspr_status_t) fspr_dir_rewind(fspr_dir_t *thedir);
  251. /** @} */
  252. /**
  253. * @defgroup fspr_filepath Filepath Manipulation Functions
  254. * @{
  255. */
  256. /** Cause fspr_filepath_merge to fail if addpath is above rootpath */
  257. #define APR_FILEPATH_NOTABOVEROOT 0x01
  258. /** internal: Only meaningful with APR_FILEPATH_NOTABOVEROOT */
  259. #define APR_FILEPATH_SECUREROOTTEST 0x02
  260. /** Cause fspr_filepath_merge to fail if addpath is above rootpath,
  261. * even given a rootpath /foo/bar and an addpath ../bar/bash
  262. */
  263. #define APR_FILEPATH_SECUREROOT 0x03
  264. /** Fail fspr_filepath_merge if the merged path is relative */
  265. #define APR_FILEPATH_NOTRELATIVE 0x04
  266. /** Fail fspr_filepath_merge if the merged path is absolute */
  267. #define APR_FILEPATH_NOTABSOLUTE 0x08
  268. /** Return the file system's native path format (e.g. path delimiters
  269. * of ':' on MacOS9, '\' on Win32, etc.) */
  270. #define APR_FILEPATH_NATIVE 0x10
  271. /** Resolve the true case of existing directories and file elements
  272. * of addpath, (resolving any aliases on Win32) and append a proper
  273. * trailing slash if a directory
  274. */
  275. #define APR_FILEPATH_TRUENAME 0x20
  276. /**
  277. * Extract the rootpath from the given filepath
  278. * @param rootpath the root file path returned with APR_SUCCESS or APR_EINCOMPLETE
  279. * @param filepath the pathname to parse for its root component
  280. * @param flags the desired rules to apply, from
  281. * <PRE>
  282. * APR_FILEPATH_NATIVE Use native path seperators (e.g. '\' on Win32)
  283. * APR_FILEPATH_TRUENAME Tests that the root exists, and makes it proper
  284. * </PRE>
  285. * @param p the pool to allocate the new path string from
  286. * @remark on return, filepath points to the first non-root character in the
  287. * given filepath. In the simplest example, given a filepath of "/foo",
  288. * returns the rootpath of "/" and filepath points at "foo". This is far
  289. * more complex on other platforms, which will canonicalize the root form
  290. * to a consistant format, given the APR_FILEPATH_TRUENAME flag, and also
  291. * test for the validity of that root (e.g., that a drive d:/ or network
  292. * share //machine/foovol/).
  293. * The function returns APR_ERELATIVE if filepath isn't rooted (an
  294. * error), APR_EINCOMPLETE if the root path is ambigious (but potentially
  295. * legitimate, e.g. "/" on Windows is incomplete because it doesn't specify
  296. * the drive letter), or APR_EBADPATH if the root is simply invalid.
  297. * APR_SUCCESS is returned if filepath is an absolute path.
  298. */
  299. APR_DECLARE(fspr_status_t) fspr_filepath_root(const char **rootpath,
  300. const char **filepath,
  301. fspr_int32_t flags,
  302. fspr_pool_t *p);
  303. /**
  304. * Merge additional file path onto the previously processed rootpath
  305. * @param newpath the merged paths returned
  306. * @param rootpath the root file path (NULL uses the current working path)
  307. * @param addpath the path to add to the root path
  308. * @param flags the desired APR_FILEPATH_ rules to apply when merging
  309. * @param p the pool to allocate the new path string from
  310. * @remark if the flag APR_FILEPATH_TRUENAME is given, and the addpath
  311. * contains wildcard characters ('*', '?') on platforms that don't support
  312. * such characters within filenames, the paths will be merged, but the
  313. * result code will be APR_EPATHWILD, and all further segments will not
  314. * reflect the true filenames including the wildcard and following segments.
  315. */
  316. APR_DECLARE(fspr_status_t) fspr_filepath_merge(char **newpath,
  317. const char *rootpath,
  318. const char *addpath,
  319. fspr_int32_t flags,
  320. fspr_pool_t *p);
  321. /**
  322. * Split a search path into separate components
  323. * @param pathelts the returned components of the search path
  324. * @param liststr the search path (e.g., <tt>getenv("PATH")</tt>)
  325. * @param p the pool to allocate the array and path components from
  326. * @remark empty path componenta do not become part of @a pathelts.
  327. * @remark the path separator in @a liststr is system specific;
  328. * e.g., ':' on Unix, ';' on Windows, etc.
  329. */
  330. APR_DECLARE(fspr_status_t) fspr_filepath_list_split(fspr_array_header_t **pathelts,
  331. const char *liststr,
  332. fspr_pool_t *p);
  333. /**
  334. * Merge a list of search path components into a single search path
  335. * @param liststr the returned search path; may be NULL if @a pathelts is empty
  336. * @param pathelts the components of the search path
  337. * @param p the pool to allocate the search path from
  338. * @remark emtpy strings in the source array are ignored.
  339. * @remark the path separator in @a liststr is system specific;
  340. * e.g., ':' on Unix, ';' on Windows, etc.
  341. */
  342. APR_DECLARE(fspr_status_t) fspr_filepath_list_merge(char **liststr,
  343. fspr_array_header_t *pathelts,
  344. fspr_pool_t *p);
  345. /**
  346. * Return the default file path (for relative file names)
  347. * @param path the default path string returned
  348. * @param flags optional flag APR_FILEPATH_NATIVE to retrieve the
  349. * default file path in os-native format.
  350. * @param p the pool to allocate the default path string from
  351. */
  352. APR_DECLARE(fspr_status_t) fspr_filepath_get(char **path, fspr_int32_t flags,
  353. fspr_pool_t *p);
  354. /**
  355. * Set the default file path (for relative file names)
  356. * @param path the default path returned
  357. * @param p the pool to allocate any working storage
  358. */
  359. APR_DECLARE(fspr_status_t) fspr_filepath_set(const char *path, fspr_pool_t *p);
  360. /** The FilePath character encoding is unknown */
  361. #define APR_FILEPATH_ENCODING_UNKNOWN 0
  362. /** The FilePath character encoding is locale-dependent */
  363. #define APR_FILEPATH_ENCODING_LOCALE 1
  364. /** The FilePath character encoding is UTF-8 */
  365. #define APR_FILEPATH_ENCODING_UTF8 2
  366. /**
  367. * Determine the encoding used internally by the FilePath functions
  368. * @param style points to a variable which receives the encoding style flag
  369. * @param p the pool to allocate any working storage
  370. * @remark Use @c fspr_os_locale_encoding and/or @c fspr_os_default_encoding
  371. * to get the name of the path encoding if it's not UTF-8.
  372. */
  373. APR_DECLARE(fspr_status_t) fspr_filepath_encoding(int *style, fspr_pool_t *p);
  374. /** @} */
  375. /** @} */
  376. #ifdef __cplusplus
  377. }
  378. #endif
  379. #endif /* ! APR_FILE_INFO_H */