summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-02-11 15:27:23 +0100
committerThomas Martitz <kugel@rockbox.org>2014-02-23 20:23:52 +0100
commit0f928f87850153a38c7e6cfafd283ce4f52a0666 (patch)
tree55bbb19b5a17cd6e30a29bb3c2446a6e4c02738a
parentcbc57af0f3192093177d90861df72c4074566cf8 (diff)
downloadrockbox-0f928f87850153a38c7e6cfafd283ce4f52a0666.tar.gz
rockbox-0f928f87850153a38c7e6cfafd283ce4f52a0666.zip
RaaA: Move directory related stuff from filesystem-unix.c into rbpaths.c.
Part of this change is to align sdlapp builds to other application targets in that the sim_* wrappers are not used anymore (except for sim_read/write). Path mangling is now done in rbpaths.c as well. Change-Id: I9726da73b50a83d9e1a1840288de16ec01ea029d
-rw-r--r--firmware/common/filefuncs.c2
-rw-r--r--firmware/common/rbpaths.c173
-rw-r--r--firmware/export/rbpaths.h18
-rw-r--r--firmware/include/dir_uncached.h32
-rw-r--r--firmware/include/file.h42
-rw-r--r--firmware/target/hosted/android/dir-target.h46
-rw-r--r--firmware/target/hosted/filesystem-unix.c103
-rw-r--r--firmware/target/hosted/samsungypr/dir-target.h48
-rw-r--r--tools/checkwps/dir-target.h27
-rw-r--r--uisimulator/common/io.c82
10 files changed, 216 insertions, 357 deletions
diff --git a/firmware/common/filefuncs.c b/firmware/common/filefuncs.c
index 6c0275709c..16f8d88684 100644
--- a/firmware/common/filefuncs.c
+++ b/firmware/common/filefuncs.c
@@ -93,7 +93,7 @@ bool dir_exists(const char *path)
93} 93}
94 94
95 95
96#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) 96#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SIMULATOR)
97struct dirinfo dir_get_info(DIR* parent, struct dirent *entry) 97struct dirinfo dir_get_info(DIR* parent, struct dirent *entry)
98{ 98{
99 (void)parent; 99 (void)parent;
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index a188cf6642..8efb6dd238 100644
--- a/firmware/common/rbpaths.c
+++ b/firmware/common/rbpaths.c
@@ -23,6 +23,9 @@
23#include <stdio.h> /* snprintf */ 23#include <stdio.h> /* snprintf */
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdarg.h> 25#include <stdarg.h>
26#include <sys/stat.h>
27#include <time.h>
28#include <unistd.h>
26#include "config.h" 29#include "config.h"
27#include "rbpaths.h" 30#include "rbpaths.h"
28#include "file.h" /* MAX_PATH */ 31#include "file.h" /* MAX_PATH */
@@ -31,39 +34,34 @@
31#include "string-extra.h" 34#include "string-extra.h"
32#include "filefuncs.h" 35#include "filefuncs.h"
33 36
37/* In this file we need the actual OS library functions, not the shadowed
38 * wrapper used within Rockbox' application code (except SDL adds
39 * another layer) */
34#undef open 40#undef open
35#undef creat 41#undef creat
36#undef remove 42#undef remove
37#undef rename 43#undef rename
38#undef opendir 44#undef opendir
45#undef closedir
46#undef readdir
39#undef mkdir 47#undef mkdir
40#undef rmdir 48#undef rmdir
49#undef dirent
50#undef DIR
41 51
42
43#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) && !defined(__PCTOOL__)
44#include "dir-target.h"
45#define opendir _opendir
46#define mkdir _mkdir
47#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 52#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
48static const char rbhome[] = "/sdcard"; 53static const char rbhome[] = "/sdcard";
49#endif 54#endif
50#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) && !defined(__PCTOOL__) 55#if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) && !defined(__PCTOOL__)
51#define open sim_open
52#define remove sim_remove
53#define rename sim_rename
54#define opendir sim_opendir
55#define mkdir sim_mkdir
56#define rmdir sim_rmdir
57extern int sim_open(const char* name, int o, ...);
58extern int sim_remove(const char* name);
59extern int sim_rename(const char* old, const char* new);
60extern DIR* sim_opendir(const char* name);
61extern int sim_mkdir(const char* name);
62extern int sim_rmdir(const char* name);
63const char *rbhome; 56const char *rbhome;
64#endif 57#endif
65 58
66#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)) && !defined(__PCTOOL__) 59#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)) && !defined(__PCTOOL__)
60/* Special dirs are user-accessible (and user-writable) dirs which take priority
61 * over the ones where Rockbox is installed to. Classic example would be
62 * $HOME/.config/rockbox.org vs /usr/share/rockbox */
63#define HAVE_SPECIAL_DIRS
64#endif
67 65
68/* flags for get_user_file_path() */ 66/* flags for get_user_file_path() */
69/* whether you need write access to that file/dir, especially true 67/* whether you need write access to that file/dir, especially true
@@ -72,12 +70,13 @@ const char *rbhome;
72/* file or directory? */ 70/* file or directory? */
73#define IS_FILE (1<<1) 71#define IS_FILE (1<<1)
74 72
73#ifdef HAVE_SPECIAL_DIRS
75void paths_init(void) 74void paths_init(void)
76{ 75{
77 /* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */ 76 /* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */
78#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 77#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
79 mkdir("/sdcard/rockbox"); 78 mkdir("/sdcard/rockbox", 0777);
80 mkdir("/sdcard/rockbox/rocks.data"); 79 mkdir("/sdcard/rockbox/rocks.data", 0777);
81#else 80#else
82 char config_dir[MAX_PATH]; 81 char config_dir[MAX_PATH];
83 82
@@ -94,13 +93,14 @@ void paths_init(void)
94 93
95 rbhome = home; 94 rbhome = home;
96 snprintf(config_dir, sizeof(config_dir), "%s/.config", home); 95 snprintf(config_dir, sizeof(config_dir), "%s/.config", home);
97 mkdir(config_dir); 96 mkdir(config_dir, 0777);
98 snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org", home); 97 snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org", home);
99 mkdir(config_dir); 98 mkdir(config_dir, 0777);
100 /* Plugin data directory */ 99 /* Plugin data directory */
101 snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org/rocks.data", home); 100 snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org/rocks.data", home);
102 mkdir(config_dir); 101 mkdir(config_dir, 0777);
103#endif 102#endif
103
104} 104}
105 105
106static bool try_path(const char* filename, unsigned flags) 106static bool try_path(const char* filename, unsigned flags)
@@ -173,6 +173,21 @@ static const char* handle_special_dirs(const char* dir, unsigned flags,
173 return dir; 173 return dir;
174} 174}
175 175
176#else /* !HAVE_SPECIAL_DIRS */
177
178#ifndef paths_init
179void paths_init(void) { }
180#endif
181
182static const char* handle_special_dirs(const char* dir, unsigned flags,
183 char *buf, const size_t bufsize)
184{
185 (void) flags; (void) buf; (void) bufsize;
186 return dir;
187}
188
189#endif
190
176int app_open(const char *name, int o, ...) 191int app_open(const char *name, int o, ...)
177{ 192{
178 char realpath[MAX_PATH]; 193 char realpath[MAX_PATH];
@@ -215,48 +230,102 @@ int app_rename(const char *old, const char *new)
215 return rename(final_old, final_new); 230 return rename(final_old, final_new);
216} 231}
217 232
218DIR *app_opendir(const char *name) 233/* need to wrap around DIR* because we need to save the parent's
234 * directory path in order to determine dirinfo, required to implement
235 * get_dir_info() */
236struct __dir {
237 DIR *dir;
238 char path[];
239};
240
241struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
242{
243 struct __dir *parent = (struct __dir*)_parent;
244 struct stat s;
245 struct tm *tm = NULL;
246 struct dirinfo ret;
247 char path[MAX_PATH];
248
249 snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
250 memset(&ret, 0, sizeof(ret));
251
252 if (!stat(path, &s))
253 {
254 if (S_ISDIR(s.st_mode))
255 {
256 ret.attribute = ATTR_DIRECTORY;
257 }
258 ret.size = s.st_size;
259 tm = localtime(&(s.st_mtime));
260 }
261
262 if (!lstat(path, &s) && S_ISLNK(s.st_mode))
263 {
264 ret.attribute |= ATTR_LINK;
265 }
266
267 if (tm)
268 {
269 ret.wrtdate = ((tm->tm_year - 80) << 9) |
270 ((tm->tm_mon + 1) << 5) |
271 tm->tm_mday;
272 ret.wrttime = (tm->tm_hour << 11) |
273 (tm->tm_min << 5) |
274 (tm->tm_sec >> 1);
275 }
276
277 return ret;
278}
279
280DIR* app_opendir(const char *_name)
219{ 281{
220 char realpath[MAX_PATH]; 282 char realpath[MAX_PATH];
221 const char *fname = handle_special_dirs(name, 0, realpath, sizeof(realpath)); 283 const char *name = handle_special_dirs(_name, 0, realpath, sizeof(realpath));
222 return opendir(fname); 284 char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
285 if (!buf)
286 return NULL;
287
288 struct __dir *this = (struct __dir*)buf;
289 /* definitely fits due to strlen() */
290 strcpy(this->path, name);
291
292 this->dir = opendir(name);
293
294 if (!this->dir)
295 {
296 free(buf);
297 return NULL;
298 }
299 return (DIR*)this;
300}
301
302int app_closedir(DIR *dir)
303{
304 struct __dir *this = (struct __dir*)dir;
305 int ret = closedir(this->dir);
306 free(this);
307 return ret;
308}
309
310
311struct dirent* app_readdir(DIR* dir)
312{
313 struct __dir *d = (struct __dir*)dir;
314 return readdir(d->dir);
223} 315}
224 316
317
225int app_mkdir(const char* name) 318int app_mkdir(const char* name)
226{ 319{
227 char realpath[MAX_PATH]; 320 char realpath[MAX_PATH];
228 const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath)); 321 const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
229 return mkdir(fname); 322 return mkdir(fname, 0777);
230} 323}
231 324
325
232int app_rmdir(const char* name) 326int app_rmdir(const char* name)
233{ 327{
234 char realpath[MAX_PATH]; 328 char realpath[MAX_PATH];
235 const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath)); 329 const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
236 return rmdir(fname); 330 return rmdir(fname);
237} 331}
238
239#else
240
241int app_open(const char *name, int o, ...)
242{
243 if (o & O_CREAT)
244 {
245 int ret;
246 va_list ap;
247 va_start(ap, o);
248 ret = open(name, o, va_arg(ap, mode_t));
249 va_end(ap);
250 return ret;
251 }
252 return open(name, o);
253}
254
255int app_creat(const char* name, mode_t mode) { return creat(name, mode); }
256int app_remove(const char *name) { return remove(name); }
257int app_rename(const char *old, const char *new) { return rename(old,new); }
258DIR *app_opendir(const char *name) { return (DIR*)opendir(name); } /* cast to remove warning in checkwps */
259int app_mkdir(const char* name) { return mkdir(name); }
260int app_rmdir(const char* name) { return rmdir(name); }
261
262#endif
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h
index 9fa1d32286..0a5b36c5ab 100644
--- a/firmware/export/rbpaths.h
+++ b/firmware/export/rbpaths.h
@@ -73,6 +73,23 @@ extern void paths_init(void);
73 73
74#endif /* !APPLICATION || SAMSUNG_YPR0 */ 74#endif /* !APPLICATION || SAMSUNG_YPR0 */
75 75
76#ifdef APPLICATION
77
78#include <dirent.h>
79#include <fcntl.h>
80
81int app_open(const char *name, int o, ...);
82int app_creat(const char* name, mode_t mode);
83int app_remove(const char *name);
84int app_rename(const char *old, const char *new);
85DIR* app_opendir(const char *_name);
86int app_closedir(DIR *dir);
87struct dirent* app_readdir(DIR* dir);
88int app_mkdir(const char* name);
89int app_rmdir(const char* name);
90
91#endif
92
76#define REC_BASE_DIR HOME_DIR 93#define REC_BASE_DIR HOME_DIR
77#define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists" 94#define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists"
78 95
@@ -120,4 +137,5 @@ extern void paths_init(void);
120#define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control" 137#define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control"
121#define NVRAM_FILE ROCKBOX_DIR "/nvram.bin" 138#define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
122#define GLYPH_CACHE_FILE ROCKBOX_DIR "/.glyphcache" 139#define GLYPH_CACHE_FILE ROCKBOX_DIR "/.glyphcache"
140
123#endif /* __PATHS_H__ */ 141#endif /* __PATHS_H__ */
diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
index 1f9b8c1a4e..6443d5ba97 100644
--- a/firmware/include/dir_uncached.h
+++ b/firmware/include/dir_uncached.h
@@ -33,7 +33,7 @@ struct dirinfo {
33#include <stdbool.h> 33#include <stdbool.h>
34#include "file.h" 34#include "file.h"
35 35
36#if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) || defined(__PCTOOL__) 36#if defined(SIMULATOR) || defined(__PCTOOL__)
37# define dirent_uncached sim_dirent 37# define dirent_uncached sim_dirent
38# define DIR_UNCACHED SIM_DIR 38# define DIR_UNCACHED SIM_DIR
39# define opendir_uncached sim_opendir 39# define opendir_uncached sim_opendir
@@ -41,10 +41,21 @@ struct dirinfo {
41# define closedir_uncached sim_closedir 41# define closedir_uncached sim_closedir
42# define mkdir_uncached sim_mkdir 42# define mkdir_uncached sim_mkdir
43# define rmdir_uncached sim_rmdir 43# define rmdir_uncached sim_rmdir
44#elif defined(APPLICATION)
45# include "rbpaths.h"
46# define DIRENT_DEFINED
47# define DIR_DEFINED
48# define dirent_uncached dirent
49# define DIR_UNCACHED DIR
50# define opendir_uncached app_opendir
51# define readdir_uncached app_readdir
52# define closedir_uncached app_closedir
53# define mkdir_uncached app_mkdir
54# define rmdir_uncached app_rmdir
44#endif 55#endif
45 56
46#ifndef DIRENT_DEFINED
47 57
58#ifndef DIRENT_DEFINED
48struct dirent_uncached { 59struct dirent_uncached {
49 unsigned char d_name[MAX_PATH]; 60 unsigned char d_name[MAX_PATH];
50 struct dirinfo info; 61 struct dirinfo info;
@@ -72,23 +83,6 @@ typedef struct {
72} DIR_UNCACHED CACHEALIGN_ATTR; 83} DIR_UNCACHED CACHEALIGN_ATTR;
73#endif 84#endif
74 85
75
76#if defined(APPLICATION) && !defined(__PCTOOL__)
77#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)
78#include "dir-target.h"
79#endif
80# undef opendir_uncached
81# define opendir_uncached app_opendir
82# undef mkdir_uncached
83# define mkdir_uncached app_mkdir
84# undef rmdir_uncached
85# define rmdir_uncached app_rmdir
86/* defined in rbpaths.c */
87extern DIR_UNCACHED* app_opendir(const char* name);
88extern int app_rmdir(const char* name);
89extern int app_mkdir(const char* name);
90#endif
91
92#ifdef HAVE_HOTSWAP 86#ifdef HAVE_HOTSWAP
93char *get_volume_name(int volume); 87char *get_volume_name(int volume);
94#endif 88#endif
diff --git a/firmware/include/file.h b/firmware/include/file.h
index 4ba9c503b4..9b7f123999 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -38,33 +38,27 @@
38 38
39#if !defined(PLUGIN) && !defined(CODEC) 39#if !defined(PLUGIN) && !defined(CODEC)
40#if defined(APPLICATION) && !defined(__PCTOOL__) 40#if defined(APPLICATION) && !defined(__PCTOOL__)
41# define open(x, ...) app_open(x, __VA_ARGS__) 41#include "rbpaths.h"
42# define creat(x,m) app_creat(x, m) 42# define open(x, ...) app_open(x, __VA_ARGS__)
43# define remove(x) app_remove(x) 43# define creat(x,m) app_creat(x, m)
44# define rename(x,y) app_rename(x,y) 44# define remove(x) app_remove(x)
45extern int app_open(const char *name, int o, ...); 45# define rename(x,y) app_rename(x,y)
46extern int app_creat(const char *name, mode_t mode);
47extern int app_remove(const char* pathname);
48extern int app_rename(const char* path, const char* newname);
49# if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) 46# if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
50# define fsync(x) sim_fsync(x) 47/* SDL overrides a few more */
51# define ftruncate(x,y) sim_ftruncate(x,y) 48# define read(x,y,z) sim_read(x,y,z)
52# define lseek(x,y,z) sim_lseek(x,y,z) 49# define write(x,y,z) sim_write(x,y,z)
53# define read(x,y,z) sim_read(x,y,z)
54# define write(x,y,z) sim_write(x,y,z)
55# define close(x) sim_close(x)
56# endif 50# endif
57#elif defined(SIMULATOR) || defined(DBTOOL) 51#elif defined(SIMULATOR) || defined(DBTOOL)
58# define open(x, ...) sim_open(x, __VA_ARGS__) 52# define open(x, ...) sim_open(x, __VA_ARGS__)
59# define creat(x,m) sim_creat(x,m) 53# define creat(x,m) sim_creat(x,m)
60# define remove(x) sim_remove(x) 54# define remove(x) sim_remove(x)
61# define rename(x,y) sim_rename(x,y) 55# define rename(x,y) sim_rename(x,y)
62# define fsync(x) sim_fsync(x) 56# define fsync(x) sim_fsync(x)
63# define ftruncate(x,y) sim_ftruncate(x,y) 57# define ftruncate(x,y) sim_ftruncate(x,y)
64# define lseek(x,y,z) sim_lseek(x,y,z) 58# define lseek(x,y,z) sim_lseek(x,y,z)
65# define read(x,y,z) sim_read(x,y,z) 59# define read(x,y,z) sim_read(x,y,z)
66# define write(x,y,z) sim_write(x,y,z) 60# define write(x,y,z) sim_write(x,y,z)
67# define close(x) sim_close(x) 61# define close(x) sim_close(x)
68extern int sim_open(const char *name, int o, ...); 62extern int sim_open(const char *name, int o, ...);
69extern int sim_creat(const char *name, mode_t mode); 63extern int sim_creat(const char *name, mode_t mode);
70#endif 64#endif
diff --git a/firmware/target/hosted/android/dir-target.h b/firmware/target/hosted/android/dir-target.h
deleted file mode 100644
index 6962d943fe..0000000000
--- a/firmware/target/hosted/android/dir-target.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __DIR_TARGET_H__
23#define __DIR_TARGET_H__
24
25#include <dirent.h>
26
27#define dirent_uncached dirent
28#define DIR_UNCACHED DIR
29#define opendir_uncached _opendir
30#define readdir_uncached _readdir
31#define closedir_uncached _closedir
32#define mkdir_uncached _mkdir
33#define rmdir_uncached rmdir
34
35extern DIR* _opendir(const char* name);
36extern int _mkdir(const char* name);
37extern int rmdir(const char* name);
38extern int _closedir(DIR* dir);
39extern struct dirent *_readdir(DIR* dir);
40extern void fat_size(unsigned long *size, unsigned long *free);
41
42#define DIRFUNCTIONS_DEFINED
43#define DIRENT_DEFINED
44#define DIR_DEFINED
45
46#endif /* __DIR_TARGET_H__ */
diff --git a/firmware/target/hosted/filesystem-unix.c b/firmware/target/hosted/filesystem-unix.c
index 45b9e0fca1..8ac1d4ada9 100644
--- a/firmware/target/hosted/filesystem-unix.c
+++ b/firmware/target/hosted/filesystem-unix.c
@@ -19,17 +19,8 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include <stdlib.h>
23#include <sys/stat.h> /* stat() */ 22#include <sys/stat.h> /* stat() */
24#include <stdio.h> /* snprintf */ 23#include "mv.h" /* stat() */
25#include <string.h> /* size_t */
26#include <dirent.h>
27#include <time.h> /* localtime() */
28#include "system-target.h"
29#include "dir-target.h"
30#include "file.h"
31#include "dir.h"
32#include "rbpaths.h"
33 24
34 25
35long filesize(int fd) 26long filesize(int fd)
@@ -48,95 +39,3 @@ void fat_size(IF_MV(int volume,) unsigned long* size, unsigned long* free)
48 IF_MV((void) volume); 39 IF_MV((void) volume);
49 *size = *free = 0; 40 *size = *free = 0;
50} 41}
51
52#undef opendir
53#undef closedir
54#undef mkdir
55#undef readdir
56
57/* need to wrap around DIR* because we need to save the parent's
58 * directory path in order to determine dirinfo */
59struct __dir {
60 DIR *dir;
61 char *path;
62};
63
64DIR* _opendir(const char *name)
65{
66 char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
67 if (!buf)
68 return NULL;
69
70 struct __dir *this = (struct __dir*)buf;
71
72 this->path = buf+sizeof(struct __dir);
73 /* definitely fits due to strlen() */
74 strcpy(this->path, name);
75
76 this->dir = opendir(name);
77
78 if (!this->dir)
79 {
80 free(buf);
81 return NULL;
82 }
83 return (DIR*)this;
84}
85
86int _mkdir(const char *name)
87{
88 return mkdir(name, 0777);
89}
90
91int _closedir(DIR *dir)
92{
93 struct __dir *this = (struct __dir*)dir;
94 int ret = closedir(this->dir);
95 free(this);
96 return ret;
97}
98
99struct dirent* _readdir(DIR* dir)
100{
101 struct __dir *d = (struct __dir*)dir;
102 return readdir(d->dir);
103}
104
105struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
106{
107 struct __dir *parent = (struct __dir*)_parent;
108 struct stat s;
109 struct tm *tm = NULL;
110 struct dirinfo ret;
111 char path[MAX_PATH];
112
113 snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
114 memset(&ret, 0, sizeof(ret));
115
116 if (!stat(path, &s))
117 {
118 if (S_ISDIR(s.st_mode))
119 {
120 ret.attribute = ATTR_DIRECTORY;
121 }
122 ret.size = s.st_size;
123 tm = localtime(&(s.st_mtime));
124 }
125
126 if (!lstat(path, &s) && S_ISLNK(s.st_mode))
127 {
128 ret.attribute |= ATTR_LINK;
129 }
130
131 if (tm)
132 {
133 ret.wrtdate = ((tm->tm_year - 80) << 9) |
134 ((tm->tm_mon + 1) << 5) |
135 tm->tm_mday;
136 ret.wrttime = (tm->tm_hour << 11) |
137 (tm->tm_min << 5) |
138 (tm->tm_sec >> 1);
139 }
140
141 return ret;
142}
diff --git a/firmware/target/hosted/samsungypr/dir-target.h b/firmware/target/hosted/samsungypr/dir-target.h
deleted file mode 100644
index acd11d8041..0000000000
--- a/firmware/target/hosted/samsungypr/dir-target.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __DIR_TARGET_H__
23#define __DIR_TARGET_H__
24
25#include <dirent.h>
26/* including unistd.h is too noisy */
27extern int rmdir(const char* name);
28
29
30#define dirent_uncached dirent
31#define DIR_UNCACHED DIR
32#define opendir_uncached _opendir
33#define readdir_uncached _readdir
34#define closedir_uncached _closedir
35#define mkdir_uncached _mkdir
36#define rmdir_uncached rmdir
37
38extern DIR* _opendir(const char* name);
39extern int _mkdir(const char* name);
40extern int _rmdir(const char* name);
41extern int _closedir(DIR* dir);
42extern struct dirent *_readdir(DIR* dir);
43
44#define DIRFUNCTIONS_DEFINED
45#define DIRENT_DEFINED
46#define DIR_DEFINED
47
48#endif /* __DIR_TARGET_H__ */
diff --git a/tools/checkwps/dir-target.h b/tools/checkwps/dir-target.h
deleted file mode 100644
index efe76cb7fe..0000000000
--- a/tools/checkwps/dir-target.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <dirent.h>
24
25#define _mkdir mkdir
26#define _opendir opendir
27
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 690ef39f5f..9401f7d54a 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -155,6 +155,7 @@ void dircache_remove(const char *name);
155void dircache_rename(const char *oldname, const char *newname); 155void dircache_rename(const char *oldname, const char *newname);
156#endif 156#endif
157 157
158#ifndef APPLICATION
158 159
159#define SIMULATOR_DEFAULT_ROOT "simdisk" 160#define SIMULATOR_DEFAULT_ROOT "simdisk"
160extern const char *sim_root_dir; 161extern const char *sim_root_dir;
@@ -210,6 +211,8 @@ static unsigned int rockbox2sim(int opt)
210#endif 211#endif
211} 212}
212 213
214#endif /* APPLICATION */
215
213/** Simulator I/O engine routines **/ 216/** Simulator I/O engine routines **/
214#define IO_YIELD_THRESHOLD 512 217#define IO_YIELD_THRESHOLD 512
215 218
@@ -282,6 +285,43 @@ static ssize_t io_trigger_and_wait(enum io_dir cmd)
282 return result; 285 return result;
283} 286}
284 287
288
289ssize_t sim_read(int fd, void *buf, size_t count)
290{
291 ssize_t result;
292
293 mutex_lock(&io.sim_mutex);
294
295 /* Setup parameters */
296 io.fd = fd;
297 io.buf = buf;
298 io.count = count;
299
300 result = io_trigger_and_wait(IO_READ);
301
302 mutex_unlock(&io.sim_mutex);
303
304 return result;
305}
306
307
308ssize_t sim_write(int fd, const void *buf, size_t count)
309{
310 ssize_t result;
311
312 mutex_lock(&io.sim_mutex);
313
314 io.fd = fd;
315 io.buf = (void*)buf;
316 io.count = count;
317
318 result = io_trigger_and_wait(IO_WRITE);
319
320 mutex_unlock(&io.sim_mutex);
321
322 return result;
323}
324
285#if !defined(APPLICATION) 325#if !defined(APPLICATION)
286static const char *get_sim_pathname(const char *name) 326static const char *get_sim_pathname(const char *name)
287{ 327{
@@ -296,9 +336,6 @@ static const char *get_sim_pathname(const char *name)
296 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); 336 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name);
297 return name; 337 return name;
298} 338}
299#else
300#define get_sim_pathname(name) name
301#endif
302 339
303MYDIR *sim_opendir(const char *name) 340MYDIR *sim_opendir(const char *name)
304{ 341{
@@ -446,41 +483,6 @@ int sim_creat(const char *name, mode_t mode)
446 return ret; 483 return ret;
447} 484}
448 485
449ssize_t sim_read(int fd, void *buf, size_t count)
450{
451 ssize_t result;
452
453 mutex_lock(&io.sim_mutex);
454
455 /* Setup parameters */
456 io.fd = fd;
457 io.buf = buf;
458 io.count = count;
459
460 result = io_trigger_and_wait(IO_READ);
461
462 mutex_unlock(&io.sim_mutex);
463
464 return result;
465}
466
467ssize_t sim_write(int fd, const void *buf, size_t count)
468{
469 ssize_t result;
470
471 mutex_lock(&io.sim_mutex);
472
473 io.fd = fd;
474 io.buf = (void*)buf;
475 io.count = count;
476
477 result = io_trigger_and_wait(IO_WRITE);
478
479 mutex_unlock(&io.sim_mutex);
480
481 return result;
482}
483
484int sim_mkdir(const char *name) 486int sim_mkdir(const char *name)
485{ 487{
486 return MKDIR(get_sim_pathname(name), 0777); 488 return MKDIR(get_sim_pathname(name), 0777);
@@ -520,6 +522,10 @@ long sim_lseek(int fildes, long offset, int whence)
520 return lseek(fildes, offset, whence); 522 return lseek(fildes, offset, whence);
521} 523}
522 524
525#else
526#define get_sim_pathname(x) x
527#endif
528
523long filesize(int fd) 529long filesize(int fd)
524{ 530{
525#ifdef WIN32 531#ifdef WIN32