common/rc: Add _require_{chown,chmod}()
[xfstests-dev.git] / common / rc
index aa4ea7d4dd7be94144bd5a234006e51d4029a6a0..bed322fe11c4eccd894c0b197ce93e4cde64e517 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2185,6 +2185,40 @@ _require_user()
     [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
 }
 
+# check for a chown support
+#
+_require_chown()
+{
+       local rnd_uid=4242
+       local file="$TEST_DIR/chown_testfile"
+
+       rm -f $file
+       touch $file
+       chown ${rnd_uid}:${rnd_uid} $file >/dev/null 2>&1 \
+               || _notrun "chown is not supported ${FSTYP}"
+}
+
+
+# check for a chmod support
+# Since chmod sometimes fails silently actual functionality test is done
+#
+_require_chmod()
+{
+       local file="$TEST_DIR/chmod_testfile"
+
+       rm -f $file
+       touch $file
+
+       # get original file mode
+       local mode=`stat --format="0%a" $file`
+       # flip the user's read bit
+       let mode^=0400
+       chmod `printf '%o' "$mode"` $file
+       # check that the chmod actually flipped the bit
+       [ `stat --format="0%a" $file` == `printf '0%o' "$mode"` ] \
+               || _notrun "chmod is not supported ${FSTYP}"
+}
+
 # check for a group on the machine, fsgqa as default
 #
 _require_group()
@@ -2421,7 +2455,15 @@ _format_swapfile() {
        # Swap files must be nocow on Btrfs.
        $CHATTR_PROG +C "$fname" > /dev/null 2>&1
        _pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
-       $MKSWAP_PROG "$fname" >> $seqres.full
+       # Ignore permission complaints on filesystems that don't support perms
+       $MKSWAP_PROG "$fname" 2> >(grep -v 'insecure permission' >&2) >> $seqres.full
+}
+
+_swapon_file() {
+       local fname="$1"
+
+       # Ignore permission complaints on filesystems that don't support perms
+       swapon "$fname" 2> >(grep -v "insecure permissions" >&2)
 }
 
 # Check that the filesystem supports swapfiles
@@ -4131,6 +4173,16 @@ _get_block_size()
        stat -f -c %S $1
 }
 
+# Require that the fundamental allocation unit of a file is the same as the
+# filesystem block size.
+_require_file_block_size_equals_fs_block_size()
+{
+       local file_alloc_unit="$(_get_file_block_size $1)"
+       local fs_block_size="$(_get_block_size $1)"
+       test "$file_alloc_unit" != "$fs_block_size" && \
+               _notrun "File allocation unit is larger than a filesystem block"
+}
+
 get_page_size()
 {
        echo $(getconf PAGE_SIZE)