void EditorSectorsMenu::create_sector() { auto level = Editor::current()->get_level(); auto new_sector = SectorParser::from_nothing(*level); if (!new_sector) { log_warning << "Failed to create a new sector." << std::endl; return; } // Find an unique name std::string sector_name; int num = 2; do { sector_name = "sector" + std::to_string(num); num++; } while ( level->get_sector(sector_name) ); *(new_sector->get_name_ptr()) = sector_name; level->add_sector(move(new_sector)); Editor::current()->load_sector(level->get_sector_count() - 1); MenuManager::instance().clear_menu_stack(); Editor::current()->reactivate_request = true; }
int get_dev_geometry (int fd, __u32 *cyls, __u32 *heads, __u32 *sects, __u64 *start_lba, __u64 *nsectors) { static struct local_hd_geometry g; static struct local_hd_big_geometry bg; int err = 0, try_getgeo_big_first = 1; if (nsectors) { err = get_sector_count(fd, nsectors); if (err) return err; } if (start_lba) { /* * HDIO_GETGEO uses 32-bit fields on 32-bit architectures, * so it cannot be relied upon for start_lba with very large drives >= 2TB. */ __u64 result; if (0 == sysfs_get_attr(fd, "start", "%llu", &result, NULL, 0) || 0 == get_raid1_start_lba(fd, &result)) { *start_lba = result; start_lba = NULL; try_getgeo_big_first = 0; /* if kernel has sysfs, it probably lacks GETGEO_BIG */ } else if (fd_is_raid(fd)) { *start_lba = START_LBA_UNKNOWN; /* RAID: no such thing as a "start_lba" */ start_lba = NULL; try_getgeo_big_first = 0; /* no point even trying it on RAID */ } } if (cyls || heads || sects || start_lba) { /* Skip HDIO_GETGEO_BIG (doesn't exist) on kernels with sysfs (>= 2.6.xx) */ if (try_getgeo_big_first && !ioctl(fd, HDIO_GETGEO_BIG, &bg)) { if (cyls) *cyls = bg.cylinders; if (heads) *heads = bg.heads; if (sects) *sects = bg.sectors; if (start_lba) *start_lba = bg.start; } else if (!ioctl(fd, HDIO_GETGEO, &g)) { if (cyls) *cyls = g.cylinders; if (heads) *heads = g.heads; if (sects) *sects = g.sectors; if (start_lba) *start_lba = g.start; } else if (!try_getgeo_big_first && !ioctl(fd, HDIO_GETGEO_BIG, &bg)) { if (cyls) *cyls = bg.cylinders; if (heads) *heads = bg.heads; if (sects) *sects = bg.sectors; if (start_lba) *start_lba = bg.start; } else { err = errno; perror(" HDIO_GETGEO failed"); return err; } /* * On all (32 and 64 bit) systems, the cyls value is bit-limited. * So try and correct it using other info we have at hand. */ if (nsectors && cyls && heads && sects) { __u64 hs = (*heads) * (*sects); __u64 cyl = (*cyls); __u64 chs = cyl * hs; if (chs < (*nsectors)) *cyls = (*nsectors) / hs; } } return 0; }