![]() |
|
|||
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_FILE_API_H_ 0023 #define GFAL_FILE_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 <unistd.h> 0034 #include <errno.h> 0035 #ifndef ENOATTR 0036 #define ENOATTR ENODATA 0037 #endif 0038 #if defined __APPLE__ 0039 #include <sys/xattr.h> 0040 #else 0041 #if defined __GLIBC_PREREQ && __GLIBC_PREREQ(2,27) 0042 #include <sys/xattr.h> 0043 #else 0044 #include <attr/xattr.h> 0045 #endif 0046 #endif 0047 0048 #include <glib.h> 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 file_group GFAL 2.0 generic file API 0061 0062 0063 GFAL 2.0 file API is the main entry point for 0064 file/directory operations 0065 0066 All functions report a EPROTONOSUPPORT GError if the url protocol 0067 does not support this operation. 0068 */ 0069 0070 /*! 0071 \addtogroup file_group 0072 @{ 0073 */ 0074 0075 /** 0076 * @briefcompute checksum 0077 * 0078 * Compute checksum function for a file url 0079 * @param context : gfal2 handle, see \ref gfal2_context_new 0080 * @param url : url of the file 0081 * @param check_type : string of the checksum type ( \ref GFAL_CHKSUM_MD5, \ref GFAL_CHKSUM_SHA1, .. ) 0082 * @param start_offset : offset in the file where the checksum calculation will start ( 0 : from begining ) 0083 * @param data_length : size of data to compute for the checksum after start_offset ( 0 -: full file ) 0084 * @param checksum_buffer : buffer with checksum string as result 0085 * @param buffer_length : maximum buffer length 0086 * @param err : GError error report 0087 * @return 0 if success, else -1 and err is be set 0088 * See gfal2 error system for more information \ref gfal2_error_system 0089 */ 0090 int gfal2_checksum(gfal2_context_t context, const char* url, const char* check_type, 0091 off_t start_offset, size_t data_length, 0092 char * checksum_buffer, size_t buffer_length, GError ** err); 0093 0094 /** 0095 * @brief permission check 0096 * 0097 * Check real user's permissions for a file 0098 * @param context : gfal2 handle, see \ref gfal2_context_new 0099 * @param url : url of the file 0100 * @param amode : mode of the access 0101 * @param err : GError error report 0102 * @return 0 if success, else -1 and err MUST be set properly 0103 * See gfal2 error system for more information \ref gfal2_error_system 0104 */ 0105 int gfal2_access(gfal2_context_t context, const char *url, int amode, GError** err); 0106 0107 /** 0108 * @brief change file access permissions 0109 * 0110 * Change the permissions of a file according to "mode" 0111 * @param context : gfal2 handle, see \ref gfal2_context_new 0112 * @param url : url of the file or the folder 0113 * @param mode : right to configure 0114 * @param err : GError error report 0115 * @return return 0 if success else -1 and err is be set 0116 * See gfal2 error system for more information \ref gfal2_error_system 0117 */ 0118 int gfal2_chmod(gfal2_context_t context, const char* url, mode_t mode, GError ** err); 0119 0120 /** 0121 * @brief change the name or location of a file 0122 * 0123 * Move ( or rename ) the file 'oldurl' to 'newurl' 0124 * @param context : gfal2 handle, see \ref gfal2_context_new 0125 * @param oldurl : the old url of the file 0126 * @param newurl : the new url of the file 0127 * @param err : GError error report 0128 * @return : return 0 if success, else -1 if errors. 0129 * See gfal2 error system for more information \ref gfal2_error_system 0130 */ 0131 int gfal2_rename(gfal2_context_t context, const char *oldurl, const char *newurl, GError ** err); 0132 0133 /** 0134 * @brief posix file status 0135 * 0136 * Get meta-data information about the file 'url' 0137 * @param context : gfal2 handle, see \ref gfal2_context_new 0138 * @param url : url of the file 0139 * @param buff : stat structure filled 0140 * @param err : GError error report 0141 */ 0142 int gfal2_stat(gfal2_context_t context, const char* url, struct stat* buff, GError ** err); 0143 0144 /** 0145 * @brief posix file status 0146 * 0147 * Get meta-data information about the file 'url' 0148 * same behavior than \ref gfal2_stat but return information 0149 * about the link itself if "url" is a symbolic link 0150 * 0151 * @param context : gfal2 handle, see \ref gfal2_context_new 0152 * @param url : url of the file 0153 * @param buff : stat structure filled 0154 * @param err : GError error report 0155 */ 0156 int gfal2_lstat(gfal2_context_t context, const char* url, struct stat* buff, GError ** err); 0157 0158 /** 0159 * @brief create directory 0160 * 0161 * Create a directory at the address 'url' 0162 * 0163 * @param context : gfal2 handle, see \ref gfal2_context_new 0164 * @param url : url of the file 0165 * @param mode : directory file rights 0166 * @param err : GError error report 0167 */ 0168 int gfal2_mkdir(gfal2_context_t context, const char* url, mode_t mode, GError ** err); 0169 0170 /** 0171 * @brief create directory 0172 * 0173 * Create a directory at the address 'url' 0174 * Create all the parent drectories and 0175 * does not return an error if the directory already exist 0176 * 0177 * @param context : gfal2 handle, see \ref gfal2_context_new 0178 * @param url : url of the file 0179 * @param mode : directory file rights 0180 * @param err : GError error report 0181 */ 0182 int gfal2_mkdir_rec(gfal2_context_t context, const char* url, mode_t mode, GError ** err); 0183 0184 /** 0185 * @brief suppress a directory 0186 * 0187 * Suppress a directory at the address 'url' 0188 * @param context : gfal2 handle, see \ref gfal2_context_new 0189 * @param url : url of the file 0190 * @param err : GError error report 0191 * @return 0 if success, negative value if error, set err properly in case of error 0192 */ 0193 int gfal2_rmdir(gfal2_context_t context, const char* url, GError ** err); 0194 0195 /** 0196 * @brief open a directory for content listing 0197 * 0198 * Return a directory handle for content listing 0199 * 0200 * @param context : gfal2 handle, see \ref gfal2_context_new 0201 * @param url : url of the file 0202 * @param err : GError error report 0203 * @return a directory handle in case of success or NULL if error occurs, set err properly in case of error 0204 */ 0205 DIR* gfal2_opendir(gfal2_context_t context, const char* url, GError ** err); 0206 0207 /** 0208 * @brief return the next directory entry 0209 * 0210 * @param context : gfal2 handle, see \ref gfal2_context_new 0211 * @param d : directory handle created by \ref gfal2_opendir 0212 * @param err : GError error report 0213 * @return pointer to a dirent struct if success, NULL if end of listing or error, 0214 * set err properly in case of error 0215 */ 0216 struct dirent* gfal2_readdir(gfal2_context_t context, DIR* d, GError ** err); 0217 0218 /** 0219 * @brief return the next directory entry in addition of the entry meta-data 0220 * 0221 * readdirpp get both of the directory entry informations and the stat 0222 * informations in one operation, improving the performance in case of remote file system 0223 * 0224 * @param context : gfal2 handle, see \ref gfal2_context_new 0225 * @param d : directory handle created by \ref gfal2_opendir 0226 * @param st : the file stats will be stored here 0227 * @param err : GError error report 0228 * @return pointer to a dirent struct and configure st with the meta-data information if success, NULL if end of listing or error, set err properly in case of error 0229 */ 0230 struct dirent* gfal2_readdirpp(gfal2_context_t context, DIR* d, struct stat* st, GError ** err); 0231 0232 /** 0233 * @brief close a directory handle 0234 * 0235 * @param context : gfal2 handle, see \ref gfal2_context_new 0236 * @param d : directory handle created by \ref gfal2_opendir 0237 * @param err : GError error report 0238 * @return 0 if success, negative value if error, set err properly in case of error 0239 */ 0240 int gfal2_closedir(gfal2_context_t context, DIR* d, GError ** err); 0241 0242 /** 0243 * @brief create a symbolic link 0244 * 0245 * Symbolic links are not supported by all protocols, in case of non-supported feature 0246 * GFAL2 always return an error and set err to the code EPROTONOSUPPORT 0247 * 0248 * @param context : gfal2 handle, see \ref gfal2_context_new 0249 * @param oldurl : origin file 0250 * @param newurl : symbolic link path 0251 * @param err : GError error report 0252 * @return 0 if success, negative value if error, set err properly in case of error 0253 */ 0254 int gfal2_symlink(gfal2_context_t context, const char* oldurl, const char* newurl, GError ** err); 0255 0256 /** 0257 * @brief read a symbolic link value, provide the linked file path 0258 * 0259 * Symbolic links are not supported by all protocols, in case of non-supported feature 0260 * GFAL2 always return an error and set err to the code EPROTONOSUPPORT. 0261 * gfal2_readlink follows the POSIX behavior and does not add a null byte at the end of the buffer if the link is truncated. 0262 * 0263 * @param context : gfal2 handle, see \ref gfal2_context_new 0264 * @param url : path of the symbolic link to read 0265 * @param buff : buffer for symbolic link value 0266 * @param buffsiz : maximum number of bytes to write 0267 * @param err : GError error report 0268 * @return size of the link value in bytes if success, negative value if error. set err properly in case of error 0269 */ 0270 ssize_t gfal2_readlink(gfal2_context_t context, const char* url, char* buff, size_t buffsiz, GError ** err); 0271 0272 /** 0273 * @brief Delete a file entry 0274 * 0275 * Does not work for Collections or directory. 0276 * 0277 * @param context : gfal2 handle, see \ref gfal2_context_new 0278 * @param url : path of the file to delete 0279 * @param err : GError error report 0280 * @return 0 if success, -1 if error. set err properly in case of error 0281 */ 0282 int gfal2_unlink(gfal2_context_t context, const char* url, GError ** err); 0283 0284 /** 0285 * @brief list extended attributes of a resource. 0286 * 0287 * Extended attributes keys are concatenated in the buffer and separated by a null character 0288 * 0289 * @param context : gfal2 handle, see \ref gfal2_context_new 0290 * @param url : path of the resource 0291 * @param list : buffer for the extended attribute keys 0292 * @param size : maximum size of the buffer to write 0293 * @param err : GError error report 0294 * @return the size of the concatenated xattr keys in bytes if success, -1 if error. set err properly in case of errors. 0295 */ 0296 ssize_t gfal2_listxattr (gfal2_context_t context, const char *url, char *list, size_t size, GError ** err); 0297 0298 /** 0299 * @brief get an extended attribute value of a resource. 0300 * 0301 * @param context : gfal2 handle, see \ref gfal2_context_new 0302 * @param url : path of the resource 0303 * @param name : key of the extended attribute 0304 * @param value : buffer for the extended attribute value 0305 * @param size : maximum size of the buffer to write 0306 * @param err : GError error report 0307 * @return the size of the xattr value in bytes if success, -1 if error. set err properly in case of errors. 0308 */ 0309 ssize_t gfal2_getxattr (gfal2_context_t context, const char *url, const char *name, 0310 void *value, size_t size, GError ** err); 0311 0312 /** 0313 * @brief set an extended attribute value of a resource. 0314 * 0315 * @param context : gfal2 handle, see \ref gfal2_context_new 0316 * @param url : path of the resource 0317 * @param name : key of the extended attribute to define/set 0318 * @param value : new value of the xattr 0319 * @param size : size of the data 0320 * @param flags : xattr flag, XATTR_CREATE specifies a pure create, which fails if the named attribute exists already. XATTR_REPLACE specifies a pure 0321 * replace operation, which fails if the named attribute does not already exist. By default (no flags), the extended attribute will be created if need be, or will simply replace the value if the 0322 * attribute exists. 0323 * 0324 * @param err : GError error report 0325 * @return 0 if success, -1 if error. set err properly in case of errors. 0326 */ 0327 int gfal2_setxattr (gfal2_context_t context, const char *url, const char *name, 0328 const void *value, size_t size, int flags, GError ** err); 0329 0330 /** 0331 * @brief Bring online a file 0332 * 0333 * @param context : gfal2 handle, see \ref gfal2_context_new 0334 * @param url : url of the file 0335 * @param pintime : pin time 0336 * @param timeout : timeout 0337 * @param token : The token will be put in the buffer pointed by this 0338 * @param tsize: The size of the buffer pointed by token 0339 * @param async: Asynchronous request (does not block if != 0) 0340 * @param err : GError error report 0341 * @return 0 if the request has been queued, > 0 if the file is pinned, < 0 on error 0342 */ 0343 int gfal2_bring_online(gfal2_context_t context, const char* url, 0344 time_t pintime, time_t timeout, 0345 char* token, size_t tsize, 0346 int async, 0347 GError ** err); 0348 0349 /** 0350 * @brief Bring online a file 0351 * 0352 * @param context : gfal2 handle, see \ref gfal2_context_new 0353 * @param url : url of the file 0354 * @param metadata : Staging metadata 0355 * @param pintime : pin time 0356 * @param timeout : timeout 0357 * @param token : The token will be put in the buffer pointed by this 0358 * @param tsize : The size of the buffer pointed by token 0359 * @param async : Asynchronous request (does not block if != 0) 0360 * @param err : GError error report 0361 * @return 0 if the request has been queued, > 0 if the file is pinned, < 0 on error 0362 */ 0363 int gfal2_bring_online_v2(gfal2_context_t context, 0364 const char* url, const char* metadata, 0365 time_t pintime, time_t timeout, 0366 char* token, size_t tsize, 0367 int async, 0368 GError ** err); 0369 0370 /** 0371 * @brief Check for a bring online request 0372 * 0373 * @param context : gfal2 handle, see \ref gfal2_context_new 0374 * @param url : url of the file 0375 * @param token : as set by gfal2_bring_online 0376 * @param err : GError error report 0377 * @return 0 if the request is queued, > 0 if the file is pinned, < 0 on error 0378 */ 0379 int gfal2_bring_online_poll(gfal2_context_t context, const char* url, 0380 const char* token, GError ** err); 0381 0382 /** 0383 * @brief Release a file 0384 * 0385 * @param context : gfal2 handle, see \ref gfal2_context_new 0386 * @param url : url of the file 0387 * @param token : as set by gfal2_bring_online 0388 * @param err : GError error report 0389 * @return 0 if the file was released, < 0 on error 0390 */ 0391 int gfal2_release_file(gfal2_context_t context, const char* url, 0392 const char* token, GError ** err); 0393 0394 /** 0395 * @brief Check available QoS classes supported by the endpoint 0396 * 0397 * @param context : gfal2 handle, see \ref gfal2_context_new 0398 * @param url : url of the endpoint 0399 * @param type : QoS type of the entity 0400 * @param buff : buffer for the QoS classes string 0401 * @param s_buff : maximum size of the buffer to write 0402 * @param err : GError error report 0403 * @return the size of the QoS classes string in bytes if success, -1 if error 0404 */ 0405 ssize_t gfal2_qos_check_classes(gfal2_context_t context, const char *url, const char *type, 0406 char *buff, size_t s_buff, GError **err); 0407 0408 /** 0409 * @brief Check QoS of a file 0410 * 0411 * @param context : gfal2 handle, see \ref gfal2_context_new 0412 * @param url : url of the file 0413 * @param buff : buffer for the file QoS class 0414 * @param s_buff : maximum size of the buffer to write 0415 * @param err : GError error report 0416 * @return the size of the QoS class value in bytes if success, -1 if error 0417 */ 0418 ssize_t gfal2_check_file_qos(gfal2_context_t context, const char *url, 0419 char *buff, size_t s_buff, GError **err); 0420 0421 /** 0422 * @brief Check available QoS transitions of a QoS class 0423 * 0424 * @param context : gfal2 handle, see \ref gfal2_context_new 0425 * @param qos_class_url : url of the QoS class 0426 * @param buff : buffer for the QoS transitions string 0427 * @param s_buff : maximum size of the buffer to write 0428 * @param err : GError error report 0429 * @return the size of the QoS transitions string in bytes if success, -1 if error 0430 */ 0431 ssize_t gfal2_check_available_qos_transitions(gfal2_context_t context, const char *qos_class_url, 0432 char *buff, size_t s_buff, GError **err); 0433 0434 /** 0435 * @brief Check target QoS of a file 0436 * 0437 * @param context : gfal2 handle, see \ref gfal2_context_new 0438 * @param url : url of the file 0439 * @param buff : buffer for the target QoS class 0440 * @param s_buff : maximum size of the buffer to write 0441 * @param err : GError error report 0442 * @return the size of the target QoS class value in bytes if success, -1 if error 0443 * 0444 * @note Usually available during QoS transitions 0445 */ 0446 ssize_t gfal2_check_target_qos(gfal2_context_t context, const char *url, 0447 char *buff, size_t s_buff, GError **err); 0448 0449 /** 0450 * @brief Request the QoS transition of a CDMI object 0451 * 0452 * @param context : gfal2 handle, see \ref gfal2_context_new 0453 * @param url : url of the file 0454 * @param target_qos : the target QoS class 0455 * @param err : GError error report 0456 * @return 0 if success, -1 if error 0457 */ 0458 int gfal2_change_object_qos(gfal2_context_t context, const char *url, 0459 const char *target_qos, GError **err); 0460 0461 /** 0462 * @brief Retrieve a Storage Element token for a given resource 0463 * 0464 * @param context : gfal2 handle, see \ref gfal2_context_new 0465 * @param url : url of the resource 0466 * @param issuer : the token issuer endpoint (optional) 0467 * @param write_access : write access flag 0468 * @param validity : token validity in minutes 0469 * @param activities : array of activities for access request 0470 * @param buff : buffer for the token content 0471 * @param s_buff : maximum buffer size 0472 * @param err : GError error report 0473 * @return the size of the token value in bytes if success, -1 if error 0474 */ 0475 ssize_t gfal2_token_retrieve(gfal2_context_t context, const char* url, const char* issuer, 0476 gboolean write_access, unsigned validity, const char* const* activities, 0477 char* buff, size_t s_buff, GError** err); 0478 0479 /** 0480 * @brief Bring online a file 0481 * 0482 * @param context : gfal2 handle, see \ref gfal2_context_new 0483 * @param nbfiles : number of files 0484 * @param urls : urls of files 0485 * @param pintime : pin time 0486 * @param timeout : timeout 0487 * @param token : The token will be put in the buffer pointed by this 0488 * @param tsize : The size of the buffer pointed by token 0489 * @param async: Asynchronous request (does not block if != 0) 0490 * @param errors : Preallocated array of nbfiles pointers to GError. User must allocate and free. 0491 * @return 0 if the request has been queued, > 0 if the file is pinned, < 0 on error 0492 * @note Even if the result is > 0, you need to check each individual file status 0493 */ 0494 int gfal2_bring_online_list(gfal2_context_t context, int nbfiles, const char* const* urls, 0495 time_t pintime, time_t timeout, 0496 char* token, size_t tsize, 0497 int async, 0498 GError ** errors); 0499 0500 /** 0501 * @brief Bring online a file 0502 * 0503 * @param context : gfal2 handle, see \ref gfal2_context_new 0504 * @param nbfiles : number of files 0505 * @param urls : urls of files 0506 * @param metadata : Staging metadata array 0507 * @param pintime : pin time 0508 * @param timeout : timeout 0509 * @param token : The token will be put in the buffer pointed by this 0510 * @param tsize : The size of the buffer pointed by token 0511 * @param async : Asynchronous request (does not block if != 0) 0512 * @param errors : Preallocated array of nbfiles pointers to GError. User must allocate and free. 0513 * @return 0 if the request has been queued, > 0 if the file is pinned, < 0 on error 0514 * @note Even if the result is > 0, you need to check each individual file status 0515 */ 0516 int gfal2_bring_online_list_v2(gfal2_context_t context, int nbfiles, 0517 const char* const* urls, const char* const* metadata, 0518 time_t pintime, time_t timeout, 0519 char* token, size_t tsize, 0520 int async, 0521 GError ** errors); 0522 0523 /** 0524 * @brief Check for a bring online request 0525 * 0526 * @param context : gfal2 handle, see \ref gfal2_context_new 0527 * @param nbfiles : number of files 0528 * @param urls : urls of files 0529 * @param token : As set by gfal2_bring_online 0530 * @param errors : Preallocated array of nbfiles pointers to GError. User must allocate and free. 0531 * @return 0 if the request is queued, > 0 if the file is pinned, < 0 on error 0532 * @note Even if the result is > 0, you need to check each individual file status 0533 */ 0534 int gfal2_bring_online_poll_list(gfal2_context_t context, int nbfiles, const char* const* urls, 0535 const char* token, GError ** errors); 0536 0537 /** 0538 * @brief Perform a bulk release file 0539 * 0540 * @param context : gfal2 handle, see \ref gfal2_context_new 0541 * @param nbfiles : number of files 0542 * @param urls : paths of the files to delete 0543 * @param token : the token from the bring online request 0544 * @param errors : Preallocated array of nbfiles pointers to GError. User must allocate and free. 0545 * @note Even if the result is > 0, you need to check each individual file status 0546 */ 0547 int gfal2_release_file_list(gfal2_context_t context, int nbfiles, const char* const* urls, 0548 const char* token, GError ** errors); 0549 0550 /** 0551 * @brief Perform a bulk deletion 0552 * 0553 * Does not work for Collections or directories. 0554 * 0555 * @param context : gfal2 handle, see \ref gfal2_context_new 0556 * @param nbfiles : number of files 0557 * @param urls : paths of the files to delete 0558 * @param errors : Pre-allocated array with nbfiles pointers to errors. 0559 * It is the user's responsability to allocate and free. 0560 * @return 0 if success, -1 if error. set err properly in case of error 0561 * @note The plugin tried will be the one that matches the first url 0562 * @note If bulk deletion is not supported, gfal2_unlink will be called nbfiles times 0563 */ 0564 int gfal2_unlink_list(gfal2_context_t context, int nbfiles, const char* const* urls, GError ** errors); 0565 0566 /** 0567 * @brief abort a list of files 0568 * @param context : gfal2 handle, see \ref gfal2_context_new 0569 * @param nbfiles : number of files 0570 * @param urls : paths of the files to delete 0571 * @param token : the token from the bring online request 0572 * @param errors : Preallocated array of nbfiles pointers to GError. User must allocate and free. 0573 * @note Even if the result is > 0, you need to check each individual file status 0574 */ 0575 int gfal2_abort_files(gfal2_context_t context, int nbfiles, const char* const* urls, const char* token, GError ** errors); 0576 0577 0578 /** 0579 * @brief Check status of an archive request 0580 * 0581 * @param context : gfal2 handle, see \ref gfal2_context_new 0582 * @param url : url of the file 0583 * @param err : GError error report 0584 * @return 0 if the request is queued, > 0 if the file is archived, < 0 on error 0585 */ 0586 int gfal2_archive_poll(gfal2_context_t context, const char* url, GError ** err); 0587 0588 /** 0589 * @brief Check status for a list of archive requests 0590 * 0591 * @param context : gfal2 handle, see \ref gfal2_context_new 0592 * @param nbfiles : number of files 0593 * @param urls : urls of files 0594 * @param errors : Preallocated array of nbfiles pointers to GError. User must allocate and free. 0595 * @return 0 if the request is queued, > 0 if the file is archived, < 0 on error 0596 * @note Even if the result is > 0, you need to check each individual file status 0597 */ 0598 int gfal2_archive_poll_list(gfal2_context_t context, int nbfiles, const char* const* urls, 0599 GError ** errors); 0600 0601 /** 0602 * @brief Open a file, return GFAL2 file descriptor 0603 * 0604 * gfal_open supports the same flags than the POSIX open call 0605 * 0606 * O_TRUNC 0607 * 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‐ 0608 * nal device file, the O_TRUNC flag is ignored. Otherwise the effect of O_TRUNC is unspecified. 0609 * 0610 * O_APPEND 0611 * 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 0612 * 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 0613 * can't be done without a race condition. 0614 * 0615 * O_CREAT 0616 * 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 0617 * 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 0618 * mount options bsdgroups and sysvgroups described in mount(8)). 0619 * 0620 * 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 0621 * 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 0622 * 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. 0623 * 0624 * O_DIRECT 0625 * 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 0626 * 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 0627 * 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‐ 0628 * ther discussion. 0629 * 0630 * O_LARGEFILE 0631 * (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‐ 0632 * 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 0633 * obtaining method of accessing large files on 32-bit systems 0634 * 0635 * @param context : gfal2 handle, see \ref gfal2_context_new 0636 * @param url : url of the file to open 0637 * @param flags : flags to use ( similar to open ) 0638 * @param err : GError error report 0639 * @return This routine return a valid file descriptor if the operation is a success 0640 * or -1 if error occured. In case of Error, err is set properly 0641 */ 0642 int gfal2_open(gfal2_context_t context, const char * url, int flags, GError ** err); 0643 0644 /** 0645 * 0646 * Same than \ref gfal2_open but allow to specify the default right of the file 0647 */ 0648 int gfal2_open2(gfal2_context_t context, const char * url, int flag, mode_t mode, GError ** err); 0649 0650 /** 0651 * \ref gfal2_creat is equivalent to \ref gfal2_open2 with flags equal to O_CREAT|O_WRONLY|O_TRUNC. 0652 */ 0653 int gfal2_creat (gfal2_context_t context, const char *filename, mode_t mode, GError ** err); 0654 0655 /** 0656 * @brief read data from a GFAL2 file descriptor 0657 * 0658 * @param context : gfal2 handle, see \ref gfal2_context_new 0659 * @param fd : GFAL2 file descriptor of the file 0660 * @param buff : buffer for read data 0661 * @param s_buff : maximum size to read 0662 * @param err : GError error report* 0663 * @return On success, the number of bytes read is returned 0664 * (zero indicates end of file), and the file position is advanced 0665 * by this number. It is not an error if this number is 0666 * smaller than the number of bytes requested. or a negative value is returned when an error occurs 0667 * In case of Error, err is set properly 0668 */ 0669 ssize_t gfal2_read(gfal2_context_t context, int fd, void* buff, size_t s_buff, GError ** err); 0670 0671 /** 0672 * @brief write data to a GFAL2 file descriptor 0673 * 0674 * @param context : gfal2 handle, see \ref gfal2_context_new 0675 * @param fd : GFAL2 file descriptor of the file 0676 * @param buff : buffer with data to write 0677 * @param s_buff : maximum size to write 0678 * @param err : GError error report* 0679 * @return On success, the number of bytes written is returned 0680 * (zero indicates end of file), and the file position is advanced 0681 * by this number. It is not an error if this number is 0682 * smaller than the number of bytes requested. or a negative value is returned when an error occurs. 0683 * In case of Error, err is set properly 0684 */ 0685 ssize_t gfal2_write(gfal2_context_t context, int fd, const void *buff, size_t s_buff, GError ** err); 0686 0687 /** 0688 * @brief move the file cursor 0689 * 0690 * Move the file cursor of the GFAL2 file descriptor fd to offset 0691 * 0692 * @param context : gfal2 handle, see \ref gfal2_context_new 0693 * @param fd : file descriptor 0694 * @param offset : new position of the cursor 0695 * @param whence : directive to follow, can be SEEK_SET, SEEK_CUR or SEEK_END 0696 * @param err : GError error report 0697 * @return new cursor position if success, -1 if failure, set err properly in case of error. 0698 */ 0699 off_t gfal2_lseek (gfal2_context_t context, int fd, off_t offset, int whence, GError ** err); 0700 0701 /** 0702 * @brief close a file GFAL2 descriptor 0703 * 0704 * @param context : gfal2 handle, see \ref gfal2_context_new 0705 * @param fd : file descriptor 0706 * @param err : GError error report 0707 * @return new cursor position if success, -1 if failure, set err properly in case of error. 0708 */ 0709 int gfal2_close(gfal2_context_t context, int fd, GError ** err); 0710 0711 /** 0712 * @brief flush all buffered data for the given file descriptor 0713 * 0714 * @param context : gfal2 handle, see \ref gfal2_context_new 0715 * @param fd : file descriptor 0716 * @param err : GError error report 0717 * @return new cursor position if success, -1 if failure, set err properly in case of error. 0718 */ 0719 int gfal2_flush(gfal2_context_t context, int fd, GError ** err); 0720 0721 /** 0722 * @brief read from file descriptor at a given offset 0723 * 0724 * @param context : gfal2 handle, see \ref gfal2_context_new 0725 * @param fd : file descriptor 0726 * @param buffer: buffer for read data 0727 * @param count : maximum size to read 0728 * @param offset : operation offset 0729 * @param err : GError error report 0730 * @return number of read bytes, -1 on failure, set err properly in case of error. 0731 */ 0732 ssize_t gfal2_pread(gfal2_context_t context, int fd, void * buffer, size_t count, off_t offset, GError ** err); 0733 0734 /** 0735 * @brief write to file descriptor at a given offset 0736 * 0737 * @param context : gfal2 handle, see \ref gfal2_context_new 0738 * @param fd : file descriptor 0739 * @param buffer: buffer for read data 0740 * @param count : maximum size to write 0741 * @param offset : operation offset 0742 * @param err : GError error report 0743 * @return number of written bytes, -1 on failure, set err properly in case of error. 0744 */ 0745 ssize_t gfal2_pwrite(gfal2_context_t context, int fd, const void * buffer, size_t count, off_t offset, GError ** err); 0746 0747 /** 0748 @} 0749 End of the FILE group 0750 */ 0751 #ifdef __cplusplus 0752 } 0753 #endif 0754 0755 0756 #endif /* GFAL_FILE_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 |
![]() ![]() |