From a6142ab7ab58f69a3f1a034db4bdf1eff24d3dd6 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 10 Jun 2004 13:29:52 +0000 Subject: Finally, the archos directory sandbox works in the same way for both X11 and win32 simulators. Unfortunately, this breaks the VC++ compatibility. Also, the plugin API now supports DEBUGF. Last, but not least, we have a new plugin, vbrfix.rock. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4726 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/dir.h | 45 ++++++++++ uisimulator/common/file.h | 71 +++++++++++++++ uisimulator/common/io.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 uisimulator/common/dir.h create mode 100644 uisimulator/common/file.h create mode 100644 uisimulator/common/io.c (limited to 'uisimulator/common') diff --git a/uisimulator/common/dir.h b/uisimulator/common/dir.h new file mode 100644 index 0000000000..15332be54e --- /dev/null +++ b/uisimulator/common/dir.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Daniel Stenberg + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _SIM_DIR_H_ +#define _SIM_DIR_H_ + +#include + +#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ +#define dirent sim_dirent +#include "../../firmware/include/dir.h" +#undef dirent + +typedef void * MYDIR; + +extern MYDIR *sim_opendir(const char *name); +extern struct sim_dirent* sim_readdir(MYDIR* dir); +extern int sim_closedir(MYDIR *dir); +extern int sim_mkdir(char *name, int mode); +extern int sim_rmdir(char *name); + +#define DIR MYDIR +#define dirent sim_dirent +#define opendir(x) sim_opendir(x) +#define readdir(x) sim_readdir(x) +#define closedir(x) sim_closedir(x) +#define mkdir(x, y) sim_mkdir(x, y) +#define rmdir(x) sim_rmdir(x) + +#endif diff --git a/uisimulator/common/file.h b/uisimulator/common/file.h new file mode 100644 index 0000000000..8d91b61831 --- /dev/null +++ b/uisimulator/common/file.h @@ -0,0 +1,71 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Daniel Stenberg + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _SIM_FILE_H_ +#define _SIM_FILE_H_ + +#ifdef WIN32 +#include +#include +#else +#include +#endif + +#include + +#ifdef WIN32 +#ifndef _commit +extern int _commit( int handle ); +#endif +#endif + +int sim_open(const char *name, int opts); +int sim_close(int fd); +int sim_rename(const char *oldpath, const char *newpath); +int sim_filesize(int fd); +int sim_creat(const char *name, mode_t mode); +int sim_remove(const char *name); + +#ifndef NO_REDEFINES_PLEASE +#define open(x,y) sim_open(x,y) +#define close(x) sim_close(x) +#define filesize(x) sim_filesize(x) +#define creat(x,y) sim_creat(x,y) +#define remove(x) sim_remove(x) +#define rename(x,y) sim_rename(x,y) +#ifdef WIN32 +#define fsync _commit +#endif +#endif + +#include "../../firmware/include/file.h" + +#ifndef WIN32 +int open(const char* pathname, int flags); +int close(int fd); +int printf(const char *format, ...); +int ftruncate(int fd, off_t length); +int fsync(int fd); + +off_t lseek(int fildes, off_t offset, int whence); +ssize_t read(int fd, void *buf, size_t count); +ssize_t write(int fd, const void *buf, size_t count); +#endif + +#endif diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c new file mode 100644 index 0000000000..745e417fa6 --- /dev/null +++ b/uisimulator/common/io.c @@ -0,0 +1,225 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 Daniel Stenberg + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#include +#elif !defined(WIN32) +#include +#endif +#include +#include + +#include +#include "debug.h" + +#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ +#define dirent sim_dirent +#define DIR SIMDIR +#include "../../firmware/include/dir.h" +#undef dirent +#undef DIR + +#define SIMULATOR_ARCHOS_ROOT "archos" + +struct mydir { + DIR *dir; + char *name; +}; + +typedef struct mydir MYDIR; + +MYDIR *sim_opendir(const char *name) +{ + char buffer[256]; /* sufficiently big */ + DIR *dir; + + if(name[0] == '/') { + sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); + dir=(DIR *)opendir(buffer); + } + else + dir=(DIR *)opendir(name); + + if(dir) { + MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR)); + my->dir = dir; + my->name = (char *)strdup(name); + + return my; + } + /* failed open, return NULL */ + return (MYDIR *)0; +} + +struct sim_dirent *sim_readdir(MYDIR *dir) +{ + char buffer[512]; /* sufficiently big */ + static struct sim_dirent secret; + struct stat s; + struct dirent *x11 = (readdir)(dir->dir); + + if(!x11) + return (struct sim_dirent *)0; + + strcpy(secret.d_name, x11->d_name); + + /* build file name */ + sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s", + dir->name, x11->d_name); + stat(buffer, &s); /* get info */ + + secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0; + secret.size = s.st_size; + + return &secret; +} + +void sim_closedir(MYDIR *dir) +{ + free(dir->name); + (closedir)(dir->dir); + + free(dir); +} + + +int sim_open(const char *name, int opts) +{ + char buffer[256]; /* sufficiently big */ + + if(name[0] == '/') { + sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); + + debugf("We open the real file '%s'\n", buffer); + return (open)(buffer, opts); + } + return (open)(name, opts); +} + +int sim_close(int fd) +{ + return (close)(fd); +} + +int sim_creat(const char *name, mode_t mode) +{ + char buffer[256]; /* sufficiently big */ + (void)mode; + if(name[0] == '/') { + sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); + + debugf("We create the real file '%s'\n", buffer); + return (creat)(buffer, 0666); + } + return (creat)(name, 0666); +} + +int sim_mkdir(const char *name, mode_t mode) +{ + char buffer[256]; /* sufficiently big */ + (void)mode; + + sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); + + debugf("We create the real directory '%s'\n", buffer); +#ifdef WIN32 + return (mkdir)(buffer); +#else + return (mkdir)(buffer, 0666); +#endif +} + +int sim_rmdir(const char *name) +{ + char buffer[256]; /* sufficiently big */ + if(name[0] == '/') { + sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); + + debugf("We remove the real directory '%s'\n", buffer); + return (rmdir)(buffer); + } + return (rmdir)(name); +} + +int sim_remove(const char *name) +{ + char buffer[256]; /* sufficiently big */ + + if(name[0] == '/') { + sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); + + debugf("We remove the real file '%s'\n", buffer); + return (remove)(buffer); + } + return (remove)(name); +} + +int sim_rename(const char *oldpath, const char* newpath) +{ + char buffer1[256]; + char buffer2[256]; + + if(oldpath[0] == '/') { + sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath); + sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath); + + debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); + return (rename)(buffer1, buffer2); + } + return -1; +} + +int sim_filesize(int fd) +{ + int old = lseek(fd, 0, SEEK_CUR); + int size = lseek(fd, 0, SEEK_END); + lseek(fd, old, SEEK_SET); + + return(size); +} + +void fat_size(unsigned int* size, unsigned int* free) +{ +#ifdef WIN32 + *size = 2049; + *free = 1037; +#else + struct statfs fs; + + if (!statfs(".", &fs)) { + DEBUGF("statfs: bsize=%d blocks=%d free=%d\n", + fs.f_bsize, fs.f_blocks, fs.f_bfree); + if (size) + *size = fs.f_blocks * (fs.f_bsize / 1024); + if (free) + *free = fs.f_bfree * (fs.f_bsize / 1024); + } + else { + if (size) + *size = 0; + if (free) + *free = 0; + } +#endif +} -- cgit v1.2.3