int main(int, char **) { dialogMode = true; CursesInterface ncInterface; ncInterface.setTitle(_("AgiliaLinux setup")); ncInterface.setSubtitle(_("Root partition selection")); vector<pEntry> rootList = getPartitionList(); if (rootList.empty()) { ncInterface.showMsgBox(_("No partitions found for root filesystem. Create it first.")); return 1; } string swapPartition = ReadFile(SETUPCONFIG_SWAP); vector<MenuItem> menuItems; int def_id=0; for (size_t i=0; i<rootList.size(); i++) { menuItems.push_back(MenuItem(rootList[i].devname, rootList[i].fstype + " (" + rootList[i].size + "Mb)")); if (rootList[i].devname==swapPartition) continue; } string rootPartition; int rootSelectNum; rootSelectNum = ncInterface.showMenu(_("Choose root partition for AgiliaLinux:"), menuItems, def_id); if (rootSelectNum<0) return 1; rootPartition = rootList[rootSelectNum].devname; WriteFile(SETUPCONFIG_ROOT, rootPartition); return 0; }
/*permute partition*/ TypePartition getPermutedPartition(TypePartition *part) { TypePartitionList *pl = getPartitionList(part); TypePartition res; int i, j, c, *elt, ind, *start; start = (int*) malloc((part->sizeAtom+1)*sizeof(int)); elt = (int*) malloc(part->sizeItem*sizeof(int)); ind = 0; for(c=0; c<pl->sizeAtom; c++) { start[c] = ind; for(i=pl->start[c]; i>=0; i=pl->next[i]) elt[ind++] = i; } start[pl->sizeAtom] = part->sizeItem+1; /*shuffle*/ for(i=0; i<pl->sizeItem; i++) { int j = (rand() % (pl->sizeItem-i))+i, tmp; tmp = elt[i]; elt[i] = elt[j]; elt[j] = tmp; } res.sizeItem = part->sizeItem; res.sizeAtom = part->sizeAtom; res.atom = (int*) malloc(res.sizeItem*sizeof(int)); for(c=0; c<pl->sizeAtom; c++) for(i=start[c]; i<start[c+1]; i++) res.atom[elt[i]] = c; return res; }
bool PlatformUdisks::isMounted(QString path) { bool ret = false; QStringList partitionList = getPartitionList(path); for (int i = 0; i < partitionList.size(); ++i) { ret = isPartitionMounted(partitionList.at(i)); if (ret) break; } return(ret); }
bool PlatformUdisks2::unmountDevice(QString path) { bool res = true; QStringList partitions = getPartitionList(path); foreach(QString partition, partitions) { if (!doUnmount(partition)) { res = false; break; } } return(res); }
bool PlatformUdisks2::isMounted(QString path) { bool mounted = false; QStringList partitions = getPartitionList(path); foreach(QString partition, partitions) { if (isPartitionMounted(partition)) { mounted = true; break; } } return mounted; }
TypePartitionCompact *getPartitionCompact(TypePartition *part) { int a, ind=0; TypePartitionList *pl = getPartitionList(part); TypePartitionCompact *pc = (TypePartitionCompact *) malloc(sizeof(TypePartitionCompact)); pc->sizeAtom = part->sizeAtom; pc->start = (int*) malloc((pc->sizeAtom+1)*sizeof(int)); pc->item = (int*) malloc((part->sizeItem)*sizeof(int)); ind = 0; for(a=0; a<pc->sizeAtom; a++) { int i; pc->start[a] = ind; for(i=pl->start[a]; i!=-1; i=pl->next[i]) pc->item[ind++] = i; } pc->start[a] = ind; freePartitionList(pl); return pc; }
bool PlatformUdisks::unmountDevice (QString path) { bool ret = true; QStringList partitionList = getPartitionList(path); for (int i = 0; i < partitionList.size(); ++i) { if (isPartitionMounted(partitionList.at(i))) { ret = performUnmount(partitionList.at(i)); if (!ret) break; } } return(ret); }
void TextSetupMechanics::updatePartitionLists() { ncInterface.showInfoBox(_("Updating lists of available drives and partitions, please wait")); // Let's go setuid. At least, let's try. uid_t uid = getuid(); if (uid) { perror("Failed to obtain root privileges to read disk partition table"); ncInterface.showMsgBox(_("This program should have suid bit, or be run from root. Otherwise, it could not get drive information.\nThis is fatal, and we have to exit.")); exit(1); return; } drives = getDevList(); partitions = getPartitionList(); lvm_groups = getLVM_VGList(); // Since fslabel in libparted means completely other thing, let's get this from blkid for (size_t i=0; i<partitions.size(); ++i) { partitions[i].fslabel = getLABEL(partitions[i].devname).c_str(); } }
/*print partition*/ void fprintPartitionStandard(FILE *f, TypePartition *part, char **name) { TypePartitionList *pl = getPartitionList(part); if(name) { int c,i; for(c=0; c<pl->sizeAtom; c++) { for(i=pl->start[c]; i>=0; i=pl->next[i]) fprintf(f, "%s\t", name[i]); fprintf(f, "\n"); } } else { int c,i; for(c=0; c<pl->sizeAtom; c++) { for(i=pl->start[c]; i>=0; i=pl->next[i]) fprintf(f, "%d\t", i+1); fprintf(f, "\n"); } } freePartitionList(pl); }
bool PlatformUdisks2::isMounted(QString path) { bool mounted = false; QStringList partitions = getPartitionList(path); foreach(QString partition, partitions) { if (isPartitionMounted(partition)) { mounted = true; break; } } if (!mounted) { mounted = isPartitionMounted(QString("/org/freedesktop/UDisks2/block_devices/") + path); } return mounted; }
/*print partition*/ void fprintPartitionClustNSee(FILE *f, TypePartition *part, char **name) { TypePartitionList *pl = getPartitionList(part); fprintf(f, "#ClustnSee analysis export\n"); if(name) { int c,i; for(c=0; c<pl->sizeAtom; c++) { fprintf(f, "ClusterID:%d||\n", c+1); for(i=pl->start[c]; i>=0; i=pl->next[i]) fprintf(f, "%s\n", name[i]); fprintf(f, "\n"); } } else { int c,i; for(c=0; c<pl->sizeAtom; c++) { fprintf(f, "ClusterID:%d||\n", c+1); for(i=pl->start[c]; i>=0; i=pl->next[i]) fprintf(f, "%d\n", i+1); fprintf(f, "\n"); } } freePartitionList(pl); }
bool PlatformUdisks2::unmountDevice(QString path) { bool res = true; QStringList partitions = getPartitionList(path); if (partitions.empty()) { res = doUnmount(QString("/org/freedesktop/UDisks2/block_devices/") + path); } else { foreach(QString partition, partitions) { if (isPartitionMounted(partition) && !doUnmount(partition)) { res = false; break; } } } return(res); }