簡易NC通信端末の製作
Revisão | 4d90248a84c2db68af0b77ded25c837ce312d8de (tree) |
---|---|
Hora | 2012-06-04 18:56:37 |
Autor | KAZ.Imamura (Office) <kaz@tekk...> |
Commiter | KAZ.Imamura (Office) |
Merge branch 'master' of git.pf.sourceforge.jp:/gitroot/t/te/tekken_boss/H8_first_build
Conflicts:
tool/fat_test.c
@@ -7,7 +7,13 @@ | ||
7 | 7 | #include <stdlib.h> |
8 | 8 | #include <error.h> |
9 | 9 | |
10 | +<<<<<<< HEAD | |
10 | 11 | #define MAX_FILE_IN_DIR 128 |
12 | +======= | |
13 | +void read_BPB( int fd ); | |
14 | +void read_DIR( int fd ); | |
15 | +unsigned long Cluster2Sector( unsigned long cluster ); | |
16 | +>>>>>>> 5d25b5c54834a18f08f4fba3c3a1bb32974c16f2 | |
11 | 17 | |
12 | 18 | typedef struct { |
13 | 19 | char Name[13]; |
@@ -45,6 +51,7 @@ struct BPB_information { | ||
45 | 51 | // Only for FAT32 |
46 | 52 | unsigned long FATSz32; // Offset 36 Size 2 FAT size for FAT32 |
47 | 53 | unsigned long RootClus; // Offset 44 Size 4 |
54 | +<<<<<<< HEAD | |
48 | 55 | }; |
49 | 56 | struct BPB_information BPB_info; |
50 | 57 |
@@ -60,6 +67,18 @@ enum { | ||
60 | 67 | }; |
61 | 68 | |
62 | 69 | DIR_ENTRY dir_entry; |
70 | +======= | |
71 | +}; | |
72 | +struct BPB_information BPB_info; | |
73 | + | |
74 | + | |
75 | +struct DIR_Entry { | |
76 | + char Name[13]; | |
77 | + unsigned long FirstCluster; | |
78 | + unsigned char Attributes; | |
79 | +}; | |
80 | +struct DIR_Entry dir_info[128]; | |
81 | +>>>>>>> 5d25b5c54834a18f08f4fba3c3a1bb32974c16f2 | |
63 | 82 | |
64 | 83 | unsigned char buf[512]; |
65 | 84 |
@@ -70,11 +89,15 @@ unsigned long TotalSect; | ||
70 | 89 | unsigned long DataSectors; |
71 | 90 | unsigned long CountofClusters; |
72 | 91 | |
92 | +<<<<<<< HEAD | |
73 | 93 | unsigned long CurrentWindowSector; |
94 | +======= | |
95 | +>>>>>>> 5d25b5c54834a18f08f4fba3c3a1bb32974c16f2 | |
74 | 96 | unsigned long CurrentDirCluster; |
75 | 97 | unsigned int TotalFileNum; |
76 | 98 | unsigned char IsFAT32; |
77 | 99 | |
100 | +<<<<<<< HEAD | |
78 | 101 | void read_DIR( int fd ) { |
79 | 102 | unsigned long SearchSector, SearchCluster; |
80 | 103 | int i,a; |
@@ -86,6 +109,19 @@ void read_DIR( int fd ) { | ||
86 | 109 | else if ( res == DIR_ENTRY_READY ) TotalFileNum++; |
87 | 110 | |
88 | 111 | next_dir_entry(fd, &dir_entry); |
112 | +======= | |
113 | +main (int argc, char *argv[] ) { | |
114 | + int fd, i; | |
115 | + | |
116 | + // Global initialize | |
117 | + CurrentDirCluster = 0; | |
118 | + TotalFileNum = 0; | |
119 | + IsFAT32 = 0; | |
120 | + | |
121 | + if( argc == 1 ) { | |
122 | + printf("No file is specified.\r\n"); | |
123 | + return; | |
124 | +>>>>>>> 5d25b5c54834a18f08f4fba3c3a1bb32974c16f2 | |
89 | 125 | } |
90 | 126 | } |
91 | 127 |
@@ -236,6 +272,7 @@ int GetNextCluster(int fd, unsigned long *p_cluster ) { | ||
236 | 272 | return; |
237 | 273 | } |
238 | 274 | |
275 | +<<<<<<< HEAD | |
239 | 276 | if(IsFAT32) { |
240 | 277 | EntryVal = *(unsigned long*) &buf[FATEntOffset] & 0x0FFFFFFF; |
241 | 278 | } else { |
@@ -258,6 +295,10 @@ int GetNextCluster(int fd, unsigned long *p_cluster ) { | ||
258 | 295 | printf("[GetNextCluster] it should be reserved cluster.\r\n"); |
259 | 296 | return -1; |
260 | 297 | } |
298 | +======= | |
299 | + read_BPB(fd); | |
300 | + read_DIR(fd); | |
301 | +>>>>>>> 5d25b5c54834a18f08f4fba3c3a1bb32974c16f2 | |
261 | 302 | } |
262 | 303 | |
263 | 304 |
@@ -369,6 +410,7 @@ void read_BPB(int fd) { | ||
369 | 410 | IsFAT32 = 1; |
370 | 411 | } |
371 | 412 | } |
413 | +<<<<<<< HEAD | |
372 | 414 | |
373 | 415 | // ------------------------------------------------------ |
374 | 416 | // Main function |
@@ -396,4 +438,97 @@ main (int argc, char *argv[] ) { | ||
396 | 438 | |
397 | 439 | init_dir_entry(fd, (P_DIR_ENTRY) &dir_entry, 0L ); // Set to root |
398 | 440 | read_DIR(fd); |
441 | +======= | |
442 | + | |
443 | + | |
444 | +void read_DIR( int fd ) { | |
445 | + unsigned long SearchSector; | |
446 | + int i; | |
447 | + | |
448 | + | |
449 | + if( CurrentDirCluster == 0 ) { // Root directory ? | |
450 | + if(IsFAT32) { | |
451 | + SearchSector = FirstDataSector; | |
452 | + } else { | |
453 | + SearchSector = BPB_info.ResvdSecCnt + (BPB_info.NumFATs * FATSectors); | |
454 | + } | |
455 | + } else { | |
456 | + SearchSector = Cluster2Sector( CurrentDirCluster ); | |
457 | + } | |
458 | + printf("[read_DIR] Seek to 0x%08X.\r\n", SearchSector); | |
459 | + if( lseek(fd, (off_t) (SearchSector * BPB_info.BytsPerSec), SEEK_SET) < 0 ) { | |
460 | + printf("[read_DIR] Seek failed.\r\n"); | |
461 | + perror("[read_DIR]"); | |
462 | + return; | |
463 | + } | |
464 | + if( read(fd, buf, sizeof(buf)) == 0 ) { | |
465 | + printf("[read_DIR] Read failed.\r\n"); | |
466 | + return; | |
467 | + } | |
468 | + | |
469 | + i=0; | |
470 | + for(i=0;i<sizeof(buf)/32;i++) { // 1 entry = 32 bytes | |
471 | + if(buf[i*32+ 0] == 0x00) { | |
472 | + // end of entries | |
473 | + break; | |
474 | + } else if (buf[i*32+ 0] == 0xE5) { | |
475 | + // empty entry | |
476 | + continue; | |
477 | + } else if ( (buf[i*32+ 11] & 0x0F) == 0x0F) { | |
478 | + // Long file name entry | |
479 | + continue; | |
480 | + } else { | |
481 | + TotalFileNum++; | |
482 | + | |
483 | + dir_info[i].FirstCluster = buf[i*32+ 20] * 0x10000 | |
484 | + + buf[i*32+ 21] * 0x1000000 | |
485 | + + buf[i*32+ 26] | |
486 | + + buf[i*32+ 27] * 0x100; | |
487 | + dir_info[i].Attributes = buf[i*32+ 11]; | |
488 | + | |
489 | + dir_info[i].Name[ 0] = buf[i*32+ 0]; | |
490 | + dir_info[i].Name[ 1] = buf[i*32+ 1]; | |
491 | + dir_info[i].Name[ 2] = buf[i*32+ 2]; | |
492 | + dir_info[i].Name[ 3] = buf[i*32+ 3]; | |
493 | + dir_info[i].Name[ 4] = buf[i*32+ 4]; | |
494 | + dir_info[i].Name[ 5] = buf[i*32+ 5]; | |
495 | + dir_info[i].Name[ 6] = buf[i*32+ 6]; | |
496 | + dir_info[i].Name[ 7] = buf[i*32+ 7]; | |
497 | + | |
498 | + if(dir_info[i].Attributes & 0x10) { | |
499 | + dir_info[i].Name[ 8] = buf[i*32+ 8]; | |
500 | + dir_info[i].Name[ 9] = buf[i*32+ 9]; | |
501 | + dir_info[i].Name[10] = buf[i*32+ 10]; | |
502 | + dir_info[i].Name[11] = ' '; | |
503 | + dir_info[i].Name[12] = 0x00; | |
504 | + printf(" [%12s] 0x%08X\r\n", dir_info[i].Name, dir_info[i].FirstCluster ); | |
505 | + } else { | |
506 | + dir_info[i].Name[ 8] = '.'; | |
507 | + dir_info[i].Name[ 9] = buf[i*32+ 8]; | |
508 | + dir_info[i].Name[10] = buf[i*32+ 9]; | |
509 | + dir_info[i].Name[11] = buf[i*32+ 10]; | |
510 | + dir_info[i].Name[12] = 0x00; | |
511 | + printf(" %12s 0x%08X\r\n", dir_info[i].Name, dir_info[i].FirstCluster ); | |
512 | + } | |
513 | + } | |
514 | + | |
515 | + | |
516 | + } | |
517 | + | |
518 | + // Contents dump | |
519 | + for(i=0; i<sizeof(buf)/16; i++) { | |
520 | + printf("%06X | %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X \r\n", | |
521 | + i*0x10, | |
522 | + buf[i*16+ 0], buf[i*16+ 1], buf[i*16+ 2], buf[i*16+ 3], | |
523 | + buf[i*16+ 4], buf[i*16+ 5], buf[i*16+ 6], buf[i*16+ 7], | |
524 | + buf[i*16+ 8], buf[i*16+ 9], buf[i*16+10], buf[i*16+11], | |
525 | + buf[i*16+12], buf[i*16+13], buf[i*16+14], buf[i*16+15] ); | |
526 | + } | |
527 | + | |
528 | + | |
529 | +} | |
530 | + | |
531 | +unsigned long Cluster2Sector( unsigned long cluster ) { | |
532 | + return ( FirstDataSector + (cluster - 2) * BPB_info.SecPerClus ); | |
533 | +>>>>>>> 5d25b5c54834a18f08f4fba3c3a1bb32974c16f2 | |
399 | 534 | } |