kumquat-buildroot/package/util-linux/0004-libfdisk-add-fdisk_set_disklabel_id_from_string.patch
Carlos Santos 4f3af906fb package/util-linux: bump to version 2.35
This version brings bug fixes, enhancements and a new script utility,
scriptlive. For detailed information see the release notes:

  http://www.kernel.org/pub/linux/utils/util-linux/v2.35/v2.35-ReleaseNotes

Pull some fixed applied after the release.

Disable the use of code under GPLv3 included in hwclock since v2.30. The
subject was discussed upstream[1] and it was decided that hwclock will
be made GPLv2-only again in v2.36, so do it in advance in Buildroot.

Meanwhile, be warned that all OS images selecting hwclock built with
Buildroot since commit 74235a6854 (util-linux: bump to version 2.30)
contain code under GPLv3, which imposes some technical difficulties to
include in embedded systems. For more information see GPLv3, Section 6,
"Conveying Non-Source Forms", and the definitions of User Product and
Installation Information[2].

1. https://lore.kernel.org/util-linux/20200127202152.4jh2w4chch37wgee@ws.net.home/T/#t
2. https://www.gnu.org/licenses/gpl-3.0.html

Signed-off-by: Carlos Santos <unixmania@gmail.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2020-02-02 14:20:26 +01:00

195 lines
5.9 KiB
Diff

