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

📄 file.lst

📁 单片机读写优盘
💻 LST
📖 第 1 页 / 共 3 页
字号:
 340   4                                      {
 341   5                                              memset(file, 0, sizeof(struct _FILE));
 342   5                                              file->DirSectorNum = Sector;
 343   5                                              file->DirIndex = j; //j 代表了文件中该扇区中的位置(0-15);
 344   5                                              memcpy(&file->dir, dir, sizeof(struct _DIR));
 345   5                                      }
 346   4                                      temp=WordSwap(dir->FstClusLO);
 347   4                                      temp1=ClusterToSec(temp);
 348   4                                      return temp1;
 349   4                              }       
 350   3                              dir++;
 351   3                      }//end for cycle
 352   2                      Sector++;
 353   2              }//end for cycle
 354   1              return  0xffffffff;
 355   1      }
 356          
 357          DWORD LocateFile(const char *filename, struct _FILE *file)
 358          {
 359   1              DWORD Sector = FatParameter.FirstRootDirSecNum;
C51 COMPILER V7.06   FILE                                                                  07/30/2008 08:56:13 PAGE 7   

 360   1              char NewFile[12];
 361   1              char *p=NewFile;
 362   1              ///////////////////////////////////////////////////////////////////////////////
 363   1              if(!CheckFileName(filename,p))
 364   1                      return FALSE;
 365   1              Sector = SeekSector(Sector, p, file);
 366   1              if(*(p+11)==NULL)
 367   1                      return Sector;
 368   1              return 0Xffffffff;
 369   1      }
 370          BYTE LocateDir(struct _DIR* new_dir, struct _FILE * fp)
 371          {
 372   1              BYTE Cache[512];
 373   1              struct _DIR *dir;
 374   1              DWORD i;
 375   1              DWORD DirSectorNum = FatParameter.FirstRootDirSecNum;   
 376   1              ////////////////////////////////////////////////////////////////////////////////
 377   1              for(i=0; i<SimpleBpb.RootEntCnt * sizeof(struct _DIR) / SimpleBpb.BytsPerSec; i++)//total root dir sector
             -s;
 378   1              {
 379   2                      if(!Read(DirSectorNum,1,(BYTE *)Cache))
 380   2                              return FALSE;
 381   2                      /////////////////////////////////////////////////////////////////////
 382   2                      for(dir = (struct _DIR *)Cache; (BYTE*)dir < Cache + SimpleBpb.BytsPerSec; dir++)
 383   2                      {
 384   3                              if(dir->Name[0] == '\0'||dir->Name[0] == 0xE5)
 385   3                              {
 386   4                                      memcpy(dir, new_dir, sizeof(struct _DIR));      
 387   4                                      if(!Write(DirSectorNum,1,Cache,TRUE))
 388   4                                              if(!Write(DirSectorNum,1,Cache,TRUE))   
 389   4                                                      return FALSE;                           
 390   4                                      if(fp)
 391   4                                      {
 392   5                                              fp->DirSectorNum = DirSectorNum;
 393   5                                              fp->DirIndex = ((BYTE*)dir - Cache)/sizeof(struct _DIR);
 394   5                                              memcpy(&fp->dir, new_dir, sizeof(struct _DIR));
 395   5                                      }
 396   4                                      return TRUE;
 397   4                              }
 398   3                      }//--------------------------end for cycle
 399   2                       DirSectorNum++;
 400   2              }//-------------------------------end for cycle
 401   1              return FALSE; 
 402   1      }
 403          BYTE CheckFileName(const char * oldfilename,  char newfilename[11])
 404          {
 405   1              char* p=newfilename;
 406   1              char path[12];
 407   1              char* ppath = path;
 408   1              int dir_len_count; //count dir len.
 409   1              int i;
 410   1              ////////////////////////////////////////////////////////////////////////////////////
 411   1              if(oldfilename==NULL || strlen(oldfilename) >=12)
 412   1                      return FALSE;
 413   1              dir_len_count=0;
 414   1              strcpy(path, oldfilename);
 415   1              //变小写字母为大写
 416   1              for(i=0;(*ppath!=NULL&&i<12);i++)
 417   1              {
 418   2                      if(     *ppath > 96 && *ppath < 123)
 419   2                              *ppath -= 32;   
 420   2                      ppath++;
C51 COMPILER V7.06   FILE                                                                  07/30/2008 08:56:13 PAGE 8   

 421   2              }
 422   1              memset(p, 0, 12);
 423   1              ppath = path;
 424   1              for(;;)
 425   1              {
 426   2                      switch(*ppath)
 427   2                      {
 428   3                      case 0:
 429   3                              {
 430   4                                      if(dir_len_count>=11)
 431   4                                              return TRUE;            
 432   4                                      else 
 433   4                                      {
 434   5                                      dir_len_count ++;
 435   5                                      *p = 0x20;
 436   5                                      p++;
 437   5                                      }
 438   4                                      continue;
 439   4                              }
 440   3                      ////////////////////////////////////////////////////////////////////////////////
 441   3                      case '.':
 442   3                              {
 443   4                                      if(dir_len_count > 8 || dir_len_count ==0)
 444   4                                      { 
 445   5                                              return FALSE;
 446   5                                      }
 447   4                                      if(ppath[1] == '.')
 448   4                                      {
 449   5                                              return FALSE;
 450   5                                      }
 451   4                                      for(i=0; i<(8 - dir_len_count); i++)
 452   4                                      {
 453   5                                              *p = 0x20;
 454   5                                              p++;
 455   5                                      }
 456   4                                      dir_len_count =8;
 457   4                                      ppath++;
 458   4                                      continue;
 459   4                                      break;
 460   4                              }
 461   3                      /////////////////////////////////////////////////////////////////////////////////
 462   3                      case 0x22:
 463   3                      case 0x2A:
 464   3                      case 0x2B:
 465   3                      case 0x2C:
 466   3                      case 0x2F:
 467   3                      case 0x3A:
 468   3                      case 0x3B:
 469   3                      case 0x3C:
 470   3                      case 0x3D:
 471   3                      case 0x3E:
 472   3                      case 0x3F:
 473   3                      case 0x5B:
 474   3                      case 0x5D:
 475   3                      case 0x7C:
 476   3                              return FALSE;
 477   3                      /////////////////////////////////////////////////////////////////////////////////
 478   3                      default:
 479   3                              {
 480   4                                      if(*ppath < 0x20)
 481   4                                              return FALSE;           
 482   4                                      break;  
C51 COMPILER V7.06   FILE                                                                  07/30/2008 08:56:13 PAGE 9   

 483   4                              }
 484   3                      ////////////////////////////////////////////////////////////////////////////////
 485   3                      }
 486   2                      *p = *ppath;
 487   2                      dir_len_count ++;
 488   2                      if(dir_len_count >= 11)
 489   2                              return TRUE;
 490   2                      p++;
 491   2                      ppath++;
 492   2              }//*end for cycle
 493   1              return FALSE;   
 494   1      }
 495          //************************************************************************
 496          //author:dragon
 497          //web:8dragon.com
 498          //2004.2.5完成于桃龙源
 499          //*************************************************************************


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   4252    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   1130    2680
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  3 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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