2010-08-01 16:15:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Thomas Martitz
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> /* snprintf */
|
|
|
|
#include <stdlib.h>
|
2010-12-06 22:26:31 +00:00
|
|
|
#include <stdarg.h>
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
#include "config.h"
|
2010-08-01 16:15:27 +00:00
|
|
|
#include "rbpaths.h"
|
|
|
|
#include "file.h" /* MAX_PATH */
|
2011-02-25 14:31:26 +00:00
|
|
|
#include "logf.h"
|
2010-08-01 16:15:27 +00:00
|
|
|
#include "gcc_extensions.h"
|
|
|
|
#include "string-extra.h"
|
|
|
|
#include "filefuncs.h"
|
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
#undef open
|
|
|
|
#undef creat
|
|
|
|
#undef remove
|
|
|
|
#undef rename
|
|
|
|
#undef opendir
|
|
|
|
#undef mkdir
|
|
|
|
#undef rmdir
|
|
|
|
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
|
2013-09-10 20:48:34 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) && !defined(__PCTOOL__)
|
2010-12-06 22:26:31 +00:00
|
|
|
#include "dir-target.h"
|
2012-01-19 06:59:28 +00:00
|
|
|
#define opendir _opendir
|
|
|
|
#define mkdir _mkdir
|
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
2011-12-25 20:11:18 +00:00
|
|
|
static const char rbhome[] = "/sdcard";
|
2012-01-19 06:59:28 +00:00
|
|
|
#endif
|
2012-03-03 19:23:51 +00:00
|
|
|
#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) && !defined(__PCTOOL__)
|
2010-12-06 22:26:31 +00:00
|
|
|
#define open sim_open
|
|
|
|
#define remove sim_remove
|
|
|
|
#define rename sim_rename
|
|
|
|
#define opendir sim_opendir
|
|
|
|
#define mkdir sim_mkdir
|
|
|
|
#define rmdir sim_rmdir
|
|
|
|
extern int sim_open(const char* name, int o, ...);
|
|
|
|
extern int sim_remove(const char* name);
|
|
|
|
extern int sim_rename(const char* old, const char* new);
|
|
|
|
extern DIR* sim_opendir(const char* name);
|
|
|
|
extern int sim_mkdir(const char* name);
|
|
|
|
extern int sim_rmdir(const char* name);
|
2011-12-05 12:07:23 +00:00
|
|
|
const char *rbhome;
|
2010-12-06 22:26:31 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-10 20:48:34 +00:00
|
|
|
#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)) && !defined(__PCTOOL__)
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
/* flags for get_user_file_path() */
|
|
|
|
/* whether you need write access to that file/dir, especially true
|
|
|
|
* for runtime generated files (config.cfg) */
|
|
|
|
#define NEED_WRITE (1<<0)
|
|
|
|
/* file or directory? */
|
|
|
|
#define IS_FILE (1<<1)
|
2010-08-01 16:15:27 +00:00
|
|
|
|
|
|
|
void paths_init(void)
|
|
|
|
{
|
|
|
|
/* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */
|
2010-08-02 20:34:47 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
|
|
|
mkdir("/sdcard/rockbox");
|
2011-03-02 23:43:54 +00:00
|
|
|
mkdir("/sdcard/rockbox/rocks.data");
|
2010-08-02 20:34:47 +00:00
|
|
|
#else
|
2011-02-25 14:31:26 +00:00
|
|
|
char config_dir[MAX_PATH];
|
|
|
|
|
2011-12-05 12:07:23 +00:00
|
|
|
const char *home = getenv("RBROOT");
|
|
|
|
if (!home)
|
|
|
|
{
|
|
|
|
home = getenv("HOME");
|
|
|
|
}
|
2011-02-25 14:31:26 +00:00
|
|
|
if (!home)
|
|
|
|
{
|
|
|
|
logf("HOME environment var not set. Can't write config");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-05 12:07:23 +00:00
|
|
|
rbhome = home;
|
2011-02-25 14:31:26 +00:00
|
|
|
snprintf(config_dir, sizeof(config_dir), "%s/.config", home);
|
|
|
|
mkdir(config_dir);
|
|
|
|
snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org", home);
|
|
|
|
mkdir(config_dir);
|
2011-03-02 23:43:54 +00:00
|
|
|
/* Plugin data directory */
|
|
|
|
snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org/rocks.data", home);
|
|
|
|
mkdir(config_dir);
|
2010-08-02 20:34:47 +00:00
|
|
|
#endif
|
2010-08-01 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
static bool try_path(const char* filename, unsigned flags)
|
|
|
|
{
|
|
|
|
if (flags & IS_FILE)
|
|
|
|
{
|
|
|
|
if (file_exists(filename))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dir_exists(filename))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* _get_user_file_path(const char *path,
|
|
|
|
unsigned flags,
|
|
|
|
char* buf,
|
|
|
|
const size_t bufsize)
|
2010-08-01 16:15:27 +00:00
|
|
|
{
|
|
|
|
const char *ret = path;
|
|
|
|
const char *pos = path;
|
|
|
|
/* replace ROCKBOX_DIR in path with $HOME/.config/rockbox.org */
|
|
|
|
pos += ROCKBOX_DIR_LEN;
|
|
|
|
if (*pos == '/') pos += 1;
|
|
|
|
|
2010-08-02 20:34:47 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
|
|
|
if (snprintf(buf, bufsize, "/sdcard/rockbox/%s", pos)
|
|
|
|
#else
|
2011-12-05 12:07:23 +00:00
|
|
|
if (snprintf(buf, bufsize, "%s/.config/rockbox.org/%s", rbhome, pos)
|
2010-08-02 20:34:47 +00:00
|
|
|
#endif
|
2010-08-01 16:15:27 +00:00
|
|
|
>= (int)bufsize)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* always return the replacement buffer (pointing to $HOME) if
|
|
|
|
* write access is needed */
|
|
|
|
if (flags & NEED_WRITE)
|
|
|
|
ret = buf;
|
2010-12-06 22:26:31 +00:00
|
|
|
else if (try_path(buf, flags))
|
|
|
|
ret = buf;
|
|
|
|
|
|
|
|
if (ret != buf) /* not found in $HOME, try ROCKBOX_BASE_DIR, !NEED_WRITE only */
|
2010-08-01 16:15:27 +00:00
|
|
|
{
|
2010-12-06 22:26:31 +00:00
|
|
|
if (snprintf(buf, bufsize, ROCKBOX_SHARE_PATH "/%s", pos) >= (int)bufsize)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (try_path(buf, flags))
|
|
|
|
ret = buf;
|
2010-08-01 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-25 20:11:18 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
int app_open(const char *name, int o, ...)
|
|
|
|
{
|
|
|
|
char realpath[MAX_PATH];
|
|
|
|
va_list ap;
|
|
|
|
int fd;
|
2011-12-25 20:11:18 +00:00
|
|
|
int flags = IS_FILE;
|
|
|
|
if (o & (O_CREAT|O_RDWR|O_TRUNC|O_WRONLY))
|
|
|
|
flags |= NEED_WRITE;
|
2010-12-06 22:26:31 +00:00
|
|
|
|
2011-12-25 20:11:18 +00:00
|
|
|
name = handle_special_dirs(name, flags, realpath, sizeof(realpath));
|
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
va_start(ap, o);
|
2010-12-07 12:20:27 +00:00
|
|
|
fd = open(name, o, va_arg(ap, unsigned int));
|
2010-12-06 22:26:31 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
2010-08-01 16:15:27 +00:00
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
int app_creat(const char* name, mode_t mode)
|
|
|
|
{
|
|
|
|
return app_open(name, O_CREAT|O_WRONLY|O_TRUNC, mode);
|
2010-08-01 16:15:27 +00:00
|
|
|
}
|
2010-12-06 22:26:31 +00:00
|
|
|
|
|
|
|
int app_remove(const char *name)
|
|
|
|
{
|
|
|
|
char realpath[MAX_PATH];
|
2011-12-25 20:11:18 +00:00
|
|
|
const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
|
2011-01-27 21:09:25 +00:00
|
|
|
|
2010-12-06 22:26:31 +00:00
|
|
|
return remove(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int app_rename(const char *old, const char *new)
|
|
|
|
{
|
2011-02-15 22:46:36 +00:00
|
|
|
char realpath_old[MAX_PATH], realpath_new[MAX_PATH];
|
2011-12-25 20:11:18 +00:00
|
|
|
const char *final_old, *final_new;
|
2011-02-15 22:46:36 +00:00
|
|
|
|
2011-12-25 20:11:18 +00:00
|
|
|
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));
|
2011-02-15 22:46:36 +00:00
|
|
|
|
|
|
|
return rename(final_old, final_new);
|
2010-12-06 22:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIR *app_opendir(const char *name)
|
|
|
|
{
|
|
|
|
char realpath[MAX_PATH];
|
2011-12-25 20:11:18 +00:00
|
|
|
const char *fname = handle_special_dirs(name, 0, realpath, sizeof(realpath));
|
2010-12-06 22:26:31 +00:00
|
|
|
return opendir(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int app_mkdir(const char* name)
|
|
|
|
{
|
|
|
|
char realpath[MAX_PATH];
|
2011-12-25 20:11:18 +00:00
|
|
|
const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
|
2010-12-06 22:26:31 +00:00
|
|
|
return mkdir(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int app_rmdir(const char* name)
|
|
|
|
{
|
|
|
|
char realpath[MAX_PATH];
|
2011-12-25 20:11:18 +00:00
|
|
|
const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
|
2010-12-06 22:26:31 +00:00
|
|
|
return rmdir(fname);
|
|
|
|
}
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int app_open(const char *name, int o, ...)
|
|
|
|
{
|
|
|
|
if (o & O_CREAT)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, o);
|
|
|
|
ret = open(name, o, va_arg(ap, mode_t));
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return open(name, o);
|
|
|
|
}
|
|
|
|
|
|
|
|
int app_creat(const char* name, mode_t mode) { return creat(name, mode); }
|
|
|
|
int app_remove(const char *name) { return remove(name); }
|
|
|
|
int app_rename(const char *old, const char *new) { return rename(old,new); }
|
2012-02-10 19:27:14 +00:00
|
|
|
DIR *app_opendir(const char *name) { return (DIR*)opendir(name); } /* cast to remove warning in checkwps */
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
int app_mkdir(const char* name) { return mkdir(name); }
|
|
|
|
int app_rmdir(const char* name) { return rmdir(name); }
|
|
|
|
|
|
|
|
#endif
|