thin-provisioning-tools/space_map_disk_structures.h

117 lines
3.4 KiB
C
Raw Normal View History

2011-12-06 19:23:05 +05:30
// Copyright (C) 20011 Red Hat, Inc. All rights reserved.
//
2011-12-06 19:13:56 +05:30
// This file is part of the thin-provisioning-tools source.
//
// thin-provisioning-tools is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// thin-provisioning-tools is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>.
2011-07-22 20:39:56 +05:30
#ifndef SPACE_MAP_DISK_STRUCTURES_H
#define SPACE_MAP_DISK_STRUCTURES_H
2011-08-22 15:12:13 +05:30
#include "endian_utils.h"
2011-07-22 20:39:56 +05:30
#include "btree.h"
//----------------------------------------------------------------
namespace persistent_data {
using namespace base;
namespace sm_disk_detail {
struct index_entry_disk {
__le64 blocknr_;
__le32 nr_free_;
__le32 none_free_before_;
} __attribute__ ((packed));
struct index_entry {
uint64_t blocknr_;
uint32_t nr_free_;
uint32_t none_free_before_;
};
struct index_entry_traits {
typedef index_entry_disk disk_type;
typedef index_entry value_type;
typedef NoOpRefCounter<index_entry> ref_counter;
static void unpack(disk_type const &disk, value_type &value) {
value.blocknr_ = to_cpu<uint64_t>(disk.blocknr_);
value.nr_free_ = to_cpu<uint32_t>(disk.nr_free_);
value.none_free_before_ = to_cpu<uint32_t>(disk.none_free_before_);
}
static void pack(value_type const &value, disk_type &disk) {
disk.blocknr_ = to_disk<__le64>(value.blocknr_);
disk.nr_free_ = to_disk<__le32>(value.nr_free_);
disk.none_free_before_ = to_disk<__le32>(value.none_free_before_);
}
};
unsigned const MAX_METADATA_BITMAPS = 255;
unsigned const ENTRIES_PER_BYTE = 4;
struct metadata_index {
__le32 csum_;
__le32 padding_;
__le64 blocknr_;
2011-08-25 19:35:23 +05:30
struct index_entry_disk index[MAX_METADATA_BITMAPS];
2011-07-22 20:39:56 +05:30
} __attribute__ ((packed));
struct sm_root_disk {
__le64 nr_blocks_;
__le64 nr_allocated_;
__le64 bitmap_root_;
__le64 ref_count_root_;
} __attribute__ ((packed));
struct sm_root {
uint64_t nr_blocks_;
uint64_t nr_allocated_;
uint64_t bitmap_root_;
uint64_t ref_count_root_;
};
struct sm_root_traits {
typedef sm_root_disk disk_type;
typedef sm_root value_type;
typedef NoOpRefCounter<sm_root> ref_counter;
static void unpack(disk_type const &disk, value_type &value) {
value.nr_blocks_ = to_cpu<uint64_t>(disk.nr_blocks_);
value.nr_allocated_ = to_cpu<uint64_t>(disk.nr_allocated_);
value.bitmap_root_ = to_cpu<uint64_t>(disk.bitmap_root_);
value.ref_count_root_ = to_cpu<uint64_t>(disk.ref_count_root_);
}
static void pack(value_type const &value, disk_type &disk) {
disk.nr_blocks_ = to_disk<__le64>(value.nr_blocks_);
disk.nr_allocated_ = to_disk<__le64>(value.nr_allocated_);
disk.bitmap_root_ = to_disk<__le64>(value.bitmap_root_);
disk.ref_count_root_ = to_disk<__le64>(value.ref_count_root_);
}
};
struct bitmap_header {
__le32 csum;
__le32 not_used;
__le64 blocknr;
} __attribute__ ((packed));
}
}
//----------------------------------------------------------------
#endif