summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2024-05-02 13:38:32 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2024-05-02 13:38:32 -0400
commitefcea6628024c5f6796c3850c3779801db4b6874 (patch)
tree6b0a5ce6ce0ddb46de5e412dae110d9ba99414d5
parent0c737d3b2e4728347cf4d52025f9fc2ebbee6e90 (diff)
downloadrockbox-efcea6628024c5f6796c3850c3779801db4b6874.tar.gz
rockbox-efcea6628024c5f6796c3850c3779801db4b6874.zip
Revert "readdir_r use in tagcache.check_dir, ft_load"
This reverts commit 0c737d3b2e4728347cf4d52025f9fc2ebbee6e90. Reason for revert: Not really a concern as open_stream returns an independent buffer since g#566 Change-Id: Idbd2f4a7cc2ea6362b7714629469eeb7b3d19b3b
-rw-r--r--apps/filetree.c20
-rw-r--r--apps/tagcache.c6
-rw-r--r--firmware/common/dir.c40
-rw-r--r--firmware/target/hosted/filesystem-app.c50
-rw-r--r--firmware/target/hosted/filesystem-app.h1
-rw-r--r--uisimulator/common/filesystem-sim.c35
-rw-r--r--uisimulator/common/filesystem-sim.h1
7 files changed, 24 insertions, 129 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 99bb1340d7..b5f5dece5a 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -292,7 +292,6 @@ int ft_load(struct tree_context* c, const char* tempdir)
292 292
293 int files_in_dir = 0; 293 int files_in_dir = 0;
294 int name_buffer_used = 0; 294 int name_buffer_used = 0;
295 struct dirent direntry;
296 struct dirent *entry; 295 struct dirent *entry;
297 bool (*callback_show_item)(char *, int, struct tree_context *) = NULL; 296 bool (*callback_show_item)(char *, int, struct tree_context *) = NULL;
298 DIR *dir; 297 DIR *dir;
@@ -314,7 +313,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
314 c->dirfull = false; 313 c->dirfull = false;
315 314
316 tree_lock_cache(c); 315 tree_lock_cache(c);
317 while (readdir_r(dir, &direntry, &entry) == 0 && entry) { 316 while ((entry = readdir(dir))) {
318 int len; 317 int len;
319 struct dirinfo info; 318 struct dirinfo info;
320 struct entry* dptr = tree_get_entry_at(c, files_in_dir); 319 struct entry* dptr = tree_get_entry_at(c, files_in_dir);
@@ -327,17 +326,17 @@ int ft_load(struct tree_context* c, const char* tempdir)
327 info = dir_get_info(dir, entry); 326 info = dir_get_info(dir, entry);
328 len = strlen((char *)entry->d_name); 327 len = strlen((char *)entry->d_name);
329 328
330 /* Skip FAT volume ID */ 329 /* skip directories . and .. */
331 if (info.attribute & ATTR_VOLUME_ID) { 330 if ((info.attribute & ATTR_DIRECTORY) &&
331 (((len == 1) && (!strncmp((char *)entry->d_name, ".", 1))) ||
332 ((len == 2) && (!strncmp((char *)entry->d_name, "..", 2))))) {
332 continue; 333 continue;
333 } 334 }
334 335
335 dptr->attr = info.attribute; 336 /* Skip FAT volume ID */
336 int dir_attr = (dptr->attr & ATTR_DIRECTORY); 337 if (info.attribute & ATTR_VOLUME_ID) {
337
338 /* skip directories . and .. */
339 if (dir_attr && is_dotdir_name(entry->d_name))
340 continue; 338 continue;
339 }
341 340
342 /* filter out dotfiles and hidden files */ 341 /* filter out dotfiles and hidden files */
343 if (*c->dirfilter != SHOW_ALL && 342 if (*c->dirfilter != SHOW_ALL &&
@@ -346,6 +345,9 @@ int ft_load(struct tree_context* c, const char* tempdir)
346 continue; 345 continue;
347 } 346 }
348 347
348 dptr->attr = info.attribute;
349 int dir_attr = (dptr->attr & ATTR_DIRECTORY);
350
349 /* check for known file types */ 351 /* check for known file types */
350 if ( !(dir_attr) ) 352 if ( !(dir_attr) )
351 dptr->attr |= filetype_get_attr((char *)entry->d_name); 353 dptr->attr |= filetype_get_attr((char *)entry->d_name);
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 302b6ad9de..9463d7c865 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -4863,8 +4863,8 @@ static int free_search_roots(struct search_roots_ll * start)
4863 4863
4864static bool check_dir(const char *dirname, int add_files) 4864static bool check_dir(const char *dirname, int add_files)
4865{ 4865{
4866 static struct dirent direntry; /* function is recursive, static uses less stack */
4867 int success = false; 4866 int success = false;
4867
4868 DIR *dir = opendir(dirname); 4868 DIR *dir = opendir(dirname);
4869 if (!dir) 4869 if (!dir)
4870 { 4870 {
@@ -4883,9 +4883,7 @@ static bool check_dir(const char *dirname, int add_files)
4883 /* Recursively scan the dir. */ 4883 /* Recursively scan the dir. */
4884 while (!check_event_queue()) 4884 while (!check_event_queue())
4885 { 4885 {
4886 struct dirent *entry; 4886 struct dirent *entry = readdir(dir);
4887 readdir_r(dir, &direntry, &entry);
4888
4889 if (entry == NULL) 4887 if (entry == NULL)
4890 { 4888 {
4891 success = true; 4889 success = true;
diff --git a/firmware/common/dir.c b/firmware/common/dir.c
index 27af5f7fca..9a78d910a7 100644
--- a/firmware/common/dir.c
+++ b/firmware/common/dir.c
@@ -159,7 +159,6 @@ file_error:
159 return rc; 159 return rc;
160} 160}
161 161
162#if 0
163/* read a directory */ 162/* read a directory */
164struct dirent * readdir(DIR *dirp) 163struct dirent * readdir(DIR *dirp)
165{ 164{
@@ -183,19 +182,23 @@ file_error:
183 182
184 return res; 183 return res;
185} 184}
186#endif
187 185
188/* readdir, readdir_r common fn */ 186#if 0 /* not included now but probably should be */
189static int readdir_common(DIR *dirp, struct dirent *entry, struct dirent **result) 187/* read a directory (reentrant) */
188int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
190{ 189{
191 *result = NULL; /* we checked for validity before calling, yes? */ 190 if (!result)
191 FILE_ERROR_RETURN(EFAULT, -2);
192
193 *result = NULL;
194
195 if (!entry)
196 FILE_ERROR_RETURN(EFAULT, -3);
197
192 struct dirstr_desc * const dir = GET_DIRSTR(READER, dirp); 198 struct dirstr_desc * const dir = GET_DIRSTR(READER, dirp);
193 if (!dir) 199 if (!dir)
194 FILE_ERROR_RETURN(ERRNO, -1); 200 FILE_ERROR_RETURN(ERRNO, -1);
195 201
196 if (!entry)
197 entry = &dir->entry;
198
199 int rc = ns_readdir_dirent(&dir->stream, &dir->scan, entry); 202 int rc = ns_readdir_dirent(&dir->stream, &dir->scan, entry);
200 if (rc < 0) 203 if (rc < 0)
201 FILE_ERROR(EIO, rc * 10 - 4); 204 FILE_ERROR(EIO, rc * 10 - 4);
@@ -215,27 +218,6 @@ file_error:
215 return rc; 218 return rc;
216} 219}
217 220
218/* read a directory */
219struct dirent * readdir(DIR *dirp)
220{
221 struct dirent *entry;
222 readdir_common(dirp, NULL, &entry);
223 return entry;
224}
225
226/* read a directory (reentrant) */
227int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
228{
229 if (!result)
230 FILE_ERROR_RETURN(EFAULT, -2);
231 *result = NULL;
232 if (!entry)
233 FILE_ERROR_RETURN(EFAULT, -3);
234 return readdir_common(dirp, entry, result);
235}
236
237
238#if 0 /* not included now but probably should be */
239/* reset the position of a directory stream to the beginning of a directory */ 221/* reset the position of a directory stream to the beginning of a directory */
240void rewinddir(DIR *dirp) 222void rewinddir(DIR *dirp)
241{ 223{
diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c
index fc4fff0eb5..7d59a174dc 100644
--- a/firmware/target/hosted/filesystem-app.c
+++ b/firmware/target/hosted/filesystem-app.c
@@ -453,56 +453,6 @@ struct dirent * app_readdir(DIR *dirp)
453 return (struct dirent *)osdirent; 453 return (struct dirent *)osdirent;
454} 454}
455 455
456/* read a directory (reentrant) */
457int app_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
458{
459 struct __dir *this = (struct __dir *)dirp;
460 if (!this)
461 FILE_ERROR_RETURN(EBADF, -6);
462
463 if (!result)
464 FILE_ERROR_RETURN(EFAULT, -2);
465
466 *result = NULL;
467
468 if (!entry)
469 FILE_ERROR_RETURN(EFAULT, -3);
470
471#ifdef HAVE_MULTIDRIVE
472 if (this->volumes_returned < NUM_VOLUMES)
473 {
474 while (++this->volumes_returned < NUM_VOLUMES)
475 {
476 if (!volume_present(this->volumes_returned))
477 continue;
478
479 get_volume_name(this->volumes_returned, entry->d_name);
480 *result = entry;
481 return 0;
482 }
483 }
484 /* do normal directory reads */
485#endif /* HAVE_MULTIDRIVE */
486
487 OS_DIRENT_T *osdirent = os_readdir(this->osdirp);
488 if (!osdirent)
489 FILE_ERROR_RETURN(ERRNO, -4);
490#ifdef OS_DIRENT_CONVERT
491 size_t name_size = sizeof (entry->d_name);
492 if (strlcpy_from_os(entry->d_name, osdirent->d_name,
493 name_size) >= name_size)
494 {
495 entry->d_name[0] = '\0';
496 errno = EOVERFLOW;
497 FILE_ERROR_RETURN(ENAMETOOLONG, -5);
498 }
499
500 *result = entry;
501#endif /* OS_DIRENT_CONVERT */
502
503 return 0;
504}
505
506int app_mkdir(const char *path) 456int app_mkdir(const char *path)
507{ 457{
508 char realpath[MAX_PATH]; 458 char realpath[MAX_PATH];
diff --git a/firmware/target/hosted/filesystem-app.h b/firmware/target/hosted/filesystem-app.h
index 2d7d6e817d..b35b63e95f 100644
--- a/firmware/target/hosted/filesystem-app.h
+++ b/firmware/target/hosted/filesystem-app.h
@@ -107,7 +107,6 @@ ssize_t app_readlink(const char *path, char *buf, size_t bufsize);
107#ifndef DIRFUNCTIONS_DECLARED 107#ifndef DIRFUNCTIONS_DECLARED
108DIR * app_opendir(const char *dirname); 108DIR * app_opendir(const char *dirname);
109struct dirent * app_readdir(DIR *dirp); 109struct dirent * app_readdir(DIR *dirp);
110int app_readdir_r(DIR *dirp, struct dirent* entry, struct dirent **result);
111int app_closedir(DIR *dirp); 110int app_closedir(DIR *dirp);
112int app_mkdir(const char *path); 111int app_mkdir(const char *path);
113int app_rmdir(const char *path); 112int app_rmdir(const char *path);
diff --git a/uisimulator/common/filesystem-sim.c b/uisimulator/common/filesystem-sim.c
index 54e703ff40..f4f6321b7d 100644
--- a/uisimulator/common/filesystem-sim.c
+++ b/uisimulator/common/filesystem-sim.c
@@ -704,41 +704,6 @@ struct sim_dirent * sim_readdir(DIR *dirp)
704 return entry; 704 return entry;
705} 705}
706 706
707/* read a directory (reentrant) */
708int sim_readdir_r(DIR *dirp, struct sim_dirent *entry, struct sim_dirent **result)
709{
710 if (!result)
711 FILE_ERROR_RETURN(EFAULT, -2);
712
713 *result = NULL;
714
715 if (!entry)
716 FILE_ERROR_RETURN(EFAULT, -3);
717
718 struct dirstr_desc *dirstr = get_dirstr(dirp);
719 if (!dirstr)
720 FILE_ERROR_RETURN(ERRNO, -1);
721
722 entry->info.osdirent = NULL;
723
724 if (readdir_volume(dirstr, entry))
725 {
726 *result = entry;
727 return 0;
728 }
729 OS_DIRENT_T *osdirent = os_readdir(dirstr->osdirp);
730 if (!osdirent)
731 FILE_ERROR_RETURN(ERRNO, -4);
732
733 size_t size = sizeof (entry->d_name);
734 if (strlcpy_from_os(entry->d_name, osdirent->d_name, size) >= size)
735 FILE_ERROR_RETURN(ENAMETOOLONG, -5);
736
737 entry->info.osdirent = osdirent;
738 *result = entry;
739 return 0;
740}
741
742int sim_mkdir(const char *path) 707int sim_mkdir(const char *path)
743{ 708{
744 char ospath[SIM_TMPBUF_MAX_PATH]; 709 char ospath[SIM_TMPBUF_MAX_PATH];
diff --git a/uisimulator/common/filesystem-sim.h b/uisimulator/common/filesystem-sim.h
index 1b6c6dfe69..346d6fa74e 100644
--- a/uisimulator/common/filesystem-sim.h
+++ b/uisimulator/common/filesystem-sim.h
@@ -98,7 +98,6 @@ struct dirinfo_native
98#ifndef DIRFUNCTIONS_DECLARED 98#ifndef DIRFUNCTIONS_DECLARED
99DIR * sim_opendir(const char *dirname); 99DIR * sim_opendir(const char *dirname);
100struct sim_dirent * sim_readdir(DIR *dirp); 100struct sim_dirent * sim_readdir(DIR *dirp);
101int sim_readdir_r(DIR *dirp, struct sim_dirent* entry, struct sim_dirent **result);
102int sim_closedir(DIR *dirp); 101int sim_closedir(DIR *dirp);
103int sim_mkdir(const char *path); 102int sim_mkdir(const char *path);
104int sim_rmdir(const char *path); 103int sim_rmdir(const char *path);