summaryrefslogtreecommitdiff
path: root/libparted/fs/reiserfs/geom_dal.c
blob: ad315f01a849bb0ace4268e489a0627e0e5fa1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
    geom_dal.c -- parted device abstraction layer
    Copyright (C) 2001, 2002  Free Software Foundation, Inc.

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/

#include "config.h"

#if (DYNAMIC_LOADING || HAVE_LIBREISERFS) && !DISCOVER_ONLY

#include "geom_dal.h"

#include <parted/parted.h>
#include <parted/debug.h>

static blk_t __len(dal_t *dal) {
    PED_ASSERT(dal != NULL, return 0);
    
    return ((PedGeometry *)dal->dev)->length / 
	(dal->block_size / PED_SECTOR_SIZE_DEFAULT);
}

static int __read(dal_t *dal, void *buff, blk_t block, blk_t count) {
    blk_t k;
    PedSector block_pos;
    PedSector block_count;
    
    PED_ASSERT(dal != NULL, return 0);
    
    k = dal->block_size / PED_SECTOR_SIZE_DEFAULT;
    block_pos = (PedSector)(block * k);
    block_count = (PedSector)(count * k);
    
    return ped_geometry_read((PedGeometry *)dal->dev, buff, block_pos, block_count);
}

static int __write(dal_t *dal, void *buff, blk_t block, blk_t count) {
    blk_t k;
    PedSector block_pos;
    PedSector block_count;
    
    PED_ASSERT(dal != NULL, return 0);
    
    k = dal->block_size / PED_SECTOR_SIZE_DEFAULT;
    block_pos = (PedSector)(block * k);
    block_count = (PedSector)(count * k);
    
    return ped_geometry_write((PedGeometry *)dal->dev, buff, block_pos, 
	block_count);
}

static int __sync(dal_t *dal) {
    PED_ASSERT(dal != NULL, return 0);
    return ped_geometry_sync((PedGeometry *)dal->dev);
}

static int __flags(dal_t *dal) {
    PED_ASSERT(dal != NULL, return 0);
    return dal->flags;
}

static int __equals(dal_t *dal1, dal_t *dal2) {
    PED_ASSERT(dal1 != NULL, return 0);
    PED_ASSERT(dal2 != NULL, return 0);

    return ped_geometry_test_equal((PedGeometry *)dal1->dev, 
	(PedGeometry *)dal2->dev);
}

static int __stat(dal_t *dal, struct stat *st) {
    
    PED_ASSERT(dal != NULL, return 0);
    PED_ASSERT(st != NULL, return 0);
    
    if (stat(((PedGeometry *)dal->dev)->dev->path, st))
	return 0;

    return 1;
}

static dev_t __dev(dal_t *dal) {
    struct stat st;
    
    if (!__stat(dal, &st))
	return (dev_t)0;
	
    return st.st_dev;
}

static struct dal_ops ops = {
    __len, __read, __write, __sync, 
    __flags, __equals, __stat, __dev
};

dal_t *geom_dal_create(PedGeometry *geom, size_t block_size, int flags) {
    dal_t *dal;

    if (!geom) 
	return NULL;
    
    if (!(dal = ped_malloc(sizeof(dal_t))))
	return NULL;
    
    dal->ops = &ops;
    dal->dev = geom;
    dal->block_size = block_size;
    dal->flags = flags;
    dal->len = 0;

    return dal;
}

int geom_dal_reopen(dal_t *dal, int flags) {

    if (!dal) return 0;
    dal->flags = flags;
    
    return 1;
}

void geom_dal_free(dal_t *dal) {
    PED_ASSERT(dal != NULL, return);
    ped_free(dal);
}

#endif