Apollo/Kronos: Display backup options for 'var' and 'root1'...

...only if are mounted.

- Using /proc/mounts to find correct mountpoint for backup
This commit is contained in:
M. Liebmann
2015-09-22 13:39:47 +02:00
parent cb4c7431c7
commit 885f13f6b0
3 changed files with 49 additions and 13 deletions

View File

@@ -92,7 +92,6 @@ extern int allow_flash;
#define MTD_OF_WHOLE_IMAGE 0 #define MTD_OF_WHOLE_IMAGE 0
#ifdef BOXMODEL_APOLLO #ifdef BOXMODEL_APOLLO
#define MTD_DEVICE_OF_UPDATE_PART "/dev/mtd0" #define MTD_DEVICE_OF_UPDATE_PART "/dev/mtd0"
#define ROOT1_MOUNT "/ext"
#else #else
#define MTD_DEVICE_OF_UPDATE_PART "/dev/mtd3" #define MTD_DEVICE_OF_UPDATE_PART "/dev/mtd3"
#endif #endif
@@ -770,17 +769,20 @@ void CFlashExpert::readmtd(int preadmtd)
filename = (std::string)g_settings.update_dir + "/" + mtdInfo->getMTDName(preadmtd) + timeStr + tankStr + ".img"; filename = (std::string)g_settings.update_dir + "/" + mtdInfo->getMTDName(preadmtd) + timeStr + tankStr + ".img";
#ifdef BOXMODEL_APOLLO #ifdef BOXMODEL_APOLLO
std::string title = " [" + CMTDInfo::getInstance()->getMTDName(preadmtd) + "]"; std::string title = " (" + CMTDInfo::getInstance()->getMTDName(preadmtd) + ")";
std::string mountp = getJFFS2MountPoint(preadmtd);
if (preadmtd == 0) { if (preadmtd == 0) {
readmtdJFFS2(filename, title); readmtdJFFS2(filename, title);
return; return;
} }
if (preadmtd == 1) { if (preadmtd == 1) {
readmtdJFFS2(filename, title, "/var", false); if (mountp != "")
readmtdJFFS2(filename, title, mountp.c_str(), false);
return; return;
} }
if (preadmtd == 2) { if (preadmtd == 2) {
readmtdJFFS2(filename, title, ROOT1_MOUNT, false); if (mountp != "")
readmtdJFFS2(filename, title, mountp.c_str(), false);
return; return;
} }
#endif #endif
@@ -886,12 +888,15 @@ int CFlashExpert::showMTDSelector(const std::string & actionkey)
lx == mtdInfo->findMTDNumberFromName("uldr") || lx == mtdInfo->findMTDNumberFromName("uldr") ||
lx == mtdInfo->findMTDNumberFromName("env"))) lx == mtdInfo->findMTDNumberFromName("env")))
enabled = false; enabled = false;
// build jffs2 image from root0 if (actionkey == "readmtd") {
if ((actionkey == "readmtd") && (lx == mtdInfo->findMTDNumberFromName("root0"))) { // Enabled when file system is mounted
CMenuForwarder *mf = new CMenuDForwarder("root0", true, NULL, new CFlashExpertSetup(), NULL, CRCInput::convertDigitToKey(shortcut++)); if (lx == mtdInfo->findMTDNumberFromName("var"))
mtdselector->addItem(mf); enabled = (getJFFS2MountPoint(lx) == "") ? false : true;
continue; else if (lx == mtdInfo->findMTDNumberFromName("root1"))
enabled = (getJFFS2MountPoint(lx) == "") ? false : true;
} }
if (lx == 3)
mtdselector->addItem(GenericMenuSeparatorLine);
#else #else
// disable write uboot // disable write uboot
if ((actionkey == "writemtd") && (lx == mtdInfo->findMTDNumberFromName("U-Boot"))) if ((actionkey == "writemtd") && (lx == mtdInfo->findMTDNumberFromName("U-Boot")))
@@ -1089,10 +1094,18 @@ int CFlashExpertSetup::showMenu()
CMenuSeparator *s1 = new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_FLASHUPDATE_CREATEIMAGE_OPTIONS); CMenuSeparator *s1 = new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_FLASHUPDATE_CREATEIMAGE_OPTIONS);
CMenuForwarder *m1 = new CMenuForwarder(LOCALE_FLASHUPDATE_CREATEIMAGE, true, NULL, this, "readmtd0", CRCInput::convertDigitToKey(0)); CMenuForwarder *m1 = new CMenuForwarder(LOCALE_FLASHUPDATE_CREATEIMAGE, true, NULL, this, "readmtd0", CRCInput::convertDigitToKey(0));
CMenuOptionChooser *m8 = new CMenuOptionChooser(LOCALE_FLASHUPDATE_CREATEIMAGE_ADD_VAR, &g_settings.flashupdate_createimage_add_var, bool isMountVar = (getJFFS2MountPoint(1) == "") ? false : true;
CMenuOptionChooser *m8=NULL;
if (isMountVar)
m8 = new CMenuOptionChooser(LOCALE_FLASHUPDATE_CREATEIMAGE_ADD_VAR, &g_settings.flashupdate_createimage_add_var,
MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true);
CMenuOptionChooser *m9 = new CMenuOptionChooser(LOCALE_FLASHUPDATE_CREATEIMAGE_ADD_ROOT1, &g_settings.flashupdate_createimage_add_root1,
bool isMountRoot1 = (getJFFS2MountPoint(2) == "") ? false : true;
CMenuOptionChooser *m9=NULL;
if (isMountRoot1)
m9 = new CMenuOptionChooser(LOCALE_FLASHUPDATE_CREATEIMAGE_ADD_ROOT1, &g_settings.flashupdate_createimage_add_root1,
MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true);
CMenuOptionChooser *m2 = new CMenuOptionChooser(LOCALE_FLASHUPDATE_CREATEIMAGE_ADD_ULDR, &g_settings.flashupdate_createimage_add_uldr, CMenuOptionChooser *m2 = new CMenuOptionChooser(LOCALE_FLASHUPDATE_CREATEIMAGE_ADD_ULDR, &g_settings.flashupdate_createimage_add_uldr,
MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true);
#ifndef UBOOT_BIN #ifndef UBOOT_BIN
@@ -1117,8 +1130,10 @@ g_settings.flashupdate_createimage_add_spare = 0;
rootfsSetup->addItem(m1); // create image rootfsSetup->addItem(m1); // create image
rootfsSetup->addItem(s1); rootfsSetup->addItem(s1);
rootfsSetup->addItem(m8); // include var if (isMountVar)
rootfsSetup->addItem(m9); // include root1 rootfsSetup->addItem(m8); // include var
if (isMountRoot1)
rootfsSetup->addItem(m9); // include root1
rootfsSetup->addItem(m2); // include uldr rootfsSetup->addItem(m2); // include uldr
#ifdef UBOOT_BIN #ifdef UBOOT_BIN
rootfsSetup->addItem(m3); // include u-boot rootfsSetup->addItem(m3); // include u-boot

View File

@@ -898,3 +898,21 @@ std::string to_string(unsigned long long i)
return s.str(); return s.str();
} }
std::string getJFFS2MountPoint(int mtdPos)
{
FILE* fd = fopen("/proc/mounts", "r");
if (!fd) return "";
int iBlock;
char lineRead[1024], sMount[512], sFs[512];
memset(lineRead, '\0', sizeof(lineRead));
while (fgets(lineRead, sizeof(lineRead)-1, fd)) {
sscanf(lineRead, "/dev/mtdblock%d %512s %512s", &iBlock, sMount, sFs);
if ((iBlock == mtdPos) && (strstr(sMount, "/") != NULL) && (strstr(sFs, "jffs2") != NULL)) {
fclose(fd);
return sMount;
}
memset(lineRead, '\0', sizeof(lineRead));
}
fclose(fd);
return "";
}

View File

@@ -113,4 +113,7 @@ inline void cstrncpy(char *dest, const std::string &src, size_t n) { n--; strncp
std::vector<std::string> split(const std::string &s, char delim); std::vector<std::string> split(const std::string &s, char delim);
bool split_config_string(const std::string &str, std::map<std::string,std::string> &smap); bool split_config_string(const std::string &str, std::map<std::string,std::string> &smap);
std::string getJFFS2MountPoint(int mtdPos);
#endif #endif