src/worker.cc
// Retrieves the size (in bytes) of the disk/file.
// Return false on failure.
Retrieves the size (in bytes) of the disk/file.
Return false on failure.
Retrieves the size ( in bytes ) of the disk / file . Return false on failure .
bool DiskThread::GetDiskSize(int fd) {
  struct stat device_stat;
  if (fstat(fd, &device_stat) == -1) {
    logprintf(0, "Process Error: Unable to fstat disk %s (thread %d).\n",
              device_name_.c_str(), thread_num_);
    return false;
  }
  if (S_ISBLK(device_stat.st_mode)) {
    uint64 block_size = 0;
    if (ioctl(fd, BLKGETSIZE64, &block_size) == -1) {
      logprintf(0, "Process Error: Unable to ioctl disk %s (thread %d).\n",
                device_name_.c_str(), thread_num_);
      return false;
    }
    if (block_size == 0) {
      os_->ErrorReport(device_name_.c_str(), "device-size-zero", 1);
      ++errorcount_;
      status_ = true;  
      return false;
    }
    device_sectors_ = block_size / kSectorSize;
  } else if (S_ISREG(device_stat.st_mode)) {
    device_sectors_ = device_stat.st_size / kSectorSize;
  } else {
    logprintf(0, "Process Error: %s is not a regular file or block "
              "device (thread %d).\n", device_name_.c_str(),
              thread_num_);
    return false;
  }
  logprintf(12, "Log: Device sectors: %lld on disk %s (thread %d).\n",
            device_sectors_, device_name_.c_str(), thread_num_);
  if (update_block_table_) {
    block_table_->SetParameters(kSectorSize, write_block_size_,
                                device_sectors_, segment_size_,
                                device_name_);
  }
  return true;
}
bool DiskThread :: GetDiskSize ( int fd ) { struct stat device_stat ; if ( fstat ( fd , & device_stat ) == -1 ) { logprintf ( 0 , " \n " , device_name_ . c_str ( ) , thread_num_ ) ; return false ; } if ( S_ISBLK ( device_stat . st_mode ) ) { uint64 block_size = 0 ; if ( ioctl ( fd , BLKGETSIZE64 , & block_size ) == -1 ) { logprintf ( 0 , " \n " , device_name_ . c_str ( ) , thread_num_ ) ; return false ; } if ( block_size == 0 ) { os_ -> ErrorReport ( device_name_ . c_str ( ) , " " , 1 ) ; ++ errorcount_ ; status_ = true ; return false ; } device_sectors_ = block_size / kSectorSize ; } else if ( S_ISREG ( device_stat . st_mode ) ) { device_sectors_ = device_stat . st_size / kSectorSize ; } else { logprintf ( 0 , " " " \n " , device_name_ . c_str ( ) , thread_num_ ) ; return false ; } logprintf ( 12 , " \n " , device_sectors_ , device_name_ . c_str ( ) , thread_num_ ) ; if ( update_block_table_ ) { block_table_ -> SetParameters ( kSectorSize , write_block_size_ , device_sectors_ , segment_size_ , device_name_ ) ; } return true ; }
Retrieves the size (in bytes) of the disk/file.
Retrieves the size ( in bytes ) of the disk / file .
// For a block device, an ioctl is needed to get the size since the size // of the device file (i.e. /dev/sdb) is 0. // Zero size indicates nonworking device.. // Avoid a procedural error.