![]() |
|
|||
File indexing completed on 2025-02-22 10:38:43
0001 /* 0002 * Copyright (c) CERN 2013-2017 0003 * 0004 * Copyright (c) Members of the EMI Collaboration. 2010-2013 0005 * See http://www.eu-emi.eu/partners for details on the copyright 0006 * holders. 0007 * 0008 * Licensed under the Apache License, Version 2.0 (the "License"); 0009 * you may not use this file except in compliance with the License. 0010 * You may obtain a copy of the License at 0011 * 0012 * http://www.apache.org/licenses/LICENSE-2.0 0013 * 0014 * Unless required by applicable law or agreed to in writing, software 0015 * distributed under the License is distributed on an "AS IS" BASIS, 0016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0017 * See the License for the specific language governing permissions and 0018 * limitations under the License. 0019 */ 0020 0021 #pragma once 0022 #ifndef GFAL_POSIX_API_H_ 0023 #define GFAL_POSIX_API_H_ 0024 0025 #if !defined(__GFAL2_H_INSIDE__) && !defined(__GFAL2_BUILD__) 0026 # warning "Direct inclusion of gfal2 headers is deprecated. Please, include only gfal_api.h or gfal_plugins_api.h" 0027 #endif 0028 0029 #include <sys/types.h> 0030 #include <fcntl.h> 0031 #include <dirent.h> 0032 #include <sys/stat.h> 0033 #include <stdlib.h> 0034 #include <stdio.h> 0035 #include <unistd.h> 0036 #include <errno.h> 0037 #ifndef ENOATTR 0038 #define ENOATTR ENODATA 0039 #endif 0040 #if defined __APPLE__ 0041 #include <sys/xattr.h> 0042 #else 0043 #if defined __GLIBC_PREREQ && __GLIBC_PREREQ(2,27) 0044 #include <sys/xattr.h> 0045 #else 0046 #include <attr/xattr.h> 0047 #endif 0048 #endif 0049 0050 #include <common/gfal_common.h> 0051 #include <common/gfal_constants.h> 0052 0053 #ifdef __cplusplus 0054 extern "C" 0055 { 0056 #endif 0057 0058 0059 /*! 0060 \defgroup posix_group POSIX-like API 0061 */ 0062 0063 /*! 0064 \addtogroup posix_group 0065 @{ 0066 */ 0067 0068 /** 0069 * Warnings about POSIX functions : some protocols do not permit a full POSIX support ( ex : no symlinks in srm:// URLs ) 0070 * In case of a call to a unsupported function, -1 code is return and an error is set to EPROTONOSUPPORT 0071 */ 0072 0073 0074 0075 /** 0076 * @brief change file access permissions 0077 * 0078 * gfal_chmod changes the permissions of each given file according to mode, 0079 * Similar behavior to the POSIX chmod ( man 2 chmod ) 0080 * 0081 * @param url : url of the file or the folder, can be in all supported protocols (lfn, srm, file, guid,..) 0082 * @param mode : right to configure 0083 * @return return 0 if success else -1 if errors occures. 0084 * In case of errors, see @ref gfal_posix_check_error() for error management 0085 */ 0086 int gfal_chmod(const char *url, mode_t mode); 0087 0088 /** 0089 * @brief change the name or location of a file 0090 * 0091 * gfal_rename will rename the specified files by replacing the first occurrence of from in their name by to. 0092 * gfal_rename implies two URL with the same protocols and generally on the same server. 0093 * Similar behavior to the POSIX rename ( man 2 rename ) 0094 * 0095 * @param oldurl : the old url of the file 0096 * @param newurl : the new url of the file 0097 * @return : return 0 if success, else -1 if errors. 0098 * In case of errors, see @ref gfal_posix_check_error() for error management 0099 */ 0100 int gfal_rename(const char *oldurl, const char *newurl); 0101 0102 0103 /** 0104 * @brief get the file status, follow links 0105 * 0106 * return informations about the given files 0107 * Similar behavior to the POSIX stat ( man 2 stat ) 0108 * 0109 * @param url : url of the file 0110 * @param st : pointer to an allocated struct stat 0111 * @return : return 0 if success, else -1 if errors. 0112 * In case of errors, see @ref gfal_posix_check_error() for error management 0113 */ 0114 int gfal_stat(const char *url, struct stat *st); 0115 0116 /** 0117 * @brief get the file status, does not follow links 0118 * 0119 * return informations about the given files and links 0120 * Similar behavior to the POSIX lstat ( man 2 lstat ) 0121 * 0122 * In case of protocols without the support of links, GFAL 2.0 \ 0123 * convert this call to @ref gfal_stat 0124 * 0125 * 0126 * @param url : url of the file 0127 * @param st : pointer to an allocated struct stat 0128 * @return : return 0 if success, else -1 if errors. 0129 * In case of errors, see @ref gfal_posix_check_error() for error management 0130 */ 0131 int gfal_lstat(const char *url, struct stat *st); 0132 0133 /** 0134 * @brief check user permissions for a file 0135 * 0136 * Similar behavior to the POSIX access ( man 2 access ) 0137 * 0138 * @param url : url of the file to access 0139 * @param amode : access mode to check (R_OK, W_OK, X_OK or F_OK) 0140 * @return This routine return 0 if the operation was successful, or -1 if error occured. 0141 * In case of errors, see @ref gfal_posix_check_error() for error management 0142 */ 0143 int gfal_access(const char *url, int amode); 0144 0145 /** 0146 * @brief resolve a link destination 0147 * 0148 * Similar behavior to the POSIX readlink ( man 2 readlink ) 0149 * 0150 * Some protocols can not support this functionality, \ 0151 * check the protocol specification for more information. 0152 * 0153 * @param url : url of the file to access, can be in supported protocols (lfn, srm, file, guid,..) 0154 * @param buff : buffer to fill 0155 * @param buffsiz : maximum size of the link destination 0156 * @return This routine return the size of the link destination \ 0157 * if the operation was successful, or -1 if error occured. 0158 * In case of errors, see @ref gfal_posix_check_error() for error management 0159 */ 0160 ssize_t gfal_readlink(const char *url, char *buff, size_t buffsiz); 0161 0162 /** 0163 * @brief create a symbolic link 0164 * 0165 * Similar behavior to the POSIX symlink ( man 2 symlink ) 0166 * 0167 * Some protocols can not support this functionality, \ 0168 * check the protocol specification for more information. 0169 * 0170 * @param oldurl : url of the original file 0171 * @param newurl : url of the symlink 0172 * @return This routine return 0 if the operation was successful, or -1 if error occured. 0173 * In case of errors, see @ref gfal_posix_check_error() for error management 0174 */ 0175 int gfal_symlink(const char *oldurl, const char *newurl); 0176 0177 /** 0178 * @brief unlink a file, delete it 0179 * 0180 * Similar behavior to the POSIX unlink ( man 2 unlink ) 0181 * 0182 * @param url : url of the file to delete 0183 * @return This routine return 0 if the operation was successful, or -1 if error occured. 0184 * In case of errors, see @ref gfal_posix_check_error() for error management 0185 */ 0186 int gfal_unlink(const char *url); 0187 0188 /** 0189 * @brief create a directory 0190 * 0191 * Similar behavior to the POSIX mkdir( man 2 mkdir ) 0192 * 0193 * @param url : url of the directory to create 0194 * @param mode : initial mode right of the directory 0195 * @return This routine return 0 if the operation was successful, or -1 if error occured. 0196 * In case of errors, see @ref gfal_posix_check_error() for error management 0197 */ 0198 int gfal_mkdir(const char *url, mode_t mode); 0199 0200 /** 0201 * @brief open a directory 0202 * 0203 * Similar behavior to the POSIX opendir ( man 2 opendir ) 0204 * 0205 * @param url : url of the directory to list 0206 * @return This routine return a directory descriptor if the operation was successful, or -1 if error occured. 0207 * In case of errors, see @ref gfal_posix_check_error() for error management 0208 */ 0209 DIR *gfal_opendir(const char *url); 0210 0211 /** 0212 * @brief read a directory 0213 * 0214 * the directory descriptor must be provided by @ref gfal_opendir 0215 * Similar behavior to the POSIX readdir ( man 2 readdir ) 0216 * 0217 * @param d : descriptor of the directory 0218 * @return This routine return the directory information if the operation was successful, 0219 * NULL if the end of the directory is reached 0220 * or if error occured. 0221 * In case of errors, see @ref gfal_posix_check_error() for error management 0222 */ 0223 struct dirent *gfal_readdir(DIR *d); 0224 0225 /** 0226 * @brief close a directory 0227 * 0228 * Similar behavior to the POSIX closedir ( man 2 closedir ) 0229 * 0230 * @param d : descriptor of the directory 0231 * @return This routine return 0 if the operation was successful, or -1 if error occured. 0232 * In case of errors, see @ref gfal_posix_check_error() for error management 0233 */ 0234 int gfal_closedir(DIR *d); 0235 0236 /** 0237 * @brief delete a directory 0238 * 0239 * Similar behavior to the POSIX rmdir ( man 2 rmdir ) 0240 * 0241 * @param url : url of the directory to suppress 0242 * @return This routine return 0 if the operation was successful, or -1 if error occured. 0243 * In case of errors, see @ref gfal_posix_check_error() for error management 0244 */ 0245 int gfal_rmdir(const char *url); 0246 0247 /** 0248 * @brief creat a file 0249 * 0250 * Similar behavior to the POSIX creat ( man 2 creat ) 0251 * gfal_creat is similar to @ref gfal_open with the flags O_CREAT|O_WRONLY|O_TRUNC 0252 * 0253 * @param url : url of the file to creat 0254 * @param mode : mode of the file. 0255 * @return This routine return a valid file descriptor if the operation is a success 0256 * or -1 if error occured. 0257 * In case of errors, see @ref gfal_posix_check_error() for error management 0258 */ 0259 int gfal_creat(const char *url, mode_t mode); 0260 0261 /** 0262 * @brief open a file 0263 * 0264 * Similar behavior to the POSIX open ( man 2 open ) 0265 * gfal_open supports the same flags than the POSIX open call 0266 * 0267 * O_TRUNC 0268 * If the file already exists and is a regular file and the open mode allows writing (i.e., is O_RDWR or O_WRONLY) it will be truncated to length 0. If the file is a FIFO or termi‐ 0269 * nal device file, the O_TRUNC flag is ignored. Otherwise the effect of O_TRUNC is unspecified. 0270 * 0271 * O_APPEND 0272 * The file is opened in append mode. Before each write(2), the file offset is positioned at the end of the file, as if with lseek(2). O_APPEND may lead to corrupted files on NFS 0273 * file systems if more than one process appends data to a file at once. This is because NFS does not support appending to a file, so the client kernel has to simulate it, which 0274 * can't be done without a race condition. 0275 * 0276 * O_CREAT 0277 * If the file does not exist it will be created. The owner (user ID) of the file is set to the effective user ID of the process. The group ownership (group ID) is set either to 0278 * the effective group ID of the process or to the group ID of the parent directory (depending on file system type and mount options, and the mode of the parent directory, see the 0279 * mount options bsdgroups and sysvgroups described in mount(8)). 0280 * 0281 * mode specifies the permissions to use in case a new file is created. This argument must be supplied when O_CREAT is specified in flags; if O_CREAT is not specified, then mode is 0282 * ignored. The effective permissions are modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask). Note that this mode only 0283 * applies to future accesses of the newly created file; the open() call that creates a read-only file may well return a read/write file descriptor. 0284 * 0285 * 0286 * 0287 * O_DIRECT 0288 * Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is useful in special situations, such as when applications do 0289 * their own caching. File I/O is done directly to/from user space buffers. The O_DIRECT flag on its own makes at an effort to transfer data synchronously, but does not give the 0290 * guarantees of the O_SYNC that data and necessary metadata are transferred. To guarantee synchronous I/O the O_SYNC must be used in addition to O_DIRECT. See NOTES below for fur‐ 0291 * ther discussion. 0292 * 0293 * O_LARGEFILE 0294 * (LFS) Allow files whose sizes cannot be represented in an off_t (but can be represented in an off64_t) to be opened. The _LARGEFILE64_SOURCE macro must be defined (before includ‐ 0295 * ing any header files) in order to obtain this definition. Setting the _FILE_OFFSET_BITS feature test macro to 64 (rather than using O_LARGEFILE) is the preferred method of 0296 * obtaining method of accessing large files on 32-bit systems 0297 * 0298 * 0299 * @param url : url of the file to open 0300 * @param flags : flags to use ( similar to open ) 0301 * @param mode (optional) : mode of the file in case of a new file. 0302 * @return This routine return a valid file descriptor if the operation is a success 0303 * or -1 if error occured. 0304 * In case of errors, see @ref gfal_posix_check_error() for error management 0305 */ 0306 int gfal_open(const char *url, int flags, ...); 0307 0308 /** 0309 * @brief reposition read/write file offset 0310 * 0311 * Similar behavior to the POSIX lseek ( man 2 lseek ) 0312 * 0313 * @param fd : gfal file descriptor of the file 0314 * @param off : offset to set 0315 * @param flags : offset mode 0316 * @return This routine return the current offset if the operation is a success 0317 * or -1 if error occured. 0318 * In case of errors, see @ref gfal_posix_check_error() for error management 0319 */ 0320 off_t gfal_lseek(int fd, off_t off, int flags); 0321 0322 /** 0323 * @brief close a gfal file descriptor 0324 * 0325 * Similar behavior to the POSIX close ( man 2 close ) 0326 * 0327 * @param fd : gfal file descriptor of the file 0328 * @return This routine return 0 if the operation is a success 0329 * or -1 if error occured. 0330 * In case of errors, see @ref gfal_posix_check_error() for error management 0331 */ 0332 int gfal_close(int fd); 0333 0334 /** 0335 * @brief read from a gfal file descriptor 0336 * 0337 * Similar behavior to the POSIX read ( man 2 read ) 0338 * 0339 * @param fd : gfal file descriptor of the file 0340 * @param buff : buffer for the read content 0341 * @param size : maximum size to read 0342 * @return On success, the number of bytes read is returned 0343 * (zero indicates end of file), and the file position is advanced 0344 * by this number. It is not an error if this number is 0345 * smaller than the number of bytes requested.In case of errors, 0346 * see @ref gfal_posix_check_error() for error management 0347 * In case of errors, see @ref gfal_posix_check_error() for error management 0348 */ 0349 ssize_t gfal_read(int fd, void *buff, size_t size); 0350 0351 /** 0352 * @brief write from a gfal file descriptor 0353 * 0354 * Similar behavior to the POSIX write ( man 2 write ) 0355 * 0356 * @param fd : gfal file descriptor of the file 0357 * @param buff : buffer for the write content 0358 * @param size : maximum size to write 0359 * @return On success, the number of bytes written is returned. 0360 * In case of errors, -1 is returned 0361 * see @ref gfal_posix_check_error() for error management 0362 */ 0363 ssize_t gfal_write(int fd, const void *buff, size_t size); 0364 0365 /** 0366 * @brief flush the given file descriptor 0367 * 0368 * flush the current fiel descriptor, clear the cache \ 0369 * and commit the changes. 0370 * This call is reserved fora futur usage. 0371 * 0372 * @param fd : gfal file descriptor of the file 0373 * @return On success, return 0. 0374 * In case of errors, -1 is returned 0375 * see @ref gfal_posix_check_error() for error management 0376 */ 0377 int gfal_flush(int fd); 0378 0379 /** 0380 * @brief parallel read from a gfal file descriptor 0381 * 0382 * Similar behavior to the POSIX pread ( man 2 pread ) 0383 * 0384 * In gfal2, this call is thread-safe and allows the usage of \ 0385 * parallels read at the same time on the same file descriptor. 0386 * 0387 * This is the recommended way to execute parallels transfers. 0388 * 0389 * This gfal_pread is emulated on filesystem that does not support it 0390 * explicitely ( ex : rfio ) 0391 * 0392 * @param fd : gfal file descriptor of the file 0393 * @param buff : buffer for the read content 0394 * @param size : maximum size to read 0395 * @param offset : offset where the read start 0396 * @return On success, the number of bytes read is returned 0397 * (zero indicates end of file), and the file position is advanced 0398 * by this number. It is not an error if this number is 0399 * smaller than the number of bytes requested.In case of errors, 0400 * see @ref gfal_posix_check_error() for error management 0401 * In case of errors, see @ref gfal_posix_check_error() for error management 0402 */ 0403 ssize_t gfal_pread(int fd, void *buff, size_t size, off_t offset); 0404 0405 /** 0406 * @brief parallel write from a gfal file descriptor 0407 * 0408 * Similar behavior to the POSIX pwrite ( man 2 pwrite ) 0409 * 0410 * In gfal2, this function is thread-safe and allows the usage of 0411 * parallels write at the same time on the same file descriptor. 0412 * 0413 * This is the recommended way to execute parallels transfers. 0414 * 0415 * This gfal_pwrite is emulated on filesystem that does not support it 0416 * explicitely ( ex : rfio ) 0417 * 0418 * @param fd : gfal file descriptor of the file 0419 * @param buff : buffer for the write content 0420 * @param size : maximum size to write 0421 * @param offset : offset where the write start 0422 * @return On success, the number of bytes read is returned 0423 * (zero indicates end of file), and the file position is advanced 0424 * by this number. It is not an error if this number is 0425 * smaller than the number of bytes requested.In case of errors, 0426 * see @ref gfal_posix_check_error() for error management 0427 * In case of errors, see @ref gfal_posix_check_error() for error management 0428 */ 0429 ssize_t gfal_pwrite(int fd, const void *buff, size_t size, off_t offset); 0430 0431 /** 0432 * @brief retrieve an extended attribute value 0433 * 0434 * similar to the getxattr function 0435 * 0436 * In gfal2, this is the standard way to interact \ 0437 * with advanced file properties 0438 * 0439 * ex : gfal_getxattr("srm://myurl/endpoint", "user.replicas", 0440 * buff, 256); 0441 * 0442 * @param url : url of the file 0443 * @param name : key of the extended attribute 0444 * @param value : buffer for the extended attribute value 0445 * @param size : maximum size of the buffer 0446 * @return On success, return the size of the extended attribute. 0447 * In case of errors, -1 is returned 0448 * see @ref gfal_posix_check_error() for error management 0449 */ 0450 ssize_t gfal_getxattr(const char *url, const char *name, 0451 void *value, size_t size); 0452 0453 /** 0454 * @brief retrieve a list of the extended attributes availables 0455 * 0456 * similar to the etxattr function 0457 * 0458 * 0459 * @param url : url of the file 0460 * @param list : buffer for the list of availables attributes concatened. 0461 * @param size : maximum size of the buffer 0462 * @return On success, return the size of the list. 0463 * In case of errors, -1 is returned 0464 * see @ref gfal_posix_check_error() for error management 0465 */ 0466 ssize_t gfal_listxattr(const char *url, char *list, size_t size); 0467 0468 /** 0469 * @brief define an extended attribute value 0470 * 0471 * similar to the listxattr function 0472 * 0473 * In gfal2, this is the standard way to interact \ 0474 * with advanced file properties 0475 * 0476 * ex : gfal_setxattr("srm://myurl/endpoint", "user.status", 0477 * "ONLINE", strlen("ONLINE"),0); 0478 * // -> simple brings_online 0479 * 0480 * @param url : url of the file 0481 * @param name : key of the extended attribute 0482 * @param value : buffer for the extended attribute value 0483 * @param size : size of the attribute value 0484 * @param flags : mode 0485 * @return On success, return 0 . 0486 * In case of errors, -1 is returned 0487 * see @ref gfal_posix_check_error() for error management 0488 */ 0489 0490 int gfal_setxattr(const char *url, const char *name, 0491 const void *value, size_t size, int flags); 0492 0493 /** 0494 * @brief delete a extended attribute value 0495 * 0496 * similar to the removexattr function 0497 * 0498 * 0499 * @param url : url of the file 0500 * @param name : key of the extended attribute 0501 * @return On success, return 0. 0502 * In case of errors, -1 is returned 0503 * see @ref gfal_posix_check_error() for error management 0504 */ 0505 int gfal_removexattr(const char *url, const char *name); 0506 0507 /** 0508 * safe and easy error management : 0509 * -> if last error 0510 * -> print on stderr, return 1 0511 * -> else do nothing 0512 * @return 0 if no error, 1 else 0513 */ 0514 GFAL2_DEPRECATED_NOALT int gfal_posix_check_error(); 0515 0516 /** 0517 * clear the last error \ 0518 * provided for convenience. 0519 */ 0520 void gfal_posix_clear_error(); 0521 0522 /** 0523 * display the last error to the standard output \ 0524 * and clear it. 0525 * provided for convenience. 0526 */ 0527 GFAL2_DEPRECATED_NOALT void gfal_posix_release_error(); 0528 0529 /** 0530 * Get the string representation of the last error 0531 * @param buff_err : buffer where string representation will be stored. 0532 * @param s_err : maximum message size 0533 * @return return pointer to buff_err for convenience 0534 */ 0535 char *gfal_posix_strerror_r(char *buff_err, size_t s_err); 0536 0537 /** 0538 * display the last error recorded to the standard output, 0539 * provided for convenience. 0540 */ 0541 GFAL2_DEPRECATED_NOALT void gfal_posix_print_error(); 0542 0543 /** 0544 * return the code associated with the last error. 0545 * In case of POSIX calls and when possible, this code is similar to the local errno 0546 * @return last error code or 0 if nothing 0547 */ 0548 int gfal_posix_code_error(); 0549 0550 /** 0551 * get a string representation of the gfal2 version 0552 */ 0553 const char *gfal2_version(); 0554 0555 /** 0556 * @brief get context for advanced operation 0557 * Return the gfal2 context used for POSIX operations 0558 * Allow to do advanced operation ( config, checksum, transfer ) on this context 0559 * @warning Delete this context leads to undefined behavior. 0560 */ 0561 gfal2_context_t gfal_posix_get_handle(); 0562 0563 /** 0564 @} 0565 End of the POSIX group 0566 */ 0567 #ifdef __cplusplus 0568 } 0569 #endif 0570 0571 0572 #endif /* GFAL_POSIX_API_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |