Skip to contentSkip to conversation

common: open files in ro mode for extent and hole count helpers

PATCH New [email protected] 1 participant 1 message Nov 5, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 common: open files in ro mode for extent and hole count helpers

From: Filipe Manana <[email protected]>

The helper functions _count_extents() and _count_holes() open their input file in RW mode to call fiemap, however opening it in RO mode is enough. By opening them in RW mode it also makes it not possible to use them against files residing in btrfs readonly snapshots for example.

So just open the files in RO mode in these functions.

---
 common/rc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/rc +2 -2
index ef0c2509..238ffef9 100644
@@ -3199,12 +3199,12 @@ _require_metadata_journaling()
 
 _count_extents()
 {
-	$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
+	$XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
 }
 
 _count_holes()
 {
-	$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
+	$XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
 }
 
 _count_attr_extents()
Signature · 1 line
2.11.0