]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-doc-tombstone.c
hfs-556.100.11.tar.gz
[apple/hfs.git] / tests / cases / test-doc-tombstone.c
1 //
2 // doc-tombstone.c
3 // hfs
4 //
5 // Created by Chris Suter on 8/12/15.
6 //
7 //
8
9 #include <fcntl.h>
10 #include <sys/stat.h>
11 #include <sys/attr.h>
12 #include <unistd.h>
13
14 #include "hfs-tests.h"
15 #include "test-utils.h"
16 #include "disk-image.h"
17
18 TEST(doc_tombstone)
19
20 int run_doc_tombstone(__unused test_ctx_t *ctx)
21 {
22
23 disk_image_t *di = disk_image_get();
24
25 char *file;
26 char *new;
27 char *old;
28
29 asprintf(&file, "%s/doc-tombstone", di->mount_point);
30 asprintf(&new, "%s.new", file);
31 asprintf(&old, "%s.old", file);
32
33 int fd;
34
35 struct attrlist al = {
36 .bitmapcount = ATTR_BIT_MAP_COUNT,
37 .commonattr = ATTR_CMN_DOCUMENT_ID
38 };
39
40 struct attrs {
41 uint32_t len;
42 uint32_t doc_id;
43 } attrs;
44
45 uint32_t orig_doc_id;
46
47 unlink(file);
48 rmdir(file);
49
50
51 /*
52 * 1.a. Move file over existing
53 */
54
55 fd = open(file, O_RDWR | O_CREAT, 0666);
56
57 assert_with_errno(fd >= 0);
58
59 assert_no_err(fchflags(fd, UF_TRACKED));
60
61 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
62 FSOPT_ATTR_CMN_EXTENDED));
63
64 orig_doc_id = attrs.doc_id;
65
66 assert_no_err(close(fd));
67
68 assert_with_errno((fd = open(new,
69 O_RDWR | O_CREAT, 0666)) >= 0);
70
71 assert_no_err(rename(new, file));
72
73 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
74 FSOPT_ATTR_CMN_EXTENDED));
75
76 assert_equal(orig_doc_id, attrs.doc_id, "%u");
77
78 assert_no_err(close(fd));
79 assert_no_err(unlink(file));
80
81
82 /*
83 * 1.b. Move directory over existing
84 */
85
86 assert_no_err(mkdir(file, 0777));
87
88 assert_no_err(chflags(file, UF_TRACKED));
89
90 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
91 FSOPT_ATTR_CMN_EXTENDED));
92
93 orig_doc_id = attrs.doc_id;
94
95 assert_no_err(mkdir(new, 0777));
96
97 assert_no_err(rename(new, file));
98
99 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
100 FSOPT_ATTR_CMN_EXTENDED));
101
102 assert_equal(orig_doc_id, attrs.doc_id, "%u");
103
104 assert_no_err(rmdir(file));
105
106
107 /*
108 * 2.a. Move original file out of the way, move new file into place, delete original
109 */
110
111 fd = open(file, O_RDWR | O_CREAT, 0666);
112
113 assert_with_errno(fd >= 0);
114
115 assert_no_err(fchflags(fd, UF_TRACKED));
116
117 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
118 FSOPT_ATTR_CMN_EXTENDED));
119
120 orig_doc_id = attrs.doc_id;
121
122 assert_no_err(close(fd));
123
124 assert_with_errno((fd = open(new,
125 O_RDWR | O_CREAT, 0666)) >= 0);
126
127 assert_with_errno(fd >= 0);
128
129 assert_no_err(rename(file, old));
130 assert_no_err(rename(new, file));
131
132 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
133 FSOPT_ATTR_CMN_EXTENDED));
134
135 assert_equal(orig_doc_id, attrs.doc_id, "%u");
136
137 assert_no_err(close(fd));
138 assert_no_err(unlink(old));
139 assert_no_err(unlink(file));
140
141
142 /*
143 * 2.b. Move original directory out of the way, move new directory into place, delete original
144 */
145
146 assert_no_err(mkdir(file, 0777));
147
148 assert_no_err(chflags(file, UF_TRACKED));
149
150 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
151 FSOPT_ATTR_CMN_EXTENDED));
152
153 orig_doc_id = attrs.doc_id;
154
155 assert_no_err(mkdir(new, 0777));
156
157 assert_no_err(rename(file, old));
158 assert_no_err(rename(new, file));
159
160 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
161 FSOPT_ATTR_CMN_EXTENDED));
162
163 assert_equal(orig_doc_id, attrs.doc_id, "%u");
164
165 assert_no_err(rmdir(old));
166 assert_no_err(rmdir(file));
167
168
169 /*
170 * 3.a. Delete original file, move new file into place
171 */
172
173 assert_with_errno((fd = open(file,
174 O_RDWR | O_CREAT, 0666)) >= 0);
175
176 assert_with_errno(fd >= 0);
177
178 assert_no_err(fchflags(fd, UF_TRACKED));
179
180 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
181 FSOPT_ATTR_CMN_EXTENDED));
182
183 orig_doc_id = attrs.doc_id;
184
185 assert_no_err(close(fd));
186
187 assert_with_errno((fd = open(new,
188 O_RDWR | O_CREAT, 0666)) >= 0);
189
190 assert_with_errno(fd >= 0);
191
192 assert_no_err(unlink(file));
193
194 assert_no_err(rename(new, file));
195
196 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
197 FSOPT_ATTR_CMN_EXTENDED));
198
199 assert_equal(orig_doc_id, attrs.doc_id, "%u");
200
201 assert_no_err(close(fd));
202 assert_no_err(unlink(file));
203
204
205 /*
206 * 3.b. Delete original directory, move new directory into place
207 */
208
209 assert_no_err(mkdir(file, 0777));
210
211 assert_no_err(chflags(file, UF_TRACKED));
212
213 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
214 FSOPT_ATTR_CMN_EXTENDED));
215
216 orig_doc_id = attrs.doc_id;
217
218 assert_no_err(mkdir(new, 0777));
219
220 assert_no_err(rmdir(file));
221 assert_no_err(rename(new, file));
222
223 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
224 FSOPT_ATTR_CMN_EXTENDED));
225
226 assert_equal(orig_doc_id, attrs.doc_id, "%u");
227
228 assert_no_err(rmdir(file));
229
230
231 /*
232 * 4.a. Delete original file, create new file in place
233 */
234
235 assert_with_errno((fd = open(file,
236 O_RDWR | O_CREAT, 0666)) >= 0);
237
238 assert_no_err(fchflags(fd, UF_TRACKED));
239
240 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
241 FSOPT_ATTR_CMN_EXTENDED));
242
243 orig_doc_id = attrs.doc_id;
244
245 assert_no_err(close(fd));
246 assert_no_err(unlink(file));
247
248 assert_with_errno((fd = open(file,
249 O_RDWR | O_CREAT, 0666)) >= 0);
250
251 assert_no_err(fgetattrlist(fd, &al, &attrs, sizeof(attrs),
252 FSOPT_ATTR_CMN_EXTENDED));
253
254 assert_equal(orig_doc_id, attrs.doc_id, "%u");
255
256 assert_no_err(close(fd));
257 assert_no_err(unlink(file));
258
259
260 /*
261 * 4.b. Delete original directory, create new directory in place
262 */
263
264 assert_no_err(mkdir(file, 0777));
265
266 assert_no_err(chflags(file, UF_TRACKED));
267
268 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
269 FSOPT_ATTR_CMN_EXTENDED));
270
271 orig_doc_id = attrs.doc_id;
272
273 assert_no_err(rmdir(file));
274
275 assert_no_err(mkdir(file, 0777));
276
277 assert_no_err(getattrlist(file, &al, &attrs, sizeof(attrs),
278 FSOPT_ATTR_CMN_EXTENDED));
279
280 assert_equal(orig_doc_id, attrs.doc_id, "%u");
281
282 assert_no_err(rmdir(file));
283
284 return 0;
285 }