summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/file.c17
-rw-r--r--firmware/common/file_internal.c8
-rw-r--r--firmware/common/rb_namespace.c56
3 files changed, 76 insertions, 5 deletions
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 @@
31#include "rb_namespace.h" 31#include "rb_namespace.h"
32#include "string-extra.h" 32#include "string-extra.h"
33 33
34/* Define LOGF_ENABLE to enable logf output in this file */
35//#define LOGF_ENABLE
36#ifdef LOGF_ENABLE
37#include "logf.h"
38#undef DEBUGF
39#define DEBUGF logf
40#endif
41
42
34/** 43/**
35 * These functions provide a roughly POSIX-compatible file I/O API. 44 * These functions provide a roughly POSIX-compatible file I/O API.
36 */ 45 */
@@ -600,8 +609,10 @@ static inline ssize_t readwrite_partial(struct filestr_desc *file,
600static ssize_t readwrite(struct filestr_desc *file, void *buf, size_t nbyte, 609static ssize_t readwrite(struct filestr_desc *file, void *buf, size_t nbyte,
601 bool write) 610 bool write)
602{ 611{
612#ifndef LOGF_ENABLE /* wipes out log before you can save it */
603 DEBUGF("readwrite(%p,%lx,%lu,%s)\n", 613 DEBUGF("readwrite(%p,%lx,%lu,%s)\n",
604 file, (long)buf, (unsigned long)nbyte, write ? "write" : "read"); 614 file, (long)buf, (unsigned long)nbyte, write ? "write" : "read");
615#endif
605 616
606 const file_size_t size = *file->sizep; 617 const file_size_t size = *file->sizep;
607 file_size_t filerem; 618 file_size_t filerem;
@@ -766,8 +777,9 @@ file_error:;
766 /* error or not, update the file offset and size if anything was 777 /* error or not, update the file offset and size if anything was
767 transferred */ 778 transferred */
768 file->offset += done; 779 file->offset += done;
780#ifndef LOGF_ENABLE /* wipes out log before you can save it */
769 DEBUGF("file offset: %ld\n", file->offset); 781 DEBUGF("file offset: %ld\n", file->offset);
770 782#endif
771 /* adjust file size to length written */ 783 /* adjust file size to length written */
772 if (write && file->offset > size) 784 if (write && file->offset > size)
773 *file->sizep = file->offset; 785 *file->sizep = file->offset;
@@ -901,8 +913,9 @@ file_error:
901/* move the read/write file offset */ 913/* move the read/write file offset */
902off_t lseek(int fildes, off_t offset, int whence) 914off_t lseek(int fildes, off_t offset, int whence)
903{ 915{
916#ifndef LOGF_ENABLE /* wipes out log before you can save it */
904 DEBUGF("lseek(fd=%d,ofs=%ld,wh=%d)\n", fildes, (long)offset, whence); 917 DEBUGF("lseek(fd=%d,ofs=%ld,wh=%d)\n", fildes, (long)offset, whence);
905 918#endif
906 struct filestr_desc * const file = GET_FILESTR(READER, fildes); 919 struct filestr_desc * const file = GET_FILESTR(READER, fildes);
907 if (!file) 920 if (!file)
908 FILE_ERROR_RETURN(ERRNO, -1); 921 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 @@
30#include "string-extra.h" 30#include "string-extra.h"
31#include "rbunicode.h" 31#include "rbunicode.h"
32 32
33/* Define LOGF_ENABLE to enable logf output in this file */
34//#define LOGF_ENABLE
35#ifdef LOGF_ENABLE
36#include "logf.h"
37#undef DEBUGF
38#define DEBUGF logf
39#endif
40
33/** Internal common filesystem service functions **/ 41/** Internal common filesystem service functions **/
34 42
35/* for internal functions' scanning use to save quite a bit of stack space - 43/* 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 @@
24#include "rb_namespace.h" 24#include "rb_namespace.h"
25#include "file_internal.h" 25#include "file_internal.h"
26 26
27/* Define LOGF_ENABLE to enable logf output in this file */
28//#define LOGF_ENABLE
29#include "logf.h"
30
31#if !defined(HAVE_MULTIVOLUME) && defined(LOGF_ENABLE)
32 int volume = 0;
33#endif
34
35
27#define ROOT_CONTENTS_INDEX (NUM_VOLUMES) 36#define ROOT_CONTENTS_INDEX (NUM_VOLUMES)
28#define NUM_ROOT_ITEMS (NUM_VOLUMES+1) 37#define NUM_ROOT_ITEMS (NUM_VOLUMES+1)
29 38
@@ -53,12 +62,14 @@ static void get_mount_point_entry(IF_MV(int volume,) struct DIRENT *entry)
53 entry->info.wrtdate = 0; 62 entry->info.wrtdate = 0;
54 entry->info.wrttime = 0; 63 entry->info.wrttime = 0;
55#endif /* is dirinfo_native */ 64#endif /* is dirinfo_native */
65 logf("%s: vol:%d, %s", __func__, volume, entry->d_name);
56} 66}
57 67
58/* unmount the directory that enumerates into the root namespace */ 68/* unmount the directory that enumerates into the root namespace */
59static void unmount_item(int item) 69static void unmount_item(int item)
60{ 70{
61 unsigned int state = get_root_item_state(item); 71 unsigned int state = get_root_item_state(item);
72 logf("%s: state: %u", __func__, state);
62 if (!state) 73 if (!state)
63 return; 74 return;
64 75
@@ -83,13 +94,18 @@ int root_mount_path(const char *path, unsigned int flags)
83 return -ENOENT; 94 return -ENOENT;
84#else 95#else
85 if (!path_is_absolute(path)) 96 if (!path_is_absolute(path))
97 {
98 logf("Path not absolute %s", path);
86 return -ENOENT; 99 return -ENOENT;
100 }
87#endif /* HAVE_MULTIVOLUME */ 101#endif /* HAVE_MULTIVOLUME */
88 102
89 bool contents = flags & NSITEM_CONTENTS; 103 bool contents = flags & NSITEM_CONTENTS;
90 int item = contents ? ROOT_CONTENTS_INDEX : IF_MV_VOL(volume); 104 int item = contents ? ROOT_CONTENTS_INDEX : IF_MV_VOL(volume);
91 unsigned int state = get_root_item_state(item); 105 unsigned int state = get_root_item_state(item);
92 106
107 logf("%s: item:%d, st:%u, %s", __func__, item, state, path);
108
93 if (state) 109 if (state)
94 return -EBUSY; 110 return -EBUSY;
95 111
@@ -122,6 +138,7 @@ int root_mount_path(const char *path, unsigned int flags)
122/* inform root that an entire volume is being unmounted */ 138/* inform root that an entire volume is being unmounted */
123void root_unmount_volume(IF_MV_NONVOID(int volume)) 139void root_unmount_volume(IF_MV_NONVOID(int volume))
124{ 140{
141 logf("%s: vol: %d", __func__, volume);
125 FOR_EACH_VOLUME(volume, item) 142 FOR_EACH_VOLUME(volume, item)
126 { 143 {
127 #ifdef HAVE_MULTIVOLUME 144 #ifdef HAVE_MULTIVOLUME
@@ -143,6 +160,7 @@ void root_unmount_volume(IF_MV_NONVOID(int volume))
143/* parse the root part of a path */ 160/* parse the root part of a path */
144int ns_parse_root(const char *path, const char **pathp, uint16_t *lenp) 161int ns_parse_root(const char *path, const char **pathp, uint16_t *lenp)
145{ 162{
163 logf("%s: path: %s", __func__, path);
146 int volume = ROOT_VOLUME; 164 int volume = ROOT_VOLUME;
147 165
148#ifdef HAVE_MULTIVOLUME 166#ifdef HAVE_MULTIVOLUME
@@ -151,19 +169,35 @@ int ns_parse_root(const char *path, const char **pathp, uint16_t *lenp)
151 const char *p; 169 const char *p;
152 volume = path_strip_volume(path, &p, false); 170 volume = path_strip_volume(path, &p, false);
153 if (volume != ROOT_VOLUME && !CHECK_VOL(volume)) 171 if (volume != ROOT_VOLUME && !CHECK_VOL(volume))
172 {
173 logf("vol: %d is not root", volume);
154 return -ENOENT; 174 return -ENOENT;
175 }
155#endif /* HAVE_MULTIVOLUME */ 176#endif /* HAVE_MULTIVOLUME */
156 177
157 /* set name to start at last leading separator; name of root will 178 /* set name to start at last leading separator; name of root will
158 * be returned as "/", volume specifiers as "/<fooN>" */ 179 * be returned as "/", volume specifiers as "/<fooN>" */
159 *pathp = GOBBLE_PATH_SEPCH(path) - 1; 180 *pathp = GOBBLE_PATH_SEPCH(path) - 1;
160 *lenp = IF_MV( volume < NUM_VOLUMES ? p - *pathp : ) 1; 181 *lenp = IF_MV( volume < NUM_VOLUMES ? p - *pathp : ) 1;
161 182#ifdef LOGF_ENABLE
183 if (volume == INT_MAX)
184 logf("vol: ROOT(%d) %s", volume, *pathp);
185 else
186 logf("vol: %d %s", volume, *pathp);
187#endif
162#ifdef HAVE_MULTIVOLUME 188#ifdef HAVE_MULTIVOLUME
163 if (*lenp > MAX_COMPNAME+1) 189 if (*lenp > MAX_COMPNAME+1)
190 {
191 logf("%s: path too long %s", __func__, path);
164 return -ENAMETOOLONG; 192 return -ENAMETOOLONG;
193 }
194#endif
195#ifdef LOGF_ENABLE
196 if (volume == INT_MAX)
197 logf("%s: vol: ROOT(%d) path: %s", __func__, volume, path);
198 else
199 logf("%s: vol: %d path: %s", __func__, volume, path);
165#endif 200#endif
166
167 return volume; 201 return volume;
168} 202}
169 203
@@ -183,7 +217,7 @@ int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp,
183 217
184 int item = sysroot ? ROOT_CONTENTS_INDEX : IF_MV_VOL(volume); 218 int item = sysroot ? ROOT_CONTENTS_INDEX : IF_MV_VOL(volume);
185 unsigned int state = get_root_item_state(item); 219 unsigned int state = get_root_item_state(item);
186 220 logf("%s: Vol:%d St:%d", __func__, item, state);
187 if (sysroot) 221 if (sysroot)
188 { 222 {
189 *attrp = ATTR_SYSTEM_ROOT; 223 *attrp = ATTR_SYSTEM_ROOT;
@@ -191,7 +225,10 @@ int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp,
191 if (state) 225 if (state)
192 *infop = root_bindp->info; 226 *infop = root_bindp->info;
193 else 227 else
228 {
229 logf("%s: SysRoot Vol:%d St:%d NOT mounted", __func__, item, state);
194 *callflagsp = callflags | FF_NOFS; /* contents not mounted */ 230 *callflagsp = callflags | FF_NOFS; /* contents not mounted */
231 }
195 } 232 }
196 else 233 else
197 { 234 {
@@ -201,7 +238,10 @@ int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp,
201 return -ENOENT; /* regular open requires having been mounted */ 238 return -ENOENT; /* regular open requires having been mounted */
202#if CONFIG_PLATFORM & PLATFORM_NATIVE 239#if CONFIG_PLATFORM & PLATFORM_NATIVE
203 if (fat_open_rootdir(IF_MV(volume,) &infop->fatfile) < 0) 240 if (fat_open_rootdir(IF_MV(volume,) &infop->fatfile) < 0)
241 {
242 logf("%s: DevPath Vol:%d St:%d NOT mounted", __func__, item, state);
204 return -ENOENT; /* not mounted */ 243 return -ENOENT; /* not mounted */
244 }
205#endif 245#endif
206 get_rootinfo_internal(infop); 246 get_rootinfo_internal(infop);
207 } 247 }
@@ -216,6 +256,7 @@ int root_readdir_dirent(struct filestr_base *stream,
216 int rc = 0; 256 int rc = 0;
217 257
218 int item = scanp->item; 258 int item = scanp->item;
259 logf("%s: item: %d", __func__, item);
219 260
220 /* skip any not-mounted or hidden items */ 261 /* skip any not-mounted or hidden items */
221 unsigned int state; 262 unsigned int state;
@@ -226,7 +267,10 @@ int root_readdir_dirent(struct filestr_base *stream,
226 267
227 state = get_root_item_state(item); 268 state = get_root_item_state(item);
228 if ((state & (NSITEM_MOUNTED|NSITEM_HIDDEN)) == NSITEM_MOUNTED) 269 if ((state & (NSITEM_MOUNTED|NSITEM_HIDDEN)) == NSITEM_MOUNTED)
270 {
271 logf("Found mounted item: %d %s", item, entry->d_name);
229 break; 272 break;
273 }
230 274
231 item++; 275 item++;
232 } 276 }
@@ -238,13 +282,17 @@ int root_readdir_dirent(struct filestr_base *stream,
238 FILE_ERROR(ERRNO, rc * 10 - 1); 282 FILE_ERROR(ERRNO, rc * 10 - 1);
239 283
240 if (rc == 0) 284 if (rc == 0)
285 {
286 logf("Found root item: %d %s", item, entry->d_name);
241 item++; 287 item++;
288 }
242 } 289 }
243 else 290 else
244 { 291 {
245 get_mount_point_entry(IF_MV(item,) entry); 292 get_mount_point_entry(IF_MV(item,) entry);
246 item++; 293 item++;
247 rc = 1; 294 rc = 1;
295 logf("Found mp item:%d %s", item, entry->d_name);
248 } 296 }
249 297
250 scanp->item = item; 298 scanp->item = item;
@@ -255,6 +303,7 @@ file_eod:
255 empty_dirent(entry); 303 empty_dirent(entry);
256#endif 304#endif
257file_error: 305file_error:
306 logf("%s: status: %d", __func__, rc);
258 return rc; 307 return rc;
259} 308}
260 309
@@ -262,6 +311,7 @@ file_error:
262int ns_open_stream(const char *path, unsigned int callflags, 311int ns_open_stream(const char *path, unsigned int callflags,
263 struct filestr_base *stream, struct ns_scan_info *scanp) 312 struct filestr_base *stream, struct ns_scan_info *scanp)
264{ 313{
314 logf("%s: path: %s", __func__, path);
265 /* stream still needs synchronization even if we don't have a stream */ 315 /* stream still needs synchronization even if we don't have a stream */
266 static struct mutex no_contents_mtx SHAREDBSS_ATTR; 316 static struct mutex no_contents_mtx SHAREDBSS_ATTR;
267 317