summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVince Chang <vince_chang@aspeedtech.com>2024-10-17 16:40:02 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-10-22 12:28:18 +0100
commitbada33690472f6e4a633f7b3c6a3f1aaa5c7518c (patch)
treefc9567c02271b3c94e77eb3699eb008eb8cb78a1
parent120400663a617bfffa286e7f134e7587825154a1 (diff)
downloadpoky-bada33690472f6e4a633f7b3c6a3f1aaa5c7518c.tar.gz
util-linux: sfdisk sector size improvements
Refer to https://github.com/util-linux/util-linux/pull/3237. (From OE-Core rev: 7e37e0addeae3ade4d1634697cde5c8cc619c46a) Signed-off-by: Vince Chang <vince_chang@aspeedtech.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/util-linux/util-linux.inc1
-rw-r--r--meta/recipes-core/util-linux/util-linux/libfdisk-cfdisk-and-sfdisk-sector-size-improvements.patch252
2 files changed, 253 insertions, 0 deletions
diff --git a/meta/recipes-core/util-linux/util-linux.inc b/meta/recipes-core/util-linux/util-linux.inc
index ff47131d12..1c066631f3 100644
--- a/meta/recipes-core/util-linux/util-linux.inc
+++ b/meta/recipes-core/util-linux/util-linux.inc
@@ -39,6 +39,7 @@ SRC_URI = "${KERNELORG_MIRROR}/linux/utils/util-linux/v${MAJOR_VERSION}/util-lin
39 file://avoid_parallel_tests.patch \ 39 file://avoid_parallel_tests.patch \
40 file://fcntl-lock.c \ 40 file://fcntl-lock.c \
41 file://0001-Revert-autotools-make-pam-install-path-configurable.patch \ 41 file://0001-Revert-autotools-make-pam-install-path-configurable.patch \
42 file://libfdisk-cfdisk-and-sfdisk-sector-size-improvements.patch \
42 " 43 "
43 44
44SRC_URI[sha256sum] = "d78b37a66f5922d70edf3bdfb01a6b33d34ed3c3cafd6628203b2a2b67c8e8b3" 45SRC_URI[sha256sum] = "d78b37a66f5922d70edf3bdfb01a6b33d34ed3c3cafd6628203b2a2b67c8e8b3"
diff --git a/meta/recipes-core/util-linux/util-linux/libfdisk-cfdisk-and-sfdisk-sector-size-improvements.patch b/meta/recipes-core/util-linux/util-linux/libfdisk-cfdisk-and-sfdisk-sector-size-improvements.patch
new file mode 100644
index 0000000000..356194a8ba
--- /dev/null
+++ b/meta/recipes-core/util-linux/util-linux/libfdisk-cfdisk-and-sfdisk-sector-size-improvements.patch
@@ -0,0 +1,252 @@
1From 7ada6547fcd1f649fadaa8021ff21e3e0f431459 Mon Sep 17 00:00:00 2001
2From: Karel Zak <kzak@redhat.com>
3Date: Mon, 14 Oct 2024 11:45:32 +0200
4Subject: [PATCH 1/4] libfdisk: make sure libblkid uses the same sector size
5
6Libfdisk uses libblkid to check for filesystems on the device. It
7makes sense for both libraries to share the logical sector size
8setting, as this setting can be modified by using the fdisk command
9line.
10
11We do not see this as an issue, as filesystem detection rarely depends
12on sector size (with the exception of some RAIDs). Additionally,
13libblkid is usually intelligent enough to check multiple locations
14independently of the current device's sector size setting.
15
16Addresses: https://github.com/util-linux/util-linux/pull/3235
17
18Upstream-Status: Submitted [https://github.com/util-linux/util-linux/pull/3237]
19
20Signed-off-by: Karel Zak <kzak@redhat.com>
21---
22 libfdisk/src/wipe.c | 3 +++
23 1 file changed, 3 insertions(+)
24
25diff --git a/libfdisk/src/wipe.c b/libfdisk/src/wipe.c
26index bb5f1bb38bf..f389ed4194a 100644
27--- a/libfdisk/src/wipe.c
28+++ b/libfdisk/src/wipe.c
29@@ -133,6 +133,7 @@ int fdisk_do_wipe(struct fdisk_context *cxt)
30 DBG(WIPE, ul_debugobj(wp, "blkid_probe_set_device() failed [rc=%d]", rc));
31 return rc;
32 }
33+ blkid_probe_set_sectorsize(pr, cxt->sector_size);
34
35 DBG(WIPE, ul_debugobj(wp, " wiping..."));
36 blkid_wipe_all(pr);
37@@ -176,6 +177,8 @@ int fdisk_check_collisions(struct fdisk_context *cxt)
38 free(cxt->collision);
39 cxt->collision = NULL;
40
41+ blkid_probe_set_sectorsize(pr, cxt->sector_size);
42+
43 blkid_probe_enable_superblocks(pr, 1);
44 blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_TYPE |
45 BLKID_SUBLKS_BADCSUM);
46
47From 54f9a79301dcf492cab8e07134f96a921d367aa0 Mon Sep 17 00:00:00 2001
48From: Karel Zak <kzak@redhat.com>
49Date: Mon, 14 Oct 2024 15:47:03 +0200
50Subject: [PATCH 2/4] fdisk: (man) improve --sector-size description
51
52Signed-off-by: Karel Zak <kzak@redhat.com>
53---
54 disk-utils/fdisk.8.adoc | 2 +-
55 1 file changed, 1 insertion(+), 1 deletion(-)
56
57diff --git a/disk-utils/fdisk.8.adoc b/disk-utils/fdisk.8.adoc
58index cb72b4a3ea5..5941aa34968 100644
59--- a/disk-utils/fdisk.8.adoc
60+++ b/disk-utils/fdisk.8.adoc
61@@ -40,7 +40,7 @@ Note that *partx*(8) provides a rich interface for scripts to print disk layouts
62 == OPTIONS
63
64 *-b*, *--sector-size* _sectorsize_::
65-Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096. (Recent kernels know the sector size. Use this option only on old kernels or to override the kernel's ideas.) Since util-linux-2.17, *fdisk* differentiates between logical and physical sector size. This option changes both sector sizes to _sectorsize_.
66+Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096. The kernel is aware of the sector size for regular block devices. Use this option only on very old kernels, when working with disk images, or to override the kernel's default sector size. Since util-linux-2.17, *fdisk* distinguishes between logical and physical sector size. This option changes both sector sizes to the specified _sectorsize_.
67
68 *-B*, *--protect-boot*::
69 Don't erase the beginning of the first disk sector when creating a new disk label. This feature is supported for GPT and MBR.
70
71From fd38ee2274f7a30393d3839dfce556260355c3fa Mon Sep 17 00:00:00 2001
72From: Karel Zak <kzak@redhat.com>
73Date: Mon, 14 Oct 2024 15:48:46 +0200
74Subject: [PATCH 3/4] cfdisk: add --sector-size commanand line option
75
76* improves compatibility with fdisk
77* add ability to work with disk images where libfdisk defaults to 512
78
79Signed-off-by: Karel Zak <kzak@redhat.com>
80---
81 disk-utils/cfdisk.8.adoc | 3 +++
82 disk-utils/cfdisk.c | 15 ++++++++++++++-
83 2 files changed, 17 insertions(+), 1 deletion(-)
84
85diff --git a/disk-utils/cfdisk.8.adoc b/disk-utils/cfdisk.8.adoc
86index 97fad621d12..759f39f0e1a 100644
87--- a/disk-utils/cfdisk.8.adoc
88+++ b/disk-utils/cfdisk.8.adoc
89@@ -55,6 +55,9 @@ Use exclusive BSD lock for device or file it operates. The optional argument _mo
90 *-r*, *--read-only*::
91 Forced open in read-only mode.
92
93+*-b*, *--sector-size* _sectorsize_::
94+Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096. The kernel is aware of the sector size for regular block devices. Use this option only on very old kernels, when working with disk images, or to override the kernel's default sector size. Since util-linux-2.17, *fdisk* distinguishes between logical and physical sector size. This option changes both sector sizes to the specified _sectorsize_.
95+
96 *-z*, *--zero*::
97 Start with an in-memory zeroed partition table. This option does not zero the partition table on the disk; rather, it simply starts the program without reading the existing partition table. This option allows you to create a new partition table from scratch or from an *sfdisk*(8)-compatible script.
98
99diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
100index 2e0aada474a..bc1c87d83e4 100644
101--- a/disk-utils/cfdisk.c
102+++ b/disk-utils/cfdisk.c
103@@ -2731,6 +2731,8 @@ static void __attribute__((__noreturn__)) usage(void)
104 _(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
105 fputs(_(" -r, --read-only forced open cfdisk in read-only mode\n"), out);
106
107+ fputs(_(" -b, --sector-size <size> physical and logical sector size\n"), out);
108+
109 fputs(USAGE_SEPARATOR, out);
110 fprintf(out, USAGE_HELP_OPTIONS(26));
111
112@@ -2743,6 +2745,7 @@ int main(int argc, char *argv[])
113 const char *diskpath = NULL, *lockmode = NULL;
114 int rc, c, colormode = UL_COLORMODE_UNDEF;
115 int read_only = 0;
116+ size_t user_ss = 0;
117 struct cfdisk _cf = { .lines_idx = 0 },
118 *cf = &_cf;
119 enum {
120@@ -2752,6 +2755,7 @@ int main(int argc, char *argv[])
121 { "color", optional_argument, NULL, 'L' },
122 { "lock", optional_argument, NULL, OPT_LOCK },
123 { "help", no_argument, NULL, 'h' },
124+ { "sector-size", required_argument, NULL, 'b' },
125 { "version", no_argument, NULL, 'V' },
126 { "zero", no_argument, NULL, 'z' },
127 { "read-only", no_argument, NULL, 'r' },
128@@ -2763,8 +2767,15 @@ int main(int argc, char *argv[])
129 textdomain(PACKAGE);
130 close_stdout_atexit();
131
132- while((c = getopt_long(argc, argv, "L::hVzr", longopts, NULL)) != -1) {
133+ while((c = getopt_long(argc, argv, "b:L::hVzr", longopts, NULL)) != -1) {
134 switch(c) {
135+ case 'b':
136+ user_ss = strtou32_or_err(optarg,
137+ _("invalid sector size argument"));
138+ if (user_ss != 512 && user_ss != 1024 &&
139+ user_ss != 2048 && user_ss != 4096)
140+ errx(EXIT_FAILURE, _("invalid sector size argument"));
141+ break;
142 case 'h':
143 usage();
144 break;
145@@ -2803,6 +2814,8 @@ int main(int argc, char *argv[])
146 cf->cxt = fdisk_new_context();
147 if (!cf->cxt)
148 err(EXIT_FAILURE, _("failed to allocate libfdisk context"));
149+ if (user_ss)
150+ fdisk_save_user_sector_size(cf->cxt, user_ss, user_ss);
151
152 fdisk_set_ask(cf->cxt, ask_callback, (void *) cf);
153
154
155From ef7b76baa17ddb5414691fa8f49d61415c30871c Mon Sep 17 00:00:00 2001
156From: Karel Zak <kzak@redhat.com>
157Date: Mon, 14 Oct 2024 15:50:40 +0200
158Subject: [PATCH 4/4] sfdisk: add --sector-size commanand line option
159
160* improves compatibility with fdisk
161* add ability to work with disk images where libfdisk defaults to 512
162
163Addresses: https://github.com/util-linux/util-linux/pull/3235
164Signed-off-by: Karel Zak <kzak@redhat.com>
165---
166 disk-utils/sfdisk.8.adoc | 5 ++++-
167 disk-utils/sfdisk.c | 14 ++++++++++++++
168 2 files changed, 18 insertions(+), 1 deletion(-)
169
170diff --git a/disk-utils/sfdisk.8.adoc b/disk-utils/sfdisk.8.adoc
171index 26ccad5a3b2..ce9e97b7682 100644
172--- a/disk-utils/sfdisk.8.adoc
173+++ b/disk-utils/sfdisk.8.adoc
174@@ -208,6 +208,9 @@ The default list of columns may be extended if _list_ is specified in the format
175 *-q*, *--quiet*::
176 Suppress extra info messages.
177
178+*--sector-size* _sectorsize_::
179+Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096. The kernel is aware of the sector size for regular block devices. Use this option only on very old kernels, when working with disk images, or to override the kernel's default sector size. Since util-linux-2.17, *fdisk* distinguishes between logical and physical sector size. This option changes both sector sizes to the specified _sectorsize_.
180+
181 *-u*, *--unit S*::
182 Deprecated option. Only the sector unit is supported. This option is not supported when using the *--show-size* command.
183
184@@ -256,7 +259,7 @@ Specify the maximal number of GPT partitions.
185 *grain*::
186 Specify minimal size in bytes used to calculate partitions alignment. The default is 1MiB and it's strongly recommended to use the default. Do not modify this variable if you're not sure.
187 *sector-size*::
188-Specify sector size. *sfdisk* always uses device sector size. Since version 2.39 *sfdisk* recalculates sizes from dump if the script and device sector size differ.
189+Specifies the sector size used in the input. *sfdisk* always internally uses the device sector size provided by the kernel for the block device, or as specified by the user on the command line (see *--sector-size*). Starting with version 2.39, *sfdisk* recalculates sizes from the input if the *sector-size* header and device sector size are different.
190
191 Note that it is only possible to use header lines before the first partition is specified in the input.
192
193diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
194index cf402007b51..5e7c1d926e4 100644
195--- a/disk-utils/sfdisk.c
196+++ b/disk-utils/sfdisk.c
197@@ -2155,6 +2155,8 @@ static void __attribute__((__noreturn__)) usage(void)
198 _(" --color[=<when>] colorize output (%s, %s or %s)\n"), "auto", "always", "never");
199 fprintf(out,
200 " %s\n", USAGE_COLORS_DEFAULT);
201+ fputs(_(" --sector-size <size> physical and logical sector size\n"), out);
202+
203 fprintf(out,
204 _(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
205 fputs(_(" -N, --partno <num> specify partition number\n"), out);
206@@ -2191,6 +2193,7 @@ int main(int argc, char *argv[])
207 const char *outarg = NULL;
208 int rc = -EINVAL, c, longidx = -1, bytes = 0;
209 int colormode = UL_COLORMODE_UNDEF;
210+ size_t user_ss = 0;
211 struct sfdisk _sf = {
212 .partno = -1,
213 .wipemode = WIPEMODE_AUTO,
214@@ -2217,6 +2220,7 @@ int main(int argc, char *argv[])
215 OPT_NOTELL,
216 OPT_RELOCATE,
217 OPT_LOCK,
218+ OPT_SECTORSIZE
219 };
220
221 static const struct option longopts[] = {
222@@ -2246,6 +2250,7 @@ int main(int argc, char *argv[])
223 { "output", required_argument, NULL, 'o' },
224 { "partno", required_argument, NULL, 'N' },
225 { "reorder", no_argument, NULL, 'r' },
226+ { "sector-size", required_argument, NULL, OPT_SECTORSIZE },
227 { "show-geometry", no_argument, NULL, 'g' },
228 { "quiet", no_argument, NULL, 'q' },
229 { "verify", no_argument, NULL, 'V' },
230@@ -2450,6 +2455,13 @@ int main(int argc, char *argv[])
231 sf->lockmode = optarg;
232 }
233 break;
234+ case OPT_SECTORSIZE:
235+ user_ss = strtou32_or_err(optarg,
236+ _("invalid sector size argument"));
237+ if (user_ss != 512 && user_ss != 1024 &&
238+ user_ss != 2048 && user_ss != 4096)
239+ errx(EXIT_FAILURE, _("invalid sector size argument"));
240+ break;
241 default:
242 errtryhelp(EXIT_FAILURE);
243 }
244@@ -2460,6 +2472,8 @@ int main(int argc, char *argv[])
245 sfdisk_init(sf);
246 if (bytes)
247 fdisk_set_size_unit(sf->cxt, FDISK_SIZEUNIT_BYTES);
248+ if (user_ss)
249+ fdisk_save_user_sector_size(sf->cxt, user_ss, user_ss);
250
251 if (outarg)
252 init_fields(NULL, outarg, NULL);