1 | /*
|
---|
2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * ä¸è¨è使¨©è
|
---|
7 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
8 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
9 | * å¤ã»åé
|
---|
10 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
11 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
12 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
13 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
14 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
15 | * ç¨ã§ããå½¢ã§åé
|
---|
16 | å¸ããå ´åã«ã¯ï¼åé
|
---|
17 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
18 | * è
|
---|
19 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
20 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
21 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
22 | * ç¨ã§ããªãå½¢ã§åé
|
---|
23 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
24 | * ã¨ï¼
|
---|
25 | * (a) åé
|
---|
26 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
27 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
28 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
29 | * (b) åé
|
---|
30 | å¸ã®å½¢æ
|
---|
31 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
32 | * å ±åãããã¨ï¼
|
---|
33 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
34 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
35 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
36 | 責ãããã¨ï¼
|
---|
37 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
38 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨è使¨©è
|
---|
39 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
40 | * å
|
---|
41 | 責ãããã¨ï¼
|
---|
42 | *
|
---|
43 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
44 | ã
|
---|
45 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
46 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
47 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ã
|
---|
48 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
49 | *
|
---|
50 | * @(#) $Id: io_stub.c 286 2017-05-02 15:25:33Z coas-nagasima $
|
---|
51 | */
|
---|
52 | #include <stdint.h>
|
---|
53 | #include <stdio.h>
|
---|
54 | #include <sys/unistd.h>
|
---|
55 | #include <limits.h>
|
---|
56 | #include <fcntl.h>
|
---|
57 | #include "ff.h"
|
---|
58 | #include <kernel.h>
|
---|
59 | #include <t_syslog.h>
|
---|
60 | #include <t_stdlib.h>
|
---|
61 | #include <sil.h>
|
---|
62 | #include <stdlib.h>
|
---|
63 | #include <string.h>
|
---|
64 | #include <stdio.h>
|
---|
65 | #include <setjmp.h>
|
---|
66 | #include "syssvc/syslog.h"
|
---|
67 | #include <tinet_config.h>
|
---|
68 | #include <netinet/in.h>
|
---|
69 | #include <netinet/in_itron.h>
|
---|
70 | #include <tinet_nic_defs.h>
|
---|
71 | #include <tinet_cfg.h>
|
---|
72 | #include <netinet/in_var.h>
|
---|
73 | #include <net/ethernet.h>
|
---|
74 | #include <net/if6_var.h>
|
---|
75 | #include <net/net.h>
|
---|
76 | #include <net/if_var.h>
|
---|
77 | #include <netinet/udp_var.h>
|
---|
78 | #include <ethernet_api.h>
|
---|
79 | #include "ff.h"
|
---|
80 | #include "socket_stub.h"
|
---|
81 | #include "../../../musl-1.1.12/include/_dirent.h"
|
---|
82 | #include "../../../musl-1.1.12/include/_termios.h"
|
---|
83 | #include "ntstdio.h"
|
---|
84 |
|
---|
85 | int shell_open(const char * path, int flags)
|
---|
86 | {
|
---|
87 | FRESULT res;
|
---|
88 |
|
---|
89 | struct _IO_FILE *fp = new_file_fd(0);
|
---|
90 | if (fp == NULL)
|
---|
91 | return -1;
|
---|
92 |
|
---|
93 | BYTE fmd = 0;
|
---|
94 | switch (flags & O_ACCMODE) {
|
---|
95 | case O_RDONLY:
|
---|
96 | fmd = FA_READ;
|
---|
97 | break;
|
---|
98 | case O_WRONLY:
|
---|
99 | fmd = FA_WRITE;
|
---|
100 | break;
|
---|
101 | default:
|
---|
102 | fmd = FA_READ | FA_WRITE;
|
---|
103 | break;
|
---|
104 | }
|
---|
105 | /* ãã¡ã¤ã«ã使 */
|
---|
106 | if (flags & O_CREAT) {
|
---|
107 | /* æ¢åã®å
|
---|
108 | å®¹ã¯æ¶ã */
|
---|
109 | if (flags & O_TRUNC) {
|
---|
110 | fmd |= FA_CREATE_ALWAYS;
|
---|
111 | }
|
---|
112 | /* æ°è¦ä½æã®ä¿é */
|
---|
113 | else if (flags & O_EXCL) {
|
---|
114 | fmd |= FA_CREATE_NEW;
|
---|
115 | }
|
---|
116 | else {
|
---|
117 | fmd |= FA_OPEN_ALWAYS;
|
---|
118 | }
|
---|
119 | }
|
---|
120 | /* ããå ´åã¯éã */
|
---|
121 | else {
|
---|
122 | /* æ¢åã®å
|
---|
123 | å®¹ã¯æ¶ã */
|
---|
124 | if (flags & O_TRUNC) {
|
---|
125 | fmd |= FA_CREATE_ALWAYS;
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | if ((res = f_open(&fp->file, path, fmd)) == FR_OK) {
|
---|
130 | fp->handle = fp->fd;
|
---|
131 | return fp->fd;
|
---|
132 | }
|
---|
133 |
|
---|
134 | return -1;
|
---|
135 | }
|
---|
136 |
|
---|
137 | int file_close(struct _IO_FILE *fp)
|
---|
138 | {
|
---|
139 | FRESULT res;
|
---|
140 |
|
---|
141 | if ((res = f_close(&fp->file)) == FR_OK) {
|
---|
142 | return 0;
|
---|
143 | }
|
---|
144 |
|
---|
145 | return -1;
|
---|
146 | }
|
---|
147 |
|
---|
148 | size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
|
---|
149 | {
|
---|
150 | unsigned int ret = 0;
|
---|
151 | FRESULT res;
|
---|
152 |
|
---|
153 | if ((res = f_read(&fp->file, data, len, &ret)) != FR_OK)
|
---|
154 | return -1;
|
---|
155 |
|
---|
156 | return ret;
|
---|
157 | }
|
---|
158 |
|
---|
159 | size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
|
---|
160 | {
|
---|
161 | unsigned int ret = 0;
|
---|
162 | FRESULT res;
|
---|
163 |
|
---|
164 | if ((res = f_write(&fp->file, data, len, &ret)) != FR_OK)
|
---|
165 | return -1;
|
---|
166 |
|
---|
167 | return ret;
|
---|
168 | }
|
---|
169 |
|
---|
170 | int shell_close(int fd)
|
---|
171 | {
|
---|
172 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
173 | if (fp == NULL)
|
---|
174 | return -1;
|
---|
175 |
|
---|
176 | return fp->close(fp);
|
---|
177 | }
|
---|
178 |
|
---|
179 | int shell_read(int fd, char *data, int len)
|
---|
180 | {
|
---|
181 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
182 | if (fp == NULL)
|
---|
183 | return -1;
|
---|
184 |
|
---|
185 | return fp->read(fp, (unsigned char *)data, len);
|
---|
186 | }
|
---|
187 |
|
---|
188 | int shell_write(int fd, char *data, int len)
|
---|
189 | {
|
---|
190 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
191 | if (fp == NULL)
|
---|
192 | return -1;
|
---|
193 |
|
---|
194 | return fp->write(fp, (unsigned char *)data, len);
|
---|
195 | }
|
---|
196 |
|
---|
197 | int shell_lseek(int fd, int ptr, int dir)
|
---|
198 | {
|
---|
199 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
200 | if (fp == NULL)
|
---|
201 | return -1;
|
---|
202 |
|
---|
203 | FRESULT res;
|
---|
204 | if ((res = f_seek(&fp->file, ptr, dir)) != FR_OK)
|
---|
205 | return -1;
|
---|
206 |
|
---|
207 | return fp->file.fptr;
|
---|
208 | }
|
---|
209 |
|
---|
210 | int shell_fstat(int fd, struct stat * st)
|
---|
211 | {
|
---|
212 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
213 | if (fp == NULL)
|
---|
214 | return -1;
|
---|
215 |
|
---|
216 | memset(st, 0, sizeof(*st));
|
---|
217 | st->st_mode = S_IFCHR;
|
---|
218 | //st->st_blksize = 1024;
|
---|
219 | return 0;
|
---|
220 | }
|
---|
221 |
|
---|
222 | int fsync(int fd)
|
---|
223 | {
|
---|
224 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
225 | if (fp == NULL)
|
---|
226 | return -1;
|
---|
227 | return -1;
|
---|
228 | }
|
---|
229 |
|
---|
230 | int ftruncate(int fd, off_t length)
|
---|
231 | {
|
---|
232 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
233 | if (fp == NULL)
|
---|
234 | return -1;
|
---|
235 |
|
---|
236 | FRESULT res;
|
---|
237 | if ((res = f_truncate(&fp->file)) != FR_OK)
|
---|
238 | return -1;
|
---|
239 |
|
---|
240 | return 0;
|
---|
241 | }
|
---|
242 |
|
---|
243 | int ioctl(int fd, int request, va_list ap)
|
---|
244 | {
|
---|
245 | struct _IO_FILE *fp = fd_to_fp(fd);
|
---|
246 | if (fp == NULL)
|
---|
247 | return -1;
|
---|
248 | return -1;
|
---|
249 | }
|
---|
250 |
|
---|
251 | int tcgetattr(int fd, struct termios *termios)
|
---|
252 | {
|
---|
253 | extern ntstdio_t ntstdio;
|
---|
254 |
|
---|
255 | if (fd == STDIN_FILENO) {
|
---|
256 | memset(termios, 0, sizeof(*termios));
|
---|
257 |
|
---|
258 | if (ntstdio.option & NTSTDIO_OPTION_LINE_ECHO) {
|
---|
259 | termios->c_lflag |= ECHO;
|
---|
260 | }
|
---|
261 | else {
|
---|
262 | termios->c_lflag &= ~ECHO;
|
---|
263 | }
|
---|
264 | if (ntstdio.option & NTSTDIO_OPTION_CANON) {
|
---|
265 | termios->c_lflag |= ICANON;
|
---|
266 | }
|
---|
267 | else {
|
---|
268 | termios->c_lflag &= ~ICANON;
|
---|
269 | }
|
---|
270 | if (ntstdio.option & NTSTDIO_OPTION_LF_CR) {
|
---|
271 | termios->c_iflag |= INLCR;
|
---|
272 | }
|
---|
273 | else {
|
---|
274 | termios->c_iflag &= ~INLCR;
|
---|
275 | }
|
---|
276 | if (ntstdio.option & NTSTDIO_OPTION_LF_CRLF) {
|
---|
277 | termios->c_oflag |= ONLCR;
|
---|
278 | }
|
---|
279 | else {
|
---|
280 | termios->c_oflag &= ~ONLCR;
|
---|
281 | }
|
---|
282 | return 0;
|
---|
283 | }
|
---|
284 | abort();
|
---|
285 | return 0;
|
---|
286 | }
|
---|
287 |
|
---|
288 | int tcsetattr(int fd, int optional_actions, const struct termios *termios)
|
---|
289 | {
|
---|
290 | extern ntstdio_t ntstdio;
|
---|
291 |
|
---|
292 | if ((fd == STDIN_FILENO) && (optional_actions == TCSANOW)) {
|
---|
293 | if (termios->c_lflag & ECHO) {
|
---|
294 | ntstdio.option |= NTSTDIO_OPTION_LINE_ECHO;
|
---|
295 | }
|
---|
296 | else {
|
---|
297 | ntstdio.option &= ~NTSTDIO_OPTION_LINE_ECHO;
|
---|
298 | }
|
---|
299 | if (termios->c_lflag & ICANON) {
|
---|
300 | ntstdio.option |= NTSTDIO_OPTION_CANON;
|
---|
301 | }
|
---|
302 | else {
|
---|
303 | ntstdio.option &= ~NTSTDIO_OPTION_CANON;
|
---|
304 | }
|
---|
305 | if (termios->c_iflag & INLCR) {
|
---|
306 | ntstdio.option |= NTSTDIO_OPTION_LF_CR;
|
---|
307 | }
|
---|
308 | else{
|
---|
309 | ntstdio.option &= ~NTSTDIO_OPTION_LF_CR;
|
---|
310 | }
|
---|
311 | if (termios->c_oflag & ONLCR) {
|
---|
312 | ntstdio.option |= NTSTDIO_OPTION_LF_CRLF;
|
---|
313 | }
|
---|
314 | else {
|
---|
315 | ntstdio.option &= ~NTSTDIO_OPTION_LF_CRLF;
|
---|
316 | }
|
---|
317 | return 0;
|
---|
318 | }
|
---|
319 | abort();
|
---|
320 | return 0;
|
---|
321 | }
|
---|
322 |
|
---|
323 | int shell_stat(const char *path, struct stat *st)
|
---|
324 | {
|
---|
325 | FILINFO fi;
|
---|
326 | FRESULT ret;
|
---|
327 | #if _USE_LFN
|
---|
328 | static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */
|
---|
329 | fi.lfname = lfn;
|
---|
330 | fi.lfsize = sizeof lfn;
|
---|
331 | #endif
|
---|
332 | if (strcmp(path, ".") == 0) {
|
---|
333 | char cwd[_MAX_LFN];
|
---|
334 | if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) {
|
---|
335 | return -1;
|
---|
336 | }
|
---|
337 | int l = strlen(cwd);
|
---|
338 | // ã«ã¼ããã£ã¬ã¯ããªã®å ´å
|
---|
339 | if (cwd[l - 2] == ':' && cwd[l - 1] == '/') {
|
---|
340 | st->st_size = 0;
|
---|
341 | st->st_mtime = 0;
|
---|
342 | st->st_mode = S_IFDIR;
|
---|
343 | return 0;
|
---|
344 | }
|
---|
345 | if ((ret = f_stat(cwd, &fi)) != FR_OK) {
|
---|
346 | return -1;
|
---|
347 | }
|
---|
348 | }
|
---|
349 | else if ((ret = f_stat(path, &fi)) != FR_OK) {
|
---|
350 | return -1;
|
---|
351 | }
|
---|
352 |
|
---|
353 | st->st_size = fi.fsize;
|
---|
354 | st->st_mtime = fi.fdate + fi.ftime;
|
---|
355 | st->st_mode = (S_IRUSR | S_IRGRP | S_IROTH);
|
---|
356 | st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
|
---|
357 | st->st_mode |= (fi.fattrib & (AM_DIR | AM_VOL)) ? S_IFDIR : S_IFREG;
|
---|
358 |
|
---|
359 | return 0;
|
---|
360 | }
|
---|
361 |
|
---|
362 | int shell_link(void)
|
---|
363 | {
|
---|
364 | return -1;
|
---|
365 | }
|
---|
366 |
|
---|
367 | int shell_unlink(const char *path)
|
---|
368 | {
|
---|
369 | FRESULT res;
|
---|
370 |
|
---|
371 | if ((res = f_unlink(path)) != FR_OK)
|
---|
372 | return -1;
|
---|
373 |
|
---|
374 | return 0;
|
---|
375 | }
|
---|
376 |
|
---|
377 | int rmdir(const char *path)
|
---|
378 | {
|
---|
379 | FRESULT res;
|
---|
380 |
|
---|
381 | if ((res = f_unlink(path)) != FR_OK)
|
---|
382 | return -1;
|
---|
383 |
|
---|
384 | return 0;
|
---|
385 | }
|
---|
386 |
|
---|
387 | int shell_rename(const char *oldpath, const char *newpath)
|
---|
388 | {
|
---|
389 | FRESULT res;
|
---|
390 |
|
---|
391 | if ((res = f_rename(oldpath, newpath)) != FR_OK)
|
---|
392 | return -1;
|
---|
393 | return 0;
|
---|
394 | }
|
---|
395 |
|
---|
396 | int mkdir(const char *path, mode_t mode)
|
---|
397 | {
|
---|
398 | FRESULT res;
|
---|
399 |
|
---|
400 | if ((res = f_mkdir(path)) != FR_OK)
|
---|
401 | return -1;
|
---|
402 |
|
---|
403 | BYTE attr = 0;
|
---|
404 | BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
|
---|
405 |
|
---|
406 | if(mode & S_IREAD) {
|
---|
407 | if((mode & S_IWRITE) == 0) {
|
---|
408 | attr |= AM_RDO;
|
---|
409 | }
|
---|
410 | }
|
---|
411 | else {
|
---|
412 | attr |= AM_SYS;
|
---|
413 | }
|
---|
414 |
|
---|
415 | if((res = f_chmod(path, attr, mask)) != FR_OK) {
|
---|
416 | return -1;
|
---|
417 | }
|
---|
418 |
|
---|
419 | return 0;
|
---|
420 | }
|
---|
421 |
|
---|
422 | int chmod(const char *path, mode_t mode)
|
---|
423 | {
|
---|
424 | FRESULT ret;
|
---|
425 | BYTE attr = 0;
|
---|
426 | BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
|
---|
427 |
|
---|
428 | if(mode & S_IREAD) {
|
---|
429 | if((mode & S_IWRITE) == 0) {
|
---|
430 | attr |= AM_RDO;
|
---|
431 | }
|
---|
432 | }
|
---|
433 | else {
|
---|
434 | attr |= AM_SYS;
|
---|
435 | }
|
---|
436 |
|
---|
437 | if((ret = f_chmod(path, attr, mask)) != FR_OK) {
|
---|
438 | return -1;
|
---|
439 | }
|
---|
440 |
|
---|
441 | return 0;
|
---|
442 | }
|
---|
443 |
|
---|
444 | char *getcwd(char *buf, size_t size)
|
---|
445 | {
|
---|
446 | FRESULT ret;
|
---|
447 | if((ret = f_getcwd(buf, size)) != FR_OK) {
|
---|
448 | return NULL;
|
---|
449 | }
|
---|
450 |
|
---|
451 | return buf;
|
---|
452 | }
|
---|
453 |
|
---|
454 | int chdir(const char *path)
|
---|
455 | {
|
---|
456 | FRESULT ret;
|
---|
457 | if ((ret = f_chdir(path)) != FR_OK) {
|
---|
458 | return -1;
|
---|
459 | }
|
---|
460 |
|
---|
461 | return 0;
|
---|
462 | }
|
---|
463 |
|
---|
464 | int chroot(const char *path)
|
---|
465 | {
|
---|
466 | abort();
|
---|
467 | return -1;
|
---|
468 | }
|
---|
469 |
|
---|
470 | DIR *opendir(const char *path)
|
---|
471 | {
|
---|
472 | DIR *dir = malloc(sizeof(DIR) + sizeof(struct dirent));
|
---|
473 | FRESULT ret;
|
---|
474 | if ((ret = f_opendir(dir, path)) != FR_OK) {
|
---|
475 | free(dir);
|
---|
476 | return NULL;
|
---|
477 | }
|
---|
478 |
|
---|
479 | dir->dirent = &dir[1];
|
---|
480 | return dir;
|
---|
481 | }
|
---|
482 |
|
---|
483 | int closedir(DIR *dir)
|
---|
484 | {
|
---|
485 | FRESULT ret;
|
---|
486 | if ((ret = f_closedir(dir)) != FR_OK) {
|
---|
487 | free(dir);
|
---|
488 | return -1;
|
---|
489 | }
|
---|
490 |
|
---|
491 | free(dir);
|
---|
492 | return 0;
|
---|
493 | }
|
---|
494 |
|
---|
495 | struct dirent *readdir(DIR *dir)
|
---|
496 | {
|
---|
497 | struct dirent *de = dir->dirent;
|
---|
498 | FILINFO fno;
|
---|
499 | #if _USE_LFN
|
---|
500 | static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */
|
---|
501 | fno.lfname = lfn;
|
---|
502 | fno.lfsize = sizeof lfn;
|
---|
503 | #endif
|
---|
504 | FRESULT ret;
|
---|
505 | if ((ret = f_readdir(dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
|
---|
506 | return NULL;
|
---|
507 | }
|
---|
508 |
|
---|
509 | memset(de, 0, sizeof(*de));
|
---|
510 | #if _USE_LFN
|
---|
511 | strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
|
---|
512 | #else
|
---|
513 | strlcpy(de->d_name, fno.fname, sizeof(de->d_name));
|
---|
514 | #endif
|
---|
515 |
|
---|
516 | return de;
|
---|
517 | }
|
---|
518 |
|
---|
519 | void rewinddir(DIR *dir)
|
---|
520 | {
|
---|
521 | FRESULT ret;
|
---|
522 | if ((ret = f_rewinddir(dir)) != FR_OK) {
|
---|
523 | return;
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | void seekdir(DIR *dir, long pos)
|
---|
528 | {
|
---|
529 | abort();
|
---|
530 | }
|
---|
531 |
|
---|
532 | long telldir(DIR *dir)
|
---|
533 | {
|
---|
534 | abort();
|
---|
535 | return 0;
|
---|
536 | }
|
---|
537 |
|
---|
538 | int shell_getpid(int n)
|
---|
539 | {
|
---|
540 | return 1;
|
---|
541 | }
|
---|