/*
interface.c -- parted binding glue to libext2resize
- Copyright (C) 1998-2000, 2007-2010 Free Software Foundation, Inc.
+ Copyright (C) 1998-2000, 2007-2011 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
#include <parted/parted.h>
#include "ext2.h"
-#include "parted_io.h"
static PedFileSystemType _ext2_type;
static PedFileSystemType _ext3_type;
is_ext4 = ((EXT2_SUPER_FEATURE_RO_COMPAT (*sb)
& EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
|| (EXT2_SUPER_FEATURE_RO_COMPAT (*sb)
+ & EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
+ || (EXT2_SUPER_FEATURE_RO_COMPAT (*sb)
& EXT4_FEATURE_RO_COMPAT_DIR_NLINK)
|| (EXT2_SUPER_FEATURE_INCOMPAT (*sb)
& EXT4_FEATURE_INCOMPAT_EXTENTS)
|| (EXT2_SUPER_FEATURE_INCOMPAT (*sb)
- & EXT4_FEATURE_INCOMPAT_64BIT));
+ & EXT4_FEATURE_INCOMPAT_64BIT)
+ || (EXT2_SUPER_FEATURE_INCOMPAT (*sb)
+ & EXT4_FEATURE_INCOMPAT_FLEX_BG));
if (is_ext4)
is_ext3 = 0;
}
return _ext2_generic_probe (geom, 4);
}
-#ifndef DISCOVER_ONLY
-static int
-_ext2_clobber (PedGeometry* geom)
-{
- void *sb_v;
- int ok = 0;
-
- if (ped_geometry_read_alloc(geom, &sb_v, 2, 2)) {
- struct ext2_super_block *sb = sb_v;
- /* Clobber only if there's a matching magic number. */
- if (EXT2_SUPER_MAGIC(*sb) != EXT2_SUPER_MAGIC_CONST) {
- ok = 1;
- } else {
- sb->s_magic = 0;
- ok = ped_geometry_write(geom, sb, 2, 2);
- }
- free (sb);
- }
- return ok;
-}
-
-static PedFileSystem*
-_ext2_open (PedGeometry* geom)
-{
- PedFileSystem* fs;
- struct ext2_fs* fs_info;
- struct ext2_dev_handle* handle;
-
- fs = (PedFileSystem*) ped_malloc (sizeof (PedFileSystem));
- if (!fs) goto error;
-
- fs->type = &_ext2_type;
- fs->geom = ped_geometry_duplicate (geom);
- fs->checked = 1;
-
- handle = ext2_make_dev_handle_from_parted_geometry(fs->geom);
- if (!handle) goto error_free_fs;
-
- fs_info = (struct ext2_fs*) ext2_open(handle, 0);
- if (!fs_info) goto error_free_handle;
-
- fs->type_specific = (void*) fs_info;
- fs_info->opt_verbose = 0;
-
- return fs;
-
-error_free_handle:
- ext2_destroy_dev_handle(handle);
-error_free_fs:
- free(fs);
-error:
- return NULL;
-}
-
-static PedFileSystem*
-_ext2_create (PedGeometry* geom, PedTimer* timer)
-{
- PedFileSystem* fs;
- struct ext2_fs* fs_info;
- struct ext2_dev_handle* handle;
-
- fs = (PedFileSystem*) ped_malloc (sizeof (PedFileSystem));
- if (!fs) goto error;
-
- fs->type = &_ext2_type;
- fs->geom = ped_geometry_duplicate (geom);
-
- handle = ext2_make_dev_handle_from_parted_geometry(fs->geom);
- if (!handle) goto error_free_fs;
-
- fs_info = ext2_mkfs (handle, 0, 0, 0, 0, -1, -1, timer);
- if (!fs_info) goto error_free_handle;
-
- fs->type_specific = (void*) fs_info;
- fs_info->opt_verbose = 0;
-
- return fs;
-
-error_free_handle:
- ext2_destroy_dev_handle(handle);
-error_free_fs:
- free(fs);
-error:
- return NULL;
-}
-
-static int
-_ext2_close (PedFileSystem *fs)
-{
- struct ext2_dev_handle* handle;
-
- handle = ((struct ext2_fs*)fs->type_specific)->devhandle;
- ext2_close(fs->type_specific);
- ext2_destroy_dev_handle(handle);
-
- free(fs);
- return 1;
-}
-
-static int
-_ext2_check (PedFileSystem *fs, PedTimer* timer)
-{
- ped_exception_throw (PED_EXCEPTION_INFORMATION, PED_EXCEPTION_OK,
- _("The ext2 file system passed a basic check. For a more "
- "comprehensive check, use the e2fsck program."));
- return 1;
-}
-
-static int
-_ext2_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
-{
- struct ext2_fs* f;
- PedSector old_length = fs->geom->length;
-
- PED_ASSERT (fs->geom->dev == geom->dev, return 0);
-
- if (fs->geom->start != geom->start)
- {
- ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
- PED_EXCEPTION_CANCEL,
- _("Sorry, can't move the start of ext2 partitions yet!"));
- return 0;
- }
-
- geom->dev->boot_dirty = 1;
-
- f = (struct ext2_fs *) fs->type_specific;
-
-/* ensure that the geometry contains the new and old geometry */
- if (old_length > geom->length) {
- if (!ext2_resize_fs(f, geom->length >> (f->logsize - 9),
- timer))
- goto error;
-
- fs->geom->length = geom->length;
- fs->geom->end = fs->geom->start + geom->length - 1;
- } else {
- fs->geom->length = geom->length;
- fs->geom->end = fs->geom->start + geom->length - 1;
-
- if (!ext2_resize_fs(f, geom->length >> (f->logsize - 9),
- timer))
- goto error;
- }
- return 1;
-
-error:
- return 0;
-}
-
-static PedConstraint*
-_ext2_get_create_constraint (const PedDevice* dev)
-{
- PedGeometry full_dev;
-
- if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
- return NULL;
-
- return ped_constraint_new (
- ped_alignment_any, ped_alignment_any,
- &full_dev, &full_dev,
- 64, dev->length);
-}
-
-static PedConstraint*
-_ext2_get_resize_constraint (const PedFileSystem* fs)
-{
- struct ext2_fs* f = (struct ext2_fs *) fs->type_specific;
- PedDevice* dev = fs->geom->dev;
- PedAlignment start_align;
- PedGeometry start_sector;
- PedGeometry full_dev;
- PedSector min_size;
-
- if (!ped_alignment_init (&start_align, fs->geom->start, 0))
- return NULL;
- if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
- return NULL;
- if (!ped_geometry_init (&start_sector, dev, fs->geom->start, 1))
- return NULL;
- min_size = (EXT2_SUPER_BLOCKS_COUNT(f->sb)
- - EXT2_SUPER_FREE_BLOCKS_COUNT(f->sb))
- * (f->blocksize / dev->sector_size);
-
- return ped_constraint_new (&start_align, ped_alignment_any,
- &start_sector, &full_dev, min_size,
- dev->length);
-}
-#endif /* !DISCOVER_ONLY */
-
static PedFileSystemOps _ext2_ops = {
probe: _ext2_probe,
-#ifndef DISCOVER_ONLY
- clobber: _ext2_clobber,
- open: _ext2_open,
- create: _ext2_create,
- close: _ext2_close,
- check: _ext2_check,
- resize: _ext2_resize,
- copy: NULL,
- get_create_constraint: _ext2_get_create_constraint,
- get_copy_constraint: NULL,
- get_resize_constraint: _ext2_get_resize_constraint
-#else /* !DISCOVER_ONLY */
- clobber: NULL,
- open: NULL,
- create: NULL,
- close: NULL,
- check: NULL,
- resize: NULL,
- copy: NULL,
- get_create_constraint: NULL,
- get_copy_constraint: NULL,
- get_resize_constraint: NULL
-#endif /* !DISCOVER_ONLY */
};
static PedFileSystemOps _ext3_ops = {
probe: _ext3_probe,
-#ifndef DISCOVER_ONLY
- clobber: _ext2_clobber,
- open: _ext2_open,
- create: NULL,
- close: _ext2_close,
- check: _ext2_check,
- resize: _ext2_resize,
- copy: NULL,
- get_create_constraint: _ext2_get_create_constraint,
- get_copy_constraint: NULL,
- get_resize_constraint: _ext2_get_resize_constraint
-#else /* !DISCOVER_ONLY */
- clobber: NULL,
- open: NULL,
- create: NULL,
- close: NULL,
- check: NULL,
- resize: NULL,
- copy: NULL,
- get_create_constraint: NULL,
- get_copy_constraint: NULL,
- get_resize_constraint: NULL
-#endif /* !DISCOVER_ONLY */
};
static PedFileSystemOps _ext4_ops = {
probe: _ext4_probe,
- clobber: NULL,
- open: NULL,
- create: NULL,
- close: NULL,
- check: NULL,
- resize: NULL,
- copy: NULL,
- get_create_constraint: NULL,
- get_copy_constraint: NULL,
- get_resize_constraint: NULL
};
#define EXT23_BLOCK_SIZES ((int[6]){512, 1024, 2048, 4096, 8192, 0})