summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-12-25 20:11:18 +0000
committerThomas Martitz <kugel@rockbox.org>2011-12-25 20:11:18 +0000
commit20b662a946861b5acee8970948a22f7a2d1aedf3 (patch)
tree392d9568a3baaa23be0e109799485255ddcd067f
parent16784598ac550dab147ea8ee15634a2f15739fff (diff)
downloadrockbox-20b662a946861b5acee8970948a22f7a2d1aedf3.zip
rockbox-20b662a946861b5acee8970948a22f7a2d1aedf3.tar.gz
rockbox-20b662a946861b5acee8970948a22f7a2d1aedf3.tar.bz2
rockbox-20b662a946861b5acee8970948a22f7a2d1aedf3.tar.xz
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.c2
-rw-r--r--apps/plugins/test_codec.c2
-rw-r--r--apps/plugins/test_disk.c4
-rw-r--r--apps/plugins/test_gfx.c2
-rw-r--r--apps/plugins/test_grey.c2
-rw-r--r--firmware/common/rbpaths.c68
-rw-r--r--firmware/export/rbpaths.h23
-rw-r--r--firmware/general.c3
8 files changed, 54 insertions, 52 deletions
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index be509cf..302d74c 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -24,7 +24,7 @@
#include "plugin.h"
-#define BATTERY_LOG "/battery_bench.txt"
+#define BATTERY_LOG HOME_DIR"/battery_bench.txt"
#define BUF_SIZE 16000
#define EV_EXIT 1337
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index 849b40d..4c0739f 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -80,7 +80,7 @@ static bool log_init(bool use_logfile)
if (use_logfile) {
log_close();
- rb->create_numbered_filename(logfilename, "/", "test_codec_log_", ".txt",
+ rb->create_numbered_filename(logfilename, HOME_DIR, "test_codec_log_", ".txt",
2 IF_CNFN_NUM_(, NULL));
log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
return log_fd >= 0;
diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c
index 6d5ea29..7c46101 100644
--- a/apps/plugins/test_disk.c
+++ b/apps/plugins/test_disk.c
@@ -24,7 +24,7 @@
-#define TESTBASEDIR "/__TEST__"
+#define TESTBASEDIR HOME_DIR "/__TEST__"
#define TEST_FILE TESTBASEDIR "/test_disk.tmp"
#define FRND_SEED 0x78C3 /* arbirary */
@@ -83,7 +83,7 @@ static bool log_init(void)
rb->lcd_clear_display();
rb->lcd_update();
- rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt",
+ rb->create_numbered_filename(logfilename, HOME_DIR, "test_disk_log_", ".txt",
2 IF_CNFN_NUM_(, NULL));
log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
return log_fd >= 0;
diff --git a/apps/plugins/test_gfx.c b/apps/plugins/test_gfx.c
index 4081e64..1dfab8c 100644
--- a/apps/plugins/test_gfx.c
+++ b/apps/plugins/test_gfx.c
@@ -46,7 +46,7 @@ static int log_init(void)
char logfilename[MAX_PATH];
int fd;
- rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt",
+ rb->create_numbered_filename(logfilename, HOME_DIR, "test_gfx_log_", ".txt",
2 IF_CNFN_NUM_(, NULL));
fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
return fd;
diff --git a/apps/plugins/test_grey.c b/apps/plugins/test_grey.c
index efceeff..f4555c1 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)
case GREY_OK:
/* dump result in form suitable for lcdlinear[] */
- rb->create_numbered_filename(filename, "/", "test_grey_",
+ rb->create_numbered_filename(filename, HOME_DIR, "test_grey_",
".txt", 2 IF_CNFN_NUM_(, NULL));
fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (fd >= 0)
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index 95bff33..aacd949 100644
--- a/firmware/common/rbpaths.c
+++ b/firmware/common/rbpaths.c
@@ -45,6 +45,7 @@
#define opendir opendir_android
#define mkdir mkdir_android
#define rmdir rmdir_android
+static const char rbhome[] = "/sdcard";
#elif defined(SAMSUNG_YPR0)
#include "dir-target.h"
#define opendir opendir_ypr0
@@ -159,19 +160,34 @@ static const char* _get_user_file_path(const char *path,
return ret;
}
+
+static const char* handle_special_dirs(const char* dir, unsigned flags,
+ char *buf, const size_t bufsize)
+{
+ if (!strncmp(HOME_DIR, dir, HOME_DIR_LEN))
+ {
+ const char *p = dir + HOME_DIR_LEN;
+ while (*p == '/') p++;
+ snprintf(buf, bufsize, "%s/%s", rbhome, p);
+ return buf;
+ }
+ else if (!strncmp(ROCKBOX_DIR, dir, ROCKBOX_DIR_LEN))
+ return _get_user_file_path(dir, flags, buf, bufsize);
+
+ return dir;
+}
+
int app_open(const char *name, int o, ...)
{
char realpath[MAX_PATH];
va_list ap;
int fd;
+ int flags = IS_FILE;
+ if (o & (O_CREAT|O_RDWR|O_TRUNC|O_WRONLY))
+ flags |= NEED_WRITE;
- if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
- {
- int flags = IS_FILE;
- if (o & (O_CREAT|O_RDWR|O_TRUNC|O_WRONLY))
- flags |= NEED_WRITE;
- name = _get_user_file_path(name, flags, realpath, sizeof(realpath));
- }
+ name = handle_special_dirs(name, flags, realpath, sizeof(realpath));
+
va_start(ap, o);
fd = open(name, o, va_arg(ap, unsigned int));
va_end(ap);
@@ -187,11 +203,7 @@ int app_creat(const char* name, mode_t mode)
int app_remove(const char *name)
{
char realpath[MAX_PATH];
- const char *fname = name;
- if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
- {
- fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath));
- }
+ const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
return remove(fname);
}
@@ -199,18 +211,10 @@ int app_remove(const char *name)
int app_rename(const char *old, const char *new)
{
char realpath_old[MAX_PATH], realpath_new[MAX_PATH];
+ const char *final_old, *final_new;
- const char *final_old = old;
- if (!strncmp(ROCKBOX_DIR, old, ROCKBOX_DIR_LEN))
- {
- final_old = _get_user_file_path(old, NEED_WRITE, realpath_old, sizeof(realpath_old));
- }
-
- const char *final_new = new;
- if (!strncmp(ROCKBOX_DIR, new, ROCKBOX_DIR_LEN))
- {
- final_new = _get_user_file_path(new, NEED_WRITE, realpath_new, sizeof(realpath_new));
- }
+ final_old = handle_special_dirs(old, NEED_WRITE, realpath_old, sizeof(realpath_old));
+ final_new = handle_special_dirs(new, NEED_WRITE, realpath_new, sizeof(realpath_new));
return rename(final_old, final_new);
}
@@ -218,33 +222,21 @@ int app_rename(const char *old, const char *new)
DIR *app_opendir(const char *name)
{
char realpath[MAX_PATH];
- const char *fname = name;
- if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
- {
- fname = _get_user_file_path(name, 0, realpath, sizeof(realpath));
- }
+ const char *fname = handle_special_dirs(name, 0, realpath, sizeof(realpath));
return opendir(fname);
}
int app_mkdir(const char* name)
{
char realpath[MAX_PATH];
- const char *fname = name;
- if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
- {
- fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath));
- }
+ const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
return mkdir(fname);
}
int app_rmdir(const char* name)
{
char realpath[MAX_PATH];
- const char *fname = name;
- if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
- {
- fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath));
- }
+ const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
return rmdir(fname);
}
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h
index 8f554c2..f351c5e 100644
--- a/firmware/export/rbpaths.h
+++ b/firmware/export/rbpaths.h
@@ -46,6 +46,12 @@
#if !defined(APPLICATION) || defined(SAMSUNG_YPR0)
+#ifdef SAMSUNG_YPR0
+#define HOME_DIR "/mnt/media0"
+#else
+#define HOME_DIR "/." /* dot to avoid "//XX", /./X is valid */
+#endif
+
/* make sure both are the same for native builds */
#undef ROCKBOX_LIBRARY_PATH
#define ROCKBOX_LIBRARY_PATH ROCKBOX_DIR
@@ -53,12 +59,15 @@
#define PLUGIN_DIR ROCKBOX_DIR "/rocks"
#define CODECS_DIR ROCKBOX_DIR "/codecs"
-#define REC_BASE_DIR "/"
-#define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists"
+#define REC_BASE_DIR HOME_DIR
+#define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists"
#define paths_init()
-#else /* application */
+#else /* APPLICATION */
+
+#define HOME_DIR "<HOME>" /* replaced at runtime */
+#define HOME_DIR_LEN (sizeof(HOME_DIR)-1)
#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks"
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
@@ -67,12 +76,12 @@
#define CODECS_DIR ROCKBOX_LIBRARY_PATH "/rockbox/codecs"
#endif
-#define REC_BASE_DIR ROCKBOX_DIR "/"
-#define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists"
+#define REC_BASE_DIR HOME_DIR
+#define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "Playlists"
extern void paths_init(void);
-#endif /* APPLICATION */
+#endif /* !APPLICATION || SAMSUNG_YPR0 */
#define LANG_DIR ROCKBOX_DIR "/langs"
@@ -82,7 +91,7 @@ extern void paths_init(void);
#define VIEWERS_DIR PLUGIN_DIR "/viewers"
#if defined(APPLICATION) && !defined(SAMSUNG_YPR0)
-#define PLUGIN_DATA_DIR "/.rockbox/rocks.data"
+#define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data"
#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR
#define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR
#define PLUGIN_DEMOS_DATA_DIR PLUGIN_DATA_DIR
diff --git a/firmware/general.c b/firmware/general.c
index 3daf2f0..8e6d5af 100644
--- a/firmware/general.c
+++ b/firmware/general.c
@@ -24,6 +24,7 @@
#include "general.h"
#include "file.h"
#include "dir.h"
+#include "rbpaths.h"
#include "limits.h"
#include "stdlib.h"
#include "string-extra.h"
@@ -126,7 +127,7 @@ char *create_numbered_filename(char *buffer, const char *path,
/* automatic numbering */
max_num = 0;
- dir = opendir(pathlen ? buffer : "/");
+ dir = opendir(pathlen ? buffer : HOME_DIR);
if (!dir)
return NULL;