diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/hosted/android/dir-target.h | 46 | ||||
-rw-r--r-- | firmware/target/hosted/filesystem-unix.c | 103 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/dir-target.h | 48 |
3 files changed, 1 insertions, 196 deletions
diff --git a/firmware/target/hosted/android/dir-target.h b/firmware/target/hosted/android/dir-target.h deleted file mode 100644 index 6962d943fe..0000000000 --- a/firmware/target/hosted/android/dir-target.h +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
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 dirent_uncached dirent | ||
28 | #define DIR_UNCACHED DIR | ||
29 | #define opendir_uncached _opendir | ||
30 | #define readdir_uncached _readdir | ||
31 | #define closedir_uncached _closedir | ||
32 | #define mkdir_uncached _mkdir | ||
33 | #define rmdir_uncached rmdir | ||
34 | |||
35 | extern DIR* _opendir(const char* name); | ||
36 | extern int _mkdir(const char* name); | ||
37 | extern int rmdir(const char* name); | ||
38 | extern int _closedir(DIR* dir); | ||
39 | extern struct dirent *_readdir(DIR* dir); | ||
40 | extern void fat_size(unsigned long *size, unsigned long *free); | ||
41 | |||
42 | #define DIRFUNCTIONS_DEFINED | ||
43 | #define DIRENT_DEFINED | ||
44 | #define DIR_DEFINED | ||
45 | |||
46 | #endif /* __DIR_TARGET_H__ */ | ||
diff --git a/firmware/target/hosted/filesystem-unix.c b/firmware/target/hosted/filesystem-unix.c index 45b9e0fca1..8ac1d4ada9 100644 --- a/firmware/target/hosted/filesystem-unix.c +++ b/firmware/target/hosted/filesystem-unix.c | |||
@@ -19,17 +19,8 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <stdlib.h> | ||
23 | #include <sys/stat.h> /* stat() */ | 22 | #include <sys/stat.h> /* stat() */ |
24 | #include <stdio.h> /* snprintf */ | 23 | #include "mv.h" /* stat() */ |
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 | #include "rbpaths.h" | ||
33 | 24 | ||
34 | 25 | ||
35 | long filesize(int fd) | 26 | long filesize(int fd) |
@@ -48,95 +39,3 @@ void fat_size(IF_MV(int volume,) unsigned long* size, unsigned long* free) | |||
48 | IF_MV((void) volume); | 39 | IF_MV((void) volume); |
49 | *size = *free = 0; | 40 | *size = *free = 0; |
50 | } | 41 | } |
51 | |||
52 | #undef opendir | ||
53 | #undef closedir | ||
54 | #undef mkdir | ||
55 | #undef readdir | ||
56 | |||
57 | /* need to wrap around DIR* because we need to save the parent's | ||
58 | * directory path in order to determine dirinfo */ | ||
59 | struct __dir { | ||
60 | DIR *dir; | ||
61 | char *path; | ||
62 | }; | ||
63 | |||
64 | DIR* _opendir(const char *name) | ||
65 | { | ||
66 | char *buf = malloc(sizeof(struct __dir) + strlen(name)+1); | ||
67 | if (!buf) | ||
68 | return NULL; | ||
69 | |||
70 | struct __dir *this = (struct __dir*)buf; | ||
71 | |||
72 | this->path = buf+sizeof(struct __dir); | ||
73 | /* definitely fits due to strlen() */ | ||
74 | strcpy(this->path, name); | ||
75 | |||
76 | this->dir = opendir(name); | ||
77 | |||
78 | if (!this->dir) | ||
79 | { | ||
80 | free(buf); | ||
81 | return NULL; | ||
82 | } | ||
83 | return (DIR*)this; | ||
84 | } | ||
85 | |||
86 | int _mkdir(const char *name) | ||
87 | { | ||
88 | return mkdir(name, 0777); | ||
89 | } | ||
90 | |||
91 | int _closedir(DIR *dir) | ||
92 | { | ||
93 | struct __dir *this = (struct __dir*)dir; | ||
94 | int ret = closedir(this->dir); | ||
95 | free(this); | ||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | struct dirent* _readdir(DIR* dir) | ||
100 | { | ||
101 | struct __dir *d = (struct __dir*)dir; | ||
102 | return readdir(d->dir); | ||
103 | } | ||
104 | |||
105 | struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir) | ||
106 | { | ||
107 | struct __dir *parent = (struct __dir*)_parent; | ||
108 | struct stat s; | ||
109 | struct tm *tm = NULL; | ||
110 | struct dirinfo ret; | ||
111 | char path[MAX_PATH]; | ||
112 | |||
113 | snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name); | ||
114 | memset(&ret, 0, sizeof(ret)); | ||
115 | |||
116 | if (!stat(path, &s)) | ||
117 | { | ||
118 | if (S_ISDIR(s.st_mode)) | ||
119 | { | ||
120 | ret.attribute = ATTR_DIRECTORY; | ||
121 | } | ||
122 | ret.size = s.st_size; | ||
123 | tm = localtime(&(s.st_mtime)); | ||
124 | } | ||
125 | |||
126 | if (!lstat(path, &s) && S_ISLNK(s.st_mode)) | ||
127 | { | ||
128 | ret.attribute |= ATTR_LINK; | ||
129 | } | ||
130 | |||
131 | if (tm) | ||
132 | { | ||
133 | ret.wrtdate = ((tm->tm_year - 80) << 9) | | ||
134 | ((tm->tm_mon + 1) << 5) | | ||
135 | tm->tm_mday; | ||
136 | ret.wrttime = (tm->tm_hour << 11) | | ||
137 | (tm->tm_min << 5) | | ||
138 | (tm->tm_sec >> 1); | ||
139 | } | ||
140 | |||
141 | return ret; | ||
142 | } | ||
diff --git a/firmware/target/hosted/samsungypr/dir-target.h b/firmware/target/hosted/samsungypr/dir-target.h deleted file mode 100644 index acd11d8041..0000000000 --- a/firmware/target/hosted/samsungypr/dir-target.h +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
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 | /* including unistd.h is too noisy */ | ||
27 | extern int rmdir(const char* name); | ||
28 | |||
29 | |||
30 | #define dirent_uncached dirent | ||
31 | #define DIR_UNCACHED DIR | ||
32 | #define opendir_uncached _opendir | ||
33 | #define readdir_uncached _readdir | ||
34 | #define closedir_uncached _closedir | ||
35 | #define mkdir_uncached _mkdir | ||
36 | #define rmdir_uncached rmdir | ||
37 | |||
38 | extern DIR* _opendir(const char* name); | ||
39 | extern int _mkdir(const char* name); | ||
40 | extern int _rmdir(const char* name); | ||
41 | extern int _closedir(DIR* dir); | ||
42 | extern struct dirent *_readdir(DIR* dir); | ||
43 | |||
44 | #define DIRFUNCTIONS_DEFINED | ||
45 | #define DIRENT_DEFINED | ||
46 | #define DIR_DEFINED | ||
47 | |||
48 | #endif /* __DIR_TARGET_H__ */ | ||