From dc22522c2c21f058333e4383d644cb18f355ac76 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 12 Feb 2017 07:13:25 -0500 Subject: Tweak a few tagcache things. * Take out pointless dircache_search; nothing can be reconstructed with the given info in find_entry_ram(); don't even try there. Path AND index id must be known. Work it out later. * Timed yield must be far more often than once every 1/4 second (?!) * Do better the memory-remaining checks for ramcache load. * Root separator mustn't be doubled up when searching files. Change-Id: I091813f4495f3bd0d0c4672bc674df52343b3e48 --- apps/tagcache.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/apps/tagcache.c b/apps/tagcache.c index dfab06da20..6b6e4839d5 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -438,8 +438,8 @@ static bool do_timed_yield(void) static long wakeup_tick = 0; if (TIME_AFTER(current_tick, wakeup_tick)) { - wakeup_tick = current_tick + (HZ/4); yield(); + wakeup_tick = current_tick + (HZ/50); return true; } return false; @@ -471,27 +471,17 @@ static long find_entry_ram(const char *filename) { for (int i = last_pos; i < end_pos; i++) { - if (tcramcache.hdr->indices[i].flag & FLAG_DIRCACHE) - { - int cmp = dircache_fileref_cmp(&tcrc_dcfrefs[i], &dcfref); - if (cmp > 0) - { - if (cmp < 3) - { - if (dircache_search(DCS_CACHED_PATH | DCS_UPDATE_FILEREF, - &dcfref, filename) <= 0) - return -1; + do_timed_yield(); - if (dircache_fileref_cmp(&tcrc_dcfrefs[i], &dcfref) < 3) - return -1; - } + if (!(tcramcache.hdr->indices[i].flag & FLAG_DIRCACHE)) + continue; - last_pos = MAX(0, i - 3); - return i; - } - } + int cmp = dircache_fileref_cmp(&tcrc_dcfrefs[i], &dcfref); + if (cmp < 3) + continue; - do_timed_yield(); + last_pos = MAX(0, i - 3); + return i; } if (last_pos == 0) @@ -4084,7 +4074,7 @@ static bool load_tagcache(void) p = TC_ALIGN_PTR(p, &rc); bytesleft -= rc; - if (bytesleft <= 0) + if (bytesleft < (ssize_t)sizeof(struct tagcache_header)) { logf("Too big tagcache #10.5"); goto failure; @@ -4112,17 +4102,11 @@ static bool load_tagcache(void) p = TC_ALIGN_PTR(p, &rc); bytesleft -= rc; - if (bytesleft <= 0) + if (bytesleft < (ssize_t)sizeof(struct tagfile_entry)) { logf("Too big tagcache #10.75"); goto failure; } - - if (bytesleft < (ssize_t)sizeof (struct tagfile_entry)) - { - logf("Too big tagcache #10.875"); - goto failure; - } struct tagfile_entry *fe = (struct tagfile_entry *)p; off_t pos = lseek(fd, 0, SEEK_CUR); @@ -4141,6 +4125,12 @@ static bool load_tagcache(void) if (tag == tag_filename) { int idx_id = fe->idx_id; /* gonna clobber tagfile entry */ + if (idx_id < 0 || idx_id >= tcmh.tch.entry_count) + { + logf("corrupt tagfile entry (tag: %d)", tag); + goto failure; + } + struct index_entry *idx = &tcramcache.hdr->indices[idx_id]; #ifdef HAVE_DIRCACHE @@ -4479,7 +4469,7 @@ static bool check_dir(const char *dirname, int add_files) struct dirinfo info = dir_get_info(dir, entry); size_t len = strlen(curpath); - path_append(&curpath[len], PA_SEP_HARD, entry->d_name, + path_append(&curpath[len-1], PA_SEP_HARD, entry->d_name, sizeof (curpath) - len); processed_dir_count++; -- cgit v1.2.3