From e5f31446166de7212213c62a019945afb8e197ef Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Tue, 14 Jan 2020 11:43:24 +0100
Subject: [PATCH] libfdisk: add fdisk_set_disklabel_id_from_string()
We have fdisk_set_disklabel_id(), but it's old ask-API based function.
It's not comfortable if you want to avoid dialog or template.
Addresses: https://github.com/karelzak/util-linux/issues/916
Signed-off-by: Karel Zak <kzak@redhat.com>
---
libfdisk/docs/libfdisk-sections.txt | 1 +
libfdisk/src/dos.c | 29 ++++++++++++++++++-----------
libfdisk/src/fdiskP.h | 2 +-
libfdisk/src/gpt.c | 18 ++++++++++--------
libfdisk/src/label.c | 19 ++++++++++++++++++-
libfdisk/src/libfdisk.h.in | 1 +
libfdisk/src/libfdisk.sym | 3 +++
7 files changed, 52 insertions(+), 21 deletions(-)
diff --git a/libfdisk/docs/libfdisk-sections.txt b/libfdisk/docs/libfdisk-sections.txt
index f148da527..6675c1100 100644
--- a/libfdisk/docs/libfdisk-sections.txt
+++ b/libfdisk/docs/libfdisk-sections.txt
@@ -81,6 +81,7 @@ fdisk_list_disklabel
fdisk_locate_disklabel
fdisk_reorder_partitions
fdisk_set_disklabel_id
+fdisk_set_disklabel_id_from_string
fdisk_set_partition_type
fdisk_toggle_partition_flag
fdisk_verify_disklabel
diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c
index 53713ec5f..98314dfa6 100644
--- a/libfdisk/src/dos.c
+++ b/libfdisk/src/dos.c
@@ -707,12 +707,12 @@ static int dos_create_disklabel(struct fdisk_context *cxt)
return 0;
}
-static int dos_set_disklabel_id(struct fdisk_context *cxt)
+static int dos_set_disklabel_id(struct fdisk_context *cxt, const char *str)
{
- char *end = NULL, *str = NULL;
+ char *str0 = str;
unsigned int id, old;
struct fdisk_dos_label *l;
- int rc;
+ int rc = 0;
assert(cxt);
assert(cxt->label);
@@ -722,18 +722,25 @@ static int dos_set_disklabel_id(struct fdisk_context *cxt)
l = self_label(cxt);
old = mbr_get_id(cxt->firstsector);
- rc = fdisk_ask_string(cxt,
+
+ if (!str)
+ rc = fdisk_ask_string(cxt,
_("Enter the new disk identifier"), &str);
- if (rc)
- return rc;
+ if (!rc) {
+ char *end = NULL;
- errno = 0;
- id = strtoul(str, &end, 0);
- if (errno || str == end || (end && *end)) {
- fdisk_warnx(cxt, _("Incorrect value."));
- return -EINVAL;
+ errno = 0;
+ id = strtoul(str, &end, 0);
+ if (errno || str == end || (end && *end)) {
+ fdisk_warnx(cxt, _("Incorrect value."));
+ rc = -EINVAL;
+ }
}
+ if (!str0)
+ free(str);
+ if (rc)
+ return -EINVAL;
mbr_set_id(cxt->firstsector, id);
l->non_pt_changed = 1;
diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h
index fefebae2a..0487466e3 100644
--- a/libfdisk/src/fdiskP.h
+++ b/libfdisk/src/fdiskP.h
@@ -220,7 +220,7 @@ struct fdisk_label_operations {
/* get details from label */
int (*get_item)(struct fdisk_context *cxt, struct fdisk_labelitem *item);
/* set disk label ID */
- int (*set_id)(struct fdisk_context *cxt);
+ int (*set_id)(struct fdisk_context *cxt, const char *str);
/* new partition */
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index f50bb4441..9608053a2 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -2502,11 +2502,11 @@ done:
return rc;
}
-static int gpt_set_disklabel_id(struct fdisk_context *cxt)
+static int gpt_set_disklabel_id(struct fdisk_context *cxt, const char *str)
{
struct fdisk_gpt_label *gpt;
struct gpt_guid uuid;
- char *str, *old, *new;
+ char *old, *new;
int rc;
assert(cxt);
@@ -2514,12 +2514,14 @@ static int gpt_set_disklabel_id(struct fdisk_context *cxt)
assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
- if (fdisk_ask_string(cxt,
- _("Enter new disk UUID (in 8-4-4-4-12 format)"), &str))
- return -EINVAL;
-
- rc = string_to_guid(str, &uuid);
- free(str);
+ if (!str) {
+ if (fdisk_ask_string(cxt,
+ _("Enter new disk UUID (in 8-4-4-4-12 format)"), &str))
+ return -EINVAL;
+ rc = string_to_guid(str, &uuid);
+ free(str);
+ } else
+ rc = string_to_guid(str, &uuid);
if (rc) {
fdisk_warnx(cxt, _("Failed to parse your UUID."));
diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c
index a18cdeaff..fd4555de2 100644
--- a/libfdisk/src/label.c
+++ b/libfdisk/src/label.c
@@ -481,7 +481,24 @@ int fdisk_set_disklabel_id(struct fdisk_context *cxt)
return -ENOSYS;
DBG(CXT, ul_debugobj(cxt, "setting %s disk ID", cxt->label->name));
- return cxt->label->op->set_id(cxt);
+ return cxt->label->op->set_id(cxt, NULL);
+}
+
+/**
+ * fdisk_set_disklabel_id_from_string
+ * @cxt: fdisk context
+ *
+ * Returns: 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_set_disklabel_id_from_string(struct fdisk_context *cxt, const char *str)
+{
+ if (!cxt || !cxt->label || !str)
+ return -EINVAL;
+ if (!cxt->label->op->set_id)
+ return -ENOSYS;
+
+ DBG(CXT, ul_debugobj(cxt, "setting %s disk ID from '%s'", cxt->label->name, str));
+ return cxt->label->op->set_id(cxt, str);
}
/**
diff --git a/libfdisk/src/libfdisk.h.in b/libfdisk/src/libfdisk.h.in
index 0669c0a7c..2ba34dc0a 100644
--- a/libfdisk/src/libfdisk.h.in
+++ b/libfdisk/src/libfdisk.h.in
@@ -399,6 +399,7 @@ extern int fdisk_get_disklabel_item(struct fdisk_context *cxt, int id, struct fd
extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);
+extern int fdisk_set_disklabel_id_from_string(struct fdisk_context *cxt, const char *str);
extern int fdisk_get_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition **pa);
extern int fdisk_set_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition *pa);
diff --git a/libfdisk/src/libfdisk.sym b/libfdisk/src/libfdisk.sym
index 96fcadd71..eee2d6bda 100644
--- a/libfdisk/src/libfdisk.sym
+++ b/libfdisk/src/libfdisk.sym
@@ -308,3 +308,6 @@ FDISK_2.35 {
fdisk_script_set_table;
fdisk_assign_device_by_fd;
} FDISK_2.33;
+FDISK_2.36 {
+ fdisk_set_disklabel_id_from_string;
+} FDISK_2.35;
--
2.18.2