This commit is contained in:
Karel Zak 2015-08-13 10:41:08 +02:00
commit bc1e34e125
2 changed files with 107 additions and 1 deletions

View file

@ -0,0 +1,99 @@
diff -up util-linux-2.26.2/libfdisk/src/dos.c.kzak util-linux-2.26.2/libfdisk/src/dos.c
--- util-linux-2.26.2/libfdisk/src/dos.c.kzak 2015-04-29 12:41:22.705973232 +0200
+++ util-linux-2.26.2/libfdisk/src/dos.c 2015-08-13 10:24:23.651856847 +0200
@@ -1529,7 +1529,7 @@ static int dos_add_partition(struct fdis
goto done;
/* pa specifies that extended partition is wanted */
- } else if (pa && pa->type && pa->type->code == MBR_DOS_EXTENDED_PARTITION) {
+ } else if (pa && pa->type && IS_EXTENDED(pa->type->code)) {
DBG(LABEL, ul_debug("DOS: pa template %p: add extened", pa));
if (l->ext_offset) {
fdisk_warnx(cxt, _("Extended partition already exists."));
@@ -1894,11 +1894,25 @@ static int dos_get_partition(struct fdis
return 0;
}
+static int has_logical(struct fdisk_context *cxt)
+{
+ size_t i;
+ struct fdisk_dos_label *l = self_label(cxt);
+
+ for (i = 4; i < cxt->label->nparts_max; i++) {
+ if (l->ptes[i].pt_entry)
+ return 1;
+ }
+ return 0;
+}
+
static int dos_set_partition(struct fdisk_context *cxt, size_t n,
struct fdisk_partition *pa)
{
+ struct fdisk_dos_label *l;
struct dos_partition *p;
struct pte *pe;
+ int orgtype;
fdisk_sector_t start, size;
assert(cxt);
@@ -1909,17 +1923,29 @@ static int dos_set_partition(struct fdis
if (n >= cxt->label->nparts_max)
return -EINVAL;
- if (pa->type && IS_EXTENDED(pa->type->code)) {
- fdisk_warnx(cxt, _("You cannot change a partition into an "
- "extended one or vice versa. Delete it first."));
- return -EINVAL;
- }
-
- if (pa->type && !pa->type->code)
- fdisk_warnx(cxt, _("Type 0 means free space to many systems. "
- "Having partitions of type 0 is probably unwise."));
+ l = self_label(cxt);
p = self_partition(cxt, n);
pe = self_pte(cxt, n);
+ orgtype = p->sys_ind;
+
+ if (pa->type) {
+ if (IS_EXTENDED(pa->type->code) && l->ext_offset) {
+ fdisk_warnx(cxt, _("Extended partition already exists."));
+ return -EINVAL;
+ }
+
+ if (!pa->type->code)
+ fdisk_warnx(cxt, _("Type 0 means free space to many systems. "
+ "Having partitions of type 0 is probably unwise."));
+
+ if (IS_EXTENDED(p->sys_ind) && !IS_EXTENDED(pa->type->code) && has_logical(cxt)) {
+ fdisk_warnx(cxt, _(
+ "Cannot change type of the extended partition which is "
+ "already used by logical partitons. Delete logical "
+ "partitions first."));
+ return -EINVAL;
+ }
+ }
FDISK_INIT_UNDEF(start);
FDISK_INIT_UNDEF(size);
@@ -1950,6 +1976,21 @@ static int dos_set_partition(struct fdis
p->boot_ind = fdisk_partition_is_bootable(pa) ? ACTIVE_FLAG : 0;
}
+ if (pa->type) {
+ if (IS_EXTENDED(pa->type->code) && !IS_EXTENDED(orgtype)) {
+ /* new extended partition - create a reference */
+ l->ext_index = n;
+ l->ext_offset = dos_partition_get_start(p);
+ pe->ex_entry = p;
+ } else if (IS_EXTENDED(orgtype)) {
+ /* remove extended partition */
+ cxt->label->nparts_max = 4;
+ l->ptes[l->ext_index].ex_entry = NULL;
+ l->ext_offset = 0;
+ l->ext_index = 0;
+ }
+ }
+
partition_set_changed(cxt, n, 1);
return 0;
}

View file

@ -2,7 +2,7 @@
Summary: A collection of basic system utilities
Name: util-linux
Version: 2.26.2
Release: 2%{?dist}
Release: 3%{?dist}
License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain
Group: System Environment/Base
URL: http://en.wikipedia.org/wiki/Util-linux
@ -78,6 +78,10 @@ Requires: libfdisk = %{version}-%{release}
# 151635 - makeing /var/log/lastlog
Patch0: 2.23-login-lastlog-create.patch
### Upstream patches
# 1248115 - sfdisk: you cannot change a partition into an extended one or vice versa
Patch1: 2.27-libfdisk-mbr-ext.patch
%description
The util-linux package contains a large variety of low-level system
utilities that are necessary for a Linux system to function. Among
@ -879,6 +883,9 @@ exit 0
%{_libdir}/python*/site-packages/libmount/*
%changelog
* Thu Aug 13 2015 Karel Zak <kzak@redhat.com> 2.26.2-3
- fix #1248115 - sfdisk: you cannot change a partition into an extended one or vice versa
* Fri Jun 19 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.26.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild