2
interface.c -- parted binding glue to libext2resize
3
Copyright (C) 1998-2000, 2007-2012 Free Software Foundation, Inc.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
/* VERSION: libext2resize 1.1.6 (by Lennert)
20
* merged 1.1.11 changes (by Andrew)
25
#include <parted/parted.h>
28
static PedFileSystemType _ext2_type;
29
static PedFileSystemType _ext3_type;
31
struct ext2_dev_handle* ext2_make_dev_handle_from_parted_geometry(PedGeometry* geom);
34
_ext2_generic_probe (PedGeometry* geom, int expect_ext_ver)
37
if (!ped_geometry_read_alloc(geom, &sb_v, 2, 2))
39
struct ext2_super_block *sb = sb_v;
41
if (EXT2_SUPER_MAGIC(*sb) == EXT2_SUPER_MAGIC_CONST) {
42
PedSector block_size = 1 << (EXT2_SUPER_LOG_BLOCK_SIZE(*sb) + 1);
43
PedSector block_count = EXT2_SUPER_BLOCKS_COUNT(*sb);
44
PedSector group_blocks = EXT2_SUPER_BLOCKS_PER_GROUP(*sb);
45
PedSector group_nr = EXT2_SUPER_BLOCK_GROUP_NR(*sb);
46
PedSector first_data_block = EXT2_SUPER_FIRST_DATA_BLOCK(*sb);
47
int version = EXT2_SUPER_REV_LEVEL(*sb);
51
is_ext3 = (EXT2_SUPER_FEATURE_COMPAT (*sb)
52
& EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0;
54
is_ext4 = ((EXT2_SUPER_FEATURE_RO_COMPAT (*sb)
55
& EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
56
|| (EXT2_SUPER_FEATURE_RO_COMPAT (*sb)
57
& EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
58
|| (EXT2_SUPER_FEATURE_RO_COMPAT (*sb)
59
& EXT4_FEATURE_RO_COMPAT_DIR_NLINK)
60
|| (EXT2_SUPER_FEATURE_INCOMPAT (*sb)
61
& EXT4_FEATURE_INCOMPAT_EXTENTS)
62
|| (EXT2_SUPER_FEATURE_INCOMPAT (*sb)
63
& EXT4_FEATURE_INCOMPAT_64BIT)
64
|| (EXT2_SUPER_FEATURE_INCOMPAT (*sb)
65
& EXT4_FEATURE_INCOMPAT_FLEX_BG));
71
if (expect_ext_ver == 2 && (is_ext3 || is_ext4))
73
if (expect_ext_ver == 3 && !is_ext3)
75
else if (expect_ext_ver == 4 && !is_ext4)
78
if (version > 0 && group_nr > 0) {
80
PedGeometry probe_geom;
83
- group_blocks * group_nr
88
ped_geometry_init (&probe_geom, geom->dev,
89
start, block_count * block_size);
90
return _ext2_generic_probe (&probe_geom,
93
return ped_geometry_new (geom->dev, geom->start,
94
block_count * block_size);
105
_ext2_probe (PedGeometry* geom)
107
return _ext2_generic_probe (geom, 2);
111
_ext3_probe (PedGeometry* geom)
113
return _ext2_generic_probe (geom, 3);
117
_ext4_probe (PedGeometry* geom)
119
return _ext2_generic_probe (geom, 4);
122
static PedFileSystemOps _ext2_ops = {
126
static PedFileSystemOps _ext3_ops = {
130
static PedFileSystemOps _ext4_ops = {
134
#define EXT23_BLOCK_SIZES ((int[6]){512, 1024, 2048, 4096, 8192, 0})
136
static PedFileSystemType _ext2_type = {
140
block_sizes: EXT23_BLOCK_SIZES
143
static PedFileSystemType _ext3_type = {
147
block_sizes: EXT23_BLOCK_SIZES
150
static PedFileSystemType _ext4_type = {
154
block_sizes: EXT23_BLOCK_SIZES
157
void ped_file_system_ext2_init ()
159
ped_file_system_type_register (&_ext2_type);
160
ped_file_system_type_register (&_ext3_type);
161
ped_file_system_type_register (&_ext4_type);
164
void ped_file_system_ext2_done ()
166
ped_file_system_type_unregister (&_ext2_type);
167
ped_file_system_type_unregister (&_ext3_type);
168
ped_file_system_type_unregister (&_ext4_type);