コード例 #1
0
ファイル: partition_manager.cpp プロジェクト: vsfs/vsfs
Status PartitionManager::remove_partition(const string &path,
                                          HashValueType sep) {
  Partition *partitions = nullptr;
  {
    MutexGuard lock(mutex_);
    auto iter = partition_map_by_index_path_.find(path);
    if (iter == partition_map_by_index_path_.end()) {
      LOG(ERROR) << "Attempt to remove a hash range from an non-existed index:"
                 << path << " hash(" << sep << ")";
      return Status(-ENOENT, "The index does not existed.");
    }
    partitions = iter->second.get();
    partitions->refcount_++;
  }
  MutexGuard lock(partitions->mutex_);
  Status status = partitions->partitions_.remove(sep);
  if (!status.ok()) {
    return status;
  }
  status = write_partition_map(path);
  if (!status.ok()) {
    LOG(ERROR) << "Failed to write partition map to DB after removing "
               << "partition for (" << path << ", " << sep << "):"
               << status.message();
  }
  return Status::OK;
}
コード例 #2
0
ファイル: partition_manager.cpp プロジェクト: vsfs/vsfs
Status PartitionManager::add_partition(const string &path,
                                       HashValueType sep) {
  Partition *partitions = nullptr;
  {
    MutexGuard lock(mutex_);
    auto iter = partition_map_by_index_path_.find(path);
    if (iter == partition_map_by_index_path_.end()) {
      LOG(ERROR) << "Attempt to insert a hash range to an non-existed index: "
                 << path << "  hash(" << sep << ")";
      return Status(-ENOENT, "The index does not existed.");
    }
    partitions = iter->second.get();
    partitions->refcount_++;
  }
  // Checks whether the `sep` has already existed.
  MutexGuard lock(partitions->mutex_);
  if (partitions->partitions_.has_key(sep)) {
    partitions->refcount_--;
    return Status(-1, "The separator is already existed.");
  }
  string node = path + "." + to_string(sep);
  partitions->partitions_.insert(sep, node);
  partitions->refcount_--;

  Status status = write_partition_map(path);
  if (!status.ok()) {
    // TODO(eddyxu): add recovery.
    LOG(ERROR) << "Failed to write partition map to DB when add partition for "
               << "(" << path << ", " << sep << "): " << status.message();
  }
  return status;
}
コード例 #3
0
ファイル: pdisk.c プロジェクト: gosudream/netbsd-src
void
do_write_partition_map(partition_map_header *map)
{
    if (map == NULL) {
	bad_input("No partition map exists");
	return;
    }
    if (map->changed == 0 && map->written == 0) {
	bad_input("The map has not been changed.");
	return;
    }
    if (map->writable == 0) {
	bad_input("The map is not writable.");
	return;
    }
#if 0 /* this check is not found in linux fdisk-0.1 */
    if (map->blocks_in_map > MAX_LINUX_MAP) {
	error(-1, "Map contains more than %d blocks - Linux may have trouble", MAX_LINUX_MAP);
    }
#endif
    printf("Writing the map destroys what was there before. ");
    if (get_okay("Is that okay? [n/y]: ", 0) != 1) {
	return;
    }

    write_partition_map(map);
    
    map->changed = 0;
    map->written = 1;

    // exit(0);
}
コード例 #4
0
ファイル: partition_manager.cpp プロジェクト: vsfs/vsfs
Status PartitionManager::add_index(const string &path) {
  CHECK_NOTNULL(store_.get());
  MutexGuard lock(mutex_);
  if (contain_key(partition_map_by_index_path_, path)) {
    LOG(WARNING) << "The index has already existed:" << path;
    return Status(-1, "The index has already existed");
  }
  partition_map_by_index_path_[path].reset(new Partition);
  PartitionMap::key_type initial_key = 0;  // TODO(lxu): a random number?
  string node = path + "." + to_string(initial_key);
  partition_map_by_index_path_[path]->partitions_.insert(initial_key, node);

  return write_partition_map(path);
}
コード例 #5
0
ファイル: cvt_pt.c プロジェクト: marwatk/TivoTools
/*
 * The operation to apply to each file ...
 */
void
process(char *filename)
{
    char *s;
    int index;
    partition_map_header *map;
    int valid_file;
    partition_map * entry;

    //printf("Processing %s\n", filename);

    // 1)       strip off number from end of filename
    s = strdup(filename);
    index = trim_num(s);

    if (index < 0) {
        fatal(-1, "%s does not end in a number", filename);
    }

    // 2)       open prefix of filename as partition map
    map = open_partition_map(s, &valid_file, 0);
    if (!valid_file) {
        fatal(-1, "%s does not have a partition map", s);
        return;
    }

    // 3)       verify the type for the partition;

    if (map->writeable == 0) {
	fatal(-1, "The map is not writeable");
        return;
    }

    // 4) find partition and change it
    entry = find_entry_by_disk_address(index, map);
    if (entry == NULL) {
	fatal(-1, "No such partition");
    } else if (strcmp(entry->data->dpme_type, kHFSType) != 0) {
	fatal(-1, "Can't convert a partition with type %s",
		entry->data->dpme_type);
    } else {
	// 4a)       modify the type
	strncpy(entry->data->dpme_type, kUnixType, DPISTRLEN);
	
	// 5)       and write back.
	write_partition_map(map);
    }
}