1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 #include <sys/param.h>
26 #include <sys/mount.h>
36 #define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
37 #define dirent x11_dirent
38 #include "../../firmware/include/dir.h"
41 #define SIMULATOR_ARCHOS_ROOT "archos"
48 typedef struct mydir MYDIR
;
50 MYDIR
*x11_opendir(const char *name
)
52 char buffer
[256]; /* sufficiently big */
56 sprintf(buffer
, "%s%s", SIMULATOR_ARCHOS_ROOT
, name
);
57 dir
=(DIR *)opendir(buffer
);
60 dir
=(DIR *)opendir(name
);
63 MYDIR
*my
= (MYDIR
*)malloc(sizeof(MYDIR
));
65 my
->name
= (char *)strdup(name
);
69 /* failed open, return NULL */
73 struct x11_dirent
*x11_readdir(MYDIR
*dir
)
75 char buffer
[512]; /* sufficiently big */
76 static struct x11_dirent secret
;
78 struct dirent
*x11
= (readdir
)(dir
->dir
);
81 return (struct x11_dirent
*)0;
83 strcpy(secret
.d_name
, x11
->d_name
);
86 sprintf(buffer
, SIMULATOR_ARCHOS_ROOT
"%s/%s",
87 dir
->name
, x11
->d_name
);
88 stat(buffer
, &s
); /* get info */
90 secret
.attribute
= S_ISDIR(s
.st_mode
)?ATTR_DIRECTORY
:0;
91 secret
.size
= s
.st_size
;
96 void x11_closedir(MYDIR
*dir
)
105 int x11_open(const char *name
, int opts
)
107 char buffer
[256]; /* sufficiently big */
110 sprintf(buffer
, "%s%s", SIMULATOR_ARCHOS_ROOT
, name
);
112 debugf("We open the real file '%s'\n", buffer
);
113 return (open
)(buffer
, opts
);
115 return (open
)(name
, opts
);
118 int x11_close(int fd
)
123 int x11_creat(const char *name
, mode_t mode
)
125 char buffer
[256]; /* sufficiently big */
128 sprintf(buffer
, "%s%s", SIMULATOR_ARCHOS_ROOT
, name
);
130 debugf("We create the real file '%s'\n", buffer
);
131 return (creat
)(buffer
, 0666);
133 return (creat
)(name
, 0666);
136 int x11_mkdir(const char *name
, mode_t mode
)
138 char buffer
[256]; /* sufficiently big */
141 sprintf(buffer
, "%s%s", SIMULATOR_ARCHOS_ROOT
, name
);
143 debugf("We create the real directory '%s'\n", buffer
);
144 return (mkdir
)(buffer
, 0666);
146 return (mkdir
)(name
, 0666);
149 int x11_rmdir(const char *name
)
151 char buffer
[256]; /* sufficiently big */
153 sprintf(buffer
, "%s%s", SIMULATOR_ARCHOS_ROOT
, name
);
155 debugf("We remove the real directory '%s'\n", buffer
);
156 return (rmdir
)(buffer
);
158 return (rmdir
)(name
);
161 int x11_remove(char *name
)
163 char buffer
[256]; /* sufficiently big */
166 sprintf(buffer
, "%s%s", SIMULATOR_ARCHOS_ROOT
, name
);
168 debugf("We remove the real file '%s'\n", buffer
);
169 return (remove
)(buffer
);
171 return (remove
)(name
);
174 int x11_rename(char *oldpath
, char* newpath
)
179 if(oldpath
[0] == '/') {
180 sprintf(buffer1
, "%s%s", SIMULATOR_ARCHOS_ROOT
, oldpath
);
181 sprintf(buffer2
, "%s%s", SIMULATOR_ARCHOS_ROOT
, newpath
);
183 debugf("We rename the real file '%s' to '%s'\n", buffer1
, buffer2
);
184 return (rename
)(buffer1
, buffer2
);
189 int x11_filesize(int fd
)
191 int old
= lseek(fd
, 0, SEEK_CUR
);
192 int size
= lseek(fd
, 0, SEEK_END
);
193 lseek(fd
, old
, SEEK_SET
);
198 void fat_size(unsigned int* size
, unsigned int* free
)
202 if (!statfs(".", &fs
)) {
203 DEBUGF("statfs: bsize=%d blocks=%d free=%d\n",
204 fs
.f_bsize
, fs
.f_blocks
, fs
.f_bfree
);
206 *size
= fs
.f_blocks
* (fs
.f_bsize
/ 1024);
208 *free
= fs
.f_bfree
* (fs
.f_bsize
/ 1024);