diff --git a/apps/codecs.c b/apps/codecs.c
index 29a6644..93b1b6b 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -55,7 +55,11 @@
#include "logf.h"
#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
-
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
+# define FS_PREFIX(_x_) sim_ ## _x_
+# else
+# define FS_PREFIX(_x_) _x_
+# endif
#define PREFIX(_x_) sim_ ## _x_
#if CONFIG_CODEC == SWCODEC
unsigned char codecbuf[CODEC_SIZE];
@@ -66,6 +70,7 @@ void sim_codec_close(void *pd);
#else /* !PLATFORM_HOSTED */
#define PREFIX
+#define FS_PREFIX
#define sim_codec_close(x)
#endif
@@ -77,7 +82,7 @@ extern void* plugin_get_audio_buffer(size_t *buffer_size);
#undef open
static int open(const char* pathname, int flags, ...)
{
-#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
int fd;
if (flags & O_CREAT)
{
@@ -178,11 +183,11 @@ struct codec_api ci = {
enc_unget_pcm_data,
/* file */
- (open_func)PREFIX(open),
- PREFIX(close),
- (read_func)PREFIX(read),
- PREFIX(lseek),
- (write_func)PREFIX(write),
+ (open_func)FS_PREFIX(open),
+ FS_PREFIX(close),
+ (read_func)FS_PREFIX(read),
+ FS_PREFIX(lseek),
+ (write_func)FS_PREFIX(write),
round_value_to_list32,
#endif /* HAVE_RECORDING */
diff --git a/apps/main.c b/apps/main.c
index 67cd6d2..2973bd8 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -353,7 +353,39 @@ static void init(void)
sb_skin_init();
viewportmanager_init();
+#if defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
+ disk_init_subsystem();
+ int rc = storage_init();
+ if(rc)
+ panicf("storage error: %d", rc);
+ rc = disk_mount_all();
+ if(rc <= 0)
+ {
+ printf("disk_mount error: %d\n", rc);
+ lcd_clear_display();
+ lcd_puts(0, 0, "No partition");
+ lcd_puts(0, 1, "found.");
+ lcd_puts(0, 2, "Continue ?");
+
+ lcd_update();
+
+ while(true)
+ {
+ int button = get_action(CONTEXT_YESNOSCREEN, HZ*5);
+ switch (button)
+ {
+ case ACTION_YESNO_ACCEPT: goto Lcontinue;
+ case ACTION_NONE: continue;
+ default: exit(1);
+ }
+ }
+
+ Lcontinue:
+ printf("continue without partition !\n");
+ }
+#else /* defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
storage_init();
+#endif
settings_reset();
settings_load(SETTINGS_ALL);
settings_apply(true);
diff --git a/apps/plugin.c b/apps/plugin.c
index b3baea7..ae1e9cf 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -59,9 +59,15 @@
#endif
#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
+# define FS_PREFIX(_x_) sim_ ## _x_
+# else
+# define FS_PREFIX(_x_) _x_
+# endif
#define PREFIX(_x_) sim_ ## _x_
#else
#define PREFIX
+#define FS_PREFIX
#endif
#if defined(HAVE_PLUGIN_CHECK_OPEN_CLOSE) && (MAX_OPEN_FILES>32)
@@ -306,20 +312,20 @@ static const struct plugin_api rockbox_api = {
#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
close_wrapper,
#else
- PREFIX(close),
+ FS_PREFIX(close),
#endif
- (read_func)PREFIX(read),
- PREFIX(lseek),
+ (read_func)FS_PREFIX(read),
+ FS_PREFIX(lseek),
#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
(creat_func)creat_wrapper,
#else
- (creat_func)PREFIX(creat),
+ (creat_func)FS_PREFIX(creat),
#endif
- (write_func)PREFIX(write),
- PREFIX(remove),
- PREFIX(rename),
- PREFIX(ftruncate),
- PREFIX(filesize),
+ (write_func)FS_PREFIX(write),
+ FS_PREFIX(remove),
+ FS_PREFIX(rename),
+ FS_PREFIX(ftruncate),
+ FS_PREFIX(filesize),
fdprintf,
read_line,
settings_parseline,
@@ -991,7 +997,7 @@ static int open_wrapper(const char* pathname, int flags, ...)
/* we don't have an 'open' function. it's a define. and we need
* the real file_open, hence PREFIX() doesn't work here */
int fd;
-#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
if (flags & O_CREAT)
{
va_list ap;
diff --git a/firmware/SOURCES b/firmware/SOURCES
index d8cfade..5c50637 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -95,7 +95,8 @@ common/crc32.c
#ifdef MI4_FORMAT
common/crc32-mi4.c
#endif
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
+ ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
common/dir_uncached.c
common/file.c
common/disk.c
@@ -185,7 +186,8 @@ drivers/touchscreen.c
/* Storage */
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
+ ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
#if (CONFIG_STORAGE & STORAGE_MMC)
drivers/ata_mmc.c
#endif
diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h
index 5dcb4f6..f359a7b 100644
--- a/firmware/export/config/sim.h
+++ b/firmware/export/config/sim.h
@@ -30,12 +30,14 @@
#undef AMS_OF_SIZE
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
#undef HAVE_MULTIDRIVE
#undef NUM_DRIVES
#undef HAVE_HOTSWAP
#undef HAVE_HOTSWAP_STORAGE_AS_MAIN
#undef CONFIG_STORAGE
+#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
#undef CONFIG_USBOTG
diff --git a/firmware/export/sd.h b/firmware/export/sd.h
index c798f54..f207421 100644
--- a/firmware/export/sd.h
+++ b/firmware/export/sd.h
@@ -36,7 +36,6 @@ void sd_sleepnow(void);
bool sd_disk_is_active(void);
int sd_soft_reset(void);
int sd_init(void);
-void sd_close(void);
int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
void sd_spin(void);
diff --git a/firmware/export/storage.h b/firmware/export/storage.h
index e59a5e5..b6e8acf 100644
--- a/firmware/export/storage.h
+++ b/firmware/export/storage.h
@@ -51,7 +51,8 @@ struct storage_info
char *revision;
};
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(CONFIG_STORAGE_MULTI)
+#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(CONFIG_STORAGE_MULTI)) || \
+ ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER) && !defined(CONFIG_STORAGE_MULTI))
/* storage_spindown, storage_sleep and storage_spin are passed as
* pointers, which doesn't work with argument-macros.
*/
diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
index f225cf8..38663ca 100644
--- a/firmware/include/dir_uncached.h
+++ b/firmware/include/dir_uncached.h
@@ -32,7 +32,7 @@
#define ATTR_ARCHIVE 0x20
#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
-#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
#define dirent_uncached sim_dirent
#define DIR_UNCACHED SIM_DIR
#define opendir_uncached sim_opendir
@@ -57,7 +57,8 @@ struct dirent_uncached {
#include "fat.h"
typedef struct {
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
+ ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
bool busy;
long startcluster;
struct fat_dir fatdir;
diff --git a/firmware/include/file.h b/firmware/include/file.h
index a9d1d05..ff7164a 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -49,7 +49,7 @@
#define O_TRUNC 0x10
#endif
-#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(PLUGIN) && !defined(CODEC)
+#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(PLUGIN) && !defined(CODEC) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
#define open(x, ...) sim_open(x, __VA_ARGS__)
#define creat(x,m) sim_creat(x,m)
#define remove(x) sim_remove(x)
@@ -78,7 +78,8 @@ extern int fsync(int fd);
extern ssize_t read(int fd, void *buf, size_t count);
extern off_t lseek(int fildes, off_t offset, int whence);
extern int file_creat(const char *pathname);
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
+ ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
/* posix compatibility function */
static inline int creat(const char *pathname, mode_t mode)
{
diff --git a/uisimulator/common/SOURCES b/uisimulator/common/SOURCES
index a30b5ab..243c994 100644
--- a/uisimulator/common/SOURCES
+++ b/uisimulator/common/SOURCES
@@ -12,5 +12,9 @@ backlight-sim.c
/* this is still needed for application since it has some stubs */
powermgmt-sim.c
io.c
+debug.c
sim_tasks.c
stubs.c
+#if defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
+storage.c
+#endif
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 260e880..b1e76bc 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -147,6 +147,7 @@ void dircache_rename(const char *oldname, const char *newname);
#define SIMULATOR_DEFAULT_ROOT "simdisk"
extern const char *sim_root_dir;
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
static int num_openfiles = 0;
struct sim_dirent {
@@ -170,26 +171,6 @@ struct mydir {
typedef struct mydir MYDIR;
-#if 1 /* maybe this needs disabling for MSVC... */
-static unsigned int rockbox2sim(int opt)
-{
- int newopt = O_BINARY;
-
- if(opt & 1)
- newopt |= O_WRONLY;
- if(opt & 2)
- newopt |= O_RDWR;
- if(opt & 4)
- newopt |= O_CREAT;
- if(opt & 8)
- newopt |= O_APPEND;
- if(opt & 0x10)
- newopt |= O_TRUNC;
-
- return newopt;
-}
-#endif
-
/** Simulator I/O engine routines **/
#define IO_YIELD_THRESHOLD 512
@@ -212,6 +193,26 @@ struct sim_io
static struct sim_io io;
+#if 1 /* maybe this needs disabling for MSVC... */
+static unsigned int rockbox2sim(int opt)
+{
+ int newopt = O_BINARY;
+
+ if(opt & 1)
+ newopt |= O_WRONLY;
+ if(opt & 2)
+ newopt |= O_RDWR;
+ if(opt & 4)
+ newopt |= O_CREAT;
+ if(opt & 8)
+ newopt |= O_APPEND;
+ if(opt & 0x10)
+ newopt |= O_TRUNC;
+
+ return newopt;
+}
+#endif
+
int ata_init(void)
{
/* Initialize the rockbox kernel objects on a rockbox thread */
@@ -256,6 +257,7 @@ static ssize_t io_trigger_and_wait(int cmd)
return result;
}
+#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
#if !defined(__PCTOOL__) && !defined(APPLICATION)
static const char *get_sim_pathname(const char *name)
@@ -275,6 +277,7 @@ static const char *get_sim_pathname(const char *name)
#define get_sim_pathname(name) name
#endif
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
MYDIR *sim_opendir(const char *name)
{
DIR_T *dir;
@@ -509,6 +512,18 @@ int sim_fsync(int fd)
#endif
}
+/* rockbox off_t may be different from system off_t */
+int sim_ftruncate(int fd, long length)
+{
+#ifdef WIN32
+ return _chsize(fd, length);
+#else
+ return ftruncate(fd, length);
+#endif
+}
+
+#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
+
#ifdef WIN32
/* sim-win32 */
#define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_))
@@ -586,6 +601,8 @@ void sim_codec_close(void *pd)
void *sim_plugin_load(char *plugin, void **pd)
{
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
+
void *hdr;
char path[MAX_PATH];
#ifdef WIN32
@@ -614,60 +631,15 @@ void *sim_plugin_load(char *plugin, void **pd)
hdr = dlsym(*pd, "___header");
return hdr; /* maybe NULL if symbol not present */
-}
-
-void sim_plugin_close(void *pd)
-{
- dlclose(pd);
-}
-
-#ifdef WIN32
-static unsigned old_cp;
-
-void debug_exit(void)
-{
- /* Reset console output codepage */
- SetConsoleOutputCP(old_cp);
-}
-void debug_init(void)
-{
- old_cp = GetConsoleOutputCP();
- /* Set console output codepage to UTF8. Only works
- * correctly when the console uses a truetype font. */
- SetConsoleOutputCP(65001);
- atexit(debug_exit);
-}
-#else
-void debug_init(void)
-{
- /* nothing to be done */
-}
-#endif
+#else /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
-void debugf(const char *fmt, ...)
-{
- va_list ap;
- va_start( ap, fmt );
- vfprintf( stderr, fmt, ap );
- va_end( ap );
-}
+ return NULL;
-void ldebugf(const char* file, int line, const char *fmt, ...)
-{
- va_list ap;
- va_start( ap, fmt );
- fprintf( stderr, "%s:%d ", file, line );
- vfprintf( stderr, fmt, ap );
- va_end( ap );
+#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
}
-/* rockbox off_t may be different from system off_t */
-int sim_ftruncate(int fd, long length)
+void sim_plugin_close(void *pd)
{
-#ifdef WIN32
- return _chsize(fd, length);
-#else
- return ftruncate(fd, length);
-#endif
+ dlclose(pd);
}
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index 6d7d7de..0063f0d 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -36,7 +36,6 @@
#include "ata.h" /* for volume definitions */
extern char having_new_lcd;
-static bool storage_spinning = false;
#if CONFIG_CODEC != SWCODEC
void audio_set_buffer_margin(int seconds)
@@ -45,6 +44,9 @@ void audio_set_buffer_margin(int seconds)
}
#endif
+#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
+static bool storage_spinning = false;
+
int fat_startsector(void)
{
return 63;
@@ -131,6 +133,8 @@ void storage_spindown(int s)
storage_spinning = false;
}
+#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
+
void rtc_init(void)
{
}