2002-05-13 15:23:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-06-14 11:00:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-05-07 12:06:32 +00:00
|
|
|
#include <sys/stat.h>
|
2002-11-12 11:32:26 +00:00
|
|
|
#include <sys/vfs.h>
|
2002-05-07 12:25:30 +00:00
|
|
|
#include <dirent.h>
|
2003-01-28 23:14:41 +00:00
|
|
|
#include <unistd.h>
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-06-14 11:00:13 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include "debug.h"
|
|
|
|
|
2002-05-07 12:25:30 +00:00
|
|
|
#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
|
|
|
|
#define dirent x11_dirent
|
2003-02-07 10:10:17 +00:00
|
|
|
#include "../../firmware/include/dir.h"
|
2002-05-07 12:25:30 +00:00
|
|
|
#undef dirent
|
|
|
|
|
|
|
|
#define SIMULATOR_ARCHOS_ROOT "archos"
|
|
|
|
|
|
|
|
struct mydir {
|
2003-03-05 22:59:36 +00:00
|
|
|
DIR *dir;
|
|
|
|
char *name;
|
2002-05-07 12:25:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct mydir MYDIR;
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
MYDIR *x11_opendir(char *name)
|
2002-04-30 13:14:59 +00:00
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
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;
|
2002-04-30 13:14:59 +00:00
|
|
|
}
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2002-05-07 12:25:30 +00:00
|
|
|
struct x11_dirent *x11_readdir(MYDIR *dir)
|
2002-05-07 11:35:03 +00:00
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
char buffer[512]; /* sufficiently big */
|
|
|
|
static struct x11_dirent secret;
|
|
|
|
struct stat s;
|
|
|
|
struct dirent *x11 = (readdir)(dir->dir);
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(!x11)
|
|
|
|
return (struct x11_dirent *)0;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
strcpy(secret.d_name, x11->d_name);
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
/* build file name */
|
|
|
|
sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s",
|
|
|
|
dir->name, x11->d_name);
|
|
|
|
stat(buffer, &s); /* get info */
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0;
|
|
|
|
secret.size = s.st_size;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
return &secret;
|
2002-05-07 11:35:03 +00:00
|
|
|
}
|
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
void x11_closedir(MYDIR *dir)
|
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
free(dir->name);
|
|
|
|
(closedir)(dir->dir);
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
free(dir);
|
2002-05-07 12:06:32 +00:00
|
|
|
}
|
|
|
|
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2003-06-29 16:43:15 +00:00
|
|
|
int x11_open(const char *name, int opts)
|
2002-05-05 10:28:23 +00:00
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
char buffer[256]; /* sufficiently big */
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
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);
|
2002-05-05 10:28:23 +00:00
|
|
|
}
|
2002-11-12 11:32:26 +00:00
|
|
|
|
2003-01-28 23:14:41 +00:00
|
|
|
int x11_close(int fd)
|
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
return (close)(fd);
|
2003-01-28 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2003-01-09 00:55:00 +00:00
|
|
|
int x11_creat(char *name, int mode)
|
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
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);
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int x11_remove(char *name)
|
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
char buffer[256]; /* sufficiently big */
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(name[0] == '/') {
|
|
|
|
sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
debugf("We remove the real file '%s'\n", buffer);
|
|
|
|
return (remove)(buffer);
|
|
|
|
}
|
|
|
|
return (remove)(name);
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
|
2003-01-15 11:38:03 +00:00
|
|
|
int x11_rename(char *oldpath, char* newpath)
|
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
char buffer1[256];
|
|
|
|
char buffer2[256];
|
2003-01-15 11:38:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(oldpath[0] == '/') {
|
|
|
|
sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath);
|
|
|
|
sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath);
|
2003-01-15 11:38:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2);
|
|
|
|
return (rename)(buffer1, buffer2);
|
|
|
|
}
|
|
|
|
return -1;
|
2003-01-15 11:38:03 +00:00
|
|
|
}
|
|
|
|
|
2003-03-18 00:39:57 +00:00
|
|
|
int x11_filesize(int fd)
|
|
|
|
{
|
|
|
|
int old = lseek(fd, 0, SEEK_CUR);
|
|
|
|
int size = lseek(fd, 0, SEEK_END);
|
|
|
|
lseek(fd, old, SEEK_SET);
|
|
|
|
|
|
|
|
return(size);
|
|
|
|
}
|
|
|
|
|
2002-11-12 11:32:26 +00:00
|
|
|
void fat_size(unsigned int* size, unsigned int* free)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|