Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 9f19ac3..016488b 100644 #include <string.h> #include <stdbool.h> #include <stdlib.h> +#include <stdarg.h> +#include "sprintf.h" #include "debug.h" #include "system.h" #include "logf.h" static unsigned int cache_build_ticks = 0; static unsigned long appflags = 0; static struct event_queue dircache_queue; -static long dircache_stack[(DEFAULT_STACK_SIZE + 0x200)/sizeof(long)]; +static long dircache_stack[(DEFAULT_STACK_SIZE + 0x400)/sizeof(long)]; static const char dircache_thread_name[] = "dircache"; static struct fdbind_queue fdbind_cache[MAX_PENDING_BINDINGS]; static struct #endif struct fat_dir *dir; struct fat_direntry *direntry; + int depth; + int fd; }sab; +static int sab_logf_push(void *userp, unsigned char c) +{ + write(sab.fd, &c, sizeof(c)); + + return true; +} + +static void sab_logf(const char *fmt, ...) +{ + va_list ap; + if(sab.fd < 0) + return; + + va_start(ap, fmt); + + vuprintf(sab_logf_push, NULL, fmt, ap); + va_end(ap); + + /* add trailing zero */ + sab_logf_push(NULL, '\n'); + + fsync(sab.fd); +} + static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce) { /* normally, opendir expects a full fat_dir as parent but in our case, static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce if(!strcmp(".", sab.direntry->name) || !strcmp("..", sab.direntry->name)) continue; + + sab_logf("%d: %s", sab.depth, sab.direntry->name); + _logf("%d: %s", sab.depth, sab.direntry->name); ce->attribute = sab.direntry->attr; ce->name_len = strlen(sab.direntry->name) + 1; static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce if(ce == NULL) return -5; - /* When simulator is used, it's only safe to yield here. */ if(thread_enabled) { /* Stop if we got an external signal. */ static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce while(rc >= 0 && ce) { + sab.depth++; if(ce->name_len != 0 && ce->down != NULL && strcmp(ce->d_name, ".") && strcmp(ce->d_name, "..")) rc = sab_process_dir(ce->startcluster, ce->down); + sab.depth--; ce = ce->next; } static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce /* used during the generation */ static struct fat_dir sab_fat_dir; +static struct fat_direntry sab_fat_direntry; static int dircache_scan_and_build(IF_MV2(int volume,) struct dircache_entry *ce) { static int dircache_scan_and_build(IF_MV2(int volume,) struct dircache_entry *ce } #endif - struct fat_direntry direntry; /* ditto */ #ifdef HAVE_MULTIVOLUME sab.volume = volume; #endif sab.dir = &sab_fat_dir; - sab.direntry = &direntry; + sab.direntry = &sab_fat_direntry; return sab_process_dir(0, ce); } int dircache_load(void) dircache_root = buffer_alloc(0); if ((long)maindata.root_entry != (long)dircache_root) { - logf("Position missmatch"); + logf("Position mismatch"); close(fd); remove(DIRCACHE_FILE); return -4; static int dircache_do_rebuild(void) dircache_size = sizeof(struct dircache_entry); + sab.fd = open("/sab_logf.txt", O_RDWR | O_TRUNC | O_CREAT); + #ifdef HAVE_MULTIVOLUME append_position = dircache_root; static int dircache_do_rebuild(void) } #endif + close(sab.fd); logf("Done, %ld KiB used", dircache_size / 1024); dircache_initialized = true; |