diff options
Diffstat (limited to 'uisimulator/x11/io.c')
-rw-r--r-- | uisimulator/x11/io.c | 216 |
1 files changed, 0 insertions, 216 deletions
diff --git a/uisimulator/x11/io.c b/uisimulator/x11/io.c deleted file mode 100644 index d4d2714026..0000000000 --- a/uisimulator/x11/io.c +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Daniel Stenberg | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <sys/stat.h> | ||
24 | #ifdef __FreeBSD__ | ||
25 | #include <sys/param.h> | ||
26 | #include <sys/mount.h> | ||
27 | #else | ||
28 | #include <sys/vfs.h> | ||
29 | #endif | ||
30 | #include <dirent.h> | ||
31 | #include <unistd.h> | ||
32 | |||
33 | #include <fcntl.h> | ||
34 | #include "debug.h" | ||
35 | |||
36 | #define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ | ||
37 | #define dirent x11_dirent | ||
38 | #include "../../firmware/include/dir.h" | ||
39 | #undef dirent | ||
40 | |||
41 | #define SIMULATOR_ARCHOS_ROOT "archos" | ||
42 | |||
43 | struct mydir { | ||
44 | DIR *dir; | ||
45 | char *name; | ||
46 | }; | ||
47 | |||
48 | typedef struct mydir MYDIR; | ||
49 | |||
50 | MYDIR *x11_opendir(const char *name) | ||
51 | { | ||
52 | char buffer[256]; /* sufficiently big */ | ||
53 | DIR *dir; | ||
54 | |||
55 | if(name[0] == '/') { | ||
56 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
57 | dir=(DIR *)opendir(buffer); | ||
58 | } | ||
59 | else | ||
60 | dir=(DIR *)opendir(name); | ||
61 | |||
62 | if(dir) { | ||
63 | MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR)); | ||
64 | my->dir = dir; | ||
65 | my->name = (char *)strdup(name); | ||
66 | |||
67 | return my; | ||
68 | } | ||
69 | /* failed open, return NULL */ | ||
70 | return (MYDIR *)0; | ||
71 | } | ||
72 | |||
73 | struct x11_dirent *x11_readdir(MYDIR *dir) | ||
74 | { | ||
75 | char buffer[512]; /* sufficiently big */ | ||
76 | static struct x11_dirent secret; | ||
77 | struct stat s; | ||
78 | struct dirent *x11 = (readdir)(dir->dir); | ||
79 | |||
80 | if(!x11) | ||
81 | return (struct x11_dirent *)0; | ||
82 | |||
83 | strcpy(secret.d_name, x11->d_name); | ||
84 | |||
85 | /* build file name */ | ||
86 | sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s", | ||
87 | dir->name, x11->d_name); | ||
88 | stat(buffer, &s); /* get info */ | ||
89 | |||
90 | secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0; | ||
91 | secret.size = s.st_size; | ||
92 | |||
93 | return &secret; | ||
94 | } | ||
95 | |||
96 | void x11_closedir(MYDIR *dir) | ||
97 | { | ||
98 | free(dir->name); | ||
99 | (closedir)(dir->dir); | ||
100 | |||
101 | free(dir); | ||
102 | } | ||
103 | |||
104 | |||
105 | int x11_open(const char *name, int opts) | ||
106 | { | ||
107 | char buffer[256]; /* sufficiently big */ | ||
108 | |||
109 | if(name[0] == '/') { | ||
110 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
111 | |||
112 | debugf("We open the real file '%s'\n", buffer); | ||
113 | return (open)(buffer, opts); | ||
114 | } | ||
115 | return (open)(name, opts); | ||
116 | } | ||
117 | |||
118 | int x11_close(int fd) | ||
119 | { | ||
120 | return (close)(fd); | ||
121 | } | ||
122 | |||
123 | int x11_creat(const char *name, mode_t mode) | ||
124 | { | ||
125 | char buffer[256]; /* sufficiently big */ | ||
126 | (void)mode; | ||
127 | if(name[0] == '/') { | ||
128 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
129 | |||
130 | debugf("We create the real file '%s'\n", buffer); | ||
131 | return (creat)(buffer, 0666); | ||
132 | } | ||
133 | return (creat)(name, 0666); | ||
134 | } | ||
135 | |||
136 | int x11_mkdir(const char *name, mode_t mode) | ||
137 | { | ||
138 | char buffer[256]; /* sufficiently big */ | ||
139 | (void)mode; | ||
140 | if(name[0] == '/') { | ||
141 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
142 | |||
143 | debugf("We create the real directory '%s'\n", buffer); | ||
144 | return (mkdir)(buffer, 0666); | ||
145 | } | ||
146 | return (mkdir)(name, 0666); | ||
147 | } | ||
148 | |||
149 | int x11_rmdir(const char *name) | ||
150 | { | ||
151 | char buffer[256]; /* sufficiently big */ | ||
152 | if(name[0] == '/') { | ||
153 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
154 | |||
155 | debugf("We remove the real directory '%s'\n", buffer); | ||
156 | return (rmdir)(buffer); | ||
157 | } | ||
158 | return (rmdir)(name); | ||
159 | } | ||
160 | |||
161 | int x11_remove(char *name) | ||
162 | { | ||
163 | char buffer[256]; /* sufficiently big */ | ||
164 | |||
165 | if(name[0] == '/') { | ||
166 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
167 | |||
168 | debugf("We remove the real file '%s'\n", buffer); | ||
169 | return (remove)(buffer); | ||
170 | } | ||
171 | return (remove)(name); | ||
172 | } | ||
173 | |||
174 | int x11_rename(char *oldpath, char* newpath) | ||
175 | { | ||
176 | char buffer1[256]; | ||
177 | char buffer2[256]; | ||
178 | |||
179 | if(oldpath[0] == '/') { | ||
180 | sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath); | ||
181 | sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath); | ||
182 | |||
183 | debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); | ||
184 | return (rename)(buffer1, buffer2); | ||
185 | } | ||
186 | return -1; | ||
187 | } | ||
188 | |||
189 | int x11_filesize(int fd) | ||
190 | { | ||
191 | int old = lseek(fd, 0, SEEK_CUR); | ||
192 | int size = lseek(fd, 0, SEEK_END); | ||
193 | lseek(fd, old, SEEK_SET); | ||
194 | |||
195 | return(size); | ||
196 | } | ||
197 | |||
198 | void fat_size(unsigned int* size, unsigned int* free) | ||
199 | { | ||
200 | struct statfs fs; | ||
201 | |||
202 | if (!statfs(".", &fs)) { | ||
203 | DEBUGF("statfs: bsize=%d blocks=%d free=%d\n", | ||
204 | fs.f_bsize, fs.f_blocks, fs.f_bfree); | ||
205 | if (size) | ||
206 | *size = fs.f_blocks * (fs.f_bsize / 1024); | ||
207 | if (free) | ||
208 | *free = fs.f_bfree * (fs.f_bsize / 1024); | ||
209 | } | ||
210 | else { | ||
211 | if (size) | ||
212 | *size = 0; | ||
213 | if (free) | ||
214 | *free = 0; | ||
215 | } | ||
216 | } | ||