From 84838ed2d53149f7fea757c4179715ebaff195d2 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 6 Nov 2010 22:24:48 +0000 Subject: [PATCH] hdd_menu: do not allow to wipe the drive the root fs is on If the root FS is on a HDD, disable the HDD menu for this disk. As long as we always repartition / reformat the whole drive, this is the best way to avoid people shooting themselves in the foot. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@887 e54a6e83-5905-42d5-8d5c-058d10e6a962 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/b1fefb0e60227cba40d59cc2abc53938ac55d8de Author: Stefan Seyfried Date: 2010-11-06 (Sat, 06 Nov 2010) --- src/gui/hdd_menu.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 541b99e1d..4bb5ab560 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -85,6 +85,8 @@ int CHDDMenuHandler::doMenu () int fd; struct dirent **namelist; int ret; + struct stat s; + int root_dev = -1; bool hdd_found = 0; int n = scandir("/sys/block", &namelist, my_filter, alphasort); @@ -107,12 +109,18 @@ int CHDDMenuHandler::doMenu () //if(n > 0) hddmenu->addItem( GenericMenuSeparatorLine ); + ret = stat("/", &s); + if (ret != -1) + root_dev = (s.st_dev & 0x0ffc0); /* hda = 0x0300, hdb = 0x0340 */ + printf("HDD: root_dev: 0x%04x\n", root_dev); + for(int i = 0; i < n;i++) { char str[256]; char vendor[128], model[128]; int64_t bytes; int64_t megabytes; int removable = 0; + bool isroot = false; printf("HDD: checking /sys/block/%s\n", namelist[i]->d_name); snprintf(str, sizeof(str), "/dev/%s", namelist[i]->d_name); @@ -123,6 +131,14 @@ int CHDDMenuHandler::doMenu () } if (ioctl(fd, BLKGETSIZE64, &bytes)) perror("BLKGETSIZE64"); + + ret = fstat(fd, &s); + if (ret != -1) { + if ((int)(s.st_rdev & 0x0ffc0) == root_dev) { + isroot = true; + printf("-> root device is on this disk, skipping\n"); + } + } close(fd); megabytes = bytes/1000000; @@ -162,7 +178,7 @@ int CHDDMenuHandler::doMenu () //tempMenu->addItem( new CMenuOptionChooser(LOCALE_HDD_FS, &g_settings.hdd_fs, HDD_FILESYS_OPTIONS, HDD_FILESYS_OPTION_COUNT, true)); tempMenu->addItem(new CMenuForwarder(LOCALE_HDD_FORMAT, true, "", new CHDDFmtExec, namelist[i]->d_name)); tempMenu->addItem(new CMenuForwarder(LOCALE_HDD_CHECK, true, "", new CHDDChkExec, namelist[i]->d_name)); - hddmenu->addItem(new CMenuForwarderNonLocalized(str, removable ? false : true, NULL, tempMenu)); + hddmenu->addItem(new CMenuForwarderNonLocalized(str, (removable || isroot) ? false : true, NULL, tempMenu)); hdd_found = 1; free(namelist[i]); }