summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_file.c
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-07-31 17:16:20 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-07-31 17:16:40 +0900
commit4dd259f3b159af87e6f569082ffb5353a3886b2f (patch)
tree834eddafe35e13ca8b3ad8a5be8cfccf86737d6a /src/lib/eina/eina_file.c
parent5ae4cfd1923e502731f4d8fc2bf67b1f536a9216 (diff)
eina: add eina_file_refresh().
Diffstat (limited to 'src/lib/eina/eina_file.c')
-rw-r--r--src/lib/eina/eina_file.c109
1 files changed, 85 insertions, 24 deletions
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index 32ae4ea..ceb3e1c 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -304,11 +304,19 @@ _eina_file_stat_ls_iterator_next(Eina_File_Direct_Iterator *it, void **data)
304void 304void
305eina_file_real_close(Eina_File *file) 305eina_file_real_close(Eina_File *file)
306{ 306{
307 Eina_File_Map *map;
308
307 if (file->refcount != 0) return; 309 if (file->refcount != 0) return;
308 310
309 eina_hash_free(file->rmap); 311 eina_hash_free(file->rmap);
310 eina_hash_free(file->map); 312 eina_hash_free(file->map);
311 313
314 EINA_LIST_FREE(file->dead_map, map)
315 {
316 munmap(map->map, map->length);
317 free(map);
318 }
319
312 if (file->global_map != MAP_FAILED) 320 if (file->global_map != MAP_FAILED)
313 munmap(file->global_map, file->length); 321 munmap(file->global_map, file->length);
314 322
@@ -462,6 +470,19 @@ eina_file_shutdown(void)
462 return EINA_TRUE; 470 return EINA_TRUE;
463} 471}
464 472
473static Eina_Bool
474_eina_file_mmap_faulty_one(void *addr, long page_size,
475 Eina_File_Map *m)
476{
477 if ((unsigned char *) addr < (((unsigned char *)m->map) + m->length) &&
478 (((unsigned char *) addr) + page_size) >= (unsigned char *) m->map)
479 {
480 m->faulty = EINA_TRUE;
481 return EINA_TRUE;
482 }
483 return EINA_FALSE;
484}
485
465void 486void
466eina_file_mmap_faulty(void *addr, long page_size) 487eina_file_mmap_faulty(void *addr, long page_size)
467{ 488{
@@ -497,17 +518,23 @@ eina_file_mmap_faulty(void *addr, long page_size)
497 itm = eina_hash_iterator_data_new(f->map); 518 itm = eina_hash_iterator_data_new(f->map);
498 EINA_ITERATOR_FOREACH(itm, m) 519 EINA_ITERATOR_FOREACH(itm, m)
499 { 520 {
500 if ((unsigned char *) addr < (((unsigned char *)m->map) + m->length) && 521 faulty = _eina_file_mmap_faulty_one(addr, page_size, m);
501 (((unsigned char *) addr) + page_size) >= (unsigned char *) m->map) 522 if (faulty) break;
502 {
503 m->faulty = EINA_TRUE;
504 faulty = EINA_TRUE;
505 break;
506 }
507 } 523 }
508 eina_iterator_free(itm); 524 eina_iterator_free(itm);
509 } 525 }
510 526
527 if (!faulty)
528 {
529 Eina_List *l;
530
531 EINA_LIST_FOREACH(f->dead_map, l, m)
532 {
533 faulty = _eina_file_mmap_faulty_one(addr, page_size, m);
534 if (faulty) break;
535 }
536 }
537
511 eina_lock_release(&f->lock); 538 eina_lock_release(&f->lock);
512 539
513 if (faulty) break; 540 if (faulty) break;
@@ -902,6 +929,39 @@ eina_file_open(const char *path, Eina_Bool shared)
902 return NULL; 929 return NULL;
903} 930}
904 931
932EAPI Eina_Bool
933eina_file_refresh(Eina_File *file)
934{
935 struct stat file_stat;
936 Eina_Bool r = EINA_FALSE;
937
938 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
939
940 if (file->virtual) return EINA_FALSE;
941
942 if (fstat(file->fd, &file_stat))
943 return EINA_FALSE;
944
945 if (file->length != (unsigned long int) file_stat.st_size)
946 {
947 eina_file_flush(file, file_stat.st_size);
948 r = EINA_TRUE;
949 }
950
951 file->length = file_stat.st_size;
952 file->mtime = file_stat.st_mtime;
953#ifdef _STAT_VER_LINUX
954# if (defined __USE_MISC && defined st_mtime)
955 file->mtime_nsec = (unsigned long int)file_stat.st_mtim.tv_nsec;
956# else
957 file->mtime_nsec = (unsigned long int)file_stat.st_mtimensec;
958# endif
959#endif
960 file->inode = file_stat.st_ino;
961
962 return r;
963}
964
905EAPI void * 965EAPI void *
906eina_file_map_all(Eina_File *file, Eina_File_Populate rule) 966eina_file_map_all(Eina_File *file, Eina_File_Populate rule)
907{ 967{
@@ -1048,21 +1108,7 @@ eina_file_map_free(Eina_File *file, void *map)
1048 } 1108 }
1049 else 1109 else
1050 { 1110 {
1051 Eina_File_Map *em; 1111 eina_file_common_map_free(file, map, _eina_file_map_close);
1052 unsigned long int key[2];
1053
1054 em = eina_hash_find(file->rmap, &map);
1055 if (!em) goto on_exit;
1056
1057 em->refcount--;
1058
1059 if (em->refcount > 0) goto on_exit;
1060
1061 key[0] = em->offset;
1062 key[1] = em->length;
1063
1064 eina_hash_del(file->rmap, &map, em);
1065 eina_hash_del(file->map, &key, em);
1066 } 1112 }
1067 1113
1068 on_exit: 1114 on_exit:
@@ -1086,7 +1132,6 @@ eina_file_map_populate(Eina_File *file, Eina_File_Populate rule, void *map,
1086EAPI Eina_Bool 1132EAPI Eina_Bool
1087eina_file_map_faulted(Eina_File *file, void *map) 1133eina_file_map_faulted(Eina_File *file, void *map)
1088{ 1134{
1089 Eina_File_Map *em;
1090 Eina_Bool r = EINA_FALSE; 1135 Eina_Bool r = EINA_FALSE;
1091 1136
1092 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE); 1137 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
@@ -1101,8 +1146,24 @@ eina_file_map_faulted(Eina_File *file, void *map)
1101 } 1146 }
1102 else 1147 else
1103 { 1148 {
1149 Eina_File_Map *em;
1150
1104 em = eina_hash_find(file->rmap, &map); 1151 em = eina_hash_find(file->rmap, &map);
1105 if (em) r = em->faulty; 1152 if (em)
1153 {
1154 r = em->faulty;
1155 }
1156 else
1157 {
1158 Eina_List *l;
1159
1160 EINA_LIST_FOREACH(file->dead_map, l, em)
1161 if (em->map == map)
1162 {
1163 r = em->faulty;
1164 break;
1165 }
1166 }
1106 } 1167 }
1107 1168
1108 eina_lock_release(&file->lock); 1169 eina_lock_release(&file->lock);