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
This commit is contained in:
parent
cbc57af0f3
commit
0f928f8785
10 changed files with 216 additions and 357 deletions
|
@ -93,7 +93,7 @@ bool dir_exists(const char *path)
|
|||
}
|
||||
|
||||
|
||||
#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
|
||||
#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SIMULATOR)
|
||||
struct dirinfo dir_get_info(DIR* parent, struct dirent *entry)
|
||||
{
|
||||
(void)parent;
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include <stdio.h> /* snprintf */
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "config.h"
|
||||
#include "rbpaths.h"
|
||||
#include "file.h" /* MAX_PATH */
|
||||
|
@ -31,39 +34,34 @@
|
|||
#include "string-extra.h"
|
||||
#include "filefuncs.h"
|
||||
|
||||
/* In this file we need the actual OS library functions, not the shadowed
|
||||
* wrapper used within Rockbox' application code (except SDL adds
|
||||
* another layer) */
|
||||
#undef open
|
||||
#undef creat
|
||||
#undef remove
|
||||
#undef rename
|
||||
#undef opendir
|
||||
#undef closedir
|
||||
#undef readdir
|
||||
#undef mkdir
|
||||
#undef rmdir
|
||||
#undef dirent
|
||||
#undef DIR
|
||||
|
||||
|
||||
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) && !defined(__PCTOOL__)
|
||||
#include "dir-target.h"
|
||||
#define opendir _opendir
|
||||
#define mkdir _mkdir
|
||||
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
||||
static const char rbhome[] = "/sdcard";
|
||||
#endif
|
||||
#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) && !defined(__PCTOOL__)
|
||||
#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);
|
||||
#if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) && !defined(__PCTOOL__)
|
||||
const char *rbhome;
|
||||
#endif
|
||||
|
||||
#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)) && !defined(__PCTOOL__)
|
||||
/* Special dirs are user-accessible (and user-writable) dirs which take priority
|
||||
* over the ones where Rockbox is installed to. Classic example would be
|
||||
* $HOME/.config/rockbox.org vs /usr/share/rockbox */
|
||||
#define HAVE_SPECIAL_DIRS
|
||||
#endif
|
||||
|
||||
/* flags for get_user_file_path() */
|
||||
/* whether you need write access to that file/dir, especially true
|
||||
|
@ -72,12 +70,13 @@ const char *rbhome;
|
|||
/* file or directory? */
|
||||
#define IS_FILE (1<<1)
|
||||
|
||||
#ifdef HAVE_SPECIAL_DIRS
|
||||
void paths_init(void)
|
||||
{
|
||||
/* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */
|
||||
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
||||
mkdir("/sdcard/rockbox");
|
||||
mkdir("/sdcard/rockbox/rocks.data");
|
||||
mkdir("/sdcard/rockbox", 0777);
|
||||
mkdir("/sdcard/rockbox/rocks.data", 0777);
|
||||
#else
|
||||
char config_dir[MAX_PATH];
|
||||
|
||||
|
@ -94,13 +93,14 @@ void paths_init(void)
|
|||
|
||||
rbhome = home;
|
||||
snprintf(config_dir, sizeof(config_dir), "%s/.config", home);
|
||||
mkdir(config_dir);
|
||||
mkdir(config_dir, 0777);
|
||||
snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org", home);
|
||||
mkdir(config_dir);
|
||||
mkdir(config_dir, 0777);
|
||||
/* Plugin data directory */
|
||||
snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org/rocks.data", home);
|
||||
mkdir(config_dir);
|
||||
mkdir(config_dir, 0777);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static bool try_path(const char* filename, unsigned flags)
|
||||
|
@ -173,6 +173,21 @@ static const char* handle_special_dirs(const char* dir, unsigned flags,
|
|||
return dir;
|
||||
}
|
||||
|
||||
#else /* !HAVE_SPECIAL_DIRS */
|
||||
|
||||
#ifndef paths_init
|
||||
void paths_init(void) { }
|
||||
#endif
|
||||
|
||||
static const char* handle_special_dirs(const char* dir, unsigned flags,
|
||||
char *buf, const size_t bufsize)
|
||||
{
|
||||
(void) flags; (void) buf; (void) bufsize;
|
||||
return dir;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int app_open(const char *name, int o, ...)
|
||||
{
|
||||
char realpath[MAX_PATH];
|
||||
|
@ -215,48 +230,102 @@ int app_rename(const char *old, const char *new)
|
|||
return rename(final_old, final_new);
|
||||
}
|
||||
|
||||
DIR *app_opendir(const char *name)
|
||||
/* need to wrap around DIR* because we need to save the parent's
|
||||
* directory path in order to determine dirinfo, required to implement
|
||||
* get_dir_info() */
|
||||
struct __dir {
|
||||
DIR *dir;
|
||||
char path[];
|
||||
};
|
||||
|
||||
struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
|
||||
{
|
||||
struct __dir *parent = (struct __dir*)_parent;
|
||||
struct stat s;
|
||||
struct tm *tm = NULL;
|
||||
struct dirinfo ret;
|
||||
char path[MAX_PATH];
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
|
||||
if (!stat(path, &s))
|
||||
{
|
||||
if (S_ISDIR(s.st_mode))
|
||||
{
|
||||
ret.attribute = ATTR_DIRECTORY;
|
||||
}
|
||||
ret.size = s.st_size;
|
||||
tm = localtime(&(s.st_mtime));
|
||||
}
|
||||
|
||||
if (!lstat(path, &s) && S_ISLNK(s.st_mode))
|
||||
{
|
||||
ret.attribute |= ATTR_LINK;
|
||||
}
|
||||
|
||||
if (tm)
|
||||
{
|
||||
ret.wrtdate = ((tm->tm_year - 80) << 9) |
|
||||
((tm->tm_mon + 1) << 5) |
|
||||
tm->tm_mday;
|
||||
ret.wrttime = (tm->tm_hour << 11) |
|
||||
(tm->tm_min << 5) |
|
||||
(tm->tm_sec >> 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DIR* app_opendir(const char *_name)
|
||||
{
|
||||
char realpath[MAX_PATH];
|
||||
const char *fname = handle_special_dirs(name, 0, realpath, sizeof(realpath));
|
||||
return opendir(fname);
|
||||
const char *name = handle_special_dirs(_name, 0, realpath, sizeof(realpath));
|
||||
char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
|
||||
if (!buf)
|
||||
return NULL;
|
||||
|
||||
struct __dir *this = (struct __dir*)buf;
|
||||
/* definitely fits due to strlen() */
|
||||
strcpy(this->path, name);
|
||||
|
||||
this->dir = opendir(name);
|
||||
|
||||
if (!this->dir)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
return (DIR*)this;
|
||||
}
|
||||
|
||||
int app_closedir(DIR *dir)
|
||||
{
|
||||
struct __dir *this = (struct __dir*)dir;
|
||||
int ret = closedir(this->dir);
|
||||
free(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
struct dirent* app_readdir(DIR* dir)
|
||||
{
|
||||
struct __dir *d = (struct __dir*)dir;
|
||||
return readdir(d->dir);
|
||||
}
|
||||
|
||||
|
||||
int app_mkdir(const char* name)
|
||||
{
|
||||
char realpath[MAX_PATH];
|
||||
const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
|
||||
return mkdir(fname);
|
||||
return mkdir(fname, 0777);
|
||||
}
|
||||
|
||||
|
||||
int app_rmdir(const char* name)
|
||||
{
|
||||
char realpath[MAX_PATH];
|
||||
const char *fname = handle_special_dirs(name, NEED_WRITE, realpath, sizeof(realpath));
|
||||
return rmdir(fname);
|
||||
}
|
||||
|
||||
#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); }
|
||||
DIR *app_opendir(const char *name) { return (DIR*)opendir(name); } /* cast to remove warning in checkwps */
|
||||
int app_mkdir(const char* name) { return mkdir(name); }
|
||||
int app_rmdir(const char* name) { return rmdir(name); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -73,6 +73,23 @@ extern void paths_init(void);
|
|||
|
||||
#endif /* !APPLICATION || SAMSUNG_YPR0 */
|
||||
|
||||
#ifdef APPLICATION
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int app_open(const char *name, int o, ...);
|
||||
int app_creat(const char* name, mode_t mode);
|
||||
int app_remove(const char *name);
|
||||
int app_rename(const char *old, const char *new);
|
||||
DIR* app_opendir(const char *_name);
|
||||
int app_closedir(DIR *dir);
|
||||
struct dirent* app_readdir(DIR* dir);
|
||||
int app_mkdir(const char* name);
|
||||
int app_rmdir(const char* name);
|
||||
|
||||
#endif
|
||||
|
||||
#define REC_BASE_DIR HOME_DIR
|
||||
#define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists"
|
||||
|
||||
|
@ -120,4 +137,5 @@ extern void paths_init(void);
|
|||
#define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control"
|
||||
#define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
|
||||
#define GLYPH_CACHE_FILE ROCKBOX_DIR "/.glyphcache"
|
||||
|
||||
#endif /* __PATHS_H__ */
|
||||
|
|
|
@ -33,7 +33,7 @@ struct dirinfo {
|
|||
#include <stdbool.h>
|
||||
#include "file.h"
|
||||
|
||||
#if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) || defined(__PCTOOL__)
|
||||
#if defined(SIMULATOR) || defined(__PCTOOL__)
|
||||
# define dirent_uncached sim_dirent
|
||||
# define DIR_UNCACHED SIM_DIR
|
||||
# define opendir_uncached sim_opendir
|
||||
|
@ -41,10 +41,21 @@ struct dirinfo {
|
|||
# define closedir_uncached sim_closedir
|
||||
# define mkdir_uncached sim_mkdir
|
||||
# define rmdir_uncached sim_rmdir
|
||||
#elif defined(APPLICATION)
|
||||
# include "rbpaths.h"
|
||||
# define DIRENT_DEFINED
|
||||
# define DIR_DEFINED
|
||||
# define dirent_uncached dirent
|
||||
# define DIR_UNCACHED DIR
|
||||
# define opendir_uncached app_opendir
|
||||
# define readdir_uncached app_readdir
|
||||
# define closedir_uncached app_closedir
|
||||
# define mkdir_uncached app_mkdir
|
||||
# define rmdir_uncached app_rmdir
|
||||
#endif
|
||||
|
||||
#ifndef DIRENT_DEFINED
|
||||
|
||||
#ifndef DIRENT_DEFINED
|
||||
struct dirent_uncached {
|
||||
unsigned char d_name[MAX_PATH];
|
||||
struct dirinfo info;
|
||||
|
@ -72,23 +83,6 @@ typedef struct {
|
|||
} DIR_UNCACHED CACHEALIGN_ATTR;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(APPLICATION) && !defined(__PCTOOL__)
|
||||
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)
|
||||
#include "dir-target.h"
|
||||
#endif
|
||||
# undef opendir_uncached
|
||||
# define opendir_uncached app_opendir
|
||||
# undef mkdir_uncached
|
||||
# define mkdir_uncached app_mkdir
|
||||
# undef rmdir_uncached
|
||||
# define rmdir_uncached app_rmdir
|
||||
/* defined in rbpaths.c */
|
||||
extern DIR_UNCACHED* app_opendir(const char* name);
|
||||
extern int app_rmdir(const char* name);
|
||||
extern int app_mkdir(const char* name);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HOTSWAP
|
||||
char *get_volume_name(int volume);
|
||||
#endif
|
||||
|
|
|
@ -38,33 +38,27 @@
|
|||
|
||||
#if !defined(PLUGIN) && !defined(CODEC)
|
||||
#if defined(APPLICATION) && !defined(__PCTOOL__)
|
||||
# define open(x, ...) app_open(x, __VA_ARGS__)
|
||||
# define creat(x,m) app_creat(x, m)
|
||||
# define remove(x) app_remove(x)
|
||||
# define rename(x,y) app_rename(x,y)
|
||||
extern int app_open(const char *name, int o, ...);
|
||||
extern int app_creat(const char *name, mode_t mode);
|
||||
extern int app_remove(const char* pathname);
|
||||
extern int app_rename(const char* path, const char* newname);
|
||||
#include "rbpaths.h"
|
||||
# define open(x, ...) app_open(x, __VA_ARGS__)
|
||||
# define creat(x,m) app_creat(x, m)
|
||||
# define remove(x) app_remove(x)
|
||||
# define rename(x,y) app_rename(x,y)
|
||||
# if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
|
||||
# define fsync(x) sim_fsync(x)
|
||||
# define ftruncate(x,y) sim_ftruncate(x,y)
|
||||
# define lseek(x,y,z) sim_lseek(x,y,z)
|
||||
# define read(x,y,z) sim_read(x,y,z)
|
||||
# define write(x,y,z) sim_write(x,y,z)
|
||||
# define close(x) sim_close(x)
|
||||
/* SDL overrides a few more */
|
||||
# define read(x,y,z) sim_read(x,y,z)
|
||||
# define write(x,y,z) sim_write(x,y,z)
|
||||
# endif
|
||||
#elif defined(SIMULATOR) || defined(DBTOOL)
|
||||
# define open(x, ...) sim_open(x, __VA_ARGS__)
|
||||
# define creat(x,m) sim_creat(x,m)
|
||||
# define remove(x) sim_remove(x)
|
||||
# define rename(x,y) sim_rename(x,y)
|
||||
# define fsync(x) sim_fsync(x)
|
||||
# define ftruncate(x,y) sim_ftruncate(x,y)
|
||||
# define lseek(x,y,z) sim_lseek(x,y,z)
|
||||
# define read(x,y,z) sim_read(x,y,z)
|
||||
# define write(x,y,z) sim_write(x,y,z)
|
||||
# define close(x) sim_close(x)
|
||||
# define open(x, ...) sim_open(x, __VA_ARGS__)
|
||||
# define creat(x,m) sim_creat(x,m)
|
||||
# define remove(x) sim_remove(x)
|
||||
# define rename(x,y) sim_rename(x,y)
|
||||
# define fsync(x) sim_fsync(x)
|
||||
# define ftruncate(x,y) sim_ftruncate(x,y)
|
||||
# define lseek(x,y,z) sim_lseek(x,y,z)
|
||||
# define read(x,y,z) sim_read(x,y,z)
|
||||
# define write(x,y,z) sim_write(x,y,z)
|
||||
# define close(x) sim_close(x)
|
||||
extern int sim_open(const char *name, int o, ...);
|
||||
extern int sim_creat(const char *name, mode_t mode);
|
||||
#endif
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2010 by 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DIR_TARGET_H__
|
||||
#define __DIR_TARGET_H__
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#define dirent_uncached dirent
|
||||
#define DIR_UNCACHED DIR
|
||||
#define opendir_uncached _opendir
|
||||
#define readdir_uncached _readdir
|
||||
#define closedir_uncached _closedir
|
||||
#define mkdir_uncached _mkdir
|
||||
#define rmdir_uncached rmdir
|
||||
|
||||
extern DIR* _opendir(const char* name);
|
||||
extern int _mkdir(const char* name);
|
||||
extern int rmdir(const char* name);
|
||||
extern int _closedir(DIR* dir);
|
||||
extern struct dirent *_readdir(DIR* dir);
|
||||
extern void fat_size(unsigned long *size, unsigned long *free);
|
||||
|
||||
#define DIRFUNCTIONS_DEFINED
|
||||
#define DIRENT_DEFINED
|
||||
#define DIR_DEFINED
|
||||
|
||||
#endif /* __DIR_TARGET_H__ */
|
|
@ -19,17 +19,8 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h> /* stat() */
|
||||
#include <stdio.h> /* snprintf */
|
||||
#include <string.h> /* size_t */
|
||||
#include <dirent.h>
|
||||
#include <time.h> /* localtime() */
|
||||
#include "system-target.h"
|
||||
#include "dir-target.h"
|
||||
#include "file.h"
|
||||
#include "dir.h"
|
||||
#include "rbpaths.h"
|
||||
#include "mv.h" /* stat() */
|
||||
|
||||
|
||||
long filesize(int fd)
|
||||
|
@ -48,95 +39,3 @@ void fat_size(IF_MV(int volume,) unsigned long* size, unsigned long* free)
|
|||
IF_MV((void) volume);
|
||||
*size = *free = 0;
|
||||
}
|
||||
|
||||
#undef opendir
|
||||
#undef closedir
|
||||
#undef mkdir
|
||||
#undef readdir
|
||||
|
||||
/* need to wrap around DIR* because we need to save the parent's
|
||||
* directory path in order to determine dirinfo */
|
||||
struct __dir {
|
||||
DIR *dir;
|
||||
char *path;
|
||||
};
|
||||
|
||||
DIR* _opendir(const char *name)
|
||||
{
|
||||
char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
|
||||
if (!buf)
|
||||
return NULL;
|
||||
|
||||
struct __dir *this = (struct __dir*)buf;
|
||||
|
||||
this->path = buf+sizeof(struct __dir);
|
||||
/* definitely fits due to strlen() */
|
||||
strcpy(this->path, name);
|
||||
|
||||
this->dir = opendir(name);
|
||||
|
||||
if (!this->dir)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
return (DIR*)this;
|
||||
}
|
||||
|
||||
int _mkdir(const char *name)
|
||||
{
|
||||
return mkdir(name, 0777);
|
||||
}
|
||||
|
||||
int _closedir(DIR *dir)
|
||||
{
|
||||
struct __dir *this = (struct __dir*)dir;
|
||||
int ret = closedir(this->dir);
|
||||
free(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct dirent* _readdir(DIR* dir)
|
||||
{
|
||||
struct __dir *d = (struct __dir*)dir;
|
||||
return readdir(d->dir);
|
||||
}
|
||||
|
||||
struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
|
||||
{
|
||||
struct __dir *parent = (struct __dir*)_parent;
|
||||
struct stat s;
|
||||
struct tm *tm = NULL;
|
||||
struct dirinfo ret;
|
||||
char path[MAX_PATH];
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
|
||||
if (!stat(path, &s))
|
||||
{
|
||||
if (S_ISDIR(s.st_mode))
|
||||
{
|
||||
ret.attribute = ATTR_DIRECTORY;
|
||||
}
|
||||
ret.size = s.st_size;
|
||||
tm = localtime(&(s.st_mtime));
|
||||
}
|
||||
|
||||
if (!lstat(path, &s) && S_ISLNK(s.st_mode))
|
||||
{
|
||||
ret.attribute |= ATTR_LINK;
|
||||
}
|
||||
|
||||
if (tm)
|
||||
{
|
||||
ret.wrtdate = ((tm->tm_year - 80) << 9) |
|
||||
((tm->tm_mon + 1) << 5) |
|
||||
tm->tm_mday;
|
||||
ret.wrttime = (tm->tm_hour << 11) |
|
||||
(tm->tm_min << 5) |
|
||||
(tm->tm_sec >> 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2010 by 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DIR_TARGET_H__
|
||||
#define __DIR_TARGET_H__
|
||||
|
||||
#include <dirent.h>
|
||||
/* including unistd.h is too noisy */
|
||||
extern int rmdir(const char* name);
|
||||
|
||||
|
||||
#define dirent_uncached dirent
|
||||
#define DIR_UNCACHED DIR
|
||||
#define opendir_uncached _opendir
|
||||
#define readdir_uncached _readdir
|
||||
#define closedir_uncached _closedir
|
||||
#define mkdir_uncached _mkdir
|
||||
#define rmdir_uncached rmdir
|
||||
|
||||
extern DIR* _opendir(const char* name);
|
||||
extern int _mkdir(const char* name);
|
||||
extern int _rmdir(const char* name);
|
||||
extern int _closedir(DIR* dir);
|
||||
extern struct dirent *_readdir(DIR* dir);
|
||||
|
||||
#define DIRFUNCTIONS_DEFINED
|
||||
#define DIRENT_DEFINED
|
||||
#define DIR_DEFINED
|
||||
|
||||
#endif /* __DIR_TARGET_H__ */
|
|
@ -1,27 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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 <dirent.h>
|
||||
|
||||
#define _mkdir mkdir
|
||||
#define _opendir opendir
|
||||
|
|
@ -155,6 +155,7 @@ void dircache_remove(const char *name);
|
|||
void dircache_rename(const char *oldname, const char *newname);
|
||||
#endif
|
||||
|
||||
#ifndef APPLICATION
|
||||
|
||||
#define SIMULATOR_DEFAULT_ROOT "simdisk"
|
||||
extern const char *sim_root_dir;
|
||||
|
@ -210,6 +211,8 @@ static unsigned int rockbox2sim(int opt)
|
|||
#endif
|
||||
}
|
||||
|
||||
#endif /* APPLICATION */
|
||||
|
||||
/** Simulator I/O engine routines **/
|
||||
#define IO_YIELD_THRESHOLD 512
|
||||
|
||||
|
@ -282,6 +285,43 @@ static ssize_t io_trigger_and_wait(enum io_dir cmd)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
ssize_t sim_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
mutex_lock(&io.sim_mutex);
|
||||
|
||||
/* Setup parameters */
|
||||
io.fd = fd;
|
||||
io.buf = buf;
|
||||
io.count = count;
|
||||
|
||||
result = io_trigger_and_wait(IO_READ);
|
||||
|
||||
mutex_unlock(&io.sim_mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ssize_t sim_write(int fd, const void *buf, size_t count)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
mutex_lock(&io.sim_mutex);
|
||||
|
||||
io.fd = fd;
|
||||
io.buf = (void*)buf;
|
||||
io.count = count;
|
||||
|
||||
result = io_trigger_and_wait(IO_WRITE);
|
||||
|
||||
mutex_unlock(&io.sim_mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !defined(APPLICATION)
|
||||
static const char *get_sim_pathname(const char *name)
|
||||
{
|
||||
|
@ -296,9 +336,6 @@ static const char *get_sim_pathname(const char *name)
|
|||
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name);
|
||||
return name;
|
||||
}
|
||||
#else
|
||||
#define get_sim_pathname(name) name
|
||||
#endif
|
||||
|
||||
MYDIR *sim_opendir(const char *name)
|
||||
{
|
||||
|
@ -446,41 +483,6 @@ int sim_creat(const char *name, mode_t mode)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ssize_t sim_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
mutex_lock(&io.sim_mutex);
|
||||
|
||||
/* Setup parameters */
|
||||
io.fd = fd;
|
||||
io.buf = buf;
|
||||
io.count = count;
|
||||
|
||||
result = io_trigger_and_wait(IO_READ);
|
||||
|
||||
mutex_unlock(&io.sim_mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ssize_t sim_write(int fd, const void *buf, size_t count)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
mutex_lock(&io.sim_mutex);
|
||||
|
||||
io.fd = fd;
|
||||
io.buf = (void*)buf;
|
||||
io.count = count;
|
||||
|
||||
result = io_trigger_and_wait(IO_WRITE);
|
||||
|
||||
mutex_unlock(&io.sim_mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int sim_mkdir(const char *name)
|
||||
{
|
||||
return MKDIR(get_sim_pathname(name), 0777);
|
||||
|
@ -520,6 +522,10 @@ long sim_lseek(int fildes, long offset, int whence)
|
|||
return lseek(fildes, offset, whence);
|
||||
}
|
||||
|
||||
#else
|
||||
#define get_sim_pathname(x) x
|
||||
#endif
|
||||
|
||||
long filesize(int fd)
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
|
Loading…
Reference in a new issue