Example #1
0
int main(int argc, char *argv[])
{
    // basic assertions
    assert(sizeof(gpt_partition_t) == 128);
    assert(sizeof(gpt_header_t)    == 512);

    // require root privilege
    if (geteuid() != 0)
    {
        printf("Must run as root user.\n");
        exit(4);
    }

    // get disk size
    uint64_t size = get_disk_size("/dev/sdb");

    // create partitions entry
    gpt_partition_t partitions[2];
    createPartitions(&partitions[0]);

    // create the header
    gpt_header_t gpt;
    initGPTHeader(&gpt, size, &partitions[0]);

    // save in disk
    partition_write("/dev/sdb", &gpt, &partitions[0]);

    return 0;
}
// Break this up into smaller bits
std::vector<std::pair<boost::gregorian::date, boost::gregorian::date> > ParallelEnergyPlus::createPartitions(const openstudio::WorkspaceObject &t_runPeriod, int t_offset, int t_numPartitions)
{

  boost::gregorian::date sd, ed;
  getRunPeriod(t_runPeriod, sd, ed);

  boost::gregorian::date_duration totalduration = ed - sd;
  double totalDays = totalduration.days() + 1;

  LOG(Debug, "t_offset " << t_offset << " t_numPartitions " << t_numPartitions << " totalDays " << totalDays);

  std::vector<std::pair<boost::gregorian::date, boost::gregorian::date> > partitions(t_numPartitions);

  // Compute partitions
  double daysPerPeriod = totalDays / t_numPartitions;

  if (daysPerPeriod-1 < t_offset)
  {
    throw std::runtime_error("The days per period is too small compared to the offset, they fully overlap");
  }

  int X, Y, A, B;
  double averageDays;
  computeLinearCombination(A, B, X, Y, averageDays, daysPerPeriod, totalDays, t_numPartitions);

  // So... x processors get A days and y processors get B days
  // Start with ranks 0... x
  boost::gregorian::date d1(sd);

  //std::cout << boost::gregorian::to_simple_string(d1) << std::endl;
  createPartitions(d1, ed, A, 0, X, t_offset, sd, partitions);

  //std::cout << boost::gregorian::to_simple_string(d1) << std::endl;
  createPartitions(d1, ed, B, X, t_numPartitions, t_offset, sd, partitions);

  return partitions;
}
Example #3
0
 bool HDDisk::formatPartitions() {
   checkIsValid();
   
   if( reportInvalidObjectError( __PRETTY_FUNCTION__ ) ) {
     return false;
   }
   
   LOG_I() << "format partitions on device " << c_config->index();
   
   // call createPartitionTable() if not already done!
   if( c_device == nullptr && createPartitions() == false ) {
     LOG_E() << "createPartitions() failed... Abort!";
     return false;
   }
   
   for( auto& part_config : c_config->partition() ) {
     LOG_I() << "create filesystem " << part_config.filesystem() << " on " << part_config.index();
     
     fs::path part_path( part_config.index() );
     if( fs::exists( part_path ) == false ) {
       LOG_E() << "Partition path " << part_path.string() << " does not exist... Abort!";
       return false;
     }
     
     Command mkfs;
     if( part_config.filesystem().compare("swap") == 0 ) {
       mkfs << "mkswap" << part_config.index();
     } else {
       mkfs << "mkfs" << "-q" << "-t" << part_config.filesystem() << part_config.index();
     }
     
     if( mkfs.waitUntilFinished() != 0 ) {
       LOG_E() << "creating filesystem FAILED... Abort!";
       return false;
     }
     
   }
   return true;
 }
ParallelEnergyPlus::ParallelEnergyPlus(const openstudio::path &t_idf, int t_numPartitions, int t_offsetInDays)
  : m_idfPath(t_idf), m_numPartitions(t_numPartitions), m_offset(t_offsetInDays), m_runPeriod(getRunPeriod(t_idf)), 
    m_partitions(createPartitions(m_runPeriod.second, m_offset, m_numPartitions))
{
}