/**
* Used to check the init backup/source partition.
*
* @return result of check backup/source partition.
*/
static int _CheckBackupStatus(void)
{
int i = 0;
unsigned char filePath[256] = { 0 };
ITCFileStream srcStream = { 0 };
ITCFileStream backupStream = { 0 };
int result = 0;
//check drive validation, backup_special_file is used to identify the partition belonging to
//public or backup partition.
if (itcFileStreamOpen(&srcStream, CONFIG_DRIVE ":/backup_special_file", false))
{
//right public drive
printf("right public drive volume number\n");
}
else
{
printf("invalid drive volume number, need to repartition public\n");
result = NEED_RESTORE_FROM_BACKUP;
}
itcFileStreamClose((ITCStream*) &srcStream);
if (result)
{
return result;
}
for (i = 0; i < gBackupFileCount; i++)
{
sprintf(filePath, "%s:/%s", CONFIG_DRIVE, gtBackupList[i]->path);
if (itcFileStreamOpen(&srcStream, filePath, false))
{
//partition is broken.
printf("--------------Public partition is crashed------------------\n");
result = NEED_RESTORE_FROM_BACKUP;
//usleep(1 * 1000 * 1000);
}
itcFileStreamClose((ITCStream*) &srcStream);
sprintf(filePath, "%s:/%s", BACKUP_DRIVE, gtBackupList[i]->path);
if (itcFileStreamOpen(&backupStream, filePath, false))
{
//not existed or partition is broken.
printf("--------------Backup partition is crashed or not existed------------------\n");
result = NEED_RESTORE_DEFAULT;
//usleep(1 * 1000 * 1000);
}
itcFileStreamClose((ITCStream*) &backupStream);
if (result != 0)
{
break;
}
}
return result;
}
/**
* Used to reinit the corrupted partition.
* @param volume reinit volume number.
* @return none.
*/
static int _ReinitFatVolume(int volume)
{
ITPDriveStatus* driveStatusTable;
ITPDisk remountDiskType[ITP_MAX_DRIVE];
int remountDiskCount = 0;
int diskMode = _GetDriveDiskMode();
int i = 0, j = 0;
ioctl(ITP_DEVICE_DRIVE, ITP_IOCTL_DISABLE, NULL);
usleep(100 * 1000);
/**
* Used to restore the backup files to source.
* @return none.
*/
void BackupRestore(void)
{
printf("restore backup file to source....\n");
_FileSyncFile(BACKUP_DRIVE, CONFIG_DRIVE);
}
/**
* Used to save the source files to backup.
* @return none.
*/
void BackupSave(void)
{
printf("backup file save....\n");
_FileSyncFile(CONFIG_DRIVE, BACKUP_DRIVE);
}
/**
* Used to destroy backup feature.
*
* @return none.
*/
void BackupDestroy(void)
{
int i = 0;
printf("destroy backup feature....\n");
for (i = 0; i < gBackupFileCount; i++)
if (gtBackupList[i])
free(gtBackupList[i]);