📄 tff.lst
字号:
230 1
231 1
232 1 memset(fs->win, 0, 512);
233 1 if (disk_read(fs->win, sect, 1) == RES_OK) { /* Load boot record */
234 2 if (LD_WORD(&(fs->win[510])) == 0xAA55) { /* Is it valid? */
235 3 if (!memcmp(&(fs->win[0x36]), &fatsign[0], 5))
236 3 return FS_FAT12;
237 3 if (!memcmp(&(fs->win[0x36]), &fatsign[5], 5))
238 3 return FS_FAT16;
239 3 }
240 2 }
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 5
241 1 return 0;
242 1 }
243
244
245
246 /*--------------------------------*/
247 /* Move Directory Pointer to Next */
248
249 static
250 BOOL next_dir_entry (
251 DIR *scan /* Pointer to directory object */
252 )
253 {
254 1 WORD clust;
255 1 WORD idx;
256 1 FATFS *fs = FatFs;
257 1
258 1
259 1 idx = scan->index + 1;
260 1 if ((idx & 15) == 0) { /* Table sector changed? */
261 2 scan->sect++; /* Next sector */
262 2 if (!scan->clust) { /* In static table */
263 3 if (idx >= fs->n_rootdir) return FALSE; /* Reached to end of table */
264 3 } else { /* In dynamic table */
265 3 if (((idx / 16) & (fs->sects_clust - 1)) == 0) { /* Cluster changed? */
266 4 clust = get_cluster(scan->clust); /* Get next cluster */
267 4 if ((clust >= fs->max_clust) || (clust < 2)) /* Reached to end of table */
268 4 return FALSE;
269 4 scan->clust = clust; /* Initialize for new cluster */
270 4 scan->sect = clust2sect(clust);
271 4 }
272 3 }
273 2 }
274 1 scan->index = idx; /* Lower 4 bit of scan->index indicates offset in scan->sect */
275 1 return TRUE;
276 1 }
277
278
279
280 /*--------------------------------------*/
281 /* Get File Status from Directory Entry */
282
283 #ifndef _FS_MINIMUM
284
285 static
286 void get_fileinfo (
287 FILINFO *finfo, /* Ptr to Store the File Information */
288 const BYTE *dir /* Ptr to the Directory Entry */
289 )
290 {
291 1 BYTE n, c, a;
292 1 char *p;
293 1
294 1
295 1 p = &(finfo->fname[0]);
296 1 a = *(dir+12); /* NT flag */
297 1 for (n = 0; n < 8; n++) { /* Convert file name (body) */
298 2 c = *(dir+n);
299 2 if (c == ' ') break;
300 2 if (c == 0x05) c = 0xE5;
301 2 if ((a & 0x08) && (c >= 'A') && (c <= 'Z')) c += 0x20;
302 2 *p++ = c;
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 6
303 2 }
304 1 if (*(dir+8) != ' ') { /* Convert file name (extension) */
305 2 *p++ = '.';
306 2 for (n = 8; n < 11; n++) {
307 3 c = *(dir+n);
308 3 if (c == ' ') break;
309 3 if ((a & 0x10) && (c >= 'A') && (c <= 'Z')) c += 0x20;
310 3 *p++ = c;
311 3 }
312 2 }
313 1 *p = '\0';
314 1
315 1 finfo->fattrib = *(dir+11); /* Attribute */
316 1 finfo->fsize = LD_DWORD(dir+28); /* Size */
317 1 finfo->fdate = LD_WORD(dir+24); /* Date */
318 1 finfo->ftime = LD_WORD(dir+22); /* Time */
319 1 }
320
321 #endif /* _FS_READONLY */
322
323
324 /*-----------------------------------------------------*/
325 /* Pick a Paragraph and Create Name in Directory Entry */
326
327 static
328 char make_dirfile (
329 const char **path, /* Pointer to the file path pointer */
330 char *dirname /* Pointer to directory name buffer {Name(8), Ext(3), NT flag(1)} */
331 )
332 {
333 1 BYTE n, t, c, a, b;
334 1
335 1
336 1 memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
337 1 a = 0; b = 0x18; /* NT flag */
338 1 n = 0; t = 8;
339 1 for (;;) {
340 2 c = *(*path)++;
341 2 if (c <= ' ') c = 0;
342 2 if ((c == 0) || (c == '/')) { /* Reached to end of str or directory separator */
343 3 if (n == 0) break;
344 3 dirname[11] = a & b; return c;
345 3 }
346 2 if (c == '.') {
347 3 if(!(a & 1) && (n >= 1) && (n <= 8)) { /* Enter extension part */
348 4 n = 8; t = 11; continue;
349 4 }
350 3 break;
351 3 }
352 2 #ifdef _USE_SJIS
353 2 if (((c >= 0x81) && (c <= 0x9F)) || /* Accept S-JIS code */
354 2 ((c >= 0xE0) && (c <= 0xFC))) {
355 3 if ((n == 0) && (c == 0xE5)) /* Change heading \xE5 to \x05 */
356 3 c = 0x05;
357 3 a ^= 1; goto md_l2;
358 3 }
359 2 if ((c >= 0x7F) && (c <= 0x80)) break; /* Reject \x7F \x80 */
360 2 #else
if (c >= 0x7F) goto md_l1; /* Accept \x7F-0xFF */
#endif
363 2 if (c == '"') break; /* Reject " */
364 2 if (c <= ')') goto md_l1; /* Accept ! # $ % & ' ( ) */
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 7
365 2 if (c <= ',') break; /* Reject * + , */
366 2 if (c <= '9') goto md_l1; /* Accept - 0-9 */
367 2 if (c <= '?') break; /* Reject : ; < = > ? */
368 2 if (!(a & 1)) { /* These checks are not applied to S-JIS 2nd byte */
369 3 if (c == '|') break; /* Reject | */
370 3 if ((c >= '[') && (c <= ']')) break;/* Reject [ \ ] */
371 3 if ((c >= 'A') && (c <= 'Z'))
372 3 (t == 8) ? (b &= ~0x08) : (b &= ~0x10);
373 3 if ((c >= 'a') && (c <= 'z')) { /* Convert to upper case */
374 4 c -= 0x20;
375 4 (t == 8) ? (a |= 0x08) : (a |= 0x10);
376 4 }
377 3 }
378 2 md_l1:
379 2 a &= ~1;
380 2 md_l2:
381 2 if (n >= t) break;
382 2 dirname[n++] = c;
383 2 }
384 1 return 1;
385 1 }
386
387
388
389 /*-------------------*/
390 /* Trace a File Path */
391
392 static
393 FRESULT trace_path (
394 DIR *scan, /* Pointer to directory object to return last directory */
395 char *fn, /* Pointer to last segment name to return */
396 const char *path, /* Full-path string to trace a file or directory */
397 BYTE **dir /* Directory pointer in Win[] to retutn */
398 )
399 {
400 1 WORD clust;
401 1 char ds;
402 1 BYTE *dptr = NULL;
403 1 FATFS *fs = FatFs;
404 1
405 1 /* Initialize directory object */
406 1 clust = fs->dirbase;
407 1 scan->clust = scan->sclust = 0;
408 1 scan->sect = clust;
409 1 scan->index = 0;
410 1
411 1 while ((*path == ' ') || (*path == '/')) path++; /* Skip leading spaces */
412 1 if ((BYTE)*path < ' ') { /* Null path means the root directory */
413 2 *dir = NULL; return FR_OK;
414 2 }
415 1
416 1 for (;;) {
417 2 ds = make_dirfile(&path, fn); /* Get a paragraph into fn[] */
418 2 if (ds == 1) return FR_INVALID_NAME;
419 2 for (;;) {
420 3 if (!move_window(scan->sect)) return FR_RW_ERROR;
421 3 dptr = &(fs->win[(scan->index & 15) * 32]); /* Pointer to the directory entry */
422 3 if (*dptr == 0) /* Has it reached to end of dir? */
423 3 return !ds ? FR_NO_FILE : FR_NO_PATH;
424 3 if ( (*dptr != 0xE5) /* Matched? */
425 3 && !(*(dptr+11) & AM_VOL)
426 3 && !memcmp(dptr, fn, 8+3) ) break;
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 8
427 3 if (!next_dir_entry(scan)) /* Next directory pointer */
428 3 return !ds ? FR_NO_FILE : FR_NO_PATH;
429 3 }
430 2 if (!ds) { *dir = dptr; return FR_OK; } /* Matched with end of path */
431 2 if (!(*(dptr+11) & AM_DIR)) return FR_NO_PATH; /* Cannot trace because it is a file */
432 2 clust = LD_WORD(dptr+26); /* Get cluster# of the directory */
433 2 scan->clust = scan->sclust = clust; /* Restart scan with the new directory */
434 2 scan->sect = clust2sect(clust);
435 2 scan->index = 0;
436 2 }
437 1 }
438
439
440
441 /*---------------------------*/
442 /* Reserve a Directory Entry */
443
444 #ifndef _FS_READONLY
445 static
446 BYTE* reserve_direntry (
447 DIR *scan /* Target directory to create new entry */
448 )
449 {
450 1 WORD clust;
451 1 DWORD sector;
452 1 BYTE c, n, *dptr;
453 1 FATFS *fs = FatFs;
454 1
455 1
456 1 /* Re-initialize directory object */
457 1 clust = scan->sclust;
458 1 if (clust) { /* Dyanmic directory table */
459 2 scan->clust = clust;
460 2 scan->sect = clust2sect(clust);
461 2 } else { /* Static directory table */
462 2 scan->sect = fs->dirbase;
463 2 }
464 1 scan->index = 0;
465 1
466 1 do {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -