private long checkArgsAndGetUnallocatedSegments() throws StoreException {
    // retrieve log segments from the directory
    File dir = new File(dataDir);
    File[] segmentFiles = dir.listFiles(LogSegmentName.LOG_FILE_FILTER);
    // if the files could not be read, throw an exception
    // otherwise, populate remainingUnallocatedSegments
    if (capacityInBytes <= 0 || config.storeSegmentSizeInBytes <= 0) {
      throw new IllegalArgumentException(
          "One of totalCapacityInBytes [" + capacityInBytes + "] or " + "segmentCapacityInBytes ["
              + config.storeSegmentSizeInBytes + "] is <=0");
    }

    if (segmentFiles == null) {
      throw new StoreException("Could not read from directory: " + dataDir, StoreErrorCodes.FileNotFound);
    } else {
      long totalSegments;
      // if the files could not be read, throw an exception
      // otherwise, populate remainingUnallocatedSegments
      if (segmentFiles == null) {
        throw new StoreException("Could not read semgent files from Directory", StoreErrorCodes.FileNotFound);
      } else {
        long segmentCapacity = Math.min(capacityInBytes, config.storeSegmentSizeInBytes);
        if (segmentFiles.length == 0) {
          // checks only if we are bootstrapping
          // all segments should be the same size.
          if (capacityInBytes % segmentCapacity != 0) {
            throw new IllegalArgumentException(
                "Capacity of log [" + capacityInBytes + "] should be a multiple of segment capacity [" + segmentCapacity
                    + "]");
          }
        }

        if (isLogSegmented) {
          totalSegments = capacityInBytes / segmentCapacity;
        } else {
          // if the log is not segmented, then there should be only one segment.
          totalSegments = 1;
        }

        return totalSegments - segmentFiles.length;
      }
    }
  }
Validates the provided arguments and calculates the number of unallocated segments for the log.
@return the number of unallocated segments.
@throws StoreException if the segment files cannot be read from the directory.
@throws IllegalArgumentException if the total capacity or segment size is invalid, or if the total capacity
        is not a multiple of the segment size.
ambry-store/src/main/java/com/github/ambry/store/Log.java