diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-12-25 20:11:18 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-12-25 20:11:18 +0000 |
commit | 20b662a946861b5acee8970948a22f7a2d1aedf3 (patch) | |
tree | 392d9568a3baaa23be0e109799485255ddcd067f | |
parent | 16784598ac550dab147ea8ee15634a2f15739fff (diff) | |
download | rockbox-20b662a946861b5acee8970948a22f7a2d1aedf3.tar.gz rockbox-20b662a946861b5acee8970948a22f7a2d1aedf3.zip |
rbpaths: Add new special dir HOME_DIR for RaaA.
HOME_DIR is intended for not-so-advanced files which shall be user
visible, and thus not in /.rockbox. Therefore HOME_DIR is translated
to $HOME on RaaA, /sdcard on android, the internal memory on ypr0
and "/" on native targets.
ROCKBOX_DIR ("/.rockbox") already existed as special and is translated
to whatever the real rockbox dir is on the target (e.g. /sdcard/rockbox
on android), but it's not suitable for some files we generate
(e.g. battery-bench.txt).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31430 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/battery_bench.c | 2 | ||||
-rw-r--r-- | apps/plugins/test_codec.c | 2 | ||||
-rw-r--r-- | apps/plugins/test_disk.c | 4 | ||||
-rw-r--r-- | apps/plugins/test_gfx.c | 2 | ||||
-rw-r--r-- | apps/plugins/test_grey.c | 2 | ||||
-rw-r--r-- | firmware/common/rbpaths.c | 68 | ||||
-rw-r--r-- | firmware/export/rbpaths.h | 23 | ||||
-rw-r--r-- | firmware/general.c | 3 |
8 files changed, 54 insertions, 52 deletions
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index be509cffcb..302d74c02a 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "plugin.h" | 24 | #include "plugin.h" |
25 | 25 | ||
26 | 26 | ||
27 | #define BATTERY_LOG "/battery_bench.txt" | 27 | #define BATTERY_LOG HOME_DIR"/battery_bench.txt" |
28 | #define BUF_SIZE 16000 | 28 | #define BUF_SIZE 16000 |
29 | 29 | ||
30 | #define EV_EXIT 1337 | 30 | #define EV_EXIT 1337 |
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c index 849b40de42..4c0739f660 100644 --- a/apps/plugins/test_codec.c +++ b/apps/plugins/test_codec.c | |||
@@ -80,7 +80,7 @@ static bool log_init(bool use_logfile) | |||
80 | 80 | ||
81 | if (use_logfile) { | 81 | if (use_logfile) { |
82 | log_close(); | 82 | log_close(); |
83 | rb->create_numbered_filename(logfilename, "/", "test_codec_log_", ".txt", | 83 | rb->create_numbered_filename(logfilename, HOME_DIR, "test_codec_log_", ".txt", |
84 | 2 IF_CNFN_NUM_(, NULL)); | 84 | 2 IF_CNFN_NUM_(, NULL)); |
85 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); | 85 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
86 | return log_fd >= 0; | 86 | return log_fd >= 0; |
diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c index 6d5ea29d57..7c46101ebc 100644 --- a/apps/plugins/test_disk.c +++ b/apps/plugins/test_disk.c | |||
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | 25 | ||
26 | 26 | ||
27 | #define TESTBASEDIR "/__TEST__" | 27 | #define TESTBASEDIR HOME_DIR "/__TEST__" |
28 | #define TEST_FILE TESTBASEDIR "/test_disk.tmp" | 28 | #define TEST_FILE TESTBASEDIR "/test_disk.tmp" |
29 | #define FRND_SEED 0x78C3 /* arbirary */ | 29 | #define FRND_SEED 0x78C3 /* arbirary */ |
30 | 30 | ||
@@ -83,7 +83,7 @@ static bool log_init(void) | |||
83 | rb->lcd_clear_display(); | 83 | rb->lcd_clear_display(); |
84 | rb->lcd_update(); | 84 | rb->lcd_update(); |
85 | 85 | ||
86 | rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt", | 86 | rb->create_numbered_filename(logfilename, HOME_DIR, "test_disk_log_", ".txt", |
87 | 2 IF_CNFN_NUM_(, NULL)); | 87 | 2 IF_CNFN_NUM_(, NULL)); |
88 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); | 88 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
89 | return log_fd >= 0; | 89 | return log_fd >= 0; |
diff --git a/apps/plugins/test_gfx.c b/apps/plugins/test_gfx.c index 4081e64d13..1dfab8c3b4 100644 --- a/apps/plugins/test_gfx.c +++ b/apps/plugins/test_gfx.c | |||
@@ -46,7 +46,7 @@ static int log_init(void) | |||
46 | char logfilename[MAX_PATH]; | 46 | char logfilename[MAX_PATH]; |
47 | int fd; | 47 | int fd; |
48 | 48 | ||
49 | rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt", | 49 | rb->create_numbered_filename(logfilename, HOME_DIR, "test_gfx_log_", ".txt", |
50 | 2 IF_CNFN_NUM_(, NULL)); | 50 | 2 IF_CNFN_NUM_(, NULL)); |
51 | fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); | 51 | fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
52 | return fd; | 52 | return fd; |
diff --git a/apps/plugins/test_grey.c b/apps/plugins/test_grey.c index efceeff2c3..f4555c1eed 100644 --- a/apps/plugins/test_grey.c +++ b/apps/plugins/test_grey.c | |||
@@ -247,7 +247,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
247 | case GREY_OK: | 247 | case GREY_OK: |
248 | 248 | ||
249 | /* dump result in form suitable for lcdlinear[] */ | 249 | /* dump result in form suitable for lcdlinear[] */ |
250 | rb->create_numbered_filename(filename, "/", "test_grey_", | 250 | rb->create_numbered_filename(filename, HOME_DIR, "test_grey_", |
251 | ".txt", 2 IF_CNFN_NUM_(, NULL)); | 251 | ".txt", 2 IF_CNFN_NUM_(, NULL)); |
252 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); | 252 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
253 | if (fd >= 0) | 253 | if (fd >= 0) |
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c index 95bff3341f..aacd949430 100644 --- a/firmware/common/rbpaths.c +++ b/firmware/common/rbpaths.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #define opendir opendir_android | 45 | #define opendir opendir_android |
46 | #define mkdir mkdir_android | 46 | #define mkdir mkdir_android |
47 | #define rmdir rmdir_android | 47 | #define rmdir rmdir_android |
48 | static const char rbhome[] = "/sdcard"; | ||
48 | #elif defined(SAMSUNG_YPR0) | 49 | #elif defined(SAMSUNG_YPR0) |
49 | #include "dir-target.h" | 50 | #include "dir-target.h" |
50 | #define opendir opendir_ypr0 | 51 | #define opendir opendir_ypr0 |
@@ -159,19 +160,34 @@ static const char* _get_user_file_path(const char *path, | |||
159 | return ret; | 160 | return ret; |
160 | } | 161 | } |
161 | 162 | ||
163 | |||
164 | static const char* handle_special_dirs(const char* dir, unsigned flags, | ||
165 | char *buf, const size_t bufsize) | ||
166 | { | ||
167 | if (!strncmp(HOME_DIR, dir, HOME_DIR_LEN)) | ||
168 | { | ||
169 | const char *p = dir + HOME_DIR_LEN; | ||
170 | while (*p == '/') p++; | ||
171 | snprintf(buf, bufsize, "%s/%s", rbhome, p); | ||
172 | return buf; | ||
173 | } | ||
174 | else if (!strncmp(ROCKBOX_DIR, dir, ROCKBOX_DIR_LEN)) | ||
175 | return _get_user_file_path(dir, flags, buf, bufsize); | ||
176 | |||
177 | return dir; | ||
178 | } | ||
179 | |||
162 | int app_open(const char *name, int o, ...) | 180 | int app_open(const char *name, int o, ...) |
163 | { | 181 | { |
164 | char realpath[MAX_PATH]; | 182 | char realpath[MAX_PATH]; |
165 | va_list ap; | 183 | va_list ap; |
166 | int fd; | 184 | int fd; |
185 | int flags = IS_FILE; | ||
186 | if (o & (O_CREAT|O_RDWR|O_TRUNC|O_WRONLY)) | ||
187 | flags |= NEED_WRITE; | ||
167 | 188 | ||
168 | if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) | 189 | name = handle_special_dirs(name, flags, realpath, sizeof(realpath)); |
169 | { | 190 | |
170 | int flags = IS_FILE; | ||
171 | if (o & (O_CREAT|O_RDWR|O_TRUNC|O_WRONLY)) | ||
172 | flags |= NEED_WRITE; | ||
173 | name = _get_user_file_path(name, flags, realpath, sizeof(realpath)); | ||
174 | } | ||
175 | va_start(ap, o); | 191 | va_start(ap, o); |
176 | fd = open(name, o, va_arg(ap, unsigned int)); | 192 | fd = open(name, o, va_arg(ap, unsigned int)); |
177 | va_end(ap); | 193 | va_end(ap); |
@@ -187,11 +203,7 @@ int app_creat(const char* name, mode_t mode) | |||
187 | int app_remove(const char *name) | 203 | int app_remove(const char *name) |
188 | { | 204 | { |
189 | char realpath[MAX_PATH]; | 205 | char realpath[MAX_PATH]; |
190 | const char *fname = name; | 206 | const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath)); |
191 | if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) | ||
192 | { | ||
193 | fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath)); | ||
194 | } | ||
195 | 207 | ||
196 | return remove(fname); | 208 | return remove(fname); |
197 | } | 209 | } |
@@ -199,18 +211,10 @@ int app_remove(const char *name) | |||
199 | int app_rename(const char *old, const char *new) | 211 | int app_rename(const char *old, const char *new) |
200 | { | 212 | { |
201 | char realpath_old[MAX_PATH], realpath_new[MAX_PATH]; | 213 | char realpath_old[MAX_PATH], realpath_new[MAX_PATH]; |
214 | const char *final_old, *final_new; | ||
202 | 215 | ||
203 | const char *final_old = old; | 216 | final_old = handle_special_dirs(old, NEED_WRITE, realpath_old, sizeof(realpath_old)); |
204 | if (!strncmp(ROCKBOX_DIR, old, ROCKBOX_DIR_LEN)) | 217 | final_new = handle_special_dirs(new, NEED_WRITE, realpath_new, sizeof(realpath_new)); |
205 | { | ||
206 | final_old = _get_user_file_path(old, NEED_WRITE, realpath_old, sizeof(realpath_old)); | ||
207 | } | ||
208 | |||
209 | const char *final_new = new; | ||
210 | if (!strncmp(ROCKBOX_DIR, new, ROCKBOX_DIR_LEN)) | ||
211 | { | ||
212 | final_new = _get_user_file_path(new, NEED_WRITE, realpath_new, sizeof(realpath_new)); | ||
213 | } | ||
214 | 218 | ||
215 | return rename(final_old, final_new); | 219 | return rename(final_old, final_new); |
216 | } | 220 | } |
@@ -218,33 +222,21 @@ int app_rename(const char *old, const char *new) | |||
218 | DIR *app_opendir(const char *name) | 222 | DIR *app_opendir(const char *name) |
219 | { | 223 | { |
220 | char realpath[MAX_PATH]; | 224 | char realpath[MAX_PATH]; |
221 | const char *fname = name; | 225 | const char *fname = handle_special_dirs(name, 0, realpath, sizeof(realpath)); |
222 | if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) | ||
223 | { | ||
224 | fname = _get_user_file_path(name, 0, realpath, sizeof(realpath)); | ||
225 | } | ||
226 | return opendir(fname); | 226 | return opendir(fname); |
227 | } | 227 | } |
228 | 228 | ||
229 | int app_mkdir(const char* name) | 229 | int app_mkdir(const char* name) |
230 | { | 230 | { |
231 | char realpath[MAX_PATH]; | 231 | char realpath[MAX_PATH]; |
232 | const char *fname = name; | 232 | const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath)); |
233 | if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) | ||
234 | { | ||
235 | fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath)); | ||
236 | } | ||
237 | return mkdir(fname); | 233 | return mkdir(fname); |
238 | } | 234 | } |
239 | 235 | ||
240 | int app_rmdir(const char* name) | 236 | int app_rmdir(const char* name) |
241 | { | 237 | { |
242 | char realpath[MAX_PATH]; | 238 | char realpath[MAX_PATH]; |
243 | const char *fname = name; | 239 | const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath)); |
244 | if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN)) | ||
245 | { | ||
246 | fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath)); | ||
247 | } | ||
248 | return rmdir(fname); | 240 | return rmdir(fname); |
249 | } | 241 | } |
250 | 242 | ||
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h index 8f554c25f4..f351c5e6c9 100644 --- a/firmware/export/rbpaths.h +++ b/firmware/export/rbpaths.h | |||
@@ -46,6 +46,12 @@ | |||
46 | 46 | ||
47 | #if !defined(APPLICATION) || defined(SAMSUNG_YPR0) | 47 | #if !defined(APPLICATION) || defined(SAMSUNG_YPR0) |
48 | 48 | ||
49 | #ifdef SAMSUNG_YPR0 | ||
50 | #define HOME_DIR "/mnt/media0" | ||
51 | #else | ||
52 | #define HOME_DIR "/." /* dot to avoid "//XX", /./X is valid */ | ||
53 | #endif | ||
54 | |||
49 | /* make sure both are the same for native builds */ | 55 | /* make sure both are the same for native builds */ |
50 | #undef ROCKBOX_LIBRARY_PATH | 56 | #undef ROCKBOX_LIBRARY_PATH |
51 | #define ROCKBOX_LIBRARY_PATH ROCKBOX_DIR | 57 | #define ROCKBOX_LIBRARY_PATH ROCKBOX_DIR |
@@ -53,12 +59,15 @@ | |||
53 | #define PLUGIN_DIR ROCKBOX_DIR "/rocks" | 59 | #define PLUGIN_DIR ROCKBOX_DIR "/rocks" |
54 | #define CODECS_DIR ROCKBOX_DIR "/codecs" | 60 | #define CODECS_DIR ROCKBOX_DIR "/codecs" |
55 | 61 | ||
56 | #define REC_BASE_DIR "/" | 62 | #define REC_BASE_DIR HOME_DIR |
57 | #define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists" | 63 | #define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists" |
58 | 64 | ||
59 | #define paths_init() | 65 | #define paths_init() |
60 | 66 | ||
61 | #else /* application */ | 67 | #else /* APPLICATION */ |
68 | |||
69 | #define HOME_DIR "<HOME>" /* replaced at runtime */ | ||
70 | #define HOME_DIR_LEN (sizeof(HOME_DIR)-1) | ||
62 | 71 | ||
63 | #define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks" | 72 | #define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks" |
64 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) | 73 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) |
@@ -67,12 +76,12 @@ | |||
67 | #define CODECS_DIR ROCKBOX_LIBRARY_PATH "/rockbox/codecs" | 76 | #define CODECS_DIR ROCKBOX_LIBRARY_PATH "/rockbox/codecs" |
68 | #endif | 77 | #endif |
69 | 78 | ||
70 | #define REC_BASE_DIR ROCKBOX_DIR "/" | 79 | #define REC_BASE_DIR HOME_DIR |
71 | #define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists" | 80 | #define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "Playlists" |
72 | 81 | ||
73 | extern void paths_init(void); | 82 | extern void paths_init(void); |
74 | 83 | ||
75 | #endif /* APPLICATION */ | 84 | #endif /* !APPLICATION || SAMSUNG_YPR0 */ |
76 | 85 | ||
77 | #define LANG_DIR ROCKBOX_DIR "/langs" | 86 | #define LANG_DIR ROCKBOX_DIR "/langs" |
78 | 87 | ||
@@ -82,7 +91,7 @@ extern void paths_init(void); | |||
82 | #define VIEWERS_DIR PLUGIN_DIR "/viewers" | 91 | #define VIEWERS_DIR PLUGIN_DIR "/viewers" |
83 | 92 | ||
84 | #if defined(APPLICATION) && !defined(SAMSUNG_YPR0) | 93 | #if defined(APPLICATION) && !defined(SAMSUNG_YPR0) |
85 | #define PLUGIN_DATA_DIR "/.rockbox/rocks.data" | 94 | #define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data" |
86 | #define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR | 95 | #define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR |
87 | #define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR | 96 | #define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR |
88 | #define PLUGIN_DEMOS_DATA_DIR PLUGIN_DATA_DIR | 97 | #define PLUGIN_DEMOS_DATA_DIR PLUGIN_DATA_DIR |
diff --git a/firmware/general.c b/firmware/general.c index 3daf2f0a78..8e6d5af9a0 100644 --- a/firmware/general.c +++ b/firmware/general.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "general.h" | 24 | #include "general.h" |
25 | #include "file.h" | 25 | #include "file.h" |
26 | #include "dir.h" | 26 | #include "dir.h" |
27 | #include "rbpaths.h" | ||
27 | #include "limits.h" | 28 | #include "limits.h" |
28 | #include "stdlib.h" | 29 | #include "stdlib.h" |
29 | #include "string-extra.h" | 30 | #include "string-extra.h" |
@@ -126,7 +127,7 @@ char *create_numbered_filename(char *buffer, const char *path, | |||
126 | /* automatic numbering */ | 127 | /* automatic numbering */ |
127 | max_num = 0; | 128 | max_num = 0; |
128 | 129 | ||
129 | dir = opendir(pathlen ? buffer : "/"); | 130 | dir = opendir(pathlen ? buffer : HOME_DIR); |
130 | if (!dir) | 131 | if (!dir) |
131 | return NULL; | 132 | return NULL; |
132 | 133 | ||