acba9ed3d33bb39b3ef7ffd67c2ee05022e0eb63
[xfstests-dev.git] / tests / generic / 379
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 379
6 #
7 # Check behavior of chown with both user and group quota enabled,
8 # and changing both user and group together via chown(2).
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21 . ./common/quota
22
23 _cleanup()
24 {
25         _scratch_unmount 2>/dev/null
26         rm -f $tmp.*
27 }
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 # real QA test starts here
31 _supported_fs generic
32 _supported_os Linux
33
34 cp /dev/null $seqres.full
35 chmod ugo+rwx $seqres.full
36
37 _require_scratch
38 _require_quota
39 _require_xfs_quota_foreign
40
41 _filter_stat()
42 {
43     sed "
44         /^Access:/d;
45         /^Modify:/d;
46         /^Change:/d;
47         s/Device: *[0-9][0-9]*,[0-9][0-9]*/Device: <DEVICE>/;
48         s/Inode: *[0-9][0-9]*/Inode: <INODE>/;
49         s,$SCRATCH_MNT,<MOUNT>,;
50     " | tr -s ' '
51 }
52
53 _exercise()
54 {
55         _scratch_mkfs >/dev/null 2>&1
56         _qmount
57
58         umask 022
59         touch $SCRATCH_MNT/testfile
60         if src/feature -c $SCRATCH_MNT/testfile; then
61                 :
62         else
63                 _notrun "Installed fileutils doesn't support 32 bit uids/gids"
64         fi
65
66         chown 12345 $SCRATCH_MNT/testfile
67         chgrp 54321 $SCRATCH_MNT/testfile
68         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
69
70         chown 34567 $SCRATCH_MNT/testfile
71         chgrp 76543 $SCRATCH_MNT/testfile
72         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
73
74         chown 56789 $SCRATCH_MNT/testfile
75         chgrp 98765 $SCRATCH_MNT/testfile
76         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
77
78         # finally give back to original owners
79         chown 12345 $SCRATCH_MNT/testfile
80         chgrp 54321 $SCRATCH_MNT/testfile
81         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
82
83         echo
84         _scratch_unmount 2>/dev/null
85 }
86
87 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed!"
88
89 _qmount_option "usrquota,grpquota"
90 _qmount
91 if src/feature -G $SCRATCH_DEV ; then
92         :
93 else
94         _notrun "No quota support at mount time"
95 fi
96 _scratch_unmount 2>/dev/null
97
98 _qmount_option "rw" # no quota options
99 echo "*** Default mount options"
100 _exercise
101
102 _qmount_option "usrquota"
103 echo "*** User quota mount option"
104 _exercise
105
106 _qmount_option "grpquota"
107 echo "*** Group quota mount option"
108 _exercise
109
110 _qmount_option "usrquota,grpquota"
111 echo "*** User and Group quota mount options"
112 _exercise
113
114 # success, all done
115 status=0
116 exit