[parted-devel] [PATCH] set swap flag on GPT partitions

Wang Dong dongdwdw at linux.vnet.ibm.com
Fri Dec 2 03:35:44 UTC 2016


Hi,

I think it will be better if you can send your patch with #git send-email.

It is not convenient to comment your patch if you put it in attaches file.

So I just paste it out. I got some comments below.;-)


On 12/1/2016 7:28 PM, Arvin Schnell wrote:
> Hi,
>
> attached is a patch to support displaying and setting (on already
> existing partitions) the swap flag on GPT partitions.
>
> So far the swap flag can only be set when creating a partition
> and setting the file-system to linux-swap.
>
> Output of print looks like:
>
> Model: Maxtor 6 Y080L0 (scsi)
> Disk /dev/sdb: 82.0GB
> Sector size (logical/physical): 512B/512B
> Partition Table: gpt
> Disk Flags:
>
> Number  Start   End     Size    File system     Name  Flags
>   1      1049kB  8197MB  8196MB  linux-swap(v1)        swap
>   2      8197MB  16.4GB  8196MB
>
> Note that "linux-swap(v1)" and "swap" are independent, any
> combination is possible.
>
> Feedback is welcome.
>
> ciao
>    Arvin
> diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
>
> index d69377a..4b5f89a 100644
>
> --- a/libparted/labels/gpt.c
>
> +++ b/libparted/labels/gpt.c
>
> @@ -290,6 +290,7 @@ typedef struct _GPTPartitionData
>
>     efi_char16_t name[37];
>
>     char *translated_name;
>
>     int lvm;
>
> +  int swap;
>
>     int raid;
>
>     int boot;
>
>     int bios_grub;
>
> @@ -818,7 +819,8 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
>
>     gpt_part_data->name[i] = 0;
>
>     gpt_part_data->translated_name = 0;
>
>
>
> -  gpt_part_data->lvm = gpt_part_data->raid
>
> +  gpt_part_data->lvm = gpt_part_data->swap
>
> +    = gpt_part_data->raid
>
>       = gpt_part_data->boot = gpt_part_data->hp_service
>
>       = gpt_part_data->hidden = gpt_part_data->msftres
>
>       = gpt_part_data->msftdata
>
> @@ -841,6 +843,8 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
>
>       gpt_part_data->raid = 1;
>
>     else if (!guid_cmp (gpt_part_data->type, PARTITION_LVM_GUID))
>
>       gpt_part_data->lvm = 1;
>
> +  else if (!guid_cmp (gpt_part_data->type, PARTITION_SWAP_GUID))
>
> +    gpt_part_data->swap = 1;
>
>     else if (!guid_cmp (gpt_part_data->type, PARTITION_HPSERVICE_GUID))
>
>       gpt_part_data->hp_service = 1;
>
>     else if (!guid_cmp (gpt_part_data->type, PARTITION_MSFT_RESERVED_GUID))
>
> @@ -1361,6 +1365,7 @@ gpt_partition_new (const PedDisk *disk,
>
>
>
>     gpt_part_data->type = PARTITION_LINUX_DATA_GUID;
>
>     gpt_part_data->lvm = 0;
>
> +  gpt_part_data->swap = 0;
>
>     gpt_part_data->raid = 0;
>
>     gpt_part_data->boot = 0;
>
>     gpt_part_data->bios_grub = 0;
>
> @@ -1449,6 +1454,11 @@ gpt_partition_set_system (PedPartition *part,
>
>         gpt_part_data->type = PARTITION_LVM_GUID;
>
>         return 1;
>
>       }
>
> +  if (gpt_part_data->swap)
>
> +    {
>
> +      gpt_part_data->type = PARTITION_SWAP_GUID;
>
> +      return 1;
>
> +    }
>
>     if (gpt_part_data->raid)
>
>       {
>
>         gpt_part_data->type = PARTITION_RAID_GUID;
>
> @@ -1636,6 +1646,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>         if (state)
>
>           gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1650,6 +1661,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>         if (state)
>
>           gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->boot
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1664,6 +1676,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>         if (state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1677,6 +1690,22 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>         gpt_part_data->lvm = state;
>
>         if (state)
>
>           gpt_part_data->boot
>
> +          = gpt_part_data->swap
>
> +          = gpt_part_data->raid
>
> +          = gpt_part_data->bios_grub
>
> +          = gpt_part_data->hp_service
>
> +          = gpt_part_data->msftres
>
> +          = gpt_part_data->msftdata
>
> +          = gpt_part_data->msftrecv
>
> +          = gpt_part_data->prep
>
> +          = gpt_part_data->irst
>
> +          = gpt_part_data->atvrecv = 0;
>
> +      return gpt_partition_set_system (part, part->fs_type);
Lines above except *gpt_part_data->swap exist before. *I didn't see any 
changes compared to the source code.
> +    case PED_PARTITION_SWAP:
>
> +      gpt_part_data->swap = state;
>
> +      if (state)
>
> +        gpt_part_data->boot
>
> +          = gpt_part_data->lvm
I guess this patch is not based on the master?
Because I saw swap here is not implemented. Just one line

*case PED_PARTITION_SWAP: *But your code shows not like this.**This case is new so other flag should be set to 0*, *and line
related this should be new line, but I could see them.**

>             = gpt_part_data->raid
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
> @@ -1693,6 +1722,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->msftres
>
>             = gpt_part_data->msftdata
>
> @@ -1707,6 +1737,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftdata
>
> @@ -1721,6 +1752,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1739,6 +1771,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftdata
>
> @@ -1753,6 +1786,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1766,6 +1800,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1779,6 +1814,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>           gpt_part_data->boot
>
>             = gpt_part_data->raid
>
>             = gpt_part_data->lvm
>
> +          = gpt_part_data->swap
>
>             = gpt_part_data->bios_grub
>
>             = gpt_part_data->hp_service
>
>             = gpt_part_data->msftres
>
> @@ -1793,7 +1829,6 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>
>       case PED_PARTITION_LEGACY_BOOT:
>
>         gpt_part_data->legacy_boot = state;
>
>         return 1;
>
> -    case PED_PARTITION_SWAP:
>
>       case PED_PARTITION_ROOT:
>
>       case PED_PARTITION_LBA:
>
>       default:
>
> @@ -1839,6 +1874,7 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag)
>
>       case PED_PARTITION_IRST:
>
>         return gpt_part_data->irst;
>
>       case PED_PARTITION_SWAP:
>
> +	return gpt_part_data->swap;
>
>       case PED_PARTITION_LBA:
>
>       case PED_PARTITION_ROOT:
>
>       default:
>
> @@ -1855,6 +1891,7 @@ gpt_partition_is_flag_available (const PedPartition *part,
>
>       {
>
>       case PED_PARTITION_RAID:
>
>       case PED_PARTITION_LVM:
>
> +    case PED_PARTITION_SWAP:
>
>       case PED_PARTITION_BOOT:
>
>       case PED_PARTITION_BIOS_GRUB:
>
>       case PED_PARTITION_HPSERVICE:
>
> @@ -1868,7 +1905,6 @@ gpt_partition_is_flag_available (const PedPartition *part,
>
>       case PED_PARTITION_IRST:
>
>       case PED_PARTITION_ESP:
>
>         return 1;
>
> -    case PED_PARTITION_SWAP:
>
>       case PED_PARTITION_ROOT:
>
>       case PED_PARTITION_LBA:
>
>       default:

-- 
Best regards.

Wang Dong

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20161202/6fd00cd4/attachment.html>


More information about the parted-devel mailing list