summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/dircache.c41
-rw-r--r--firmware/include/dircache.h3
2 files changed, 44 insertions, 0 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index fa24321726..259c34cdf5 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -77,6 +77,7 @@ static struct dircache_entry* allocate_entry(void)
77 dircache_size += sizeof(struct dircache_entry); 77 dircache_size += sizeof(struct dircache_entry);
78 next_entry->name_len = 0; 78 next_entry->name_len = 0;
79 next_entry->d_name = NULL; 79 next_entry->d_name = NULL;
80 next_entry->up = NULL;
80 next_entry->down = NULL; 81 next_entry->down = NULL;
81 next_entry->next = NULL; 82 next_entry->next = NULL;
82 83
@@ -88,6 +89,7 @@ static struct dircache_entry* dircache_gen_next(struct dircache_entry *ce)
88 struct dircache_entry *next_entry; 89 struct dircache_entry *next_entry;
89 90
90 next_entry = allocate_entry(); 91 next_entry = allocate_entry();
92 next_entry->up = ce->up;
91 ce->next = next_entry; 93 ce->next = next_entry;
92 94
93 return next_entry; 95 return next_entry;
@@ -98,6 +100,7 @@ static struct dircache_entry* dircache_gen_down(struct dircache_entry *ce)
98 struct dircache_entry *next_entry; 100 struct dircache_entry *next_entry;
99 101
100 next_entry = allocate_entry(); 102 next_entry = allocate_entry();
103 next_entry->up = ce;
101 ce->down = next_entry; 104 ce->down = next_entry;
102 105
103 return next_entry; 106 return next_entry;
@@ -176,6 +179,7 @@ static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce)
176 int depth = 0; 179 int depth = 0;
177 int result; 180 int result;
178 181
182 memset(ce, 0, sizeof(struct dircache_entry));
179 dir_recursion[0].dir = dir; 183 dir_recursion[0].dir = dir;
180 dir_recursion[0].ce = ce; 184 dir_recursion[0].ce = ce;
181 185
@@ -517,6 +521,43 @@ void dircache_disable(void)
517 logf("Cache released"); 521 logf("Cache released");
518} 522}
519 523
524const struct dircache_entry *dircache_get_entry_ptr(const char *filename)
525{
526 if (!dircache_initialized || filename == NULL)
527 return NULL;
528
529 return dircache_get_entry(filename, false, false);
530}
531
532void dircache_copy_path(const struct dircache_entry *entry, char *buf, int size)
533{
534 const struct dircache_entry *down[MAX_SCAN_DEPTH];
535 int depth = 0;
536
537 if (size <= 0)
538 return ;
539
540 buf[0] = '\0';
541
542 if (entry == NULL)
543 return ;
544
545 do {
546 down[depth] = entry;
547 entry = entry->up;
548 depth++;
549 } while (entry != NULL && depth < MAX_SCAN_DEPTH);
550
551 while (--depth >= 0)
552 {
553 snprintf(buf, size, "/%s", down[depth]->d_name);
554 buf += down[depth]->name_len; /* '/' + d_name */
555 size -= down[depth]->name_len;
556 if (size <= 0)
557 break ;
558 }
559}
560
520/* --- Directory cache live updating functions --- */ 561/* --- Directory cache live updating functions --- */
521static struct dircache_entry* dircache_new_entry(const char *path, int attribute) 562static struct dircache_entry* dircache_new_entry(const char *path, int attribute)
522{ 563{
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h
index 48b74e0220..11d7335a31 100644
--- a/firmware/include/dircache.h
+++ b/firmware/include/dircache.h
@@ -47,6 +47,7 @@ struct dircache_maindata {
47/* Exported structures. */ 47/* Exported structures. */
48struct dircache_entry { 48struct dircache_entry {
49 struct dircache_entry *next; 49 struct dircache_entry *next;
50 struct dircache_entry *up;
50 struct dircache_entry *down; 51 struct dircache_entry *down;
51 int attribute; 52 int attribute;
52 long size; 53 long size;
@@ -71,6 +72,8 @@ int dircache_build(int last_size);
71bool dircache_is_enabled(void); 72bool dircache_is_enabled(void);
72int dircache_get_cache_size(void); 73int dircache_get_cache_size(void);
73void dircache_disable(void); 74void dircache_disable(void);
75const struct dircache_entry *dircache_get_entry_ptr(const char *filename);
76void dircache_copy_path(const struct dircache_entry *entry, char *buf, int size);
74 77
75void dircache_bind(int fd, const char *path); 78void dircache_bind(int fd, const char *path);
76void dircache_update_filesize(int fd, long newsize); 79void dircache_update_filesize(int fd, long newsize);