diff options
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r-- | apps/tagcache.c | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 1485ed8e51..4812198167 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -70,6 +70,7 @@ | |||
70 | #include "buffer.h" | 70 | #include "buffer.h" |
71 | #include "atoi.h" | 71 | #include "atoi.h" |
72 | #include "crc32.h" | 72 | #include "crc32.h" |
73 | #include "eeprom_settings.h" | ||
73 | 74 | ||
74 | /* Tag Cache thread. */ | 75 | /* Tag Cache thread. */ |
75 | static struct event_queue tagcache_queue; | 76 | static struct event_queue tagcache_queue; |
@@ -152,6 +153,13 @@ struct ramcache_header { | |||
152 | int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ | 153 | int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ |
153 | }; | 154 | }; |
154 | 155 | ||
156 | # ifdef HAVE_EEPROM | ||
157 | struct statefile_header { | ||
158 | struct ramcache_header *hdr; | ||
159 | struct tagcache_stat stat; | ||
160 | }; | ||
161 | # endif | ||
162 | |||
155 | /* Pointer to allocated ramcache_header */ | 163 | /* Pointer to allocated ramcache_header */ |
156 | static struct ramcache_header *hdr; | 164 | static struct ramcache_header *hdr; |
157 | #endif | 165 | #endif |
@@ -2795,6 +2803,85 @@ static bool allocate_tagcache(void) | |||
2795 | return true; | 2803 | return true; |
2796 | } | 2804 | } |
2797 | 2805 | ||
2806 | # ifdef HAVE_EEPROM | ||
2807 | static bool tagcache_dumpload(void) | ||
2808 | { | ||
2809 | struct statefile_header shdr; | ||
2810 | int fd, rc; | ||
2811 | long offpos; | ||
2812 | int i; | ||
2813 | |||
2814 | fd = open(TAGCACHE_STATEFILE, O_RDONLY); | ||
2815 | if (fd < 0) | ||
2816 | { | ||
2817 | logf("no tagcache statedump"); | ||
2818 | return false; | ||
2819 | } | ||
2820 | |||
2821 | /* Check the statefile memory placement */ | ||
2822 | hdr = buffer_alloc(0); | ||
2823 | rc = read(fd, &shdr, sizeof(struct statefile_header)); | ||
2824 | if (rc != sizeof(struct statefile_header) | ||
2825 | /* || (long)hdr != (long)shdr.hdr */) | ||
2826 | { | ||
2827 | logf("incorrect statefile"); | ||
2828 | hdr = NULL; | ||
2829 | close(fd); | ||
2830 | return false; | ||
2831 | } | ||
2832 | |||
2833 | offpos = (long)hdr - (long)shdr.hdr; | ||
2834 | |||
2835 | /* Lets allocate real memory and load it */ | ||
2836 | hdr = buffer_alloc(shdr.stat.ramcache_allocated); | ||
2837 | rc = read(fd, hdr, shdr.stat.ramcache_allocated); | ||
2838 | close(fd); | ||
2839 | |||
2840 | if (rc != shdr.stat.ramcache_allocated) | ||
2841 | { | ||
2842 | logf("read failure!"); | ||
2843 | hdr = NULL; | ||
2844 | return false; | ||
2845 | } | ||
2846 | |||
2847 | memcpy(&stat, &shdr.stat, sizeof(struct tagcache_stat)); | ||
2848 | |||
2849 | /* Now fix the pointers */ | ||
2850 | hdr->indices = (struct index_entry *)((long)hdr->indices + offpos); | ||
2851 | for (i = 0; i < TAG_COUNT; i++) | ||
2852 | hdr->tags[i] += offpos; | ||
2853 | |||
2854 | return true; | ||
2855 | } | ||
2856 | |||
2857 | static bool tagcache_dumpsave(void) | ||
2858 | { | ||
2859 | struct statefile_header shdr; | ||
2860 | int fd; | ||
2861 | |||
2862 | if (!stat.ramcache) | ||
2863 | return false; | ||
2864 | |||
2865 | fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); | ||
2866 | if (fd < 0) | ||
2867 | { | ||
2868 | logf("failed to create a statedump"); | ||
2869 | return false; | ||
2870 | } | ||
2871 | |||
2872 | /* Create the header */ | ||
2873 | shdr.hdr = hdr; | ||
2874 | memcpy(&shdr.stat, &stat, sizeof(struct tagcache_stat)); | ||
2875 | write(fd, &shdr, sizeof(struct statefile_header)); | ||
2876 | |||
2877 | /* And dump the data too */ | ||
2878 | write(fd, hdr, stat.ramcache_allocated); | ||
2879 | close(fd); | ||
2880 | |||
2881 | return true; | ||
2882 | } | ||
2883 | # endif | ||
2884 | |||
2798 | static bool load_tagcache(void) | 2885 | static bool load_tagcache(void) |
2799 | { | 2886 | { |
2800 | struct tagcache_header *tch; | 2887 | struct tagcache_header *tch; |
@@ -3250,8 +3337,15 @@ static void tagcache_thread(void) | |||
3250 | free_tempbuf(); | 3337 | free_tempbuf(); |
3251 | 3338 | ||
3252 | #ifdef HAVE_TC_RAMCACHE | 3339 | #ifdef HAVE_TC_RAMCACHE |
3340 | # ifdef HAVE_EEPROM | ||
3341 | if (firmware_settings.initialized && firmware_settings.disk_clean) | ||
3342 | check_done = tagcache_dumpload(); | ||
3343 | |||
3344 | remove(TAGCACHE_STATEFILE); | ||
3345 | # endif | ||
3346 | |||
3253 | /* Allocate space for the tagcache if found on disk. */ | 3347 | /* Allocate space for the tagcache if found on disk. */ |
3254 | if (global_settings.tagcache_ram) | 3348 | if (global_settings.tagcache_ram && !stat.ramcache) |
3255 | allocate_tagcache(); | 3349 | allocate_tagcache(); |
3256 | #endif | 3350 | #endif |
3257 | 3351 | ||
@@ -3330,6 +3424,19 @@ static void tagcache_thread(void) | |||
3330 | } | 3424 | } |
3331 | } | 3425 | } |
3332 | 3426 | ||
3427 | bool tagcache_prepare_shutdown(void) | ||
3428 | { | ||
3429 | if (tagcache_get_commit_step() > 0) | ||
3430 | return false; | ||
3431 | |||
3432 | #ifdef HAVE_EEPROM | ||
3433 | if (stat.ramcache) | ||
3434 | tagcache_dumpsave(); | ||
3435 | #endif | ||
3436 | |||
3437 | return true; | ||
3438 | } | ||
3439 | |||
3333 | static int get_progress(void) | 3440 | static int get_progress(void) |
3334 | { | 3441 | { |
3335 | int total_count = -1; | 3442 | int total_count = -1; |