Joel Granados Moreno wrote:
> * include/parted/disk.h : Added headers for new function.
> * libparted/disk.c (ped_disk_get_max_supported_partition_count):  New
>   function that calls the label specific function.
> * libparted/arch/linux.c (_disk_sync_part_table):  To sync the table in
>   disk with the kernel we remove all partitions from the kernel table
>   and then add the ones that are in disk.  For this to happen we need to
>   calculate the maximum number of supported partitions in the label.
> * libparted/labels/gpt.c (gpt_get_max_supported_partition_count):  We
>   read the gpt header from disk and calculate the maximum amount of
>   partitions that the label can hold.
> * libparted/labels/aix.c: new get_max_supported_partition_count function.
> * libparted/labels/bsd.c: likewise
> * libparted/labels/dasd.c: likewise
> * libparted/labels/dos.c: likewise
> * libparted/labels/dvh.c: likewise
> * libparted/labels/gpt.c: likewise
> * libparted/labels/loop.c: likewise
> * libparted/labels/mac.c: likewise
> * libparted/labels/pc98.c: likewise
> * libparted/labels/rdb.c: likewise
> * libparted/labels/sun.c: likewise

Thanks for your patience, Joel.
I've pushed the above with minor changes to the log message,
and then made three additional changes, included below.

BTW, do you use emacs?  If so, you can add this to your .emacs
file so it'll be handled automatically:

  (add-hook 'before-save-hook 'copyright-update)

I'll bet vim has something similar.

Jim

>From 45668ed23c6712533e2f96603db49eb1280a2f1a Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Thu, 5 Mar 2009 11:03:45 +0100
Subject: [PATCH 1/3] gpt: adjust formatting and rename a parameter: 
s/supported/max_n/.

* libparted/labels/gpt.c (gpt_get_max_supported_partition_count): Rename
parameter: s/supported/max_n/.  The latter sounds more like a number,
while "supported" sounds boolean at first.
---
 libparted/labels/gpt.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index aeaee8a..be8f264 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1501,24 +1501,24 @@ gpt_get_max_primary_partition_count (const PedDisk 
*disk)
  * SP = Blocksize(FirstusableLBA - 2) / SizeOfPartitoinEntry
  */
 static bool
-gpt_get_max_supported_partition_count (const PedDisk *disk, int *supported)
+gpt_get_max_supported_partition_count (const PedDisk *disk, int *max_n)
 {
        GuidPartitionTableHeader_t *pth = NULL;
-       uint8_t *pth_raw = ped_malloc (pth_get_size(disk->dev));
-
-       if(ped_device_read(disk->dev, pth_raw, 1, GPT_HEADER_SECTORS) ||
-                       ped_device_read(disk->dev, pth_raw, disk->dev->length, 
GPT_HEADER_SECTORS))
-               pth = pth_new_from_raw(disk->dev, pth_raw);
-       free(pth_raw);
-
-       if(pth){
-               *supported = (disk->dev->sector_size*(pth->FirstUsableLBA - 2) /
-                               pth->SizeOfPartitionEntry);
-               pth_free(pth);
-               return true;
-       }
+       uint8_t *pth_raw = ped_malloc (pth_get_size (disk->dev));
+
+       if (ped_device_read (disk->dev, pth_raw, 1, GPT_HEADER_SECTORS)
+           || ped_device_read (disk->dev, pth_raw,
+                               disk->dev->length, GPT_HEADER_SECTORS))
+               pth = pth_new_from_raw (disk->dev, pth_raw);
+       free (pth_raw);
+
+       if (pth == NULL)
+               return false;

-       return false;
+       *max_n = (disk->dev->sector_size * (pth->FirstUsableLBA - 2)
+                 / pth->SizeOfPartitionEntry);
+       pth_free (pth);
+       return true;
 }

 static PedConstraint*
--
1.6.2.rc1.285.gc5f54


>From a702d42f173c401510b7c1a65e8e2889c7e4894e Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Thu, 5 Mar 2009 11:42:45 +0100
Subject: [PATCH 2/3] rename all "support" parameters; avoid new compiler 
warnings

Change each occurrence like this (which evokes a warning from gcc):
-       return *supported = MAX_TOTAL_PART;
to this:
+       *max_n = MAX_TOTAL_PART;
+       return true;

I did it mostly mechanically:

  cd libparted/labels &&
    grep -l 'return .supported = ' *.c|xargs perl -ni \
      -e '$m=/^\treturn \*supported( = .*;)/;' \
      -e 'print $m ? "\t*max_n$1\n\treturn true;\n" : $_'
  git grep -l 'int\* supported'|xargs perl -pi -e 's/int\* supported/int 
*max_n/'

That got all but aix.c, which used different spacing: "int *supported",
which I changed manually.  Then I updated all copyright dates.
---
 libparted/labels/aix.c  |    7 ++++---
 libparted/labels/bsd.c  |    7 ++++---
 libparted/labels/dasd.c |    5 +++--
 libparted/labels/dos.c  |    7 ++++---
 libparted/labels/dvh.c  |    7 ++++---
 libparted/labels/loop.c |    7 ++++---
 libparted/labels/mac.c  |    7 ++++---
 libparted/labels/pc98.c |    7 ++++---
 libparted/labels/rdb.c  |    7 ++++---
 libparted/labels/sun.c  |    7 ++++---
 10 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/libparted/labels/aix.c b/libparted/labels/aix.c
index 2d8a40c..465cb6c 100644
--- a/libparted/labels/aix.c
+++ b/libparted/labels/aix.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, 2007 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2001, 2007, 2009 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
@@ -224,9 +224,10 @@ aix_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-aix_get_max_supported_partition_count (const PedDisk* disk, int *supported)
+aix_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = MAX_TOTAL_PART;
+       *max_n = MAX_TOTAL_PART;
+       return true;
 }

 static int
diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c
index 55af468..83e1709 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, 2007 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2001, 2007, 2009 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
@@ -549,9 +549,10 @@ bsd_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-bsd_get_max_supported_partition_count(const PedDisk* disk, int* supported)
+bsd_get_max_supported_partition_count(const PedDisk* disk, int *max_n)
 {
-       return *supported = BSD_MAXPARTITIONS;
+       *max_n = BSD_MAXPARTITIONS;
+       return true;
 }

 static PedConstraint*
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index 35cfbb3..3a0bb32 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -716,9 +716,10 @@ dasd_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-dasd_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+dasd_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = dasd_get_max_primary_partition_count(disk);
+       *max_n = dasd_get_max_primary_partition_count(disk);
+       return true;
 }

 static PedConstraint*
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 92b728d..a0044b7 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007
+    Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2009
     Free Software Foundation, Inc.

     This program is free software; you can redistribute it and/or modify
@@ -2215,9 +2215,10 @@ msdos_get_max_primary_partition_count (const PedDisk* 
disk)
 }

 static bool
-msdos_get_max_supported_partition_count(const PedDisk* disk, int* supported)
+msdos_get_max_supported_partition_count(const PedDisk* disk, int *max_n)
 {
-       return *supported = MAX_TOTAL_PART;
+       *max_n = MAX_TOTAL_PART;
+       return true;
 }

 static PedDiskOps msdos_disk_ops = {
diff --git a/libparted/labels/dvh.c b/libparted/labels/dvh.c
index 3814824..38b7569 100644
--- a/libparted/labels/dvh.c
+++ b/libparted/labels/dvh.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 2001, 2002, 2005, 2007-2008 Free Software Foundation, Inc.
+    Copyright (C) 2001, 2002, 2005, 2007-2009 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
@@ -823,9 +823,10 @@ dvh_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-dvh_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+dvh_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = NPARTAB;
+       *max_n = NPARTAB;
+       return true;
 }


diff --git a/libparted/labels/loop.c b/libparted/labels/loop.c
index 23e0d3c..c89a9ce 100644
--- a/libparted/labels/loop.c
+++ b/libparted/labels/loop.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999, 2000, 2007, 2009 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
@@ -282,9 +282,10 @@ loop_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-loop_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+loop_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = 1;
+       *max_n = 1;
+       return true;
 }

 static PedDiskOps loop_disk_ops = {
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index db22aa8..e89dc20 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 2000, 2002, 2004, 2007-2008 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2002, 2004, 2007-2009 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
@@ -1565,9 +1565,10 @@ mac_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-mac_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+mac_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = 65536;
+       *max_n = 65536;
+       return true;
 }

 static PedDiskOps mac_disk_ops = {
diff --git a/libparted/labels/pc98.c b/libparted/labels/pc98.c
index ff21750..3ab7b03 100644
--- a/libparted/labels/pc98.c
+++ b/libparted/labels/pc98.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 2000, 2001, 2007-2008 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2001, 2007-2009 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
@@ -833,9 +833,10 @@ pc98_get_max_primary_partition_count (const PedDisk* disk)
 }

 static bool
-pc98_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+pc98_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = MAX_PART_COUNT;
+       *max_n = MAX_PART_COUNT;
+       return true;
 }

 static PedDiskOps pc98_disk_ops = {
diff --git a/libparted/labels/rdb.c b/libparted/labels/rdb.c
index 43496dc..90acc2b 100644
--- a/libparted/labels/rdb.c
+++ b/libparted/labels/rdb.c
@@ -2,7 +2,7 @@

     libparted - a library for manipulating disk partitions
     disk_amiga.c - libparted module to manipulate amiga RDB partition tables.
-    Copyright (C) 2000, 2001, 2004, 2007-2008 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2001, 2004, 2007-2009 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
@@ -1125,9 +1125,10 @@ amiga_get_max_primary_partition_count (const PedDisk* 
disk)
 }

 static bool
-amiga_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+amiga_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = AMIGA_MAX_PARTITIONS;
+       *max_n = AMIGA_MAX_PARTITIONS;
+       return true;
 }

 static PedDiskOps amiga_disk_ops = {
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 7c43240..389db47 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.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, 2005, 2007-2008 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2001, 2005, 2007-2009 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
@@ -665,9 +665,10 @@ sun_partition_is_flag_available (const PedPartition* part,
 }

 static bool
-sun_get_max_supported_partition_count (const PedDisk* disk, int* supported)
+sun_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
 {
-       return *supported = SUN_DISK_MAXPARTITIONS;
+       *max_n = SUN_DISK_MAXPARTITIONS;
+       return true;
 }

 static int
--
1.6.2.rc1.285.gc5f54


>From 87ed16c5469a8a1af88414609215cbbf1a107965 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Thu, 5 Mar 2009 15:33:55 +0100
Subject: [PATCH 3/3] reword a comment; more formatting changes.

* libparted/arch/linux.c (_disk_sync_part_table): Reword comment
to use the "active" voice, not "we ...".
Adjust formatting in new/moved code.
---
 libparted/arch/linux.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 6a90ee2..724df46 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2294,10 +2294,10 @@ _device_get_partition_range(PedDevice* dev)
 }

 /*
- * We sync the partition table in two step process:
- * 1. We remove all the partitions from the kernel's tables.  The partitions
- *    will not be removed if the ioctl call fails.
- * 2. We add all the partitions that we hold in disk.
+ * Sync the partition table in two step process:
+ * 1. Remove all of the partitions from the kernel's tables, but do not attempt
+ *    removal of any partition for which the corresponding ioctl call fails.
+ * 2. Add all the partitions that we hold in disk.
  *
  * To achieve this two step process we must calculate the minimum number of
  * maximum possible partitions between what linux supports and what the label
@@ -2324,10 +2324,10 @@ _disk_sync_part_table (PedDisk* disk)
         if(lpn < 0)
                 return 0;

-        int*        rets = ped_malloc(sizeof(int) * lpn);
-        int*        errnums = ped_malloc(sizeof(int) * lpn);
-        int                 ret = 1;
-        int                 i;
+        int *rets = ped_malloc(sizeof(int) * lpn);
+        int *errnums = ped_malloc(sizeof(int) * lpn);
+        int ret = 1;
+        int i;

         for (i = 1; i <= lpn; i++) {
                 rets[i - 1] = _blkpg_remove_partition (disk, i);
@@ -2335,9 +2335,7 @@ _disk_sync_part_table (PedDisk* disk)
         }

         for (i = 1; i <= lpn; i++) {
-                const PedPartition *part;
-
-                part = ped_disk_get_partition (disk, i);
+                const PedPartition *part = ped_disk_get_partition (disk, i);
                 if (part) {
                         /* busy... so we won't (can't!) disturb ;)  Prolly
                          * doesn't matter anyway, because users shouldn't be
--
1.6.2.rc1.285.gc5f54

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to