public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@google.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: fstests@vger.kernel.org, Eric Biggers <ebiggers@google.com>
Subject: [xfstests-bld PATCH] android-xfstests: support f2fs
Date: Thu, 29 Mar 2018 18:00:50 -0700	[thread overview]
Message-ID: <20180330010050.64034-1-ebiggers@google.com> (raw)

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


             reply	other threads:[~2018-03-30  1:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30  1:00 Eric Biggers [this message]
2018-04-02  0:24 ` [xfstests-bld PATCH] android-xfstests: support f2fs Theodore Y. Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180330010050.64034-1-ebiggers@google.com \
    --to=ebiggers@google.com \
    --cc=fstests@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox