- tests: Add a test for resizepart on a busy partition (bcl)

- parted: Preserve resizepart End when prompted for busy partition (bcl)
- tests: Add f2fs to the fs probe test (romain.perier)
- Add support for the F2FS filesystem (romain.perier)
- Removed reference to ped_file_system_create (max)
This commit is contained in:
Brian C. Lane 2020-09-25 10:13:17 -07:00
parent 7bd556f35f
commit 0dd29ac6e1
6 changed files with 408 additions and 1 deletions

View File

@ -0,0 +1,29 @@
From 8c50fec522f475c51e2aaa3c972ce4c6690dda92 Mon Sep 17 00:00:00 2001
From: Max Campbell <max@0m.ax>
Date: Thu, 12 Dec 2019 16:54:29 +0100
Subject: [PATCH 08/12] Removed reference to ped_file_system_create
Removed a reference to the removed function ped_file_system_create in
the docs for ped_file_system_clobber.
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
libparted/fs/r/filesys.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/libparted/fs/r/filesys.c b/libparted/fs/r/filesys.c
index d57447c..dd316aa 100644
--- a/libparted/fs/r/filesys.c
+++ b/libparted/fs/r/filesys.c
@@ -213,8 +213,6 @@ error_close_dev:
* file system occupies a given region described by \p geom.
* After this operation ped_file_system_probe() won't detect any file system.
*
- * \note ped_file_system_create() calls this before creating a new file system.
- *
* \return \c 1 on success, \c 0 on failure
*/
static int
--
2.26.2

View File

@ -0,0 +1,201 @@
From c6b61814cd4cf958e12d35a36184ff7d767e57d9 Mon Sep 17 00:00:00 2001
From: Romain Perier <romain.perier@gmail.com>
Date: Fri, 20 Mar 2020 17:43:16 +0100
Subject: [PATCH 09/12] Add support for the F2FS filesystem
This adds a basic support for the Flash-Friendly File System. So
we can manipulate the file system by using the PedFileSystem API and we
can do basic device probing for autodetecting the current fs.
Signed-off-by: Romain Perier <romain.perier@gmail.com>
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
libparted/fs/Makefile.am | 2 ++
libparted/fs/f2fs/f2fs.c | 60 ++++++++++++++++++++++++++++++++++++++++
libparted/fs/f2fs/f2fs.h | 57 ++++++++++++++++++++++++++++++++++++++
libparted/libparted.c | 4 +++
4 files changed, 123 insertions(+)
create mode 100644 libparted/fs/f2fs/f2fs.c
create mode 100644 libparted/fs/f2fs/f2fs.h
diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
index 74f275a..e40eee8 100644
--- a/libparted/fs/Makefile.am
+++ b/libparted/fs/Makefile.am
@@ -32,6 +32,8 @@ libfs_la_SOURCES = \
fat/count.h \
fat/fat.c \
fat/fat.h \
+ f2fs/f2fs.c \
+ f2fs/f2fs.h \
hfs/hfs.c \
hfs/hfs.h \
hfs/probe.c \
diff --git a/libparted/fs/f2fs/f2fs.c b/libparted/fs/f2fs/f2fs.c
new file mode 100644
index 0000000..64883e9
--- /dev/null
+++ b/libparted/fs/f2fs/f2fs.c
@@ -0,0 +1,60 @@
+/*
+ libparted/fs/f2fs - Flash-Friendly File System
+ Copyright (C) 2020 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
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+
+#include <parted/parted.h>
+#include <parted/endian.h>
+
+#include "f2fs.h"
+
+static PedGeometry*
+f2fs_probe (PedGeometry* geom)
+{
+ struct f2fs_super_block *sb = alloca(geom->dev->sector_size);
+
+ if (!ped_geometry_read (geom, sb, F2FS_SB_OFFSET, 1))
+ return NULL;
+
+ if (PED_LE32_TO_CPU(sb->magic) == F2FS_MAGIC)
+ return ped_geometry_new (geom->dev, geom->start, geom->length);
+
+ return NULL;
+}
+
+static PedFileSystemOps f2fs_ops = {
+ probe: f2fs_probe,
+};
+
+static PedFileSystemType f2fs_type = {
+ next: NULL,
+ ops: &f2fs_ops,
+ name: "f2fs",
+};
+
+void
+ped_file_system_f2fs_init ()
+{
+ ped_file_system_type_register (&f2fs_type);
+}
+
+void
+ped_file_system_f2fs_done ()
+{
+ ped_file_system_type_unregister (&f2fs_type);
+}
diff --git a/libparted/fs/f2fs/f2fs.h b/libparted/fs/f2fs/f2fs.h
new file mode 100644
index 0000000..c96b88f
--- /dev/null
+++ b/libparted/fs/f2fs/f2fs.h
@@ -0,0 +1,57 @@
+/*
+ libparted/fs/f2fs - Flash-Friendly File System
+ Copyright (C) 2020 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
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef _F2FS_H
+#define _F2FS_H
+
+#define F2FS_MAGIC 0xF2F52010
+#define F2FS_MAX_VOLUME_NAME 512
+#define F2FS_SB_OFFSET 0x02
+
+struct f2fs_super_block {
+ uint32_t magic; /* Magic Number */
+ uint16_t major_ver; /* Major Version */
+ uint16_t minor_ver; /* Minor Version */
+ uint32_t log_sectorsize; /* log2 sector size in bytes */
+ uint32_t log_sectors_per_block; /* log2 # of sectors per block */
+ uint32_t log_blocksize; /* log2 block size in bytes */
+ uint32_t log_blocks_per_seg; /* log2 # of blocks per segment */
+ uint32_t segs_per_sec; /* # of segments per section */
+ uint32_t secs_per_zone; /* # of sections per zone */
+ uint32_t checksum_offset; /* checksum offset inside super block */
+ uint64_t block_count; /* total # of user blocks */
+ uint32_t section_count; /* total # of sections */
+ uint32_t segment_count; /* total # of segments */
+ uint32_t segment_count_ckpt; /* # of segments for checkpoint */
+ uint32_t segment_count_sit; /* # of segments for SIT */
+ uint32_t segment_count_nat; /* # of segments for NAT */
+ uint32_t segment_count_ssa; /* # of segments for SSA */
+ uint32_t segment_count_main; /* # of segments for main area */
+ uint32_t segment0_blkaddr; /* start block address of segment 0 */
+ uint32_t cp_blkaddr; /* start block address of checkpoint */
+ uint32_t sit_blkaddr; /* start block address of SIT */
+ uint32_t nat_blkaddr; /* start block address of NAT */
+ uint32_t ssa_blkaddr; /* start block address of SSA */
+ uint32_t main_blkaddr; /* start block address of main area */
+ uint32_t root_ino; /* root inode number */
+ uint32_t node_ino; /* node inode number */
+ uint32_t meta_ino; /* meta inode number */
+ uint8_t uuid[16]; /* 128-bit uuid for volume */
+ uint16_t volume_name[F2FS_MAX_VOLUME_NAME]; /* volume name */
+} __attribute__((packed));
+
+#endif
diff --git a/libparted/libparted.c b/libparted/libparted.c
index 00f5ff8..4a57a80 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -109,6 +109,7 @@ extern void ped_file_system_linux_swap_init (void);
extern void ped_file_system_jfs_init (void);
extern void ped_file_system_hfs_init (void);
extern void ped_file_system_fat_init (void);
+extern void ped_file_system_f2fs_init (void);
extern void ped_file_system_ext2_init (void);
extern void ped_file_system_nilfs2_init (void);
extern void ped_file_system_btrfs_init (void);
@@ -126,6 +127,7 @@ init_file_system_types ()
ped_file_system_jfs_init ();
ped_file_system_hfs_init ();
ped_file_system_fat_init ();
+ ped_file_system_f2fs_init ();
ped_file_system_ext2_init ();
ped_file_system_nilfs2_init ();
ped_file_system_btrfs_init ();
@@ -186,6 +188,7 @@ _init()
extern void ped_file_system_nilfs2_done (void);
extern void ped_file_system_ext2_done (void);
extern void ped_file_system_fat_done (void);
+extern void ped_file_system_f2fs_done (void);
extern void ped_file_system_hfs_done (void);
extern void ped_file_system_jfs_done (void);
extern void ped_file_system_linux_swap_done (void);
@@ -202,6 +205,7 @@ done_file_system_types ()
{
ped_file_system_nilfs2_done ();
ped_file_system_ext2_done ();
+ ped_file_system_f2fs_done ();
ped_file_system_fat_done ();
ped_file_system_hfs_done ();
ped_file_system_jfs_done ();
--
2.26.2

View File

@ -0,0 +1,27 @@
From eaada0bc9e1cc8adb3a0260707d9474a3e01b835 Mon Sep 17 00:00:00 2001
From: Romain Perier <romain.perier@gmail.com>
Date: Fri, 20 Mar 2020 17:43:17 +0100
Subject: [PATCH 10/12] tests: Add f2fs to the fs probe test
Signed-off-by: Romain Perier <romain.perier@gmail.com>
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
tests/t1700-probe-fs.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/t1700-probe-fs.sh b/tests/t1700-probe-fs.sh
index 1fe3309..9150a37 100755
--- a/tests/t1700-probe-fs.sh
+++ b/tests/t1700-probe-fs.sh
@@ -23,7 +23,7 @@ dev=loop-file
ss=$sector_size_
n_sectors=$((512*1024))
-for type in ext2 ext3 ext4 btrfs xfs nilfs2 ntfs vfat hfsplus udf; do
+for type in ext2 ext3 ext4 btrfs xfs nilfs2 ntfs vfat hfsplus udf f2fs; do
( mkfs.$type 2>&1 | grep -i '^usage' ) > /dev/null \
|| { warn_ "$ME: no $type support"; continue; }
--
2.26.2

View File

@ -0,0 +1,53 @@
From 691dabc930a6d544dfd8da787cddd159bab34b1e Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Mon, 31 Aug 2020 16:40:07 -0700
Subject: [PATCH 11/12] parted: Preserve resizepart End when prompted for busy
partition
Resizing busy partitions is allowed, but the user is prompted, which
erases the cmdline. It is annoying to have to re-end the ending location
after answering Yes. This saves the word and pushes it back onto the
cmdline after the user agrees to resize the busy partition.
---
parted/parted.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/parted/parted.c b/parted/parted.c
index df0c7ed..dbd38d0 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1546,6 +1546,7 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
PedConstraint* constraint;
int rc = 0;
char* end_input = NULL;
+ char* end_size = NULL;
if (!disk) {
disk = ped_disk_new (*dev);
@@ -1561,9 +1562,23 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
if (!command_line_get_partition (_("Partition number?"), disk, &part))
goto error;
+
+ /* Save the optional End value if the partition is busy. */
+ if (ped_partition_is_busy(part)) {
+ if (command_line_get_word_count())
+ end_size = command_line_pop_word();
+ }
+
+ /* If the partition is busy this may clear the command_line and prompt the user */
if (!_partition_warn_busy (part))
goto error;
+ /* Push the End value back onto the command_line, if it exists */
+ if (end_size) {
+ command_line_push_word(end_size);
+ free(end_size);
+ }
+
start = part->geom.start;
end = oldend = part->geom.end;
if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, &end_input))
--
2.26.2

View File

@ -0,0 +1,85 @@
From dfc611bd5126840d68493ad0e761511a71325af7 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Tue, 1 Sep 2020 14:51:54 -0700
Subject: [PATCH 12/12] tests: Add a test for resizepart on a busy partition
This makes sure that the resizepart on a busy partition with the size on
the cmdline will work.
---
tests/t3200-resize-partition.sh | 44 ++++++++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 4 deletions(-)
diff --git a/tests/t3200-resize-partition.sh b/tests/t3200-resize-partition.sh
index 06dbe68..2200977 100755
--- a/tests/t3200-resize-partition.sh
+++ b/tests/t3200-resize-partition.sh
@@ -2,7 +2,7 @@
# exercise the resize sub-command
# based on t3000-resize-fs.sh test
-# Copyright (C) 2009-2011, 2019 Free Software Foundation, Inc.
+# Copyright (C) 2009-2020 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
@@ -66,8 +66,8 @@ sleep 1
# Running it without end should not core-dump or prompt
parted -s $dev resizepart 1 > out 2> err || fail=1
-# extend the filesystem to end on sector 4096
-new_end=4096s
+# extend the filesystem to end on sector 2048
+new_end=2048s
parted -s $dev resizepart 1 $new_end > out 2> err || fail=1
# expect no output
compare /dev/null out || fail=1
@@ -77,9 +77,45 @@ compare /dev/null err || fail=1
parted -m -s $dev u s p > out 2>&1 || fail=1
sed -n 3p out > k && mv k out || fail=1
-printf "1:$default_start:$new_end:3073s:::$ms;\n" > exp || fail=1
+printf "1:$default_start:$new_end:1025s:::$ms;\n" > exp || fail=1
compare exp out || fail=1
+## Make sure resizing a busy partition works when user answers 'yes'
+# Format the partition and mount it for the busy check
+mkfs.ext4 "${dev}1" || skip_ mkfs.ext4 failed
+
+# be sure to unmount upon interrupt, failure, etc.
+cleanup_fn_() { umount "${dev}1" > /dev/null 2>&1; }
+
+mount_point=$(pwd)/mnt
+
+mkdir $mount_point || fail=1
+mount "${dev}1" "$mount_point" || fail=1
+
+# extend the filesystem to end on sector 4096
+new_end=4096s
+echo yes | parted ---pretend-input-tty $dev resizepart 1 $new_end > out 2>&1
+cat > exp <<EOF
+Warning: Partition ${dev}1 is being used. Are you sure you want to continue?
+Yes/No? yes
+Information: You may need to update /etc/fstab.
+
+EOF
+# Transform the actual output, to avoid spurious differences when
+# $PWD contains a symlink-to-dir. Also, remove the ^M ...^M bogosity.
+# normalize the actual output
+mv out o2 && sed -e "s, * ,,g;s, $,," o2 > out
+compare exp out || fail=1
+
+# print partition table
+parted -m -s $dev u s p > out 2>&1 || fail=1
+
+sed -n 3p out > k && mv k out || fail=1
+printf "1:$default_start:$new_end:3073s:ext2::$ms;\n" > exp || fail=1
+compare exp out || fail=1
+
+umount "${dev}1" || fail=1
+
# Remove the partition explicitly, so that mklabel doesn't evoke a warning.
parted -s $dev rm 1 || fail=1
--
2.26.2

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 3.3
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv3+
URL: http://www.gnu.org/software/parted
@ -20,6 +20,11 @@ Patch0003: 0004-Fix-end_input-usage-in-do_resizepart.patch
Patch0004: 0005-libparted-Add-ChromeOS-Kernel-partition-flag.patch
Patch0005: 0006-libparted-Add-support-for-MSDOS-partition-type-bls_b.patch
Patch0006: 0007-libparted-Add-support-for-bls_boot-to-GPT-disks.patch
Patch0007: 0008-Removed-reference-to-ped_file_system_create.patch
Patch0008: 0009-Add-support-for-the-F2FS-filesystem.patch
Patch0009: 0010-tests-Add-f2fs-to-the-fs-probe-test.patch
Patch0010: 0011-parted-Preserve-resizepart-End-when-prompted-for-bus.patch
Patch0011: 0012-tests-Add-a-test-for-resizepart-on-a-busy-partition.patch
BuildRequires: gcc
BuildRequires: e2fsprogs-devel
@ -124,6 +129,13 @@ make check
%changelog
* Fri Sep 25 2020 Brian C. Lane <bcl@redhat.com> - 3.3-6
- tests: Add a test for resizepart on a busy partition (bcl)
- parted: Preserve resizepart End when prompted for busy partition (bcl)
- tests: Add f2fs to the fs probe test (romain.perier)
- Add support for the F2FS filesystem (romain.perier)
- Removed reference to ped_file_system_create (max)
* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 3.3-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild