-######
-#
-# renameat2 helpers
-#
-#-----------------------------------------------------------------------
+##/bin/bash
+# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014 Miklos Szeredi. All Rights Reserved.
#
-# 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.
-#
-# This program is distributed in the hope that it would 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, write the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#-----------------------------------------------------------------------
-#
+# renameat2 helpers
-#
# Setup source or dest
#
_setup_one()
#
# This checks whether the renameat2 syscall is supported
#
-_requires_renameat2()
+_require_renameat2()
{
+ local flags=$1
+ local rename_dir=$TEST_DIR/$$
+ local cmd=""
+
if test ! -x src/renameat2; then
_notrun "renameat2 binary not found"
fi
- if ! src/renameat2 -t; then
+
+ mkdir $rename_dir
+ touch $rename_dir/foo
+ case $flags in
+ "noreplace")
+ cmd="-n $rename_dir/foo $rename_dir/bar"
+ ;;
+ "exchange")
+ touch $rename_dir/bar
+ cmd="-x $rename_dir/foo $rename_dir/bar"
+ ;;
+ "whiteout")
+ touch $rename_dir/bar
+ cmd="-w $rename_dir/foo $rename_dir/bar"
+ ;;
+ "")
+ cmd=""
+ ;;
+ *)
+ rm -rf $rename_dir
+ _fail "_require_renameat2: only support noreplace,exchange,whiteout rename flags"
+ ;;
+ esac
+ if ! src/renameat2 -t $cmd; then
+ rm -rf $rename_dir
_notrun "kernel doesn't support renameat2 syscall"
fi
+ rm -rf $rename_dir
}