⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.lst

📁 串口小程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 247   4              if ((fat_buf_sector[510] != LOW(BR_SIGNATURE)) &&         /* check PBR signature */
 248   4                  (fat_buf_sector[511] != HIGH(BR_SIGNATURE)))
 249   4              {
 250   5                return KO;
 251   5              }
 252   4      
 253   4            }
 254   3      
 255   3          }
 256   2        }
 257   1        else
 258   1        {
 259   2          return KO;
 260   2        }
 261   1      
 262   1        /* read and check usefull PBR info */
 263   1        if (fat_load_sector(fat_ptr_fats) == OK) 
 264   1        {
 265   2          if ((fat_buf_sector[11] != LOW(SECTOR_SIZE)) ||  /* read sector size (in bytes) */
 266   2              (fat_buf_sector[12] != HIGH(SECTOR_SIZE)))
 267   2          {
 268   3            return KO;
 269   3          }
 270   2      
 271   2          /* read cluster size (in sector) */
 272   2          fat_cluster_size = fat_buf_sector[13];
 273   2          fat_cluster_mask = HIGH((Uint16)fat_cluster_size * SECTOR_SIZE) - 1;
 274   2          /* compute FATs sector address: add reserved sector number */
 275   2          fat_ptr_fats += fat_buf_sector[14];
 276   2          fat_ptr_fats += (Uint16)fat_buf_sector[15] << 8;
 277   2          /* read number of FATs */
 278   2          if (fat_buf_sector[16] == 2)
 279   2            fat_2_is_present = TRUE;
 280   2          else
 281   2            fat_2_is_present = FALSE;
 282   2          /* read number of dir entries  and compute rdir offset */
 283   2          ((Byte*)&fat_ptr_data)[3] = fat_buf_sector[17];
 284   2          ((Byte*)&fat_ptr_data)[2] = fat_buf_sector[18];
 285   2          ((Byte*)&fat_ptr_data)[1] = 0;
 286   2          ((Byte*)&fat_ptr_data)[0] = 0;
 287   2          fat_ptr_data = (fat_ptr_data * DIR_SIZE) / SECTOR_SIZE;
 288   2          /* read number of sector in partition (<32Mb) */
 289   2          ((Byte*)&fat_nb_sector)[3] = fat_buf_sector[19];
 290   2          ((Byte*)&fat_nb_sector)[2] = fat_buf_sector[20];
 291   2          ((Byte*)&fat_nb_sector)[1] = 0x00;
 292   2          ((Byte*)&fat_nb_sector)[0] = 0x00;
 293   2          /* compute root directory sector address */
 294   2          ((Byte*)&fat_fat_size)[1] = fat_buf_sector[22];
 295   2          ((Byte*)&fat_fat_size)[0] = fat_buf_sector[23];
 296   2          
 297   2          fat_ptr_rdir = fat_buf_sector[16] * fat_fat_size;
 298   2          fat_ptr_rdir += fat_ptr_fats;
 299   2      
 300   2          /* read number of sector in partition (>32Mb) */
 301   2          if (!fat_nb_sector)
 302   2          {
C51 COMPILER V7.02a   FAT                                                                  09/13/2007 11:53:07 PAGE 6   

 303   3            ((Byte*)&fat_nb_sector)[3] = fat_buf_sector[32];
 304   3            ((Byte*)&fat_nb_sector)[2] = fat_buf_sector[33];
 305   3            ((Byte*)&fat_nb_sector)[1] = fat_buf_sector[34];
 306   3            ((Byte*)&fat_nb_sector)[0] = fat_buf_sector[35];
 307   3          }
 308   2      
 309   2          fat_count_of_clusters = (fat_nb_sector - (1 + (fat_buf_sector[16] * fat_fat_size) + fat_ptr_data)) 
 310   2                                  / fat_cluster_size;
 311   2          if (fat_count_of_clusters <= MAX_CLUSTERS12)
 312   2            fat_is_fat16 = FALSE;
 313   2          else
 314   2            if (fat_count_of_clusters <= MAX_CLUSTERS16)
 315   2              fat_is_fat16 = TRUE;
 316   2            /* else is FAT32 not supported */
 317   2      
 318   2          /* compute data sector address */
 319   2          fat_ptr_data += fat_ptr_rdir;
 320   2          /* check partition signature */
 321   2          if ((fat_buf_sector[510] != LOW(BR_SIGNATURE)) &&
 322   2              (fat_buf_sector[511] != HIGH(BR_SIGNATURE)))
 323   2          {
 324   3            return KO;
 325   3          }
 326   2      
 327   2          return OK;
 328   2        }
 329   1        else
 330   1        { /* low level error */
 331   2          return KO;
 332   2        }
 333   1      }
 334          
 335          
 336          /*F**************************************************************************
 337          * NAME: fat_get_dir_entry
 338          *----------------------------------------------------------------------------
 339          * PARAMS:
 340          *   entry: directory entry structure
 341          *
 342          * return:
 343          *----------------------------------------------------------------------------
 344          * PURPOSE:
 345          *   Get from directory all information about a directory or file entry
 346          *----------------------------------------------------------------------------
 347          * EXAMPLE:
 348          *----------------------------------------------------------------------------
 349          * NOTE:
 350          *   This function reads directly datas from sectors
 351          *   It automaticaly computes difference between LFN and normal entries
 352          *----------------------------------------------------------------------------
 353          * REQUIREMENTS:
 354          *****************************************************************************/
 355          void fat_get_dir_entry (fat_st_dir_entry xdata *entry)
 356          {
 357   1      bit     exit_flag = FALSE;
 358   1      bit     lfn_entry_found = FALSE;
 359   1      Byte    i;
 360   1      
 361   1        /* clear the name buffer */
 362   1        for (i = MAX_FILENAME_LEN; i != 0; lfn_name[--i] = '\0');
 363   1      
 364   1        while (!exit_flag)
C51 COMPILER V7.02a   FAT                                                                  09/13/2007 11:53:07 PAGE 7   

 365   1        /* loop while the entry is not a normal one. */
 366   1        {
 367   2          /* read the directory entry */
 368   2          if (dir_is_root == TRUE)
 369   2          { /* root dir is linear -> Hard_read_byte() */
 370   3            for (i = 0; i < DIR_SIZE; i++)
 371   3              gl_buffer[i] = Hard_read_byte();
 372   3          }
 373   2          else
 374   2          { /* subdir can be fragmented -> dgetc() */
 375   3            for (i = 0; i < DIR_SIZE; i++)
 376   3              gl_buffer[i] = fat_dgetc();
 377   3          }
 378   2      
 379   2          /*computes gathered data
 380   2          /* check if we have a LFN entry */
 381   2          if (gl_buffer[11] != ATTR_LFN_ENTRY)
 382   2          {
 383   3            if (!lfn_entry_found)
 384   3            {
 385   4              /* true DOS 8.3 entry format */
 386   4              for (i = 0; i < 8; i++)
 387   4              {
 388   5                lfn_name[i] = gl_buffer[i];
 389   5                
 390   5                if (lfn_name[i] == ' ')
 391   5                { /* space is end of name */
 392   6                  break;
 393   6                }
 394   5              }
 395   4              /* append extension */
 396   4              lfn_name[i++] = '.';
 397   4              lfn_name[i++] = gl_buffer[8];
 398   4              lfn_name[i++] = gl_buffer[9];
 399   4              lfn_name[i++] = gl_buffer[10];
 400   4      
 401   4              for (; i != 14; i++)
 402   4              {
 403   5                lfn_name[i] = ' ';       /* append spaces for display reason */
 404   5              }
 405   4              lfn_name[i] = '\0';        /* end of string */
 406   4            }
 407   3              
 408   3            else
 409   3            { /* LFN name treatment */
 410   4              i = 0;
 411   4              /* search for the end of the string */
 412   4              while (lfn_name[i] != '\0')
 413   4              { 
 414   5                i++;
 415   5              }
 416   4              if (i <= 14)
 417   4              { /* append spaces for display reason (no scrolling) */
 418   5                while (i != 14)
 419   5                {
 420   6                  lfn_name[i++] = ' ';
 421   6                }
 422   5              }
 423   4              else
 424   4              { /* append beginning of name to ease scrolling display */
 425   5                lfn_name[i++] = ' ';
 426   5                lfn_name[i++] = ' ';
C51 COMPILER V7.02a   FAT                                                                  09/13/2007 11:53:07 PAGE 8   

 427   5                lfn_name[i++] = lfn_name[0];
 428   5                lfn_name[i++] = lfn_name[1];
 429   5                lfn_name[i++] = lfn_name[2];
 430   5                lfn_name[i++] = lfn_name[3];
 431   5                lfn_name[i++] = lfn_name[4];
 432   5                lfn_name[i++] = lfn_name[5];
 433   5                lfn_name[i++] = lfn_name[6];
 434   5                lfn_name[i++] = lfn_name[7];
 435   5                lfn_name[i++] = lfn_name[8];
 436   5                lfn_name[i++] = lfn_name[9];
 437   5                lfn_name[i++] = lfn_name[10];
 438   5                lfn_name[i++] = lfn_name[11];
 439   5                lfn_name[i++] = lfn_name[12];
 440   5              }
 441   4              lfn_name[i] = '\0';        /* end of name */
 442   4            }
 443   3      
 444   3            /* store extension */
 445   3            ext[0]= gl_buffer[8];
 446   3            ext[1]= gl_buffer[9];
 447   3            ext[2]= gl_buffer[10];
 448   3      
 449   3            /* standard computing for normal entry */
 450   3            entry->attributes = gl_buffer[11];
 451   3            entry->start_cluster = gl_buffer[26];
 452   3            entry->start_cluster += ((Uint16) gl_buffer[27]) << 8;
 453   3            entry->size.b[3] = gl_buffer[28];
 454   3            entry->size.b[2] = gl_buffer[29];
 455   3            entry->size.b[1] = gl_buffer[30];
 456   3            entry->size.b[0] = gl_buffer[31];
 457   3            /* now it's time to stop */
 458   3            exit_flag = TRUE;
 459   3          }
 460   2          else
 461   2          { /* LFN entry format */
 462   3            lfn_entry_found = TRUE;             /* a 8.3 name will follow */
 463   3      
 464   3            if ((gl_buffer[0] & LFN_SEQ_MASK) <= MAX_LFN_ENTRIES)   
 465   3            {                         /* Maximum number of entries for LFN? */
 466   4              for (i = 0; i < 5; i++)
 467   4                lfn_name[i + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 1];
 468   4              for (i = 0; i < 6; i++)
 469   4                lfn_name[i + 5 + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 14];
 470   4              for (i = 0; i < 2; i++)
 471   4                lfn_name[i + 11 + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 28];
 472   4            }
 473   3          }
 474   2        }
 475   1        Hard_read_close();                        /* close physical read */
 476   1      }
 477          
 478          
 479          /*F**************************************************************************
 480          * NAME: fat_get_dir_file_list
 481          *----------------------------------------------------------------------------
 482          * PARAMS:
 483          *   id: file extension to select
 484          *
 485          * return:
 486          *----------------------------------------------------------------------------
 487          * PURPOSE:
 488          *   Construct the file directory list
C51 COMPILER V7.02a   FAT                                                                  09/13/2007 11:53:07 PAGE 9   

 489          *----------------------------------------------------------------------------
 490          * EXAMPLE:
 491          *----------------------------------------------------------------------------
 492          * NOTE:
 493          *   The value are relative position with the previous file.
 494          *   Call to this function assume that the dir fragment chain has been created
 495          *----------------------------------------------------------------------------
 496          * REQUIREMENTS:
 497          *   Maximum of 256 entries between 2 authorized file (id extension)
 498          *   because the relative position is stored on one byte.
 499          *   To allow more than 256 entries (-> 32768), change type of
 500          *   fat_dir_entry_list[] from Byte to Uint16 (no overflow management)
 501          *   and change MAX_DIRECTORY_GAP_FILE from 255 to 32767
 502          *****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -