1N/A/*
1N/A geom_dal.c -- parted device abstraction layer
1N/A Copyright (C) 2001-2002, 2007, 2009-2010 Free Software Foundation,
1N/A Inc.
1N/A
1N/A This program is free software; you can redistribute it and/or modify
1N/A it under the terms of the GNU General Public License as published by
1N/A the Free Software Foundation; either version 3 of the License, or
1N/A (at your option) any later version.
1N/A
1N/A This program is distributed in the hope that it will be useful,
1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A GNU General Public License for more details.
1N/A
1N/A You should have received a copy of the GNU General Public License
1N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
1N/A*/
1N/A
1N/A#include <config.h>
1N/A
1N/A#if (DYNAMIC_LOADING || HAVE_LIBREISERFS) && !DISCOVER_ONLY
1N/A
1N/A#include "geom_dal.h"
1N/A
1N/A#include <parted/parted.h>
1N/A#include <parted/debug.h>
1N/A
1N/Astatic blk_t __len(dal_t *dal) {
1N/A PED_ASSERT(dal != NULL, return 0);
1N/A
1N/A return ((PedGeometry *)dal->dev)->length /
1N/A (dal->block_size / PED_SECTOR_SIZE_DEFAULT);
1N/A}
1N/A
1N/Astatic int __read(dal_t *dal, void *buff, blk_t block, blk_t count) {
1N/A blk_t k;
1N/A PedSector block_pos;
1N/A PedSector block_count;
1N/A
1N/A PED_ASSERT(dal != NULL, return 0);
1N/A
1N/A k = dal->block_size / PED_SECTOR_SIZE_DEFAULT;
1N/A block_pos = (PedSector)(block * k);
1N/A block_count = (PedSector)(count * k);
1N/A
1N/A return ped_geometry_read((PedGeometry *)dal->dev, buff, block_pos, block_count);
1N/A}
1N/A
1N/Astatic int __write(dal_t *dal, void *buff, blk_t block, blk_t count) {
1N/A blk_t k;
1N/A PedSector block_pos;
1N/A PedSector block_count;
1N/A
1N/A PED_ASSERT(dal != NULL, return 0);
1N/A
1N/A k = dal->block_size / PED_SECTOR_SIZE_DEFAULT;
1N/A block_pos = (PedSector)(block * k);
1N/A block_count = (PedSector)(count * k);
1N/A
1N/A return ped_geometry_write((PedGeometry *)dal->dev, buff, block_pos,
1N/A block_count);
1N/A}
1N/A
1N/Astatic int __sync(dal_t *dal) {
1N/A PED_ASSERT(dal != NULL, return 0);
1N/A return ped_geometry_sync((PedGeometry *)dal->dev);
1N/A}
1N/A
1N/Astatic int __flags(dal_t *dal) {
1N/A PED_ASSERT(dal != NULL, return 0);
1N/A return dal->flags;
1N/A}
1N/A
1N/Astatic int __equals(dal_t *dal1, dal_t *dal2) {
1N/A PED_ASSERT(dal1 != NULL, return 0);
1N/A PED_ASSERT(dal2 != NULL, return 0);
1N/A
1N/A return ped_geometry_test_equal((PedGeometry *)dal1->dev,
1N/A (PedGeometry *)dal2->dev);
1N/A}
1N/A
1N/Astatic int __stat(dal_t *dal, struct stat *st) {
1N/A
1N/A PED_ASSERT(dal != NULL, return 0);
1N/A PED_ASSERT(st != NULL, return 0);
1N/A
1N/A if (stat(((PedGeometry *)dal->dev)->dev->path, st))
1N/A return 0;
1N/A
1N/A return 1;
1N/A}
1N/A
1N/Astatic dev_t __dev(dal_t *dal) {
1N/A struct stat st;
1N/A
1N/A if (!__stat(dal, &st))
1N/A return (dev_t)0;
1N/A
1N/A return st.st_dev;
1N/A}
1N/A
1N/Astatic struct dal_ops ops = {
1N/A __len, __read, __write, __sync,
1N/A __flags, __equals, __stat, __dev
1N/A};
1N/A
1N/Adal_t *geom_dal_create(PedGeometry *geom, size_t block_size, int flags) {
1N/A dal_t *dal;
1N/A
1N/A if (!geom)
1N/A return NULL;
1N/A
1N/A if (!(dal = ped_malloc(sizeof(dal_t))))
1N/A return NULL;
1N/A
1N/A dal->ops = &ops;
1N/A dal->dev = geom;
1N/A dal->block_size = block_size;
1N/A dal->flags = flags;
1N/A dal->len = 0;
1N/A
1N/A return dal;
1N/A}
1N/A
1N/Aint geom_dal_reopen(dal_t *dal, int flags) {
1N/A
1N/A if (!dal) return 0;
1N/A dal->flags = flags;
1N/A
1N/A return 1;
1N/A}
1N/A
1N/Avoid geom_dal_free(dal_t *dal) {
1N/A PED_ASSERT(dal != NULL, return);
1N/A free(dal);
1N/A}
1N/A
1N/A#endif