]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | #include <sys/fcntl.h> |
2 | #include <sys/attr.h> | |
3 | #include <unistd.h> | |
4 | ||
5 | #include "hfs-tests.h" | |
6 | #include "test-utils.h" | |
7 | #include "disk-image.h" | |
8 | ||
9 | TEST(set_create_time) | |
10 | ||
11 | static disk_image_t *di; | |
12 | ||
13 | int run_set_create_time(__unused test_ctx_t *ctx) | |
14 | { | |
15 | di = disk_image_get(); | |
16 | ||
17 | char *file; | |
18 | asprintf(&file, "%s/set-create-time.data", di->mount_point); | |
19 | ||
20 | int fd; | |
21 | ||
22 | assert_with_errno((fd = open(file, O_CREAT | O_RDWR, 0666)) >= 0); | |
23 | ||
24 | struct attrs { | |
25 | uint32_t len; | |
26 | struct timespec cr_time, mod_time; | |
27 | } attrs = { | |
28 | 0, | |
29 | { 2000, 0 }, // Create time after mod time | |
30 | { 1000, 0 } | |
31 | }; | |
32 | ||
33 | struct attrlist attrlist = { | |
34 | .bitmapcount = ATTR_BIT_MAP_COUNT, | |
35 | .commonattr = ATTR_CMN_CRTIME | ATTR_CMN_MODTIME, | |
36 | }; | |
37 | ||
38 | assert_no_err(fsetattrlist(fd, &attrlist, (char *)&attrs + 4, sizeof(attrs) - 4, 0)); | |
39 | ||
40 | assert_no_err(fgetattrlist(fd, &attrlist, &attrs, sizeof(attrs), 0)); | |
41 | ||
42 | assert(attrs.cr_time.tv_sec == 2000 && attrs.mod_time.tv_sec == 1000); | |
43 | ||
ec99dd30 | 44 | assert_no_err (close(fd)); |
558d2836 A |
45 | unlink(file); |
46 | free(file); | |
47 | ||
48 | return 0; | |
49 | } |