Functions to handle files and directories. More...
Data Structures | |
| struct | _Eina_File_Direct_Info |
| A structure to store informations of a path. More... | |
| struct | _Eina_Stat |
| A structure to store some file statistics. More... | |
| struct | _Eina_File_Line |
| A structure to store information of line. More... | |
| struct | _Eina_File |
| This is the underlying data structure that represents a file in Eina. More... | |
| struct | _Eina_File_Map |
| This represents a memory mapped region of a file. More... | |
| struct | _Eina_Lines_Iterator |
| This represents a line iterator a file. More... | |
Macros | |
| #define | EINA_PATH_MAX 8192 |
| The constant defined as the highest value for PATH_MAX. | |
| #define | EINA_FILE_DIR_LIST_CB(function) ((Eina_File_Dir_List_Cb)function) |
| cast to an Eina_File_Dir_List_Cb. More... | |
| #define | EINA_LOG_COLOR_DEFAULT EINA_COLOR_CYAN |
| Set the color for Eina log entries. | |
| #define | ERR(...) EINA_LOG_DOM_ERR(_eina_file_log_dom, __VA_ARGS__) |
| Macro for logging Eina errors. | |
| #define | WRN(...) EINA_LOG_DOM_WARN(_eina_file_log_dom, __VA_ARGS__) |
| Macro for logging Eina warnings. | |
| #define | INF(...) EINA_LOG_DOM_INFO(_eina_file_log_dom, __VA_ARGS__) |
| Macro for logging Eina info messages. | |
| #define | DBG(...) EINA_LOG_DOM_DBG(_eina_file_log_dom, __VA_ARGS__) |
| Macro for logging Eina debug messages. | |
Typedefs | |
|
typedef struct _Eina_File_Direct_Info | Eina_File_Direct_Info |
| A typedef to _Eina_File_Direct_Info. | |
| typedef struct _Eina_Stat | Eina_Stat |
| A typedef to _Eina_Stat. More... | |
| typedef struct _Eina_File_Line | Eina_File_Line |
| A typedef to _Eina_File_Line. | |
| typedef void(* | Eina_File_Dir_List_Cb )(const char *name, const char *path, void *data) |
| Type for a callback to be called when iterating over the files of a directory. More... | |
| typedef struct _Eina_File | Eina_File |
| A file handle. | |
| typedef Eina_Bool(* | Eina_File_Copy_Progress )(void *data, unsigned long long done, unsigned long long total) |
used to report progress during eina_file_copy(), where done is the bytes already copied and size is the total file size. More... | |
| typedef struct _Eina_File_Map | Eina_File_Map |
| Type definition for an Eina File Map. | |
| typedef struct _Eina_Lines_Iterator | Eina_Lines_Iterator |
| Type definition for an Eina Lines Iterator. | |
Enumerations | |
| enum | Eina_File_Type { EINA_FILE_UNKNOWN, EINA_FILE_FIFO, EINA_FILE_CHR, EINA_FILE_DIR, EINA_FILE_BLK, EINA_FILE_REG, EINA_FILE_LNK, EINA_FILE_SOCK, EINA_FILE_WHT } |
| file type in Eina_File_Direct_Info. More... | |
| enum | Eina_File_Populate { EINA_FILE_RANDOM, EINA_FILE_SEQUENTIAL, EINA_FILE_WILLNEED, EINA_FILE_POPULATE, EINA_FILE_DONTNEED, EINA_FILE_REMOVE } |
| File access type used in Eina_File_Direct_info. More... | |
| enum | Eina_File_Copy_Flags { EINA_FILE_COPY_DATA = 0, EINA_FILE_COPY_PERMISSION = (1 << 0), EINA_FILE_COPY_XATTR = (1 << 1) } |
| what to copy from file. | |
Functions | |
| EAPI Eina_Bool | eina_file_dir_list (const char *dir, Eina_Bool recursive, Eina_File_Dir_List_Cb cb, void *data) EINA_ARG_NONNULL(1 |
| List all files on the directory calling the function for every file found. More... | |
| EAPI Eina_Bool EAPI Eina_Array * | eina_file_split (char *path) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC |
| Split a path according to the delimiter of the filesystem. More... | |
| EAPI Eina_Iterator * | eina_file_ls (const char *dir) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC |
| Get an iterator to list the content of a directory. More... | |
| EAPI Eina_Iterator * | eina_file_stat_ls (const char *dir) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC |
| Get an iterator to list the content of a directory, with direct information. More... | |
| EAPI int | eina_file_statat (void *container, Eina_File_Direct_Info *info, Eina_Stat *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1 |
| Use information provided by Eina_Iterator of eina_file_stat_ls or eina_file_direct_ls to call stat in the most efficient way on your system. More... | |
| EAPI int EAPI int | eina_file_mkstemp (const char *templatename, Eina_Tmpstr **path) |
| Generate and create a uniquely named temporary file from template. More... | |
| EAPI Eina_Bool | eina_file_mkdtemp (const char *templatename, Eina_Tmpstr **path) |
| Generate and create a uniquely named temporary directory from template. More... | |
| EAPI Eina_Iterator * | eina_file_direct_ls (const char *dir) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC |
| Get an iterator to list the content of a directory, with direct information. More... | |
| EAPI char * | eina_file_path_sanitize (const char *path) |
| Sanitize file path. More... | |
| EAPI Eina_Bool | eina_file_copy (const char *src, const char *dst, Eina_File_Copy_Flags flags, Eina_File_Copy_Progress cb, const void *cb_data) EINA_ARG_NONNULL(1 |
| Copy one file to another using the fastest possible way, report progress. More... | |
| EAPI Eina_Bool EAPI Eina_File * | eina_file_open (const char *name, Eina_Bool shared) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC |
| Get a read-only handler to a file. More... | |
| EAPI Eina_File * | eina_file_virtualize (const char *virtual_name, const void *data, unsigned long long length, Eina_Bool copy) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) |
| Create a virtual file from a memory pointer. More... | |
| EAPI Eina_Bool | eina_file_virtual (Eina_File *file) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) |
| Tell if a file is a real file or only exist in memory. More... | |
| EAPI Eina_Bool | eina_file_refresh (Eina_File *file) |
| Refresh file information. More... | |
| EAPI Eina_File * | eina_file_dup (const Eina_File *file) |
| Dup a read-only handler of a previously open file. More... | |
| EAPI void | eina_file_close (Eina_File *file) |
| Unref file handler. More... | |
| EAPI size_t | eina_file_size_get (const Eina_File *file) |
| Get file size at open time. More... | |
| EAPI time_t | eina_file_mtime_get (const Eina_File *file) |
| Get the last modification time of an open file. More... | |
| EAPI const char * | eina_file_filename_get (const Eina_File *file) |
| Get the filename of an open file. More... | |
| EAPI Eina_Iterator * | eina_file_xattr_get (Eina_File *file) |
| Get the eXtended attribute of an open file. More... | |
| EAPI Eina_Iterator * | eina_file_xattr_value_get (Eina_File *file) |
| Get the eXtended attribute of an open file. More... | |
| EAPI void * | eina_file_map_all (Eina_File *file, Eina_File_Populate rule) |
| Map all the file to a buffer. More... | |
| EAPI void * | eina_file_map_new (Eina_File *file, Eina_File_Populate rule, unsigned long int offset, unsigned long int length) |
| Map a part of the file. More... | |
| EAPI void | eina_file_map_free (Eina_File *file, void *map) |
| Unref and unmap memory if possible. More... | |
| EAPI void | eina_file_map_populate (Eina_File *file, Eina_File_Populate rule, const void *map, unsigned long int offset, unsigned long int length) |
| Ask the OS to populate or otherwise pages of memory in file mapping. More... | |
| EAPI Eina_Iterator * | eina_file_map_lines (Eina_File *file) |
| Map line by line in memory efficiently with an Eina_Iterator. More... | |
| EAPI Eina_Bool | eina_file_map_faulted (Eina_File *file, void *map) |
| Tell if there was an IO error during the life of a mmaped file. More... | |
| Eina_Bool | eina_file_path_relative (const char *path) |
| Determines if a path is relative or absolute. More... | |
| Eina_Tmpstr * | eina_file_current_directory_get (const char *path, size_t len) |
| Gets the current directory and optionally appends a path to it. More... | |
| char * | eina_file_cleanup (Eina_Tmpstr *path) |
| Cleans up Eina after a file is no longer needed. More... | |
| void | eina_file_clean_close (Eina_File *file) |
| Closes and cleans up after an Eina file. More... | |
| void | eina_file_real_close (Eina_File *file) |
| Closes a file from the OS perspective. More... | |
| void | eina_file_flush (Eina_File *file, unsigned long int length) |
| Resets the internal housekeeping structures after a file has changed. More... | |
| void | eina_file_common_map_free (Eina_File *file, void *map, void(*free_func)(Eina_File_Map *map)) |
| Removes a mapped region from the file and frees the resources. More... | |
| void * | eina_file_virtual_map_all (Eina_File *file) |
| Map the entire contents fo a virtual file to a buffer. More... | |
| void * | eina_file_virtual_map_new (Eina_File *file, unsigned long int offset, unsigned long int length) |
| Map a part of a virtual file to a buffer. More... | |
| void | eina_file_virtual_map_free (Eina_File *file, void *map) |
| Unref and unmap memory if possible. More... | |
| unsigned int | eina_file_map_key_length (const void *key) |
| Get the length of a map key. More... | |
| int | eina_file_map_key_cmp (const unsigned long long int *key1, int key1_length, const unsigned long long int *key2, int key2_length) |
| Compares two map keys. More... | |
| int | eina_file_map_key_hash (const unsigned long long int *key, int key_length) |
| Creates a hash from a map key. More... | |
Variables | |
| Eina_Hash * | _eina_file_cache |
| A pointer to the global Eina file cache. More... | |
| Eina_Lock | _eina_file_lock_cache |
| The global file lock cache. | |
| int | _eina_file_log_dom |
| The global Eina log file domain. More... | |
Functions to handle files and directories.
This functions make it easier to do a number o file and directory operations such as getting the list of files in a directory, spliting paths and finding out file size and type.
See an example here.
This module performs internal housekeeping and utility tasks for Eina_File. It also provides the underlying data types for things like file handles, file maps and file iterators.
| #define EINA_FILE_DIR_LIST_CB | ( | function | ) | ((Eina_File_Dir_List_Cb)function) |
cast to an Eina_File_Dir_List_Cb.
| function | The function to cast. |
This macro casts function to Eina_File_Dir_List_Cb.
A typedef to _Eina_Stat.
| Eina_File_Dir_List_Cb |
Type for a callback to be called when iterating over the files of a directory.
| name | The file name EXCLUDING the path |
| path | The path passed to eina_file_dir_list() |
| data | The data passed to eina_file_dir_list() |
| Eina_File_Copy_Progress |
used to report progress during eina_file_copy(), where done is the bytes already copied and size is the total file size.
If returns EINA_FALSE, it will stop the copy.
| enum Eina_File_Type |
file type in Eina_File_Direct_Info.
| enum Eina_File_Populate |
File access type used in Eina_File_Direct_info.
| EAPI Eina_Bool eina_file_dir_list | ( | const char * | dir, |
| Eina_Bool | recursive, | ||
| Eina_File_Dir_List_Cb | cb, | ||
| void * | data | ||
| ) |
List all files on the directory calling the function for every file found.
| dir | The directory name. |
| recursive | Iterate recursively in the directory. |
| cb | The callback to be called. |
| data | The data to pass to the callback. |
This function calls cb for each file that is in dir. To have cb called on files that are in subdirectories of dir recursive should be EINA_TRUE. In other words if recursive is EINA_FALSE, only direct children of dir will be operated on, if recursive is EINA_TRUE the entire tree of files that is below dir will be operated on.
If cb or dir are NULL, or if dir is a string of size 0, or if dir can not be opened, this function returns EINA_FALSE immediately. otherwise, it returns EINA_TRUE.
Referenced by eina_module_arch_list_get(), and eina_module_list_get().
| EAPI Eina_Bool EAPI Eina_Array* eina_file_split | ( | char * | path | ) |
Split a path according to the delimiter of the filesystem.
| path | The path to split. |
This function splits path according to the delimiter of the used filesystem. If path is NULL or if the array can not be created, NULL is returned, otherwise, an array with each part of path is returned.
References eina_array_new(), and eina_array_push().
| EAPI Eina_Iterator* eina_file_ls | ( | const char * | dir | ) |
Get an iterator to list the content of a directory.
| dir | The name of the directory to list |
dir. On failure it will return NULL.Returns an iterator for shared strings, the name of each file in dir will only be fetched when advancing the iterator, which means there is very little cost associated with creating the list and stopping halfway through it.
References closedir(), EINA_MAGIC_SET, EINA_UNLIKELY, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, FUNC_ITERATOR_NEXT, and opendir().
| EAPI Eina_Iterator* eina_file_stat_ls | ( | const char * | dir | ) |
Get an iterator to list the content of a directory, with direct information.
| dir | The name of the directory to list |
Returns an iterator for Eina_File_Direct_Info, the name of each file in dir will only be fetched when advancing the iterator, which means there is cost associated with creating the list and stopping halfway through it.
References closedir(), eina_file_direct_ls(), EINA_MAGIC_SET, EINA_PATH_MAX, EINA_UNLIKELY, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, FUNC_ITERATOR_NEXT, and opendir().
| EAPI int eina_file_statat | ( | void * | container, |
| Eina_File_Direct_Info * | info, | ||
| Eina_Stat * | buf | ||
| ) |
Use information provided by Eina_Iterator of eina_file_stat_ls or eina_file_direct_ls to call stat in the most efficient way on your system.
| container | The container returned by the Eina_Iterator using eina_iterator_container_get(). |
| info | The content of the current Eina_File_Direct_Info provided by the Eina_Iterator |
| buf | Where to put the result of the stat |
0 is returned, On error -1 is returned and errno is set appropriately.This function calls fstatat or stat depending on what your system supports. This makes it efficient and simple to use on your side without complex detection already done inside Eina on what the system can do.
| EAPI int EAPI int eina_file_mkstemp | ( | const char * | templatename, |
| Eina_Tmpstr ** | path | ||
| ) |
Generate and create a uniquely named temporary file from template.
Generated file is opened with the open(2) O_EXCL flag.
| [in] | templatename | is a string. It must contain the six characters 'XXXXXX' at the end or directly followed by an extension as in 'prefixXXXXXX.ext'. |
| [out] | path | Where to put the name of the created file. If not NULL should be released by eina_tmpstr_del. |
file descriptor of the temporary file is returned, On error -1 is returned, in which case errno is set appropriately.This function calls mkstemp[s], generates a unique temporary filename from template, creates and opens the file, and returns an open file descriptor for the file.
If a filename extension was specified in templatename, then the new path will also contain this extension (since 1.10).
References eina_tmpstr_add(), evil_tmpdir_get(), mkstemp(), and mkstemps().
| EAPI Eina_Bool eina_file_mkdtemp | ( | const char * | templatename, |
| Eina_Tmpstr ** | path | ||
| ) |
Generate and create a uniquely named temporary directory from template.
| [in] | templatename | is a string. The last six characters of templatename must be XXXXXX. |
| [out] | path | Where to put the name of the created directory. If not NULL should be released by eina_tmpstr_del. |
EINA_TRUE is returned, On error EINA_FALSE is returned, in which case errno is set appropriately.This function calls mkdtemp. The directory is then created with permissions 0700.
References EINA_FALSE, eina_tmpstr_add(), EINA_TRUE, evil_tmpdir_get(), and mkdtemp().
| EAPI Eina_Iterator* eina_file_direct_ls | ( | const char * | dir | ) |
Get an iterator to list the content of a directory, with direct information.
| dir | The name of the directory to list |
NULL.Returns an iterator for Eina_File_Direct_Info, the name of each file in dir will only be fetched when advancing the iterator, which means there is cost associated with creating the list and stopping halfway through it.
References closedir(), EINA_MAGIC_SET, EINA_PATH_MAX, EINA_UNLIKELY, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, FUNC_ITERATOR_NEXT, and opendir().
Referenced by ecore_file_dir_is_empty(), ecore_file_ls(), ecore_file_recursive_rm(), edje_available_modules_get(), and eina_file_stat_ls().
| EAPI char* eina_file_path_sanitize | ( | const char * | path | ) |
Sanitize file path.
| path | The path to sanitize |
This function take care of adding the current working directory if it's a relative path and also remove all '..' and '//' reference in the original path.
References eina_file_cleanup(), eina_file_current_directory_get(), eina_file_path_relative(), and eina_tmpstr_strlen().
Referenced by efreet_desktop_new(), efreet_desktop_uncached_new(), efreet_icon_deprecated_user_dir_get(), efreet_icon_user_dir_get(), and eina_file_open().
| EAPI Eina_Bool eina_file_copy | ( | const char * | src, |
| const char * | dst, | ||
| Eina_File_Copy_Flags | flags, | ||
| Eina_File_Copy_Progress | cb, | ||
| const void * | cb_data | ||
| ) |
Copy one file to another using the fastest possible way, report progress.
This function will try splice if it is available. It will block until the whole file is copied or it fails.
During the progress it may call back cb with the progress summary.
| src | the source file. |
| dst | the destination file. |
| flags | controls what is copied (data is always copied). |
| cb | if provided will be called with file copy progress information. |
| cb_data | context data to provide to cb during copy. |
Get a read-only handler to a file.
| name | Filename to open |
| shared | Requested a shm |
Opens a file in read-only mode. name should be an absolute path. An Eina_File handle can be shared among multiple instances if shared is EINA_TRUE.
References _eina_file_cache, _eina_file_lock_cache, _Eina_File::delete_me, eina_file_clean_close(), eina_file_map_key_cmp(), eina_file_map_key_hash(), eina_file_map_key_length(), eina_file_path_sanitize(), EINA_FREE_CB, eina_hash_del(), eina_hash_direct_add(), eina_hash_find(), eina_hash_new(), eina_hash_pointer_new(), EINA_KEY_CMP, EINA_KEY_HASH, EINA_KEY_LENGTH, eina_lock_new(), eina_lock_release(), eina_lock_take(), EINA_MAGIC_SET, EINA_TRUE, ERR, fcntl(), _Eina_File::fd, _Eina_File::filename, _Eina_File::global_map, _Eina_File::inode, _Eina_File::length, _Eina_File::lock, _Eina_File::map, _Eina_File::mtime, _Eina_File::refcount, _Eina_File::rmap, _Eina_File::shared, and WRN.
Referenced by edje_file_collection_list(), edje_file_data_get(), edje_file_group_exists(), eet_identity_open(), and eet_open().
| EAPI Eina_File* eina_file_virtualize | ( | const char * | virtual_name, |
| const void * | data, | ||
| unsigned long long | length, | ||
| Eina_Bool | copy | ||
| ) |
Create a virtual file from a memory pointer.
| virtual_name | A virtual name for Eina_File, if NULL, a generated one will be given |
| data | The memory pointer to take data from |
| length | The length of the data in memory |
| copy | EINA_TRUE if the data must be copied |
References eina_file_map_key_cmp(), eina_file_map_key_hash(), eina_file_map_key_length(), EINA_FREE_CB, eina_hash_new(), eina_hash_pointer_new(), EINA_KEY_CMP, EINA_KEY_HASH, EINA_KEY_LENGTH, eina_lock_new(), EINA_TRUE, _Eina_File::fd, _Eina_File::filename, _Eina_File::global_map, _Eina_File::length, _Eina_File::lock, _Eina_File::map, _Eina_File::mtime, _Eina_File::refcount, and _Eina_File::rmap.
Referenced by evas_object_image_memfile_set().
Tell if a file is a real file or only exist in memory.
| file | The file to test |
References EINA_FALSE.
Refresh file information.
| file | The file to refresh |
All current map continue to exist. You need to manually delete and recreate them to have the new correct mapping.
References EINA_FALSE, eina_file_flush(), EINA_TRUE, _Eina_File::fd, _Eina_File::filename, _Eina_File::inode, _Eina_File::length, and _Eina_File::mtime.
Dup a read-only handler of a previously open file.
| file | To duplicate a reference to |
Opens a file in read-only mode.
References eina_lock_release(), eina_lock_take(), _Eina_File::lock, and _Eina_File::refcount.
Referenced by eet_mmap().
Unref file handler.
| file | File handler to unref. |
Decrement file's refcount and if it reaches zero close it.
References _eina_file_cache, _eina_file_lock_cache, EINA_FALSE, eina_file_clean_close(), eina_hash_del_by_key_hash(), eina_hash_djb2(), eina_hash_find_by_hash(), eina_lock_release(), eina_lock_take(), EINA_TRUE, _Eina_File::filename, _Eina_File::lock, and _Eina_File::refcount.
Referenced by edje_file_collection_list(), edje_file_data_get(), edje_file_group_exists(), eet_identity_open(), eet_open(), and evas_object_image_memfile_set().
Get file size at open time.
| file | The file handler to request the size from. |
References _Eina_File::length.
Referenced by eet_identity_open(), eet_mmap(), eet_open(), and eio_file_map_all().
Get the last modification time of an open file.
| file | The file handler to request the modification time from. |
References _Eina_File::mtime.
Get the filename of an open file.
| file | The file handler to request the name from. |
References _Eina_File::filename.
Referenced by edje_mmap_group_exists(), and eet_mmap().
| EAPI Eina_Iterator* eina_file_xattr_get | ( | Eina_File * | file | ) |
Get the eXtended attribute of an open file.
| file | The file handler to request the eXtended attribute from. |
The iterator will list all eXtended attribute name without allocating them, so you need to copy them yourself if needed.
References eina_xattr_fd_ls(), and _Eina_File::fd.
| EAPI Eina_Iterator* eina_file_xattr_value_get | ( | Eina_File * | file | ) |
Get the eXtended attribute of an open file.
| file | The file handler to request the eXtended attribute from. |
The iterator will list all eXtended attribute without allocating them, so you need to copy them yourself if needed. It is returning Eina_Xattr structure.
References eina_xattr_value_fd_ls(), and _Eina_File::fd.
| EAPI void* eina_file_map_all | ( | Eina_File * | file, |
| Eina_File_Populate | rule | ||
| ) |
Map all the file to a buffer.
| file | The file handler to map in memory |
| rule | The rule to apply to the mapped memory |
NULL if it fail.References EINA_FALSE, EINA_FILE_POPULATE, eina_file_virtual_map_all(), eina_lock_release(), eina_lock_take(), eina_mmap_safety_enabled_set(), EINA_TRUE, _Eina_File::fd, _Eina_File::global_map, _Eina_File::global_refcount, _Eina_File::length, _Eina_File::lock, and mmap().
Referenced by eet_identity_open(), eet_mmap(), eet_open(), eina_file_map_lines(), and eina_file_map_new().
| EAPI void* eina_file_map_new | ( | Eina_File * | file, |
| Eina_File_Populate | rule, | ||
| unsigned long int | offset, | ||
| unsigned long int | length | ||
| ) |
Map a part of the file.
| file | The file handler to map in memory |
| rule | The rule to apply to the mapped memory |
| offset | The offset inside the file |
| length | The length of the memory to map |
length valid byte in it. And NULL if not inside the file or anything else goes wrong.This does handle refcounting so it will share map that target the same memory area.
References EINA_FALSE, eina_file_map_all(), EINA_FILE_POPULATE, eina_file_virtual_map_new(), eina_hash_add(), eina_hash_direct_add(), eina_hash_find(), eina_lock_release(), eina_lock_take(), eina_mmap_safety_enabled_set(), EINA_TRUE, _Eina_File::fd, _Eina_File_Map::hugetlb, _Eina_File::length, _Eina_File_Map::length, _Eina_File::lock, _Eina_File::map, _Eina_File_Map::map, mmap(), _Eina_File_Map::offset, _Eina_File_Map::refcount, and _Eina_File::rmap.
Unref and unmap memory if possible.
| file | The file handler to unmap memory from. |
| map | Memory map to unref and unmap. |
References eina_file_common_map_free(), eina_file_virtual_map_free(), eina_lock_release(), eina_lock_take(), _Eina_File::global_map, _Eina_File::global_refcount, _Eina_File::length, _Eina_File::lock, and munmap().
Referenced by eet_identity_open().
| EAPI void eina_file_map_populate | ( | Eina_File * | file, |
| Eina_File_Populate | rule, | ||
| const void * | map, | ||
| unsigned long int | offset, | ||
| unsigned long int | length | ||
| ) |
Ask the OS to populate or otherwise pages of memory in file mapping.
| file | The file handle from which the map comes |
| rule | The rule to apply to the mapped memory |
| map | Memory that was mapped inside of which the memory range is |
| offset | The offset in bytes from the start of the map address |
| length | The length in bytes of the memory region to populate |
This advises the operating system as to what to do with the memory mapped to the given file. This affects a specific range of memory and may not be honored if the system chooses to ignore the request.
References eina_hash_find(), eina_lock_release(), eina_lock_take(), _Eina_File_Map::hugetlb, _Eina_File::lock, _Eina_File_Map::map, and _Eina_File::rmap.
| EAPI Eina_Iterator* eina_file_map_lines | ( | Eina_File * | file | ) |
Map line by line in memory efficiently with an Eina_Iterator.
| file | The file to run over |
This function return an iterator that will act like fgets without the useless memcpy. Be aware that once eina_iterator_next has been called, nothing garanty you that the memory will still be mapped.
References _Eina_Lines_Iterator::boundary, _Eina_Lines_Iterator::current, eina_file_map_all(), EINA_FILE_SEQUENTIAL, eina_lock_release(), eina_lock_take(), EINA_MAGIC_SET, _Eina_Lines_Iterator::end, _Eina_File_Line::end, _Eina_Lines_Iterator::fp, _Eina_Iterator::free, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, FUNC_ITERATOR_NEXT, _Eina_Iterator::get_container, _Eina_File_Line::index, _Eina_Lines_Iterator::iterator, _Eina_File::length, _Eina_File_Line::length, _Eina_File::lock, _Eina_Lines_Iterator::map, _Eina_Iterator::next, _Eina_File::refcount, _Eina_File_Line::start, and _Eina_Iterator::version.
Tell if there was an IO error during the life of a mmaped file.
| file | The file handler to the mmaped file. |
| map | Memory map to check if an error occurred on it. |
References _Eina_File::dead_map, EINA_FALSE, eina_hash_find(), EINA_LIST_FOREACH, eina_lock_release(), eina_lock_take(), _Eina_File_Map::faulty, _Eina_File::global_faulty, _Eina_File::global_map, _Eina_File::lock, _Eina_File_Map::map, and _Eina_File::rmap.
| Eina_Bool eina_file_path_relative | ( | const char * | path | ) |
Determines if a path is relative or absolute.
The implementation simply chekcs if the fist char in the path is '/'. If it is not, the path is considered relative.
| path | The path to check. |
References EINA_FALSE, EINA_TRUE, and evil_path_is_absolute().
Referenced by eina_file_path_sanitize().
| Eina_Tmpstr* eina_file_current_directory_get | ( | const char * | path, |
| size_t | len | ||
| ) |
Gets the current directory and optionally appends a path to it.
If a string was passed in via the path parameter, it will be appended to the current working directory. Presumably, this will be a relative path.
| path | The path to append to the current directory. |
| len | The length of path. |
References alloca(), eina_tmpstr_add_length(), and getcwd.
Referenced by eina_file_path_sanitize().
| char* eina_file_cleanup | ( | Eina_Tmpstr * | path | ) |
Cleans up Eina after a file is no longer needed.
| path | The path of the file. |
path string. If path is NULL, it will return and empty string. References eina_tmpstr_del().
Referenced by eina_file_path_sanitize().
| void eina_file_clean_close | ( | Eina_File * | file | ) |
Closes and cleans up after an Eina file.
| file | The path of the file. |
References eina_file_real_close(), eina_hash_free(), EINA_MAGIC_SET, _Eina_File::map, and _Eina_File::rmap.
Referenced by eina_file_close(), and eina_file_open().
| void eina_file_real_close | ( | Eina_File * | file | ) |
Closes a file from the OS perspective.
| file | The path of the file. |
Referenced by eina_file_clean_close().
| void eina_file_flush | ( | Eina_File * | file, |
| unsigned long int | length | ||
| ) |
Resets the internal housekeeping structures after a file has changed.
Despite the name, this routine does not write anything to disk. It invalidates the memory maps for the file. If the file has shrunk, it also adds any mapped regions past the end of the file to the dead_map.
| file | The file. |
| length | The current length of the file after the change. |
References _Eina_File::dead_map, eina_hash_del(), eina_hash_iterator_data_new(), EINA_ITERATOR_FOREACH, eina_iterator_free(), eina_list_append(), EINA_LIST_FOREACH, eina_list_merge(), eina_lock_release(), eina_lock_take(), _Eina_File::global_map, _Eina_File::global_refcount, _Eina_File::length, _Eina_File_Map::length, _Eina_File::lock, _Eina_File::map, _Eina_File_Map::map, _Eina_File_Map::offset, _Eina_File::refcount, _Eina_File_Map::refcount, and _Eina_File::rmap.
Referenced by eina_file_refresh().
| void eina_file_common_map_free | ( | Eina_File * | file, |
| void * | map, | ||
| void(*)(Eina_File_Map *map) | free_func | ||
| ) |
Removes a mapped region from the file and frees the resources.
This routine will remove a previously mapped region from the internal Eina File housekeeping and free the resources associated with it. In the case where the map is part of the dead_map, free_func will be called to handle the actual deallocation.
| file | The file. |
| map | The memory mapped region that is to be freed. |
| free_func | A pointer to a function that will be called to free up the resources used by the map. |
References _Eina_File::dead_map, EINA_FALSE, eina_hash_del(), eina_hash_find(), EINA_LIST_FOREACH, eina_list_remove_list(), EINA_TRUE, _Eina_File_Map::length, _Eina_File::map, _Eina_File_Map::map, _Eina_File_Map::offset, _Eina_File_Map::refcount, and _Eina_File::rmap.
Referenced by eina_file_map_free().
| void* eina_file_virtual_map_all | ( | Eina_File * | file | ) |
Map the entire contents fo a virtual file to a buffer.
| file | The virtual file to map in memory |
References eina_lock_release(), eina_lock_take(), _Eina_File::global_map, _Eina_File::global_refcount, and _Eina_File::lock.
Referenced by eina_file_map_all().
| void* eina_file_virtual_map_new | ( | Eina_File * | file, |
| unsigned long int | offset, | ||
| unsigned long int | length | ||
| ) |
Map a part of a virtual file to a buffer.
| file | The virtual file to map in memory |
| offset | The offset inside the file to start mapping |
| length | The length of the region to map |
References eina_hash_add(), eina_hash_direct_add(), eina_hash_find(), eina_lock_release(), eina_lock_take(), _Eina_File::global_map, _Eina_File_Map::length, _Eina_File::lock, _Eina_File::map, _Eina_File_Map::map, _Eina_File_Map::offset, _Eina_File_Map::refcount, and _Eina_File::rmap.
Referenced by eina_file_map_new().
| void eina_file_virtual_map_free | ( | Eina_File * | file, |
| void * | map | ||
| ) |
Unref and unmap memory if possible.
| file | The file handler to unmap memory from. |
| map | Memory map to unref and unmap. |
References eina_hash_del(), eina_hash_find(), eina_lock_release(), eina_lock_take(), _Eina_File::global_map, _Eina_File::global_refcount, _Eina_File_Map::length, _Eina_File::lock, _Eina_File::map, _Eina_File_Map::offset, _Eina_File_Map::refcount, and _Eina_File::rmap.
Referenced by eina_file_map_free().
| unsigned int eina_file_map_key_length | ( | const void * | key | ) |
Get the length of a map key.
| key | The key for which length will be calcualted. |
Referenced by eina_file_open(), and eina_file_virtualize().
| int eina_file_map_key_cmp | ( | const unsigned long long int * | key1, |
| int | key1_length, | ||
| const unsigned long long int * | key2, | ||
| int | key2_length | ||
| ) |
Compares two map keys.
The implementation assumes that key1 and key2 are both pointers to an array with 2 elements, as is the case with the Eina file map keys.
| key1 | The first key. |
| key1_length | The length of the first key. |
| key2 | The second key. |
| key2_length | The length of the second key. |
Referenced by eina_file_open(), and eina_file_virtualize().
| int eina_file_map_key_hash | ( | const unsigned long long int * | key, |
| int | key_length | ||
| ) |
Creates a hash from a map key.
| key | A pointer to the key. |
| key_length | The length of the key. |
References eina_hash_int64().
Referenced by eina_file_open(), and eina_file_virtualize().
| Eina_Hash* _eina_file_cache |
A pointer to the global Eina file cache.
Referenced by eina_file_close(), and eina_file_open().
| int _eina_file_log_dom |
The global Eina log file domain.