From 825a3d837a33f226c879cd02ad15c3fba57e8b2c Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 23 Jan 2012 23:30:42 +1000 Subject: Update the EFL to what I'm actually using, coz I'm using some stuff not yet released. --- libraries/eina/src/lib/eina_file.c | 128 +++++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 6 deletions(-) (limited to 'libraries/eina/src/lib/eina_file.c') diff --git a/libraries/eina/src/lib/eina_file.c b/libraries/eina/src/lib/eina_file.c index 84b9e78..0b836b3 100644 --- a/libraries/eina/src/lib/eina_file.c +++ b/libraries/eina/src/lib/eina_file.c @@ -38,13 +38,18 @@ extern "C" void *alloca (size_t); #endif +#include #include #include -#include +#ifdef HAVE_DIRENT_H +# include +#endif #include #include #include -#include +#ifdef HAVE_SYS_MMAN_H +# include +#endif #include #define PATH_DELIM '/' @@ -60,6 +65,8 @@ void *alloca (size_t); #include "eina_list.h" #include "eina_lock.h" #include "eina_mmap.h" +#include "eina_log.h" +#include "eina_xattr.h" #ifdef HAVE_ESCAPE_H # include @@ -95,9 +102,8 @@ void *alloca (size_t); #define EINA_SMALL_PAGE 4096 # define EINA_HUGE_PAGE 16 * 1024 * 1024 +#ifdef HAVE_DIRENT_H typedef struct _Eina_File_Iterator Eina_File_Iterator; -typedef struct _Eina_File_Map Eina_File_Map; - struct _Eina_File_Iterator { Eina_Iterator iterator; @@ -107,6 +113,7 @@ struct _Eina_File_Iterator char dir[1]; }; +#endif struct _Eina_File { @@ -132,8 +139,10 @@ struct _Eina_File Eina_Bool shared : 1; Eina_Bool delete_me : 1; + Eina_Bool global_faulty : 1; }; +typedef struct _Eina_File_Map Eina_File_Map; struct _Eina_File_Map { void *map; @@ -144,6 +153,7 @@ struct _Eina_File_Map int refcount; Eina_Bool hugetlb : 1; + Eina_Bool faulty : 1; }; static Eina_Hash *_eina_file_cache = NULL; @@ -156,6 +166,7 @@ static int _eina_file_log_dom = -1; * The code and description of the issue can be found at : * http://womble.decadent.org.uk/readdir_r-advisory.html */ +#ifdef HAVE_DIRENT_H static long _eina_name_max(DIR *dirp) { @@ -390,6 +401,7 @@ _eina_file_stat_ls_iterator_next(Eina_File_Direct_Iterator *it, void **data) return EINA_TRUE; } +#endif static void _eina_file_real_close(Eina_File *file) @@ -511,8 +523,8 @@ slprintf(char *str, size_t size, const char *format, ...) va_end(ap); } -static char* -_eina_file_escape(const char* path, int* length) +static char * +_eina_file_escape(const char *path, int *length) { char *result = strdup(path ? path : ""); char *p = result; @@ -738,6 +750,7 @@ eina_file_split(char *path) EAPI Eina_Iterator * eina_file_ls(const char *dir) { +#ifdef HAVE_DIRENT_H Eina_File_Iterator *it; size_t length; @@ -773,11 +786,16 @@ eina_file_ls(const char *dir) it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_ls_iterator_free); return &it->iterator; +#else + (void) dir; + return NULL; +#endif } EAPI Eina_Iterator * eina_file_direct_ls(const char *dir) { +#ifdef HAVE_DIRENT_H Eina_File_Direct_Iterator *it; size_t length; @@ -825,11 +843,16 @@ eina_file_direct_ls(const char *dir) it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_direct_ls_iterator_free); return &it->iterator; +#else + (void) dir; + return NULL; +#endif } EAPI Eina_Iterator * eina_file_stat_ls(const char *dir) { +#ifdef HAVE_DIRENT_H Eina_File_Direct_Iterator *it; size_t length; @@ -877,6 +900,10 @@ eina_file_stat_ls(const char *dir) it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_direct_ls_iterator_free); return &it->iterator; +#else + (void) dir; + return NULL; +#endif } EAPI Eina_File * @@ -887,7 +914,9 @@ eina_file_open(const char *path, Eina_Bool shared) char *filename; struct stat file_stat; int fd = -1; +#ifdef HAVE_EXECVP int flags; +#endif EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); @@ -1184,4 +1213,91 @@ eina_file_map_free(Eina_File *file, void *map) eina_lock_release(&file->lock); } +EAPI Eina_Bool +eina_file_map_faulted(Eina_File *file, void *map) +{ + Eina_File_Map *em; + + EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE); + + eina_lock_take(&file->lock); + + if (file->global_map == map) return file->global_faulty; + + em = eina_hash_find(file->rmap, &map); + if (!em) return EINA_FALSE; + + return em->faulty; +} + +EAPI Eina_Iterator * +eina_file_xattr_get(Eina_File *file) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); + + return eina_xattr_fd_ls(file->fd); +} + +EAPI Eina_Iterator * +eina_file_xattr_value_get(Eina_File *file) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); + + return eina_xattr_value_fd_ls(file->fd); +} + +void +eina_file_mmap_faulty(void *addr, long page_size) +{ + Eina_File_Map *m; + Eina_File *f; + Eina_Iterator *itf; + Eina_Iterator *itm; + + /* NOTE: I actually don't know if other thread are running, I will try to take the lock. + It may be possible that if other thread are not running and they were in the middle of + accessing an Eina_File this lock are still taken and we will result as a deadlock. */ + eina_lock_take(&_eina_file_lock_cache); + + itf = eina_hash_iterator_data_new(_eina_file_cache); + EINA_ITERATOR_FOREACH(itf, f) + { + Eina_Bool faulty = EINA_FALSE; + + eina_lock_take(&f->lock); + + if (f->global_map) + { + if ((unsigned char *) addr < (((unsigned char *)f->global_map) + f->length) && + (((unsigned char *) addr) + page_size) >= (unsigned char *) f->global_map) + { + f->global_faulty = EINA_TRUE; + faulty = EINA_TRUE; + } + } + + if (!faulty) + { + itm = eina_hash_iterator_data_new(f->map); + EINA_ITERATOR_FOREACH(itm, m) + { + if ((unsigned char *) addr < (((unsigned char *)m->map) + m->length) && + (((unsigned char *) addr) + page_size) >= (unsigned char *) m->map) + { + m->faulty = EINA_TRUE; + faulty = EINA_TRUE; + break; + } + } + eina_iterator_free(itm); + } + + eina_lock_release(&f->lock); + + if (faulty) break; + } + eina_iterator_free(itf); + + eina_lock_release(&_eina_file_lock_cache); +} -- cgit v1.1