]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-doc-tombstone.c
5 // Created by Chris Suter on 8/12/15.
14 #include "hfs-tests.h"
15 #include "test-utils.h"
16 #include "disk-image.h"
20 int run_doc_tombstone(__unused test_ctx_t
*ctx
)
23 disk_image_t
*di
= disk_image_get();
29 asprintf(&file
, "%s/doc-tombstone", di
->mount_point
);
30 asprintf(&new, "%s.new", file
);
31 asprintf(&old
, "%s.old", file
);
35 struct attrlist al
= {
36 .bitmapcount
= ATTR_BIT_MAP_COUNT
,
37 .commonattr
= ATTR_CMN_DOCUMENT_ID
52 * 1.a. Move file over existing
55 fd
= open(file
, O_RDWR
| O_CREAT
, 0666);
57 assert_with_errno(fd
>= 0);
59 assert_no_err(fchflags(fd
, UF_TRACKED
));
61 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
62 FSOPT_ATTR_CMN_EXTENDED
));
64 orig_doc_id
= attrs
.doc_id
;
66 assert_no_err(close(fd
));
68 assert_with_errno((fd
= open(new,
69 O_RDWR
| O_CREAT
, 0666)) >= 0);
71 assert_no_err(rename(new, file
));
73 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
74 FSOPT_ATTR_CMN_EXTENDED
));
76 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
78 assert_no_err(close(fd
));
79 assert_no_err(unlink(file
));
83 * 1.b. Move directory over existing
86 assert_no_err(mkdir(file
, 0777));
88 assert_no_err(chflags(file
, UF_TRACKED
));
90 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
91 FSOPT_ATTR_CMN_EXTENDED
));
93 orig_doc_id
= attrs
.doc_id
;
95 assert_no_err(mkdir(new, 0777));
97 assert_no_err(rename(new, file
));
99 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
100 FSOPT_ATTR_CMN_EXTENDED
));
102 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
104 assert_no_err(rmdir(file
));
108 * 2.a. Move original file out of the way, move new file into place, delete original
111 fd
= open(file
, O_RDWR
| O_CREAT
, 0666);
113 assert_with_errno(fd
>= 0);
115 assert_no_err(fchflags(fd
, UF_TRACKED
));
117 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
118 FSOPT_ATTR_CMN_EXTENDED
));
120 orig_doc_id
= attrs
.doc_id
;
122 assert_no_err(close(fd
));
124 assert_with_errno((fd
= open(new,
125 O_RDWR
| O_CREAT
, 0666)) >= 0);
127 assert_with_errno(fd
>= 0);
129 assert_no_err(rename(file
, old
));
130 assert_no_err(rename(new, file
));
132 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
133 FSOPT_ATTR_CMN_EXTENDED
));
135 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
137 assert_no_err(close(fd
));
138 assert_no_err(unlink(old
));
139 assert_no_err(unlink(file
));
143 * 2.b. Move original directory out of the way, move new directory into place, delete original
146 assert_no_err(mkdir(file
, 0777));
148 assert_no_err(chflags(file
, UF_TRACKED
));
150 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
151 FSOPT_ATTR_CMN_EXTENDED
));
153 orig_doc_id
= attrs
.doc_id
;
155 assert_no_err(mkdir(new, 0777));
157 assert_no_err(rename(file
, old
));
158 assert_no_err(rename(new, file
));
160 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
161 FSOPT_ATTR_CMN_EXTENDED
));
163 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
165 assert_no_err(rmdir(old
));
166 assert_no_err(rmdir(file
));
170 * 3.a. Delete original file, move new file into place
173 assert_with_errno((fd
= open(file
,
174 O_RDWR
| O_CREAT
, 0666)) >= 0);
176 assert_with_errno(fd
>= 0);
178 assert_no_err(fchflags(fd
, UF_TRACKED
));
180 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
181 FSOPT_ATTR_CMN_EXTENDED
));
183 orig_doc_id
= attrs
.doc_id
;
185 assert_no_err(close(fd
));
187 assert_with_errno((fd
= open(new,
188 O_RDWR
| O_CREAT
, 0666)) >= 0);
190 assert_with_errno(fd
>= 0);
192 assert_no_err(unlink(file
));
194 assert_no_err(rename(new, file
));
196 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
197 FSOPT_ATTR_CMN_EXTENDED
));
199 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
201 assert_no_err(close(fd
));
202 assert_no_err(unlink(file
));
206 * 3.b. Delete original directory, move new directory into place
209 assert_no_err(mkdir(file
, 0777));
211 assert_no_err(chflags(file
, UF_TRACKED
));
213 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
214 FSOPT_ATTR_CMN_EXTENDED
));
216 orig_doc_id
= attrs
.doc_id
;
218 assert_no_err(mkdir(new, 0777));
220 assert_no_err(rmdir(file
));
221 assert_no_err(rename(new, file
));
223 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
224 FSOPT_ATTR_CMN_EXTENDED
));
226 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
228 assert_no_err(rmdir(file
));
232 * 4.a. Delete original file, create new file in place
235 assert_with_errno((fd
= open(file
,
236 O_RDWR
| O_CREAT
, 0666)) >= 0);
238 assert_no_err(fchflags(fd
, UF_TRACKED
));
240 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
241 FSOPT_ATTR_CMN_EXTENDED
));
243 orig_doc_id
= attrs
.doc_id
;
245 assert_no_err(close(fd
));
246 assert_no_err(unlink(file
));
248 assert_with_errno((fd
= open(file
,
249 O_RDWR
| O_CREAT
, 0666)) >= 0);
251 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
),
252 FSOPT_ATTR_CMN_EXTENDED
));
254 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
256 assert_no_err(close(fd
));
257 assert_no_err(unlink(file
));
261 * 4.b. Delete original directory, create new directory in place
264 assert_no_err(mkdir(file
, 0777));
266 assert_no_err(chflags(file
, UF_TRACKED
));
268 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
269 FSOPT_ATTR_CMN_EXTENDED
));
271 orig_doc_id
= attrs
.doc_id
;
273 assert_no_err(rmdir(file
));
275 assert_no_err(mkdir(file
, 0777));
277 assert_no_err(getattrlist(file
, &al
, &attrs
, sizeof(attrs
),
278 FSOPT_ATTR_CMN_EXTENDED
));
280 assert_equal(orig_doc_id
, attrs
.doc_id
, "%u");
282 assert_no_err(rmdir(file
));