📄 fat.lst
字号:
246 2 ((Byte*)&fat_ptr_data)[2] = fat_buf_sector[18];
247 2 ((Byte*)&fat_ptr_data)[1] = 0;
248 2 ((Byte*)&fat_ptr_data)[0] = 0;
249 2 fat_ptr_data = (fat_ptr_data * DIR_SIZE) / SECTOR_SIZE;
250 2 /* read number of sector in partition (<32Mb) */
251 2 ((Byte*)&fat_nb_sector)[3] = fat_buf_sector[19];
252 2 ((Byte*)&fat_nb_sector)[2] = fat_buf_sector[20];
253 2 ((Byte*)&fat_nb_sector)[1] = 0x00;
254 2 ((Byte*)&fat_nb_sector)[0] = 0x00;
255 2 /* compute root directory sector address */
256 2 ((Byte*)&fat_fat_size)[1] = fat_buf_sector[22];
257 2 ((Byte*)&fat_fat_size)[0] = fat_buf_sector[23];
258 2
259 2 fat_ptr_rdir = fat_buf_sector[16] * fat_fat_size;
260 2 fat_ptr_rdir += fat_ptr_fats;
261 2
262 2 /* read number of sector in partition (>32Mb) */
263 2 if (!fat_nb_sector)
264 2 {
265 3 ((Byte*)&fat_nb_sector)[3] = fat_buf_sector[32];
266 3 ((Byte*)&fat_nb_sector)[2] = fat_buf_sector[33];
267 3 ((Byte*)&fat_nb_sector)[1] = fat_buf_sector[34];
268 3 ((Byte*)&fat_nb_sector)[0] = fat_buf_sector[35];
269 3 }
270 2 total_capacity = fat_nb_sector;
271 2
272 2 fat_count_of_clusters = (fat_nb_sector - (1 + (fat_buf_sector[16] * fat_fat_size) + fat_ptr_data))
273 2 / fat_cluster_size;
274 2 if (fat_count_of_clusters <= MAX_CLUSTERS12)
275 2 {
276 3 fat_is_fat16 = FALSE;
277 3 fat_is_fat32 = FALSE;
278 3 }
279 2 else if (fat_count_of_clusters <= MAX_CLUSTERS16)
280 2 {
281 3 fat_is_fat16 = TRUE;
282 3 fat_is_fat32 = FALSE;
283 3 }
284 2 else
285 2 {
286 3 fat_is_fat16 = FALSE;
287 3 fat_is_fat32 = TRUE;
288 3 }
289 2 /* else is FAT32 not supported */
290 2
291 2 /* compute data sector address */
292 2 fat_ptr_data += fat_ptr_rdir;
293 2 /* check partition signature */
294 2 if ((fat_buf_sector[510] != LOW(BR_SIGNATURE)) &&
295 2 (fat_buf_sector[511] != HIGH(BR_SIGNATURE)))
296 2 {
297 3 return KO;
298 3 }
299 2
300 2 return OK;
301 2 }
302 1 else
C51 COMPILER V7.50 FAT 02/16/2009 09:59:55 PAGE 6
303 1 { /* low level error */
304 2 return KO;
305 2 }
306 1 }
307
308
309 /*F**************************************************************************
310 * NAME: fat_get_dir_entry
311 *----------------------------------------------------------------------------
312 * PARAMS:
313 * entry: directory entry structure
314 *
315 * return:
316 *----------------------------------------------------------------------------
317 * PURPOSE:
318 * Get from directory all information about a directory or file entry
319 *----------------------------------------------------------------------------
320 * EXAMPLE:
321 *----------------------------------------------------------------------------
322 * NOTE:
323 * This function reads directly datas from sectors
324 * It automaticaly computes difference between LFN and normal entries
325 *----------------------------------------------------------------------------
326 * REQUIREMENTS:
327 *****************************************************************************/
328 void fat_get_dir_entry (fat_st_dir_entry xdata *entry)
329 {
330 1 bit exit_flag = FALSE;
331 1 bit lfn_entry_found = FALSE;
332 1 Byte i;
333 1
334 1 /* clear the name buffer */
335 1 for (i = MAX_FILENAME_LEN; i != 0; lfn_name[--i] = '\0');
336 1 for (i = 0; i < 11; i++)
337 1 song_name[i] = 0 ;
338 1
339 1 while (!exit_flag)
340 1 /* loop while the entry is not a normal one. */
341 1 {
342 2 /* read the directory entry */
343 2 if (dir_is_root == TRUE)
344 2 { /* root dir is linear -> Hard_read_byte() */
345 3 for (i = 0; i < DIR_SIZE; i++)
346 3 gl_buffer[i] = Hard_read_byte();
347 3 }
348 2 else
349 2 { /* subdir can be fragmented -> dgetc() */
350 3 for (i = 0; i < DIR_SIZE; i++)
351 3 gl_buffer[i] = fat_dgetc();
352 3 }
353 2
354 2 /*computes gathered data
355 2 /* check if we have a LFN entry */
356 2 if (gl_buffer[11] != ATTR_LFN_ENTRY)
357 2 {
358 3 if (!lfn_entry_found)
359 3 {
360 4 /* true DOS 8.3 entry format */
361 4 for (i = 0; i < 8; i++)
362 4 {
363 5 lfn_name[i] = gl_buffer[i];
364 5
C51 COMPILER V7.50 FAT 02/16/2009 09:59:55 PAGE 7
365 5 if (lfn_name[i] == ' ')
366 5 { /* space is end of name */
367 6 break;
368 6 }
369 5 }
370 4 /* append extension */
371 4 lfn_name[i++] = '.';
372 4 lfn_name[i++] = gl_buffer[8];
373 4 lfn_name[i++] = gl_buffer[9];
374 4 lfn_name[i++] = gl_buffer[10];
375 4
376 4 for (; i != 14; i++)
377 4 {
378 5 lfn_name[i] = ' '; /* append spaces for display reason */
379 5 }
380 4 lfn_name[i] = '\0'; /* end of string */
381 4 }
382 3
383 3 else
384 3 { /* LFN name treatment */
385 4 i = 0;
386 4 /* search for the end of the string */
387 4 while (lfn_name[i] != '\0')
388 4 {
389 5 i++;
390 5 }
391 4 if (i <= 14)
392 4 { /* append spaces for display reason (no scrolling) */
393 5 while (i != 14)
394 5 {
395 6 lfn_name[i++] = ' ';
396 6 }
397 5 }
398 4 else
399 4 { /* append beginning of name to ease scrolling display */
400 5 lfn_name[i++] = ' ';
401 5 lfn_name[i++] = ' ';
402 5 lfn_name[i++] = lfn_name[0];
403 5 lfn_name[i++] = lfn_name[1];
404 5 lfn_name[i++] = lfn_name[2];
405 5 lfn_name[i++] = lfn_name[3];
406 5 lfn_name[i++] = lfn_name[4];
407 5 lfn_name[i++] = lfn_name[5];
408 5 lfn_name[i++] = lfn_name[6];
409 5 lfn_name[i++] = lfn_name[7];
410 5 lfn_name[i++] = lfn_name[8];
411 5 lfn_name[i++] = lfn_name[9];
412 5 lfn_name[i++] = lfn_name[10];
413 5 lfn_name[i++] = lfn_name[11];
414 5 lfn_name[i++] = lfn_name[12];
415 5 }
416 4 lfn_name[i] = '\0'; /* end of name */
417 4 }
418 3
419 3 /* store extension */
420 3 ext[0]= gl_buffer[8];
421 3 ext[1]= gl_buffer[9];
422 3 ext[2]= gl_buffer[10];
423 3
424 3 /* standard computing for normal entry */
425 3 entry->attributes = gl_buffer[11];
426 3 entry->start_cluster = gl_buffer[26];
C51 COMPILER V7.50 FAT 02/16/2009 09:59:55 PAGE 8
427 3 entry->start_cluster += ((Uint16) gl_buffer[27]) << 8;
428 3 entry->size.b[3] = gl_buffer[28];
429 3 entry->size.b[2] = gl_buffer[29];
430 3 entry->size.b[1] = gl_buffer[30];
431 3 entry->size.b[0] = gl_buffer[31];
432 3 /* now it's time to stop */
433 3 exit_flag = TRUE;
434 3 }
435 2 else
436 2 { /* LFN entry format */
437 3 lfn_entry_found = TRUE; /* a 8.3 name will follow */
438 3
439 3 if ((gl_buffer[0] & LFN_SEQ_MASK) <= MAX_LFN_ENTRIES)
440 3 { /* Maximum number of entries for LFN? */
441 4 for (i=0; i<5; i++)
442 4 {
443 5 song_name[i] = gl_buffer[2*i + 1] + gl_buffer[2*i + 1 + 1]*256;
444 5 lfn_name[i + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 1];
445 5 }
446 4 for (i=0; i<6; i++)
447 4 {
448 5 song_name[i + 5] = gl_buffer[2*i + 14] + gl_buffer[2*i + 14 + 1]*256;
449 5 lfn_name[i + 5 + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 14];
450 5 }
451 4 for (i=0; i<2; i++)
452 4 {
453 5 lfn_name[i + 11 + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 28];
454 5 }
455 4 }
456 3 }
457 2 }
458 1 Hard_read_close(); /* close physical read */
459 1 }
460
461
462 /*F**************************************************************************
463 * NAME: fat_get_dir_file_list
464 *----------------------------------------------------------------------------
465 * PARAMS:
466 * id: file extension to select
467 *
468 * return:
469 *----------------------------------------------------------------------------
470 * PURPOSE:
471 * Construct the file directory list
472 *----------------------------------------------------------------------------
473 * EXAMPLE:
474 *----------------------------------------------------------------------------
475 * NOTE:
476 * The value are relative position with the previous file.
477 * Call to this function assume that the dir fragment chain has been created
478 *----------------------------------------------------------------------------
479 * REQUIREMENTS:
480 * Maximum of 256 entries between 2 authorized file (id extension)
481 * because the relative position is stored on one byte.
482 * To allow more than 256 entries (-> 32768), change type of
483 * fat_dir_entry_list[] from Byte to Uint16 (no overflow management)
484 * and change MAX_DIRECTORY_GAP_FILE from 255 to 32767
485 *****************************************************************************/
486 void fat_get_dir_file_list (Byte id)
487 {
488 1 Uint16 index; /* chain index */
C51 COMPILER V7.50 FAT 02/16/2009 09:59:55 PAGE 9
489 1 Uint16 counter_entry; /* entry counter: 0..MAX_DIRECTORY_FILE */
490 1 Uint16 entry_pos; /* relative entry position */
491 1 Uint16 entry_pos_saved; /* used when the file is not the id etension */
492 1 Byte i;
493 1
494 1 index = 0;
495 1 fat_dir_list_last = 0;
496 1 counter_entry = 0;
497 1 entry_pos = 0;
498 1 fat_dir_start_sect = fat_dir_current_sect;
499 1 fat_dir_current_offs = 0;
500 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -