* [xfstests-bld PATCH] android-xfstests: support f2fs
@ 2018-03-30 1:00 Eric Biggers
2018-04-02 0:24 ` Theodore Y. Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2018-03-30 1:00 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: fstests, Eric Biggers
Make android-setup-partitions use 'blkid' to detect the type of the
userdata filesystem, and if it is f2fs calculate its size using fields
from the f2fs superblock.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
.../test-appliance/android-setup-partitions | 55 +++++++++++++++++--
1 file changed, 50 insertions(+), 5 deletions(-)
diff --git a/kvm-xfstests/test-appliance/android-setup-partitions b/kvm-xfstests/test-appliance/android-setup-partitions
index 61cd001..8d38303 100755
--- a/kvm-xfstests/test-appliance/android-setup-partitions
+++ b/kvm-xfstests/test-appliance/android-setup-partitions
@@ -209,6 +209,49 @@ all_partitions_present()
return 0
}
+# Extract a little-endian binary field from a file or device.
+extract_binval()
+{
+ local file="$1"
+ local offset="$2"
+ local size="$3"
+
+ od "$file" -j $offset -N $size -t x$size -A none --endian=little \
+ | sed 's/^[[:space:]]*/0x/'
+}
+
+# Get the size of the filesystem on the specified device.
+get_fs_size()
+{
+ local device="$1" fstype="$2"
+
+ case "$fstype" in
+ ext4)
+ dumpe2fs -h "$device" 2>/dev/null | \
+ awk '/^Block count:/{blockcount=$3}
+ /^Block size:/{blocksize=$3}
+ END { print blockcount * blocksize }'
+ ;;
+ f2fs)
+ local super_offset=1024
+ local magic log_blocksize block_count
+
+ # see 'struct f2fs_super_block'
+ magic=$(extract_binval "$device" $super_offset 4)
+ log_blocksize=$(extract_binval "$device" $(( super_offset + 16 )) 4)
+ block_count=$(extract_binval "$device" $(( super_offset + 36 )) 8)
+
+ if (( magic != 0xF2F52010 )); then
+ die "f2fs superblock not found on \"$device\""
+ fi
+ echo $(( block_count * (1 << log_blocksize) ))
+ ;;
+ *)
+ die "unsupported filesystem type \"$fstype\" on \"$device\""
+ ;;
+ esac
+}
+
# Transiently shrink the userdata partition, as viewed by the kernel, if it's
# not fully used by the filesystem on it.
#
@@ -219,11 +262,10 @@ all_partitions_present()
# the end of the filesystem.
shrink_userdata_partition()
{
- local fs_size=$(dumpe2fs -h $USERDATA_FS_DEV 2>/dev/null | \
- awk '/^Block count:/{blockcount=$3}
- /^Block size:/{blocksize=$3}
- END { print blockcount * blocksize }')
- local part_size=$(get_partition_size $USERDATA_RAW_DEV)
+ local fs_size part_size
+
+ fs_size=$(get_fs_size "$USERDATA_FS_DEV" "$USERDATA_FS_TYPE")
+ part_size=$(get_partition_size "$USERDATA_RAW_DEV")
if (( fs_size <= 0 )); then
die "unable to determine size of userdata filesystem"
@@ -337,6 +379,9 @@ else
USERDATA_FS_DEV=$USERDATA_RAW_DEV
fi
+# Type of the userdata filesystem, e.g. ext4 or f2fs
+USERDATA_FS_TYPE=$(blkid -s TYPE -o value "$USERDATA_FS_DEV")
+
if ! all_partitions_present ; then
# Free up as much space as we can, then create the partitions.
shrink_userdata_partition
--
2.17.0.rc1.321.gba9d0f2565-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [xfstests-bld PATCH] android-xfstests: support f2fs
2018-03-30 1:00 [xfstests-bld PATCH] android-xfstests: support f2fs Eric Biggers
@ 2018-04-02 0:24 ` Theodore Y. Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Y. Ts'o @ 2018-04-02 0:24 UTC (permalink / raw)
To: Eric Biggers; +Cc: fstests
On Thu, Mar 29, 2018 at 06:00:50PM -0700, Eric Biggers wrote:
> Make android-setup-partitions use 'blkid' to detect the type of the
> userdata filesystem, and if it is f2fs calculate its size using fields
> from the f2fs superblock.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
Thanks, applied.
- Ted
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-02 0:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-30 1:00 [xfstests-bld PATCH] android-xfstests: support f2fs Eric Biggers
2018-04-02 0:24 ` Theodore Y. Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox