📄 hpi.lst
字号:
494 5 len=step*DeviceInfo.BPB_BytesPerSec;
495 5 }
496 4 }
497 3 else
498 3 {
499 4 step=1;
500 4 len=writeLength;
501 4 }
502 3 ////////////////////////////////////////////
503 3 if(!RBC_Write(ThisFile.SectorPointer,step,pBuffer+CHRspBlock.len))
504 3 {
505 4 CHRspBlock.errcode=ERC_DEVICEERR;
506 4 return FALSE;
507 4 }
508 3 ThisFile.OffsetofSector=len;
509 3 }
510 2 /////////////////////////////////////////////////////
511 2 //if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
512 2 // ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
513 2 writeLength-=len;
514 2 CHRspBlock.len+=len;
515 2 //ThisFile.LengthInByte+=len;
516 2 /////////////更新文件指针 //////////////////////////////
517 2 //改变参数:OffsetofSector,SectorofCluster,SectorPointer,ClusterPointer
518 2 step=ThisFile.OffsetofSector/DeviceInfo.BPB_BytesPerSec;
519 2
520 2 if(step>0)
521 2 {
522 3 ThisFile.OffsetofSector-=step*DeviceInfo.BPB_BytesPerSec;
523 3 ThisFile.SectorofCluster+=step;
524 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
525 3 {
526 4 ThisFile.SectorofCluster=0;
527 4 if(ThisFile.pointer+CHRspBlock.len<ThisFile.LengthInByte)
528 4 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
529 4 else
530 4 ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);//GetNextClusterNum(ThisFile.Clu
-sterPointer);
531 4 if(ThisFile.ClusterPointer==0x00)
532 4 {
533 5 // RspBlockReadFile.errcode=ERC_REACHEND;
534 5 // RspBlockReadFile.result=0x0;
535 5 CHRspBlock.errcode=ERC_DEVICEERR;
536 5 return FALSE;
537 5 }
538 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
539 4 }
540 3 else
541 3 ThisFile.SectorPointer=ThisFile.SectorPointer+step;
542 3 }
543 2
544 2
545 2 }//end while
546 1 ThisFile.pointer+=CHRspBlock.len;
547 1
548 1 UpdateFat(FreeFat.SectorNum);
549 1 ///////////更新文件目录信息/////////////////////////////
550 1 if(bSuccess==1)
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 10
551 1 {
552 2
553 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
554 2 {
555 3 //////////////////////////////////////////////////
556 3 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
557 3 {
558 4 CHRspBlock.errcode=ERC_DEVICEERR;
559 4 return FALSE;
560 4 }
561 3 ///////////////////////////////////////////////////
562 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
563 3 {
564 4 pDirInfo=(PDIR_INFO)(DBUF+i);
565 4
566 4 if(pDirInfo->startCluster==SwapINT16(ThisFile.StartCluster))
567 4 {
568 5 if(ThisFile.pointer>ThisFile.LengthInByte)
569 5 ThisFile.LengthInByte=ThisFile.pointer;
570 5 //else
571 5 // ThisFile.pointer=;
572 5
573 5 pDirInfo->length=SwapINT32(ThisFile.LengthInByte);
574 5 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
575 5 {
576 6 CHRspBlock.errcode=ERC_DEVICEERR;
577 6 return FALSE;
578 6 }
579 5 bStop=1;
580 5 break;
581 5 }
582 4 }
583 3 if(bStop==1)
584 3 break;
585 3 ////////////////////////////////////////////////////
586 3 }
587 2
588 2 }
589 1 /*
590 1 if(bSuccess==0)
591 1 {
592 1 RspBlockWriteFile.errcode=ERC_DEVICEERR;
593 1 RspBlockWriteFile.result=0x0;
594 1 }
595 1 */
596 1 CHRspBlock.len=0;
597 1 ThisFile.bFileOpen=1;
598 1 //////////////////////////////////////////////
599 1 return TRUE;
600 1 #undef RspBlockWriteFile
601 1 }
602
603 unsigned char RemoveFile(unsigned char *pBuffer) //删除文件
604 {
605 1 #define RspBlockRemoveFile CHRspBlock.RspBlock.Rsp_RemoveFile
606 1 unsigned int sector,i;
607 1 unsigned char bStop,j;
608 1 PDIR_INFO pDirInfo;
609 1
610 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
611 1 {
612 2 CHRspBlock.errcode=ERC_NODEVICE;
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 11
613 2 return FALSE;
614 2 }
615 1 ///////////////////////////////////////////////////////////
616 1 //RspBlockRemoveFile.result=0x1;
617 1 ////////////// 清除目录/////////////////////////////////////
618 1 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
619 1 {
620 2 //////////////////////////////////////////////////
621 2 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
622 2 {
623 3 CHRspBlock.errcode=ERC_DEVICEERR;
624 3 return FALSE;
625 3 }
626 2 ///////////////////////////////////////////////////
627 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
628 2 {
629 3 if(DBUF[i]==0x00)
630 3 {
631 4 CHRspBlock.errcode=ERC_FILENOTFOUND;
632 4 return FALSE;
633 4 }
634 3 ///////////////////////////////////////////
635 3 j=0;
636 3 while(DBUF[i+j]==*(pBuffer+j))
637 3 {
638 4 j=j+1;
639 4 if(j>10) break;
640 4 }//end while
641 3
642 3 if(j>10)
643 3 {
644 4 DBUF[i]=0xE5;
645 4 pDirInfo=(PDIR_INFO)(DBUF+i);
646 4 ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
647 4 //DelayMs(15);
648 4 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
649 4 {
650 5 CHRspBlock.errcode=ERC_DEVICEERR;
651 5 return FALSE;
652 5 }
653 4 //////////////////// 清除FAT中的纪录////////////////////////
654 4 //DelayMs(10);
655 4 if(!DeleteClusterLink(ThisFile.StartCluster))
656 4 {
657 5 CHRspBlock.errcode=ERC_DEVICEERR;
658 5 return FALSE;
659 5 }
660 4 bStop=1;
661 4 break;
662 4 }
663 3
664 3 }//end for
665 2 if(bStop==1)
666 2 break;
667 2
668 2 }//end search
669 1 if(sector>=DeviceInfo.BPB_RootEntCnt)
670 1 {
671 2 CHRspBlock.errcode=ERC_FILENOTFOUND;
672 2 return FALSE;
673 2 }
674 1 //////////////////////////////////////////////
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 12
675 1 return TRUE;
676 1 #undef RspBlockRemoveFile
677 1 }
678
679 unsigned char GetCapacity(void)
680 {
681 1 unsigned int sectorNum,freesectorcnt,i;
682 1
683 1 #define RspBlockGetCapacity CHRspBlock.RspBlock.Rsp_GetCapacity
684 1 PREAD_CAPACITY_RSP pBuf;
685 1
686 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
687 1 {
688 2 CHRspBlock.errcode=ERC_NODEVICE;
689 2 return FALSE;
690 2 }
691 1 ///////////////////////////////////////////////////////////
692 1 if(!ReadCapacity())
693 1 {
694 2 CHRspBlock.errcode=ERC_DEVICEERR;
695 2 return FALSE;
696 2 }
697 1
698 1 pBuf=(PREAD_CAPACITY_RSP)DBUF;
699 1 RspBlockGetCapacity.disksize=SwapINT32((pBuf->LastLBA+1)*pBuf->BlockSize);
700 1 ////////////////////////////////////////////////////////////////////////
701 1 sectorNum=DeviceInfo.FatStartSector;
702 1 freesectorcnt=0;
703 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
704 1 {
705 2
706 2 if(RBC_Read(sectorNum,1,DBUF))
707 2 {
708 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
709 3 {
710 4 //clusterNum++;
711 4
712 4 if((DBUF[i]==0xff)&&(DBUF[i+1]==0xff))
713 4 {
714 5 freesectorcnt++;
715 5 }
716 4 // clusterNum++;
717 4 }
718 3 }
719 2 else
720 2 {
721 3 CHRspBlock.errcode=ERC_DEVICEERR;
722 3 return FALSE;
723 3 }
724 2 sectorNum++;
725 2 }
726 1
727 1 ////////////////////////////////////////////////////////////////////////
728 1 RspBlockGetCapacity.freedisksize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
729 1 RspBlockGetCapacity.freedisksize=freesectorcnt*RspBlockGetCapacity.freedisksize;
730 1 RspBlockGetCapacity.freedisksize=SwapINT32(RspBlockGetCapacity.disksize)-RspBlockGetCapacity.freedisksize
-;
731 1 RspBlockGetCapacity.freedisksize=SwapINT32(RspBlockGetCapacity.freedisksize);
732 1
733 1 return TRUE;
734 1 #undef RspBlockGetCapacity
735 1 }
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 13
736
737 unsigned char GetFreeCapacity(void)
738 {
739 1 #define RspBlockGetCapacity CHRspBlock.RspBlock.Rsp_GetFreeCapacity
740 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
741 1 {
742 2 CHRspBlock.errcode=ERC_NODEVICE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -