void SD_File_Create(void) { ReadBPB(); FormatCard(); FATSystemType(); //MMC/SD卡文件系统类型判断,FAT32_EN==1则为FAT32文件系统 if(FAT32_EN==1) ReadBPB32(); FileCountSearch(); //搜索文件夹及文件数量 DelFile("DATAFILETXT"); //FileCountSearch(); //搜索文件夹及文件数量 if(FAT32_EN==0) { //FAT文件系统下在根目录下创建文件或文件夹,0x10为文件夹,0x20为文件 CreateFile("DATAFILETXT", 0x20); DeBug_Print_Str("create success ..!\r\n"); } else { FAT32CreateFile("DATAFILETXT"); DeBug_Print_Str("create fail ..!\r\n"); } }
exp bool Open(const char* fname, unsigned int pO, unsigned int pLen) { partitionOffset = pO; partitionLength = pLen; // Open the image f.open(fname, std::ios::in | std::ios::out | std::ios::binary); if (!f.is_open()) { LastError("Open", "Failed to open disk"); return false; } f.seekg(0, std::ios::end); fsize = (size_t)f.tellg(); f.seekg(0); // Allocate a buffer sectorBuffer = new char[SECTOR_SIZE]; // Read the BPB if (!ReadBPB()) { LastError("Open", "Failed to read the BPB"); return false; } // Read filesystem info fsInfo = new FileSystemInfo; ReadSector((char*)fsInfo, bpb->clusterFSInfo); // Load the root directory if (!DirOpenRoot()) { LastError("Open", "Failed to load the root directory"); return false; } volumeId = new char[DOS83_MAX_LEN + 1]; ReadSector(sectorBuffer, ClusterToSector(bpb->clusterRoot)); DirectoryEntry* entry = FindEntryAttribute(ATTRIB_VOLUME_ID, &directory); if (entry) { memcpy(volumeId, entry->name, DOS83_MAX_LEN); volumeId[11] = 0; } return true; }
/******************************************************************************* * Function Name : FAT_Init * Description : Init the FAT16 File System. * Input : Mone * Output : None * Return : None *******************************************************************************/ void FAT_Init(void) { ReadMBR(); ReadBPB(); }