BOOL RelocateClusterChain(RDWRHandle handle, CLUSTER source, CLUSTER dest) { unsigned long filesize; /* Start by relocating the first cluster */ if (!RelocateCluster(handle, source, dest)) RETURN_FTEERROR(FALSE); /* After that, just move all the data from the source to the destination, adding fat labels to the destination */ filesize = CalculateFileSize(handle, source); if (filesize == FAIL) RETURN_FTEERROR(FALSE); if (!MarkClusterChain(handle, dest, filesize)) RETURN_FTEERROR(FALSE); if (!CopyClusterChain(handle, source, dest)) RETURN_FTEERROR(FALSE); /* In the end, remove all the fat labels from the source */ if (!CleanFatLabelChain(handle, source)) RETURN_FTEERROR(FALSE); return TRUE; }
BOOL RelocateKnownFile(RDWRHandle handle, struct DirectoryPosition* pos, struct DirectoryEntry* entry, CLUSTER destination) { /* We assume destination long enough to relocate the complete file */ unsigned long length, flength; CLUSTER firstcluster; CLUSTER source; firstcluster = GetFirstCluster(entry); length = CalculateFileSize(handle, firstcluster); if (length == FAIL) RETURN_FTEERROR(FALSE); /* Small optimization for when length == 1 */ if (!RelocateFirstCluster(handle, pos, entry, destination)) RETURN_FTEERROR(FALSE); if (length == 1) return TRUE; length--; /* Change the structures for the relocation */ firstcluster = GetFirstCluster(entry); // Value is now different! if (!GetNthCluster(handle, firstcluster, &source)) return FALSE; destination++; while (length > 0) { if (!GetNextConsecutiveChain(handle, source, length, &flength)) RETURN_FTEERROR(FALSE); if (!RelocateConsecutiveClusterSeq(handle, source, destination, flength)) RETURN_FTEERROR(FALSE); if (!GetNthCluster(handle, destination + flength-1, &source)) return FALSE; if (FAT_LAST(source)) return length == flength; destination += flength; length -= flength; } return TRUE; }
FileDisk(std::string file_name, u32 desired_size) { //Chequeamos si existe y si no lo cremaos file=fopen(file_name.c_str(), "rb"); if(!file) { //Creamos file=fopen(file_name.c_str(), "wb"); //Relenamos con ceros u8 null=0; for(unsigned int i=0; i<desired_size; i++) fwrite(&null, 1, 1, file); } fclose(file); //Obtenemos el file size file_size=CalculateFileSize(file_name); //Abrimos file=fopen(file_name.c_str(), "r+b"); }