[parted-devel] labels/ const correctness patch #1
Jim Meyering
jim at meyering.net
Mon Mar 5 14:35:27 CET 2007
I'm checking this in as an obvious improvement.
All it does is add "const" attributes, with the exception of mac.c,
where I've added a FIXME comment, along with the cast that forces
the inconsistent mac_write into the now-const mold.
-------------------------------------------------------------------------------
constify-labels-part-1
-------------------------------------------------------------------------------
Begin making libparted/labels/*.c const-correct.
For an introduction, see
http://mail-archive.com/parted-devel@lists.alioth.debian.org/msg00930.html
In particular, I've used a const-adding case in mac.c to work around
the current, inconsistent semantics of mac_write.
---
libparted/labels/aix.c | 2 +-
libparted/labels/bsd.c | 6 +++--
libparted/labels/dasd.c | 6 +++--
libparted/labels/dos.c | 52 +++++++++++++++++++++++++----------------------
libparted/labels/dvh.c | 7 +++---
libparted/labels/gpt.c | 5 ++---
libparted/labels/loop.c | 3 +--
libparted/labels/mac.c | 4 +++-
libparted/labels/pc98.c | 2 +-
libparted/labels/rdb.c | 6 +++--
libparted/labels/sun.c | 5 ++---
11 files changed, 50 insertions(+), 48 deletions(-)
diff --git a/libparted/labels/aix.c b/libparted/labels/aix.c
index 0259a10..e051789 100644
--- a/libparted/labels/aix.c
+++ b/libparted/labels/aix.c
@@ -118,7 +118,7 @@ aix_read (PedDisk* disk)
#ifndef DISCOVER_ONLY
static int
-aix_write (PedDisk* disk)
+aix_write (const PedDisk* disk)
{
ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c
index ebcc714..b9f5dd2 100644
--- a/libparted/labels/bsd.c
+++ b/libparted/labels/bsd.c
@@ -1,7 +1,7 @@
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
libparted - a library for manipulating disk partitions
- Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2007 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
@@ -305,7 +305,7 @@ error:
}
static void
-_probe_and_add_boot_code (PedDisk* disk)
+_probe_and_add_boot_code (const PedDisk* disk)
{
BSDDiskData* bsd_specific;
BSDRawLabel* old_label;
@@ -323,7 +323,7 @@ _probe_and_add_boot_code (PedDisk* disk)
#ifndef DISCOVER_ONLY
static int
-bsd_write (PedDisk* disk)
+bsd_write (const PedDisk* disk)
{
BSDDiskData* bsd_specific;
BSDRawLabel* label;
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index 1ea5b49..9a72bdc 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -77,7 +77,7 @@ typedef struct {
static int dasd_probe (const PedDevice *dev);
static int dasd_clobber (PedDevice* dev);
static int dasd_read (PedDisk* disk);
-static int dasd_write (PedDisk* disk);
+static int dasd_write (const PedDisk* disk);
static PedPartition* dasd_partition_new (const PedDisk* disk,
PedPartitionType part_type,
@@ -443,7 +443,7 @@ error_close_dev:
}
static int
-dasd_update_type (PedDisk* disk)
+dasd_update_type (const PedDisk* disk)
{
PedPartition* part;
LinuxSpecific* arch_specific;
@@ -519,7 +519,7 @@ dasd_update_type (PedDisk* disk)
}
static int
-dasd_write (PedDisk* disk)
+dasd_write (const PedDisk* disk)
{
DasdPartitionData* dasd_data;
PedPartition* part;
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index ef2231a..6b135aa 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -272,7 +272,7 @@ chs_get_sector (const RawCHS* chs)
}
static PedSector
-chs_to_sector (PedDevice* dev, const PedCHSGeometry *bios_geom,
+chs_to_sector (const PedDevice* dev, const PedCHSGeometry *bios_geom,
const RawCHS* chs)
{
PedSector c; /* not measured in sectors, but need */
@@ -295,7 +295,7 @@ chs_to_sector (PedDevice* dev, const PedCHSGeometry *bios_geom,
}
static void
-sector_to_chs (PedDevice* dev, const PedCHSGeometry* bios_geom,
+sector_to_chs (const PedDevice* dev, const PedCHSGeometry* bios_geom,
PedSector sector, RawCHS* chs)
{
PedSector real_c, real_h, real_s;
@@ -324,7 +324,7 @@ sector_to_chs (PedDevice* dev, const PedCHSGeometry* bios_geom,
}
static PedSector
-legacy_start (PedDisk* disk, const PedCHSGeometry* bios_geom,
+legacy_start (const PedDisk* disk, const PedCHSGeometry* bios_geom,
const DosRawPartition* raw_part)
{
PED_ASSERT (disk != NULL, return 0);
@@ -334,7 +334,7 @@ legacy_start (PedDisk* disk, const PedCHSGeometry* bios_geom,
}
static PedSector
-legacy_end (PedDisk* disk, const PedCHSGeometry* bios_geom,
+legacy_end (const PedDisk* disk, const PedCHSGeometry* bios_geom,
const DosRawPartition* raw_part)
{
PED_ASSERT (disk != NULL, return 0);
@@ -395,7 +395,7 @@ partition_check_bios_geometry (PedPartition* part, PedCHSGeometry* bios_geom)
}
static int
-disk_check_bios_geometry (PedDisk* disk, PedCHSGeometry* bios_geom)
+disk_check_bios_geometry (const PedDisk* disk, PedCHSGeometry* bios_geom)
{
PedPartition* part = NULL;
@@ -501,7 +501,7 @@ end:
* the algorithm. We know, however, that C > 0.
*/
static int
-probe_partition_for_geom (PedPartition* part, PedCHSGeometry* bios_geom)
+probe_partition_for_geom (const PedPartition* part, PedCHSGeometry* bios_geom)
{
DosPartitionData* dos_data;
RawCHS* start_chs;
@@ -637,7 +637,8 @@ probe_partition_for_geom (PedPartition* part, PedCHSGeometry* bios_geom)
}
static void
-partition_probe_bios_geometry (PedPartition* part, PedCHSGeometry* bios_geom)
+partition_probe_bios_geometry (const PedPartition* part,
+ PedCHSGeometry* bios_geom)
{
PED_ASSERT (part != NULL, return);
PED_ASSERT (part->disk != NULL, return);
@@ -662,7 +663,7 @@ partition_probe_bios_geometry (PedPartition* part, PedCHSGeometry* bios_geom)
}
static void
-disk_probe_bios_geometry (PedDisk* disk, PedCHSGeometry* bios_geom)
+disk_probe_bios_geometry (const PedDisk* disk, PedCHSGeometry* bios_geom)
{
PedPartition* part;
@@ -760,7 +761,7 @@ raw_part_is_lba (const DosRawPartition* raw_part)
}
PedPartition*
-raw_part_parse (PedDisk* disk, const DosRawPartition* raw_part,
+raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part,
PedSector lba_offset, PedPartitionType type)
{
PedPartition* part;
@@ -948,7 +949,8 @@ msdos_read (PedDisk* disk)
#ifndef DISCOVER_ONLY
static int
-fill_raw_part (DosRawPartition* raw_part, PedPartition* part, PedSector offset)
+fill_raw_part (DosRawPartition* raw_part,
+ const PedPartition* part, PedSector offset)
{
DosPartitionData* dos_data;
PedCHSGeometry bios_geom;
@@ -984,8 +986,9 @@ fill_raw_part (DosRawPartition* raw_part, PedPartition* part, PedSector offset)
}
static int
-fill_ext_raw_part_geom (DosRawPartition* raw_part, PedCHSGeometry* bios_geom,
- PedGeometry* geom, PedSector offset)
+fill_ext_raw_part_geom (DosRawPartition* raw_part,
+ const PedCHSGeometry* bios_geom,
+ const PedGeometry* geom, PedSector offset)
{
PED_ASSERT (raw_part != NULL, return 0);
PED_ASSERT (geom != NULL, return 0);
@@ -1006,7 +1009,8 @@ fill_ext_raw_part_geom (DosRawPartition* raw_part, PedCHSGeometry* bios_geom,
}
static int
-write_ext_table (PedDisk* disk, PedSector sector, PedPartition* logical)
+write_ext_table (const PedDisk* disk,
+ PedSector sector, const PedPartition* logical)
{
DosRawTable table;
PedPartition* part;
@@ -1046,7 +1050,7 @@ write_ext_table (PedDisk* disk, PedSector sector, PedPartition* logical)
}
static int
-write_empty_table (PedDisk* disk, PedSector sector)
+write_empty_table (const PedDisk* disk, PedSector sector)
{
DosRawTable table;
@@ -1061,7 +1065,7 @@ write_empty_table (PedDisk* disk, PedSector sector)
/* Find the first logical partition, and write the partition table for it.
*/
static int
-write_extended_partitions (PedDisk* disk)
+write_extended_partitions (const PedDisk* disk)
{
PedPartition* ext_part;
PedPartition* part;
@@ -1078,7 +1082,7 @@ write_extended_partitions (PedDisk* disk)
return write_empty_table (disk, ext_part->geom.start);
}
-static inline uint32_t generate_random_id()
+static inline uint32_t generate_random_id (void)
{
struct timeval tv;
int rc;
@@ -1089,7 +1093,7 @@ static inline uint32_t generate_random_id()
}
static int
-msdos_write (PedDisk* disk)
+msdos_write (const PedDisk* disk)
{
DosRawTable table;
PedPartition* part;
@@ -1541,8 +1545,9 @@ _primary_constraint (PedDisk* disk, const PedCHSGeometry* bios_geom,
* must start on the 2nd head of the 1st cylinder.
*/
static PedConstraint*
-_primary_start_constraint (PedDisk* disk, const PedCHSGeometry* bios_geom,
- PedGeometry* min_geom)
+_primary_start_constraint (const PedDisk* disk,
+ const PedCHSGeometry* bios_geom,
+ const PedGeometry* min_geom)
{
PedDevice* dev = disk->dev;
PedSector cylinder_size = bios_geom->sectors * bios_geom->heads;
@@ -1828,7 +1833,7 @@ _align (PedPartition* part, const PedCHSGeometry* bios_geom,
}
static PedConstraint*
-_no_geom_constraint (PedDisk* disk, PedSector start, PedSector end)
+_no_geom_constraint (const PedDisk* disk, PedSector start, PedSector end)
{
PedGeometry max;
@@ -1837,7 +1842,7 @@ _no_geom_constraint (PedDisk* disk, PedSector start, PedSector end)
}
static PedConstraint*
-_no_geom_extended_constraint (PedPartition* part)
+_no_geom_extended_constraint (const PedPartition* part)
{
PedDevice* dev = part->disk->dev;
PedGeometry* min = _get_min_extended_part_geom (part, NULL);
@@ -1982,7 +1987,7 @@ error:
* tables, etc.
*/
static int
-add_logical_part_metadata (PedDisk* disk, PedPartition* log_part)
+add_logical_part_metadata (PedDisk* disk, const PedPartition* log_part)
{
PedPartition* ext_part = ped_disk_extended_partition (disk);
PedPartition* prev = log_part->prev;
@@ -2022,7 +2027,7 @@ add_logical_part_metadata (PedDisk* disk, PedPartition* log_part)
}
static PedPartition*
-get_last_part (PedDisk* disk)
+get_last_part (const PedDisk* disk)
{
PedPartition* first_part = disk->part_list;
PedPartition* walk;
@@ -2209,4 +2214,3 @@ ped_disk_msdos_done ()
{
ped_disk_type_unregister (&msdos_disk_type);
}
-
diff --git a/libparted/labels/dvh.c b/libparted/labels/dvh.c
index 77122d3..dce8e5c 100644
--- a/libparted/labels/dvh.c
+++ b/libparted/labels/dvh.c
@@ -263,7 +263,7 @@ _parse_boot_file (PedDisk* disk, struct volume_directory* vd)
return part;
}
-static int dvh_write (PedDisk* disk);
+static int dvh_write (const PedDisk* disk);
/* YUCK
*
@@ -273,7 +273,7 @@ static int dvh_write (PedDisk* disk);
* new partition numbers, and before we write to disk.
*/
static void
-_flush_stale_flags (PedDisk* disk)
+_flush_stale_flags (const PedDisk* disk)
{
DVHDiskData* dvh_disk_data = disk->disk_specific;
@@ -437,7 +437,7 @@ _generate_boot_file (PedPartition* part, struct volume_directory* vd)
}
static int
-dvh_write (PedDisk* disk)
+dvh_write (const PedDisk* disk)
{
DVHDiskData* dvh_disk_data = disk->disk_specific;
struct volume_header vh;
@@ -910,4 +910,3 @@ ped_disk_dvh_done ()
{
ped_disk_type_unregister (&dvh_disk_type);
}
-
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 94cafe5..263b38a 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -950,7 +950,7 @@ _write_pmbr (PedDevice * dev)
}
static void
-_generate_header (PedDisk* disk, int alternate, uint32_t ptes_crc,
+_generate_header (const PedDisk* disk, int alternate, uint32_t ptes_crc,
GuidPartitionTableHeader_t** gpt_p)
{
GPTDiskData* gpt_disk_data = disk->disk_specific;
@@ -1017,7 +1017,7 @@ _partition_generate_part_entry (PedPartition* part, GuidPartitionEntry_t* pte)
}
static int
-gpt_write(PedDisk * disk)
+gpt_write(const PedDisk * disk)
{
GPTDiskData* gpt_disk_data;
GuidPartitionEntry_t* ptes;
@@ -1502,4 +1502,3 @@ ped_disk_gpt_done()
{
ped_disk_type_unregister (&gpt_disk_type);
}
-
diff --git a/libparted/labels/loop.c b/libparted/labels/loop.c
index a899457..2dd87ad 100644
--- a/libparted/labels/loop.c
+++ b/libparted/labels/loop.c
@@ -165,7 +165,7 @@ error:
#ifndef DISCOVER_ONLY
static int
-loop_write (PedDisk* disk)
+loop_write (const PedDisk* disk)
{
char buf [512];
@@ -332,4 +332,3 @@ ped_disk_loop_done ()
{
ped_disk_type_unregister (&loop_disk_type);
}
-
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index 9ccce69..aeb0f5a 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -1572,7 +1572,9 @@ static PedDiskOps mac_disk_ops = {
free: mac_free,
read: mac_read,
#ifndef DISCOVER_ONLY
- write: mac_write,
+ /* FIXME: remove this cast, once mac_write is fixed not to
+ modify its *DISK parameter. */
+ write: (int (*) (const PedDisk*)) mac_write,
#else
write: NULL,
#endif
diff --git a/libparted/labels/pc98.c b/libparted/labels/pc98.c
index df3ed20..9d12689 100644
--- a/libparted/labels/pc98.c
+++ b/libparted/labels/pc98.c
@@ -499,7 +499,7 @@ fill_raw_part (PC98RawPartition* raw_part, const PedPartition* part)
}
static int
-pc98_write (PedDisk* disk)
+pc98_write (const PedDisk* disk)
{
PC98RawTable table;
PedPartition* part;
diff --git a/libparted/labels/rdb.c b/libparted/labels/rdb.c
index 216098b..c5d52af 100644
--- a/libparted/labels/rdb.c
+++ b/libparted/labels/rdb.c
@@ -565,7 +565,7 @@ amiga_read (PedDisk* disk)
}
static int
-_amiga_find_free_blocks(PedDisk *disk, uint32_t *table,
+_amiga_find_free_blocks(const PedDisk *disk, uint32_t *table,
struct LinkedBlock *block, uint32_t first, uint32_t type)
{
PedSector next;
@@ -623,7 +623,7 @@ _amiga_next_free_block(uint32_t *table, uint32_t start, uint32_t type) {
return i;
}
static PedPartition *
-_amiga_next_real_partition(PedDisk *disk, PedPartition *part) {
+_amiga_next_real_partition(const PedDisk *disk, PedPartition *part) {
PedPartition *next;
for (next = ped_disk_next_partition (disk, part);
@@ -633,7 +633,7 @@ _amiga_next_real_partition(PedDisk *disk, PedPartition *part) {
}
#ifndef DISCOVER_ONLY
static int
-amiga_write (PedDisk* disk)
+amiga_write (const PedDisk* disk)
{
struct RigidDiskBlock *rdb;
struct LinkedBlock *block;
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 586b07f..602dc2e 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -363,7 +363,7 @@ sun_read (PedDisk* disk)
#ifndef DISCOVER_ONLY
static void
-_probe_and_use_old_info (PedDisk* disk)
+_probe_and_use_old_info (const PedDisk* disk)
{
SunDiskData* sun_specific;
SunRawLabel old_label;
@@ -378,7 +378,7 @@ _probe_and_use_old_info (PedDisk* disk)
}
static int
-sun_write (PedDisk* disk)
+sun_write (const PedDisk* disk)
{
SunRawLabel* label;
SunPartitionData* sun_data;
@@ -851,4 +851,3 @@ ped_disk_sun_done ()
{
ped_disk_type_unregister (&sun_disk_type);
}
-
More information about the parted-devel
mailing list