xref: /aosp_15_r20/external/strace/tests-mx32/mount.c (revision cf84ac9a129d8ea9952db616b4e9b904c4bdde56)
1*cf84ac9aSAndroid Build Coastguard Worker /*
2*cf84ac9aSAndroid Build Coastguard Worker  * Check decoding of mount syscall.
3*cf84ac9aSAndroid Build Coastguard Worker  *
4*cf84ac9aSAndroid Build Coastguard Worker  * Copyright (c) 2016 Dmitry V. Levin <[email protected]>
5*cf84ac9aSAndroid Build Coastguard Worker  * Copyright (c) 2016-2018 The strace developers.
6*cf84ac9aSAndroid Build Coastguard Worker  * All rights reserved.
7*cf84ac9aSAndroid Build Coastguard Worker  *
8*cf84ac9aSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
9*cf84ac9aSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
10*cf84ac9aSAndroid Build Coastguard Worker  * are met:
11*cf84ac9aSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
12*cf84ac9aSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
13*cf84ac9aSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
14*cf84ac9aSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
15*cf84ac9aSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
16*cf84ac9aSAndroid Build Coastguard Worker  * 3. The name of the author may not be used to endorse or promote products
17*cf84ac9aSAndroid Build Coastguard Worker  *    derived from this software without specific prior written permission.
18*cf84ac9aSAndroid Build Coastguard Worker  *
19*cf84ac9aSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20*cf84ac9aSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21*cf84ac9aSAndroid Build Coastguard Worker  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22*cf84ac9aSAndroid Build Coastguard Worker  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23*cf84ac9aSAndroid Build Coastguard Worker  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24*cf84ac9aSAndroid Build Coastguard Worker  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*cf84ac9aSAndroid Build Coastguard Worker  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*cf84ac9aSAndroid Build Coastguard Worker  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*cf84ac9aSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28*cf84ac9aSAndroid Build Coastguard Worker  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*cf84ac9aSAndroid Build Coastguard Worker  */
30*cf84ac9aSAndroid Build Coastguard Worker 
31*cf84ac9aSAndroid Build Coastguard Worker #include "tests.h"
32*cf84ac9aSAndroid Build Coastguard Worker #include <stdio.h>
33*cf84ac9aSAndroid Build Coastguard Worker #include <unistd.h>
34*cf84ac9aSAndroid Build Coastguard Worker #include <sys/mount.h>
35*cf84ac9aSAndroid Build Coastguard Worker 
36*cf84ac9aSAndroid Build Coastguard Worker #ifndef MS_MGC_VAL
37*cf84ac9aSAndroid Build Coastguard Worker # define MS_MGC_VAL 0xC0ED0000
38*cf84ac9aSAndroid Build Coastguard Worker #endif
39*cf84ac9aSAndroid Build Coastguard Worker 
40*cf84ac9aSAndroid Build Coastguard Worker #ifndef MS_RELATIME
41*cf84ac9aSAndroid Build Coastguard Worker # define MS_RELATIME (1ul << 21)
42*cf84ac9aSAndroid Build Coastguard Worker #endif
43*cf84ac9aSAndroid Build Coastguard Worker 
44*cf84ac9aSAndroid Build Coastguard Worker #if XLAT_RAW
45*cf84ac9aSAndroid Build Coastguard Worker # define str_unknown "0x300"
46*cf84ac9aSAndroid Build Coastguard Worker # define str_submount_200 "0x4000200"
47*cf84ac9aSAndroid Build Coastguard Worker # define str_mgc_val "0xc0ed0000"
48*cf84ac9aSAndroid Build Coastguard Worker # define str_remount "0x20"
49*cf84ac9aSAndroid Build Coastguard Worker # define str_bind "0x1000"
50*cf84ac9aSAndroid Build Coastguard Worker # define str_ro_nosuid_nodev_noexec "0xf"
51*cf84ac9aSAndroid Build Coastguard Worker # define str_ro_nosuid_nodev_noexec_relatime "0x20000f"
52*cf84ac9aSAndroid Build Coastguard Worker #elif XLAT_VERBOSE
53*cf84ac9aSAndroid Build Coastguard Worker # define str_unknown "0x300 /* MS_??? */"
54*cf84ac9aSAndroid Build Coastguard Worker # define str_submount_200 "0x4000200 /* MS_SUBMOUNT|0x200 */"
55*cf84ac9aSAndroid Build Coastguard Worker # define str_mgc_val "0xc0ed0000 /* MS_MGC_VAL */"
56*cf84ac9aSAndroid Build Coastguard Worker # define str_remount "0x20 /* MS_REMOUNT */"
57*cf84ac9aSAndroid Build Coastguard Worker # define str_bind "0x1000 /* MS_BIND */"
58*cf84ac9aSAndroid Build Coastguard Worker # define str_ro_nosuid_nodev_noexec \
59*cf84ac9aSAndroid Build Coastguard Worker 	"0xf /* MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC */"
60*cf84ac9aSAndroid Build Coastguard Worker # define str_ro_nosuid_nodev_noexec_relatime \
61*cf84ac9aSAndroid Build Coastguard Worker 	"0x20000f /* MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME */"
62*cf84ac9aSAndroid Build Coastguard Worker #else /* !XLAT_RAW && !XLAT_VERBOSE */
63*cf84ac9aSAndroid Build Coastguard Worker # define str_unknown "0x300 /* MS_??? */"
64*cf84ac9aSAndroid Build Coastguard Worker # define str_submount_200 "MS_SUBMOUNT|0x200"
65*cf84ac9aSAndroid Build Coastguard Worker # define str_mgc_val "MS_MGC_VAL"
66*cf84ac9aSAndroid Build Coastguard Worker # define str_remount "MS_REMOUNT"
67*cf84ac9aSAndroid Build Coastguard Worker # define str_bind "MS_BIND"
68*cf84ac9aSAndroid Build Coastguard Worker # define str_ro_nosuid_nodev_noexec "MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC"
69*cf84ac9aSAndroid Build Coastguard Worker # define str_ro_nosuid_nodev_noexec_relatime \
70*cf84ac9aSAndroid Build Coastguard Worker 	"MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME"
71*cf84ac9aSAndroid Build Coastguard Worker #endif /* XLAT_RAW, XLAT_VERBOSE */
72*cf84ac9aSAndroid Build Coastguard Worker 
73*cf84ac9aSAndroid Build Coastguard Worker int
main(void)74*cf84ac9aSAndroid Build Coastguard Worker main(void)
75*cf84ac9aSAndroid Build Coastguard Worker {
76*cf84ac9aSAndroid Build Coastguard Worker 	static const char source[] = "mount_source";
77*cf84ac9aSAndroid Build Coastguard Worker 	static const char target[] = "mount_target";
78*cf84ac9aSAndroid Build Coastguard Worker 	static const char fstype[] = "mount_fstype";
79*cf84ac9aSAndroid Build Coastguard Worker 	static const char data[] = "mount_data";
80*cf84ac9aSAndroid Build Coastguard Worker 	TAIL_ALLOC_OBJECT_CONST_PTR(char, bogus);
81*cf84ac9aSAndroid Build Coastguard Worker 
82*cf84ac9aSAndroid Build Coastguard Worker 	bogus[0] = 'a';
83*cf84ac9aSAndroid Build Coastguard Worker 
84*cf84ac9aSAndroid Build Coastguard Worker 	int rc = mount(NULL, NULL, NULL, 0, NULL);
85*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(NULL, NULL, NULL, 0, NULL) = %s\n",
86*cf84ac9aSAndroid Build Coastguard Worker 	       sprintrc(rc));
87*cf84ac9aSAndroid Build Coastguard Worker 
88*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(bogus, bogus, bogus, 768, bogus);
89*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(%p, %p, %p, %s, %p) = %s\n",
90*cf84ac9aSAndroid Build Coastguard Worker 	       bogus, bogus, bogus, str_unknown, bogus, sprintrc(rc));
91*cf84ac9aSAndroid Build Coastguard Worker 
92*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(bogus + 1, bogus + 1, bogus + 1, 0x4000200, bogus + 1);
93*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(%p, %p, %p, %s, %p) = %s\n",
94*cf84ac9aSAndroid Build Coastguard Worker 	       bogus + 1, bogus + 1, bogus + 1, str_submount_200,
95*cf84ac9aSAndroid Build Coastguard Worker 	       bogus + 1, sprintrc(rc));
96*cf84ac9aSAndroid Build Coastguard Worker 
97*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, fstype, 15, data);
98*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
99*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, fstype, str_ro_nosuid_nodev_noexec,
100*cf84ac9aSAndroid Build Coastguard Worker 	       data, sprintrc(rc));
101*cf84ac9aSAndroid Build Coastguard Worker 
102*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, fstype, MS_RELATIME | 15, data);
103*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
104*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, fstype,
105*cf84ac9aSAndroid Build Coastguard Worker 	       str_ro_nosuid_nodev_noexec_relatime,
106*cf84ac9aSAndroid Build Coastguard Worker 	       data, sprintrc(rc));
107*cf84ac9aSAndroid Build Coastguard Worker 
108*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, fstype, MS_MGC_VAL, data);
109*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
110*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, fstype, str_mgc_val, data, sprintrc(rc));
111*cf84ac9aSAndroid Build Coastguard Worker 
112*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, fstype, MS_MGC_VAL | 15, data);
113*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
114*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, fstype,
115*cf84ac9aSAndroid Build Coastguard Worker 	       str_mgc_val "|" str_ro_nosuid_nodev_noexec,
116*cf84ac9aSAndroid Build Coastguard Worker 	       data, sprintrc(rc));
117*cf84ac9aSAndroid Build Coastguard Worker 
118*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, NULL, MS_REMOUNT, data);
119*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", NULL, %s, \"%s\") = %s\n",
120*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, str_remount, data, sprintrc(rc));
121*cf84ac9aSAndroid Build Coastguard Worker 
122*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, fstype, MS_REMOUNT, data);
123*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", %p, %s, \"%s\") = %s\n",
124*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, fstype, str_remount, data, sprintrc(rc));
125*cf84ac9aSAndroid Build Coastguard Worker 
126*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, NULL, MS_BIND, data);
127*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", NULL, %s, %p) = %s\n",
128*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, str_bind, data, sprintrc(rc));
129*cf84ac9aSAndroid Build Coastguard Worker 
130*cf84ac9aSAndroid Build Coastguard Worker 	rc = mount(source, target, fstype, MS_BIND, NULL);
131*cf84ac9aSAndroid Build Coastguard Worker 	printf("mount(\"%s\", \"%s\", %p, %s, NULL) = %s\n",
132*cf84ac9aSAndroid Build Coastguard Worker 	       source, target, fstype, str_bind, sprintrc(rc));
133*cf84ac9aSAndroid Build Coastguard Worker 
134*cf84ac9aSAndroid Build Coastguard Worker 	puts("+++ exited with 0 +++");
135*cf84ac9aSAndroid Build Coastguard Worker 	return 0;
136*cf84ac9aSAndroid Build Coastguard Worker }
137