diff --git a/firmware/common/file.c b/firmware/common/file.c index a204cf71cc..202410db81 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -31,6 +31,15 @@ #include "rb_namespace.h" #include "string-extra.h" +/* Define LOGF_ENABLE to enable logf output in this file */ +//#define LOGF_ENABLE +#ifdef LOGF_ENABLE +#include "logf.h" +#undef DEBUGF +#define DEBUGF logf +#endif + + /** * These functions provide a roughly POSIX-compatible file I/O API. */ @@ -600,8 +609,10 @@ static inline ssize_t readwrite_partial(struct filestr_desc *file, static ssize_t readwrite(struct filestr_desc *file, void *buf, size_t nbyte, bool write) { +#ifndef LOGF_ENABLE /* wipes out log before you can save it */ DEBUGF("readwrite(%p,%lx,%lu,%s)\n", file, (long)buf, (unsigned long)nbyte, write ? "write" : "read"); +#endif const file_size_t size = *file->sizep; file_size_t filerem; @@ -766,8 +777,9 @@ file_error:; /* error or not, update the file offset and size if anything was transferred */ file->offset += done; +#ifndef LOGF_ENABLE /* wipes out log before you can save it */ DEBUGF("file offset: %ld\n", file->offset); - +#endif /* adjust file size to length written */ if (write && file->offset > size) *file->sizep = file->offset; @@ -901,8 +913,9 @@ file_error: /* move the read/write file offset */ off_t lseek(int fildes, off_t offset, int whence) { +#ifndef LOGF_ENABLE /* wipes out log before you can save it */ DEBUGF("lseek(fd=%d,ofs=%ld,wh=%d)\n", fildes, (long)offset, whence); - +#endif struct filestr_desc * const file = GET_FILESTR(READER, fildes); if (!file) FILE_ERROR_RETURN(ERRNO, -1); diff --git a/firmware/common/file_internal.c b/firmware/common/file_internal.c index 14db247347..9ddbb232b4 100644 --- a/firmware/common/file_internal.c +++ b/firmware/common/file_internal.c @@ -30,6 +30,14 @@ #include "string-extra.h" #include "rbunicode.h" +/* Define LOGF_ENABLE to enable logf output in this file */ +//#define LOGF_ENABLE +#ifdef LOGF_ENABLE +#include "logf.h" +#undef DEBUGF +#define DEBUGF logf +#endif + /** Internal common filesystem service functions **/ /* for internal functions' scanning use to save quite a bit of stack space - diff --git a/firmware/common/rb_namespace.c b/firmware/common/rb_namespace.c index beaaf78bed..ff5ad0f6db 100644 --- a/firmware/common/rb_namespace.c +++ b/firmware/common/rb_namespace.c @@ -24,6 +24,15 @@ #include "rb_namespace.h" #include "file_internal.h" +/* Define LOGF_ENABLE to enable logf output in this file */ +//#define LOGF_ENABLE +#include "logf.h" + +#if !defined(HAVE_MULTIVOLUME) && defined(LOGF_ENABLE) + int volume = 0; +#endif + + #define ROOT_CONTENTS_INDEX (NUM_VOLUMES) #define NUM_ROOT_ITEMS (NUM_VOLUMES+1) @@ -53,12 +62,14 @@ static void get_mount_point_entry(IF_MV(int volume,) struct DIRENT *entry) entry->info.wrtdate = 0; entry->info.wrttime = 0; #endif /* is dirinfo_native */ + logf("%s: vol:%d, %s", __func__, volume, entry->d_name); } /* unmount the directory that enumerates into the root namespace */ static void unmount_item(int item) { unsigned int state = get_root_item_state(item); + logf("%s: state: %u", __func__, state); if (!state) return; @@ -83,13 +94,18 @@ int root_mount_path(const char *path, unsigned int flags) return -ENOENT; #else if (!path_is_absolute(path)) + { + logf("Path not absolute %s", path); return -ENOENT; + } #endif /* HAVE_MULTIVOLUME */ bool contents = flags & NSITEM_CONTENTS; int item = contents ? ROOT_CONTENTS_INDEX : IF_MV_VOL(volume); unsigned int state = get_root_item_state(item); + logf("%s: item:%d, st:%u, %s", __func__, item, state, path); + if (state) return -EBUSY; @@ -122,6 +138,7 @@ int root_mount_path(const char *path, unsigned int flags) /* inform root that an entire volume is being unmounted */ void root_unmount_volume(IF_MV_NONVOID(int volume)) { + logf("%s: vol: %d", __func__, volume); FOR_EACH_VOLUME(volume, item) { #ifdef HAVE_MULTIVOLUME @@ -143,6 +160,7 @@ void root_unmount_volume(IF_MV_NONVOID(int volume)) /* parse the root part of a path */ int ns_parse_root(const char *path, const char **pathp, uint16_t *lenp) { + logf("%s: path: %s", __func__, path); int volume = ROOT_VOLUME; #ifdef HAVE_MULTIVOLUME @@ -151,19 +169,35 @@ int ns_parse_root(const char *path, const char **pathp, uint16_t *lenp) const char *p; volume = path_strip_volume(path, &p, false); if (volume != ROOT_VOLUME && !CHECK_VOL(volume)) + { + logf("vol: %d is not root", volume); return -ENOENT; + } #endif /* HAVE_MULTIVOLUME */ /* set name to start at last leading separator; name of root will * be returned as "/", volume specifiers as "/" */ *pathp = GOBBLE_PATH_SEPCH(path) - 1; *lenp = IF_MV( volume < NUM_VOLUMES ? p - *pathp : ) 1; - +#ifdef LOGF_ENABLE + if (volume == INT_MAX) + logf("vol: ROOT(%d) %s", volume, *pathp); + else + logf("vol: %d %s", volume, *pathp); +#endif #ifdef HAVE_MULTIVOLUME if (*lenp > MAX_COMPNAME+1) + { + logf("%s: path too long %s", __func__, path); return -ENAMETOOLONG; + } +#endif +#ifdef LOGF_ENABLE + if (volume == INT_MAX) + logf("%s: vol: ROOT(%d) path: %s", __func__, volume, path); + else + logf("%s: vol: %d path: %s", __func__, volume, path); #endif - return volume; } @@ -183,7 +217,7 @@ int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp, int item = sysroot ? ROOT_CONTENTS_INDEX : IF_MV_VOL(volume); unsigned int state = get_root_item_state(item); - + logf("%s: Vol:%d St:%d", __func__, item, state); if (sysroot) { *attrp = ATTR_SYSTEM_ROOT; @@ -191,7 +225,10 @@ int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp, if (state) *infop = root_bindp->info; else + { + logf("%s: SysRoot Vol:%d St:%d NOT mounted", __func__, item, state); *callflagsp = callflags | FF_NOFS; /* contents not mounted */ + } } else { @@ -201,7 +238,10 @@ int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp, return -ENOENT; /* regular open requires having been mounted */ #if CONFIG_PLATFORM & PLATFORM_NATIVE if (fat_open_rootdir(IF_MV(volume,) &infop->fatfile) < 0) + { + logf("%s: DevPath Vol:%d St:%d NOT mounted", __func__, item, state); return -ENOENT; /* not mounted */ + } #endif get_rootinfo_internal(infop); } @@ -216,6 +256,7 @@ int root_readdir_dirent(struct filestr_base *stream, int rc = 0; int item = scanp->item; + logf("%s: item: %d", __func__, item); /* skip any not-mounted or hidden items */ unsigned int state; @@ -226,7 +267,10 @@ int root_readdir_dirent(struct filestr_base *stream, state = get_root_item_state(item); if ((state & (NSITEM_MOUNTED|NSITEM_HIDDEN)) == NSITEM_MOUNTED) + { + logf("Found mounted item: %d %s", item, entry->d_name); break; + } item++; } @@ -238,13 +282,17 @@ int root_readdir_dirent(struct filestr_base *stream, FILE_ERROR(ERRNO, rc * 10 - 1); if (rc == 0) + { + logf("Found root item: %d %s", item, entry->d_name); item++; + } } else { get_mount_point_entry(IF_MV(item,) entry); item++; rc = 1; + logf("Found mp item:%d %s", item, entry->d_name); } scanp->item = item; @@ -255,6 +303,7 @@ file_eod: empty_dirent(entry); #endif file_error: + logf("%s: status: %d", __func__, rc); return rc; } @@ -262,6 +311,7 @@ file_error: int ns_open_stream(const char *path, unsigned int callflags, struct filestr_base *stream, struct ns_scan_info *scanp) { + logf("%s: path: %s", __func__, path); /* stream still needs synchronization even if we don't have a stream */ static struct mutex no_contents_mtx SHAREDBSS_ATTR;