Please find attached the 'diff -urNp' against the current SVN trunk.
This patch is meant to address the following:
a. libparted/filesys.c, ped_file_system_type_unregister: Handle
instances where fs_types == NULL and the given fs_type is not in the
list of registered file-system types. Some code clean-up.
b. libparted/disk.c, ped_register_disk_type, ped_unregister_disk_type:
Some code clean-up.
c. libparted/fs/linux_swap/linux_swap.c: Initial support for
recognizing swap partitions containing 'swsusp' data. Only the 'print'
command can be expected to work stably. Rest have to improved.
d. libparted/libparted.c: init and done functions have been added for
'swsusp' file-system type.
The code for 'swsusp' is still in the initial stages as I mentioned
above. Hence if you are in a hurry to release 1.8.0 final, you might
not want to add it. The support for 'suspend2' partitions too need to
be added. Hopefully I will be able to complete them soon. :-)
Happy hacking,
Debarshi
--
"India is not, as people keep calling it, an underdeveloped country,
but rather a developed nation in an advanced state of decay."
--Shashi Tharoor
diff -urNp trunk/libparted/disk.c trunk-modified/libparted/disk.c
--- trunk/libparted/disk.c 2006-11-11 02:11:29.000000000 +0000
+++ trunk-modified/libparted/disk.c 2006-11-10 23:53:43.000000000 +0000
@@ -65,33 +65,32 @@ static int _disk_raw_add (PedDisk* disk,
static PedDiskType* disk_types = NULL;
void
-ped_register_disk_type (PedDiskType* type)
+ped_register_disk_type (PedDiskType* disk_type)
{
- PED_ASSERT (type != NULL, return);
- PED_ASSERT (type->ops != NULL, return);
- PED_ASSERT (type->name != NULL, return);
+ PED_ASSERT (disk_type != NULL, return);
+ PED_ASSERT (disk_type->ops != NULL, return);
+ PED_ASSERT (disk_type->name != NULL, return);
- ((struct _PedDiskType*) type)->next = disk_types;
- disk_types = (struct _PedDiskType*) type;
+ /* pretend that "next" isn't part of the struct :-) */
+ ((struct _PedDiskType*) disk_type)->next = disk_types;
+ disk_types = (struct _PedDiskType*) disk_type;
}
-void ped_unregister_disk_type (PedDiskType* type)
+void ped_unregister_disk_type (PedDiskType* disk_type)
{
PedDiskType* walk;
PedDiskType* last = NULL;
PED_ASSERT (disk_types != NULL, return);
- PED_ASSERT (type != NULL, return);
+ PED_ASSERT (disk_type != NULL, return);
- for (walk = disk_types; walk; last = walk, walk = walk->next) {
- if (walk == type) break;
- }
+ for (walk = disk_types; walk && walk != disk_type; last = walk, walk = walk->next);
PED_ASSERT (walk != NULL, return);
if (last)
- ((struct _PedDiskType*) last)->next = type->next;
+ ((struct _PedDiskType*) last)->next = disk_type->next;
else
- disk_types = type->next;
+ disk_types = disk_type->next;
}
/**
diff -urNp trunk/libparted/filesys.c trunk-modified/libparted/filesys.c
--- trunk/libparted/filesys.c 2006-11-11 02:11:29.000000000 +0000
+++ trunk-modified/libparted/filesys.c 2006-11-10 23:55:25.000000000 +0000
@@ -62,18 +62,16 @@ ped_file_system_type_unregister (PedFile
PedFileSystemType* walk;
PedFileSystemType* last = NULL;
+ PED_ASSERT (fs_types != NULL, return);
PED_ASSERT (fs_type != NULL, return);
- for (walk = fs_types; walk != fs_type; walk = walk->next) {
- if (!walk) return;
- last = walk;
- }
+ for (walk = fs_types; walk && walk != fs_type; last = walk, walk = walk->next);
- if (last) {
+ PED_ASSERT (walk != NULL, return);
+ if (last)
((struct _PedFileSystemType*) last)->next = fs_type->next;
- } else {
- fs_types = fs_types->next;
- }
+ else
+ fs_types = fs_type->next;
}
/**
diff -urNp trunk/libparted/fs/linux_swap/linux_swap.c trunk-modified/libparted/fs/linux_swap/linux_swap.c
--- trunk/libparted/fs/linux_swap/linux_swap.c 2006-11-11 02:11:22.000000000 +0000
+++ trunk-modified/libparted/fs/linux_swap/linux_swap.c 2006-11-11 04:23:47.000000000 +0000
@@ -69,10 +69,13 @@ typedef struct {
} SwapSpecific;
static PedFileSystemType swap_type;
+static PedFileSystemType swsusp_swap_type;
static PedFileSystem* swap_open (PedGeometry* geom);
static int swap_close (PedFileSystem* fs);
+static PedFileSystem* swsusp_open (PedGeometry* geom);
+
static PedGeometry*
swap_probe (PedGeometry* geom)
{
@@ -472,6 +475,75 @@ swap_get_copy_constraint (const PedFileS
}
#endif /* !DISCOVER_ONLY */
+static PedGeometry*
+swsusp_probe (PedGeometry* geom)
+{
+ PedFileSystem* fs;
+ SwapSpecific* fs_info;
+ PedGeometry* probed_geom;
+ PedSector length;
+
+ fs = swsusp_open (geom);
+ if (!fs)
+ goto error;
+ fs_info = SWAP_SPECIFIC (fs);
+
+ if (fs_info->version != 0)
+ length = fs_info->page_sectors * fs_info->page_count;
+ else
+ length = geom->length;
+ probed_geom = ped_geometry_new (geom->dev, geom->start, length);
+ if (!probed_geom)
+ goto error_close_fs;
+ swap_close (fs);
+ return probed_geom;
+
+error_close_fs:
+ swap_close (fs);
+error:
+ return NULL;
+}
+
+static PedFileSystem*
+swsusp_open (PedGeometry* geom)
+{
+ PedFileSystem* fs;
+ SwapSpecific* fs_info;
+ const char* sig;
+
+ fs = swap_alloc (geom);
+ if (!fs)
+ goto error;
+ fs->type = &swsusp_swap_type;
+ swap_init (fs, 0);
+
+ fs_info = SWAP_SPECIFIC (fs);
+ if (!ped_geometry_read (fs->geom, fs_info->header, 0,
+ fs_info->page_sectors))
+ goto error_free_fs;
+
+ sig = ((char*) fs_info->header) + getpagesize() - 10;
+ if (strncmp (sig, "S1SUSPEND", 9) == 0) {
+ fs_info->version = -1;
+ } else {
+ char _sig [10];
+
+ memcpy (_sig, sig, 9);
+ _sig [9] = 0;
+ ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Unrecognised linux swsusp signature '%9s'."), _sig);
+ goto error_free_fs;
+ }
+
+ fs->checked = 1;
+ return fs;
+
+error_free_fs:
+ swap_free (fs);
+error:
+ return NULL;
+}
+
static PedFileSystemOps swap_ops = {
probe: swap_probe,
#ifndef DISCOVER_ONLY
@@ -499,6 +571,33 @@ static PedFileSystemOps swap_ops = {
#endif /* !DISCOVER_ONLY */
};
+static PedFileSystemOps swsusp_ops = {
+ probe: swsusp_probe,
+#ifndef DISCOVER_ONLY
+ clobber: swap_clobber,
+ open: swsusp_open,
+ create: swap_create,
+ close: swap_close,
+ check: swap_check,
+ copy: swap_copy,
+ resize: swap_resize,
+ get_create_constraint: swap_get_create_constraint,
+ get_resize_constraint: swap_get_resize_constraint,
+ get_copy_constraint: swap_get_copy_constraint
+#else
+ clobber: NULL,
+ open: NULL,
+ create: NULL,
+ close: NULL,
+ check: NULL,
+ copy: NULL,
+ resize: NULL,
+ get_create_constraint: NULL,
+ get_resize_constraint: NULL,
+ get_copy_constraint: NULL
+#endif /* !DISCOVER_ONLY */
+};
+
static PedFileSystemType swap_type = {
next: NULL,
ops: &swap_ops,
@@ -506,6 +605,13 @@ static PedFileSystemType swap_type = {
block_sizes: LINUXSWAP_BLOCK_SIZES
};
+static PedFileSystemType swsusp_type = {
+ next: NULL,
+ ops: &swsusp_ops,
+ name: "swsusp",
+ block_sizes: LINUXSWAP_BLOCK_SIZES
+};
+
void
ped_file_system_linux_swap_init ()
{
@@ -518,3 +624,14 @@ ped_file_system_linux_swap_done ()
ped_file_system_type_unregister (&swap_type);
}
+void
+ped_file_system_linux_swsusp_init ()
+{
+ ped_file_system_type_register (&swsusp_type);
+}
+
+void
+ped_file_system_linux_swsusp_done ()
+{
+ ped_file_system_type_unregister (&swsusp_type);
+}
diff -urNp trunk/libparted/libparted.c trunk-modified/libparted/libparted.c
--- trunk/libparted/libparted.c 2006-11-11 02:11:29.000000000 +0000
+++ trunk-modified/libparted/libparted.c 2006-11-11 04:04:15.000000000 +0000
@@ -121,6 +121,7 @@ extern void ped_file_system_ufs_init (vo
extern void ped_file_system_reiserfs_init (void);
extern void ped_file_system_ntfs_init (void);
extern void ped_file_system_linux_swap_init (void);
+extern void ped_file_system_linux_swsusp_init (void);
extern void ped_file_system_jfs_init (void);
extern void ped_file_system_hfs_init (void);
extern void ped_file_system_fat_init (void);
@@ -135,6 +136,7 @@ init_file_system_types ()
ped_file_system_reiserfs_init ();
ped_file_system_ntfs_init ();
ped_file_system_linux_swap_init ();
+ ped_file_system_linux_swsusp_init ();
ped_file_system_jfs_init ();
ped_file_system_hfs_init ();
ped_file_system_fat_init ();
@@ -209,6 +211,7 @@ extern void ped_file_system_fat_done (vo
extern void ped_file_system_hfs_done (void);
extern void ped_file_system_jfs_done (void);
extern void ped_file_system_linux_swap_done (void);
+extern void ped_file_system_linux_swsusp_done (void);
extern void ped_file_system_ntfs_done (void);
extern void ped_file_system_reiserfs_done (void);
extern void ped_file_system_ufs_done (void);
@@ -223,6 +226,7 @@ done_file_system_types ()
ped_file_system_hfs_done ();
ped_file_system_jfs_done ();
ped_file_system_linux_swap_done ();
+ ped_file_system_linux_swsusp_done ();
ped_file_system_ntfs_done ();
ped_file_system_reiserfs_done ();
ped_file_system_ufs_done ();
_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel