diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/hosted/android/dir-target.h | 37 | ||||
-rw-r--r-- | firmware/target/hosted/android/fs-android.c | 129 | ||||
-rw-r--r-- | firmware/target/hosted/android/lc-android.c | 40 |
3 files changed, 206 insertions, 0 deletions
diff --git a/firmware/target/hosted/android/dir-target.h b/firmware/target/hosted/android/dir-target.h new file mode 100644 index 0000000000..4516215d62 --- /dev/null +++ b/firmware/target/hosted/android/dir-target.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 by Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef __DIR_TARGET_H__ | ||
23 | #define __DIR_TARGET_H__ | ||
24 | |||
25 | #include <dirent.h> | ||
26 | |||
27 | #define opendir _opendir | ||
28 | #define mkdir _mkdir | ||
29 | #define closedir _closedir | ||
30 | #define readdir _readdir | ||
31 | |||
32 | extern DIR* _opendir(const char* name); | ||
33 | extern int _mkdir(const char* name); | ||
34 | extern int _closedir(DIR* dir); | ||
35 | extern struct dirent *_readdir(DIR* dir); | ||
36 | |||
37 | #endif /* __DIR_TARGET_H__ */ | ||
diff --git a/firmware/target/hosted/android/fs-android.c b/firmware/target/hosted/android/fs-android.c new file mode 100644 index 0000000000..5209458e54 --- /dev/null +++ b/firmware/target/hosted/android/fs-android.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 by Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdlib.h> | ||
23 | #include <sys/stat.h> /* stat() */ | ||
24 | #include <stdio.h> /* snprintf */ | ||
25 | #include <string.h> /* size_t */ | ||
26 | #include <dirent.h> | ||
27 | #include <time.h> /* localtime() */ | ||
28 | #include "system-target.h" | ||
29 | #include "dir-target.h" | ||
30 | #include "file.h" | ||
31 | #include "dir.h" | ||
32 | |||
33 | |||
34 | long filesize(int fd) | ||
35 | { | ||
36 | struct stat buf; | ||
37 | |||
38 | if (!fstat(fd, &buf)) | ||
39 | return buf.st_size; | ||
40 | else | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | /* do we really need this in the app? */ | ||
45 | void fat_size(unsigned long* size, unsigned long* free) | ||
46 | { | ||
47 | *size = *free = 0; | ||
48 | } | ||
49 | |||
50 | #undef opendir | ||
51 | #undef closedir | ||
52 | #undef mkdir | ||
53 | #undef readdir | ||
54 | |||
55 | /* need to wrap around DIR* because we need to save the parent's | ||
56 | * directory path in order to determine dirinfo */ | ||
57 | struct __dir { | ||
58 | DIR *dir; | ||
59 | char *path; | ||
60 | }; | ||
61 | |||
62 | DIR* _opendir(const char *name) | ||
63 | { | ||
64 | char *buf = malloc(sizeof(struct __dir) + strlen(name)+1); | ||
65 | if (!buf) | ||
66 | return NULL; | ||
67 | |||
68 | struct __dir *this = (struct __dir*)buf; | ||
69 | |||
70 | this->path = buf+sizeof(struct __dir); | ||
71 | /* definitely fits due to strlen() */ | ||
72 | strcpy(this->path, name); | ||
73 | |||
74 | this->dir = opendir(name); | ||
75 | |||
76 | if (!this->dir) | ||
77 | { | ||
78 | free(buf); | ||
79 | return NULL; | ||
80 | } | ||
81 | return (DIR*)this; | ||
82 | } | ||
83 | |||
84 | int _mkdir(const char *name) | ||
85 | { | ||
86 | return mkdir(name, 0777); | ||
87 | } | ||
88 | |||
89 | int _closedir(DIR *dir) | ||
90 | { | ||
91 | struct __dir *this = (struct __dir*)dir; | ||
92 | int ret = closedir(this->dir); | ||
93 | free(this); | ||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | struct dirent* _readdir(DIR* dir) | ||
98 | { | ||
99 | struct __dir *d = (struct __dir*)dir; | ||
100 | return readdir(d->dir); | ||
101 | } | ||
102 | |||
103 | struct dirinfo dir_get_info(struct DIR* _parent, struct dirent *dir) | ||
104 | { | ||
105 | struct __dir *parent = (struct __dir*)_parent; | ||
106 | struct stat s; | ||
107 | struct tm *tm; | ||
108 | struct dirinfo ret; | ||
109 | char path[MAX_PATH]; | ||
110 | |||
111 | snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name); | ||
112 | stat(path, &s); | ||
113 | memset(&ret, 0, sizeof(ret)); | ||
114 | |||
115 | if (S_ISDIR(s.st_mode)) | ||
116 | { | ||
117 | ret.attribute = ATTR_DIRECTORY; | ||
118 | } | ||
119 | |||
120 | ret.size = s.st_size; | ||
121 | tm = localtime(&(s.st_mtime)); | ||
122 | ret.wrtdate = ((tm->tm_year - 80) << 9) | | ||
123 | ((tm->tm_mon + 1) << 5) | | ||
124 | tm->tm_mday; | ||
125 | ret.wrttime = (tm->tm_hour << 11) | | ||
126 | (tm->tm_min << 5) | | ||
127 | (tm->tm_sec >> 1); | ||
128 | return ret; | ||
129 | } | ||
diff --git a/firmware/target/hosted/android/lc-android.c b/firmware/target/hosted/android/lc-android.c new file mode 100644 index 0000000000..52ab08badb --- /dev/null +++ b/firmware/target/hosted/android/lc-android.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 by Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <string.h> /* size_t */ | ||
23 | #include "load_code.h" | ||
24 | |||
25 | /* the load_code wrappers simply wrap, nothing to do */ | ||
26 | void *lc_open(const char *filename, char *buf, size_t buf_size) | ||
27 | { | ||
28 | return _lc_open(filename, buf, buf_size); | ||
29 | } | ||
30 | |||
31 | void *lc_get_header(void *handle) | ||
32 | { | ||
33 | return _lc_get_header(handle); | ||
34 | } | ||
35 | |||
36 | void lc_close(void *handle) | ||
37 | { | ||
38 | _lc_close(handle); | ||
39 | } | ||
40 | |||