Subversion リポジトリの参照
Contents of /branches/ccs-tools/ccstools/kernel_test/ccs_filesystem_test.c
Parent Directory
| Revision Log
1 |
/* |
2 |
* ccs_filesystem_test.c |
3 |
* |
4 |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
6 |
* Version: 1.8.0-pre 2010/08/01 |
7 |
* |
8 |
*/ |
9 |
#define _GNU_SOURCE |
10 |
#include "include.h" |
11 |
|
12 |
static void show_prompt(const char *str, const int should_fail) |
13 |
{ |
14 |
printf("Testing %60s: (%s) ", str, |
15 |
should_fail ? "must fail" : "should success"); |
16 |
errno = 0; |
17 |
} |
18 |
|
19 |
#ifndef MS_MOVE |
20 |
#define MS_MOVE 8192 |
21 |
#endif |
22 |
|
23 |
static int child(void *arg) |
24 |
{ |
25 |
errno = 0; |
26 |
pivot_root("/proc/", "/proc/ccs/"); |
27 |
return errno; |
28 |
} |
29 |
|
30 |
static void mount2(const char *source, const char *target, |
31 |
const char *filesystemtype) |
32 |
{ |
33 |
if (mount(source, target, filesystemtype, 0, NULL)) { |
34 |
printf("BUG: mount() failed\n"); |
35 |
fflush(stdout); |
36 |
} |
37 |
} |
38 |
|
39 |
static const unsigned char compressed_ext2_image_sample[1350] = { |
40 |
0x1F, 0x8B, 0x08, 0x00, 0xA8, 0xF2, 0x96, 0x4B, 0x02, 0x03, 0xED, 0xDC, |
41 |
0x3D, 0x4B, 0x5B, 0x51, 0x18, 0x07, 0xF0, 0xE7, 0xDE, 0xAB, 0x14, 0x8C, |
42 |
0xAB, 0xD5, 0x9A, 0xF8, 0x36, 0x0B, 0xA1, 0xE0, 0xE0, 0xDC, 0xD0, 0xAD, |
43 |
0xD0, 0xC5, 0xAF, 0x50, 0x9C, 0x42, 0x1D, 0x6A, 0xE6, 0xA6, 0x9B, 0x9B, |
44 |
0x8B, 0xD8, 0xA5, 0x5B, 0x97, 0x2E, 0xF9, 0x0E, 0x85, 0x4C, 0xF6, 0x23, |
45 |
0x74, 0x70, 0x55, 0x28, 0x52, 0xA8, 0xDD, 0xED, 0xB9, 0xB9, 0xB1, 0xA6, |
46 |
0xEA, 0x24, 0xA5, 0x81, 0xDE, 0xDF, 0x0F, 0x9E, 0xDC, 0xB7, 0x13, 0x2E, |
47 |
0xF7, 0xC0, 0xFF, 0x70, 0xCE, 0x85, 0x24, 0x02, 0xA8, 0xAB, 0x7E, 0xF9, |
48 |
0x31, 0x13, 0xB1, 0x95, 0x36, 0xA7, 0x45, 0x44, 0x2F, 0x6D, 0xB3, 0xC9, |
49 |
0x06, 0xEB, 0x55, 0xF5, 0xC7, 0x87, 0x9F, 0x7E, 0x1C, 0xBF, 0x88, 0x68, |
50 |
0xC5, 0xCE, 0xF7, 0x6C, 0xD4, 0x6E, 0x74, 0xFC, 0xF2, 0x62, 0x74, 0xED, |
51 |
0xFA, 0x7B, 0x8D, 0xB8, 0x69, 0x9F, 0x8F, 0xCF, 0x9F, 0x1D, 0x7E, 0x78, |
52 |
0xF7, 0x6D, 0xD8, 0x79, 0xFF, 0x71, 0xD0, 0xED, 0xBC, 0xCD, 0x9A, 0xBD, |
53 |
0x69, 0x3C, 0xEB, 0xE0, 0xCB, 0xF0, 0xA4, 0xF9, 0xF5, 0xF9, 0xCA, 0xE0, |
54 |
0xE0, 0x72, 0xBB, 0x7B, 0xD4, 0x1A, 0xE6, 0x13, 0xD7, 0xAA, 0xE7, 0x82, |
55 |
0x7A, 0x29, 0xAA, 0xF8, 0xC7, 0xEC, 0x28, 0xFF, 0xBD, 0xC8, 0x75, 0x09, |
56 |
0xD4, 0xC6, 0x55, 0x92, 0x4D, 0x71, 0xFA, 0x71, 0x05, 0x4C, 0xCF, 0xA3, |
57 |
0xBB, 0xE3, 0x01, 0x50, 0x0F, 0x93, 0xEB, 0xDF, 0xEB, 0xFA, 0x97, 0x13, |
58 |
0x80, 0x8B, 0x67, 0xD5, 0x02, 0xE4, 0xEE, 0xFD, 0x8B, 0x3F, 0xD6, 0x22, |
59 |
0x0B, 0xA6, 0x6A, 0xC0, 0x5F, 0xF6, 0xB9, 0x1C, 0x7F, 0x9E, 0xDE, 0x37, |
60 |
0xFE, 0xE4, 0xB1, 0x34, 0xD1, 0xEE, 0x71, 0xAA, 0xC5, 0x54, 0xE5, 0xB9, |
61 |
0x27, 0xA9, 0x96, 0x53, 0x35, 0xA3, 0x7C, 0x13, 0x1A, 0xB1, 0x92, 0x6A, |
62 |
0x35, 0xD5, 0xDA, 0xF8, 0x75, 0xE9, 0x86, 0x6E, 0x05, 0x00, 0x00, 0x00, |
63 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x81, |
64 |
0xCA, 0xDF, 0xD8, 0xCF, 0x47, 0x96, 0xB7, 0x7F, 0xEF, 0xE7, 0x79, 0xBB, |
65 |
0x5D, 0xFD, 0x87, 0xDF, 0x79, 0x31, 0x97, 0x77, 0xF7, 0xDE, 0xEC, 0x6F, |
66 |
0xEE, 0xEE, 0xF5, 0x5E, 0xBF, 0xD2, 0x57, 0xF0, 0xBF, 0x69, 0xDC, 0xCA, |
67 |
0xFF, 0xCF, 0xA2, 0xCA, 0x3F, 0x50, 0x13, 0x33, 0xBA, 0x00, 0xE4, 0x1F, |
68 |
0x90, 0x7F, 0x40, 0xFE, 0x01, 0xF9, 0x07, 0xE4, 0x1F, 0x90, 0x7F, 0x40, |
69 |
0xFE, 0x01, 0xF9, 0x07, 0xE4, 0x1F, 0x90, 0x7F, 0x00, 0x00, 0x00, 0x00, |
70 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
71 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
72 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
73 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
74 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
75 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
76 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
77 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
78 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
79 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
80 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
81 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
82 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
83 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
84 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
85 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
86 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
87 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
88 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
89 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
90 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
91 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
92 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
93 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
94 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
95 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
96 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
97 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
98 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
99 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
100 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
101 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
102 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
103 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
104 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
105 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
106 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
107 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
108 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
109 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
110 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
111 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
112 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
113 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
114 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
115 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
116 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
117 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
118 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
119 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
120 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
121 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
122 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
123 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
124 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
125 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
126 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
127 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
128 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
129 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
130 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
131 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
132 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
133 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
134 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
135 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
136 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
137 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
138 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
139 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
140 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
141 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
142 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
143 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
144 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
145 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
146 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
147 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
148 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
149 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
150 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
151 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFA, 0xF9, 0x05, 0x34, 0xF2, |
152 |
0x14, 0x08, 0x00, 0x00, 0x10, 0x00 |
153 |
}; |
154 |
|
155 |
int main(int argc, char *argv[]) |
156 |
{ |
157 |
char c = 0; |
158 |
ccs_test_init(); |
159 |
|
160 |
/* Test mount(). */ |
161 |
{ |
162 |
set_profile(3, "file::mount"); |
163 |
show_prompt("mount('dev\\011name', '/', 'fs\\011name') ", 1); |
164 |
if (mount("dev\tname", "/", "fs\tname", 0, NULL) == EOF && |
165 |
errno == EPERM) |
166 |
printf("OK: Permission denied.\n"); |
167 |
else if (errno == ENODEV) |
168 |
printf("OK: No such device.\n"); |
169 |
else |
170 |
printf("BUG: %s\n", strerror(errno)); |
171 |
set_profile(1, "file::mount"); |
172 |
show_prompt("mount('dev\\011name', '/', 'fs\\011name') ", 0); |
173 |
if (mount("dev\tname", "/", "fs\tname", 0, NULL) == EOF && |
174 |
errno == ENOMEM) |
175 |
printf("OK: Out of memory.\n"); |
176 |
else if (errno == ENODEV) |
177 |
printf("OK: No such device.\n"); |
178 |
else |
179 |
printf("BUG: %s\n", strerror(errno)); |
180 |
set_profile(3, "file::mount"); |
181 |
show_prompt("mount('dev\\011name', '/', 'fs\\011name') ", 0); |
182 |
if (mount("dev\tname", "/", "fs\tname", 0, NULL) == EOF && |
183 |
errno == ENOMEM) |
184 |
printf("OK: Out of memory.\n"); |
185 |
else if (errno == ENODEV) |
186 |
printf("OK: No such device.\n"); |
187 |
else |
188 |
printf("BUG: %s\n", strerror(errno)); |
189 |
fprintf(domain_fp, "delete file mount dev\\011name / " |
190 |
"fs\\011name 0\n"); |
191 |
show_prompt("mount('dev\\011name', '/', 'fs\\011name') ", 1); |
192 |
if (mount("dev\tname", "/", "fs\tname", 0, NULL) == EOF && |
193 |
errno == EPERM) |
194 |
printf("OK: Permission denied.\n"); |
195 |
else if (errno == ENODEV) |
196 |
printf("OK: No such device.\n"); |
197 |
else |
198 |
printf("BUG: %s\n", strerror(errno)); |
199 |
set_profile(1, "file::mount"); |
200 |
show_prompt("mount(NULL, '/', 'tmpfs') ", 0); |
201 |
if (mount(NULL, "/", "tmpfs", 0, NULL)) |
202 |
printf("BUG: %s\n", strerror(errno)); |
203 |
else |
204 |
printf("OK: Success\n"); |
205 |
set_profile(3, "file::mount"); |
206 |
show_prompt("mount(NULL, '/', 'tmpfs') ", 0); |
207 |
if (mount(NULL, "/", "tmpfs", 0, NULL)) |
208 |
printf("BUG: %s\n", strerror(errno)); |
209 |
else |
210 |
printf("OK: Success\n"); |
211 |
show_prompt("mount('anydev', '/', 'tmpfs') ", 0); |
212 |
if (mount("anydev", "/", "tmpfs", 0, NULL)) |
213 |
printf("BUG: %s\n", strerror(errno)); |
214 |
else |
215 |
printf("OK: Success\n"); |
216 |
fprintf(domain_fp, "delete file mount <NULL> / tmpfs 0\n"); |
217 |
fprintf(domain_fp, "file mount anydev / tmpfs 0\n"); |
218 |
show_prompt("mount(NULL, '/', 'tmpfs') ", 0); |
219 |
if (mount(NULL, "/", "tmpfs", 0, NULL)) |
220 |
printf("BUG: %s\n", strerror(errno)); |
221 |
else |
222 |
printf("OK: Success\n"); |
223 |
fprintf(domain_fp, "delete file mount anydev / tmpfs 0\n"); |
224 |
set_profile(2, "file::mount"); |
225 |
show_prompt("mount(NULL, NULL, 'tmpfs') ", 1); |
226 |
if (mount(NULL, NULL, "tmpfs", 0, NULL)) |
227 |
printf("OK: %s\n", strerror(errno)); |
228 |
else |
229 |
printf("BUG: Did not fail.\n"); |
230 |
show_prompt("mount(NULL, NULL, NULL) ", 1); |
231 |
if (mount(NULL, NULL, NULL, 0, NULL)) |
232 |
printf("OK: %s\n", strerror(errno)); |
233 |
else |
234 |
printf("BUG: Did not fail.\n"); |
235 |
show_prompt("mount('/', NULL, NULL) ", 1); |
236 |
if (mount("/", NULL, NULL, 0, NULL)) |
237 |
printf("OK: %s\n", strerror(errno)); |
238 |
else |
239 |
printf("BUG: Did not fail.\n"); |
240 |
show_prompt("mount('/', NULL, 'tmpfs') ", 1); |
241 |
if (mount("/", NULL, "tmpfs", 0, NULL)) |
242 |
printf("OK: %s\n", strerror(errno)); |
243 |
else |
244 |
printf("BUG: Did not fail.\n"); |
245 |
show_prompt("mount('/', '/', 'nonexistentfs') ", 1); |
246 |
if (mount("/", "/", "nonexistentfs", 0, NULL)) |
247 |
printf("OK: %s\n", strerror(errno)); |
248 |
else |
249 |
printf("BUG: Did not fail.\n"); |
250 |
set_profile(0, "file::mount"); |
251 |
} |
252 |
|
253 |
mkdir("/tmp/mount/", 0755); |
254 |
mkdir("/tmp/mount_bind/", 0755); |
255 |
mkdir("/tmp/mount_move/", 0755); |
256 |
|
257 |
/* Test mount(). */ |
258 |
{ |
259 |
static char buf[4096]; |
260 |
char *dev_ram_path = canonicalize_file_name("/dev/ram0"); |
261 |
if (!dev_ram_path) |
262 |
dev_ram_path = canonicalize_file_name("/dev/ram"); |
263 |
if (!dev_ram_path) { |
264 |
dev_ram_path = "/dev/ram0"; |
265 |
mknod(dev_ram_path, S_IFBLK, MKDEV(1, 0)); |
266 |
} |
267 |
memset(buf, 0, sizeof(buf)); |
268 |
{ |
269 |
struct stat sbuf; |
270 |
FILE *fp = NULL; |
271 |
snprintf(buf, sizeof(buf) - 1, "zcat - > %s", |
272 |
dev_ram_path); |
273 |
if (lstat(dev_ram_path, &sbuf) == 0 && |
274 |
S_ISBLK(sbuf.st_mode) && MAJOR(sbuf.st_rdev) == 1) |
275 |
fp = popen(buf, "w"); |
276 |
if (fp) { |
277 |
fwrite(compressed_ext2_image_sample, 1, |
278 |
sizeof(compressed_ext2_image_sample), |
279 |
fp); |
280 |
pclose(fp); |
281 |
} else |
282 |
fprintf(stderr, "Can't write to %s .\n", |
283 |
dev_ram_path); |
284 |
} |
285 |
set_profile(3, "file::mount"); |
286 |
|
287 |
/* Test standard case */ |
288 |
show_prompt("mount('none', '/tmp/mount/', 'tmpfs') for " |
289 |
"'/tmp/mount/'", 1); |
290 |
if (mount("none", "/tmp/mount/", "tmpfs", 0, NULL) == EOF && |
291 |
errno == EPERM) |
292 |
printf("OK: Permission denied.\n"); |
293 |
else |
294 |
printf("BUG: %s\n", strerror(errno)); |
295 |
|
296 |
/* Test device_name with pattern */ |
297 |
snprintf(buf, sizeof(buf) - 1, "mount('%s', '/tmp/mount/', " |
298 |
"'ext2') for '%s\\*'", dev_ram_path, dev_ram_path); |
299 |
show_prompt(buf, 1); |
300 |
if (mount(dev_ram_path, "/tmp/mount/", "ext2", MS_RDONLY, NULL) |
301 |
== EOF && errno == EPERM) |
302 |
printf("OK: Permission denied.\n"); |
303 |
else |
304 |
printf("BUG: %s\n", strerror(errno)); |
305 |
|
306 |
/* Test dir_name with pattern */ |
307 |
show_prompt("mount('none', '/tmp/mount/', 'tmpfs') for " |
308 |
"'/tmp/\\?\\?\\?\\?\\?/'", 1); |
309 |
if (mount("none", "/tmp/mount/", "tmpfs", 0, NULL) == EOF && |
310 |
errno == EPERM) |
311 |
printf("OK: Permission denied.\n"); |
312 |
else |
313 |
printf("BUG: %s\n", strerror(errno)); |
314 |
|
315 |
/* Test standard case */ |
316 |
fprintf(domain_fp, "file mount none /tmp/mount/ tmpfs 0\n"); |
317 |
show_prompt("mount('none', '/tmp/mount/', 'tmpfs') for " |
318 |
"'/tmp/mount/'", 0); |
319 |
if (mount("none", "/tmp/mount/", "tmpfs", 0, NULL) == 0) |
320 |
printf("OK\n"); |
321 |
else |
322 |
printf("FAILED: %s\n", strerror(errno)); |
323 |
fprintf(domain_fp, |
324 |
"delete file mount none /tmp/mount/ tmpfs 0\n"); |
325 |
|
326 |
/* Test device_name with pattern */ |
327 |
fprintf(domain_fp, "file mount %s\\* /tmp/mount/ ext2 1\n", |
328 |
dev_ram_path); |
329 |
snprintf(buf, sizeof(buf) - 1, "mount('%s', '/tmp/mount/', " |
330 |
"'ext2') for '%s\\*'", dev_ram_path, dev_ram_path); |
331 |
show_prompt(buf, 0); |
332 |
if (mount(dev_ram_path, "/tmp/mount/", "ext2", MS_RDONLY, NULL) |
333 |
== 0) |
334 |
printf("OK\n"); |
335 |
else |
336 |
printf("FAILED: %s\n", strerror(errno)); |
337 |
fprintf(domain_fp, "delete file mount %s\\* " |
338 |
"/tmp/mount/ ext2 1\n", dev_ram_path); |
339 |
|
340 |
/* Test dir_name with pattern */ |
341 |
fprintf(domain_fp, |
342 |
"file mount none /tmp/\\?\\?\\?\\?\\?/ tmpfs 0\n"); |
343 |
show_prompt("mount('none', '/tmp/mount/', 'tmpfs') for " |
344 |
"'/tmp/\\?\\?\\?\\?\\?/'", 0); |
345 |
if (mount("none", "/tmp/mount/", "tmpfs", 0, NULL) == 0) |
346 |
printf("OK\n"); |
347 |
else |
348 |
printf("FAILED: %s\n", strerror(errno)); |
349 |
fprintf(domain_fp, "delete file mount none " |
350 |
"/tmp/\\?\\?\\?\\?\\?/ tmpfs 0\n"); |
351 |
|
352 |
set_profile(0, "file::mount"); |
353 |
while (umount("/tmp/mount/") == 0) |
354 |
c++; /* Dummy. */ |
355 |
} |
356 |
|
357 |
/* Test mount(). */ |
358 |
{ |
359 |
mount2("none", "/tmp/mount/", "tmpfs"); |
360 |
set_profile(3, "file::mount"); |
361 |
|
362 |
/* Test remount case */ |
363 |
show_prompt("mount('/tmp/mount/', MS_REMOUNT)", 1); |
364 |
if (mount("none", "/tmp/mount/", "tmpfs", MS_REMOUNT, NULL) |
365 |
== EOF && errno == EPERM) |
366 |
printf("OK: Permission denied.\n"); |
367 |
else |
368 |
printf("BUG: %s\n", strerror(errno)); |
369 |
show_prompt("mount('/tmp/mount/', MS_REMOUNT)", 1); |
370 |
if (mount(NULL, "/tmp/mount/", NULL, MS_REMOUNT, NULL) == EOF |
371 |
&& errno == EPERM) |
372 |
printf("OK: Permission denied.\n"); |
373 |
else |
374 |
printf("BUG: %s\n", strerror(errno)); |
375 |
fprintf(domain_fp, "file mount something /tmp/mount/ " |
376 |
"--remount 0\n"); |
377 |
show_prompt("mount('/tmp/mount/', MS_REMOUNT)", 0); |
378 |
if (mount(NULL, "/tmp/mount/", NULL, MS_REMOUNT, NULL)) |
379 |
printf("BUG: %s\n", strerror(errno)); |
380 |
else |
381 |
printf("OK: Success.\n"); |
382 |
fprintf(domain_fp, "delete file mount something /tmp/mount/ " |
383 |
"--remount 0\n"); |
384 |
|
385 |
/* Test bind case */ |
386 |
show_prompt("mount('/tmp/mount/', '/tmp/mount_bind/', " |
387 |
"MS_BIND)", 1); |
388 |
if (mount("/tmp/mount/", "/tmp/mount_bind/", NULL, MS_BIND, |
389 |
NULL) == EOF && errno == EPERM) |
390 |
printf("OK: Permission denied.\n"); |
391 |
else |
392 |
printf("BUG: %s\n", strerror(errno)); |
393 |
|
394 |
/* Test move case */ |
395 |
show_prompt("mount('/tmp/mount/', '/tmp/mount_move/', " |
396 |
"MS_MOVE)", 1); |
397 |
if (mount("/tmp/mount/", "/tmp/mount_move/", NULL, MS_MOVE, |
398 |
NULL) == EOF && errno == EPERM) |
399 |
printf("OK: Permission denied.\n"); |
400 |
else |
401 |
printf("BUG: %s\n", strerror(errno)); |
402 |
|
403 |
/* Test remount case */ |
404 |
fprintf(domain_fp, |
405 |
"file mount any /tmp/mount/ --remount 0\n"); |
406 |
show_prompt("mount('/tmp/mount/', MS_REMOUNT)", 0); |
407 |
if (mount("none", "/tmp/mount/", "tmpfs", MS_REMOUNT, NULL) |
408 |
== 0) |
409 |
printf("OK\n"); |
410 |
else |
411 |
printf("FAILED: %s\n", strerror(errno)); |
412 |
fprintf(domain_fp, "delete file mount any /tmp/mount/ " |
413 |
"--remount 0\n"); |
414 |
|
415 |
/* Test bind case */ |
416 |
fprintf(domain_fp, |
417 |
"file mount /tmp/mount/ /tmp/mount_bind/ --bind 0\n"); |
418 |
show_prompt("mount('/tmp/mount/', '/tmp/mount_bind', MS_BIND)", |
419 |
0); |
420 |
if (mount("/tmp/mount/", "/tmp/mount_bind/", NULL, MS_BIND, |
421 |
NULL) == 0) |
422 |
printf("OK\n"); |
423 |
else |
424 |
printf("FAILED: %s\n", strerror(errno)); |
425 |
set_profile(0, "file::mount"); |
426 |
umount("/tmp/mount_bind/"); |
427 |
fprintf(domain_fp, "delete file mount /tmp/mount/ " |
428 |
"/tmp/mount_bind/ --bind 0\n"); |
429 |
|
430 |
/* Test move case */ |
431 |
set_profile(3, "file::mount"); |
432 |
fprintf(domain_fp, "file unmount /tmp/mount/\n"); |
433 |
fprintf(domain_fp, "file mount /tmp/mount/ /tmp/mount_move/ " |
434 |
"--move 0\n"); |
435 |
show_prompt("mount('/tmp/mount/', '/tmp/mount_move/', " |
436 |
"MS_MOVE)", 0); |
437 |
if (mount("/tmp/mount/", "/tmp/mount_move/", NULL, MS_MOVE, |
438 |
NULL) == 0) |
439 |
printf("OK\n"); |
440 |
else |
441 |
printf("FAILED: %s\n", strerror(errno)); |
442 |
set_profile(0, "file::mount"); |
443 |
umount("/tmp/mount_move/"); |
444 |
fprintf(domain_fp, "delete file unmount /tmp/mount/\n"); |
445 |
fprintf(domain_fp, "delete file mount /tmp/mount/ " |
446 |
"/tmp/mount_move/ --move 0\n"); |
447 |
|
448 |
while (umount("/tmp/mount/") == 0) |
449 |
c++; /* Dummy. */ |
450 |
} |
451 |
|
452 |
/* Test umount(). */ |
453 |
{ |
454 |
/* Test standard case */ |
455 |
fprintf(domain_fp, "file unmount /tmp/mount/\n"); |
456 |
|
457 |
set_profile(0, "file::umount"); |
458 |
mount2("none", "/tmp/mount/", "tmpfs"); |
459 |
set_profile(3, "file::umount"); |
460 |
show_prompt("umount('/tmp/mount/') for '/tmp/mount/'", 0); |
461 |
if (umount("/tmp/mount/") == 0) |
462 |
printf("OK\n"); |
463 |
else |
464 |
printf("BUG: %s\n", strerror(errno)); |
465 |
fprintf(domain_fp, "delete file unmount /tmp/mount/\n"); |
466 |
|
467 |
set_profile(0, "file::umount"); |
468 |
|
469 |
mount2("none", "/tmp/mount/", "tmpfs"); |
470 |
set_profile(3, "file::umount"); |
471 |
show_prompt("umount('/tmp/mount/') for '/tmp/mount/'", 1); |
472 |
if (umount("/tmp/mount/") == EOF && errno == EPERM) |
473 |
printf("OK: Permission denied.\n"); |
474 |
else |
475 |
printf("FAILED: %s\n", strerror(errno)); |
476 |
|
477 |
/* Test pattern */ |
478 |
fprintf(domain_fp, "file unmount /tmp/\\?\\?\\?\\?\\?/\n"); |
479 |
set_profile(0, "file::umount"); |
480 |
mount2("none", "/tmp/mount/", "tmpfs"); |
481 |
set_profile(3, "file::umount"); |
482 |
show_prompt("umount('/tmp/mount/') for " |
483 |
"'/tmp/\\?\\?\\?\\?\\?/'", 1); |
484 |
if (umount("/tmp/mount/") == 0) |
485 |
printf("OK\n"); |
486 |
else |
487 |
printf("BUG: %s\n", strerror(errno)); |
488 |
fprintf(domain_fp, |
489 |
"delete file unmount /tmp/\\?\\?\\?\\?\\?/\n"); |
490 |
|
491 |
set_profile(0, "file::umount"); |
492 |
while (umount("/tmp/mount/") == 0) |
493 |
c++; /* Dummy. */ |
494 |
} |
495 |
|
496 |
/* Test chroot(). */ |
497 |
{ |
498 |
set_profile(3, "file::chroot"); |
499 |
|
500 |
/* Test standard case */ |
501 |
fprintf(domain_fp, "file chroot /tmp/mount/\n"); |
502 |
show_prompt("chroot('/tmp/mount/') for '/tmp/mount/'", 0); |
503 |
fflush(stdout); |
504 |
if (fork() == 0) { |
505 |
if (chroot("/tmp/mount/") == 0) |
506 |
printf("OK\n"); |
507 |
else |
508 |
printf("FAILED: %s\n", strerror(errno)); |
509 |
fflush(stdout); |
510 |
_exit(0); |
511 |
} |
512 |
wait(NULL); |
513 |
fprintf(domain_fp, "delete file chroot /tmp/mount/\n"); |
514 |
|
515 |
show_prompt("chroot('/tmp/mount/') for '/tmp/mount/'", 1); |
516 |
fflush(stdout); |
517 |
if (fork() == 0) { |
518 |
if (chroot("/tmp/mount/") == EOF && errno == EPERM) |
519 |
printf("OK: Permission denied.\n"); |
520 |
else |
521 |
printf("BUG: %s\n", strerror(errno)); |
522 |
fflush(stdout); |
523 |
_exit(0); |
524 |
} |
525 |
wait(NULL); |
526 |
|
527 |
/* Test pattern */ |
528 |
fprintf(domain_fp, "file chroot /tmp/\\?\\?\\?\\?\\?/\n"); |
529 |
show_prompt("chroot('/tmp/mount/') for " |
530 |
"'/tmp/\\?\\?\\?\\?\\?/'", 0); |
531 |
fflush(stdout); |
532 |
if (fork() == 0) { |
533 |
if (chroot("/tmp/mount/") == 0) |
534 |
printf("OK\n"); |
535 |
else |
536 |
printf("FAILED: %s\n", strerror(errno)); |
537 |
fflush(stdout); |
538 |
_exit(0); |
539 |
} |
540 |
wait(NULL); |
541 |
fprintf(domain_fp, |
542 |
"delete file chroot /tmp/\\?\\?\\?\\?\\?/\n"); |
543 |
|
544 |
set_profile(0, "file::chroot"); |
545 |
} |
546 |
|
547 |
/* Test pivot_root(). */ |
548 |
{ |
549 |
int error; |
550 |
char *stack = malloc(8192); |
551 |
set_profile(3, "file::pivot_root"); |
552 |
fprintf(domain_fp, "file pivot_root proc:/ proc:/ccs/\n"); |
553 |
snprintf(stack, 8191, "pivot_root('proc:/', 'proc:/ccs/')"); |
554 |
show_prompt(stack, 0); |
555 |
{ |
556 |
const pid_t pid = clone(child, stack + (8192 / 2), |
557 |
CLONE_NEWNS, NULL); |
558 |
while (waitpid(pid, &error, __WALL) == EOF && |
559 |
errno == EINTR) |
560 |
c++; /* Dummy. */ |
561 |
} |
562 |
errno = WIFEXITED(error) ? WEXITSTATUS(error) : -1; |
563 |
if (errno == 0) |
564 |
printf("OK\n"); |
565 |
else |
566 |
printf("FAILED: %s\n", strerror(errno)); |
567 |
|
568 |
fprintf(domain_fp, "delete file pivot_root proc:/ proc:/ccs/\n"); |
569 |
snprintf(stack, 8191, "pivot_root('proc:/', 'proc:/ccs/')"); |
570 |
show_prompt(stack, 1); |
571 |
{ |
572 |
const pid_t pid = clone(child, stack + (8192 / 2), |
573 |
CLONE_NEWNS, NULL); |
574 |
while (waitpid(pid, &error, __WALL) == EOF && |
575 |
errno == EINTR) |
576 |
c++; /* Dummy. */ |
577 |
} |
578 |
errno = WIFEXITED(error) ? WEXITSTATUS(error) : -1; |
579 |
if (errno == EPERM) |
580 |
printf("OK: Permission denied.\n"); |
581 |
else |
582 |
printf("BUG: %s\n", strerror(errno)); |
583 |
|
584 |
set_profile(2, "file::pivot_root"); |
585 |
snprintf(stack, 8191, "pivot_root('proc:/', 'proc:/ccs/')"); |
586 |
show_prompt(stack, 0); |
587 |
{ |
588 |
const pid_t pid = clone(child, stack + (8192 / 2), |
589 |
CLONE_NEWNS, NULL); |
590 |
while (waitpid(pid, &error, __WALL) == EOF && |
591 |
errno == EINTR) |
592 |
c++; /* Dummy. */ |
593 |
} |
594 |
errno = WIFEXITED(error) ? WEXITSTATUS(error) : -1; |
595 |
if (errno == 0) |
596 |
printf("OK\n"); |
597 |
else |
598 |
printf("FAILED: %s\n", strerror(errno)); |
599 |
|
600 |
set_profile(0, "file::pivot_root"); |
601 |
|
602 |
free(stack); |
603 |
} |
604 |
|
605 |
rmdir("/tmp/mount_move/"); |
606 |
rmdir("/tmp/mount_bind/"); |
607 |
rmdir("/tmp/mount/"); |
608 |
|
609 |
clear_status(); |
610 |
return 0; |
611 |
} |
| |