1N/A/*
1N/A parted_io.c -- parted I/O code interface for libext2resize
1N/A Copyright (C) 1998-2000, 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#ifndef DISCOVER_ONLY
1N/A
1N/A#include <parted/parted.h>
1N/A#include <stdio.h>
1N/A#include <stdlib.h>
1N/A#include "ext2.h"
1N/A
1N/A/* pseudo-header.... */
1N/A
1N/Aloff_t llseek(unsigned int fd, loff_t offset, unsigned int whence);
1N/A
1N/Astruct my_cookie
1N/A{
1N/A int logsize;
1N/A PedGeometry* geom;
1N/A};
1N/A
1N/A/* ...then this must be pseudo-code :-) */
1N/A
1N/Astatic int do_close (void *cookie);
1N/Astatic int do_sync (void *cookie);
1N/Astatic blk_t do_get_size (void *cookie);
1N/Astatic int do_read (void *cookie, void *ptr, blk_t block, blk_t numblocks);
1N/Astatic int do_set_blocksize(void *cookie, int logsize);
1N/Astatic int do_write (void *cookie, void *ptr, blk_t block, blk_t numblocks);
1N/A
1N/Astruct ext2_dev_ops ops =
1N/A{
1N/A .close = do_close,
1N/A .get_size = do_get_size,
1N/A .read = do_read,
1N/A .set_blocksize = do_set_blocksize,
1N/A .sync = do_sync,
1N/A .write = do_write
1N/A};
1N/A
1N/A
1N/A
1N/Astatic int do_close(void *cookie)
1N/A{
1N/A struct my_cookie *monster = cookie;
1N/A
1N/A return ped_geometry_sync(monster->geom);
1N/A}
1N/A
1N/Astatic int do_sync(void *cookie)
1N/A{
1N/A struct my_cookie *monster = cookie;
1N/A
1N/A return ped_geometry_sync(monster->geom);
1N/A}
1N/A
1N/Astatic blk_t do_get_size(void *cookie)
1N/A{
1N/A struct my_cookie *monster = cookie;
1N/A
1N/A return monster->geom->length >> (monster->logsize - 9);
1N/A}
1N/A
1N/Astatic int do_read(void *cookie, void *ptr, blk_t block, blk_t num)
1N/A{
1N/A struct my_cookie *monster = cookie;
1N/A
1N/A return ped_geometry_read(monster->geom, ptr,
1N/A (PedSector) block << (monster->logsize - 9),
1N/A (PedSector) num << (monster->logsize - 9));
1N/A}
1N/A
1N/Astatic int do_set_blocksize(void *cookie, int logsize)
1N/A{
1N/A struct my_cookie *monster = cookie;
1N/A
1N/A monster->logsize = logsize;
1N/A return 1;
1N/A}
1N/A
1N/Astatic int do_write(void *cookie, void *ptr, blk_t block, blk_t num)
1N/A{
1N/A struct my_cookie *monster = cookie;
1N/A
1N/A return ped_geometry_write(monster->geom, ptr,
1N/A (PedSector) block << (monster->logsize - 9),
1N/A (PedSector) num << (monster->logsize - 9));
1N/A}
1N/A
1N/A
1N/Astruct ext2_dev_handle *ext2_make_dev_handle_from_parted_geometry(PedGeometry* geom)
1N/A{
1N/A struct ext2_dev_handle *dh;
1N/A struct my_cookie *monster;
1N/A
1N/A if ((dh = ped_malloc(sizeof(struct ext2_dev_handle))) == NULL)
1N/A goto error;
1N/A
1N/A if ((monster = ped_malloc(sizeof(struct my_cookie))) == NULL)
1N/A goto error_free_dh;
1N/A
1N/A dh->ops = &ops;
1N/A dh->cookie = monster;
1N/A monster->logsize = 9;
1N/A monster->geom = geom;
1N/A
1N/A return dh;
1N/A
1N/Aerror_free_dh:
1N/A free(dh);
1N/Aerror:
1N/A return NULL;
1N/A}
1N/A
1N/Avoid ext2_destroy_dev_handle(struct ext2_dev_handle *handle)
1N/A{
1N/A ped_geometry_destroy(((struct my_cookie *)handle->cookie)->geom);
1N/A free(handle->cookie);
1N/A free(handle);
1N/A}
1N/A#endif /* !DISCOVER_ONLY */